Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build save path with '?external=*' #1036

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"');
}
});
Loading