@@ -640,6 +640,19 @@ export default class StateManager {
640640
641641 const [_packageName, projectDir] = pkgInfo;
642642
643+ const resolveAliasPaths = (value: string | $ReadOnlyArray< string > ) =>
644+ ( Array . isArray ( value ) ? value : [ value ] ) . map ( ( p ) => {
645+ const endsWithStar = p . endsWith ( '/*' ) ;
646+ let basePath = p . replace ( / \/ \* $ / , '' ) ;
647+ if ( basePath . startsWith ( '.' ) ) {
648+ basePath = path . resolve ( projectDir , basePath ) ;
649+ }
650+ if ( endsWithStar ) {
651+ basePath = basePath . endsWith ( '/' ) ? basePath + '*' : basePath + '/*' ;
652+ }
653+ return basePath ;
654+ } );
655+
643656 // Load aliases from package.json imports field
644657 try {
645658 const packageJsonPath = path . join ( projectDir , 'package.json' ) ;
@@ -658,10 +671,7 @@ export default class StateManager {
658671 packageAliases = Object . fromEntries (
659672 Object . entries ( imports )
660673 . filter ( ( [ key ] ) => key . startsWith ( '#' ) )
661- . map ( ( [ key , value ] ) => [
662- key . slice ( 1 ) ,
663- Array . isArray ( value ) ? value : [ value ] ,
664- ] ) ,
674+ . map ( ( [ key , value ] ) => [ key . slice ( 1 ) , resolveAliasPaths ( value ) ] ) ,
665675 ) ;
666676 }
667677 }
@@ -680,25 +690,13 @@ export default class StateManager {
680690 throw new Error ( 'Invalid tsconfig.json format' ) ;
681691 }
682692 const tsconfig : TSConfig = rawConfig as $FlowFixMe ;
683- const baseUrl = tsconfig . compilerOptions ?. baseUrl || '.' ;
684- if ( tsconfig . compilerOptions ?. paths ) {
693+ const tsConfigAliasPaths = tsconfig . compilerOptions ?. paths ;
694+ if ( tsConfigAliasPaths != null && isImportsObject ( tsConfigAliasPaths ) ) {
685695 tsconfigAliases = Object . fromEntries (
686- Object . entries ( tsconfig . compilerOptions . paths ) . map (
687- ( [ key , value ] ) => [
688- key . replace ( / \/ \* $ / , '' ) ,
689- Array . isArray ( value )
690- ? value . map ( ( p ) =>
691- this . normalizePath (
692- path . join ( baseUrl , p . replace ( / \/ \* $ / , '' ) ) ,
693- ) ,
694- )
695- : [
696- this . normalizePath (
697- path . join ( baseUrl , value . replace ( / \/ \* $ / , '' ) ) ,
698- ) ,
699- ] ,
700- ] ,
701- ) ,
696+ Object . entries ( tsConfigAliasPaths ) . map ( ( [ key , value ] ) => [
697+ key ,
698+ resolveAliasPaths ( value ) ,
699+ ] ) ,
702700 ) ;
703701 }
704702 }
@@ -719,10 +717,9 @@ export default class StateManager {
719717 const denoConfig : DenoConfig = rawConfig as $FlowFixMe ;
720718 if ( denoConfig . imports ) {
721719 denoAliases = Object . fromEntries (
722- Object . entries ( denoConfig . imports ) . map ( ( [ key , value ] ) => [
723- key ,
724- Array . isArray ( value ) ? value : [ value ] ,
725- ] ) ,
720+ Object . entries ( denoConfig . imports ) . map ( ( [ key , value ] ) => {
721+ return [ key , resolveAliasPaths ( value ) ] ;
722+ } ) ,
726723 ) ;
727724 }
728725 }
@@ -899,15 +896,21 @@ function formatRelativePath(filePath: string) {
899896 return filePath . startsWith ( '.' ) ? filePath : './' + filePath ;
900897}
901898
902- function isPackageJSON ( obj : mixed ) : boolean % checks {
899+ function isImportsObject ( obj : mixed ) : implies obj is { ... } {
900+ return obj != null && typeof obj === 'object' ;
901+ }
902+
903+ function isPackageJSON ( obj : mixed ) : implies obj is { + imports : mixed , ... } {
903904 return (
904905 obj != null &&
905906 typeof obj === 'object' &&
906907 ( ! ( 'imports' in obj ) || typeof obj . imports === 'object' )
907908 ) ;
908909}
909910
910- function isTSConfig ( obj : mixed ) : boolean {
911+ function isTSConfig (
912+ obj : mixed ,
913+ ) : implies obj is { + compilerOptions : mixed , ... } {
911914 return (
912915 obj != null &&
913916 typeof obj === 'object' &&
@@ -917,7 +920,7 @@ function isTSConfig(obj: mixed): boolean {
917920 ) ;
918921}
919922
920- function isDenoConfig ( obj : mixed ) : boolean {
923+ function isDenoConfig ( obj : mixed ) : implies obj is { + imports : mixed , ... } {
921924 return (
922925 obj != null &&
923926 typeof obj === 'object' &&
0 commit comments