diff --git a/doc/DEVELOPING.md b/doc/DEVELOPING.md index 97f70086..e85de611 100644 --- a/doc/DEVELOPING.md +++ b/doc/DEVELOPING.md @@ -39,6 +39,8 @@ This starts: `pnpm dev` runs the server in watch mode and restarts on changes from workspace packages (including adapter packages). Use `pnpm dev:once` to run without file watching. +`pnpm dev:once` auto-applies pending local migrations by default before starting the dev server. + `pnpm dev` and `pnpm dev:once` are now idempotent for the current repo and instance: if the matching Paperclip dev runner is already alive, Paperclip reports the existing process instead of starting a duplicate. Inspect or stop the current repo's managed dev runner: diff --git a/scripts/dev-runner.ts b/scripts/dev-runner.ts index 4ee46395..aed49c1b 100644 --- a/scripts/dev-runner.ts +++ b/scripts/dev-runner.ts @@ -85,6 +85,7 @@ const env: NodeJS.ProcessEnv = { if (mode === "dev") { env.PAPERCLIP_DEV_SERVER_STATUS_FILE = devServerStatusFilePath; + env.PAPERCLIP_MIGRATION_AUTO_APPLY ??= "true"; } if (mode === "watch") { @@ -304,11 +305,13 @@ async function updateDevServiceRecord(extra?: Record) { async function runPnpm(args: string[], options: { stdio?: "inherit" | ["ignore", "pipe", "pipe"]; env?: NodeJS.ProcessEnv; + cwd?: string; } = {}) { return await new Promise<{ code: number; signal: NodeJS.Signals | null; stdout: string; stderr: string }>((resolve, reject) => { const spawned = spawn(pnpmBin, args, { stdio: options.stdio ?? ["ignore", "pipe", "pipe"], env: options.env ?? process.env, + cwd: options.cwd, shell: process.platform === "win32", }); @@ -416,13 +419,10 @@ async function maybePreflightMigrations(options: { interactive?: boolean; autoAp return; } - const migrate = spawn(pnpmBin, ["db:migrate"], { + const exit = await runPnpm(["db:migrate"], { stdio: "inherit", env, - shell: process.platform === "win32", - }); - const exit = await new Promise<{ code: number; signal: NodeJS.Signals | null }>((resolve) => { - migrate.on("exit", (code, signal) => resolve({ code: code ?? 0, signal })); + cwd: repoRoot, }); if (exit.signal) { exitForSignal(exit.signal);