diff --git a/README.md b/README.md index 352aaa8f..09c4f657 100644 --- a/README.md +++ b/README.md @@ -220,7 +220,7 @@ CI runs one combined C++ / native-browser job per desktop platform on each code - WebFront owns an HTTP/WebSocket server on a background thread. Callbacks run there; avoid blocking it. Native windows must be created and shown on the main thread. Application coroutines use `app.spawn(task)` or `ui.spawn(task)`; see [execution and cancellation](docs/ASYNC_EXECUTION.md). - JavaScript calls to C++ always return Promises. C++ `ui.jsFunction(name)(...)` is fire-and-forget; `ui.jsFunction(name)(...)` returns `std::future`. Missing functions, exceptions, malformed replies and disconnects fail the typed call. - The binary bridge supports scalars, strings, tuples, numeric typed arrays and packed bitsets. Arbitrary objects do not cross it. Strings have a 16-bit encoded length limit. -- Development project access is explicit and intended for trusted local code. Downloaded tools run with the application's bridge authority. Package scripts, native Node add-ons and Node APIs are unsupported. TypeScript is transformed without type checking. +- Development project access is explicit and intended for trusted local code. Downloaded tools run with the application's bridge authority. Package scripts, native Node add-ons and Node APIs are unsupported. Previews transform TypeScript without type checking; `wf check` type-checks with the compiler the project locks. - Packaging, accessibility and native-engine deployment still need application-specific work. General DOM abstractions remain future work. See [project status](docs/PROJECT_STATUS.md) for known limitations. [Developer environment reference](docs/DEVELOPER_ENVIRONMENT.md) · [UI components](docs/UI_COMPONENTS.md) · [architecture decisions](docs/adr/README.md) · [contributing](.github/CONTRIBUTING.md) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index e3b81496..42ab1031 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -28,6 +28,13 @@ imports are refused while loading. Ctrl+C or the time limit aborts `context.signal`, then terminates the Worker after a 2 s grace period; staged writes are aborted, committed ones complete. Exit codes reach the terminal. New bridge callback `webfront.developer.list` (`developer::Store::list`). +- `wf check [--timeout ]` (developer distribution 0.5.0): a TypeScript type check in a dedicated Worker with the + `typescript` of the lock (5.x and 6.x; older versions and the native TypeScript 7 are refused). It loads an + in-memory snapshot (lib files, declarations of the locked graph, project files covered by `tsconfig.json` or the + manifest entries; at most 10,000 files and 64 MiB), then compiles synchronously over it with TypeScript's own type + resolution limited to the locked graph. Diagnostics print as `file(line,column): error TScode: message`; errors + end with code 1. Nothing is written (`noEmit`). Ctrl+C and the time limit terminate a running compilation after + the 2 s grace period. The local registry fixture serves typescript 5.9.3 and 6.0.3, typed and `@types` packages. ### Changed diff --git a/docs/DEVELOPER_ENVIRONMENT.md b/docs/DEVELOPER_ENVIRONMENT.md index 670607c0..a29c60c0 100644 --- a/docs/DEVELOPER_ENVIRONMENT.md +++ b/docs/DEVELOPER_ENVIRONMENT.md @@ -4,7 +4,8 @@ The developer environment downloads its terminal, npm resolver and WebAssembly c runtime. The application's C++ executable initially contains the bridge and a small bootstrap; it does not embed React, Babel, xterm or esbuild. Node.js and npm are **not required on the application developer's machine**. A C++ compiler, CMake and the selected native webview remain -necessary. TypeScript/JSX is transformed in the browser; type checking is not performed. +necessary. TypeScript/JSX is transformed in the browser without type checking; `wf check` type-checks the project +with the TypeScript compiler it locks. This is an experimental, explicit development facility. The downloaded environment runs with the application's bridge authority and may read/write the selected project. It exposes no shell. @@ -291,6 +292,46 @@ writes it did not await complete first; if one of them fails, the run ends with returns ends with code 0, a thrown error with 1, `exit(code)` with that code, Ctrl+C with 130 and the time limit with 124; a non-zero code is an error carrying `exitCode`. +## Type checking (`wf check`) + +Previews and providers are built by esbuild-wasm, which removes the types without checking them. `wf check +[--timeout ]` runs the TypeScript compiler of the project's lock on the project, in the browser: + +```sh +wf install typescript@6 +wf check +``` + +- **Supported versions**: `typescript` 5.x and 6.x (`>=5.0.0 <7.0.0`), whose `lib/typescript.js` provides the + compiler API; 5.9.3 and 6.0.3 are tested. An older version, or TypeScript 7 (a native program without that API), is + refused with an explicit message. The version is the one the lock records, never a copy shipped by WebFront. +- **Options**: the project's `tsconfig.json` if it exists (comments, `extends` of project or package files, + `include`/`exclude`/`files`, `compilerOptions`). Otherwise the TS/TSX entries of `webfront.project.json` are the root + files, with `target` ES2022, `module` ESNext, `moduleResolution` Bundler, `jsx` react-jsx, `lib` ES2022/DOM/ + DOM.Iterable, `strict`, `isolatedModules` and `skipLibCheck`. `noEmit` is always added (and `emitDeclarationOnly` + removed), the other options keep their meaning; nothing is written, not even build information. Project references + are not followed. +- **Two phases**: the check runs in a dedicated Worker. It first loads, asynchronously, an in-memory snapshot: the + `lib.*.d.ts` of the locked `typescript`, the declaration files and `package.json` of every locked package, then the + `.ts`/`.tsx`/`.mts`/`.cts` files (with `.js` family files under `allowJs`, `.json` under `resolveJsonModule`) and + `package.json` files of the directories that `tsconfig.json` includes, or of the entries' directories, recursively, + and the `package.json` files above them up to the project root, which give their module format. + `node_modules`, `.webfront` and `.git` are never listed. TypeScript then compiles synchronously over that snapshot: + a file absent from it does not exist, including a project file imported from outside those directories. +- **Type resolution** follows TypeScript, not esbuild: `types`/`typings`, the `types` condition of `exports`, + `@types/*` and the `moduleResolution` of `tsconfig.json`. Only the locked graph is visible, without flattening: the + project sees its roots, and each package its own dependencies. +- **Diagnostics** print as `file(line,column): error TScode: message`, with project-relative paths, or + `@/` inside a package, then a summary. Any error ends the check with code 1. +- **Bounds**: the snapshot holds at most 10,000 files and 64 MiB, and listing stops at 50,000 directory entries. A + snapshot that reaches its bounds still compiles but reports the files it left out and fails; a listing past its + bound fails at once. TypeScript itself (about 9 MiB) is read from the cache and is not counted. The Worker's memory + is the browser's; it is not limited further. +- **Time**: `--timeout` (600 seconds by default, from 1 to 3600) and Ctrl+C stop the check like `wf run`: a check + still loading its snapshot stops at its next read, and one compiling, which never returns to its event loop, is + terminated with `worker.terminate()` after the two-second grace period. The exit code is 130 (Ctrl+C) or 124 (time + limit), and the terminal stays usable. + ## Dependencies, storage and limitations - `wf install` accepts exact versions, registry tags and semver ranges, resolves ordinary diff --git a/docs/PROJECT_STATUS.md b/docs/PROJECT_STATUS.md index 03a4f7d3..9d90807b 100644 --- a/docs/PROJECT_STATUS.md +++ b/docs/PROJECT_STATUS.md @@ -124,8 +124,9 @@ Status snapshot: 2026-07-19. Optional mddlog integration note: 2026-10-02. Newco React dependencies from npm, passed PI/Life previews and deterministic generation, then compiled those public-path headers and ran both applications offline with developer callbacks absent. Pages returned HTTP 200, CORS `*` and byte-identical pinned environment data on 2026-10-20. -- Browser packages only: no installation scripts, native modules, Node API shims, optional - dependencies or TypeScript type checking. `wf run`/`wf exec` (#307) run WebFront scripts in a Worker under the +- Browser packages only: no installation scripts, native modules, Node API shims or optional + dependencies. `wf check` (#322) type-checks with the locked `typescript` 5.x/6.x in a Worker, over a bounded + in-memory snapshot. `wf run`/`wf exec` (#307) run WebFront scripts in a Worker under the manifest permissions, which frame the `context` API only and are not a sandbox. Peers require explicit compatible roots/direct dependencies. Automatic rebuild/watch is future work. `wf restore [--offline]` (0.5.0, #306) rebuilds or checks the cache from the lock, from the application's registry option, else the manifest's, else npmjs. diff --git a/js/developer/environment/bundles.json b/js/developer/environment/bundles.json index b81cb3d1..98f859a8 100644 --- a/js/developer/environment/bundles.json +++ b/js/developer/environment/bundles.json @@ -7,13 +7,16 @@ "js/developer/environment/scripts.mjs": "83ae28e822db986d9b3ae547f005f1a7c94868c36f232d68ddeb6126fb0a5021", "js/developer/environment/script-worker.mjs": "b50ddfddf696720ab0b1958c0bd327ac3a9004f37cc0aa439a9ad536fd11ac92", "js/developer/environment/permissions.mjs": "4efa523d3c90b17a2b15c116da008d439f4f8a6fc181b8a4fd59d28359965cd8", + "js/developer/environment/typecheck.mjs": "1cfd82efa7cbbdc12dfb537576fdb34add2c352ebca31affb1bc3caaabf4ea42", + "js/developer/environment/typecheck-snapshot.mjs": "2b68ae117cb39a3f67e3fe2c0b88c479ed0aed31f793c95725488b0af7d97d54", + "js/developer/environment/typecheck-worker.mjs": "7c072f7ce902ba8d6ee59015be93c3a5c358d95a5153758309ea825bd39a903e", "js/developer/environment/packages-entry.mjs": "e0b4acd4330b8b51eb0e695384c8df2b103a4be4f598ac83277838022f747e30", "js/developer/environment/bootstrap.mjs": "534af4b3d07891338c3390e1d5e06c2fb6dd8df11ca6547735565b17f1b9cd70", "js/developer/environment/bootstrap-entry.mjs": "ff8084f23f5acc721f97eb1ed0a454e7bfee1894de17d54f0100fa11f7ef8b77", "js/developer/environment/packages.mjs": "faed29500a34c6ce24756d07bd4b47b9168ccec4bd49d12f00096a869637d74d", "js/developer/environment/starter.mjs": "048cf2af36b407bc075323f78a1195b4be91ad7da51f6ce941d9fb230f314ff9", "js/developer/environment/paths.mjs": "3b6114df78eb193161c5c84499dda084cb7ff91c56a4496371c30295d00880e3", - "js/developer/environment/runtime.mjs": "47833b73c547679bdac9b20e235e55b5a6d1f8fde6b00adf5f0c636eff78d92f", + "js/developer/environment/runtime.mjs": "37e236b86100f382bb0cf96598573b6d1a22c021b909760ec8ecdc27e6aaa940", "js/developer/environment/compiler.mjs": "cc6fbe8cabbd94750045cebfdf942234247519099a192ef9cdda6ccbdbfbb6a4", "js/developer/environment/bundler.mjs": "c2f55056a4702d57207203a29226f98a95a31ae615596bf21338b7dfabe83ed9", "js/developer/environment/entry.mjs": "b2b942443e3c74ae2c008392ba244d9b7e91db70ba1b4ebbe1357c455ebf51bb", @@ -33,10 +36,10 @@ "examples/life/ui/style.css": "9bb55eb0f0a3287e5b7dc78af9d69608b87ff42c4d9c8a653bc83a52fe293c44", "js/developer/components/tools/wf.mjs": "2a8b463b2da223deb8d54d9fdd6037fdd079afeb24e39337693df03cdbcbd0ec", "js/developer/tools/distribution.json": "12b40657d1bc34c4093cd5f793d772bf3fa6fd8615ab7b766ad1756092438f83", - "js/developer/tools/build.mjs": "baf9694a38be8f80462014516c5353a627a91ca9f8985887ac42d55d7404e112", + "js/developer/tools/build.mjs": "24325d88355574ff498426c9260420ed02adf6cf1c5cfa5f98e066c048739e51", "js/developer/tools/site.mjs": "1827d3fd7e1e470336aab25ea8686c912c2b674a10f7be496f2f0077fbc45292", "js/developer/tools/archive.mjs": "bfe9feeb5e4d4e1b7c44c4dec4dcbeab4ae59c2bf16a1d2b32cd6910a2b84e7b", - "js/developer/vendor/package-lock.json": "eb545112b672f9dbf520125df1f44a878d62cc8e611f0e33baee36470ded4dec", + "js/developer/vendor/package-lock.json": "f6aefe8b4cb0b15f866f41eae425f6654d2c6c2d96438fd0da878c5651585616", "js/core/bootstrap/bootstrap.bundle.mjs": "792fe7cf564bd12ac47fef419d8c71e2070925764a17706552e7d3f5d6ba2181", "js/developer/environment/packages.bundle.mjs": "47fae31846bad6569a4f83e5fb765a8b2c01b265eb830c3c302d97d4a2d2ba68", "include/webfront/system/DeveloperReleaseData.hpp": "c97a8c3b21df3306c179f7b46d945159b5854f9d2810f135a4ab224c768c75d7" diff --git a/js/developer/environment/runtime.mjs b/js/developer/environment/runtime.mjs index 34982990..9c79a780 100644 --- a/js/developer/environment/runtime.mjs +++ b/js/developer/environment/runtime.mjs @@ -9,6 +9,7 @@ import {restore, describeRegistry} from './restore.mjs'; import {loadProject, syncNotice, resolveEntry, embedTarget, lockPath, packageRoot, noManifest} from './project.mjs'; import {parseRunOptions, scriptCommand, execTarget, scriptHost, runWorker, runResult, runDeadline, secondsLeft} from './scripts.mjs'; import {generateProvider, applicationPage} from './embed.mjs'; +import {typescriptPackage, parseCheckOptions, checkHost} from './typecheck.mjs'; const encoder = new TextEncoder(); const decoder = new TextDecoder(); @@ -176,14 +177,29 @@ async function exec(args, context) { return syncNotice(project) + await runModule(context, project, {label: `${id}:${name}`, entry, args: extra, deadline: runDeadline(timeout, context.deadline)}); } +const checkWorker = () => new Worker(new URL('./typecheck-worker.mjs', import.meta.url), {type: 'module'}); + +// wf check [--timeout ]: a TypeScript type check with the locked typescript, in a Worker that writes nothing. +// snapshotBounds lowers the snapshot's bounds for the integration test. +async function check(args, {bridge, signal, write = () => {}, createWorker = checkWorker, deadline, snapshotBounds}) { + const {timeout} = parseCheckOptions(args); + const project = await loadManifest(bridge); + const [typescript] = typescriptPackage(project.lock); + const host = checkHost(bridge); + const outcome = await runWorker({createWorker, host, signal, timeout: secondsLeft(runDeadline(timeout, deadline)), write, + message: {lock: project.lock, typescript, entries: Object.values(project.manifest.entries ?? {}), bounds: snapshotBounds}}); + await host.stop(); + return syncNotice(project) + runResult('Type check', outcome, host.publications); +} + async function list(_args, {bridge}) { const project = await loadProject(bridge); const names = Object.keys(project.lock?.packages ?? {}).sort().join('\n'); return syncNotice(project) + (names || 'No installed packages.'); } -const help = () => 'wf init [name]\nwf create [directory]\nwf install [--update] [[@range] ...]\nwf restore [--offline]\nwf run [--timeout ]