Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): update copy-webpack-plugin to ver…
Browse files Browse the repository at this point in the history
…sion 6

Fixes #17858
  • Loading branch information
alan-agius4 authored and filipesilva committed Jun 8, 2020
1 parent b908a07 commit a8ecbc8
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 81 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@types/babel__core": "7.1.6",
"@types/browserslist": "^4.4.0",
"@types/caniuse-lite": "^1.0.0",
"@types/copy-webpack-plugin": "^5.0.0",
"@types/copy-webpack-plugin": "^6.0.0",
"@types/cssnano": "^4.0.0",
"@types/debug": "^4.1.2",
"@types/express": "^4.16.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular_devkit/build_angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"cacache": "15.0.0",
"caniuse-lite": "^1.0.30001032",
"circular-dependency-plugin": "5.2.0",
"copy-webpack-plugin": "5.1.1",
"copy-webpack-plugin": "6.0.2",
"core-js": "3.6.4",
"css-loader": "3.5.1",
"cssnano": "4.1.10",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,34 +254,40 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
if (buildOptions.assets.length) {
const copyWebpackPluginPatterns = buildOptions.assets.map((asset: AssetPatternClass) => {
// Resolve input paths relative to workspace root and add slash at the end.
asset.input = path.resolve(root, asset.input).replace(/\\/g, '/');
asset.input = asset.input.endsWith('/') ? asset.input : asset.input + '/';
asset.output = asset.output.endsWith('/') ? asset.output : asset.output + '/';

if (asset.output.startsWith('..')) {
const message = 'An asset cannot be written to a location outside of the output path.';
throw new Error(message);
// tslint:disable-next-line: prefer-const
let { input, output, ignore = [], glob } = asset;
input = path.resolve(root, input).replace(/\\/g, '/');
input = input.endsWith('/') ? input : input + '/';
output = output.endsWith('/') ? output : output + '/';

if (output.startsWith('..')) {
throw new Error('An asset cannot be written to a location outside of the output path.');
}

return {
context: asset.input,
context: input,
// Now we remove starting slash to make Webpack place it from the output root.
to: asset.output.replace(/^\//, ''),
ignore: asset.ignore,
from: {
glob: asset.glob,
to: output.replace(/^\//, ''),
from: glob,
noErrorOnMissing: true,
globOptions: {
dot: true,
ignore: [
'.gitkeep',
'**/.DS_Store',
'**/Thumbs.db',
// Negate patterns needs to be absolute because copy-webpack-plugin uses absolute globs which
// causes negate patterns not to match.
// See: https://github.com/webpack-contrib/copy-webpack-plugin/issues/498#issuecomment-639327909
...ignore,
].map(i => path.posix.join(input, i)),
},
};
});

const copyWebpackPluginOptions = { ignore: ['.gitkeep', '**/.DS_Store', '**/Thumbs.db'] };

const copyWebpackPluginInstance = new CopyWebpackPlugin(
copyWebpackPluginPatterns,
copyWebpackPluginOptions,
);
extraPlugins.push(copyWebpackPluginInstance);
extraPlugins.push(new CopyWebpackPlugin({
patterns: copyWebpackPluginPatterns,
}));
}

if (buildOptions.progress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ describe('Browser Builder assets', () => {
const output = await run.result as BrowserBuilderOutput;
expect(output.success).toBe(true);

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

await run.stop();
});
Expand Down
Loading

0 comments on commit a8ecbc8

Please sign in to comment.