Skip to content

Commit 369126a

Browse files
committed
Fix getImportPath function (close #1166)
1 parent dfb488e commit 369126a

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

server/build.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,10 @@ func (ctx *BuildContext) buildPath() {
211211
if ctx.dev {
212212
name += ".development"
213213
}
214-
if ctx.bundleMode == BundleDeps {
214+
switch ctx.bundleMode {
215+
case BundleDeps:
215216
name += ".bundle"
216-
} else if ctx.bundleMode == BundleFalse {
217+
case BundleFalse:
217218
name += ".nobundle"
218219
}
219220
ctx.path = fmt.Sprintf(
@@ -1520,9 +1521,10 @@ func (ctx *BuildContext) install() (err error) {
15201521

15211522
// - install dependencies in `BundleDeps` mode
15221523
// - install '@babel/runtime' and '@swc/helpers' if they are present in the dependencies in `BundleDefault` mode
1523-
if ctx.bundleMode == BundleDeps {
1524+
switch ctx.bundleMode {
1525+
case BundleDeps:
15241526
ctx.npmrc.installDependencies(ctx.wd, ctx.pkgJson, false, nil)
1525-
} else if ctx.bundleMode == BundleDefault {
1527+
case BundleDefault:
15261528
if v, ok := ctx.pkgJson.Dependencies["@babel/runtime"]; ok {
15271529
ctx.npmrc.installDependencies(ctx.wd, &npm.PackageJSON{Dependencies: map[string]string{"@babel/runtime": v}}, false, nil)
15281530
}

server/build_resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ func (ctx *BuildContext) resolveDTS(entry BuildEntry) (string, error) {
999999

10001000
func (ctx *BuildContext) getImportPath(esm EsmPath, buildArgsPrefix string, externalAll bool) string {
10011001
if strings.HasSuffix(esm.SubPath, ".json") && ctx.existsPkgFile(esm.SubPath) {
1002-
return esm.Name() + "/" + esm.SubPath + "?module"
1002+
return "/" + esm.Name() + "/" + esm.SubPath + "?module"
10031003
}
10041004
asteriskPrefix := ""
10051005
if externalAll {

server/npmrc.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,10 @@ func (npmrc *NpmRC) getRegistryByPackageName(packageName string) *NpmRegistry {
126126
return &npmrc.NpmRegistry
127127
}
128128

129-
type versionResolver func(metadata *npm.PackageMetadata, version string) (string, error)
130-
131129
func (npmrc *NpmRC) fetchPackageMetadata(pkgName string, version string, useVersionSpecificEndpoint bool) (*npm.PackageMetadata, *npm.PackageJSONRaw, error) {
132130
reg := npmrc.getRegistryByPackageName(pkgName)
133131
regUrl := reg.Registry + pkgName
134-
132+
135133
if useVersionSpecificEndpoint && strings.HasPrefix(regUrl, npmRegistry) {
136134
regUrl += "/" + version
137135
}
@@ -286,7 +284,7 @@ func (npmrc *NpmRC) getPackageInfoByDate(pkgName string, dateVersion string) (pa
286284

287285
reg := npmrc.getRegistryByPackageName(pkgName)
288286
cacheKey := reg.Registry + pkgName + "@date=" + dateVersion
289-
287+
290288
return withCache(cacheKey, time.Duration(config.NpmQueryCacheTTL)*time.Second, func() (*npm.PackageJSON, string, error) {
291289
metadata, _, err := npmrc.fetchPackageMetadata(pkgName, dateVersion, false)
292290
if err != nil {
@@ -308,7 +306,6 @@ func (npmrc *NpmRC) getPackageInfoByDate(pkgName string, dateVersion string) (pa
308306
})
309307
}
310308

311-
312309
func (npmrc *NpmRC) installPackage(pkg npm.Package) (packageJson *npm.PackageJSON, err error) {
313310
installDir := path.Join(npmrc.StoreDir(), pkg.String())
314311
packageJsonPath := path.Join(installDir, "node_modules", pkg.Name, "package.json")

test/issue-1166/test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { assert, assertEquals } from "jsr:@std/assert";
2+
3+
// change the import path to the module you want to test
4+
import { parse } from "http://localhost:8080/[email protected]";
5+
6+
// related issue: https://github.com/esm-dev/esm.sh/issues/1161
7+
Deno.test("testing name", () => {
8+
const config = parse("BASIC=basic"); // will return an object
9+
assertEquals(typeof config, "object");
10+
assert(config);
11+
assertEquals(config.BASIC, "basic");
12+
});

0 commit comments

Comments
 (0)