Skip to content

Commit 9d11c14

Browse files
Johannes L. Borresenmilahu
authored andcommitted
feat: add pnpm-lock.json detection if run from workspace folder
1 parent 6b85a8b commit 9d11c14

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "@milahu/patch-package-with-pnpm-support",
3-
"version": "6.4.8",
2+
"name": "@tellus/patch-package-with-pnpm-support",
3+
"version": "6.4.9-jlb.0",
44
"description": "Fix broken node modules with no fuss",
55
"main": "dist/index.js",
66
"repository": "github:ds300/patch-package",

src/detectPackageManager.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from "fs-extra"
22
import { join } from "./path"
3+
import path from "path"
34
import chalk from "chalk"
45
import process from "process"
56
import findWorkspaceRoot from "find-yarn-workspace-root"
@@ -37,6 +38,28 @@ package-lock.json if you don't need it
3738
)
3839
}
3940

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+
4063
export const detectPackageManager = (
4164
appRootPath: string,
4265
overridePackageManager: PackageManager | null,
@@ -64,7 +87,8 @@ export const detectPackageManager = (
6487
}
6588
} else if (yarnLockExists || findWorkspaceRoot()) {
6689
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"))) {
6892
return "pnpm"
6993
} else {
7094
printNoLockfilesError()

0 commit comments

Comments
 (0)