@@ -61,10 +61,10 @@ type DiscoveredFramework = {
6161 bundledWith ?: Array < ( typeof PLATFORMS ) [ number ] [ 4 ] [ number ] [ 0 ] > ;
6262} ;
6363
64- export async function discover ( path : string , githubRepo ?: string , githubToken ?: string ) {
64+ export async function discover ( directory : string , githubRepo ?: string , githubToken ?: string ) {
6565 if ( githubRepo && ! githubToken ) throw new Error ( "needs token" ) ;
6666
67- const { join } = await ( githubRepo ? import ( "node:path" ) : import ( "node:path/posix" ) ) ;
67+ const path = await ( githubRepo ? import ( "node:path" ) : import ( "node:path/posix" ) ) ;
6868
6969 const { readFile, pathExists, readJson } = githubRepo
7070 ? {
@@ -115,12 +115,14 @@ export async function discover(path: string, githubRepo?: string, githubToken?:
115115 await Promise . all (
116116 PLATFORMS . map (
117117 async ( [ platform , files , defaultPackageManager , packageManagers , frameworkDefinitions ] ) => {
118- const filesExist = await Promise . all ( files . map ( ( it ) => pathExists ( join ( path , it ) ) ) ) ;
118+ const filesExist = await Promise . all (
119+ files . map ( ( it ) => pathExists ( path . join ( directory , it ) ) ) ,
120+ ) ;
119121 if ( files . length && ! filesExist . some ( ( it ) => it ) ) return ;
120122 const discoverFrameworks = ( fallback = false ) => {
121123 return async ( [ packageManager , possibleLockfiles ] : ( typeof packageManagers ) [ number ] ) => {
122124 const possibleLockfilesExist = await Promise . all (
123- possibleLockfiles . map ( ( it ) => pathExists ( join ( path , it ) ) ) ,
125+ possibleLockfiles . map ( ( it ) => pathExists ( path . join ( directory , it ) ) ) ,
124126 ) ;
125127 const [ lockfile ] = possibleLockfilesExist
126128 . map ( ( exists , index ) => ( exists ? possibleLockfiles [ index ] : undefined ) )
@@ -131,7 +133,7 @@ export async function discover(path: string, githubRepo?: string, githubToken?:
131133 if ( platform === "nodejs" ) {
132134 // TODO handle workspaces
133135 if ( lockfile === "package-lock.json" || lockfile === "npm-shrinkwrap.json" ) {
134- const packageJSON = await readJson ( join ( path , lockfile ) ) ;
136+ const packageJSON = await readJson ( path . join ( directory , lockfile ) ) ;
135137 packages = new Map (
136138 Object . keys ( packageJSON . packages ) . map ( ( pkg ) => {
137139 const name = pkg . replace ( / ^ n o d e _ m o d u l e s \/ / , "" ) ;
@@ -140,7 +142,7 @@ export async function discover(path: string, githubRepo?: string, githubToken?:
140142 } ) ,
141143 ) ;
142144 } else if ( lockfile === "yarn.lock" ) {
143- const file = await readFile ( join ( path , lockfile ) ) ;
145+ const file = await readFile ( path . join ( directory , lockfile ) ) ;
144146 const yarnLock = YarnLockfile . parse ( file . toString ( ) ) ;
145147 if ( yarnLock . type !== "success" ) throw new Error ( `unable to read ${ lockfile } ` ) ;
146148 packages = new Map (
@@ -151,7 +153,7 @@ export async function discover(path: string, githubRepo?: string, githubToken?:
151153 } ) ,
152154 ) ;
153155 } else if ( lockfile === "pnpm-lock.yaml" ) {
154- const file = await readFile ( join ( path , lockfile ) ) ;
156+ const file = await readFile ( path . join ( directory , lockfile ) ) ;
155157 const pnpmLock = parseYaml ( file . toString ( ) ) ;
156158 packages = new Map (
157159 Object . keys ( pnpmLock . packages ) . map ( ( pkg ) => {
@@ -164,9 +166,11 @@ export async function discover(path: string, githubRepo?: string, githubToken?:
164166 } else if ( platform === "python" ) {
165167 if ( packageManager === "pip" ) {
166168 const requirementsFile = "requirements.txt" ;
167- const requirementsFileExists = await pathExists ( join ( path , requirementsFile ) ) ;
169+ const requirementsFileExists = await pathExists (
170+ path . join ( directory , requirementsFile ) ,
171+ ) ;
168172 if ( ! requirementsFileExists ) return false ;
169- const file = await readFile ( join ( path , requirementsFile ) ) ;
173+ const file = await readFile ( path . join ( directory , requirementsFile ) ) ;
170174 packages = new Map (
171175 file
172176 . toString ( )
@@ -176,7 +180,7 @@ export async function discover(path: string, githubRepo?: string, githubToken?:
176180 } ) ,
177181 ) ;
178182 } else if ( lockfile === "Pipfile.lock" ) {
179- const pipfileLock = await readJson ( join ( path , lockfile ) ) ;
183+ const pipfileLock = await readJson ( path . join ( directory , lockfile ) ) ;
180184 // TODO include develop too?
181185 packages = new Map (
182186 Object . keys ( pipfileLock . default ) . map ( ( name ) => {
@@ -186,11 +190,11 @@ export async function discover(path: string, githubRepo?: string, githubToken?:
186190 } ) ,
187191 ) ;
188192 } else if ( lockfile === "poetry.lock" ) {
189- const poetryLock = await readFile ( join ( path , lockfile ) ) ;
193+ const poetryLock = await readFile ( path . join ( directory , lockfile ) ) ;
190194 packages = new Map (
191195 toml
192196 . parse ( poetryLock . toString ( ) )
193- . package ?. map ( ( it : any ) => [ it . name , it . version ] ) ,
197+ . package ?. map ( ( it : { name : string ; version : string } ) => [ it . name , it . version ] ) ,
194198 ) ;
195199 }
196200 }
@@ -200,9 +204,9 @@ export async function discover(path: string, githubRepo?: string, githubToken?:
200204 if ( ! requiredPackagePresent ) continue ;
201205 const requiredFileExist =
202206 requiredFiles . length === 0 ||
203- ( await Promise . all ( requiredFiles . map ( ( it ) => pathExists ( join ( path , it ) ) ) ) ) . some (
204- ( it ) => it ,
205- ) ;
207+ (
208+ await Promise . all ( requiredFiles . map ( ( it ) => pathExists ( path . join ( directory , it ) ) ) )
209+ ) . some ( ( it ) => it ) ;
206210 if ( ! requiredFileExist ) continue ;
207211 const [ packageName ] = requiredPackages ;
208212 if ( packageName )
0 commit comments