Skip to content

Commit 60d3602

Browse files
committed
fix(@angular/cli): add a flag to let assets outside of outDir
On top of #7778 Fixes #8122
1 parent a02892f commit 60d3602

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

packages/@angular/cli/lib/config/schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
"description": "Directory where app files are placed.",
3939
"default": "app"
4040
},
41+
"allowAssetsOutsideOutDir": {
42+
"type": "boolean",
43+
"description": "Allow assets to be copied outside the outDir.",
44+
"default": false
45+
}
4146
"root": {
4247
"type": "string",
4348
"description": "The root directory of the app."

packages/@angular/cli/models/webpack-configs/common.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,20 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
9595
asset.output = asset.output || '';
9696
asset.glob = asset.glob || '';
9797

98-
// Prevent asset configurations from writing outside of the output path
98+
// Prevent asset configurations from writing outside of the output path, except if the user
99+
// specify a configuration flag.
100+
// Also prevent writing outside the project path. That is not overridable.
99101
const fullOutputPath = path.resolve(buildOptions.outputPath, asset.output);
100-
if (!fullOutputPath.startsWith(path.resolve(buildOptions.outputPath))) {
101-
const message = 'An asset cannot be written to a location outside of the output path.';
102+
if (!fullOutputPath.startsWith(projectRoot)) {
103+
const message = 'An asset cannot be written to a location outside the project.';
102104
throw new SilentError(message);
103105
}
106+
if (!fullOutputPath.startsWith(path.resolve(buildOptions.outputPath))) {
107+
if (!appConfig.allowAssetsOutsideOutDir) {
108+
const message = 'An asset cannot be written to a location outside of the output path.';
109+
throw new SilentError(message);
110+
}
111+
}
104112

105113
// Ensure trailing slash.
106114
if (isDirectory(path.resolve(asset.input))) {

0 commit comments

Comments
 (0)