Skip to content

Commit fceb8a3

Browse files
committed
refactor(@angular/cli): support non-registry sources in getPackageManifest
The `getPackageManifest` method in the package manager abstraction was previously limited to fetching manifests from an NPM registry. This commit refactors the method to accept a generic `packageSpecifier` string. This allows the abstraction to leverage the underlying package manager's native ability to read manifests from various sources, including local tarballs (`.tgz`), local directories (`file:`), and git URLs, in addition to registry specifiers. This makes the `PackageManager` class more robust and capable of handling all package sources supported by commands like `ng add`.
1 parent f371b52 commit fceb8a3

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,29 +343,30 @@ export class PackageManager {
343343
}
344344

345345
/**
346-
* Fetches the registry manifest for a specific version of a package.
346+
* Fetches the manifest for a package.
347347
* The manifest is similar to the package's `package.json` file.
348-
* @param packageName The name of the package to fetch the manifest for.
349-
* @param version The version of the package to fetch the manifest for.
348+
* This method can handle various package sources, including registry specifiers
349+
* (`name@version`), local tarballs (`./package.tgz`), and local directories (`file:.`).
350+
* @param packageSpecifier The identifier of the package to fetch the manifest for.
350351
* @param options Options for the fetch.
351352
* @param options.timeout The maximum time in milliseconds to wait for the command to complete.
352-
* @param options.registry The registry to use for the fetch.
353+
* @param options.registry The registry to use for the fetch (for registry specifiers).
353354
* @param options.bypassCache If true, ignores the in-memory cache and fetches fresh data.
354355
* @returns A promise that resolves to the `PackageManifest` object, or `null` if the package is not found.
355356
*/
356357
async getPackageManifest(
357-
packageName: string,
358-
version: string,
358+
packageSpecifier: string,
359359
options: { timeout?: number; registry?: string; bypassCache?: boolean } = {},
360360
): Promise<PackageManifest | null> {
361-
const specifier = `${packageName}@${version}`;
362-
const commandArgs = [...this.descriptor.getManifestCommand, specifier];
361+
const commandArgs = [...this.descriptor.getManifestCommand, packageSpecifier];
363362
const formatter = this.descriptor.viewCommandFieldArgFormatter;
364363
if (formatter) {
365364
commandArgs.push(...formatter(MANIFEST_FIELDS));
366365
}
367366

368-
const cacheKey = options.registry ? `${specifier}|${options.registry}` : specifier;
367+
const cacheKey = options.registry
368+
? `${packageSpecifier}|${options.registry}`
369+
: packageSpecifier;
369370

370371
return this.#fetchAndParse(
371372
commandArgs,

0 commit comments

Comments
 (0)