pacework 1.4.2 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/environment.mjs +34 -1
- package/package.json +1 -1
package/lib/environment.mjs
CHANGED
|
@@ -48,9 +48,42 @@ export const SERVICES = {
|
|
|
48
48
|
},
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
const JS_INSTALL = {
|
|
52
|
+
pnpm: "pnpm install --frozen-lockfile",
|
|
53
|
+
yarn: "yarn install --frozen-lockfile",
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The package manager package.json declares ("pnpm@11.14.0+sha…" → "pnpm"), or null. */
|
|
57
|
+
function declaredPackageManager(dir) {
|
|
58
|
+
try {
|
|
59
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf8"))
|
|
60
|
+
const name = String(pkg.packageManager ?? "").split("@")[0]
|
|
61
|
+
return JS_INSTALL[name] ? name : null
|
|
62
|
+
} catch {
|
|
63
|
+
return null
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The install command a repository's lockfile implies, or null when there is none to run.
|
|
69
|
+
*
|
|
70
|
+
* The package manager package.json declares wins over a stray lockfile of another
|
|
71
|
+
* one. A repository that keeps its lockfiles one level down (frontend/, backend/)
|
|
72
|
+
* installs in each of those folders.
|
|
73
|
+
*/
|
|
52
74
|
export function detectSetupCommand(dir) {
|
|
53
75
|
const has = (file) => fs.existsSync(path.join(dir, file))
|
|
76
|
+
const declared = declaredPackageManager(dir)
|
|
77
|
+
if (declared) {
|
|
78
|
+
const lockfile = declared === "pnpm" ? "pnpm-lock.yaml" : "yarn.lock"
|
|
79
|
+
if (has(lockfile)) return `corepack enable && ${JS_INSTALL[declared]}`
|
|
80
|
+
const folders = fs.readdirSync(dir, { withFileTypes: true })
|
|
81
|
+
.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules")
|
|
82
|
+
.map((entry) => entry.name)
|
|
83
|
+
.filter((name) => fs.existsSync(path.join(dir, name, lockfile)))
|
|
84
|
+
.sort()
|
|
85
|
+
if (folders.length) return `corepack enable && ${folders.map((name) => `(cd ${name} && ${JS_INSTALL[declared]})`).join(" && ")}`
|
|
86
|
+
}
|
|
54
87
|
if (has("pnpm-lock.yaml")) return "corepack enable && pnpm install --frozen-lockfile"
|
|
55
88
|
if (has("yarn.lock")) return "corepack enable && yarn install --frozen-lockfile"
|
|
56
89
|
if (has("bun.lockb") || has("bun.lock")) return "npx -y bun install --frozen-lockfile"
|