Skip to content

Commit a8ecbc8

Browse files
alan-agius4filipesilva
authored andcommittedJun 8, 2020
fix(@angular-devkit/build-angular): update copy-webpack-plugin to version 6
Fixes #17858
1 parent b908a07 commit a8ecbc8

File tree

5 files changed

+233
-81
lines changed

5 files changed

+233
-81
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"@types/babel__core": "7.1.6",
7878
"@types/browserslist": "^4.4.0",
7979
"@types/caniuse-lite": "^1.0.0",
80-
"@types/copy-webpack-plugin": "^5.0.0",
80+
"@types/copy-webpack-plugin": "^6.0.0",
8181
"@types/cssnano": "^4.0.0",
8282
"@types/debug": "^4.1.2",
8383
"@types/express": "^4.16.0",

‎packages/angular_devkit/build_angular/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"cacache": "15.0.0",
2525
"caniuse-lite": "^1.0.30001032",
2626
"circular-dependency-plugin": "5.2.0",
27-
"copy-webpack-plugin": "5.1.1",
27+
"copy-webpack-plugin": "6.0.2",
2828
"core-js": "3.6.4",
2929
"css-loader": "3.5.1",
3030
"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
@@ -254,34 +254,40 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
254254
if (buildOptions.assets.length) {
255255
const copyWebpackPluginPatterns = buildOptions.assets.map((asset: AssetPatternClass) => {
256256
// Resolve input paths relative to workspace root and add slash at the end.
257-
asset.input = path.resolve(root, asset.input).replace(/\\/g, '/');
258-
asset.input = asset.input.endsWith('/') ? asset.input : asset.input + '/';
259-
asset.output = asset.output.endsWith('/') ? asset.output : asset.output + '/';
260-
261-
if (asset.output.startsWith('..')) {
262-
const message = 'An asset cannot be written to a location outside of the output path.';
263-
throw new Error(message);
257+
// tslint:disable-next-line: prefer-const
258+
let { input, output, ignore = [], glob } = asset;
259+
input = path.resolve(root, input).replace(/\\/g, '/');
260+
input = input.endsWith('/') ? input : input + '/';
261+
output = output.endsWith('/') ? output : output + '/';
262+
263+
if (output.startsWith('..')) {
264+
throw new Error('An asset cannot be written to a location outside of the output path.');
264265
}
265266

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

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

287293
if (buildOptions.progress) {

‎packages/angular_devkit/build_angular/test/browser/assets_spec_large.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.