Repository navigation
perf: Run JavaScript and declarations watchers in single process - #942
aXenDeveloper wants to merge 9 commits into
Conversation
`vitnode dev` in a plugin package started tsdown twice - one Node process for the JavaScript and one for the declarations - because the TypeScript compiler used to block the thread it ran on. With TypeScript 7 the compiler runs in a separate native process behind an async API, so both watchers can share one runner without a JavaScript rebuild waiting for declarations. Measured over the six package watchers `pnpm dev` starts: steady RAM 7.6 GB -> 6.4 GB, startup peak 9.2 GB -> 8.3 GB; JavaScript rebuild latency in @vitnode/core unchanged (~2 s). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CnAiFa6kGTMFMW42Wy4HFj
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
`tsc --watch` holds a whole TypeScript program per plugin package and is the largest part of what `pnpm dev` keeps in memory. `vitnode dev --no-typecheck`, or `VITNODE_DEV_TYPECHECK=0` for every package a workspace starts, leaves it out; tsdown still writes the JavaScript and the declarations, and `vitnode build` keeps type checking. Measured over the six package watchers in this repository: steady RAM 6.4 GB -> 2.8 GB, startup peak 8.3 GB -> 4.7 GB. - turbo.json (root and the create-vitnode-app template) passes the variable through to the `dev` task. - The two tsdown watchers only share a runner process when the installed TypeScript compiles natively (>= 7); TypeScript 6 keeps a process each, so its in-thread compiler cannot hold back JavaScript rebuilds. - Docs: CLI dev page, plugin build page, contribution guide and READMEs. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CnAiFa6kGTMFMW42Wy4HFj
`pnpm dev` runs `build:scripts` first, which ended in `pnpm i`. The `vitnode` bin points at the committed `packages/api/cli.mjs`, so pnpm links it on the first install whether or not `dist/scripts` exists yet - the reinstall only added start-up time. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CnAiFa6kGTMFMW42Wy4HFj
… lint The nine `*.postgres.test.ts` files only ran with `VITNODE_TEST_POSTGRES_URL` set and skipped everywhere else, CI included. They and their `tests/postgres.ts` helper are gone; AGENTS.md now says tests never need a running service. With nothing external left, `test` and `lint` are cacheable: both depend on `^build:plugins` (they read their dependencies' `dist`), so a change in a dependency invalidates them and an unchanged package is replayed from cache. The CI lint step passes `--only`, as the test step already did, because the packages are built by an earlier job and downloaded. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CnAiFa6kGTMFMW42Wy4HFj
…gram A package build ran two full TypeScript programs over the same files: tsdown emitting the declarations and `tsc --noEmit` checking the types. `tsc` now does both, and tsdown only writes the JavaScript. `tsc` emits into a staging folder under `node_modules/.cache/vitnode`, kept between runs with its incremental build info. The CLI copies what changed into `dist/src`, rewriting `@/` aliases and extensionless imports to the relative `.js` path of the compiled module and pointing declaration maps back at the sources - what tsdown's declaration step did before. - `vitnode build`: one `tsc` (check + emit) next to tsdown. - `vitnode dev`: `tsc --watch` checks and emits; the package watcher copies. - `vitnode dev --no-typecheck`: the watcher runs a short `tsc --noCheck` after each save, so no TypeScript program stays in memory. Measured on @vitnode/core (1538 modules): build 16 s / 3.9 GB -> 10 s / 2.8 GB cold, 2.8 s / 1.1 GB with a warm cache; declarations after a save 12-23 s -> ~1 s (3 s without type checking). Six package watchers: 6.4 GB -> 4.4 GB steady, 2.8 GB -> 2.0 GB without type checking. The TypeScript 6 fallback of two runner processes is gone with the in-thread declaration build it protected. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CnAiFa6kGTMFMW42Wy4HFj
…ation step - `@inquirer/prompts` and `ora` are replaced by `@clack/prompts`, which covers prompts and the spinner. Questions, defaults, validation and the non-interactive flags are unchanged; Ctrl+C, Esc and a closed stdin all end the setup with the same goodbye and exit code 0. - Creating a project no longer runs `vitnode migrate --generate` after installing. The generated `dev` script runs `vitnode db:prepare`, which generates and applies migrations on first start, so the step only made creation slower. - Removed what nothing used: `@types/prompts` and the `prepare` script, which only checked that a committed folder exists. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CnAiFa6kGTMFMW42Wy4HFj
…tsc-alias `vitnode build` in an API app ran `tsc` and then `tsc-alias` over its output to rewrite the `@/` imports. tsdown resolves the aliases while it compiles, so one pass writes `dist` (one file per module, `dist/index.js` as before) and `tsc --noEmit` checks the types next to it. JSX is compiled with React's automatic runtime, and `dist` is emptied first so deleted sources leave nothing behind. `apps/api` and the create-vitnode-app template depend on `tsdown` instead of `tsc-alias` (Bun API apps need neither). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CnAiFa6kGTMFMW42Wy4HFj
… dev The generated root `dev` script ran Turborepo three times in a row: `turbo build:plugins && turbo db:prepare && turbo dev`. It is now `turbo dev`, and the order lives in `turbo.json`: every `dev` task depends on `^build:plugins` and on the `db:prepare` of the package that owns the schema (`api#db:prepare`, or `web#db:prepare` for a single app). Naming the owner's task keeps the bootstrap one sequence point for the whole workspace - the web app of a split deployment still waits for the API's migrations - which a bare `db:prepare` would not. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CnAiFa6kGTMFMW42Wy4HFj
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cc52277b10
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const watcher: FSWatcher = watch( | ||
| emit ? join(root, "src") : staging, | ||
| { recursive: true }, | ||
| schedule, |
There was a problem hiding this comment.
Watch declaration inputs outside src in no-typecheck mode
With --no-typecheck or VITNODE_DEV_TYPECHECK=0, declaration emission only reruns for changes under src, although generated plugin tsconfigs also include types and global.d.ts, and inferred exports can depend on other workspace packages' declarations. Changes to those inputs therefore leave consumers reading stale types until a source file is touched or development restarts. I reproduced this by changing an ambient registry property's literal type: the exported function's declaration retained the old return type until src/registry.ts was touched. Watch the compiler's dependency inputs as well so disabling diagnostics does not stop declaration updates.
Useful? React with 👍 / 👎.
…lient chunks The client build merged React into the entry chunk and ProseMirror, Tiptap's core and the emoji data of `@tiptap/extension-emoji` into one 743 kB chunk. The `vitnode()` Vite plugin now declares code splitting groups for them: - entry: 358 kB -> 150 kB, with React in a 218 kB chunk that survives deploys - editor: 743 kB -> prosemirror 219 kB, tiptap 159 kB, editor-emoji 514 kB Only the grouping of modules into files changes. `editor-emoji` is a single data set and stays above the report's 500 kB warning. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CnAiFa6kGTMFMW42Wy4HFj
Description
What?
Refactored the package watch runner to execute both JavaScript and declarations watchers within a single child process instead of spawning separate processes for each. The
package-watch.tsscript now accepts multiple output arguments and creates multiple tsdown watchers that share the same Node process.Key changes:
package-watch.tsto parse multiple output types from command arguments and create watchers for eachprintfunction into aprinterfactory that creates output-specific loggerswatchPackagecalls to run concurrently viaPromise.allpackageWatchersinwatchers.tsto pass both "javascript" and "declarations" arguments to a single runner processWhy?
This optimization reduces memory overhead by consolidating two separate Node processes into one. Since TypeScript 7 runs the compiler in a separate native process behind an async API, both watchers can coexist in the same Node heap without blocking each other. The package now pays for one Node heap instead of two, while maintaining the same non-blocking behavior where JavaScript rebuilds never wait for declarations.
The change also simplifies the process management in the dev command by reducing the number of child processes that need to be spawned and tracked.