File tree Expand file tree Collapse file tree 1 file changed +21
-11
lines changed
Expand file tree Collapse file tree 1 file changed +21
-11
lines changed Original file line number Diff line number Diff line change @@ -440,17 +440,27 @@ export type PackageManager = "npm" | "yarn" | "pnpm" | "bun";
440440 * Detect the package manager used in a project by checking lock files.
441441 */
442442export function detectPackageManager ( projectRoot : string ) : PackageManager {
443- if (
444- fs . existsSync ( path . join ( projectRoot , "bun.lockb" ) ) ||
445- fs . existsSync ( path . join ( projectRoot , "bun.lock" ) )
446- ) {
447- return "bun" ;
448- }
449- if ( fs . existsSync ( path . join ( projectRoot , "pnpm-lock.yaml" ) ) ) {
450- return "pnpm" ;
451- }
452- if ( fs . existsSync ( path . join ( projectRoot , "yarn.lock" ) ) ) {
453- return "yarn" ;
443+ let dir = projectRoot ;
444+ while ( true ) {
445+ if (
446+ fs . existsSync ( path . join ( dir , "bun.lockb" ) ) ||
447+ fs . existsSync ( path . join ( dir , "bun.lock" ) )
448+ ) {
449+ return "bun" ;
450+ }
451+ if ( fs . existsSync ( path . join ( dir , "pnpm-lock.yaml" ) ) ) {
452+ return "pnpm" ;
453+ }
454+ if ( fs . existsSync ( path . join ( dir , "yarn.lock" ) ) ) {
455+ return "yarn" ;
456+ }
457+ if ( fs . existsSync ( path . join ( dir , "package-lock.json" ) ) ) {
458+ return "npm" ;
459+ }
460+
461+ const parent = path . dirname ( dir ) ;
462+ if ( parent === dir ) break ;
463+ dir = parent ;
454464 }
455465 return "npm" ;
456466}
You can’t perform that action at this time.
0 commit comments