mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
Convert bootstrap script to ESM (#3904)
This commit is contained in:
parent
20c7453425
commit
78bb7e0256
4 changed files with 89 additions and 89 deletions
5
.changeset/ready-guests-hide.md
Normal file
5
.changeset/ready-guests-hide.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"roo-cline": patch
|
||||
---
|
||||
|
||||
Convert bootstrap script to esm
|
||||
|
|
@ -5,10 +5,10 @@
|
|||
"node": "20.18.1"
|
||||
},
|
||||
"scripts": {
|
||||
"preinstall": "node scripts/bootstrap.js",
|
||||
"preinstall": "node scripts/bootstrap.mjs",
|
||||
"prepare": "husky",
|
||||
"install": "node scripts/bootstrap.js",
|
||||
"install:all": "node scripts/bootstrap.js",
|
||||
"install": "node scripts/bootstrap.mjs",
|
||||
"install:all": "node scripts/bootstrap.mjs",
|
||||
"lint": "turbo lint --log-order grouped --output-logs new-only",
|
||||
"check-types": "turbo check-types --log-order grouped --output-logs new-only",
|
||||
"test": "turbo test --log-order grouped --output-logs new-only",
|
||||
|
|
|
|||
86
scripts/bootstrap.js
vendored
86
scripts/bootstrap.js
vendored
|
|
@ -1,86 +0,0 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const { spawnSync } = require("child_process")
|
||||
|
||||
// Check if we're already bootstrapping
|
||||
if (process.env.BOOTSTRAP_IN_PROGRESS) {
|
||||
console.log("Bootstrap already in progress, continuing with normal installation...")
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
// Check if we're running under pnpm
|
||||
const isPnpm = process.env.npm_execpath && process.env.npm_execpath.includes("pnpm")
|
||||
|
||||
// If we're already using pnpm, just exit normally
|
||||
if (isPnpm) {
|
||||
console.log("Already using pnpm, continuing with normal installation...")
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
console.log("Bootstrapping to pnpm...")
|
||||
|
||||
try {
|
||||
// Check if pnpm is installed
|
||||
const pnpmCheck = spawnSync("command", ["-v", "pnpm"], { shell: true })
|
||||
|
||||
let pnpmInstall
|
||||
|
||||
if (pnpmCheck.status === 0) {
|
||||
// If pnpm is available, use it directly
|
||||
console.log("pnpm found, using it directly...")
|
||||
pnpmInstall = spawnSync("pnpm", ["install"], {
|
||||
stdio: "inherit",
|
||||
shell: true,
|
||||
env: {
|
||||
...process.env,
|
||||
BOOTSTRAP_IN_PROGRESS: "1", // Set environment variable to indicate bootstrapping
|
||||
},
|
||||
})
|
||||
} else {
|
||||
// If pnpm is not available, install it temporarily in the project
|
||||
console.log("pnpm not found, installing it temporarily...")
|
||||
|
||||
// Create a temporary package.json if it doesn't exist
|
||||
const tempPkgJson = spawnSync(
|
||||
"node",
|
||||
[
|
||||
"-e",
|
||||
'if(!require("fs").existsSync("package.json")){require("fs").writeFileSync("package.json", JSON.stringify({name:"temp",private:true}))}',
|
||||
],
|
||||
{ shell: true },
|
||||
)
|
||||
|
||||
// Install pnpm locally without saving it as a dependency
|
||||
const npmInstall = spawnSync("npm", ["install", "--no-save", "pnpm"], {
|
||||
stdio: "inherit",
|
||||
shell: true,
|
||||
})
|
||||
|
||||
if (npmInstall.status !== 0) {
|
||||
console.error("Failed to install pnpm locally")
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// Use the locally installed pnpm
|
||||
console.log("Running pnpm install...")
|
||||
pnpmInstall = spawnSync("node_modules/.bin/pnpm", ["install"], {
|
||||
stdio: "inherit",
|
||||
shell: true,
|
||||
env: {
|
||||
...process.env,
|
||||
BOOTSTRAP_IN_PROGRESS: "1", // Set environment variable to indicate bootstrapping
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if (pnpmInstall.status !== 0) {
|
||||
console.error("pnpm install failed")
|
||||
process.exit(pnpmInstall.status)
|
||||
}
|
||||
|
||||
console.log("Bootstrap completed successfully")
|
||||
process.exit(0)
|
||||
} catch (error) {
|
||||
console.error("Bootstrap failed:", error)
|
||||
process.exit(1)
|
||||
}
|
||||
81
scripts/bootstrap.mjs
Normal file
81
scripts/bootstrap.mjs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
import { spawnSync } from "child_process"
|
||||
import { existsSync, writeFileSync } from "fs"
|
||||
|
||||
if (process.env.BOOTSTRAP_IN_PROGRESS) {
|
||||
console.log("⏭️ Bootstrap already in progress, continuing with normal installation...")
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
// If we're already using pnpm, just exit normally.
|
||||
if (process.env.npm_execpath && process.env.npm_execpath.includes("pnpm")) {
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
console.log("🚀 Bootstrapping to pnpm...")
|
||||
|
||||
/**
|
||||
* Run pnpm install with bootstrap environment variable.
|
||||
*/
|
||||
function runPnpmInstall(pnpmCommand) {
|
||||
return spawnSync(pnpmCommand, ["install"], {
|
||||
stdio: "inherit",
|
||||
shell: true,
|
||||
env: {
|
||||
...process.env,
|
||||
BOOTSTRAP_IN_PROGRESS: "1", // Set environment variable to indicate bootstrapping
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a temporary package.json if it doesn't exist.
|
||||
*/
|
||||
function ensurePackageJson() {
|
||||
if (!existsSync("package.json")) {
|
||||
console.log("📦 Creating temporary package.json...")
|
||||
writeFileSync("package.json", JSON.stringify({ name: "temp", private: true }, null, 2))
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Check if pnpm is installed globally.
|
||||
const pnpmCheck = spawnSync("command", ["-v", "pnpm"], { shell: true })
|
||||
|
||||
let pnpmInstall
|
||||
|
||||
if (pnpmCheck.status === 0) {
|
||||
console.log("✨ Found pnpm")
|
||||
pnpmInstall = runPnpmInstall("pnpm")
|
||||
} else {
|
||||
console.log("⚠️ Unable to find pnpm, installing it temporarily...")
|
||||
ensurePackageJson()
|
||||
|
||||
console.log("📥 Installing pnpm locally...")
|
||||
|
||||
const npmInstall = spawnSync("npm", ["install", "--no-save", "pnpm"], {
|
||||
stdio: "inherit",
|
||||
shell: true,
|
||||
})
|
||||
|
||||
if (npmInstall.status !== 0) {
|
||||
console.error("❌ Failed to install pnpm locally")
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
console.log("🔧 Running pnpm install with local installation...")
|
||||
pnpmInstall = runPnpmInstall("node_modules/.bin/pnpm")
|
||||
}
|
||||
|
||||
if (pnpmInstall.status !== 0) {
|
||||
console.error("❌ pnpm install failed")
|
||||
process.exit(pnpmInstall.status)
|
||||
}
|
||||
|
||||
console.log("🎉 Bootstrap completed successfully!")
|
||||
process.exit(0)
|
||||
} catch (error) {
|
||||
console.error("💥 Bootstrap failed:", error.message)
|
||||
process.exit(1)
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue