Skip to content

Commit 8a0c19b

Browse files
fix: prefer lockfile detection over env var one (#105)
* chore: add missing license field in test fixtures * fix: prefer lockfile detection over env var one
1 parent 3acaed7 commit 8a0c19b

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/pkg_manager.ts

+1-1
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

+24
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]"],
@@ -657,6 +676,7 @@ describe("publish", () => {
657676
await writeJson<DenoJson>(path.join(dir, "deno.json"), {
658677
name: "@deno/jsr-cli-test",
659678
version: pkgJson.version!,
679+
license: "MIT",
660680
exports: {
661681
".": "./mod.ts",
662682
},
@@ -679,6 +699,7 @@ describe("publish", () => {
679699
await writeJson<DenoJson>(path.join(dir, "deno.json"), {
680700
name: "@deno/jsr-cli-test",
681701
version: "0.0.1",
702+
license: "MIT",
682703
exports: {
683704
".": "./mod.ts",
684705
},
@@ -717,6 +738,7 @@ describe("publish", () => {
717738
await writeJson<DenoJson>(path.join(dir, "jsr.json"), {
718739
name: "@deno/jsr-cli-test",
719740
version: pkgJson.version!,
741+
license: "MIT",
720742
exports: {
721743
".": "./mod.ts",
722744
},
@@ -744,6 +766,7 @@ describe("publish", () => {
744766
await writeJson<DenoJson>(path.join(dir, "deno.json"), {
745767
name: "@deno/jsr-cli-test",
746768
version: "1.0.0",
769+
license: "MIT",
747770
exports: {
748771
".": "./mod.ts",
749772
},
@@ -766,6 +789,7 @@ describe("publish", () => {
766789
await writeJson<DenoJson>(path.join(dir, "deno.json"), {
767790
name: "@deno/jsr-cli-test",
768791
version: "1.0.0",
792+
license: "MIT",
769793
exports: {
770794
".": "./mod.ts",
771795
},

test/test_utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface DenoJson {
77
name: string;
88
version: string;
99
exports: string | Record<string, string>;
10+
license: string;
1011
}
1112

1213
/**

0 commit comments

Comments
 (0)