From 18d7396835c8e2fb496a501c53504ab46d92b19b Mon Sep 17 00:00:00 2001 From: Isiah Meadows Date: Mon, 17 Dec 2018 01:23:03 -0500 Subject: [PATCH 1/4] Remove a broken hook --- lib/node/NodeSourcePlugin.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/node/NodeSourcePlugin.js b/lib/node/NodeSourcePlugin.js index d5505f6f5be..081e1a6efd1 100644 --- a/lib/node/NodeSourcePlugin.js +++ b/lib/node/NodeSourcePlugin.js @@ -116,9 +116,6 @@ module.exports = class NodeSourcePlugin { normalModuleFactory.hooks.parser .for("javascript/dynamic") .tap("NodeSourcePlugin", handler); - normalModuleFactory.hooks.parser - .for("javascript/esm") - .tap("NodeSourcePlugin", handler); } ); compiler.hooks.afterResolvers.tap("NodeSourcePlugin", compiler => { From 31de55386ab203ffc8b3b9ab1aaf6d7ec669f0b5 Mon Sep 17 00:00:00 2001 From: Isiah Meadows Date: Tue, 18 Dec 2018 02:44:15 -0500 Subject: [PATCH 2/4] Add test --- test/configCases/web/node-source/index.mjs | 1 + test/configCases/web/node-source/webpack.config.js | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 test/configCases/web/node-source/index.mjs create mode 100644 test/configCases/web/node-source/webpack.config.js diff --git a/test/configCases/web/node-source/index.mjs b/test/configCases/web/node-source/index.mjs new file mode 100644 index 00000000000..b47d0eb84b0 --- /dev/null +++ b/test/configCases/web/node-source/index.mjs @@ -0,0 +1 @@ +global diff --git a/test/configCases/web/node-source/webpack.config.js b/test/configCases/web/node-source/webpack.config.js new file mode 100644 index 00000000000..c51eb00dad1 --- /dev/null +++ b/test/configCases/web/node-source/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + target: "web", + entry: "index.mjs", + performance: { + hints: false + }, + optimization: { + minimize: false + } +}; From 14ef0108863f7838877b53bec00502fa79026540 Mon Sep 17 00:00:00 2001 From: Isiah Meadows Date: Tue, 18 Dec 2018 16:48:56 -0500 Subject: [PATCH 3/4] Fix nits, block `require` to prevent false positive --- test/configCases/web/node-source/index.mjs | 7 ++++++- test/configCases/web/node-source/webpack.config.js | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/test/configCases/web/node-source/index.mjs b/test/configCases/web/node-source/index.mjs index b47d0eb84b0..2974f3b5d32 100644 --- a/test/configCases/web/node-source/index.mjs +++ b/test/configCases/web/node-source/index.mjs @@ -1 +1,6 @@ -global +// Block `require`, but keep Webpack from trying to work around it. +eval("require = undefined") + +it("should compile fine", () => { + global +}) diff --git a/test/configCases/web/node-source/webpack.config.js b/test/configCases/web/node-source/webpack.config.js index c51eb00dad1..721e519b077 100644 --- a/test/configCases/web/node-source/webpack.config.js +++ b/test/configCases/web/node-source/webpack.config.js @@ -1,6 +1,6 @@ module.exports = { target: "web", - entry: "index.mjs", + entry: "./index.mjs", performance: { hints: false }, From 6b54a46842a21694787cbec33699955d11a799fc Mon Sep 17 00:00:00 2001 From: Isiah Meadows Date: Tue, 18 Dec 2018 16:55:56 -0500 Subject: [PATCH 4/4] Fix failing test. --- test/configCases/web/node-source/index.mjs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/configCases/web/node-source/index.mjs b/test/configCases/web/node-source/index.mjs index 2974f3b5d32..259f3b65bae 100644 --- a/test/configCases/web/node-source/index.mjs +++ b/test/configCases/web/node-source/index.mjs @@ -2,5 +2,11 @@ eval("require = undefined") it("should compile fine", () => { - global + // It's okay if this executes fine or if `global` is not defined. If it + // results in a `require()` call, this will throw a `TypeError` instead. + try { + global + } catch (e) { + if (!(e instanceof ReferenceError)) throw e + } })