Skip to content

Commit d349179

Browse files
committed
fix(@angular/cli): improve error handling and test for skipped registry packages
1 parent 5139035 commit d349179

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ export default function (options: UpdateSchema): Rule {
858858
// If the package cannot be fetched (e.g. private registry, JSR, AWS CodeArtifact,
859859
// or local workspace packages), return a partial object so the reduce below can
860860
// decide whether to warn or hard-fail based on whether it was explicitly requested.
861-
const message = error instanceof Error ? error.message : String(error);
861+
const message = (error as { message?: string }).message ?? String(error);
862862
logger.warn(
863863
`Package '${depName}' could not be fetched from the registry: ${message}`,
864864
);

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -336,18 +336,19 @@ describe('@schematics/update', () => {
336336
expect(resultTreeContent.endsWith('}')).toBeTrue();
337337
});
338338

339-
it('skips packages that cannot be fetched from the registry and continues updating others', async () => {
339+
it('continues updating others when one package fetch fails', async () => {
340340
// Regression test for https://github.com/angular/angular-cli/issues/28834
341341
// Packages from private registries, JSR, AWS CodeArtifact, or local workspaces
342342
// may resolve as npm-registry packages (pass isPkgFromRegistry) but fail to fetch
343-
// with a 404. The schematic should warn and skip them rather than hard-failing.
343+
// with a 404. The schematic should warn and skip them rather than hard-failing,
344+
// and other explicitly-requested packages should still be updated.
344345
const inputTree = new UnitTestTree(
345346
new HostTree(
346347
new virtualFs.test.TestHost({
347348
'/package.json': JSON.stringify({
348349
name: 'blah',
349350
dependencies: {
350-
// A real package that can be updated:
351+
// A real package that should be updated:
351352
'@angular-devkit-tests/update-base': '1.0.0',
352353
// A scoped package that does not exist on the npm registry (simulates a
353354
// private / JSR / CodeArtifact package that passes the registry specifier
@@ -363,18 +364,22 @@ describe('@schematics/update', () => {
363364
schematicRunner.logger.subscribe((x) => messages.push(x.message));
364365

365366
// Should NOT throw even though one package cannot be fetched.
366-
const resultTree = await schematicRunner.runSchematic('update', undefined, inputTree);
367+
const resultTree = await schematicRunner.runSchematic(
368+
'update',
369+
{ packages: ['@angular-devkit-tests/update-base'] },
370+
inputTree,
371+
);
367372

368-
// The unfetchable package should be warned about.
373+
// The unfetchable package should produce a warning.
369374
expect(
370375
messages.some((m) => m.includes('@private-nonexistent/package-ng-update-issue-28834')),
371376
).toBeTrue();
372377

373-
// The package.json should be unchanged (nothing to update in no-packages mode).
378+
// The valid package should have been updated despite the other package failing.
374379
const { dependencies } = resultTree.readJson('/package.json') as {
375380
dependencies: Record<string, string>;
376381
};
377-
expect(dependencies['@angular-devkit-tests/update-base']).toBe('1.0.0');
382+
expect(dependencies['@angular-devkit-tests/update-base']).toBe('1.1.0');
378383
expect(dependencies['@private-nonexistent/package-ng-update-issue-28834']).toBe('1.0.0');
379384
}, 45000);
380385

0 commit comments

Comments
 (0)