@@ -33,7 +33,6 @@ import {
33
33
isTsRequest ,
34
34
isWindows ,
35
35
lookupFile ,
36
- nestedResolveFrom ,
37
36
normalizePath ,
38
37
resolveFrom ,
39
38
slash ,
@@ -645,32 +644,20 @@ export function tryNodeResolve(
645
644
options : InternalResolveOptionsWithOverrideConditions ,
646
645
targetWeb : boolean ,
647
646
depsOptimizer ?: DepsOptimizer ,
648
- ssr ? : boolean ,
647
+ ssr : boolean = false ,
649
648
externalize ?: boolean ,
650
649
allowLinkedExternal : boolean = true ,
651
650
) : PartialResolvedId | undefined {
652
651
const { root, dedupe, isBuild, preserveSymlinks, packageCache } = options
653
652
654
- ssr ??= false
655
-
656
- // split id by last '>' for nested selected packages, for example:
657
- // 'foo > bar > baz' => 'foo > bar' & 'baz'
658
- // 'foo' => '' & 'foo'
659
- const lastArrowIndex = id . lastIndexOf ( '>' )
660
- const nestedRoot = id . substring ( 0 , lastArrowIndex ) . trim ( )
661
- const nestedPath = id . substring ( lastArrowIndex + 1 ) . trim ( )
662
-
663
653
const possiblePkgIds : string [ ] = [ ]
664
654
for ( let prevSlashIndex = - 1 ; ; ) {
665
- let slashIndex = nestedPath . indexOf ( '/' , prevSlashIndex + 1 )
655
+ let slashIndex = id . indexOf ( '/' , prevSlashIndex + 1 )
666
656
if ( slashIndex < 0 ) {
667
- slashIndex = nestedPath . length
657
+ slashIndex = id . length
668
658
}
669
659
670
- const part = nestedPath . slice (
671
- prevSlashIndex + 1 ,
672
- ( prevSlashIndex = slashIndex ) ,
673
- )
660
+ const part = id . slice ( prevSlashIndex + 1 , ( prevSlashIndex = slashIndex ) )
674
661
if ( ! part ) {
675
662
break
676
663
}
@@ -683,7 +670,7 @@ export function tryNodeResolve(
683
670
continue
684
671
}
685
672
686
- const possiblePkgId = nestedPath . slice ( 0 , slashIndex )
673
+ const possiblePkgId = id . slice ( 0 , slashIndex )
687
674
possiblePkgIds . push ( possiblePkgId )
688
675
}
689
676
@@ -700,11 +687,6 @@ export function tryNodeResolve(
700
687
basedir = root
701
688
}
702
689
703
- // nested node module, step-by-step resolve to the basedir of the nestedPath
704
- if ( nestedRoot ) {
705
- basedir = nestedResolveFrom ( nestedRoot , basedir , preserveSymlinks )
706
- }
707
-
708
690
let pkg : PackageData | undefined
709
691
let pkgId : string | undefined
710
692
// nearest package.json
@@ -742,9 +724,9 @@ export function tryNodeResolve(
742
724
// if so, we can resolve to a special id that errors only when imported.
743
725
if (
744
726
basedir !== root && // root has no peer dep
745
- ! isBuiltin ( nestedPath ) &&
746
- ! nestedPath . includes ( '\0' ) &&
747
- bareImportRE . test ( nestedPath )
727
+ ! isBuiltin ( id ) &&
728
+ ! id . includes ( '\0' ) &&
729
+ bareImportRE . test ( id )
748
730
) {
749
731
// find package.json with `name` as main
750
732
const mainPackageJson = lookupFile ( basedir , [ 'package.json' ] , {
@@ -753,11 +735,11 @@ export function tryNodeResolve(
753
735
if ( mainPackageJson ) {
754
736
const mainPkg = JSON . parse ( mainPackageJson )
755
737
if (
756
- mainPkg . peerDependencies ?. [ nestedPath ] &&
757
- mainPkg . peerDependenciesMeta ?. [ nestedPath ] ?. optional
738
+ mainPkg . peerDependencies ?. [ id ] &&
739
+ mainPkg . peerDependenciesMeta ?. [ id ] ?. optional
758
740
) {
759
741
return {
760
- id : `${ optionalPeerDepId } :${ nestedPath } :${ mainPkg . name } ` ,
742
+ id : `${ optionalPeerDepId } :${ id } :${ mainPkg . name } ` ,
761
743
}
762
744
}
763
745
}
@@ -767,10 +749,10 @@ export function tryNodeResolve(
767
749
768
750
let resolveId = resolvePackageEntry
769
751
let unresolvedId = pkgId
770
- const isDeepImport = unresolvedId !== nestedPath
752
+ const isDeepImport = unresolvedId !== id
771
753
if ( isDeepImport ) {
772
754
resolveId = resolveDeepImport
773
- unresolvedId = '.' + nestedPath . slice ( pkgId . length )
755
+ unresolvedId = '.' + id . slice ( pkgId . length )
774
756
}
775
757
776
758
let resolved : string | undefined
@@ -865,16 +847,14 @@ export function tryNodeResolve(
865
847
! isJsType ||
866
848
importer ?. includes ( 'node_modules' ) ||
867
849
exclude ?. includes ( pkgId ) ||
868
- exclude ?. includes ( nestedPath ) ||
850
+ exclude ?. includes ( id ) ||
869
851
SPECIAL_QUERY_RE . test ( resolved ) ||
870
852
// During dev SSR, we don't have a way to reload the module graph if
871
853
// a non-optimized dep is found. So we need to skip optimization here.
872
854
// The only optimized deps are the ones explicitly listed in the config.
873
855
( ! options . ssrOptimizeCheck && ! isBuild && ssr ) ||
874
856
// Only optimize non-external CJS deps during SSR by default
875
- ( ssr &&
876
- ! isCJS &&
877
- ! ( include ?. includes ( pkgId ) || include ?. includes ( nestedPath ) ) )
857
+ ( ssr && ! isCJS && ! ( include ?. includes ( pkgId ) || include ?. includes ( id ) ) )
878
858
879
859
if ( options . ssrOptimizeCheck ) {
880
860
return {
0 commit comments