Skip to content

Commit 9f414fb

Browse files
fix: prefer lockfile detection over env var one
1 parent 4d33c64 commit 9f414fb

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/pkg_manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export async function getPkgManager(
216216
);
217217
const rootPath = root || projectDir;
218218

219-
const result = pkgManagerName || fromEnv || fromLockfile || "npm";
219+
const result = pkgManagerName || fromLockfile || fromEnv || "npm";
220220

221221
let pkgManager: PackageManager;
222222
if (result === "yarn") {

test/commands.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,25 @@ describe("install", () => {
503503
);
504504
});
505505

506+
it("prefer lockfile detection over env detection", async () => {
507+
await runInTempDir(async (tmp) => {
508+
await writeJson<PkgJson>(path.join(tmp, "package.json"), {
509+
name: "foo",
510+
version: "0.0.1",
511+
dependencies: {
512+
preact: "10.23.2",
513+
},
514+
});
515+
516+
await exec("pnpm", ["install"], tmp);
517+
await runJsr(["i", "@std/[email protected]"], tmp, {
518+
npm_config_user_agent:
519+
`npm/10.8.2 node/v22.5.1 darwin arm64 workspaces/false`,
520+
});
521+
assert.ok(!fs.existsSync(path.join(tmp, "package-lock.json")));
522+
});
523+
});
524+
506525
it("overwrite detection with arg from npm_config_user_agent", async () => {
507526
await withTempEnv(
508527
["i", "--npm", "@std/[email protected]"],

0 commit comments

Comments
 (0)