feat(workbench-cli): generate types for federated remotes#1440
Draft
gu-stav wants to merge 1 commit into
Draft
Conversation
a0e770d to
9d4f005
Compare
Type generation was off because @module-federation/vite compiled the exposes with the app's own tsconfig, which broke on real projects: the exposes are generated .js/.jsx render-contract shims the compiler rejects without allowJs, and declaration emit then dragged in the app's noEmit source (TS2742/TS4082). Compile from a tsconfig the build owns instead, scoped with noResolve so only the shims are emitted — the app's own types can never break it. Best-effort: generation never fails the build, and errors surface in dev but stay silent in production.
9d4f005 to
9b4ed67
Compare
Contributor
📦 Bundle Stats —
|
| Metric | Value | vs main (fa1edf4) |
|---|---|---|
| Internal (raw) | 2.2 KB | - |
| Internal (gzip) | 838 B | - |
| Bundled (raw) | 11.16 MB | - |
| Bundled (gzip) | 2.10 MB | - |
| Import time | 877ms | -21ms, -2.4% |
bin:sanity
| Metric | Value | vs main (fa1edf4) |
|---|---|---|
| Internal (raw) | 782 B | - |
| Internal (gzip) | 423 B | - |
| Bundled (raw) | 9.87 MB | - |
| Bundled (gzip) | 1.78 MB | - |
| Import time | 2.27s | -13ms, -0.6% |
🗺️ View treemap · Artifacts
Details
- Import time regressions over 10% are flagged with
⚠️ - Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.
📦 Bundle Stats — @sanity/cli-core
Compared against main (fa1edf4b)
| Metric | Value | vs main (fa1edf4) |
|---|---|---|
| Internal (raw) | 108.1 KB | - |
| Internal (gzip) | 27.0 KB | - |
| Bundled (raw) | 21.72 MB | - |
| Bundled (gzip) | 3.46 MB | - |
| Import time | 775ms | +0ms, +0.0% |
🗺️ View treemap · Artifacts
Details
- Import time regressions over 10% are flagged with
⚠️ - Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.
📦 Bundle Stats — create-sanity
Compared against main (fa1edf4b)
| Metric | Value | vs main (fa1edf4) |
|---|---|---|
| Internal (raw) | 908 B | - |
| Internal (gzip) | 483 B | - |
| Bundled (raw) | 931 B | - |
| Bundled (gzip) | 491 B | - |
| Import time | ❌ ChildProcess denied: node | - |
Details
- Import time regressions over 10% are flagged with
⚠️ - Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.
Contributor
Coverage Delta
Comparing 6 changed files against main @ Overall Coverage
|
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.
Description
Federation type generation is turned off in the workbench CLI, so remotes build without any
@mf-types. Turning it back on isn't a one-liner, though: someone tried the naive version in #1282 and had to revert it in #1288.@module-federation/viteruns the TypeScript compiler over the exposed files using the app's own tsconfig. But our exposed files aren't the app's code, they're small.js/.jsxwrappers the build generates. The compiler won't touch.jswithoutallowJs, and once you add that it starts emitting.d.tsfor the app's real source, which falls over on most real projects (TS2742, TS4082).So hand the compiler its own tsconfig instead of the app's. Two settings do the work:
allowJsso it accepts the generated wrappers, androotDirplusnoResolveso it only ever looks at those wrappers and never follows their imports into the app's code. Every wrapper exports the same tiny shape (render,version), so there's nothing app-specific to generate anyway.Two guardrails: type generation logs and moves on if it hiccups rather than failing the build, and it only prints those errors during
sanity dev, notsanity build.consumeTypesis on as well. Nothing consumes remote types today, but leaving it on means a workbench app that starts loading another app's view gets its types for free. It's inert until then, since nothing configuresremotesto consume yet.What to review
plugin-sanity-federation-types.ts: the tsconfig and why each setting is there.plugin-module-federation.ts: thedtsblock.devflag threaded throughgetViteConfig,workbenchVitePluginsandfederation, which is what keeps the errors dev-only.Testing
generate-types.real.node.test.tsbuilds a small fixture app for real and checks the@mf-typesoutput actually shows up with the render contract, and that the app's own source never gets compiled into it. It fails on the current (off) build.