From cd0005b2bde52a130fb42dc9c2ac108ad802e590 Mon Sep 17 00:00:00 2001 From: Konstantin Wohlwend Date: Mon, 20 Oct 2025 18:03:55 -0700 Subject: [PATCH] Watch fewer open files during development --- CONTRIBUTING.md | 3 +++ apps/backend/package.json | 2 +- scripts/set-process-title.js | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 scripts/set-process-title.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 29bba0fee..8a0f24d06 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -61,6 +61,9 @@ This will work for Claude Code and everything that runs inside the integrated te # .envrc # make sure to install direnv and add it to your shell rc file (e.g. ~/.bashrc or ~/.zshrc) export NEXT_PUBLIC_STACK_PORT_PREFIX=181 + +# with this many processes running, it can be useful to add a custom title to all Node.js processes +# export NODE_OPTIONS="--require=/scripts/set-process-title.js $NODE_OPTIONS" ``` And make sure that `direnv` works in non-interactive login shells, make sure you added it to your ~/.bash_profile as well as your ~/.bashrc: diff --git a/apps/backend/package.json b/apps/backend/package.json index 1976c8a61..0d2eabc81 100644 --- a/apps/backend/package.json +++ b/apps/backend/package.json @@ -31,7 +31,7 @@ "generate-migration-imports": "pnpm run with-env tsx scripts/generate-migration-imports.ts", "generate-migration-imports:watch": "chokidar 'prisma/migrations/**/*.sql' -c 'pnpm run generate-migration-imports'", "lint": "next lint", - "watch-docs": "pnpm run with-env bash -c 'tsx watch --clear-screen=false scripts/generate-openapi-fumadocs.ts && pnpm run --filter=@stackframe/stack-docs generate-openapi-docs'", + "watch-docs": "pnpm run with-env tsx watch --exclude '**/node_modules/**' --clear-screen=false scripts/generate-openapi-fumadocs.ts", "generate-openapi-fumadocs": "pnpm run with-env tsx scripts/generate-openapi-fumadocs.ts", "generate-keys": "pnpm run with-env tsx scripts/generate-keys.ts", "db-seed-script": "pnpm run db:seed", diff --git a/scripts/set-process-title.js b/scripts/set-process-title.js new file mode 100644 index 000000000..668d667c6 --- /dev/null +++ b/scripts/set-process-title.js @@ -0,0 +1,8 @@ +// If not set, set the process title to an abridged version of the command that was used to start the process + +function escapeBashString(str) { + return str.replace(/'/g, "'\\''"); +} + +const shortenedCommand = `node ${process.argv.slice(1).map(a => escapeBashString(a)).join(' ')}`; +process.title = `[stack-auth:${process.env.NEXT_PUBLIC_STACK_PORT_PREFIX || 81}xx] ${process.title || shortenedCommand.length > 200 ? shortenedCommand.slice(0, 200) + '...' : shortenedCommand}`;