Skip to content

Commit 8bf040b

Browse files
committed
feat(@angular/cli): add flag to not delete output path
Fix #5925 Fix #6193
1 parent d76d8fd commit 8bf040b

File tree

6 files changed

+35
-14
lines changed

6 files changed

+35
-14
lines changed

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

+7
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

+1-1
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

+3-1
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

+3-1
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {ng} from '../../utils/process';
2+
import {expectToFail} from '../../utils/utils';
3+
import {deleteFile, expectFileToExist} from '../../utils/fs';
4+
import {getGlobalVariable} from '../../utils/env';
5+
6+
export default function() {
7+
// Skip this in ejected tests.
8+
if (getGlobalVariable('argv').eject) {
9+
return Promise.resolve();
10+
}
11+
12+
return ng('build')
13+
// This is supposed to fail since there's a missing file
14+
.then(() => deleteFile('src/app/app.component.ts'))
15+
// The build fails but we don't delete the output of the previous build.
16+
.then(() => expectToFail(() => ng('build', '--no-delete-output-path')))
17+
.then(() => expectFileToExist('dist'))
18+
// By default, output path is always cleared.
19+
.then(() => expectToFail(() => ng('build')))
20+
.then(() => expectToFail(() => expectFileToExist('dist')));
21+
}

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

-11
This file was deleted.

0 commit comments

Comments
 (0)