Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ije committed Nov 17, 2023
1 parent 58a81f4 commit ce4baf0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 6 additions & 10 deletions server/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,10 @@ rebuild:
}

if isLocalSpecifier(specifier) {
// sub-module of current package and non-dynamic import
// is sub-module of current package and non-dynamic import
if strings.HasPrefix(fullFilepath, task.realWd) && args.Kind != api.ResolveJSDynamicImport {
relPath := "." + strings.TrimPrefix(fullFilepath, path.Join(task.installDir, "node_modules", npm.Name))
// splits modules based on the `exports` defines in package.json,
// split modules based on the `exports` defines in package.json,
// see https://nodejs.org/api/packages.html
if om, ok := npm.PkgExports.(*orderedMap); ok {
modName := relPath
Expand Down Expand Up @@ -580,17 +580,16 @@ rebuild:
}
}

// externalize the sub module that is in the `sideEffects` field(as list)
// split the sub module that is in the `sideEffects` field(as list)
if npm.SideEffects != nil {
if npm.SideEffects.Has(relPath) || npm.SideEffects.Has(strings.TrimPrefix(relPath, "./")) {
url := path.Join(npm.Name, relPath)
return api.OnResolveResult{Path: task.resolveExternal(url, args.Kind), External: true}, nil
}
}

// externalize the module that is an alias of a dependency
// split the module that is an alias of a dependency
// means this file just include a single line(js): `export * from "dep"`
isAlias := false
fi, ioErr := os.Lstat(fullFilepath)
if ioErr == nil && fi.Size() < 256 {
data, ioErr := os.ReadFile(fullFilepath)
Expand All @@ -601,17 +600,14 @@ rebuild:
if len(p) == 3 && string(p[0]) == "export*from" && string(p[2]) == ";\n" {
url := string(p[1])
if !isLocalSpecifier(url) {
specifier = url
isAlias = true
return api.OnResolveResult{Path: task.resolveExternal(url, args.Kind), External: true}, nil
}
}
}
}
}

if !isAlias {
return api.OnResolveResult{}, nil
}
return api.OnResolveResult{}, nil
}

specifier = strings.TrimPrefix(fullFilepath, filepath.Join(task.installDir, "node_modules")+"/")
Expand Down
4 changes: 3 additions & 1 deletion server/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ func (a *NpmPackageJSON) ToNpmPackage() *NpmPackageInfo {
var v interface{}
if json.Unmarshal(rawExports, &v) == nil {
if s, ok := v.(string); ok {
pkgExports = s
if len(s) > 0 {
pkgExports = s
}
} else if _, ok := v.(map[string]interface{}); ok {
om := newOrderedMap()
if om.UnmarshalJSON(rawExports) == nil {
Expand Down

0 comments on commit ce4baf0

Please sign in to comment.