MCPcopy Index your code
hub / github.com/nodejs/corepack / execute

Method execute

sources/commands/Enable.ts:41–79  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39 names = Option.Rest();
40
41 async execute() {
42 let installDirectory = this.installDirectory;
43
44 // Node always call realpath on the module it executes, so we already
45 // lost track of how the binary got called. To find it back, we need to
46 // iterate over the PATH variable.
47 if (typeof installDirectory === `undefined`)
48 installDirectory = path.dirname(await which(`corepack`));
49
50 // Otherwise the relative symlink we'll compute will be incorrect, if the
51 // install directory is within a symlink
52 installDirectory = fs.realpathSync(installDirectory);
53
54 const manifestPath = require.resolve(`corepack/package.json`);
55
56 const distFolder = path.join(path.dirname(manifestPath), `dist`);
57 if (!fs.existsSync(distFolder))
58 throw new Error(`Assertion failed: The stub folder doesn't exist`);
59
60 const names = this.names.length === 0
61 ? SupportedPackageManagerSetWithoutNpm
62 : this.names;
63
64 const allBinNames: Array<string> = [];
65
66 for (const name of new Set(names)) {
67 if (!isSupportedPackageManager(name))
68 throw new UsageError(`Invalid package manager name '${name}'`);
69
70 const binNames = this.context.engine.getBinariesFor(name);
71 allBinNames.push(...binNames);
72 }
73
74 const generateLink = process.platform === `win32` ?
75 (binName: string) => this.generateWin32Link(installDirectory, distFolder, binName) :
76 (binName: string) => this.generatePosixLink(installDirectory, distFolder, binName);
77
78 await Promise.all(allBinNames.map(generateLink));
79 }
80
81 async generatePosixLink(installDirectory: string, distFolder: string, binName: string) {
82 const file = path.join(installDirectory, binName);

Callers

nothing calls this directly

Calls 4

generateWin32LinkMethod · 0.95
generatePosixLinkMethod · 0.95
getBinariesForMethod · 0.80

Tested by

no test coverage detected