Skip to content

Commit 0773033

Browse files
hanslfilipesilva
authored andcommitted
fix(@angular/cli): allow build output in outDir outside of project
1 parent 38b1178 commit 0773033

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
9999
// specify a configuration flag.
100100
// Also prevent writing outside the project path. That is not overridable.
101101
const fullOutputPath = path.resolve(buildOptions.outputPath, asset.output);
102-
if (!fullOutputPath.startsWith(projectRoot)) {
103-
const message = 'An asset cannot be written to a location outside the project.';
104-
throw new SilentError(message);
105-
}
106102
if (!fullOutputPath.startsWith(path.resolve(buildOptions.outputPath))) {
103+
if (!fullOutputPath.startsWith(projectRoot)) {
104+
const message = 'An asset cannot be written to a location outside the project.';
105+
throw new SilentError(message);
106+
}
107+
107108
if (!asset.allowOutsideOutDir) {
108109
const message = 'An asset cannot be written to a location outside of the output path. '
109110
+ 'You can override this message by setting the `allowOutsideOutDir` '

tests/e2e/tests/build/assets.ts

+20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as path from 'path';
12
import {
23
writeMultipleFiles,
34
createDir,
@@ -10,6 +11,10 @@ import { expectToFail } from '../../utils/utils';
1011
import {getGlobalVariable} from '../../utils/env';
1112

1213

14+
const temp = require('temp');
15+
const tempDir = path.join(temp.mkdirSync('angular-cli-e2e-assets-'), 'out');
16+
17+
1318
export default function () {
1419
// Disable parts of it in webpack tests.
1520
const ejected = getGlobalVariable('argv').eject;
@@ -55,6 +60,21 @@ export default function () {
5560
}))
5661
.then(() => expectToFail(() => ng('build')))
5762

63+
// This asset will not fail with the exception above.
64+
.then(() => updateJsonFile('.angular-cli.json', configJson => {
65+
const app = configJson['apps'][0];
66+
app['outDir'] = tempDir;
67+
app['assets'] = [
68+
{ 'glob': '**/*', 'input': '../node_modules/some-package/', 'output': tempDir,
69+
'allowOutsideOutDir': true }
70+
];
71+
}))
72+
.then(() => ng('build'))
73+
.then(() => updateJsonFile('.angular-cli.json', configJson => {
74+
const app = configJson['apps'][0];
75+
app['outDir'] = 'dist';
76+
})
77+
5878
// This asset should also fail from reading from outside the project.
5979
.then(() => updateJsonFile('.angular-cli.json', configJson => {
6080
const app = configJson['apps'][0];

0 commit comments

Comments
 (0)