From dabbab46273fbc9a02d5ff26b1e5303d7d1ab09a Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Sat, 15 Jun 2013 17:31:56 +0200 Subject: [PATCH] removed the last TODO :) --- lib/dependencies/RequireContextPlugin.js | 15 ++++++++++----- package.json | 2 +- test/browsertest/lib/index.web.js | 1 + test/browsertest/templates/node_modules/xyz.js | 1 + 4 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 test/browsertest/templates/node_modules/xyz.js diff --git a/lib/dependencies/RequireContextPlugin.js b/lib/dependencies/RequireContextPlugin.js index a405b093b..f79334db8 100644 --- a/lib/dependencies/RequireContextPlugin.js +++ b/lib/dependencies/RequireContextPlugin.js @@ -26,7 +26,6 @@ RequireContextPlugin.prototype.apply = function(compiler) { compilation.dependencyFactories.set(ContextElementDependency, normalModuleFactory); }); compiler.plugin("context-module-factory", function(cmf) { - // TODO extract in modules cmf.plugin("alternatives", function(items, callback) { if(items.length == 0) return callback(null, items); @@ -48,10 +47,16 @@ RequireContextPlugin.prototype.apply = function(compiler) { cmf.plugin("alternatives", function(items, callback) { if(items.length == 0) return callback(null, items); - callback(null, items.filter(function(obj) { - return modulesDirectories.filter(function(dir) { - return obj.request.indexOf("/" + dir + "/") >= 0; - }) == 0; + callback(null, items.map(function(obj) { + for(var i = 0; i < modulesDirectories.length; i++) { + var dir = modulesDirectories[i]; + var idx = obj.request.indexOf("/" + dir + "/"); + if(idx >= 0) { + obj.request = obj.request.slice(idx+dir.length+2); + break; + } + } + return obj; })); }); }); diff --git a/package.json b/package.json index 7c7b421be..83c8b3701 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "webpack", - "version": "0.10.0-beta22", + "version": "0.10.0-beta23", "author": "Tobias Koppers @sokra", "description": "Packs CommonJs/AMD/Labeled Modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jade, coffee, css, less, ... and your custom stuff.", "dependencies": { diff --git a/test/browsertest/lib/index.web.js b/test/browsertest/lib/index.web.js index 80b68bbd3..29ad70277 100644 --- a/test/browsertest/lib/index.web.js +++ b/test/browsertest/lib/index.web.js @@ -362,6 +362,7 @@ describe("main", function() { (require.context("../././templates"))("./tmpl").should.be.eql("test template"); (require.context(".././templates/.")("./tmpl")).should.be.eql("test template"); require . context ( "." + "." + "/" + "templ" + "ates" ) ( "./subdir/tmpl.js" ).should.be.eql("subdir test template"); + require.context("../templates", true, /./)("xyz").should.be.eql("xyz"); }); it("should automatically create contexts", function() { diff --git a/test/browsertest/templates/node_modules/xyz.js b/test/browsertest/templates/node_modules/xyz.js new file mode 100644 index 000000000..8bede5fb1 --- /dev/null +++ b/test/browsertest/templates/node_modules/xyz.js @@ -0,0 +1 @@ +module.exports = "xyz"; \ No newline at end of file