@@ -53,6 +53,7 @@ function getEntrypoints(fs: Package, exportsObject: unknown, options: CheckPacka
53
53
} ) ;
54
54
} ) ;
55
55
}
56
+
56
57
function formatEntrypointString ( path : string , packageName : string ) {
57
58
return (
58
59
path === "." || path . startsWith ( "./" )
@@ -64,6 +65,7 @@ function formatEntrypointString(path: string, packageName: string) {
64
65
: `./${ path } `
65
66
) . trim ( ) ;
66
67
}
68
+
67
69
function getSubpaths ( exportsObject : any ) : string [ ] {
68
70
if ( ! exportsObject || typeof exportsObject !== "object" || Array . isArray ( exportsObject ) ) {
69
71
return [ ] ;
@@ -74,22 +76,41 @@ function getSubpaths(exportsObject: any): string[] {
74
76
}
75
77
return keys . flatMap ( ( key ) => getSubpaths ( exportsObject [ key ] ) ) ;
76
78
}
79
+
77
80
function getProxyDirectories ( rootDir : string , fs : Package ) {
78
- return fs
79
- . listFiles ( )
80
- . filter ( ( f ) => f . startsWith ( rootDir ) && f . endsWith ( "package.json" ) )
81
- . filter ( ( f ) => {
81
+ const vendorDirectories = new Set < string > ( ) ;
82
+ const proxyDirectories : string [ ] = [ ] ;
83
+ const files = fs . listFiles ( ) . sort ( ( a , b ) => a . length - b . length ) ;
84
+ for ( const file of files ) {
85
+ if ( file . startsWith ( rootDir ) && file . endsWith ( "/package.json" ) ) {
82
86
try {
83
- const packageJson = JSON . parse ( fs . readFile ( f ) ) ;
84
- return "main" in packageJson && ( ! packageJson . name || packageJson . name . startsWith ( fs . packageName ) ) ;
85
- } catch {
86
- return false ;
87
+ const packageJson = JSON . parse ( fs . readFile ( file ) ) ;
88
+ if ( packageJson . name && ! packageJson . name . startsWith ( fs . packageName ) ) {
89
+ // Name unrelated to the root package, this is a vendored package
90
+ const vendorDir = file . slice ( 0 , file . lastIndexOf ( "/" ) ) ;
91
+ vendorDirectories . add ( vendorDir ) ;
92
+ } else if ( "main" in packageJson && ! isInsideVendorDirectory ( file ) ) {
93
+ // No name or name starting with root package name, this is intended to be an entrypoint
94
+ const proxyDir = "." + file . slice ( rootDir . length , file . lastIndexOf ( "/" ) ) ;
95
+ proxyDirectories . push ( proxyDir ) ;
96
+ }
97
+ } catch { }
98
+ }
99
+ }
100
+
101
+ return proxyDirectories . sort ( ( a , b ) => {
102
+ return ts . comparePathsCaseInsensitive ( a , b ) ;
103
+ } ) ;
104
+
105
+ function isInsideVendorDirectory ( file : string ) {
106
+ return ! ! ts . forEachAncestorDirectory ( file , ( dir ) => {
107
+ if ( vendorDirectories . has ( dir ) ) {
108
+ return true ;
87
109
}
88
- } )
89
- . map ( ( f ) => "." + f . slice ( rootDir . length ) . slice ( 0 , - `/package.json` . length ) )
90
- . filter ( ( f ) => f !== "./" )
91
- . sort ( ) ;
110
+ } ) ;
111
+ }
92
112
}
113
+
93
114
export function getEntrypointInfo (
94
115
packageName : string ,
95
116
fs : Package ,
0 commit comments