Skip to content

Commit 0889ed8

Browse files
fix
1 parent 3748683 commit 0889ed8

File tree

4 files changed

+125
-116
lines changed

4 files changed

+125
-116
lines changed

src/commands.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ import {
88
JsrPackage,
99
styleText,
1010
timeAgo,
11-
} from "./utils";
12-
import { Bun, getPkgManager, PkgManagerName, YarnBerry } from "./pkg_manager";
13-
import { downloadDeno, getDenoDownloadUrl } from "./download";
14-
import { getNpmPackageInfo, getPackageMeta } from "./api";
11+
} from "./utils.ts";
12+
import {
13+
Bun,
14+
getPkgManager,
15+
type PkgManagerName,
16+
YarnBerry,
17+
} from "./pkg_manager.ts";
18+
import { downloadDeno, getDenoDownloadUrl } from "./download.ts";
19+
import { getNpmPackageInfo, getPackageMeta } from "./api.ts";
1520
import semiver from "semiver";
1621

1722
const NPMRC_FILE = ".npmrc";

src/utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,14 @@ export async function exec(
263263

264264
return new Promise<ExecOutput>((resolve, reject) => {
265265
cp.on("exit", (code) => {
266-
if (code === 0) resolve({ combined, stdout, stderr });
267-
else reject(new ExecError(code ?? 1));
266+
if (code === 0) {
267+
resolve({ combined, stdout, stderr });
268+
} else {
269+
console.log(`Command: ${cmd} ${args.join(" ")}`);
270+
console.log(`CWD: ${cwd}`);
271+
console.log(`Output: ${combined}`);
272+
reject(new ExecError(code ?? 1));
273+
}
268274
});
269275
});
270276
}

test/commands.test.ts

Lines changed: 96 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
type PkgJson,
1818
readJson,
1919
readTextFile,
20+
styleText,
2021
writeJson,
2122
writeTextFile,
2223
} from "../src/utils.ts";
@@ -273,23 +274,21 @@ describe("install", () => {
273274
});
274275
});
275276

276-
if (process.platform !== "win32") {
277-
await withTempEnv(
278-
["i", "--bun", "--save-dev", "@std/[email protected]"],
279-
async (dir) => {
280-
assert.ok(
281-
await isFile(path.join(dir, "bun.lock")),
282-
"bun lockfile not created",
283-
);
284-
const pkgJson = await readJson<PkgJson>(
285-
path.join(dir, "package.json"),
286-
);
287-
assert.deepEqual(pkgJson.devDependencies, {
288-
"@std/encoding": "npm:@jsr/[email protected]",
289-
});
290-
},
291-
);
292-
}
277+
await withTempEnv(
278+
["i", "--bun", "--save-dev", "@std/[email protected]"],
279+
async (dir) => {
280+
assert.ok(
281+
await isFile(path.join(dir, "bun.lock")),
282+
"bun lockfile not created",
283+
);
284+
const pkgJson = await readJson<PkgJson>(
285+
path.join(dir, "package.json"),
286+
);
287+
assert.deepEqual(pkgJson.devDependencies, {
288+
"@std/encoding": "npm:@jsr/[email protected]",
289+
});
290+
},
291+
);
293292
});
294293

295294
it("jsr add -O @std/[email protected] - dev dependency", async () => {
@@ -329,23 +328,21 @@ describe("install", () => {
329328
});
330329
});
331330

332-
if (process.platform !== "win32") {
333-
await withTempEnv(
334-
["i", "--bun", "--save-optional", "@std/[email protected]"],
335-
async (dir) => {
336-
assert.ok(
337-
await isFile(path.join(dir, "bun.lock")),
338-
"bun lockfile not created",
339-
);
340-
const pkgJson = await readJson<PkgJson>(
341-
path.join(dir, "package.json"),
342-
);
343-
assert.deepEqual(pkgJson.optionalDependencies, {
344-
"@std/encoding": "npm:@jsr/[email protected]",
345-
});
346-
},
347-
);
348-
}
331+
await withTempEnv(
332+
["i", "--bun", "--save-optional", "@std/[email protected]"],
333+
async (dir) => {
334+
assert.ok(
335+
await isFile(path.join(dir, "bun.lock")),
336+
"bun lockfile not created",
337+
);
338+
const pkgJson = await readJson<PkgJson>(
339+
path.join(dir, "package.json"),
340+
);
341+
assert.deepEqual(pkgJson.optionalDependencies, {
342+
"@std/encoding": "npm:@jsr/[email protected]",
343+
});
344+
},
345+
);
349346
});
350347

351348
it("jsr i - runs '<pkg-manager> install' instead", async () => {
@@ -435,54 +432,53 @@ describe("install", () => {
435432
});
436433
});
437434

438-
if (process.platform !== "win32") {
439-
it("jsr add --bun @std/[email protected] - forces bun", async () => {
440-
await withTempEnv(
441-
["i", "--bun", "@std/[email protected]"],
442-
async (dir) => {
435+
it("jsr add --bun @std/[email protected] - forces bun", async () => {
436+
await withTempEnv(
437+
["i", "--bun", "@std/[email protected]"],
438+
async (dir) => {
439+
assert.ok(
440+
await isFile(path.join(dir, "bun.lock")),
441+
"bun lockfile not created",
442+
);
443+
444+
const bun = new Bun(dir);
445+
446+
if (await bun.isNpmrcSupported()) {
447+
const npmrcPath = path.join(dir, ".npmrc");
448+
const npmRc = await readTextFile(npmrcPath);
443449
assert.ok(
444-
await isFile(path.join(dir, "bun.lock")),
445-
"bun lockfile not created",
450+
npmRc.includes("@jsr:registry=https://npm.jsr.io"),
451+
"Missing npmrc registry",
446452
);
453+
} else {
454+
const config = await readTextFile(path.join(dir, "bunfig.toml"));
455+
assert.match(config, /"@jsr"\s+=/, "bunfig.toml not created");
456+
}
457+
},
458+
);
459+
});
447460

448-
const bun = new Bun(dir);
449-
450-
if (await bun.isNpmrcSupported()) {
451-
const npmrcPath = path.join(dir, ".npmrc");
452-
const npmRc = await readTextFile(npmrcPath);
453-
assert.ok(
454-
npmRc.includes("@jsr:registry=https://npm.jsr.io"),
455-
"Missing npmrc registry",
456-
);
457-
} else {
458-
const config = await readTextFile(path.join(dir, "bunfig.toml"));
459-
assert.match(config, /"@jsr"\s+=/, "bunfig.toml not created");
460-
}
461-
},
462-
);
463-
});
464-
it("jsr add --bun @std/[email protected] - forces bun for twice", async () => {
465-
await withTempEnv(
466-
["i", "--bun", "@std/[email protected]"],
467-
async (dir) => {
468-
await runJsr(["i", "--bun", "@std/[email protected]"], dir);
469-
470-
const bun = new Bun(dir);
471-
if (await bun.isNpmrcSupported()) {
472-
const npmrcPath = path.join(dir, ".npmrc");
473-
const npmRc = await readTextFile(npmrcPath);
474-
assert.ok(
475-
npmRc.includes("@jsr:registry=https://npm.jsr.io"),
476-
"Missing npmrc registry",
477-
);
478-
} else {
479-
const config = await readTextFile(path.join(dir, "bunfig.toml"));
480-
assert.match(config, /"@jsr"\s+=/, "bunfig.toml not created");
481-
}
482-
},
483-
);
484-
});
485-
}
461+
it("jsr add --bun @std/[email protected] - forces bun for twice", async () => {
462+
await withTempEnv(
463+
["i", "--bun", "@std/[email protected]"],
464+
async (dir) => {
465+
await runJsr(["i", "--bun", "@std/[email protected]"], dir);
466+
467+
const bun = new Bun(dir);
468+
if (await bun.isNpmrcSupported()) {
469+
const npmrcPath = path.join(dir, ".npmrc");
470+
const npmRc = await readTextFile(npmrcPath);
471+
assert.ok(
472+
npmRc.includes("@jsr:registry=https://npm.jsr.io"),
473+
"Missing npmrc registry",
474+
);
475+
} else {
476+
const config = await readTextFile(path.join(dir, "bunfig.toml"));
477+
assert.match(config, /"@jsr"\s+=/, "bunfig.toml not created");
478+
}
479+
},
480+
);
481+
});
486482

487483
describe("env detection", () => {
488484
it("detect pnpm from npm_config_user_agent", async () => {
@@ -579,26 +575,24 @@ describe("install", () => {
579575
});
580576
});
581577

582-
if (process.platform !== "win32") {
583-
it("detect bun from npm_config_user_agent", async () => {
584-
await withTempEnv(
585-
["i", "@std/[email protected]"],
586-
async (dir) => {
587-
assert.ok(
588-
await isFile(path.join(dir, "bun.lock")),
589-
"bun lockfile not created",
590-
);
591-
},
592-
{
593-
env: {
594-
...process.env,
595-
npm_config_user_agent:
596-
`bun/1.0.29 ${process.env.npm_config_user_agent}`,
597-
},
578+
it("detect bun from npm_config_user_agent", async () => {
579+
await withTempEnv(
580+
["i", "@std/[email protected]"],
581+
async (dir) => {
582+
assert.ok(
583+
await isFile(path.join(dir, "bun.lock")),
584+
"bun lockfile not created",
585+
);
586+
},
587+
{
588+
env: {
589+
...process.env,
590+
npm_config_user_agent:
591+
`bun/1.0.29 ${process.env.npm_config_user_agent}`,
598592
},
599-
);
600-
});
601-
}
593+
},
594+
);
595+
});
602596
});
603597
});
604598

@@ -673,8 +667,7 @@ describe("publish", () => {
673667
"export const value = 42;",
674668
);
675669

676-
// TODO: Change this once deno supports jsr.json
677-
await writeJson<DenoJson>(path.join(dir, "deno.json"), {
670+
await writeJson<DenoJson>(path.join(dir, "jsr.json"), {
678671
name: "@deno/jsr-cli-test",
679672
version: pkgJson.version!,
680673
license: "MIT",
@@ -767,8 +760,7 @@ describe("publish", () => {
767760
"export const value = 42;",
768761
);
769762

770-
// TODO: Change this once deno supports jsr.json
771-
await writeJson<DenoJson>(path.join(dir, "deno.json"), {
763+
await writeJson<DenoJson>(path.join(dir, "jsr.json"), {
772764
name: "@deno/jsr-cli-test",
773765
version: "1.0.0",
774766
license: "MIT",
@@ -790,8 +782,7 @@ describe("publish", () => {
790782
"export const value = 42;",
791783
);
792784

793-
// TODO: Change this once deno supports jsr.json
794-
await writeJson<DenoJson>(path.join(dir, "deno.json"), {
785+
await writeJson<DenoJson>(path.join(dir, "jsr.json"), {
795786
name: "@deno/jsr-cli-test",
796787
version: "1.0.0",
797788
license: "MIT",
@@ -871,7 +862,7 @@ describe("show", () => {
871862
true,
872863
);
873864

874-
assert.ok(output.combined.includes("latest: -"));
865+
assert.ok(output.combined.includes("latest: " + styleText("magenta", "-")));
875866
assert.ok(output.combined.includes("npm tarball:"));
876867
});
877868
});

test/test_utils.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,18 @@ export async function runJsr(
2828
) {
2929
const bin = path.join(__dirname, "..", "src", "bin.ts");
3030

31-
return await exec("node", ["--experimental-strip-types", bin, ...args], cwd, {
32-
...process.env,
33-
npm_config_user_agent: undefined,
34-
...env,
35-
}, captureOutput);
31+
return await exec(
32+
"node",
33+
["--no-warnings", "--experimental-strip-types", bin, ...args],
34+
cwd,
35+
{
36+
...process.env,
37+
npm_config_user_agent: undefined,
38+
...env,
39+
NO_COLOR: "true",
40+
},
41+
captureOutput,
42+
);
3643
}
3744

3845
export async function runInTempDir(fn: (dir: string) => Promise<void>) {

0 commit comments

Comments
 (0)