Skip to content

Commit be19a49

Browse files
KJ7LNWEric Wheeler
andauthored
fix: improve pnpm bootstrapping and add compile script (#3882)
Co-authored-by: Eric Wheeler <[email protected]>
1 parent 1791bb9 commit be19a49

File tree

4 files changed

+105
-7
lines changed

4 files changed

+105
-7
lines changed

.husky/pre-commit

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ fi
99
if [ "$OS" = "Windows_NT" ]; then
1010
pnpm_cmd="pnpm.cmd"
1111
else
12-
pnpm_cmd="pnpm"
12+
if command -v pnpm >/dev/null 2>&1; then
13+
pnpm_cmd="pnpm"
14+
else
15+
pnpm_cmd="npx pnpm"
16+
fi
1317
fi
1418

15-
"$pnpm_cmd" --filter roo-cline generate-types
19+
$pnpm_cmd --filter roo-cline generate-types
1620

1721
if [ -n "$(git diff --name-only src/exports/roo-code.d.ts)" ]; then
1822
echo "Error: There are unstaged changes to roo-code.d.ts after running 'pnpm --filter roo-cline generate-types'."
@@ -27,5 +31,5 @@ else
2731
npx_cmd="npx"
2832
fi
2933

30-
"$npx_cmd" lint-staged
31-
"$pnpm_cmd" lint
34+
$npx_cmd lint-staged
35+
$pnpm_cmd lint

.husky/pre-push

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ fi
99
if [ "$OS" = "Windows_NT" ]; then
1010
pnpm_cmd="pnpm.cmd"
1111
else
12-
pnpm_cmd="pnpm"
12+
if command -v pnpm >/dev/null 2>&1; then
13+
pnpm_cmd="pnpm"
14+
else
15+
pnpm_cmd="npx pnpm"
16+
fi
1317
fi
1418

15-
"$pnpm_cmd" run check-types
19+
$pnpm_cmd run check-types
1620

1721
# Check for new changesets.
1822
NEW_CHANGESETS=$(find .changeset -name "*.md" ! -name "README.md" | wc -l | tr -d ' ')

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
"node": "20.18.1"
66
},
77
"scripts": {
8-
"preinstall": "npx only-allow pnpm",
8+
"preinstall": "node scripts/bootstrap.js",
99
"prepare": "husky",
10+
"install": "node scripts/bootstrap.js",
11+
"install:all": "node scripts/bootstrap.js",
1012
"lint": "turbo lint --log-order grouped --output-logs new-only",
1113
"check-types": "turbo check-types --log-order grouped --output-logs new-only",
1214
"test": "turbo test --log-order grouped --output-logs new-only",
1315
"format": "turbo format --log-order grouped --output-logs new-only",
1416
"clean": "turbo clean --log-order grouped --output-logs new-only && rimraf dist out bin .vite-port .turbo",
1517
"build": "pnpm --filter roo-cline vsix",
18+
"compile": "pnpm --filter roo-cline bundle",
19+
"vsix": "pnpm --filter roo-cline vsix",
1620
"build:nightly": "pnpm --filter @roo-code/vscode-nightly vsix",
1721
"generate-types": "pnpm --filter roo-cline generate-types",
1822
"changeset:version": "cp CHANGELOG.md src/CHANGELOG.md && changeset version && cp -vf src/CHANGELOG.md .",

scripts/bootstrap.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env node
2+
3+
const { spawnSync } = require("child_process")
4+
5+
// Check if we're already bootstrapping
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+
// Check if we're running under pnpm
12+
const isPnpm = process.env.npm_execpath && process.env.npm_execpath.includes("pnpm")
13+
14+
// If we're already using pnpm, just exit normally
15+
if (isPnpm) {
16+
console.log("Already using pnpm, continuing with normal installation...")
17+
process.exit(0)
18+
}
19+
20+
console.log("Bootstrapping to pnpm...")
21+
22+
try {
23+
// Check if pnpm is installed
24+
const pnpmCheck = spawnSync("command", ["-v", "pnpm"], { shell: true })
25+
26+
let pnpmInstall
27+
28+
if (pnpmCheck.status === 0) {
29+
// If pnpm is available, use it directly
30+
console.log("pnpm found, using it directly...")
31+
pnpmInstall = spawnSync("pnpm", ["install"], {
32+
stdio: "inherit",
33+
shell: true,
34+
env: {
35+
...process.env,
36+
BOOTSTRAP_IN_PROGRESS: "1", // Set environment variable to indicate bootstrapping
37+
},
38+
})
39+
} else {
40+
// If pnpm is not available, install it temporarily in the project
41+
console.log("pnpm not found, installing it temporarily...")
42+
43+
// Create a temporary package.json if it doesn't exist
44+
const tempPkgJson = spawnSync(
45+
"node",
46+
[
47+
"-e",
48+
'if(!require("fs").existsSync("package.json")){require("fs").writeFileSync("package.json", JSON.stringify({name:"temp",private:true}))}',
49+
],
50+
{ shell: true },
51+
)
52+
53+
// Install pnpm locally without saving it as a dependency
54+
const npmInstall = spawnSync("npm", ["install", "--no-save", "pnpm"], {
55+
stdio: "inherit",
56+
shell: true,
57+
})
58+
59+
if (npmInstall.status !== 0) {
60+
console.error("Failed to install pnpm locally")
61+
process.exit(1)
62+
}
63+
64+
// Use the locally installed pnpm
65+
console.log("Running pnpm install...")
66+
pnpmInstall = spawnSync("node_modules/.bin/pnpm", ["install"], {
67+
stdio: "inherit",
68+
shell: true,
69+
env: {
70+
...process.env,
71+
BOOTSTRAP_IN_PROGRESS: "1", // Set environment variable to indicate bootstrapping
72+
},
73+
})
74+
}
75+
76+
if (pnpmInstall.status !== 0) {
77+
console.error("pnpm install failed")
78+
process.exit(pnpmInstall.status)
79+
}
80+
81+
console.log("Bootstrap completed successfully")
82+
process.exit(0)
83+
} catch (error) {
84+
console.error("Bootstrap failed:", error)
85+
process.exit(1)
86+
}

0 commit comments

Comments
 (0)