Skip to content

Commit 4b41043

Browse files
fix: switch to deno release binary for publishing by default (#100)
* fix: switch to deno release binary for publishing by default This adds a new `DENO_BIN_CANARY` environment variable check to use the canary binary instead as well. * fix: update label
1 parent a2f4908 commit 4b41043

File tree

4 files changed

+52
-11
lines changed

4 files changed

+52
-11
lines changed

src/bin.ts

+6
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ ${
107107
"DENO_BIN_PATH",
108108
"Use specified Deno binary instead of local downloaded one.",
109109
],
110+
[
111+
"DENO_BIN_CANARY",
112+
"Use the canary Deno binary instead of latest for publishing.",
113+
],
110114
])
111115
}
112116
`);
@@ -148,6 +152,7 @@ if (args.length === 0) {
148152
run(async () => {
149153
const projectInfo = await findProjectDir(process.cwd());
150154
return publish(process.cwd(), {
155+
canary: process.env.DENO_BIN_CANARY !== undefined,
151156
binFolder,
152157
publishArgs: args.slice(1),
153158
pkgJsonPath: projectInfo.pkgJsonPath,
@@ -185,6 +190,7 @@ if (args.length === 0) {
185190
pnpm: { type: "boolean", default: false },
186191
bun: { type: "boolean", default: false },
187192
debug: { type: "boolean", default: false },
193+
canary: { type: "boolean", default: false },
188194
help: { type: "boolean", default: false, short: "h" },
189195
version: { type: "boolean", default: false, short: "v" },
190196
},

src/commands.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ export interface PublishOptions {
129129
binFolder: string;
130130
pkgJsonPath: string | null;
131131
publishArgs: string[];
132+
canary: boolean;
132133
}
133134

134-
async function getOrDownloadBinPath(binFolder: string) {
135-
const info = await getDenoDownloadUrl();
135+
async function getOrDownloadBinPath(binFolder: string, canary: boolean) {
136+
const info = await getDenoDownloadUrl(canary);
136137

137138
const binPath = path.join(
138139
binFolder,
@@ -164,7 +165,7 @@ async function getOrDownloadBinPath(binFolder: string) {
164165

165166
export async function publish(cwd: string, options: PublishOptions) {
166167
const binPath = process.env.DENO_BIN_PATH ??
167-
await getOrDownloadBinPath(options.binFolder);
168+
await getOrDownloadBinPath(options.binFolder, options.canary);
168169

169170
// Ready to publish now!
170171
const args = [

src/download.ts

+19-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as StreamZip from "node-stream-zip";
1010
const streamFinished = util.promisify(stream.finished);
1111

1212
const DENO_CANARY_INFO_URL = "https://dl.deno.land/canary-latest.txt";
13+
const DENO_RELEASE_INFO_URL = "https://dl.deno.land/release-latest.txt";
1314

1415
// Example: https://github.com/denoland/deno/releases/download/v1.41.0/deno-aarch64-apple-darwin.zip
1516
// Example: https://dl.deno.land/canary/d722de886b85093eeef08d1e9fd6f3193405762d/deno-aarch64-apple-darwin.zip
@@ -25,30 +26,39 @@ export interface DownloadInfo {
2526
url: string;
2627
filename: string;
2728
version: string;
29+
canary: boolean;
2830
}
2931

30-
export async function getDenoDownloadUrl(): Promise<DownloadInfo> {
32+
export async function getDenoDownloadUrl(
33+
canary: boolean,
34+
): Promise<DownloadInfo> {
3135
const key = `${process.platform} ${os.arch()}`;
3236
if (!(key in FILENAMES)) {
3337
throw new Error(`Unsupported platform: ${key}`);
3438
}
3539

3640
const name = FILENAMES[key];
3741

38-
const res = await fetch(DENO_CANARY_INFO_URL);
42+
const url = canary ? DENO_CANARY_INFO_URL : DENO_RELEASE_INFO_URL;
43+
const res = await fetch(url);
3944
if (!res.ok) {
4045
await res.body?.cancel();
4146
throw new Error(
42-
`${res.status}: Unable to retrieve canary version information from ${DENO_CANARY_INFO_URL}.`,
47+
`${res.status}: Unable to retrieve ${
48+
canary ? "canary" : "release"
49+
} version information from ${url}.`,
4350
);
4451
}
45-
const sha = (await res.text()).trim();
52+
const version = (await res.text()).trim();
4653

4754
const filename = name + ".zip";
4855
return {
49-
url: `https://dl.deno.land/canary/${decodeURI(sha)}/${filename}`,
56+
canary,
57+
url: canary
58+
? `https://dl.deno.land/canary/${decodeURI(version)}/${filename}`
59+
: `https://dl.deno.land/release/${decodeURI(version)}/${filename}`,
5060
filename,
51-
version: sha,
61+
version: version,
5262
};
5363
}
5464

@@ -66,7 +76,9 @@ export async function downloadDeno(
6676
throw new Error(`Unexpected empty body`);
6777
}
6878

69-
console.log(`Downloading JSR binary...`);
79+
console.log(
80+
`Downloading JSR ${info.canary ? "canary" : "release"} binary...`,
81+
);
7082

7183
await withProgressBar(
7284
async (tick) => {

test/commands.test.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ describe("install", () => {
197197

198198
assert.match(
199199
pkgJson.dependencies["@std/encoding"],
200-
/^npm:@jsr\/std__encoding@\d+\.\d+\.\d+.*$/,
200+
/^npm:@jsr\/std__encoding@[^]?\d+\.\d+\.\d+.*$/,
201201
);
202202

203203
const npmRc = await readTextFile(path.join(dir, ".npmrc"));
@@ -754,6 +754,28 @@ describe("publish", () => {
754754
});
755755
});
756756
});
757+
758+
it("use deno canary binary when DENO_BIN_CANARY when set", async () => {
759+
await runInTempDir(async (dir) => {
760+
await writeTextFile(
761+
path.join(dir, "mod.ts"),
762+
"export const value = 42;",
763+
);
764+
765+
// TODO: Change this once deno supports jsr.json
766+
await writeJson<DenoJson>(path.join(dir, "deno.json"), {
767+
name: "@deno/jsr-cli-test",
768+
version: "1.0.0",
769+
exports: {
770+
".": "./mod.ts",
771+
},
772+
});
773+
774+
await runJsr(["publish", "--dry-run"], dir, {
775+
DENO_BIN_CANARY: "true",
776+
});
777+
});
778+
});
757779
}
758780
});
759781

0 commit comments

Comments
 (0)