Skip to content

Commit

Permalink
Fix build save path with '?external=*' (#1036)
Browse files Browse the repository at this point in the history
  • Loading branch information
ije authored Jan 16, 2025
1 parent 4751fd6 commit 52b46e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,9 @@ func esmRouter(db DB, buildStorage storage.Storage) rex.Handle {
// build/dts files
if pathKind == EsmBuild || pathKind == EsmSourceMap || pathKind == EsmDts {
var savePath string
if asteriskPrefix {
pathname = "/*" + pathname[1:]
}
if pathKind == EsmDts {
savePath = path.Join("types", pathname)
} else {
Expand Down Expand Up @@ -1654,7 +1657,7 @@ func esmRouter(db DB, buildStorage storage.Storage) rex.Handle {
return buf.Bytes()
}
savePath := buildCtx.getSavepath()
if strings.HasSuffix(esm.SubPath, ".css") {
if strings.HasSuffix(esm.SubPath, ".css") && ret.CSSInJS {
path, _ := utils.SplitByLastByte(savePath, '.')
savePath = path + ".css"
}
Expand Down
13 changes: 13 additions & 0 deletions test/fix-url/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,16 @@ Deno.test("[workaround] force the dependency version of react equals to react-do
const js = await res.text();
assertStringIncludes(js, '"/[email protected]/es2022/react.mjs"');
});

Deno.test("fix external save path", async () => {
// non-external module
{
const res = await fetch("http://localhost:8080/[email protected]/es2022/hooks.mjs");
assertStringIncludes(await res.text(), 'from"/[email protected]/es2022/preact.mjs"');
}
// in https://github.com/preactjs/preact-www/issues/1225, the module returns the non-external module
{
const res = await fetch("http://localhost:8080/*[email protected]/es2022/hooks.mjs");
assertStringIncludes(await res.text(), 'from"preact"');
}
});

0 comments on commit 52b46e2

Please sign in to comment.