MCPcopy Create free account
hub / github.com/nodejs/corepack / getPackageManagerRequestFromCli

Function getPackageManagerRequestFromCli

sources/main.ts:21–39  ·  view source on GitHub ↗
(parameter: string | undefined, engine: Engine)

Source from the content-addressed store, hash-verified

19export type Context = BaseContext & CustomContext;
20
21function getPackageManagerRequestFromCli(parameter: string | undefined, engine: Engine): PackageManagerRequest | null {
22 if (!parameter)
23 return null;
24
25 const match = parameter.match(/^([^@]*)(?:@(.*))?$/);
26 if (!match)
27 return null;
28
29 const [, binaryName, binaryVersion] = match;
30 const packageManager = engine.getPackageManagerFor(binaryName)!;
31
32 if (packageManager == null && binaryVersion == null) return null;
33
34 return {
35 packageManager,
36 binaryName,
37 binaryVersion: binaryVersion || null,
38 };
39}
40
41function isUsageError(error: any): error is UsageError {
42 return error?.name === `UsageError`;

Callers 1

runMainFunction · 0.85

Calls 1

getPackageManagerForMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…