Skip to content

Commit 8474431

Browse files
authored
Fix module resolver with imports of package.json (#1094)
1 parent 427a4b0 commit 8474431

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

server/build.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,15 +469,21 @@ func (ctx *BuildContext) buildModule(analyzeMode bool) (meta *BuildMeta, include
469469
// check tailing slash
470470
pkgName, _, subPath, _ := splitEsmPath(specifier)
471471
v, ok = pkgJson.Imports[pkgName]
472+
if !ok {
473+
v, ok = pkgJson.Imports[pkgName+"/"]
474+
}
472475
if ok && subPath != "" {
473476
if s, ok := v.(string); ok {
474-
v = s + "/" + subPath
477+
v = strings.TrimSuffix(s, "/") + "/" + subPath
475478
}
476479
}
477480
}
478481
if ok {
479482
if s, ok := v.(string); ok {
480483
specifier = normalizeImportSpecifier(s)
484+
if isRelPathSpecifier(specifier) {
485+
specifier = ctx.esm.PkgName + "/" + strings.TrimPrefix(specifier, "./")
486+
}
481487
} else if m, ok := v.(map[string]interface{}); ok {
482488
targets := []string{"browser", "module", "import", "default"}
483489
if ctx.isDenoTarget() {

server/router.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,6 @@ func esmRouter(db Database, buildStorage storage.Storage, logger *log.Logger) re
15721572
}
15731573
}
15741574

1575-
BUILD:
15761575
build := &BuildContext{
15771576
npmrc: npmrc,
15781577
logger: logger,
@@ -1673,7 +1672,7 @@ func esmRouter(db Database, buildStorage storage.Storage, logger *log.Logger) re
16731672
key := npmrc.zoneId + ":" + build.Path()
16741673
db.Delete(key)
16751674
cacheStore.Delete("lru:" + key)
1676-
goto BUILD
1675+
return rex.Status(500, "Storage error")
16771676
}
16781677
return rex.Status(500, err.Error())
16791678
}

test/valtown/test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { assertEquals, assertExists } from "jsr:@std/assert";
2+
3+
import ValTown from "http://localhost:8080/@valtown/sdk@0.30.0";
4+
5+
Deno.test("valtown SDK", () => {
6+
assertEquals(typeof ValTown, "function");
7+
const valtown = new ValTown({ bearerToken: "My Bearer Token" });
8+
assertExists(valtown, "emails");
9+
});

0 commit comments

Comments
 (0)