Repository navigation
wf check: TypeScript type check in a Worker over an in-memory snapshot (#322) - #330
Conversation
…napshot [#322] The locked typescript (5.x or 6.x) compiles synchronously over a bounded snapshot loaded beforehand: its lib files, the declarations of the locked graph and the project files that tsconfig.json or the manifest entries cover. Type resolution follows TypeScript within the locked graph, without flattening. Diagnostics carry file, line, column and code; nothing is written. Ctrl+C and the time limit terminate a running compilation after the grace period of wf run. The local registry fixture serves typescript 5.9.3 and 6.0.3, an unsupported 4.9.5, typed and scoped @types packages.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 49 minutes. View limit details
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
…ite under noEmit [#322] NodeNext takes a file's module format from the nearest package.json, which may lie above the directories tsconfig.json includes. Forcing composite off dropped the declaration it implies and reported TS5069 for valid configurations; only noEmit is forced now, the host still writes nothing.
There was a problem hiding this comment.
🔵 Needs a closer look
It adds a large, intricate TypeScript CompilerHost/module-resolution implementation whose correctness depends on subtle TS-internal behavior and is validated only through browser integration tests, warranting human review.
1 open issue
What changed in this PR
This PR implements wf check, a real TypeScript type check that runs in the browser inside a dedicated Worker, using the typescript version the project locks (5.x/6.x). It fits into the developer-environment epic (#303) as the type-checking counterpart to the esbuild previews, which strip types without checking them. The check runs in two phases: an asynchronous pass loads an in-memory snapshot (lib files, locked-graph declarations, project files covered by tsconfig.json or manifest entries, within bounds), then a synchronous CompilerHost compiles over that snapshot with TypeScript's own module resolution. Termination reuses the wf run Worker mechanism (Ctrl+C / --timeout, grace period, exit codes 130/124).
Changes:
- New environment modules
typecheck.mjs(page side / version gating),typecheck-worker.mjs(Worker driver), andtypecheck-snapshot.mjs(snapshot, layout, CompilerHost, diagnostics), wired intoruntime.mjsas thecheckcommand. - Registry fixture now supports scoped packages and serves typed/
@typespackages plustypescript5.9.3/6.0.3 and a synthetic unsupported 4.9.5; vendorpackage.json/lock addtypescriptand thetypescript5alias. - Build/bundle plumbing (
build.mjs,bundles.json) adds the new worker entry; docs (README, DEVELOPER_ENVIRONMENT, PROJECT_STATUS, CHANGELOG) and the browser integration test cover the feature.
| File | Description |
|---|---|
| js/developer/environment/typecheck-snapshot.mjs | New: in-memory snapshot, locked-graph layout, CompilerHost, diagnostics/report. |
| js/developer/environment/typecheck-worker.mjs | New: Worker that loads TS, runs phase 1 (async) then phase 2 (sync). |
| js/developer/environment/typecheck.mjs | New: version gating and page-side read/list host for the check. |
| js/developer/environment/runtime.mjs | Adds the check command, help text, and Worker factory. |
| js/developer/tools/registry-fixture.mjs | Adds scoped-package support and typed/@types/old-typescript fixtures. |
| js/developer/tools/registry-fixture-node.mjs | Creates parent directories for scoped packument files. |
| js/developer/tools/build.mjs | Bundles/ships typecheck-worker.mjs; tracks new inputs. |
| js/developer/environment/bundles.json | Updated source hashes for the new/changed modules. |
| js/developer/vendor/package.json, package-lock.json | Add typescript 6.0.3 and typescript5 (typescript@5.9.3). |
| test/web/developer-specs.mjs | Browser integration coverage for wf check. |
| README.md, docs/*.md | Document wf check, versions, bounds, and behavior. |
Review effort: Balanced
| } else { | ||
| const converted = ts.convertCompilerOptionsFromJson(defaultCompilerOptions, projectRoot); | ||
| options = converted.options; | ||
| errors = converted.errors; | ||
| const sources = entries.filter(entry => projectExtensions(options).some(extension => entry.endsWith(extension))); | ||
| if (!sources.length) | ||
| throw new Error('wf check needs a tsconfig.json or TypeScript entries in webfront.project.json'); | ||
| // The directories of the entries, recursively: the files they import are found there. | ||
| const directories = [...new Set(sources.map(entry => entry.includes('/') ? entry.slice(0, entry.lastIndexOf('/')) : ''))]; | ||
| const listed = await listProject(snapshot, list, directories.map(directory => [directory, true]), bounds, signal); | ||
| for (const path of new Set([...sources, ...listed.filter(projectSource(options))])) | ||
| await loadProjectFile(path); | ||
| rootNames = sources.map(entry => `${projectRoot}/${entry}`); | ||
| } |

Closes #322 (epic #303).
Summary
wf check [--timeout <seconds>]runs a real TypeScript type check in the browser with thetypescriptthe project locks.>=5.0.0 <7.0.0), tested with 5.9.3 and 6.0.3. Older versions and TypeScript 7 (native, without the JavaScript API) are refused with an explicit message.typecheck-worker.mjs):lib.*.d.tsof the locked typescript, declarations andpackage.jsonof the locked graph, project files covered bytsconfig.json(withextends) or by the manifest entries; bounded to 10,000 files / 64 MiB (50,000 listed entries);CompilerHostover the snapshot (typecheck-snapshot.mjs): a file absent from it does not exist; a truncated snapshot is reported and fails.types/typings,typescondition ofexports,@types/*,moduleResolution), limited to the locked graph without flattening: roots under/project/node_modules, each package at/packages/<id>/node_modules/<name>with its dependencies as siblings;realpathmaps to the canonical place.file(line,column): error TScode: message, exit code 1 on errors;noEmitis forced, nothing is written.wf run(runWorker): Ctrl+C /--timeoutterminate a running compilation after the 2 s grace period (codes 130 / 124).typescript5), a synthetic unsupported 4.9.5, typed packages and scoped@types/*packuments (now supported by the fixture).Docs: new section in
docs/DEVELOPER_ENVIRONMENT.md, CHANGELOG, PROJECT_STATUS, README. The pin inDeveloperReleaseData.hppstays on the published 0.4.1;bundles.jsonrecomputed.Tests
Per the maintainer's choice,
wf checkis tested only in the real browser throughwfitself (test/web/developer-specs.mjs, local registry): typescript missing, 4.9.5 refused, correct project accepted with 5.9.3 then 6.0.3, all requests to the local registry only, type error with file/line/column/code, snapshot past its bounds, long check stopped by Ctrl+C (Worker terminated after the grace period, no file written or staged, terminal usable).DeveloperBrowserIntegration,DeveloperEmbedded*,LifeEmbedded*passcheck,distribution-check,manifest-check,restore-check,scripts-check): 64/64