Skip to content

Commit 1a8de6f

Browse files
alan-agius4filipesilva
authored andcommitted
fix(@angular-devkit/build-angular): update copy-webpack-plugin to version 6
Fixes #17858
1 parent 4c2e21a commit 1a8de6f

File tree

5 files changed

+388
-89
lines changed

5 files changed

+388
-89
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"@types/browserslist": "^4.4.0",
9292
"@types/caniuse-lite": "^1.0.0",
9393
"@types/clean-css": "^4.2.1",
94-
"@types/copy-webpack-plugin": "^4.4.1",
94+
"@types/copy-webpack-plugin": "^6.0.0",
9595
"@types/express": "^4.16.0",
9696
"@types/find-cache-dir": "^2.0.0",
9797
"@types/glob": "^7.0.0",

packages/angular_devkit/build_angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"circular-dependency-plugin": "5.2.0",
2323
"clean-css": "4.2.1",
2424
"coverage-istanbul-loader": "2.0.3",
25-
"copy-webpack-plugin": "5.1.1",
25+
"copy-webpack-plugin": "6.0.2",
2626
"core-js": "3.6.4",
2727
"file-loader": "4.2.0",
2828
"find-cache-dir": "3.0.0",

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

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -194,37 +194,43 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
194194
}
195195

196196
// process asset entries
197-
if (buildOptions.assets) {
197+
if (buildOptions.assets.length) {
198198
const copyWebpackPluginPatterns = buildOptions.assets.map((asset: AssetPatternClass) => {
199199
// Resolve input paths relative to workspace root and add slash at the end.
200-
asset.input = path.resolve(root, asset.input).replace(/\\/g, '/');
201-
asset.input = asset.input.endsWith('/') ? asset.input : asset.input + '/';
202-
asset.output = asset.output.endsWith('/') ? asset.output : asset.output + '/';
203-
204-
if (asset.output.startsWith('..')) {
205-
const message = 'An asset cannot be written to a location outside of the output path.';
206-
throw new Error(message);
200+
// tslint:disable-next-line: prefer-const
201+
let { input, output, ignore = [], glob } = asset;
202+
input = path.resolve(root, input).replace(/\\/g, '/');
203+
input = input.endsWith('/') ? input : input + '/';
204+
output = output.endsWith('/') ? output : output + '/';
205+
206+
if (output.startsWith('..')) {
207+
throw new Error('An asset cannot be written to a location outside of the output path.');
207208
}
208209

209210
return {
210-
context: asset.input,
211+
context: input,
211212
// Now we remove starting slash to make Webpack place it from the output root.
212-
to: asset.output.replace(/^\//, ''),
213-
ignore: asset.ignore,
214-
from: {
215-
glob: asset.glob,
213+
to: output.replace(/^\//, ''),
214+
from: glob,
215+
noErrorOnMissing: true,
216+
globOptions: {
216217
dot: true,
218+
ignore: [
219+
'.gitkeep',
220+
'**/.DS_Store',
221+
'**/Thumbs.db',
222+
// Negate patterns needs to be absolute because copy-webpack-plugin uses absolute globs which
223+
// causes negate patterns not to match.
224+
// See: https://github.com/webpack-contrib/copy-webpack-plugin/issues/498#issuecomment-639327909
225+
...ignore,
226+
].map(i => path.posix.join(input, i)),
217227
},
218228
};
219229
});
220230

221-
const copyWebpackPluginOptions = { ignore: ['.gitkeep', '**/.DS_Store', '**/Thumbs.db'] };
222-
223-
const copyWebpackPluginInstance = new CopyWebpackPlugin(
224-
copyWebpackPluginPatterns,
225-
copyWebpackPluginOptions,
226-
);
227-
extraPlugins.push(copyWebpackPluginInstance);
231+
extraPlugins.push(new CopyWebpackPlugin({
232+
patterns: copyWebpackPluginPatterns,
233+
}));
228234
}
229235

230236
if (buildOptions.progress) {

packages/angular_devkit/build_angular/test/browser/assets_spec_large.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ describe('Browser Builder assets', () => {
9191
const output = await run.result as BrowserBuilderOutput;
9292
expect(output.success).toBe(true);
9393

94-
expect(host.scopedSync().exists(normalize('./dist/folder/asset.txt'))).toBe(true);
95-
expect(host.scopedSync().exists(normalize('./dist/folder/asset-ignored.txt'))).toBe(false);
96-
expect(host.scopedSync().exists(normalize('./dist/folder/.gitkeep'))).toBe(false);
94+
expect(host.scopedSync().exists(normalize('./dist/folder/asset.txt'))).toBe(true, `asset.txt doesn't exist.`);
95+
expect(host.scopedSync().exists(normalize('./dist/folder/asset-ignored.txt'))).toBe(false, 'asset-ignored.txt exists.');
96+
expect(host.scopedSync().exists(normalize('./dist/folder/.gitkeep'))).toBe(false, '.gitkeep exists.');
9797

9898
await run.stop();
9999
});

0 commit comments

Comments
 (0)