diff --git a/internal/bundler/bundler.go b/internal/bundler/bundler.go index 7c2f2b8e62c..c018a8b8a4b 100644 --- a/internal/bundler/bundler.go +++ b/internal/bundler/bundler.go @@ -457,7 +457,7 @@ func parseFile(args parseArgs) { // All "require.resolve()" imports should be external because we don't // want to waste effort traversing into them if record.Kind == ast.ImportRequireResolve { - if resolveResult != nil && resolveResult.IsExternal { + if resolveResult != nil && resolveResult.PathPair.IsExternal { // Allow path substitution as long as the result is external result.resolveResults[importRecordIndex] = resolveResult } else if !record.Flags.Has(ast.HandlesImportErrors) { @@ -926,8 +926,7 @@ func RunOnResolvePlugins( } return &resolver.ResolveResult{ - PathPair: resolver.PathPair{Primary: result.Path}, - IsExternal: result.External, + PathPair: resolver.PathPair{Primary: result.Path, IsExternal: result.External}, PluginData: result.PluginData, PrimarySideEffectsData: sideEffectsData, }, false, resolver.DebugMeta{} @@ -1580,7 +1579,7 @@ func (s *scanner) preprocessInjectedFiles() { nil, ) if resolveResult != nil { - if resolveResult.IsExternal { + if resolveResult.PathPair.IsExternal { s.log.AddError(nil, logger.Range{}, fmt.Sprintf("The injected path %q cannot be marked as external", importPath)) } else { injectResolveResults[i] = resolveResult @@ -1759,7 +1758,7 @@ func (s *scanner) addEntryPoints(entryPoints []EntryPoint) []graph.EntryPoint { nil, ) if resolveResult != nil { - if resolveResult.IsExternal { + if resolveResult.PathPair.IsExternal { s.log.AddError(nil, logger.Range{}, fmt.Sprintf("The entry point %q cannot be marked as external", entryPoint.InputPath)) } else { entryPointInfos[i] = entryPointInfo{results: []resolver.ResolveResult{*resolveResult}} @@ -1975,7 +1974,7 @@ func (s *scanner) scanAllDependencies() { } path := resolveResult.PathPair.Primary - if !resolveResult.IsExternal { + if !resolveResult.PathPair.IsExternal { // Handle a path within the bundle sourceIndex := s.maybeParseFile(*resolveResult, resolver.PrettyPath(s.fs, path), &result.file.inputFile.Source, record.Range, inputKindNormal, nil) @@ -2036,7 +2035,7 @@ func (s *scanner) generateResultForGlobResolve( importRecordIndex := uint32(len(importRecords)) var sourceIndex ast.Index32 - if !resolveResult.IsExternal { + if !resolveResult.PathPair.IsExternal { sourceIndex = ast.MakeIndex32(s.maybeParseFile( resolveResult, resolver.PrettyPath(s.fs, resolveResult.PathPair.Primary), diff --git a/internal/resolver/resolver.go b/internal/resolver/resolver.go index 77703b0d0ad..194a82a2a15 100644 --- a/internal/resolver/resolver.go +++ b/internal/resolver/resolver.go @@ -69,6 +69,8 @@ type PathPair struct { // will be "main" Primary logger.Path Secondary logger.Path + + IsExternal bool } func (pp *PathPair) iter() []*logger.Path { @@ -114,8 +116,6 @@ type ResolveResult struct { // This is the "type" field from "package.json" ModuleTypeData js_ast.ModuleTypeData - - IsExternal bool } type suggestionRange uint8 @@ -431,8 +431,7 @@ func (res *Resolver) Resolve(sourceDir string, importPath string, kind ast.Impor r.flushDebugLogs(flushDueToSuccess) return &ResolveResult{ - PathPair: PathPair{Primary: logger.Path{Text: importPath}}, - IsExternal: true, + PathPair: PathPair{Primary: logger.Path{Text: importPath}, IsExternal: true}, }, debugMeta } @@ -444,8 +443,7 @@ func (res *Resolver) Resolve(sourceDir string, importPath string, kind ast.Impor r.flushDebugLogs(flushDueToSuccess) return &ResolveResult{ - PathPair: PathPair{Primary: logger.Path{Text: importPath}}, - IsExternal: true, + PathPair: PathPair{Primary: logger.Path{Text: importPath}, IsExternal: true}, PrimarySideEffectsData: &SideEffectsData{}, // Mark this with "sideEffects: false" }, debugMeta } @@ -491,8 +489,7 @@ func (res *Resolver) Resolve(sourceDir string, importPath string, kind ast.Impor r.flushDebugLogs(flushDueToSuccess) return &ResolveResult{ - PathPair: PathPair{Primary: logger.Path{Text: importPath}}, - IsExternal: true, + PathPair: PathPair{Primary: logger.Path{Text: importPath}, IsExternal: true}, PrimarySideEffectsData: sideEffects, }, debugMeta } @@ -516,8 +513,7 @@ func (res *Resolver) Resolve(sourceDir string, importPath string, kind ast.Impor } r.flushDebugLogs(flushDueToSuccess) return &ResolveResult{ - PathPair: PathPair{Primary: logger.Path{Text: importPath}}, - IsExternal: true, + PathPair: PathPair{Primary: logger.Path{Text: importPath}, IsExternal: true}, }, debugMeta } @@ -730,8 +726,7 @@ func (res *Resolver) ResolveGlob(sourceDir string, importPathPattern []helpers.G var result ResolveResult if r.isExternal(r.options.ExternalSettings.PreResolve, relPath, kind) { - result.PathPair = PathPair{Primary: logger.Path{Text: relPath}} - result.IsExternal = true + result.PathPair = PathPair{Primary: logger.Path{Text: relPath}, IsExternal: true} if r.debugLogs != nil { r.debugLogs.addNote(fmt.Sprintf("The path %q was marked as external by the user", result.PathPair.Primary.Text)) @@ -847,11 +842,11 @@ func (r resolverQuery) flushDebugLogs(mode flushMode) { } func (r resolverQuery) finalizeResolve(result *ResolveResult) { - if !result.IsExternal && r.isExternal(r.options.ExternalSettings.PostResolve, result.PathPair.Primary.Text, r.kind) { + if !result.PathPair.IsExternal && r.isExternal(r.options.ExternalSettings.PostResolve, result.PathPair.Primary.Text, r.kind) { if r.debugLogs != nil { r.debugLogs.addNote(fmt.Sprintf("The path %q was marked as external by the user", result.PathPair.Primary.Text)) } - result.IsExternal = true + result.PathPair.IsExternal = true } else { for i, path := range result.PathPair.iter() { if path.Namespace != "file" { @@ -1024,8 +1019,7 @@ func (r resolverQuery) resolveWithoutSymlinks(sourceDir string, sourceDirInfo *d r.flushDebugLogs(flushDueToSuccess) return &ResolveResult{ - PathPair: PathPair{Primary: logger.Path{Text: importPath}}, - IsExternal: true, + PathPair: PathPair{Primary: logger.Path{Text: importPath}, IsExternal: true}, } } @@ -1037,7 +1031,7 @@ func (r resolverQuery) resolveWithoutSymlinks(sourceDir string, sourceDirInfo *d if r.debugLogs != nil { r.debugLogs.addNote(fmt.Sprintf("The path %q was marked as external by the user", absPath)) } - return &ResolveResult{PathPair: PathPair{Primary: logger.Path{Text: absPath, Namespace: "file"}}, IsExternal: true} + return &ResolveResult{PathPair: PathPair{Primary: logger.Path{Text: absPath, Namespace: "file"}, IsExternal: true}} } // Check the "browser" map diff --git a/pkg/api/api_impl.go b/pkg/api/api_impl.go index d8b919758ee..513dbba61f3 100644 --- a/pkg/api/api_impl.go +++ b/pkg/api/api_impl.go @@ -2099,7 +2099,7 @@ func loadPlugins(initialOptions *BuildOptions, fs fs.FS, log logger.Log, caches result.Warnings = convertMessagesToPublic(logger.Warning, msgs) if resolveResult != nil { result.Path = resolveResult.PathPair.Primary.Text - result.External = resolveResult.IsExternal + result.External = resolveResult.PathPair.IsExternal result.SideEffects = resolveResult.PrimarySideEffectsData == nil result.Namespace = resolveResult.PathPair.Primary.Namespace result.Suffix = resolveResult.PathPair.Primary.IgnoredSuffix