From 9dbed7360d772dad8aefca7750c724434c970130 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 26 Jul 2017 10:12:40 +0200 Subject: [PATCH] integrate the delegated module better into the exports flagging process --- lib/DelegatedModule.js | 4 +-- lib/DelegatedPlugin.js | 3 ++ lib/DllReferencePlugin.js | 3 ++ .../DelegatedExportsDependency.js | 33 +++++++++++++++++++ test/WatchTestCases.test.js | 4 +++ .../plugins/dll-reference-plugin/1/index.js | 5 +++ .../plugins/dll-reference-plugin/2/index.js | 5 +++ .../dll-reference-plugin/webpack.config.js | 19 +++++++++++ 8 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 lib/dependencies/DelegatedExportsDependency.js create mode 100644 test/watchCases/plugins/dll-reference-plugin/1/index.js create mode 100644 test/watchCases/plugins/dll-reference-plugin/2/index.js create mode 100644 test/watchCases/plugins/dll-reference-plugin/webpack.config.js diff --git a/lib/DelegatedModule.js b/lib/DelegatedModule.js index b769f17455a..49287b23b3d 100644 --- a/lib/DelegatedModule.js +++ b/lib/DelegatedModule.js @@ -9,6 +9,7 @@ const OriginalSource = require("webpack-sources").OriginalSource; const RawSource = require("webpack-sources").RawSource; const WebpackMissingModule = require("./dependencies/WebpackMissingModule"); const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency"); +const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency"); class DelegatedModule extends Module { constructor(sourceRequest, data, type, userRequest, originalRequest) { @@ -44,10 +45,9 @@ class DelegatedModule extends Module { this.built = true; this.builtTime = Date.now(); this.cacheable = true; - this.usedExports = true; - this.providedExports = this.delegateData.exports || true; this.dependencies.length = 0; this.addDependency(new DelegatedSourceDependency(this.sourceRequest)); + this.addDependency(new DelegatedExportsDependency(this, this.delegateData.exports || true)); callback(); } diff --git a/lib/DelegatedPlugin.js b/lib/DelegatedPlugin.js index 73ecde4498a..3cf11d3625e 100644 --- a/lib/DelegatedPlugin.js +++ b/lib/DelegatedPlugin.js @@ -7,6 +7,8 @@ const DelegatedModuleFactoryPlugin = require("./DelegatedModuleFactoryPlugin"); const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency"); +const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency"); +const NullFactory = require("./NullFactory"); class DelegatedPlugin { constructor(options) { @@ -16,6 +18,7 @@ class DelegatedPlugin { apply(compiler) { compiler.plugin("compilation", (compilation, params) => { compilation.dependencyFactories.set(DelegatedSourceDependency, params.normalModuleFactory); + compilation.dependencyFactories.set(DelegatedExportsDependency, new NullFactory()); }); compiler.plugin("compile", (params) => { diff --git a/lib/DllReferencePlugin.js b/lib/DllReferencePlugin.js index 82d094d8d40..bc314250ccb 100644 --- a/lib/DllReferencePlugin.js +++ b/lib/DllReferencePlugin.js @@ -7,6 +7,8 @@ const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency"); const DelegatedModuleFactoryPlugin = require("./DelegatedModuleFactoryPlugin"); const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin"); +const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency"); +const NullFactory = require("./NullFactory"); class DllReferencePlugin { constructor(options) { @@ -17,6 +19,7 @@ class DllReferencePlugin { compiler.plugin("compilation", (compilation, params) => { const normalModuleFactory = params.normalModuleFactory; compilation.dependencyFactories.set(DelegatedSourceDependency, normalModuleFactory); + compilation.dependencyFactories.set(DelegatedExportsDependency, new NullFactory()); }); compiler.plugin("before-compile", (params, callback) => { diff --git a/lib/dependencies/DelegatedExportsDependency.js b/lib/dependencies/DelegatedExportsDependency.js new file mode 100644 index 00000000000..4ec8d589f3c --- /dev/null +++ b/lib/dependencies/DelegatedExportsDependency.js @@ -0,0 +1,33 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +"use strict"; +const NullDependency = require("./NullDependency"); + +class DelegatedExportsDependency extends NullDependency { + constructor(originModule, exports) { + super(); + this.originModule = originModule; + this.exports = exports; + } + + get type() { + return "delegated exports"; + } + + getReference() { + return { + module: this.originModule, + importedNames: true + }; + } + + getExports() { + return { + exports: this.exports + }; + } +} + +module.exports = DelegatedExportsDependency; diff --git a/test/WatchTestCases.test.js b/test/WatchTestCases.test.js index ad98f6a0e1f..a247bb10fae 100644 --- a/test/WatchTestCases.test.js +++ b/test/WatchTestCases.test.js @@ -116,6 +116,10 @@ describe("WatchTestCases", () => { const watching = compiler.watch({ aggregateTimeout: 1000 }, (err, stats) => { + if(err) + return done(err); + if(!stats) + return done(new Error("No stats reported from Compiler")); if(stats.hash === lastHash) return; lastHash = stats.hash; diff --git a/test/watchCases/plugins/dll-reference-plugin/1/index.js b/test/watchCases/plugins/dll-reference-plugin/1/index.js new file mode 100644 index 00000000000..4f865d5f49e --- /dev/null +++ b/test/watchCases/plugins/dll-reference-plugin/1/index.js @@ -0,0 +1,5 @@ +import value from "dll/module"; + +it("should have the correct default export", function() { + value.should.be.eql("ok"); +}); diff --git a/test/watchCases/plugins/dll-reference-plugin/2/index.js b/test/watchCases/plugins/dll-reference-plugin/2/index.js new file mode 100644 index 00000000000..0b849002c78 --- /dev/null +++ b/test/watchCases/plugins/dll-reference-plugin/2/index.js @@ -0,0 +1,5 @@ +import value from "dll/module"; + +it("should have still the correct default export", function() { + value.should.be.eql("ok"); +}); diff --git a/test/watchCases/plugins/dll-reference-plugin/webpack.config.js b/test/watchCases/plugins/dll-reference-plugin/webpack.config.js new file mode 100644 index 00000000000..07ad2bf34a4 --- /dev/null +++ b/test/watchCases/plugins/dll-reference-plugin/webpack.config.js @@ -0,0 +1,19 @@ +var webpack = require("../../../../"); +module.exports = { + plugins: [ + new webpack.DllReferencePlugin({ + name: "function(id) { return {default: 'ok'}; }", + scope: "dll", + content: { + "./module": { + id: 1, + meta: { + harmonyModule: true + }, + exports: ["default"] + } + } + }), + new webpack.optimize.ModuleConcatenationPlugin() + ] +};