Skip to content

Commit 4d64d78

Browse files
authored
Fix wasm url related to import.meta.url (#1110)
1 parent 384e8ad commit 4d64d78

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

server/router.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ func esmRouter(db Database, buildStorage storage.Storage, logger *log.Logger) re
10861086
if file == "" {
10871087
return rex.Status(404, "File not found")
10881088
}
1089-
url := fmt.Sprintf("%s/%s@%s/%s", origin, esm.PkgName, esm.PkgVersion, file)
1089+
url := fmt.Sprintf("%s%s/%s@%s/%s", origin, registryPrefix, esm.PkgName, esm.PkgVersion, file)
10901090
return redirect(ctx, url, true)
10911091
}
10921092

test/fix-url/test.ts

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,27 +96,42 @@ Deno.test("redirect asset URLs", async () => {
9696
});
9797

9898
Deno.test("Fix wasm URLs with `target` segment", async () => {
99-
const res = await fetch(
100-
"http://localhost:8080/lightningcss-wasm@1.19.0/deno/lightningcss_node.wasm",
101-
{ redirect: "manual" },
102-
);
103-
res.body?.cancel();
104-
assertEquals(res.status, 301);
105-
assertEquals(
106-
res.headers.get("location"),
107-
"http://localhost:8080/lightningcss-wasm@1.19.0/lightningcss_node.wasm",
108-
);
109-
110-
const res2 = await fetch(
111-
"http://localhost:8080/esm-compiler@0.7.2/es2024/esm_compiler_bg.wasm",
112-
{ redirect: "manual" },
113-
);
114-
res2.body?.cancel();
115-
assertEquals(res2.status, 301);
116-
assertEquals(
117-
res2.headers.get("location"),
118-
"http://localhost:8080/esm-compiler@0.7.2/pkg/esm_compiler_bg.wasm",
119-
);
99+
{
100+
const res = await fetch(
101+
"http://localhost:8080/lightningcss-wasm@1.19.0/deno/lightningcss_node.wasm",
102+
{ redirect: "manual" },
103+
);
104+
res.body?.cancel();
105+
assertEquals(res.status, 301);
106+
assertEquals(
107+
res.headers.get("location"),
108+
"http://localhost:8080/lightningcss-wasm@1.19.0/lightningcss_node.wasm",
109+
);
110+
}
111+
{
112+
const res = await fetch(
113+
"http://localhost:8080/esm-compiler@0.7.2/es2024/esm_compiler_bg.wasm",
114+
{ redirect: "manual" },
115+
);
116+
res.body?.cancel();
117+
assertEquals(res.status, 301);
118+
assertEquals(
119+
res.headers.get("location"),
120+
"http://localhost:8080/esm-compiler@0.7.2/pkg/esm_compiler_bg.wasm",
121+
);
122+
}
123+
{
124+
const res = await fetch(
125+
"http://localhost:8080/gh/oxc-project/oxc@7d785c3/es2022/napi/parser/parser.wasm32-wasi.wasm",
126+
{ redirect: "manual" },
127+
);
128+
res.body?.cancel();
129+
assertEquals(res.status, 301);
130+
assertEquals(
131+
res.headers.get("location"),
132+
"http://localhost:8080/gh/oxc-project/oxc@7d785c3/napi/parser/parser.wasm32-wasi.wasm",
133+
);
134+
}
120135
});
121136

122137
Deno.test("Fix json URLs with `target` segment", async () => {

0 commit comments

Comments
 (0)