Commit 7cb8dba
fix(apps): parse backend module source instead of reading ModuleInfo#ast
The Apps backend module-graph collector read `moduleInfo.ast` in
`moduleParsed`, coupling it to whatever AST the active bundler exposes.
Rolldown — the bundler Vite 8 uses by default — deliberately stubs that
getter to throw `UNSUPPORTED: ModuleInfo#ast`, so any app with a
`.backend.ts` built under Vite 8 (or `rolldown-vite` on Vite 7) failed in
`closeBundle` with an opaque error, after the client bundle had already
succeeded.
Parse `moduleInfo.code` instead, using the plugin context's own `parse`.
A bundler then only has to supply the module's source and its resolved
dependency IDs, neither of which Rolldown withholds.
Using the context's parser rather than bundling one keeps this correct by
construction: the bundler must already have parsed this exact source to
compute `importedIds`, so anything it accepted, its own parser accepts
here. A third-party parser could disagree with the bundler; its own
cannot. Verified `this.parse` is available in `moduleParsed` under both
Rollup and Rolldown 1.1.5.
It also means no TypeScript-capable parser is needed. `moduleParsed` runs
after `transform`, so types and JSX are already gone — verified against a
real Vite 8.1.5 + Rolldown 1.1.5 build, where `'x' as string` arrives as
`"x"` and `<div/>` arrives as a `_jsx(...)` call.
Two alternatives were measured and rejected:
- Bundling `@typescript-eslint/typescript-estree`. It eagerly requires
`typescript`, which it declares only as an optional peer, so it would
have needed a deferred require to avoid dragging `typescript` into
every consumer of every published plugin — and it added a dependency
to all five of them for capability this path never exercises.
- Injecting Vite's `parseAst` export. Vite maps its `require` condition
to a reduced CJS entry that omits `parseAst` entirely, so it is
unavailable to consumers of the plugin's CJS build.
Also filters before parsing, so `node_modules` files never reach the
parser, and skips modules whose `code` is absent rather than passing a
non-string to it.
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 9797d6e commit 7cb8dba
8 files changed
Lines changed: 420 additions & 53 deletions
File tree
- packages/plugins/apps/src
- backend/ast-parsing
- vite
Lines changed: 43 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
Lines changed: 42 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
Lines changed: 18 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
17 | 24 | | |
18 | | - | |
19 | | - | |
20 | | - | |
| 25 | + | |
21 | 26 | | |
22 | 27 | | |
23 | 28 | | |
24 | 29 | | |
25 | | - | |
26 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
27 | 39 | | |
28 | 40 | | |
29 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
55 | 62 | | |
56 | 63 | | |
57 | 64 | | |
| |||
0 commit comments