@@ -869,6 +869,29 @@ export function makeApi(runtimeState: RuntimeState, opts: MakeApiOptions): PnpAp
869
869
}
870
870
}
871
871
872
+ function resolvePrivateRequest ( request : PortablePath , issuer : PortablePath | null , opts : ResolveRequestOptions ) {
873
+ if ( ! issuer )
874
+ throw new Error ( `Assertion failed: An issuer is required to resolve private import mappings` ) ;
875
+
876
+ const resolved = packageImportsResolve ( {
877
+ name : request ,
878
+ base : pathToFileURL ( npath . fromPortablePath ( issuer ) ) ,
879
+ conditions : opts . conditions ?? defaultExportsConditions ,
880
+ readFileSyncFn : tryReadFile ,
881
+ } ) ;
882
+
883
+ if ( resolved instanceof URL ) {
884
+ return resolveUnqualified ( npath . toPortablePath ( fileURLToPath ( resolved ) ) , { extensions : opts . extensions } ) ;
885
+ } else {
886
+ if ( resolved . startsWith ( `#` ) )
887
+ // Node behaves interestingly by default so just block the request for now.
888
+ // https://github.com/nodejs/node/issues/40579
889
+ throw new Error ( `Mapping from one private import to another isn't allowed` ) ;
890
+
891
+ return resolveRequest ( resolved as PortablePath , issuer , opts ) ;
892
+ }
893
+ }
894
+
872
895
/**
873
896
* Transforms a request into a fully qualified path.
874
897
*
@@ -877,30 +900,12 @@ export function makeApi(runtimeState: RuntimeState, opts: MakeApiOptions): PnpAp
877
900
* imports won't be computed correctly (they'll get resolved relative to "/tmp/" instead of "/tmp/foo/").
878
901
*/
879
902
880
- function resolveRequest ( request : PortablePath , issuer : PortablePath | null , { considerBuiltins , extensions , conditions } : ResolveRequestOptions = { } ) : PortablePath | null {
903
+ function resolveRequest ( request : PortablePath , issuer : PortablePath | null , opts : ResolveRequestOptions = { } ) : PortablePath | null {
881
904
try {
882
- if ( request . startsWith ( `#` ) ) {
883
- if ( ! issuer )
884
- throw new Error ( `Assertion failed: An issuer is required to resolve private import mappings` ) ;
885
-
886
- const resolved = packageImportsResolve ( {
887
- name : request ,
888
- base : pathToFileURL ( npath . fromPortablePath ( issuer ) ) ,
889
- conditions : conditions ?? defaultExportsConditions ,
890
- readFileSyncFn : tryReadFile ,
891
- } ) ;
892
-
893
- if ( resolved instanceof URL ) {
894
- return resolveUnqualified ( npath . toPortablePath ( fileURLToPath ( resolved ) ) , { extensions} ) ;
895
- } else {
896
- if ( resolved . startsWith ( `#` ) )
897
- // Node behaves interestingly by default so just block the request for now.
898
- // https://github.com/nodejs/node/issues/40579
899
- throw new Error ( `Mapping from one private import to another isn't allowed` ) ;
905
+ if ( request . startsWith ( `#` ) )
906
+ return resolvePrivateRequest ( request , issuer , opts ) ;
900
907
901
- return resolveRequest ( resolved as PortablePath , issuer , { conditions, considerBuiltins, extensions} ) ;
902
- }
903
- }
908
+ const { considerBuiltins, extensions, conditions} = opts ;
904
909
905
910
const unqualifiedPath = resolveToUnqualified ( request , issuer , { considerBuiltins} ) ;
906
911
0 commit comments