Skip to content

Commit

Permalink
Merge pull request #5375 from webpack/bugfix/delegated-exports
Browse files Browse the repository at this point in the history
integrate the delegated module better into the exports flagging process
  • Loading branch information
sokra committed Jul 26, 2017
2 parents c8732c8 + 9dbed73 commit 8f4a9d2
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/DelegatedModule.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}

Expand Down
3 changes: 3 additions & 0 deletions lib/DelegatedPlugin.js
Expand Up @@ -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) {
Expand All @@ -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) => {
Expand Down
3 changes: 3 additions & 0 deletions lib/DllReferencePlugin.js
Expand Up @@ -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) {
Expand All @@ -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) => {
Expand Down
33 changes: 33 additions & 0 deletions 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;
4 changes: 4 additions & 0 deletions test/WatchTestCases.test.js
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions 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");
});
5 changes: 5 additions & 0 deletions 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");
});
19 changes: 19 additions & 0 deletions 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()
]
};

0 comments on commit 8f4a9d2

Please sign in to comment.