Skip to content

Commit

Permalink
fix(@angular/cli): no-op ng update --all
Browse files Browse the repository at this point in the history
'--all' functionality has been removed from `ng update` as updating multiple packages at once is not recommended. To update the depencencies in your workspace 'package.json' use the update command of your package manager.

Closes #15278
Closes #13095
Closes #12261
Closes #12243
Closes #18813
  • Loading branch information
alan-agius4 committed Sep 29, 2020
1 parent c78a460 commit 824add1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
43 changes: 18 additions & 25 deletions packages/angular/cli/commands/update-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,20 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
);
}

if (options.all) {
const updateCmd = this.packageManager === PackageManager.Yarn
? `'yarn upgrade-interactive' or 'yarn upgrade'`
: `'${this.packageManager} update'`;

this.logger.warn(`
'--all' functionality has been removed as updating multiple packages at once is not recommended.
To update packages which don’t provide 'ng update' capabilities in your workspace 'package.json' use ${updateCmd} instead.
Run the package manager update command after updating packages which provide 'ng update' capabilities.
`);

return 0;
}

const packages: PackageIdentifier[] = [];
for (const request of options['--'] || []) {
try {
Expand Down Expand Up @@ -342,24 +356,15 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
}
}

if (options.all && packages.length > 0) {
this.logger.error('Cannot specify packages when using the "all" option.');

return 1;
} else if (options.all && options.migrateOnly) {
this.logger.error('Cannot use "all" option with "migrate-only" option.');

return 1;
} else if (!options.migrateOnly && (options.from || options.to)) {
if (!options.migrateOnly && (options.from || options.to)) {
this.logger.error('Can only use "from" or "to" options with "migrate-only" option.');

return 1;
}

// If not asking for status then check for a clean git repository.
// This allows the user to easily reset any changes from the update.
const statusCheck = packages.length === 0 && !options.all;
if (!statusCheck && !this.checkCleanGit()) {
if (packages.length && !this.checkCleanGit()) {
if (options.allowDirty) {
this.logger.warn(
'Repository is not clean. Update changes will be mixed with pre-existing changes.',
Expand All @@ -379,7 +384,6 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
if (
options.migrateOnly === undefined &&
options.from === undefined &&
!options.all &&
packages.length === 1 &&
packages[0].name === '@angular/cli' &&
this.workspace.configFile &&
Expand All @@ -395,25 +399,14 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {

this.logger.info(`Found ${rootDependencies.size} dependencies.`);

if (options.all) {
// 'all' option and a zero length packages have already been checked.
// Add all direct dependencies to be updated
for (const dep of rootDependencies.keys()) {
const packageIdentifier = npa(dep);
if (options.next) {
packageIdentifier.fetchSpec = 'next';
}

packages.push(packageIdentifier);
}
} else if (packages.length === 0) {
if (packages.length === 0) {
// Show status
const { success } = await this.executeSchematic('@schematics/update', 'update', {
force: options.force || false,
next: options.next || false,
verbose: options.verbose || false,
packageManager: this.packageManager,
packages: options.all ? rootDependencies.keys() : [],
packages: [],
});

return success ? 0 : 1;
Expand Down
3 changes: 2 additions & 1 deletion packages/angular/cli/commands/update.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"all": {
"description": "Whether to update all packages in package.json.",
"default": false,
"type": "boolean"
"type": "boolean",
"x-deprecated": true
},
"next": {
"description": "Use the prerelease version, including beta and RCs.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default async function() {
await writeFile('../added.ts', 'console.log(\'created\');\n');
await silentGit('add', '../added.ts');

const { stderr } = await ng('update', '--all', '--force');
const { stderr } = await ng('update', '@angular/cli');
if (stderr && stderr.includes('Repository is not clean.')) {
throw new Error('Expected clean repository');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/misc/update-git-clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { expectToFail } from '../../utils/utils';
export default async function() {
await appendToFile('src/main.ts', 'console.log(\'changed\');\n');

const { message } = await expectToFail(() => ng('update', '--all'));
const { message } = await expectToFail(() => ng('update', '@angular/cli'));
if (!message || !message.includes('Repository is not clean.')) {
throw new Error('Expected unclean repository');
}
Expand Down

0 comments on commit 824add1

Please sign in to comment.