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

fix: outputPath function overriden by useRelativePath #139

Merged
merged 3 commits into from
Apr 1, 2017
Merged
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
17 changes: 7 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -56,8 +48,13 @@ 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;
Expand Down
52 changes: 51 additions & 1 deletion test/correct-filename.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -86,4 +109,31 @@ describe("useRelativePath option", function() {
'module.exports = __webpack_public_path__ + \"this/81dc9bdb52d04dc20036dbd8313ed055.txt\";'
);
});
});
});
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\";'
);

});
});