diff --git a/index.js b/index.js index aff5c56..cd23bf3 100644 --- a/index.js +++ b/index.js @@ -52,7 +52,7 @@ module.exports = function(content) { // support functions as outputPath to generate them dynamically outputPath = ( typeof config.outputPath === "function" - ? config.outputPath(url) + ? config.outputPath(url, this._module || {}) : config.outputPath + url ); url = outputPath; @@ -65,7 +65,7 @@ module.exports = function(content) { // support functions as publicPath to generate them dynamically publicPath = JSON.stringify( typeof config.publicPath === "function" - ? config.publicPath(url) + ? config.publicPath(url, this._module || {}) : config.publicPath + url ); } diff --git a/test/correct-filename.test.js b/test/correct-filename.test.js index 735f86d..49ddf90 100644 --- a/test/correct-filename.test.js +++ b/test/correct-filename.test.js @@ -48,6 +48,32 @@ function run_with_options(resourcePath,options, content) { } } +function run_with_path_callbacks(resourcePath, query, content) { + content = content || new Buffer("1234"); + var result = { publicPath: false, outputPath: false }; + var context = { + resourcePath: resourcePath, + query: "?" + query, + options: { + context: "/this/is/the/context", + fileLoader: { + publicPath: function(url, module) { + if (!!module) + result.publicPath = true + }, + outputPath: function(url, module) { + if (!!module) + result.outputPath = true + } + }, + }, + emitFile: function(url, content2) { + } + }; + fileLoader.call(context, content); + return result; +} + function test(excepted, resourcePath, query, content) { run(resourcePath, query, content).file.should.be.eql(excepted); } @@ -104,6 +130,14 @@ describe("publicPath option", function() { 'module.exports = __webpack_public_path__ + "81dc9bdb52d04dc20036dbd8313ed055.txt";' ); }); + + it("should call publicPath callback with module", function() { + run_with_path_callbacks("whatever.txt", "").should.property("publicPath", true); + }); + + it("should call outputPath callback with module", function() { + run_with_path_callbacks("whatever.txt", "").should.property("outputPath", true); + }); }); describe("useRelativePath option", function() {