@@ -1041,6 +1041,46 @@ function resolvePackageExportImportPath(value: unknown): string | null {
10411041 : null ;
10421042}
10431043
1044+ function listRootPackagedWorkspacePackageAliasEntries ( params : {
1045+ packageRoot : string ;
1046+ packageName : string ;
1047+ packageDir : string ;
1048+ } ) : WorkspacePackageAliasEntry [ ] {
1049+ const distRoot = path . join ( params . packageRoot , "dist" , params . packageDir ) ;
1050+ if ( ! fs . existsSync ( distRoot ) ) {
1051+ return [ ] ;
1052+ }
1053+ const entries : WorkspacePackageAliasEntry [ ] = [ ] ;
1054+ const visit = ( dir : string , prefix = "" ) => {
1055+ for ( const entry of fs . readdirSync ( dir , { withFileTypes : true } ) ) {
1056+ const relativePath = prefix ? path . join ( prefix , entry . name ) : entry . name ;
1057+ const fullPath = path . join ( dir , entry . name ) ;
1058+ if ( entry . isDirectory ( ) ) {
1059+ visit ( fullPath , relativePath ) ;
1060+ continue ;
1061+ }
1062+ if ( ! entry . isFile ( ) || ! relativePath . endsWith ( ".js" ) ) {
1063+ continue ;
1064+ }
1065+ const normalizedRelativePath = relativePath . split ( path . sep ) . join ( "/" ) ;
1066+ const subpath =
1067+ normalizedRelativePath === "index.js" ? "" : normalizedRelativePath . slice ( 0 , - ".js" . length ) ;
1068+ if ( subpath . includes ( ".." ) ) {
1069+ continue ;
1070+ }
1071+ entries . push ( {
1072+ packageName : params . packageName ,
1073+ packageDir : params . packageDir ,
1074+ subpath,
1075+ srcFile : `${ subpath || "index" } .ts` ,
1076+ distFile : relativePath ,
1077+ } ) ;
1078+ }
1079+ } ;
1080+ visit ( distRoot ) ;
1081+ return entries . toSorted ( ( a , b ) => a . subpath . localeCompare ( b . subpath ) ) ;
1082+ }
1083+
10441084export function listWorkspacePackageExportAliasEntries ( params : {
10451085 packageRoot : string ;
10461086 packageName : string ;
@@ -1062,7 +1102,7 @@ export function listWorkspacePackageExportAliasEntries(params: {
10621102 : null ) ;
10631103 const exports = packageJson ?. exports ;
10641104 if ( ! exports || typeof exports !== "object" || Array . isArray ( exports ) ) {
1065- return [ ] ;
1105+ return listRootPackagedWorkspacePackageAliasEntries ( params ) ;
10661106 }
10671107 const entries : WorkspacePackageAliasEntry [ ] = [ ] ;
10681108 for ( const [ exportKey , value ] of Object . entries ( exports ) ) {
@@ -1081,7 +1121,9 @@ export function listWorkspacePackageExportAliasEntries(params: {
10811121 distFile,
10821122 } ) ;
10831123 }
1084- return entries . toSorted ( ( a , b ) => a . subpath . localeCompare ( b . subpath ) ) ;
1124+ return entries . length > 0
1125+ ? entries . toSorted ( ( a , b ) => a . subpath . localeCompare ( b . subpath ) )
1126+ : listRootPackagedWorkspacePackageAliasEntries ( params ) ;
10851127}
10861128
10871129function isUsableDistPluginSdkArtifact ( candidate : string ) : boolean {
0 commit comments