Repository navigation
feat: lazy declaration watchers and single-process workspace watch - #20
Merged
Merged
Conversation
Skip outputs that are newer than their sources on watch startup and only start a package's TypeScript watch program once it is stale or edited, so idle packages in a monorepo-wide watch only cost a chokidar watcher. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
`tsx-transform --watch --workspace` at a workspace root watches every package whose build:watch runs bite, with that script's arguments. One process avoids exhausting inotify instances (EMFILE) and the ~125 MB baseline of a watcher process per package. Stale declarations at watch startup are now emitted by a one-off program instead of a long-lived watch program, so many packages can share a process; the watch program still starts on a package's first edit. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The workspace summary was logged before each package's initial scan finished, so an edit right after it could be missed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
lerna run build:watchin sc-fe-components starts one bite process per package (54), and each one eagerly built a full TypeScript watch program. Each program loads and watches every imported file, every auto-included@types/*package and sibling packages'dist/*.d.ts. For example, Accordion has 2 source files but its program loaded 646 files and 214 MB.Change
On watch startup bite now:
Idle packages cost only a chokidar watcher on
src.Measured on sc-fe-components (all packages, after a full build)
The first edit in a package pays for starting its program: ~2.9 s in
components. After that, edits take ~0.4 s, the same as before.Notes
CreateSmallcasesandservicesusetsx-transform --clean --watch, which wipesdistand so always starts TypeScript at startup. Dropping--cleanfrom those scripts lets them start lazily too.Workspace mode (
--watch --workspace)Running all 57 per-package watchers with
lerna run build:watch --parallelhitEMFILE: too many open files. Each Node process takes one inotify instance, and Linux allows 128 per user by default.bite-tsx-transform --watch --workspaceat the repo root watches every package whosebuild:watchruns bite, using that script's own arguments (e.g.--src=theming --dist=dist), from a single process. Stale declarations at startup are now generated once instead of keeping a TypeScript watch program alive, so dozens of packages can share the process. A package's watch program still starts on its first edit.Measured on sc-fe-components with all 55 bite packages, idle:
--workspaceEdit latency is unchanged: ~2.3 s for the first
.d.tsincomponents, ~0.3 s after that. Each package edited stays loaded; with two edited it was ~1.1 GB.Suggested root script in sc-fe-components:
"build:watch": "bite-tsx-transform --watch --workspace".Testing
build:watchisn't bite, and updates declarations in a--src=lib --dist=outpackage..d.tsafter one. It fails on the previous code.🤖 Generated with Claude Code