From a5b54cd09edcd125c1cf5d7145adcf166346d919 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Thu, 22 Oct 2020 15:43:08 +0300 Subject: [PATCH 01/10] feat: added `sourceFilename` with original file to asset info --- src/index.js | 17 ++-- test/CopyPlugin.test.js | 100 +++++++++++++++++++++ test/__snapshots__/CopyPlugin.test.js.snap | 87 ++++++++++++++++++ 3 files changed, 199 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 9ece267a..a14bbf87 100644 --- a/src/index.js +++ b/src/index.js @@ -99,12 +99,13 @@ class CopyPlugin { pattern.to = path.normalize( typeof pattern.to !== 'undefined' ? pattern.to : '' ); + pattern.compilerContext = compiler.context; pattern.context = path.normalize( typeof pattern.context !== 'undefined' ? !path.isAbsolute(pattern.context) - ? path.join(compiler.options.context, pattern.context) + ? path.join(pattern.compilerContext, pattern.context) : pattern.context - : compiler.options.context + : pattern.compilerContext ); logger.debug(`processing from "${pattern.from}" to "${pattern.to}"`); @@ -303,7 +304,12 @@ class CopyPlugin { logger.log(`determined that "${from}" should write to "${webpackTo}"`); - return { absoluteFrom, relativeFrom, webpackTo }; + const sourceFilename = path.relative( + pattern.compilerContext, + absoluteFrom + ); + + return { absoluteFrom, sourceFilename, relativeFrom, webpackTo }; }); return Promise.all( @@ -527,6 +533,7 @@ class CopyPlugin { .filter(Boolean) .forEach((asset) => { const { + sourceFilename, absoluteFrom, targetPath, webpackTo, @@ -551,7 +558,7 @@ class CopyPlugin { `force updating "${webpackTo}" to compilation assets from "${absoluteFrom}"` ); - const info = { copied: true }; + const info = { copied: true, sourceFilename }; if (asset.immutable) { info.immutable = true; @@ -573,7 +580,7 @@ class CopyPlugin { `writing "${webpackTo}" to compilation assets from "${absoluteFrom}"` ); - const info = { copied: true }; + const info = { copied: true, sourceFilename }; if (asset.immutable) { info.immutable = true; diff --git a/test/CopyPlugin.test.js b/test/CopyPlugin.test.js index 898f0607..cb025ec5 100644 --- a/test/CopyPlugin.test.js +++ b/test/CopyPlugin.test.js @@ -2,6 +2,7 @@ import path from 'path'; import webpack from 'webpack'; import del from 'del'; +import { createFsFromVolume, Volume } from 'memfs'; import CopyPlugin from '../src'; @@ -380,6 +381,70 @@ describe('CopyPlugin', () => { .then(done) .catch(done); }); + + it('should work with multi compiler mode', async () => { + const compiler = webpack([ + { + mode: 'development', + context: path.resolve(__dirname, './fixtures'), + entry: path.resolve(__dirname, './helpers/enter.js'), + output: { + path: path.resolve(__dirname, './outputs/multi-compiler/dist/a'), + }, + stats: { + source: true, + }, + plugins: [ + new CopyPlugin({ + patterns: [ + { + from: path.resolve(__dirname, './fixtures/directory'), + }, + ], + }), + ], + }, + { + mode: 'development', + entry: path.resolve(__dirname, './helpers/enter.js'), + output: { + path: path.resolve(__dirname, './outputs/multi-compiler/dist/b'), + }, + stats: { + source: true, + }, + plugins: [ + new CopyPlugin({ + patterns: [ + { + context: path.resolve(__dirname, './fixtures'), + from: path.resolve(__dirname, './fixtures/directory'), + }, + ], + }), + ], + }, + ]); + + compiler.compilers.forEach((item) => { + const outputFileSystem = createFsFromVolume(new Volume()); + // Todo remove when we drop webpack@4 support + outputFileSystem.join = path.join.bind(path); + + // eslint-disable-next-line no-param-reassign + item.outputFileSystem = outputFileSystem; + }); + + const { stats } = await compile(compiler); + + stats.stats.forEach((item, index) => { + expect(item.compilation.errors).toMatchSnapshot('errors'); + expect(item.compilation.warnings).toMatchSnapshot('warnings'); + expect(readAssets(compiler.compilers[index], item)).toMatchSnapshot( + 'assets' + ); + }); + }); }); describe('watch mode', () => { @@ -747,6 +812,41 @@ describe('CopyPlugin', () => { }); }); + describe('stats', () => { + it('should work have assets info', async () => { + const compiler = getCompiler(); + + new CopyPlugin({ + patterns: [ + { + from: path.resolve(__dirname, './fixtures/directory'), + }, + ], + }).apply(compiler); + + const { stats } = await compile(compiler); + + expect(stats.compilation.warnings).toMatchSnapshot('warnings'); + expect(stats.compilation.errors).toMatchSnapshot('errors'); + expect(readAssets(compiler, stats)).toMatchSnapshot('assets'); + + const assetsInfo = []; + + for (const [name, info] of stats.compilation.assetsInfo.entries()) { + assetsInfo.push({ + name, + info: { + immutable: info.immutable, + copied: info.copied, + sourceFilename: info.sourceFilename, + }, + }); + } + + expect(assetsInfo).toMatchSnapshot('assets info'); + }); + }); + describe('logging', () => { it('should logging when "from" is a file', (done) => { const expectedAssetKeys = ['file.txt']; diff --git a/test/__snapshots__/CopyPlugin.test.js.snap b/test/__snapshots__/CopyPlugin.test.js.snap index 9f77923e..2945161f 100644 --- a/test/__snapshots__/CopyPlugin.test.js.snap +++ b/test/__snapshots__/CopyPlugin.test.js.snap @@ -1,5 +1,33 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`CopyPlugin basic should work with multi compiler mode: assets 1`] = ` +Object { + ".dottedfile": "dottedfile contents +", + "directoryfile.txt": "new", + "nested/deep-nested/deepnested.txt": "", + "nested/nestedfile.txt": "", +} +`; + +exports[`CopyPlugin basic should work with multi compiler mode: assets 2`] = ` +Object { + ".dottedfile": "dottedfile contents +", + "directoryfile.txt": "new", + "nested/deep-nested/deepnested.txt": "", + "nested/nestedfile.txt": "", +} +`; + +exports[`CopyPlugin basic should work with multi compiler mode: errors 1`] = `Array []`; + +exports[`CopyPlugin basic should work with multi compiler mode: errors 2`] = `Array []`; + +exports[`CopyPlugin basic should work with multi compiler mode: warnings 1`] = `Array []`; + +exports[`CopyPlugin basic should work with multi compiler mode: warnings 2`] = `Array []`; + exports[`CopyPlugin cache should work with the "filesystem" cache: assets 1`] = ` Object { ".dottedfile": "dottedfile contents @@ -132,3 +160,62 @@ Object { ], } `; + +exports[`CopyPlugin stats should work have assets info: assets 1`] = ` +Object { + ".dottedfile": "dottedfile contents +", + "directoryfile.txt": "new", + "nested/deep-nested/deepnested.txt": "", + "nested/nestedfile.txt": "", +} +`; + +exports[`CopyPlugin stats should work have assets info: assets info 1`] = ` +Array [ + Object { + "info": Object { + "copied": undefined, + "immutable": undefined, + "sourceFilename": undefined, + }, + "name": "main.js", + }, + Object { + "info": Object { + "copied": true, + "immutable": undefined, + "sourceFilename": "directory/.dottedfile", + }, + "name": ".dottedfile", + }, + Object { + "info": Object { + "copied": true, + "immutable": undefined, + "sourceFilename": "directory/directoryfile.txt", + }, + "name": "directoryfile.txt", + }, + Object { + "info": Object { + "copied": true, + "immutable": undefined, + "sourceFilename": "directory/nested/nestedfile.txt", + }, + "name": "nested/nestedfile.txt", + }, + Object { + "info": Object { + "copied": true, + "immutable": undefined, + "sourceFilename": "directory/nested/deep-nested/deepnested.txt", + }, + "name": "nested/deep-nested/deepnested.txt", + }, +] +`; + +exports[`CopyPlugin stats should work have assets info: errors 1`] = `Array []`; + +exports[`CopyPlugin stats should work have assets info: warnings 1`] = `Array []`; From 7ef0b2e4eb3a604c5cf91641c629541f99df2cae Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Thu, 22 Oct 2020 16:07:53 +0300 Subject: [PATCH 02/10] test: more --- .github/workflows/nodejs.yml | 4 ++-- package-lock.json | 5 ++--- package.json | 2 +- test/CopyPlugin.test.js | 4 +++- test/__snapshots__/CopyPlugin.test.js.snap | 9 +++++++++ test/helpers/enter-with-asset-modules.js | 3 +++ test/helpers/getCompiler.js | 8 ++++++++ 7 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 test/helpers/enter-with-asset-modules.js diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index acfca4f1..01617136 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -83,8 +83,8 @@ jobs: - name: Install dependencies run: npm ci - - name: Install webpack ${{ matrix.webpack-version }} - run: npm i webpack@${{ matrix.webpack-version }} + # - name: Install webpack ${{ matrix.webpack-version }} + # run: npm i webpack@${{ matrix.webpack-version }} - name: Run tests for webpack version ${{ matrix.webpack-version }} run: npm run test:coverage -- --ci diff --git a/package-lock.json b/package-lock.json index 24afd90e..95fa5d22 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12240,9 +12240,8 @@ "dev": true }, "webpack": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.1.3.tgz", - "integrity": "sha512-bNBF5EOpt5a6NeCBFu0+8KJtG61cVmOb2b/a5tPNRLz3OWgDpHMbmnDkaSm3nf/UQ6ufw4PWYGVsVOAi8UfL2A==", + "version": "github:webpack/webpack#4d0db65e6409bbac90378c8104f0846c9c4e73a6", + "from": "github:webpack/webpack#master", "dev": true, "requires": { "@types/eslint-scope": "^3.7.0", diff --git a/package.json b/package.json index 42c31d58..d34b8046 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "npm-run-all": "^4.1.5", "prettier": "^2.1.2", "standard-version": "^9.0.0", - "webpack": "^5.1.3" + "webpack": "webpack/webpack#master" }, "keywords": [ "webpack", diff --git a/test/CopyPlugin.test.js b/test/CopyPlugin.test.js index cb025ec5..6097e116 100644 --- a/test/CopyPlugin.test.js +++ b/test/CopyPlugin.test.js @@ -814,7 +814,9 @@ describe('CopyPlugin', () => { describe('stats', () => { it('should work have assets info', async () => { - const compiler = getCompiler(); + const compiler = getCompiler({ + entry: path.resolve(__dirname, './helpers/enter-with-asset-modules.js'), + }); new CopyPlugin({ patterns: [ diff --git a/test/__snapshots__/CopyPlugin.test.js.snap b/test/__snapshots__/CopyPlugin.test.js.snap index 2945161f..bbaf84a6 100644 --- a/test/__snapshots__/CopyPlugin.test.js.snap +++ b/test/__snapshots__/CopyPlugin.test.js.snap @@ -165,6 +165,7 @@ exports[`CopyPlugin stats should work have assets info: assets 1`] = ` Object { ".dottedfile": "dottedfile contents ", + "31d6cfe0d16ae931b73c.txt": "", "directoryfile.txt": "new", "nested/deep-nested/deepnested.txt": "", "nested/nestedfile.txt": "", @@ -181,6 +182,14 @@ Array [ }, "name": "main.js", }, + Object { + "info": Object { + "copied": undefined, + "immutable": true, + "sourceFilename": "directory/nested/deep-nested/deepnested.txt", + }, + "name": "31d6cfe0d16ae931b73c.txt", + }, Object { "info": Object { "copied": true, diff --git a/test/helpers/enter-with-asset-modules.js b/test/helpers/enter-with-asset-modules.js new file mode 100644 index 00000000..a2bb5b30 --- /dev/null +++ b/test/helpers/enter-with-asset-modules.js @@ -0,0 +1,3 @@ +import txtURL from '../fixtures/directory/nested/deep-nested/deepnested.txt'; + +export default txtURL; diff --git a/test/helpers/getCompiler.js b/test/helpers/getCompiler.js index 242e970b..a4f11f48 100644 --- a/test/helpers/getCompiler.js +++ b/test/helpers/getCompiler.js @@ -11,6 +11,14 @@ export default (config = {}) => { output: { path: path.resolve(__dirname, '../build'), }, + module: { + rules: [ + { + test: /\.txt/, + type: 'asset/resource', + }, + ], + }, ...config, }; From cb6425b657293ecf19bab28c60627e0239ad7cb0 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Thu, 22 Oct 2020 16:14:48 +0300 Subject: [PATCH 03/10] test: debug --- test/CopyPlugin.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/CopyPlugin.test.js b/test/CopyPlugin.test.js index 6097e116..d0e85989 100644 --- a/test/CopyPlugin.test.js +++ b/test/CopyPlugin.test.js @@ -834,6 +834,9 @@ describe('CopyPlugin', () => { const assetsInfo = []; + // eslint-disable-next-line no-console + console.log(stats.compilation.assetsInfo); + for (const [name, info] of stats.compilation.assetsInfo.entries()) { assetsInfo.push({ name, From 4fea45793b9e4247e29ddccf5ef6cdeb9483ed4a Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Thu, 22 Oct 2020 16:19:48 +0300 Subject: [PATCH 04/10] test: debug --- .github/workflows/nodejs.yml | 4 ++-- package-lock.json | 4 ++-- package.json | 2 +- src/index.js | 5 ++--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 01617136..acfca4f1 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -83,8 +83,8 @@ jobs: - name: Install dependencies run: npm ci - # - name: Install webpack ${{ matrix.webpack-version }} - # run: npm i webpack@${{ matrix.webpack-version }} + - name: Install webpack ${{ matrix.webpack-version }} + run: npm i webpack@${{ matrix.webpack-version }} - name: Run tests for webpack version ${{ matrix.webpack-version }} run: npm run test:coverage -- --ci diff --git a/package-lock.json b/package-lock.json index 95fa5d22..807b6634 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12240,8 +12240,8 @@ "dev": true }, "webpack": { - "version": "github:webpack/webpack#4d0db65e6409bbac90378c8104f0846c9c4e73a6", - "from": "github:webpack/webpack#master", + "version": "5.1.3", + "resolved": "github:webpack/webpack#4d0db65e6409bbac90378c8104f0846c9c4e73a6", "dev": true, "requires": { "@types/eslint-scope": "^3.7.0", diff --git a/package.json b/package.json index d34b8046..42c31d58 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "npm-run-all": "^4.1.5", "prettier": "^2.1.2", "standard-version": "^9.0.0", - "webpack": "webpack/webpack#master" + "webpack": "^5.1.3" }, "keywords": [ "webpack", diff --git a/src/index.js b/src/index.js index a14bbf87..407f8204 100644 --- a/src/index.js +++ b/src/index.js @@ -304,9 +304,8 @@ class CopyPlugin { logger.log(`determined that "${from}" should write to "${webpackTo}"`); - const sourceFilename = path.relative( - pattern.compilerContext, - absoluteFrom + const sourceFilename = normalizePath( + path.relative(pattern.compilerContext, absoluteFrom) ); return { absoluteFrom, sourceFilename, relativeFrom, webpackTo }; From a0ba76a953127b3d2485d3d756b1f475fd357167 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Thu, 22 Oct 2020 16:28:30 +0300 Subject: [PATCH 05/10] test: fix --- test/CopyPlugin.test.js | 17 +++++++++--- test/__snapshots__/CopyPlugin.test.js.snap | 32 +++++++++++----------- test/helpers/getCompiler.js | 20 ++++++++------ 3 files changed, 41 insertions(+), 28 deletions(-) diff --git a/test/CopyPlugin.test.js b/test/CopyPlugin.test.js index d0e85989..905ce415 100644 --- a/test/CopyPlugin.test.js +++ b/test/CopyPlugin.test.js @@ -834,9 +834,6 @@ describe('CopyPlugin', () => { const assetsInfo = []; - // eslint-disable-next-line no-console - console.log(stats.compilation.assetsInfo); - for (const [name, info] of stats.compilation.assetsInfo.entries()) { assetsInfo.push({ name, @@ -848,7 +845,19 @@ describe('CopyPlugin', () => { }); } - expect(assetsInfo).toMatchSnapshot('assets info'); + expect( + assetsInfo.sort((a, b) => { + if (a.name < b.name) { + return -1; + } + + if (a.name > b.name) { + return 1; + } + + return 0; + }) + ).toMatchSnapshot('assets info'); }); }); diff --git a/test/__snapshots__/CopyPlugin.test.js.snap b/test/__snapshots__/CopyPlugin.test.js.snap index bbaf84a6..e9da952c 100644 --- a/test/__snapshots__/CopyPlugin.test.js.snap +++ b/test/__snapshots__/CopyPlugin.test.js.snap @@ -165,7 +165,7 @@ exports[`CopyPlugin stats should work have assets info: assets 1`] = ` Object { ".dottedfile": "dottedfile contents ", - "31d6cfe0d16ae931b73c.txt": "", + "assets/deepnested.txt": "", "directoryfile.txt": "new", "nested/deep-nested/deepnested.txt": "", "nested/nestedfile.txt": "", @@ -176,51 +176,51 @@ exports[`CopyPlugin stats should work have assets info: assets info 1`] = ` Array [ Object { "info": Object { - "copied": undefined, + "copied": true, "immutable": undefined, - "sourceFilename": undefined, + "sourceFilename": "directory/.dottedfile", }, - "name": "main.js", + "name": ".dottedfile", }, Object { "info": Object { "copied": undefined, - "immutable": true, - "sourceFilename": "directory/nested/deep-nested/deepnested.txt", + "immutable": false, + "sourceFilename": undefined, }, - "name": "31d6cfe0d16ae931b73c.txt", + "name": "assets/deepnested.txt", }, Object { "info": Object { "copied": true, "immutable": undefined, - "sourceFilename": "directory/.dottedfile", + "sourceFilename": "directory/directoryfile.txt", }, - "name": ".dottedfile", + "name": "directoryfile.txt", }, Object { "info": Object { - "copied": true, + "copied": undefined, "immutable": undefined, - "sourceFilename": "directory/directoryfile.txt", + "sourceFilename": undefined, }, - "name": "directoryfile.txt", + "name": "main.js", }, Object { "info": Object { "copied": true, "immutable": undefined, - "sourceFilename": "directory/nested/nestedfile.txt", + "sourceFilename": "directory/nested/deep-nested/deepnested.txt", }, - "name": "nested/nestedfile.txt", + "name": "nested/deep-nested/deepnested.txt", }, Object { "info": Object { "copied": true, "immutable": undefined, - "sourceFilename": "directory/nested/deep-nested/deepnested.txt", + "sourceFilename": "directory/nested/nestedfile.txt", }, - "name": "nested/deep-nested/deepnested.txt", + "name": "nested/nestedfile.txt", }, ] `; diff --git a/test/helpers/getCompiler.js b/test/helpers/getCompiler.js index a4f11f48..4c440446 100644 --- a/test/helpers/getCompiler.js +++ b/test/helpers/getCompiler.js @@ -13,19 +13,23 @@ export default (config = {}) => { }, module: { rules: [ - { - test: /\.txt/, - type: 'asset/resource', - }, + webpack.version[0] === '5' + ? { + test: /\.txt/, + type: 'asset/resource', + } + : { + test: /\.txt/, + loader: 'file-loader', + options: { + name: 'assets/[name].[ext]', + }, + }, ], }, ...config, }; - if (webpack.version[0] === 5) { - fullConfig.stats.source = true; - } - const compiler = webpack(fullConfig); if (!config.outputFileSystem) { From 66653d31a3babd687aa90cf7e34d5e5d5785e014 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Thu, 22 Oct 2020 16:31:06 +0300 Subject: [PATCH 06/10] test: fix --- package-lock.json | 12 +++++++++++- package.json | 1 + test/__snapshots__/CopyPlugin.test.js.snap | 6 +++--- test/helpers/getCompiler.js | 5 ++++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 807b6634..d4d1229c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5976,6 +5976,15 @@ "flat-cache": "^2.0.1" } }, + "file-loader": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/file-loader/-/file-loader-6.1.1.tgz", + "integrity": "sha512-Klt8C4BjWSXYQAfhpYYkG4qHNTna4toMHEbWrI5IuVoxbU6uiDKeKAP99R8mmbJi3lvewn/jQBOgU4+NS3tDQw==", + "requires": { + "loader-utils": "^2.0.0", + "schema-utils": "^3.0.0" + } + }, "file-uri-to-path": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", @@ -12241,7 +12250,8 @@ }, "webpack": { "version": "5.1.3", - "resolved": "github:webpack/webpack#4d0db65e6409bbac90378c8104f0846c9c4e73a6", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.1.3.tgz", + "integrity": "sha512-bNBF5EOpt5a6NeCBFu0+8KJtG61cVmOb2b/a5tPNRLz3OWgDpHMbmnDkaSm3nf/UQ6ufw4PWYGVsVOAi8UfL2A==", "dev": true, "requires": { "@types/eslint-scope": "^3.7.0", diff --git a/package.json b/package.json index 42c31d58..f8ebd7a3 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "dependencies": { "cacache": "^15.0.5", "fast-glob": "^3.2.4", + "file-loader": "^6.1.1", "find-cache-dir": "^3.3.1", "glob-parent": "^5.1.1", "globby": "^11.0.1", diff --git a/test/__snapshots__/CopyPlugin.test.js.snap b/test/__snapshots__/CopyPlugin.test.js.snap index e9da952c..e236d790 100644 --- a/test/__snapshots__/CopyPlugin.test.js.snap +++ b/test/__snapshots__/CopyPlugin.test.js.snap @@ -165,7 +165,7 @@ exports[`CopyPlugin stats should work have assets info: assets 1`] = ` Object { ".dottedfile": "dottedfile contents ", - "assets/deepnested.txt": "", + "asset-modules/deepnested.txt": "", "directoryfile.txt": "new", "nested/deep-nested/deepnested.txt": "", "nested/nestedfile.txt": "", @@ -185,10 +185,10 @@ Array [ Object { "info": Object { "copied": undefined, - "immutable": false, + "immutable": undefined, "sourceFilename": undefined, }, - "name": "assets/deepnested.txt", + "name": "asset-modules/deepnested.txt", }, Object { "info": Object { diff --git a/test/helpers/getCompiler.js b/test/helpers/getCompiler.js index 4c440446..fdccde90 100644 --- a/test/helpers/getCompiler.js +++ b/test/helpers/getCompiler.js @@ -17,12 +17,15 @@ export default (config = {}) => { ? { test: /\.txt/, type: 'asset/resource', + generator: { + filename: 'asset-modules/[name][ext]', + }, } : { test: /\.txt/, loader: 'file-loader', options: { - name: 'assets/[name].[ext]', + name: 'asset-modules/[name].[ext]', }, }, ], From eb9ae9137c91355d77ce2f05333296508950737f Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Thu, 22 Oct 2020 16:42:50 +0300 Subject: [PATCH 07/10] test: fix --- test/CopyPlugin.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/CopyPlugin.test.js b/test/CopyPlugin.test.js index 905ce415..3e6d2e3c 100644 --- a/test/CopyPlugin.test.js +++ b/test/CopyPlugin.test.js @@ -838,7 +838,9 @@ describe('CopyPlugin', () => { assetsInfo.push({ name, info: { - immutable: info.immutable, + // Workaround for `file-loader` + // eslint-disable-next-line no-undefined + immutable: info.immutable === false ? undefined : info.immutable, copied: info.copied, sourceFilename: info.sourceFilename, }, From 8847ef9f68df2b74f97bc35329c299b3c78196f8 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Thu, 22 Oct 2020 16:49:02 +0300 Subject: [PATCH 08/10] test: debug --- .github/workflows/nodejs.yml | 4 ++-- package-lock.json | 5 ++--- package.json | 2 +- test/__snapshots__/CopyPlugin.test.js.snap | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index acfca4f1..14e845ad 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -83,8 +83,8 @@ jobs: - name: Install dependencies run: npm ci - - name: Install webpack ${{ matrix.webpack-version }} - run: npm i webpack@${{ matrix.webpack-version }} + # - name: Install webpack ${{ matrix.webpack-version }} + # run: npm i webpack@${{ matrix.webpack-version }} - name: Run tests for webpack version ${{ matrix.webpack-version }} run: npm run test:coverage -- --ci diff --git a/package-lock.json b/package-lock.json index d4d1229c..8709abc2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12249,9 +12249,8 @@ "dev": true }, "webpack": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.1.3.tgz", - "integrity": "sha512-bNBF5EOpt5a6NeCBFu0+8KJtG61cVmOb2b/a5tPNRLz3OWgDpHMbmnDkaSm3nf/UQ6ufw4PWYGVsVOAi8UfL2A==", + "version": "github:webpack/webpack#4d0db65e6409bbac90378c8104f0846c9c4e73a6", + "from": "github:webpack/webpack#master", "dev": true, "requires": { "@types/eslint-scope": "^3.7.0", diff --git a/package.json b/package.json index f8ebd7a3..e8dda95c 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "npm-run-all": "^4.1.5", "prettier": "^2.1.2", "standard-version": "^9.0.0", - "webpack": "^5.1.3" + "webpack": "webpack/webpack#master" }, "keywords": [ "webpack", diff --git a/test/__snapshots__/CopyPlugin.test.js.snap b/test/__snapshots__/CopyPlugin.test.js.snap index e236d790..636b0181 100644 --- a/test/__snapshots__/CopyPlugin.test.js.snap +++ b/test/__snapshots__/CopyPlugin.test.js.snap @@ -186,7 +186,7 @@ Array [ "info": Object { "copied": undefined, "immutable": undefined, - "sourceFilename": undefined, + "sourceFilename": "directory/nested/deep-nested/deepnested.txt", }, "name": "asset-modules/deepnested.txt", }, From 2dd90548d9e3746615c7469166adcdccfa7c1ed8 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Thu, 22 Oct 2020 16:56:13 +0300 Subject: [PATCH 09/10] docs: improve --- .github/workflows/nodejs.yml | 4 ++-- README.md | 2 ++ package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 14e845ad..acfca4f1 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -83,8 +83,8 @@ jobs: - name: Install dependencies run: npm ci - # - name: Install webpack ${{ matrix.webpack-version }} - # run: npm i webpack@${{ matrix.webpack-version }} + - name: Install webpack ${{ matrix.webpack-version }} + run: npm i webpack@${{ matrix.webpack-version }} - name: Run tests for webpack version ${{ matrix.webpack-version }} run: npm run test:coverage -- --ci diff --git a/README.md b/README.md index f3a46706..81d995eb 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,8 @@ module.exports = { > ℹ️ If you want `webpack-dev-server` to write files to the output directory during development, you can force it with the [`writeToDisk`](https://github.com/webpack/webpack-dev-middleware#writetodisk) option or the [`write-file-webpack-plugin`](https://github.com/gajus/write-file-webpack-plugin). +> ℹ️ You can get the original source filename from [Asset Objects](https://webpack.js.org/api/stats/#asset-objects). + ## Options The plugin's signature: diff --git a/package-lock.json b/package-lock.json index 8709abc2..9fb628d4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12249,8 +12249,8 @@ "dev": true }, "webpack": { - "version": "github:webpack/webpack#4d0db65e6409bbac90378c8104f0846c9c4e73a6", - "from": "github:webpack/webpack#master", + "version": "5.1.3", + "resolved": "github:webpack/webpack#4d0db65e6409bbac90378c8104f0846c9c4e73a6", "dev": true, "requires": { "@types/eslint-scope": "^3.7.0", diff --git a/package.json b/package.json index e8dda95c..f8ebd7a3 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "npm-run-all": "^4.1.5", "prettier": "^2.1.2", "standard-version": "^9.0.0", - "webpack": "webpack/webpack#master" + "webpack": "^5.1.3" }, "keywords": [ "webpack", From 0deba94ce76dfe438e991dee3e6524239a3c11fe Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Thu, 22 Oct 2020 17:05:02 +0300 Subject: [PATCH 10/10] test: fix --- test/__snapshots__/CopyPlugin.test.js.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/__snapshots__/CopyPlugin.test.js.snap b/test/__snapshots__/CopyPlugin.test.js.snap index 636b0181..e236d790 100644 --- a/test/__snapshots__/CopyPlugin.test.js.snap +++ b/test/__snapshots__/CopyPlugin.test.js.snap @@ -186,7 +186,7 @@ Array [ "info": Object { "copied": undefined, "immutable": undefined, - "sourceFilename": "directory/nested/deep-nested/deepnested.txt", + "sourceFilename": undefined, }, "name": "asset-modules/deepnested.txt", },