|
1 | 1 | import fs from "fs-extra"
|
2 | 2 | import { join } from "./path"
|
| 3 | +import path from "path" |
3 | 4 | import chalk from "chalk"
|
4 | 5 | import process from "process"
|
5 | 6 | import findWorkspaceRoot from "find-yarn-workspace-root"
|
@@ -37,6 +38,28 @@ package-lock.json if you don't need it
|
37 | 38 | )
|
38 | 39 | }
|
39 | 40 |
|
| 41 | +function isFileInPnpmRoot(rootPath: string, filename: string): boolean { |
| 42 | + const osRoot = path.parse(rootPath).root |
| 43 | + |
| 44 | + let currentDir = rootPath |
| 45 | + |
| 46 | + while (currentDir !== osRoot) { |
| 47 | + if (fs.existsSync(path.join(currentDir, "pnpm-workspace.yaml"))) { |
| 48 | + // Found workspace root. If the sought file is in the workspace root, |
| 49 | + // we're good. |
| 50 | + if (fs.existsSync(path.join(currentDir, filename))) { |
| 51 | + return true |
| 52 | + } else { |
| 53 | + return false |
| 54 | + } |
| 55 | + } else { |
| 56 | + currentDir = path.resolve(currentDir, "..") |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + return false |
| 61 | +} |
| 62 | + |
40 | 63 | export const detectPackageManager = (
|
41 | 64 | appRootPath: string,
|
42 | 65 | overridePackageManager: PackageManager | null,
|
@@ -64,7 +87,8 @@ export const detectPackageManager = (
|
64 | 87 | }
|
65 | 88 | } else if (yarnLockExists || findWorkspaceRoot()) {
|
66 | 89 | return "yarn"
|
67 |
| - } else if (fs.existsSync(join(appRootPath, "pnpm-lock.yaml"))) { |
| 90 | + } else if (isFileInPnpmRoot(appRootPath, "pnpm-lock.yaml")) { |
| 91 | + // (fs.existsSync(join(appRootPath, "pnpm-lock.yaml"))) { |
68 | 92 | return "pnpm"
|
69 | 93 | } else {
|
70 | 94 | printNoLockfilesError()
|
|
0 commit comments