Skip to content

Commit 2d34128

Browse files
committed
fix(@angular/cli): show a simpler command for ng update
And use validate instead of run() ot change the options which is more correct.
1 parent 9274ca7 commit 2d34128

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

packages/@angular/cli/bin/ng-update-message.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if (found) {
3838
The Angular CLI configuration format has been changed, and your existing configuration can
3939
be updated automatically by running the following command:
4040
41-
ng update @angular/cli --migrate-only --from=1
41+
ng update @angular/cli
4242
${'='.repeat(80)}
4343
\u001b[39m`.replace(/^ {4}/gm, ''));
4444
}

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { normalize } from '@angular-devkit/core';
12
import { CommandScope, Option } from '../models/command';
23
import { SchematicCommand, CoreSchematicOptions } from '../models/schematic-command';
4+
import { findUp } from '../utilities/find-up';
35

46
export interface UpdateOptions extends CoreSchematicOptions {
57
next: boolean;
@@ -38,19 +40,34 @@ export default class UpdateCommand extends SchematicCommand {
3840
this.arguments = this.arguments.concat(schematicOptions.arguments.map(a => a.name));
3941
}
4042

41-
public async run(options: UpdateOptions) {
42-
const schematicOptions: any = { ...options };
43-
if (schematicOptions._[0] == '@angular/cli'
44-
&& !schematicOptions.migrateOnly
45-
&& !schematicOptions.from) {
46-
schematicOptions.migrateOnly = true;
47-
schematicOptions.from = '1.0.0';
43+
async validate(options: any) {
44+
if (options._[0] == '@angular/cli'
45+
&& options.migrateOnly === undefined
46+
&& options.from === undefined) {
47+
// Check for a 1.7 angular-cli.json file.
48+
const oldConfigFileNames = [
49+
normalize('.angular-cli.json'),
50+
normalize('angular-cli.json'),
51+
];
52+
const oldConfigFilePath =
53+
findUp(oldConfigFileNames, process.cwd())
54+
|| findUp(oldConfigFileNames, __dirname);
55+
56+
if (oldConfigFilePath) {
57+
options.migrateOnly = true;
58+
options.from = '1.0.0';
59+
}
4860
}
4961

62+
return super.validate(options);
63+
}
64+
65+
66+
public async run(options: UpdateOptions) {
5067
return this.runSchematic({
5168
collectionName: this.collectionName,
5269
schematicName: this.schematicName,
53-
schematicOptions,
70+
schematicOptions: options,
5471
dryRun: options.dryRun,
5572
force: false,
5673
showNothingDone: false,

packages/@angular/cli/models/command-runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ function verifyWorkspace(
312312
The Angular CLI configuration format has been changed, and your existing configuration can
313313
be updated automatically by running the following command:
314314
315-
ng update @angular/cli --migrate-only --from=1
315+
ng update @angular/cli
316316
`;
317317

318318
if (!logger) {

0 commit comments

Comments
 (0)