diff --git a/server/router.go b/server/router.go index f722771d3..34527f140 100644 --- a/server/router.go +++ b/server/router.go @@ -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 { @@ -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" } diff --git a/test/fix-url/test.ts b/test/fix-url/test.ts index ca50e54f8..6fb2f5ba2 100644 --- a/test/fix-url/test.ts +++ b/test/fix-url/test.ts @@ -167,3 +167,16 @@ Deno.test("[workaround] force the dependency version of react equals to react-do const js = await res.text(); assertStringIncludes(js, '"/react@18.2.0/es2022/react.mjs"'); }); + +Deno.test("fix external save path", async () => { + // non-external module + { + const res = await fetch("http://localhost:8080/preact@10.25.4/es2022/hooks.mjs"); + assertStringIncludes(await res.text(), 'from"/preact@10.25.4/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/*preact@10.25.4/es2022/hooks.mjs"); + assertStringIncludes(await res.text(), 'from"preact"'); + } +});