Skip to content

Commit

Permalink
Merge pull request #117 from chuckdumont/work
Browse files Browse the repository at this point in the history
Fix exception using webpack-html-plugin
  • Loading branch information
chuckdumont authored Jan 3, 2018
2 parents 967e682 + a7cfb04 commit 73a33de
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
19 changes: 8 additions & 11 deletions lib/DojoLoaderPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ module.exports = class DojoLoaderPlugin {
compilation:{value: compilation},
params:{value: params}
});
compiler.plugin("make", this.make.bind(context));
if (compilation.compiler === compiler) {
// Don't do this for child compilations
// https://github.com/OpenNTF/dojo-webpack-plugin/issues/115
compiler.plugin("make", this.validateEmbeddedLoader.bind(context));
}
plugin(compilation, [
["succeed-module", this.succeedModule],
["after-optimize-chunks", this.afterOptimizeChunks]
Expand Down Expand Up @@ -163,14 +167,14 @@ module.exports = class DojoLoaderPlugin {
return loaderScope;
}

validateEmbeddedLoader(params, embeddedLoader, filename, callback) {
validateEmbeddedLoader(compilation__, callback) {
// Vefiry that embedded loader version and dojo version are the same
params.normalModuleFactory.create({
this.params.normalModuleFactory.create({
dependencies: [{request: "dojo/package.json"}]
}, (err, pkgModule) => {
if (!err) {
const dojoVersion = require(pkgModule.request).version;
const scope = this.createEmbeddedLoaderScope({}, embeddedLoader, filename);
const scope = this.createEmbeddedLoaderScope({}, this.embeddedLoader, this.filename);
if (dojoVersion !== scope.loaderVersion) {
err = new Error(
`Dojo loader version does not match the version of Dojo.
Expand Down Expand Up @@ -242,13 +246,6 @@ Refer to https://github.com/OpenNTF/dojo-webpack-plugin/blob/master/README.md#bu
this.embeddedLoaderFilename = filename;
}

make(compilation__, callback) {
// Make sure the embedded loader was created using the same version of dojo specified in the config
this.validateEmbeddedLoader(this.params, this.embeddedLoader, this.embeddedLoaderFilename, (err) => {
callback(err);
});
}

succeedModule(module) {
const {options} = this;
if (!module.issuer) {
Expand Down
6 changes: 4 additions & 2 deletions test/DojoLoaderPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ describe("DojoLoaderPlugin tests", function() {
describe("validateEmbeddedLoader edge cases", function() {
it("Should invoke callback with error if nomralModuleFactory.create returns an error", function(done) {
var error = new Error("Failed to create module");
plugin.validateEmbeddedLoader({
plugin.params = {
normalModuleFactory: {
create: function(params__, callback) {
callback(error);
}
}
}, "", "", err => {
};
plugin.embeddedLoader = plugin.filename = "";
plugin.validateEmbeddedLoader(null, err => {
err.should.be.eql(error);
done();
});
Expand Down

0 comments on commit 73a33de

Please sign in to comment.