Skip to content

Commit e954460

Browse files
committed
fix(@angular/cli): add flag to not delete output path
Fix #5925 Fix #6193
1 parent 250d35d commit e954460

File tree

6 files changed

+29
-14
lines changed

6 files changed

+29
-14
lines changed

packages/@angular/cli/commands/build.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ export const baseBuildCommandOptions: any = [
118118
type: String,
119119
aliases: ['a'],
120120
description: 'Specifies app name or index to use.'
121+
},
122+
{
123+
name: 'delete-output-path',
124+
type: Boolean,
125+
default: true,
126+
aliases: ['dop'],
127+
description: 'Delete output path before build.'
121128
}
122129
];
123130

packages/@angular/cli/models/build-options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ export interface BuildOptions {
1717
outputHashing?: string;
1818
poll?: number;
1919
app?: string;
20-
20+
deleteOutputPath?: boolean;
2121
}

packages/@angular/cli/tasks/build.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ export default Task.extend({
2727
if (config.project && config.project.ejected) {
2828
throw new SilentError('An ejected project cannot use the build command anymore.');
2929
}
30-
rimraf.sync(path.resolve(project.root, outputPath));
30+
if (runTaskOptions.deleteOutputPath) {
31+
rimraf.sync(path.resolve(project.root, outputPath));
32+
}
3133

3234
const webpackConfig = new NgCliWebpackConfig(runTaskOptions, app).buildConfig();
3335
const webpackCompiler = webpack(webpackConfig);

packages/@angular/cli/tasks/serve.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export default Task.extend({
3131
if (projectConfig.project && projectConfig.project.ejected) {
3232
throw new SilentError('An ejected project cannot use the build command anymore.');
3333
}
34-
rimraf.sync(path.resolve(this.project.root, outputPath));
34+
if (serveTaskOptions.deleteOutputPath) {
35+
rimraf.sync(path.resolve(this.project.root, outputPath));
36+
}
3537

3638
const serveDefaults = {
3739
// default deployUrl to '' on serve to prevent the default from .angular-cli.json
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {ng} from '../../utils/process';
2+
import {expectToFail} from '../../utils/utils';
3+
import {deleteFile, expectFileToExist} from '../../utils/fs';
4+
5+
export default function() {
6+
return ng('build')
7+
// This is supposed to fail since there's a missing file
8+
.then(() => deleteFile('src/app/app.component.ts'))
9+
// The build fails but we don't delete the output of the previous build.
10+
.then(() => expectToFail(() => ng('build', '--no-delete-output-path')))
11+
.then(() => expectFileToExist('dist'))
12+
// By default, output path is always cleared.
13+
.then(() => expectToFail(() => ng('build')))
14+
.then(() => expectToFail(() => expectFileToExist('dist')));
15+
}

tests/e2e/tests/build/fail-build.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)