Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 057411d

Browse files
alan-agius4filipesilva
authored andcommittedJun 9, 2020
fix(@angular-devkit/build-angular): update copy-webpack-plugin to version 6
Fixes #17858
1 parent 09b446f commit 057411d

File tree

6 files changed

+190
-79
lines changed

6 files changed

+190
-79
lines changed
 

‎integration/angular_cli/yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
cacache "15.0.0"
3333
caniuse-lite "^1.0.30001032"
3434
circular-dependency-plugin "5.2.0"
35-
copy-webpack-plugin "5.1.1"
35+
copy-webpack-plugin "6.0.1"
3636
core-js "3.6.4"
3737
cssnano "4.1.10"
3838
file-loader "6.0.0"

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"@types/babel__template": "7.0.2",
9898
"@types/browserslist": "^4.4.0",
9999
"@types/caniuse-lite": "^1.0.0",
100-
"@types/copy-webpack-plugin": "^5.0.0",
100+
"@types/copy-webpack-plugin": "^6.0.0",
101101
"@types/cssnano": "^4.0.0",
102102
"@types/debug": "^4.1.2",
103103
"@types/express": "^4.16.0",
@@ -136,7 +136,7 @@
136136
"common-tags": "^1.8.0",
137137
"conventional-changelog": "^3.0.0",
138138
"conventional-commits-parser": "^3.0.0",
139-
"copy-webpack-plugin": "5.1.1",
139+
"copy-webpack-plugin": "6.0.2",
140140
"core-js": "3.6.4",
141141
"css-loader": "3.5.2",
142142
"cssnano": "4.1.10",

‎packages/angular_devkit/build_angular/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"cacache": "15.0.3",
2727
"caniuse-lite": "^1.0.30001032",
2828
"circular-dependency-plugin": "5.2.0",
29-
"copy-webpack-plugin": "5.1.1",
29+
"copy-webpack-plugin": "6.0.2",
3030
"core-js": "3.6.4",
3131
"css-loader": "3.5.3",
3232
"cssnano": "4.1.10",

‎packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts

+25-19
Original file line numberDiff line numberDiff line change
@@ -255,34 +255,40 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
255255
if (buildOptions.assets.length) {
256256
const copyWebpackPluginPatterns = buildOptions.assets.map((asset: AssetPatternClass) => {
257257
// Resolve input paths relative to workspace root and add slash at the end.
258-
asset.input = path.resolve(root, asset.input).replace(/\\/g, '/');
259-
asset.input = asset.input.endsWith('/') ? asset.input : asset.input + '/';
260-
asset.output = asset.output.endsWith('/') ? asset.output : asset.output + '/';
261-
262-
if (asset.output.startsWith('..')) {
263-
const message = 'An asset cannot be written to a location outside of the output path.';
264-
throw new Error(message);
258+
// tslint:disable-next-line: prefer-const
259+
let { input, output, ignore = [], glob } = asset;
260+
input = path.resolve(root, input).replace(/\\/g, '/');
261+
input = input.endsWith('/') ? input : input + '/';
262+
output = output.endsWith('/') ? output : output + '/';
263+
264+
if (output.startsWith('..')) {
265+
throw new Error('An asset cannot be written to a location outside of the output path.');
265266
}
266267

267268
return {
268-
context: asset.input,
269+
context: input,
269270
// Now we remove starting slash to make Webpack place it from the output root.
270-
to: asset.output.replace(/^\//, ''),
271-
ignore: asset.ignore,
272-
from: {
273-
glob: asset.glob,
271+
to: output.replace(/^\//, ''),
272+
from: glob,
273+
noErrorOnMissing: true,
274+
globOptions: {
274275
dot: true,
276+
ignore: [
277+
'.gitkeep',
278+
'**/.DS_Store',
279+
'**/Thumbs.db',
280+
// Negate patterns needs to be absolute because copy-webpack-plugin uses absolute globs which
281+
// causes negate patterns not to match.
282+
// See: https://github.com/webpack-contrib/copy-webpack-plugin/issues/498#issuecomment-639327909
283+
...ignore,
284+
].map(i => path.posix.join(input, i)),
275285
},
276286
};
277287
});
278288

279-
const copyWebpackPluginOptions = { ignore: ['.gitkeep', '**/.DS_Store', '**/Thumbs.db'] };
280-
281-
const copyWebpackPluginInstance = new CopyWebpackPlugin(
282-
copyWebpackPluginPatterns,
283-
copyWebpackPluginOptions,
284-
);
285-
extraPlugins.push(copyWebpackPluginInstance);
289+
extraPlugins.push(new CopyWebpackPlugin({
290+
patterns: copyWebpackPluginPatterns,
291+
}));
286292
}
287293

288294
if (buildOptions.progress) {

‎packages/angular_devkit/build_angular/src/browser/specs/assets_spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ describe('Browser Builder assets', () => {
9494
const output = await run.result as BrowserBuilderOutput;
9595
expect(output.success).toBe(true);
9696

97-
expect(host.scopedSync().exists(normalize('./dist/folder/asset.txt'))).toBe(true);
98-
expect(host.scopedSync().exists(normalize('./dist/folder/asset-ignored.txt'))).toBe(false);
99-
expect(host.scopedSync().exists(normalize('./dist/folder/.gitkeep'))).toBe(false);
97+
expect(host.scopedSync().exists(normalize('./dist/folder/asset.txt'))).toBe(true, `asset.txt doesn't exist.`);
98+
expect(host.scopedSync().exists(normalize('./dist/folder/asset-ignored.txt'))).toBe(false, 'asset-ignored.txt exists.');
99+
expect(host.scopedSync().exists(normalize('./dist/folder/.gitkeep'))).toBe(false, '.gitkeep exists.');
100100

101101
await run.stop();
102102
});

0 commit comments

Comments
 (0)
Please sign in to comment.