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 9, 2020
1 parent 4c2e21a commit 1a8de6f
Show file tree
Hide file tree
Showing 5 changed files with 388 additions and 89 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"@types/browserslist": "^4.4.0",
"@types/caniuse-lite": "^1.0.0",
"@types/clean-css": "^4.2.1",
"@types/copy-webpack-plugin": "^4.4.1",
"@types/copy-webpack-plugin": "^6.0.0",
"@types/express": "^4.16.0",
"@types/find-cache-dir": "^2.0.0",
"@types/glob": "^7.0.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 @@ -22,7 +22,7 @@
"circular-dependency-plugin": "5.2.0",
"clean-css": "4.2.1",
"coverage-istanbul-loader": "2.0.3",
"copy-webpack-plugin": "5.1.1",
"copy-webpack-plugin": "6.0.2",
"core-js": "3.6.4",
"file-loader": "4.2.0",
"find-cache-dir": "3.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,37 +194,43 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
}

// process asset entries
if (buildOptions.assets) {
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 @@ -91,9 +91,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 1a8de6f

Please sign in to comment.