Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular/cli): no-op ng update --all #18888

Merged
merged 2 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
5 changes: 5 additions & 0 deletions packages/schematics/update/update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,11 @@ function _usageMessage(
logger.info(' ' + fields.map((x, i) => x.padEnd(pads[i])).join(''));
});

logger.info(
`There might be additional packages which don't provide 'ng update' capabilities that are outdated.\n`
+ `You can update the addition packages by running the update command of your package manager.`,
);

return;
}

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