Skip to content

Commit ad95ee0

Browse files
fix(create-rezi): honor npm package manager selection
1 parent 604014e commit ad95ee0

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

packages/create-rezi/src/__tests__/index.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ test("resolveInstallInvocation prefers npm_execpath and falls back to node-adjac
7272
},
7373
);
7474

75+
assert.deepEqual(
76+
resolveInstallInvocation("npm", {
77+
env: {
78+
npm_execpath:
79+
"C:\\Users\\example\\AppData\\Roaming\\npm\\node_modules\\pnpm\\bin\\pnpm.cjs",
80+
},
81+
platform: "win32",
82+
nodeExecPath: "C:\\Program Files\\nodejs\\node.exe",
83+
}),
84+
{
85+
command: "C:\\Program Files\\nodejs\\npm.cmd",
86+
args: ["install"],
87+
},
88+
);
89+
7590
assert.deepEqual(
7691
resolveInstallInvocation("npm", {
7792
env: {},

packages/create-rezi/src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ function shouldStripInstallEnvKey(key: string): boolean {
149149
);
150150
}
151151

152+
function isNpmExecPath(execPath: string): boolean {
153+
const normalized = execPath.replaceAll("\\", "/").toLowerCase();
154+
return (
155+
normalized.endsWith("/npm-cli.js") ||
156+
normalized.endsWith("/npm-cli.mjs") ||
157+
/(^|\/)npm(\.cmd|\.exe)?$/.test(normalized)
158+
);
159+
}
160+
152161
export function createInstallEnv(
153162
parentEnv: Readonly<Record<string, string | undefined>> = process.env,
154163
): NodeJS.ProcessEnv {
@@ -180,7 +189,7 @@ export function resolveInstallInvocation(
180189
if (packageManager === "npm") {
181190
// biome-ignore lint/complexity/useLiteralKeys: process.env-compatible maps use index signatures in TS.
182191
const npmExecPath = env["npm_execpath"];
183-
if (npmExecPath) {
192+
if (npmExecPath && isNpmExecPath(npmExecPath)) {
184193
return { command: nodeExecPath, args: [npmExecPath, "install"] };
185194
}
186195
if (platform === "win32") {

0 commit comments

Comments
 (0)