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

feat: add context to options.outputPath && options.publicPath #166

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
);
}
Expand Down
34 changes: 34 additions & 0 deletions test/correct-filename.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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() {
Expand Down