Skip to content

Commit 52b46e2

Browse files
authored
Fix build save path with '?external=*' (#1036)
1 parent 4751fd6 commit 52b46e2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

server/router.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,9 @@ func esmRouter(db DB, buildStorage storage.Storage) rex.Handle {
12011201
// build/dts files
12021202
if pathKind == EsmBuild || pathKind == EsmSourceMap || pathKind == EsmDts {
12031203
var savePath string
1204+
if asteriskPrefix {
1205+
pathname = "/*" + pathname[1:]
1206+
}
12041207
if pathKind == EsmDts {
12051208
savePath = path.Join("types", pathname)
12061209
} else {
@@ -1654,7 +1657,7 @@ func esmRouter(db DB, buildStorage storage.Storage) rex.Handle {
16541657
return buf.Bytes()
16551658
}
16561659
savePath := buildCtx.getSavepath()
1657-
if strings.HasSuffix(esm.SubPath, ".css") {
1660+
if strings.HasSuffix(esm.SubPath, ".css") && ret.CSSInJS {
16581661
path, _ := utils.SplitByLastByte(savePath, '.')
16591662
savePath = path + ".css"
16601663
}

test/fix-url/test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,16 @@ Deno.test("[workaround] force the dependency version of react equals to react-do
167167
const js = await res.text();
168168
assertStringIncludes(js, '"/[email protected]/es2022/react.mjs"');
169169
});
170+
171+
Deno.test("fix external save path", async () => {
172+
// non-external module
173+
{
174+
const res = await fetch("http://localhost:8080/[email protected]/es2022/hooks.mjs");
175+
assertStringIncludes(await res.text(), 'from"/[email protected]/es2022/preact.mjs"');
176+
}
177+
// in https://github.com/preactjs/preact-www/issues/1225, the module returns the non-external module
178+
{
179+
const res = await fetch("http://localhost:8080/*[email protected]/es2022/hooks.mjs");
180+
assertStringIncludes(await res.text(), 'from"preact"');
181+
}
182+
});

0 commit comments

Comments
 (0)