@@ -334,11 +334,13 @@ func (ctx *BuildContext) buildModule() (result BuildResult, err error) {
334
334
func (args api.OnResolveArgs ) (api.OnResolveResult , error ) {
335
335
// if it's the entry module
336
336
if args .Path == entryPoint || args .Path == entryModuleSpecifier {
337
- if entry .esm != "" {
338
- return api.OnResolveResult {Path : path .Join (ctx .pnpmPkgDir , entry .esm )}, nil
339
- }
340
- if entry .cjs != "" {
341
- return api.OnResolveResult {Path : path .Join (ctx .pnpmPkgDir , entry .cjs )}, nil
337
+ if args .Path == entryModuleSpecifier {
338
+ if entry .esm != "" {
339
+ return api.OnResolveResult {Path : path .Join (ctx .pnpmPkgDir , entry .esm )}, nil
340
+ }
341
+ if entry .cjs != "" {
342
+ return api.OnResolveResult {Path : path .Join (ctx .pnpmPkgDir , entry .cjs )}, nil
343
+ }
342
344
}
343
345
return api.OnResolveResult {}, nil
344
346
}
@@ -525,7 +527,7 @@ func (ctx *BuildContext) buildModule() (result BuildResult, err error) {
525
527
}
526
528
527
529
// bundle "@babel/runtime/*"
528
- if (args .Kind == api .ResolveJSRequireCall || ! noBundle ) && ctx .pkgJson .Name != "@babel/runtime" && (strings .HasPrefix (specifier , "@babel/runtime/" ) || strings .Contains (args .Importer , "/@babel/runtime/" )) {
530
+ if (args .Kind != api .ResolveJSDynamicImport && ! noBundle ) && ctx .pkgJson .Name != "@babel/runtime" && (strings .HasPrefix (specifier , "@babel/runtime/" ) || strings .Contains (args .Importer , "/@babel/runtime/" )) {
529
531
return api.OnResolveResult {}, nil
530
532
}
531
533
@@ -610,10 +612,10 @@ func (ctx *BuildContext) buildModule() (result BuildResult, err error) {
610
612
}
611
613
if match {
612
614
exportPrefix , _ := utils .SplitByLastByte (exportName , '*' )
613
- url := path .Join (ctx .pkgJson .Name , exportPrefix + strings .TrimPrefix (bareName , prefix ))
614
- if i : = entryModuleSpecifier ; url != i && url != i + "/index" {
615
+ exportModuleName := path .Join (ctx .pkgJson .Name , exportPrefix + strings .TrimPrefix (bareName , prefix ))
616
+ if exportModuleName ! = entryModuleSpecifier && exportModuleName != entryModuleSpecifier + "/index" {
615
617
return api.OnResolveResult {
616
- Path : ctx .resolveExternalModule (url , args .Kind ),
618
+ Path : ctx .resolveExternalModule (exportModuleName , args .Kind ),
617
619
External : true ,
618
620
SideEffects : pkgSideEffects ,
619
621
}, nil
@@ -637,10 +639,10 @@ func (ctx *BuildContext) buildModule() (result BuildResult, err error) {
637
639
}
638
640
}
639
641
if match {
640
- url := path .Join (ctx .pkgJson .Name , stripModuleExt (exportName ))
641
- if i : = entryModuleSpecifier ; url != i && url != i + "/index" {
642
+ exportModuleName := path .Join (ctx .pkgJson .Name , stripModuleExt (exportName ))
643
+ if exportModuleName ! = entryModuleSpecifier && exportModuleName != entryModuleSpecifier + "/index" {
642
644
return api.OnResolveResult {
643
- Path : ctx .resolveExternalModule (url , args .Kind ),
645
+ Path : ctx .resolveExternalModule (exportModuleName , args .Kind ),
644
646
External : true ,
645
647
SideEffects : pkgSideEffects ,
646
648
}, nil
@@ -650,8 +652,14 @@ func (ctx *BuildContext) buildModule() (result BuildResult, err error) {
650
652
}
651
653
}
652
654
655
+ // module file path
653
656
moduleFilepath := path .Join (ctx .pnpmPkgDir , moduleSpecifier )
654
657
658
+ // if it's the entry module
659
+ if moduleSpecifier == entry .cjs || moduleSpecifier == entry .esm {
660
+ return api.OnResolveResult {Path : moduleFilepath }, nil
661
+ }
662
+
655
663
// split the module that is an alias of a dependency
656
664
// means this file just include a single line(js): `export * from "dep"`
657
665
fi , ioErr := os .Lstat (moduleFilepath )
@@ -678,9 +686,7 @@ func (ctx *BuildContext) buildModule() (result BuildResult, err error) {
678
686
// bundle the internal module if it's not a dynamic import or `?bundle=false` query present
679
687
if args .Kind != api .ResolveJSDynamicImport && ! noBundle {
680
688
if existsFile (moduleFilepath ) {
681
- return api.OnResolveResult {
682
- Path : moduleFilepath ,
683
- }, nil
689
+ return api.OnResolveResult {Path : moduleFilepath }, nil
684
690
}
685
691
// let esbuild to handle it
686
692
return api.OnResolveResult {}, nil
0 commit comments