Skip to content

Commit

Permalink
Fix analyzeSplitting function
Browse files Browse the repository at this point in the history
  • Loading branch information
ije committed Jan 8, 2025
1 parent 1cd1536 commit 40ff95c
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions server/build_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1125,35 +1125,28 @@ func (ctx *BuildContext) lexer(entry *BuildEntry) (ret *BuildMeta, cjsExports []
func (ctx *BuildContext) analyzeSplitting() (err error) {
if ctx.bundleMode == BundleDefault && ctx.pkgJson.Exports.Len() > 1 {
exportNames := set.New[string]()
exportAll := false
for _, exportName := range ctx.pkgJson.Exports.keys {
exportName := stripEntryModuleExt(exportName)
if (exportName == "." || strings.HasPrefix(exportName, "./")) && !endsWith(exportName, ".json", ".css", ".wasm", ".d.ts", ".d.mts", ".d.cts") {
if exportName == "./*" {
exportAll = true
break
}
if !strings.ContainsRune(exportName, '*') {
v := ctx.pkgJson.Exports.values[exportName]
if s, ok := v.(string); ok {
if endsWith(s, ".json", ".css", ".wasm", ".d.ts", ".d.mts", ".d.cts") {
continue
}
} else if obj, ok := v.(JSONObject); ok {
// ignore types only exports
if len(obj.keys) == 1 && obj.keys[0] == "types" {
continue
}
if (exportName == "." || (strings.HasPrefix(exportName, "./") && !strings.ContainsRune(exportName, '*'))) && !endsWith(exportName, ".json", ".css", ".wasm", ".d.ts", ".d.mts", ".d.cts") {
v := ctx.pkgJson.Exports.values[exportName]
if s, ok := v.(string); ok {
if endsWith(s, ".json", ".css", ".wasm", ".d.ts", ".d.mts", ".d.cts") {
continue
}
if exportName == "." {
exportNames.Add("")
} else if strings.HasPrefix(exportName, "./") {
exportNames.Add(exportName[2:])
} else if obj, ok := v.(JSONObject); ok {
// ignore types only exports
if len(obj.keys) == 1 && obj.keys[0] == "types" {
continue
}
}
if exportName == "." {
exportNames.Add("")
} else if strings.HasPrefix(exportName, "./") {
exportNames.Add(exportName[2:])
}
}
}
if !exportAll && exportNames.Len() > 1 {
if exportNames.Len() > 1 {
splittingTxtPath := path.Join(ctx.wd, "splitting.txt")
readSplittingTxt := func() bool {
f, err := os.Open(splittingTxtPath)
Expand Down

0 comments on commit 40ff95c

Please sign in to comment.