Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
feat: add getPackageManager helper
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jul 22, 2022
1 parent e5c650f commit 069ae7c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Utils/getPackageManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* @adonisjs/sink
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import { resolve } from 'path'
import { pathExistsSync } from 'fs-extra'

/**
* Returns the package manager in use by checking for the lock files
* on the disk or by inspecting the "npm_execpath"
*/
export function getPackageManager(appRoot: string): 'yarn' | 'pnpm' | 'npm' {
if (pathExistsSync(resolve(appRoot, 'yarn.lock'))) {
return 'yarn'
}

if (pathExistsSync(resolve(appRoot, 'pnpm-lock.yaml'))) {
return 'pnpm'
}

return process.env.npm_execpath && process.env.npm_execpath.includes('yarn')
? 'yarn'
: process.env.npm_execpath && process.env.npm_execpath.includes('pnpm')
? 'pnpm'
: 'npm'
}
1 change: 1 addition & 0 deletions src/Utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@

export { isEmptyDir } from './isEmptyDir'
export { copyFiles } from './copyFiles'
export { getPackageManager } from './getPackageManager'

0 comments on commit 069ae7c

Please sign in to comment.