-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Disable System.import parser plugin by default #6321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
lib/dependencies/SystemPlugin.js
Outdated
@@ -39,6 +39,11 @@ class SystemPlugin { | |||
parser.state.module.context, require.resolve("../../buildin/system.js")); | |||
return ParserHelpers.addParsedVariableToModule(parser, "System", systemPolyfillRequire); | |||
}); | |||
|
|||
parser.hooks.call.for("System.import").tap("SystemPlugin", expr => { | |||
parser.hooks.importCall.call(expr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This trick removes System.import
handling from ImportPlugin
by simulating an import()
call.
lib/dependencies/SystemPlugin.js
Outdated
@@ -15,7 +15,7 @@ class SystemPlugin { | |||
normalModuleFactory | |||
}) => { | |||
const handler = (parser, parserOptions) => { | |||
if(typeof parserOptions.system !== "undefined" && !parserOptions.system) | |||
if(typeof parserOptions.system === "undefined" || !parserOptions.system) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlike other parser options, this one is disabled by default.
Will users be warned they are using something that doesn't work anymore? My one concern: people use it thinking there is code splitting and it does nothing. Will this throw now? |
Good point. Maybe we should do this for webpack 4 until webpack 5.
|
@sokra working on it 👍 |
b615143
to
56aac91
Compare
I've also updated the PR message to describe the new behavior. |
lib/dependencies/SystemPlugin.js
Outdated
|
||
parser.hooks.call.for("System.import").tap("SystemPlugin", expr => { | ||
if(shouldWarn) { | ||
shouldWarn = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Emit the warning once. Only if System.import()
is used somewhere.
56aac91
to
218d0a2
Compare
The behaviour described by @sokra works for Angular CLI 👍 |
@filipesilva I've implemented it in this PR. The warning will be visible only if |
lib/dependencies/SystemPlugin.js
Outdated
this.name = "SystemImportDeprecationWarning"; | ||
this.message = "System.import() is deprecated and will be removed soon.\n" + | ||
"Use import() or require.ensure() instead.\n" + | ||
"For more info visit https://webpack.js.org/guides/code-splitting/"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should print a list of all modules using System.import.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding this to the warning and allow multiple emit?
this.origin = this.module = module;
this.originLoc = loc;
The above modification emits the following warnings:
System.import() is deprecated and will be removed soon. Use import() instead.
For more info visit https://webpack.js.org/guides/code-splitting/
@ ./index.js 43:2-33
It may be better to debug these messages rather than a module list. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I remove will be removed soon
? I feel like it's a bit to much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, that's better.
Add the warning to parser.scope.module.warnings
instead of to the Compilation directly. This should ensure that it's correctly cached.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stats
does not extract originLoc
of Module#warnings
; only Compilation#warnings
. I'm unable to match the location into warnings.js
when using parser.scope.module
instead of compilation
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought Module#warnings
are added to Compilation#warnings
after parsing...
lib/node/NodeMainTemplatePlugin.js
Outdated
@@ -36,7 +36,7 @@ module.exports = class NodeMainTemplatePlugin { | |||
`${mainTemplate.requireFn}.oe = function(err) {`, | |||
Template.indent([ | |||
"process.nextTick(function() {", | |||
Template.indent("throw err; // catch this error by using System.import().catch()"), | |||
Template.indent("throw err;"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// catch this error by using import().catch()
test/HotTestCases.test.js
Outdated
}, { | ||
test: /\.js$/, | ||
parser: { | ||
system: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove all System.import
calls in the hot test cases.
test/TestCases.test.js
Outdated
@@ -159,6 +159,11 @@ describe("TestCases", () => { | |||
}, | |||
module: { | |||
rules: [{ | |||
test: /\.js$/, | |||
parser: { | |||
system: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove all System.import
calls in the test cases.
@@ -0,0 +1,3 @@ | |||
module.exports = [ | |||
[/System\.import\(\) is deprecated/] | |||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add additional config testcases for system: true
,system: undefined
and system: false
lib/dependencies/SystemPlugin.js
Outdated
compilation.warnings.push(new SystemImportDeprecationWarning()); | ||
} | ||
|
||
parser.hooks.importCall.call(expr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return the result of this line
lib/dependencies/SystemPlugin.js
Outdated
|
||
this.name = "SystemImportDeprecationWarning"; | ||
this.message = "System.import() is deprecated and will be removed soon.\n" + | ||
"Use import() or require.ensure() instead.\n" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove require.ensure()
, only recommend import()
218d0a2
to
d170088
Compare
d170088
to
af8acab
Compare
af8acab
to
4a59e12
Compare
@@ -29,13 +29,6 @@ it("should answer typeof require.ensure correctly", function() { | |||
it("should answer typeof require.resolve correctly", function() { | |||
(typeof require.resolve).should.be.eql("function"); | |||
}); | |||
it("should answer typeof System correctly", function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two tests should be moved into configCases/parsing/system.import
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
try { | ||
System.import("./module").then(mod => { | ||
mod.should.be.eql({ default: "ok" }); | ||
done(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should error here when __SYSTEM === false
lib/dependencies/SystemPlugin.js
Outdated
|
||
parser.hooks.call.for("System.import").tap("SystemPlugin", expr => { | ||
if(shouldWarn) { | ||
compilation.warnings.push(new SystemImportDeprecationWarning(parser.state.module, expr.loc)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not happy with this. To make the warning cache correctly, it has to be in module.warnings
, but I will try changing it myself.
- `system: undefined`: Warns if `System.import()` is used - `system: true`: Disable warning - `system: false`: Skip `System.import()` instrumentation
b4529b2
to
3fb63f9
Compare
Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon. |
Thanks |
What kind of change does this PR introduce?
refactor
Did you add tests for your changes?
yes
If relevant, link to documentation update:
TODO since the parser options are updated.
Summary
System.import
is deprecated since version 2.1.0-beta.28.This PR disablesSystem.import
by default. Previously its support was opt-in. In order to enable it, the parser optionsystem
must be enabled:This PR introduce a new warning if
System.import()
is used. The plugin can be toggled using aparser
option:Possible
system
values:default
: ConsiderSystem.import()
asimport()
. Emit a warning ifSystem.import()
is used.true
: ConsiderSystem.import()
asimport()
. No warning.false
:System.import()
is not intercepted. Using it most like triggers aTypeError
Does this PR introduce a breaking change?
yes (new warning)
Other information
cc @TheLarkInn @hansl @filipesilva