Skip to content

Commit c08e91a

Browse files
committed
Convert bootstrap script to ESM
1 parent be19a49 commit c08e91a

File tree

4 files changed

+89
-89
lines changed

4 files changed

+89
-89
lines changed

.changeset/ready-guests-hide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"roo-cline": patch
3+
---
4+
5+
Convert bootstrap script to esm

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"node": "20.18.1"
66
},
77
"scripts": {
8-
"preinstall": "node scripts/bootstrap.js",
8+
"preinstall": "node scripts/bootstrap.mjs",
99
"prepare": "husky",
10-
"install": "node scripts/bootstrap.js",
11-
"install:all": "node scripts/bootstrap.js",
10+
"install": "node scripts/bootstrap.mjs",
11+
"install:all": "node scripts/bootstrap.mjs",
1212
"lint": "turbo lint --log-order grouped --output-logs new-only",
1313
"check-types": "turbo check-types --log-order grouped --output-logs new-only",
1414
"test": "turbo test --log-order grouped --output-logs new-only",

scripts/bootstrap.js

Lines changed: 0 additions & 86 deletions
This file was deleted.

scripts/bootstrap.mjs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env node
2+
3+
import { spawnSync } from "child_process"
4+
import { existsSync, writeFileSync } from "fs"
5+
6+
if (process.env.BOOTSTRAP_IN_PROGRESS) {
7+
console.log("⏭️ Bootstrap already in progress, continuing with normal installation...")
8+
process.exit(0)
9+
}
10+
11+
// If we're already using pnpm, just exit normally.
12+
if (process.env.npm_execpath && process.env.npm_execpath.includes("pnpm")) {
13+
process.exit(0)
14+
}
15+
16+
console.log("🚀 Bootstrapping to pnpm...")
17+
18+
/**
19+
* Run pnpm install with bootstrap environment variable.
20+
*/
21+
function runPnpmInstall(pnpmCommand) {
22+
return spawnSync(pnpmCommand, ["install"], {
23+
stdio: "inherit",
24+
shell: true,
25+
env: {
26+
...process.env,
27+
BOOTSTRAP_IN_PROGRESS: "1", // Set environment variable to indicate bootstrapping
28+
},
29+
})
30+
}
31+
32+
/**
33+
* Create a temporary package.json if it doesn't exist.
34+
*/
35+
function ensurePackageJson() {
36+
if (!existsSync("package.json")) {
37+
console.log("📦 Creating temporary package.json...")
38+
writeFileSync("package.json", JSON.stringify({ name: "temp", private: true }, null, 2))
39+
}
40+
}
41+
42+
try {
43+
// Check if pnpm is installed globally.
44+
const pnpmCheck = spawnSync("command", ["-v", "pnpm"], { shell: true })
45+
46+
let pnpmInstall
47+
48+
if (pnpmCheck.status === 0) {
49+
console.log("✨ Found pnpm")
50+
pnpmInstall = runPnpmInstall("pnpm")
51+
} else {
52+
console.log("⚠️ Unable to find pnpm, installing it temporarily...")
53+
ensurePackageJson()
54+
55+
console.log("📥 Installing pnpm locally...")
56+
57+
const npmInstall = spawnSync("npm", ["install", "--no-save", "pnpm"], {
58+
stdio: "inherit",
59+
shell: true,
60+
})
61+
62+
if (npmInstall.status !== 0) {
63+
console.error("❌ Failed to install pnpm locally")
64+
process.exit(1)
65+
}
66+
67+
console.log("🔧 Running pnpm install with local installation...")
68+
pnpmInstall = runPnpmInstall("node_modules/.bin/pnpm")
69+
}
70+
71+
if (pnpmInstall.status !== 0) {
72+
console.error("❌ pnpm install failed")
73+
process.exit(pnpmInstall.status)
74+
}
75+
76+
console.log("🎉 Bootstrap completed successfully!")
77+
process.exit(0)
78+
} catch (error) {
79+
console.error("💥 Bootstrap failed:", error.message)
80+
process.exit(1)
81+
}

0 commit comments

Comments
 (0)