Skip to content

Commit

Permalink
Merge pull request #122 from chuckdumont/work
Browse files Browse the repository at this point in the history
Run dojo resolver before default resolvers
  • Loading branch information
chuckdumont authored Jan 10, 2018
2 parents bed7987 + 8aa311d commit 53c81b1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 36 deletions.
10 changes: 5 additions & 5 deletions lib/DojoAMDPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ module.exports = class DojoAMDPlugin {
}

apply(compiler) {

compiler.options.resolve.plugins = compiler.options.resolve.plugins || [];
compiler.options.resolve.plugins.push(this.newResolverPlugin(this.options, compiler));
compiler.apply(
this.newDojoLoaderPlugin(this.options),
this.newMainTemplatePlugin(this.options),
this.newChunkTemplatePlugin(this.options),
this.newModuleFactoryPlugin(this.options),
this.newResolverPlugin(this.options)
this.newModuleFactoryPlugin(this.options)
);

compiler.plugin("compilation", this.compilationPlugins.bind(this));
Expand Down Expand Up @@ -118,8 +118,8 @@ module.exports = class DojoAMDPlugin {
newModuleFactoryPlugin(options) {
return new DojoAMDModuleFactoryPlugin(options);
}
newResolverPlugin() {
return new DojoAMDResolverPlugin();
newResolverPlugin(options, compiler) {
return new DojoAMDResolverPlugin(options, compiler);
}
newRequireDependenciesBlockParserPlugin(options, parser) {
return new DojoAMDRequireDependenciesBlockParserPlugin(options, parser);
Expand Down
13 changes: 8 additions & 5 deletions lib/DojoAMDResolverPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
const path = require("path");

module.exports = class DojoAMDResolverPlugin {
apply(compiler) {
constructor(options, compiler) {
this.options = options;
this.compiler = compiler;
compiler.plugin("normal-module-factory", () => {
compiler.resolvers.normal.plugin('module', this.module.bind(this));
});
}

apply(resolver) {
resolver.plugin("module", this.module.bind(this));
}

module(request, callback) {
if (request.directory) {
return callback();
Expand All @@ -36,7 +39,7 @@ module.exports = class DojoAMDResolverPlugin {
};
const message = `Dojo resolve ${obj.path} from ${request.request} in ${request.path}`;
this.compiler.resolvers.normal.doResolve(['raw-file'], obj, message, (err, result) => {
callback(null, result);
return result ? callback(null, result) : callback();
});
} else {
callback();
Expand Down
19 changes: 14 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 13 additions & 21 deletions test/DojoAMDResolverPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,23 @@
const DojoAMDResolverPlugin = require("../lib/DojoAMDResolverPlugin");

describe("DojoAMDResolverPlugin tests", function() {
const plugin = new DojoAMDResolverPlugin({});
const plugin = new DojoAMDResolverPlugin({}, {
applyPluginsBailResult(event) {
if (event === "get dojo require") {
return {
toUrl: (request) => {
return request.request === "null" ? null : request.request;
}
};
}
}
});
var moduleCallback;
beforeEach(function() {
plugin.apply({
resolvers: {
normal: {
plugin: (event, callback) => {
if (event === "module") {
moduleCallback = callback;
}
}
}
},
plugin: (event, callback) => {
if (event === "normal-module-factory") {
callback();
}
},
applyPluginsBailResult(event) {
if (event === "get dojo require") {
return {
toUrl: (request) => {
return request.request === "null" ? null : request.request;
}
};
if (event === "module") {
moduleCallback = callback;
}
}
});
Expand Down

0 comments on commit 53c81b1

Please sign in to comment.