Skip to content

Commit

Permalink
fix: do not allow absolute path in chunkFilename
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanv committed Dec 7, 2021
1 parent 76361df commit fd8e0aa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/plugin-options.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"chunkFilename": {
"anyOf": [
{
"type": "string"
"type": "string",
"absolutePath": false,
"minLength": 1
},
{
"instanceof": "Function"
Expand Down
9 changes: 7 additions & 2 deletions test/__snapshots__/validate-plugin-options.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ exports[`validate options should throw an error on the "attributes" option with
-> Read more at https://github.com/webpack-contrib/mini-css-extract-plugin#attributes"
`;

exports[`validate options should throw an error on the "chunkFilename" option with "/styles/[id].css" value 1`] = `
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
- options.chunkFilename: A relative path is expected. However, the provided value \\"/styles/[id].css\\" is an absolute path!"
`;

exports[`validate options should throw an error on the "chunkFilename" option with "true" value 1`] = `
"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema.
- options.chunkFilename should be one of these:
string | function
non-empty string | function
-> This option determines the name of non-entry chunk files.
-> Read more at https://github.com/webpack-contrib/mini-css-extract-plugin#chunkfilename
Details:
* options.chunkFilename should be a string.
* options.chunkFilename should be a non-empty string.
* options.chunkFilename should be an instance of function."
`;

Expand Down
2 changes: 1 addition & 1 deletion test/validate-plugin-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("validate options", () => {
},
chunkFilename: {
success: ["[id].css", ({ chunk }) => `${chunk.id}.${chunk.name}.css`],
failure: [true],
failure: [true, "/styles/[id].css"],
},
ignoreOrder: {
success: [true, false],
Expand Down

0 comments on commit fd8e0aa

Please sign in to comment.