From 737836f6e869341e76bb74684d3fb8ed71a4c422 Mon Sep 17 00:00:00 2001 From: Dirk Elmendorf Date: Sat, 1 Apr 2017 05:37:24 -0500 Subject: [PATCH 1/3] Handle case where you set useRelativePath to false and you are using an outputPath function to overrride where the file is put --- index.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 54d9861..8ac0c03 100644 --- a/index.js +++ b/index.js @@ -36,14 +36,6 @@ module.exports = function(content) { }); var outputPath = ""; - if (config.outputPath) { - // support functions as outputPath to generate them dynamically - outputPath = ( - typeof config.outputPath === "function" - ? config.outputPath(url) - : config.outputPath - ); - } var filePath = this.resourcePath; if (config.useRelativePath) { @@ -56,8 +48,14 @@ module.exports = function(content) { outputPath = relativePath + url; } url = relativePath + url; - } else if (outputPath) { - outputPath = outputPath + url; + } else if (config.outputPath) { + // support functions as outputPath to generate them dynamically + outputPath = ( + typeof config.outputPath === "function" + ? config.outputPath(url) + : config.outputPath + url + ); + } url = outputPath; } else { outputPath = url; From a6f8fe66cf419c102a55f623ace2d9e71d841c7f Mon Sep 17 00:00:00 2001 From: Dirk Elmendorf Date: Sat, 1 Apr 2017 05:41:51 -0500 Subject: [PATCH 2/3] Fixed typo --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index 8ac0c03..8d6cc43 100644 --- a/index.js +++ b/index.js @@ -55,7 +55,6 @@ module.exports = function(content) { ? config.outputPath(url) : config.outputPath + url ); - } url = outputPath; } else { outputPath = url; From babf9aaa5045e1d476f0067b1fd281b960011e00 Mon Sep 17 00:00:00 2001 From: Dirk Elmendorf Date: Sat, 1 Apr 2017 06:10:24 -0500 Subject: [PATCH 3/3] Added in a test to confirm that outputPath is respected --- test/correct-filename.test.js | 52 ++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/test/correct-filename.test.js b/test/correct-filename.test.js index 143eb86..129eb00 100644 --- a/test/correct-filename.test.js +++ b/test/correct-filename.test.js @@ -24,6 +24,29 @@ function run(resourcePath, query, content) { result: result } } +function run_with_options(resourcePath,options, content) { + content = content || new Buffer("1234"); + var file = null; + + var context = { + resourcePath: resourcePath, + options: { + "fileLoader": options, + context: "/this/is/the/context" + }, + emitFile: function(url, content2) { + content2.should.be.eql(content); + file = url; + } + }; + + var result = fileLoader.call(context, content) + + return { + file: file, + result: result + } +} function test(excepted, resourcePath, query, content) { run(resourcePath, query, content).file.should.be.eql(excepted); @@ -86,4 +109,31 @@ describe("useRelativePath option", function() { 'module.exports = __webpack_public_path__ + \"this/81dc9bdb52d04dc20036dbd8313ed055.txt\";' ); }); -}); \ No newline at end of file +}); +describe("outputPath function", function() { + it("should be supported", function() { + outputFunc = function(value) { + return("/path/set/by/func"); + + }; + var options = {}; + options.outputPath = outputFunc; + run_with_options("/this/is/the/context/file.txt", options).result.should.be.eql( + 'module.exports = __webpack_public_path__ + \"/path/set/by/func\";' + ); + + }); + it("should be ignored if you set useRelativePath", function() { + outputFunc = function(value) { + return("/path/set/by/func"); + + }; + var options = {}; + options.outputPath = outputFunc; + options.useRelativePath = true; + run_with_options("/this/is/the/context/file.txt", options).result.should.be.eql( + 'module.exports = __webpack_public_path__ + \"./81dc9bdb52d04dc20036dbd8313ed055.txt\";' + ); + + }); +});