MCPcopy
hub / github.com/electron/forge / resolvePackageManager

Function resolvePackageManager

packages/utils/core-utils/src/package-manager.ts:88–158  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

86 *
87 */
88export const resolvePackageManager: () => Promise<PMDetails> = async () => {
89 const executingPM = pmFromUserAgent();
90 let lockfilePM;
91 const lockfile = await findUp(
92 ['package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'pnpm-workspace.yaml'],
93 { type: 'file' },
94 );
95 if (lockfile) {
96 const lockfileName = path.basename(lockfile);
97 lockfilePM = PM_FROM_LOCKFILE[lockfileName];
98 }
99
100 let installer;
101 let installerVersion;
102
103 if (typeof process.env.NODE_INSTALLER === 'string') {
104 if (Object.keys(PACKAGE_MANAGERS).includes(process.env.NODE_INSTALLER)) {
105 installer = process.env.NODE_INSTALLER;
106 installerVersion = await spawnPackageManager(
107 PACKAGE_MANAGERS[installer as SupportedPackageManager],
108 ['--version'],
109 );
110 if (!hasWarned) {
111 console.warn(
112 logSymbols.warning,
113 chalk.yellow(
114 `The NODE_INSTALLER environment variable is deprecated and will be removed in Electron Forge v8`,
115 ),
116 );
117 hasWarned = true;
118 }
119 } else {
120 console.warn(
121 logSymbols.warning,
122 chalk.yellow(
123 `Package manager ${chalk.red(process.env.NODE_INSTALLER)} is unsupported. Falling back to ${chalk.green('npm')} instead.`,
124 ),
125 );
126 }
127 } else if (executingPM) {
128 installer = executingPM.name;
129 installerVersion = executingPM.version;
130 } else if (lockfilePM) {
131 installer = lockfilePM;
132 installerVersion = await spawnPackageManager(
133 PACKAGE_MANAGERS[installer as SupportedPackageManager],
134 ['--version'],
135 );
136 }
137
138 switch (installer) {
139 case 'yarn':
140 case 'npm':
141 case 'pnpm':
142 d(
143 `Resolved package manager to ${installer}. (Derived from NODE_INSTALLER: ${process.env.NODE_INSTALLER}, npm_config_user_agent: ${process.env.npm_config_user_agent}, lockfile: ${lockfilePM})`,
144 );
145 return {

Callers 6

import.tsFile · 0.90
init.tsFile · 0.90
checkPackageManagerFunction · 0.90
initializeTemplateMethod · 0.90
initializePackageJSONMethod · 0.90

Calls 2

pmFromUserAgentFunction · 0.85
spawnPackageManagerFunction · 0.85

Tested by

no test coverage detected