Explorar o código

fix: improve pnpm bootstrapping and add compile script (#3882)

Co-authored-by: Eric Wheeler <[email protected]>
KJ7LNW hai 7 meses
pai
achega
be19a49b20
Modificáronse 4 ficheiros con 105 adicións e 7 borrados
  1. 8 4
      .husky/pre-commit
  2. 6 2
      .husky/pre-push
  3. 5 1
      package.json
  4. 86 0
      scripts/bootstrap.js

+ 8 - 4
.husky/pre-commit

@@ -9,10 +9,14 @@ fi
 if [ "$OS" = "Windows_NT" ]; then
 if [ "$OS" = "Windows_NT" ]; then
   pnpm_cmd="pnpm.cmd"
   pnpm_cmd="pnpm.cmd"
 else
 else
-  pnpm_cmd="pnpm"
+  if command -v pnpm >/dev/null 2>&1; then
+    pnpm_cmd="pnpm"
+  else
+    pnpm_cmd="npx pnpm"
+  fi
 fi
 fi
 
 
-"$pnpm_cmd" --filter roo-cline generate-types
+$pnpm_cmd --filter roo-cline generate-types
 
 
 if [ -n "$(git diff --name-only src/exports/roo-code.d.ts)" ]; then
 if [ -n "$(git diff --name-only src/exports/roo-code.d.ts)" ]; then
   echo "Error: There are unstaged changes to roo-code.d.ts after running 'pnpm --filter roo-cline generate-types'."
   echo "Error: There are unstaged changes to roo-code.d.ts after running 'pnpm --filter roo-cline generate-types'."
@@ -27,5 +31,5 @@ else
   npx_cmd="npx"
   npx_cmd="npx"
 fi
 fi
 
 
-"$npx_cmd" lint-staged
-"$pnpm_cmd" lint
+$npx_cmd lint-staged
+$pnpm_cmd lint

+ 6 - 2
.husky/pre-push

@@ -9,10 +9,14 @@ fi
 if [ "$OS" = "Windows_NT" ]; then
 if [ "$OS" = "Windows_NT" ]; then
   pnpm_cmd="pnpm.cmd"
   pnpm_cmd="pnpm.cmd"
 else
 else
-  pnpm_cmd="pnpm"
+  if command -v pnpm >/dev/null 2>&1; then
+    pnpm_cmd="pnpm"
+  else
+    pnpm_cmd="npx pnpm"
+  fi
 fi
 fi
 
 
-"$pnpm_cmd" run check-types
+$pnpm_cmd run check-types
 
 
 # Check for new changesets.
 # Check for new changesets.
 NEW_CHANGESETS=$(find .changeset -name "*.md" ! -name "README.md" | wc -l | tr -d ' ')
 NEW_CHANGESETS=$(find .changeset -name "*.md" ! -name "README.md" | wc -l | tr -d ' ')

+ 5 - 1
package.json

@@ -5,14 +5,18 @@
 		"node": "20.18.1"
 		"node": "20.18.1"
 	},
 	},
 	"scripts": {
 	"scripts": {
-		"preinstall": "npx only-allow pnpm",
+		"preinstall": "node scripts/bootstrap.js",
 		"prepare": "husky",
 		"prepare": "husky",
+		"install": "node scripts/bootstrap.js",
+		"install:all": "node scripts/bootstrap.js",
 		"lint": "turbo lint --log-order grouped --output-logs new-only",
 		"lint": "turbo lint --log-order grouped --output-logs new-only",
 		"check-types": "turbo check-types --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",
 		"test": "turbo test --log-order grouped --output-logs new-only",
 		"format": "turbo format --log-order grouped --output-logs new-only",
 		"format": "turbo format --log-order grouped --output-logs new-only",
 		"clean": "turbo clean --log-order grouped --output-logs new-only && rimraf dist out bin .vite-port .turbo",
 		"clean": "turbo clean --log-order grouped --output-logs new-only && rimraf dist out bin .vite-port .turbo",
 		"build": "pnpm --filter roo-cline vsix",
 		"build": "pnpm --filter roo-cline vsix",
+		"compile": "pnpm --filter roo-cline bundle",
+		"vsix": "pnpm --filter roo-cline vsix",
 		"build:nightly": "pnpm --filter @roo-code/vscode-nightly vsix",
 		"build:nightly": "pnpm --filter @roo-code/vscode-nightly vsix",
 		"generate-types": "pnpm --filter roo-cline generate-types",
 		"generate-types": "pnpm --filter roo-cline generate-types",
 		"changeset:version": "cp CHANGELOG.md src/CHANGELOG.md && changeset version && cp -vf src/CHANGELOG.md .",
 		"changeset:version": "cp CHANGELOG.md src/CHANGELOG.md && changeset version && cp -vf src/CHANGELOG.md .",

+ 86 - 0
scripts/bootstrap.js

@@ -0,0 +1,86 @@
+#!/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)
+}