Skip to content

Commit 4c96537

Browse files
clydinalan-agius4
authored andcommitted
refactor(@angular/cli): remove ora-based spinner from update command
The `listr2` dependency that was recently introduced to improve the console UI for the `ng add` command is now used for the package installation step of the `ng update` command process.
1 parent dd07049 commit 4c96537

File tree

2 files changed

+45
-17
lines changed

2 files changed

+45
-17
lines changed

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

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import {
1212
FileSystemSchematicDescription,
1313
NodeWorkflow,
1414
} from '@angular-devkit/schematics/tools';
15-
import { SpawnSyncReturns, execSync, spawnSync } from 'child_process';
16-
import { existsSync, promises as fs } from 'fs';
17-
import { createRequire } from 'module';
15+
import { Listr } from 'listr2';
16+
import { SpawnSyncReturns, execSync, spawnSync } from 'node:child_process';
17+
import { existsSync, promises as fs } from 'node:fs';
18+
import { createRequire } from 'node:module';
1819
import npa from 'npm-package-arg';
1920
import pickManifest from 'npm-pick-manifest';
2021
import * as path from 'path';
@@ -74,6 +75,8 @@ interface MigrationSchematicDescriptionWithVersion extends MigrationSchematicDes
7475
version: string;
7576
}
7677

78+
class CommandError extends Error {}
79+
7780
const ANGULAR_PACKAGES_REGEXP = /^@(?:angular|nguniversal)\//;
7881
const UPDATE_SCHEMATIC_COLLECTION = path.join(__dirname, 'schematic/collection.json');
7982

@@ -756,21 +759,46 @@ export default class UpdateCommandModule extends CommandModule<UpdateCommandArgs
756759
);
757760

758761
if (success) {
759-
try {
760-
await fs.rm(path.join(this.context.root, 'node_modules'), {
761-
force: true,
762-
recursive: true,
763-
maxRetries: 3,
764-
});
765-
} catch {}
762+
const { root: commandRoot, packageManager } = this.context;
763+
const installArgs = this.packageManagerForce(options.verbose) ? ['--force'] : [];
764+
const tasks = new Listr([
765+
{
766+
title: 'Cleaning node modules directory',
767+
async task(_, task) {
768+
try {
769+
await fs.rm(path.join(commandRoot, 'node_modules'), {
770+
force: true,
771+
recursive: true,
772+
maxRetries: 3,
773+
});
774+
} catch (e) {
775+
assertIsError(e);
776+
if (e.code === 'ENOENT') {
777+
task.skip('Cleaning not required. Node modules directory not found.');
778+
}
779+
}
780+
},
781+
},
782+
{
783+
title: 'Installing packages',
784+
async task() {
785+
const installationSuccess = await packageManager.installAll(installArgs, commandRoot);
766786

767-
const installationSuccess = await this.context.packageManager.installAll(
768-
this.packageManagerForce(options.verbose) ? ['--force'] : [],
769-
this.context.root,
770-
);
787+
if (!installationSuccess) {
788+
throw new CommandError('Unable to install packages');
789+
}
790+
},
791+
},
792+
]);
771793

772-
if (!installationSuccess) {
773-
return 1;
794+
try {
795+
await tasks.run();
796+
} catch (e) {
797+
if (e instanceof CommandError) {
798+
return 1;
799+
}
800+
801+
throw e;
774802
}
775803
}
776804

packages/angular/cli/src/utilities/package-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class PackageManagerUtils {
6969
installArgs.push(packageManagerArgs.installAll);
7070
}
7171

72-
return this.run([...installArgs, ...extraArgs], { cwd, silent: true });
72+
return this.run([...installArgs, ...extraArgs], { cwd, silent: true, progress: false });
7373
}
7474

7575
/** Install a single package temporary. */

0 commit comments

Comments
 (0)