Skip to content

Commit 44ff584

Browse files
committed
fix(@angular/cli): correctly report available package updates during bare ng update
In v22.0.1, a performance optimization (4510dae) was introduced to fetch registry metadata lazily during `ng update`, only querying the registry for packages actively being updated or uninstalled. However, during a bare `ng update` to list available workspace updates (where `packages.size === 0`), `isUpdating` is false for every dependency. For installed dependencies with locked versions in package.json (no carets/tildes), localPkgJson exists, causing the resolver to fall back to local mock package info without registry versions or dist-tags. This commit updates the registry metadata check in `resolveUserUpdatePlan` to include listing mode (`packages.size === 0`), ensuring cached registry metadata is used to list available package updates. Closes #33712
1 parent ef75f6a commit 44ff584

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -942,11 +942,7 @@ export async function resolveUserUpdatePlan(
942942
};
943943

944944
if (packages.size === 0) {
945-
await Promise.all(
946-
Array.from(npmDeps.keys()).map(async (depName) => {
947-
await getOrFetchPackageMetadata(depName);
948-
}),
949-
);
945+
await Promise.all(Array.from(npmDeps.keys(), (depName) => getOrFetchPackageMetadata(depName)));
950946
} else {
951947
let lastPackagesSize;
952948
do {
@@ -999,12 +995,13 @@ export async function resolveUserUpdatePlan(
999995
} while (packages.size > lastPackagesSize);
1000996
}
1001997

998+
const isListingUpdates = packages.size === 0;
1002999
const packageInfoEntries = await Promise.all(
10031000
Array.from(npmDeps.keys(), async (depName) => {
10041001
const isUpdating = packages.has(depName);
10051002
const localPkgJson = getInstalledPackageJson(depName, workspaceRoot);
10061003

1007-
if (isUpdating || !localPkgJson) {
1004+
if (isListingUpdates || isUpdating || !localPkgJson) {
10081005
const metadata = await getOrFetchPackageMetadata(depName);
10091006
if (metadata) {
10101007
const info = await _buildPackageInfo(

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,29 @@ describe('UpdateResolver', () => {
289289
expect(plan.packagesToUpdate.size).toBe(0);
290290
});
291291

292+
it('includes registry metadata when listing updates with locked dependency versions in package.json', async () => {
293+
createMockWorkspace(
294+
{
295+
name: 'blah',
296+
dependencies: {
297+
'@angular-devkit-tests/update-base': '1.0.0',
298+
},
299+
},
300+
{
301+
'@angular-devkit-tests/update-base': { version: '1.0.0' },
302+
},
303+
);
304+
305+
const plan = await resolvePlan({
306+
packages: [],
307+
workspaceRoot: tempRoot,
308+
});
309+
310+
const info = plan.packageInfoMap.get('@angular-devkit-tests/update-base');
311+
expect(info?.npmPackageJson['dist-tags']?.['latest']).toBe('1.1.0');
312+
expect(info?.npmPackageJson.versions).toContain('1.1.0');
313+
});
314+
292315
it('should not error with yarn 2.0 protocols', async () => {
293316
createMockWorkspace(
294317
{

0 commit comments

Comments
 (0)