Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.

Commit 80cdee2

Browse files
economysizegeekjoshwiens
authored andcommittedApr 1, 2017
fix: outputPath function overriden by useRelativePath (#139)
1 parent 46cb916 commit 80cdee2

File tree

2 files changed

+58
-11
lines changed

2 files changed

+58
-11
lines changed
 

‎index.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ module.exports = function(content) {
3636
});
3737

3838
var outputPath = "";
39-
if (config.outputPath) {
40-
// support functions as outputPath to generate them dynamically
41-
outputPath = (
42-
typeof config.outputPath === "function"
43-
? config.outputPath(url)
44-
: config.outputPath
45-
);
46-
}
4739

4840
var filePath = this.resourcePath;
4941
if (config.useRelativePath) {
@@ -56,8 +48,13 @@ module.exports = function(content) {
5648
outputPath = relativePath + url;
5749
}
5850
url = relativePath + url;
59-
} else if (outputPath) {
60-
outputPath = outputPath + url;
51+
} else if (config.outputPath) {
52+
// support functions as outputPath to generate them dynamically
53+
outputPath = (
54+
typeof config.outputPath === "function"
55+
? config.outputPath(url)
56+
: config.outputPath + url
57+
);
6158
url = outputPath;
6259
} else {
6360
outputPath = url;

‎test/correct-filename.test.js

+51-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@ function run(resourcePath, query, content) {
2424
result: result
2525
}
2626
}
27+
function run_with_options(resourcePath,options, content) {
28+
content = content || new Buffer("1234");
29+
var file = null;
30+
31+
var context = {
32+
resourcePath: resourcePath,
33+
options: {
34+
"fileLoader": options,
35+
context: "/this/is/the/context"
36+
},
37+
emitFile: function(url, content2) {
38+
content2.should.be.eql(content);
39+
file = url;
40+
}
41+
};
42+
43+
var result = fileLoader.call(context, content)
44+
45+
return {
46+
file: file,
47+
result: result
48+
}
49+
}
2750

2851
function test(excepted, resourcePath, query, content) {
2952
run(resourcePath, query, content).file.should.be.eql(excepted);
@@ -86,4 +109,31 @@ describe("useRelativePath option", function() {
86109
'module.exports = __webpack_public_path__ + \"this/81dc9bdb52d04dc20036dbd8313ed055.txt\";'
87110
);
88111
});
89-
});
112+
});
113+
describe("outputPath function", function() {
114+
it("should be supported", function() {
115+
outputFunc = function(value) {
116+
return("/path/set/by/func");
117+
118+
};
119+
var options = {};
120+
options.outputPath = outputFunc;
121+
run_with_options("/this/is/the/context/file.txt", options).result.should.be.eql(
122+
'module.exports = __webpack_public_path__ + \"/path/set/by/func\";'
123+
);
124+
125+
});
126+
it("should be ignored if you set useRelativePath", function() {
127+
outputFunc = function(value) {
128+
return("/path/set/by/func");
129+
130+
};
131+
var options = {};
132+
options.outputPath = outputFunc;
133+
options.useRelativePath = true;
134+
run_with_options("/this/is/the/context/file.txt", options).result.should.be.eql(
135+
'module.exports = __webpack_public_path__ + \"./81dc9bdb52d04dc20036dbd8313ed055.txt\";'
136+
);
137+
138+
});
139+
});

0 commit comments

Comments
 (0)
This repository has been archived.