Skip to content

Commit 2fc7c73

Browse files
alan-agius4dgp1130
authored andcommitted
refactor(@angular/cli): remove deprecated --prod flag
BREAKING CHANGE: Deprecated option `--prod` has been removed from all builders. `--configuration production`/`-c production` should be used instead if the default configuration of the builder is not configured to `production`.
1 parent 69ecdda commit 2fc7c73

File tree

9 files changed

+236
-222
lines changed

9 files changed

+236
-222
lines changed

packages/angular/cli/commands/definitions.json

+1-6
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@
1414
}
1515
},
1616
"configuration": {
17-
"description": "One or more named builder configurations as a comma-separated list as specified in the \"configurations\" section of angular.json.\nThe builder uses the named configurations to run the given target.\nFor more information, see https://angular.io/guide/workspace-config#alternate-build-configurations.\nSetting this explicitly overrides the \"--prod\" flag.",
17+
"description": "One or more named builder configurations as a comma-separated list as specified in the \"configurations\" section of angular.json.\nThe builder uses the named configurations to run the given target.\nFor more information, see https://angular.io/guide/workspace-config#alternate-build-configurations.",
1818
"type": "string",
1919
"aliases": ["c"]
20-
},
21-
"prod": {
22-
"description": "Shorthand for \"--configuration=production\".\nSet the build configuration to the production target.\nBy default, the production target is set up in the workspace configuration such that all builds make use of bundling, limited tree-shaking, and also limited dead code elimination.",
23-
"type": "boolean",
24-
"x-deprecated": "Use `--configuration production` instead."
2520
}
2621
}
2722
},

packages/angular/cli/models/architect-command.ts

-15
Original file line numberDiff line numberDiff line change
@@ -422,21 +422,6 @@ export abstract class ArchitectCommand<
422422
} else {
423423
project = commandOptions.project;
424424
target = this.target;
425-
if (commandOptions.prod) {
426-
const defaultConfig =
427-
project &&
428-
target &&
429-
this.workspace?.projects.get(project)?.targets.get(target)?.defaultConfiguration;
430-
431-
this.logger.warn(
432-
defaultConfig === 'production'
433-
? 'Option "--prod" is deprecated: No need to use this option as this builder defaults to configuration "production".'
434-
: 'Option "--prod" is deprecated: Use "--configuration production" instead.',
435-
);
436-
// The --prod flag will always be the first configuration, available to be overwritten
437-
// by following configurations.
438-
configuration = 'production';
439-
}
440425
if (commandOptions.configuration) {
441426
configuration = `${configuration ? `${configuration},` : ''}${
442427
commandOptions.configuration

tests/legacy-cli/e2e/assets/9.0-project/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Run `ng generate component component-name` to generate a new component. You can
1212

1313
## Build
1414

15-
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
15+
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory.
1616

1717
## Running unit tests
1818

tests/legacy-cli/e2e/tests/build/lazy-load-syntax.ts

+51-36
Original file line numberDiff line numberDiff line change
@@ -16,64 +16,79 @@ export default async function () {
1616

1717
// Add app routing.
1818
// This is done automatically on a new app with --routing.
19-
await writeFile(appRoutingModulePath, `
20-
import { NgModule } from '@angular/core';
21-
import { Routes, RouterModule } from '@angular/router';
19+
await writeFile(
20+
appRoutingModulePath,
21+
`
22+
import { NgModule } from '@angular/core';
23+
import { Routes, RouterModule } from '@angular/router';
2224
23-
const routes: Routes = [];
25+
const routes: Routes = [];
2426
25-
@NgModule({
26-
imports: [RouterModule.forRoot(routes)],
27-
exports: [RouterModule]
28-
})
29-
export class AppRoutingModule { }
30-
`);
31-
await prependToFile('src/app/app.module.ts',
32-
`import { AppRoutingModule } from './app-routing.module';`);
27+
@NgModule({
28+
imports: [RouterModule.forRoot(routes)],
29+
exports: [RouterModule]
30+
})
31+
export class AppRoutingModule { }
32+
`,
33+
);
34+
await prependToFile(
35+
'src/app/app.module.ts',
36+
`import { AppRoutingModule } from './app-routing.module';`,
37+
);
3338
await replaceInFile('src/app/app.module.ts', `imports: [`, `imports: [ AppRoutingModule,`);
3439
await appendToFile('src/app/app.component.html', '<router-outlet></router-outlet>');
3540

3641
const originalAppRoutingModule = await readFile(appRoutingModulePath);
3742
// helper to replace loadChildren
3843
const replaceLoadChildren = async (route: string) => {
39-
const content = originalAppRoutingModule.replace('const routes: Routes = [];', `
40-
const routes: Routes = [{ path: 'lazy', loadChildren: ${route} }];
41-
`);
44+
const content = originalAppRoutingModule.replace(
45+
'const routes: Routes = [];',
46+
`
47+
const routes: Routes = [{ path: 'lazy', loadChildren: ${route} }];
48+
`,
49+
);
4250

4351
return writeFile(appRoutingModulePath, content);
4452
};
4553

4654
// Add lazy route.
4755
await ng('generate', 'module', 'lazy', '--routing');
4856
await ng('generate', 'component', 'lazy/lazy-comp');
49-
await replaceInFile('src/app/lazy/lazy-routing.module.ts', 'const routes: Routes = [];', `
50-
import { LazyCompComponent } from './lazy-comp/lazy-comp.component';
51-
const routes: Routes = [{ path: '', component: LazyCompComponent }];
52-
`);
57+
await replaceInFile(
58+
'src/app/lazy/lazy-routing.module.ts',
59+
'const routes: Routes = [];',
60+
`
61+
import { LazyCompComponent } from './lazy-comp/lazy-comp.component';
62+
const routes: Routes = [{ path: '', component: LazyCompComponent }];
63+
`,
64+
);
5365

5466
// Add lazy route e2e
55-
await writeFile('e2e/src/app.e2e-spec.ts', `
56-
import { browser, logging, element, by } from 'protractor';
67+
await writeFile(
68+
'e2e/src/app.e2e-spec.ts',
69+
`
70+
import { browser, logging, element, by } from 'protractor';
5771
58-
describe('workspace-project App', () => {
59-
it('should display lazy route', async () => {
60-
await browser.get(browser.baseUrl + '/lazy');
61-
expect(await element(by.css('app-lazy-comp p')).getText()).toEqual('lazy-comp works!');
62-
});
72+
describe('workspace-project App', () => {
73+
it('should display lazy route', async () => {
74+
await browser.get(browser.baseUrl + '/lazy');
75+
expect(await element(by.css('app-lazy-comp p')).getText()).toEqual('lazy-comp works!');
76+
});
6377
64-
afterEach(async () => {
65-
// Assert that there are no errors emitted from the browser
66-
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
67-
expect(logs).not.toContain(jasmine.objectContaining({
68-
level: logging.Level.SEVERE,
69-
}));
78+
afterEach(async () => {
79+
// Assert that there are no errors emitted from the browser
80+
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
81+
expect(logs).not.toContain(jasmine.objectContaining({
82+
level: logging.Level.SEVERE,
83+
}));
84+
});
7085
});
71-
});
72-
`);
86+
`,
87+
);
7388

7489
// Convert the default config to use JIT and prod to just do AOT.
75-
// This way we can use `ng e2e` to test JIT and `ng e2e --prod` to test AOT.
76-
await updateJsonFile('angular.json', json => {
90+
// This way we can use `ng e2e` to test JIT and `ng e2e --configuration=production` to test AOT.
91+
await updateJsonFile('angular.json', (json) => {
7792
const buildTarget = json['projects'][projectName]['architect']['build'];
7893
buildTarget['options']['aot'] = true;
7994
buildTarget['configurations']['development']['aot'] = false;

tests/legacy-cli/e2e/tests/build/material.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { isPrereleaseCli, updateJsonFile } from '../../utils/project';
77
const snapshots = require('../../ng-snapshot/package.json');
88

99
export default async function () {
10-
const tag = await isPrereleaseCli() ? '@next' : '';
10+
const tag = (await isPrereleaseCli()) ? '@next' : '';
1111
await ng('add', `@angular/material${tag}`, '--skip-confirmation');
1212

1313
const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];
@@ -72,5 +72,5 @@ export default async function () {
7272
`,
7373
);
7474

75-
await ng('e2e', '--prod');
75+
await ng('e2e', '--configuration=production');
7676
}

tests/legacy-cli/e2e/tests/build/rebuild-replacements.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@ import { wait } from '../../utils/utils';
88

99
const webpackGoodRegEx = / Compiled successfully./;
1010

11-
export default async function() {
11+
export default async function () {
1212
if (process.platform.startsWith('win')) {
1313
return;
1414
}
1515

1616
let error;
1717
try {
18-
await execAndWaitForOutputToMatch('ng', ['serve', '--prod'], webpackGoodRegEx);
18+
await execAndWaitForOutputToMatch(
19+
'ng',
20+
['serve', '--configuration=production'],
21+
webpackGoodRegEx,
22+
);
1923

2024
await wait(4000);
21-
25+
2226
// Should trigger a rebuild.
2327
await appendToFile('src/environments/environment.prod.ts', `console.log('PROD');`);
2428
await waitForAnyProcessOutputToMatch(webpackGoodRegEx, 45000);

0 commit comments

Comments
 (0)