From 8971c4aba13c2c69680d0a39639b40b8d474d1b2 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Mon, 18 May 2026 13:50:24 +0900 Subject: [PATCH] fix: auto-bootstrap submodule before typecheck/test/build/check Without this, a fresh checkout running 'npm run typecheck' fails because the submodule's dist/cli.js does not exist yet. Adds 'pre*' lifecycle hooks that call the bootstrap script. The bootstrap script is now idempotent (skips when dist/cli.js already exists), so the chained pre-step is effectively free on subsequent invocations. --- package.json | 4 ++++ scripts/bootstrap-submodule.mjs | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 2a6ff99..3a45e16 100644 --- a/package.json +++ b/package.json @@ -37,12 +37,16 @@ ], "scripts": { "bootstrap": "node scripts/bootstrap-submodule.mjs", + "prebuild": "node scripts/bootstrap-submodule.mjs", "build": "tsc -p tsconfig.build.json", + "pretest": "node scripts/bootstrap-submodule.mjs", "test": "vitest --run", "test:watch": "vitest", + "pretypecheck": "node scripts/bootstrap-submodule.mjs", "typecheck": "tsc --noEmit", "lint": "biome check src test", "lint:fix": "biome check --write src test", + "precheck": "node scripts/bootstrap-submodule.mjs", "check": "tsc --noEmit && biome check src test && tsc -p tsconfig.build.json" }, "dependencies": { diff --git a/scripts/bootstrap-submodule.mjs b/scripts/bootstrap-submodule.mjs index a09626e..a1b45e3 100644 --- a/scripts/bootstrap-submodule.mjs +++ b/scripts/bootstrap-submodule.mjs @@ -1,7 +1,11 @@ #!/usr/bin/env node // Bootstrap the lsp-tools-mcp git submodule for local development. // CI runs the install+build steps explicitly in the workflow, so this -// script is for `npm run bootstrap` after a fresh clone. +// script is mostly for `npm run bootstrap` after a fresh clone and as a +// chained pre-step before typecheck / test / check so contributors do not +// have to remember it. +// +// Idempotent: skips when dist/cli.js already exists, unless --force is passed. import { existsSync } from "node:fs"; import { execSync } from "node:child_process"; import { dirname, join } from "node:path"; @@ -10,6 +14,8 @@ import { fileURLToPath } from "node:url"; const __dirname = dirname(fileURLToPath(import.meta.url)); const submoduleDir = join(__dirname, "..", "packages", "lsp-tools-mcp"); const submodulePackageJson = join(submoduleDir, "package.json"); +const submoduleDistCli = join(submoduleDir, "dist", "cli.js"); +const force = process.argv.includes("--force"); if (!existsSync(submodulePackageJson)) { console.error( @@ -18,6 +24,11 @@ if (!existsSync(submodulePackageJson)) { process.exit(1); } +if (!force && existsSync(submoduleDistCli)) { + // Already built; nothing to do. + process.exit(0); +} + console.log("Installing lsp-tools-mcp dependencies..."); execSync("npm ci", { cwd: submoduleDir, stdio: "inherit" });