Skip to content

Commit

Permalink
refactor: code (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Nov 9, 2020
1 parent bd60650 commit 895fe61
Show file tree
Hide file tree
Showing 9 changed files with 954 additions and 483 deletions.
1,388 changes: 920 additions & 468 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@
"@gfx/zopfli": "^1.0.15",
"@webpack-contrib/defaults": "^6.3.0",
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-jest": "^26.6.1",
"babel-jest": "^26.6.3",
"cross-env": "^7.0.2",
"del": "^6.0.0",
"del-cli": "^3.0.1",
"eslint": "^7.12.1",
"eslint": "^7.13.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-import": "^2.22.1",
"file-loader": "^6.2.0",
"husky": "^4.3.0",
"jest": "^26.6.1",
"jest": "^26.6.3",
"lint-staged": "^10.5.1",
"memfs": "^3.2.0",
"npm-run-all": "^4.1.5",
Expand Down
1 change: 0 additions & 1 deletion src/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
"type": "boolean"
},
{
"type": "string",
"enum": ["keep-source-map"]
}
]
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/deleteOriginalAssets.test.js.snap.webpack4
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`"deleteOriginalAssets" option should delete original assets and keep source maps with option 'keep-source-map': assets 1`] = `
exports[`"deleteOriginalAssets" option should delete original assets and keep source maps with option "keep-source-map": assets 1`] = `
Array [
Array [
"09a1a1112c577c2794359715edfcb5ac.png",
Expand Down Expand Up @@ -29,9 +29,9 @@ Array [
]
`;

exports[`"deleteOriginalAssets" option should delete original assets and keep source maps with option 'keep-source-map': errors 1`] = `Array []`;
exports[`"deleteOriginalAssets" option should delete original assets and keep source maps with option "keep-source-map": errors 1`] = `Array []`;

exports[`"deleteOriginalAssets" option should delete original assets and keep source maps with option 'keep-source-map': warnings 1`] = `Array []`;
exports[`"deleteOriginalAssets" option should delete original assets and keep source maps with option "keep-source-map": warnings 1`] = `Array []`;

exports[`"deleteOriginalAssets" option should work and delete original assets: assets 1`] = `
Array [
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/deleteOriginalAssets.test.js.snap.webpack5
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`"deleteOriginalAssets" option should delete original assets and keep source maps with option 'keep-source-map': assets 1`] = `
exports[`"deleteOriginalAssets" option should delete original assets and keep source maps with option "keep-source-map": assets 1`] = `
Array [
Array [
"09a1a1112c577c2794359715edfcb5ac.png",
Expand All @@ -25,9 +25,9 @@ Array [
]
`;

exports[`"deleteOriginalAssets" option should delete original assets and keep source maps with option 'keep-source-map': errors 1`] = `Array []`;
exports[`"deleteOriginalAssets" option should delete original assets and keep source maps with option "keep-source-map": errors 1`] = `Array []`;

exports[`"deleteOriginalAssets" option should delete original assets and keep source maps with option 'keep-source-map': warnings 1`] = `Array []`;
exports[`"deleteOriginalAssets" option should delete original assets and keep source maps with option "keep-source-map": warnings 1`] = `Array []`;

exports[`"deleteOriginalAssets" option should work and delete original assets: assets 1`] = `
Array [
Expand Down
10 changes: 10 additions & 0 deletions test/__snapshots__/validate-options.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ exports[`validate options should throw an error on the "deleteOriginalAssets" op
* options.deleteOriginalAssets should be \\"keep-source-map\\"."
`;

exports[`validate options should throw an error on the "deleteOriginalAssets" option with "unknown" value 1`] = `
"Invalid options object. Compression Plugin has been initialized using an options object that does not match the API schema.
- options.deleteOriginalAssets should be one of these:
boolean | \\"keep-source-map\\"
-> Whether to delete the original assets or not.
Details:
* options.deleteOriginalAssets should be a boolean.
* options.deleteOriginalAssets should be \\"keep-source-map\\"."
`;

exports[`validate options should throw an error on the "exclude" option with "[{},"foo",true]" value 1`] = `
"Invalid options object. Compression Plugin has been initialized using an options object that does not match the API schema.
- options.exclude should be one of these:
Expand Down
10 changes: 10 additions & 0 deletions test/__snapshots__/validate-options.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ exports[`validate options should throw an error on the "deleteOriginalAssets" op
* options.deleteOriginalAssets should be \\"keep-source-map\\"."
`;

exports[`validate options should throw an error on the "deleteOriginalAssets" option with "unknown" value 1`] = `
"Invalid options object. Compression Plugin has been initialized using an options object that does not match the API schema.
- options.deleteOriginalAssets should be one of these:
boolean | \\"keep-source-map\\"
-> Whether to delete the original assets or not.
Details:
* options.deleteOriginalAssets should be a boolean.
* options.deleteOriginalAssets should be \\"keep-source-map\\"."
`;

exports[`validate options should throw an error on the "exclude" option with "[{},"foo",true]" value 1`] = `
"Invalid options object. Compression Plugin has been initialized using an options object that does not match the API schema.
- options.exclude should be one of these:
Expand Down
6 changes: 3 additions & 3 deletions test/deleteOriginalAssets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('"deleteOriginalAssets" option', () => {
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it(`should delete original assets and keep source maps with option 'keep-source-map'`, async () => {
it('should delete original assets and keep source maps with option "keep-source-map"', async () => {
compiler = getCompiler(
'./entry.js',
{},
Expand All @@ -95,8 +95,8 @@ describe('"deleteOriginalAssets" option', () => {
);

new CompressionPlugin({
filename: '[file]',
exclude: /.map$/,
filename: '[path][base]',
exclude: /\.map$/,
deleteOriginalAssets: 'keep-source-map',
}).apply(compiler);

Expand Down
4 changes: 2 additions & 2 deletions test/validate-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ describe('validate options', () => {
failure: [() => {}],
},
deleteOriginalAssets: {
success: [true, false],
failure: ['true'],
success: [true, false, 'keep-source-map'],
failure: ['true', 'unknown'],
},
unknown: {
success: [],
Expand Down

0 comments on commit 895fe61

Please sign in to comment.