Skip to content

Commit 9dc5485

Browse files
committed
refactor(@angular/cli): remove usage of npm-pick-manifest dependency
The amount of used functionality provided by the `npm-pick-manifest` package was minimal within the Angular CLI. Logic to determine an appropriate package version for `ng update` is similar to the logic in `ng add`. The later of which did not use the `npm-pick-manifest` package. To reduce the total amount of dependencies, the logic from `ng add` was repurposed to fit the requirements of `ng update`.
1 parent ec0dfc9 commit 9dc5485

File tree

5 files changed

+31
-47
lines changed

5 files changed

+31
-47
lines changed

packages/angular/cli/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ ts_project(
5555
":node_modules/ini",
5656
":node_modules/jsonc-parser",
5757
":node_modules/npm-package-arg",
58-
":node_modules/npm-pick-manifest",
5958
":node_modules/pacote",
6059
":node_modules/resolve",
6160
":node_modules/yargs",

packages/angular/cli/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"jsonc-parser": "3.3.1",
3636
"listr2": "9.0.1",
3737
"npm-package-arg": "12.0.2",
38-
"npm-pick-manifest": "10.0.0",
3938
"pacote": "21.0.0",
4039
"resolve": "1.22.10",
4140
"semver": "7.7.2",

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

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { createRequire } from 'node:module';
1919
import * as path from 'node:path';
2020
import { join, resolve } from 'node:path';
2121
import npa from 'npm-package-arg';
22-
import pickManifest from 'npm-pick-manifest';
2322
import * as semver from 'semver';
2423
import { Argv } from 'yargs';
2524
import { PackageManager } from '../../../lib/config/workspace-schema';
@@ -665,36 +664,41 @@ export default class UpdateCommandModule extends CommandModule<UpdateCommandArgs
665664
// Try to find a package version based on the user requested package specifier
666665
// registry specifier types are either version, range, or tag
667666
let manifest: PackageManifest | undefined;
668-
if (
669-
requestIdentifier.type === 'version' ||
670-
requestIdentifier.type === 'range' ||
671-
requestIdentifier.type === 'tag'
672-
) {
673-
try {
674-
manifest = pickManifest(metadata, requestIdentifier.fetchSpec);
675-
} catch (e) {
676-
assertIsError(e);
677-
if (e.code === 'ETARGET') {
678-
// If not found and next was used and user did not provide a specifier, try latest.
679-
// Package may not have a next tag.
667+
switch (requestIdentifier.type) {
668+
case 'tag':
669+
manifest = metadata.tags[requestIdentifier.fetchSpec];
670+
// If not found and next option was used and user did not provide a specifier, try latest.
671+
// Package may not have a next tag.
672+
if (!manifest && requestIdentifier.fetchSpec === 'next' && !requestIdentifier.rawSpec) {
673+
manifest = metadata.tags['latest'];
674+
}
675+
break;
676+
case 'version':
677+
manifest = metadata.versions[requestIdentifier.fetchSpec];
678+
break;
679+
case 'range':
680+
for (const potentialManifest of Object.values(metadata.versions)) {
681+
// Ignore deprecated package versions
682+
if (potentialManifest.deprecated) {
683+
continue;
684+
}
685+
// Only consider versions that are within the range
680686
if (
681-
requestIdentifier.type === 'tag' &&
682-
requestIdentifier.fetchSpec === 'next' &&
683-
!requestIdentifier.rawSpec
687+
!semver.satisfies(potentialManifest.version, requestIdentifier.fetchSpec, {
688+
loose: true,
689+
})
684690
) {
685-
try {
686-
manifest = pickManifest(metadata, 'latest');
687-
} catch (e) {
688-
assertIsError(e);
689-
if (e.code !== 'ETARGET' && e.code !== 'ENOVERSIONS') {
690-
throw e;
691-
}
692-
}
691+
continue;
692+
}
693+
// Update the used manifest if current potential is newer than existing or there is not one yet
694+
if (
695+
!manifest ||
696+
semver.gt(potentialManifest.version, manifest.version, { loose: true })
697+
) {
698+
manifest = potentialManifest;
693699
}
694-
} else if (e.code !== 'ENOVERSIONS') {
695-
throw e;
696700
}
697-
}
701+
break;
698702
}
699703

700704
if (!manifest) {

packages/angular/cli/src/typings.d.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

pnpm-lock.yaml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)