Skip to content

Commit

Permalink
fix: prefer lockfile detection over env var one
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Sep 11, 2024
1 parent 4d33c64 commit 9f414fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pkg_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export async function getPkgManager(
);
const rootPath = root || projectDir;

const result = pkgManagerName || fromEnv || fromLockfile || "npm";
const result = pkgManagerName || fromLockfile || fromEnv || "npm";

let pkgManager: PackageManager;
if (result === "yarn") {
Expand Down
19 changes: 19 additions & 0 deletions test/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,25 @@ describe("install", () => {
);
});

it("prefer lockfile detection over env detection", async () => {
await runInTempDir(async (tmp) => {
await writeJson<PkgJson>(path.join(tmp, "package.json"), {
name: "foo",
version: "0.0.1",
dependencies: {
preact: "10.23.2",
},
});

await exec("pnpm", ["install"], tmp);
await runJsr(["i", "@std/[email protected]"], tmp, {
npm_config_user_agent:
`npm/10.8.2 node/v22.5.1 darwin arm64 workspaces/false`,
});
assert.ok(!fs.existsSync(path.join(tmp, "package-lock.json")));
});
});

it("overwrite detection with arg from npm_config_user_agent", async () => {
await withTempEnv(
["i", "--npm", "@std/[email protected]"],
Expand Down

0 comments on commit 9f414fb

Please sign in to comment.