(argv: Array<string>)
| 43 | } |
| 44 | |
| 45 | export async function runMain(argv: Array<string>) { |
| 46 | const engine = new Engine(); |
| 47 | |
| 48 | const [firstArg, ...restArgs] = argv; |
| 49 | const request = getPackageManagerRequestFromCli(firstArg, engine); |
| 50 | |
| 51 | if (!request) { |
| 52 | // If the first argument doesn't match any supported package manager, we fallback to the standard Corepack CLI |
| 53 | const cli = new Cli({ |
| 54 | binaryLabel: `Corepack`, |
| 55 | binaryName: `corepack`, |
| 56 | binaryVersion: corepackVersion, |
| 57 | }); |
| 58 | |
| 59 | cli.register(Builtins.HelpCommand); |
| 60 | cli.register(Builtins.VersionCommand); |
| 61 | |
| 62 | cli.register(CacheCommand); |
| 63 | cli.register(DisableCommand); |
| 64 | cli.register(EnableCommand); |
| 65 | cli.register(InstallGlobalCommand); |
| 66 | cli.register(InstallLocalCommand); |
| 67 | cli.register(PackCommand); |
| 68 | cli.register(UpCommand); |
| 69 | cli.register(UseCommand); |
| 70 | |
| 71 | // Deprecated commands |
| 72 | cli.register(HydrateCommand); |
| 73 | cli.register(PrepareCommand); |
| 74 | |
| 75 | const context = { |
| 76 | ...Cli.defaultContext, |
| 77 | cwd: process.cwd(), |
| 78 | engine, |
| 79 | }; |
| 80 | |
| 81 | const code = await cli.run(argv, context); |
| 82 | |
| 83 | if (code !== 0) { |
| 84 | process.exitCode ??= code; |
| 85 | } |
| 86 | } else { |
| 87 | try { |
| 88 | await engine.executePackageManagerRequest(request, { |
| 89 | cwd: process.cwd(), |
| 90 | args: restArgs, |
| 91 | }); |
| 92 | } catch (error) { |
| 93 | if (isUsageError(error)) { |
| 94 | console.error(error.message); |
| 95 | process.exit(1); |
| 96 | } |
| 97 | throw error; |
| 98 | } |
| 99 | } |
| 100 | } |
no test coverage detected
searching dependent graphs…