diff --git a/.changeset/ready-guests-hide.md b/.changeset/ready-guests-hide.md new file mode 100644 index 0000000000..f899b697f7 --- /dev/null +++ b/.changeset/ready-guests-hide.md @@ -0,0 +1,5 @@ +--- +"roo-cline": patch +--- + +Convert bootstrap script to esm diff --git a/package.json b/package.json index 8398497d14..e488cc4987 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/bootstrap.js b/scripts/bootstrap.js deleted file mode 100755 index 52f9fb72cc..0000000000 --- a/scripts/bootstrap.js +++ /dev/null @@ -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) -} diff --git a/scripts/bootstrap.mjs b/scripts/bootstrap.mjs new file mode 100644 index 0000000000..6f0d09d01b --- /dev/null +++ b/scripts/bootstrap.mjs @@ -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) +}