Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prefer lockfile detection over env var one #105

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 24 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 Expand Up @@ -657,6 +676,7 @@ describe("publish", () => {
await writeJson<DenoJson>(path.join(dir, "deno.json"), {
name: "@deno/jsr-cli-test",
version: pkgJson.version!,
license: "MIT",
exports: {
".": "./mod.ts",
},
Expand All @@ -679,6 +699,7 @@ describe("publish", () => {
await writeJson<DenoJson>(path.join(dir, "deno.json"), {
name: "@deno/jsr-cli-test",
version: "0.0.1",
license: "MIT",
exports: {
".": "./mod.ts",
},
Expand Down Expand Up @@ -717,6 +738,7 @@ describe("publish", () => {
await writeJson<DenoJson>(path.join(dir, "jsr.json"), {
name: "@deno/jsr-cli-test",
version: pkgJson.version!,
license: "MIT",
exports: {
".": "./mod.ts",
},
Expand Down Expand Up @@ -744,6 +766,7 @@ describe("publish", () => {
await writeJson<DenoJson>(path.join(dir, "deno.json"), {
name: "@deno/jsr-cli-test",
version: "1.0.0",
license: "MIT",
exports: {
".": "./mod.ts",
},
Expand All @@ -766,6 +789,7 @@ describe("publish", () => {
await writeJson<DenoJson>(path.join(dir, "deno.json"), {
name: "@deno/jsr-cli-test",
version: "1.0.0",
license: "MIT",
exports: {
".": "./mod.ts",
},
Expand Down
1 change: 1 addition & 0 deletions test/test_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface DenoJson {
name: string;
version: string;
exports: string | Record<string, string>;
license: string;
}

/**
Expand Down
Loading