Skip to content

Commit bcbcd20

Browse files
authored
Fix browser condition for astring (#1200)
1 parent 89d8992 commit bcbcd20

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

server/build_resolver.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,15 @@ func (ctx *BuildContext) resolveConditionExportEntry(conditions npm.JSONObject,
578578
var conditionFound bool
579579

580580
if ctx.isBrowserTarget() {
581-
conditionFound = applyCondition("browser")
581+
conditionName := "browser"
582+
// [workaround] fix astring entry in browser
583+
if ctx.esmPath.PkgName == "astring" {
584+
conditionName = "import"
585+
}
586+
conditionFound = applyCondition(conditionName)
582587
} else if ctx.isDenoTarget() {
583588
conditionName := "deno"
584-
// [workaround] to support ssr in Deno, use `node` condition for solid-js < 1.6.0
589+
// [workaround] to support solid-js/ssr in Deno, use `node` condition for < 1.6.0
585590
if ctx.esmPath.PkgName == "solid-js" && semverLessThan(ctx.esmPath.PkgVersion, "1.6.0") {
586591
conditionName = "node"
587592
}
@@ -607,7 +612,7 @@ LOOP:
607612
module := false
608613
prefered := ""
609614
switch conditionName {
610-
case "module", "import", "es2015":
615+
case "import", "module", "es2015":
611616
module = true
612617
prefered = "module"
613618
case "require":

test/issue-1199/test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { assert } from "jsr:@std/assert";
2+
3+
// related issue: https://github.com/esm-dev/esm.sh/issues/1199
4+
Deno.test(
5+
"fix astring entry in browser",
6+
async () => {
7+
const mod = await import("http://localhost:8080/astring@1.9.0?target=es2022");
8+
assert(typeof mod.generate === "function");
9+
},
10+
);

0 commit comments

Comments
 (0)