@valbuild/tanstack-build 0.0.0 → 0.135.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/README.md +79 -2
  3. package/dist/declarations/src/assets.d.ts +34 -0
  4. package/dist/declarations/src/build.d.ts +260 -0
  5. package/dist/declarations/src/buildTarget.d.ts +44 -0
  6. package/dist/declarations/src/contract.d.ts +135 -0
  7. package/dist/declarations/src/gitTree.d.ts +20 -0
  8. package/dist/declarations/src/index.d.ts +33 -0
  9. package/dist/declarations/src/node/cssModules.d.ts +2 -0
  10. package/dist/declarations/src/node/index.d.ts +18 -0
  11. package/dist/declarations/src/node/nodeShims.d.ts +74 -0
  12. package/dist/declarations/src/node/routeSplitter.d.ts +14 -0
  13. package/dist/declarations/src/node/routes.d.ts +29 -0
  14. package/dist/declarations/src/node/vendorLayer.d.ts +175 -0
  15. package/dist/declarations/src/paths.d.ts +4 -0
  16. package/dist/declarations/src/projectPaths.d.ts +14 -0
  17. package/dist/declarations/src/routeSplit.d.ts +29 -0
  18. package/dist/declarations/src/tailwind.d.ts +59 -0
  19. package/dist/declarations/src/tsconfigPaths.d.ts +34 -0
  20. package/dist/declarations/src/wire.d.ts +95 -0
  21. package/dist/slicedToArray-44c37acc.esm.js +303 -0
  22. package/dist/slicedToArray-7afed0af.cjs.prod.js +310 -0
  23. package/dist/slicedToArray-80b0ffd7.cjs.dev.js +310 -0
  24. package/dist/valbuild-tanstack-build.cjs.d.ts +2 -0
  25. package/dist/valbuild-tanstack-build.cjs.dev.js +3431 -0
  26. package/dist/valbuild-tanstack-build.cjs.js +7 -0
  27. package/dist/valbuild-tanstack-build.cjs.prod.js +3431 -0
  28. package/dist/valbuild-tanstack-build.esm.js +3402 -0
  29. package/node/dist/valbuild-tanstack-build-node.cjs.d.ts +2 -0
  30. package/node/dist/valbuild-tanstack-build-node.cjs.dev.js +2204 -0
  31. package/node/dist/valbuild-tanstack-build-node.cjs.js +7 -0
  32. package/node/dist/valbuild-tanstack-build-node.cjs.prod.js +2204 -0
  33. package/node/dist/valbuild-tanstack-build-node.esm.js +2165 -0
  34. package/node/package.json +4 -0
  35. package/package.json +63 -6
@@ -0,0 +1,2165 @@
1
+ import { a as _asyncToGenerator, b as _regenerator, c as _toConsumableArray, e as _objectSpread2, _ as _createForOfIteratorHelper, d as _slicedToArray } from '../../dist/slicedToArray-44c37acc.esm.js';
2
+ import { build } from 'rolldown';
3
+ import { createHash } from 'node:crypto';
4
+ import { createRequire } from 'node:module';
5
+ import { readFile, rm, writeFile, mkdir, readdir, stat } from 'node:fs/promises';
6
+ import { join, resolve, dirname } from 'node:path';
7
+ import { parseAstAsync } from 'rolldown/parseAst';
8
+ import { pathToFileURL } from 'node:url';
9
+
10
+ function _regeneratorValues(e) {
11
+ if (null != e) {
12
+ var t = e["function" == typeof Symbol && Symbol.iterator || "@@iterator"],
13
+ r = 0;
14
+ if (t) return t.call(e);
15
+ if ("function" == typeof e.next) return e;
16
+ if (!isNaN(e.length)) return {
17
+ next: function () {
18
+ return e && r >= e.length && (e = void 0), {
19
+ value: e && e[r++],
20
+ done: !e
21
+ };
22
+ }
23
+ };
24
+ }
25
+ throw new TypeError(typeof e + " is not iterable");
26
+ }
27
+
28
+ // A CJS-to-ESM bridge for Node builtins, so a CommonJS dependency can be
29
+ // layered at all.
30
+ //
31
+ // The isolate HAS the builtins. `/__api/builtins` on the loader loads a Dynamic
32
+ // Worker and imports each one: at compatibility date 2026-08-20 all 48
33
+ // candidates resolve, under both `fs` and `node:fs`, with real export counts.
34
+ // What it does not have is `require`. A package that reaches for a builtin
35
+ // through CJS -- `require("fs")`, which is what the TypeScript compiler does,
36
+ // and `@valbuild/server` embeds the TypeScript compiler because Val's content
37
+ // is `.val.ts` source and applying a patch means rewriting a TypeScript AST --
38
+ // compiles to rolldown's `__require` against an external, and that is a startup
39
+ // crash:
40
+ //
41
+ // Calling `require` for "fs" in an environment that doesn't expose the
42
+ // `require` function
43
+ //
44
+ // Routing the specifier to a bundled module that does `import * as ns from
45
+ // 'node:fs'` turns the require into a static ESM import the isolate answers.
46
+ // That is all this file is now.
47
+ //
48
+ // It used to be something else, and the difference is worth stating because the
49
+ // old framing is what made `--node-shims` look like a hole in the import audit.
50
+ // The premise was that the isolate lacked these, so the file carried a memory
51
+ // filesystem, a hand-written `os`, and a dozen modules whose every access threw
52
+ // by name. Nobody had asked the isolate. Once asked, the stubs turned out to be
53
+ // worse answers than the runtime's own -- and a forwarding bridge is not a hole
54
+ // in an audit whose job is to catch a specifier that will not resolve.
55
+ //
56
+ // What this is still NOT is a filesystem. `node:fs` in a Worker has no disk
57
+ // behind it, so a package that genuinely reads or writes fails at the call.
58
+ // That is the honest outcome, and it is the same outcome the memory filesystem
59
+ // gave for every path it had not been seeded with.
60
+
61
+ /**
62
+ * Shims that are NOT a re-export of the real builtin.
63
+ *
64
+ * There used to be a long list here: a memory filesystem, a stubbed `os`, and a
65
+ * dozen modules whose every access threw by name. All of it rested on this
66
+ * file's original premise -- that the isolate does not provide these. It does.
67
+ * `/__api/builtins` on the loader asks a Dynamic Worker directly, and at
68
+ * compatibility date 2026-08-20 all 48 candidates import under both spellings,
69
+ * `fs` with 105 exports. The stubs were answering questions the runtime could
70
+ * answer better, and they were answering some of them WRONG: a hand-written
71
+ * `os` grew a member at a time, each discovered as `X is not a function` at
72
+ * runtime.
73
+ *
74
+ * So everything that can be is now a re-export (REEXPORT, below), and this is
75
+ * what is left.
76
+ */
77
+ var NODE_SHIMS = {
78
+ // A pure-JS posix implementation rather than a re-export of `node:path`.
79
+ //
80
+ // The runtime does provide `node:path`, but a re-export has to guess how its
81
+ // namespace is shaped -- named exports, a CJS default, or both -- and a wrong
82
+ // guess does not fail at build time. It fails as `ue.join is not a function`
83
+ // from inside a minified dependency, with nothing naming the shim. Bundling
84
+ // an implementation removes the question: there is no interop left to get
85
+ // wrong. Posix only, which is all a Worker ever sees.
86
+ path: "\nconst sep = '/'\nconst delimiter = ':'\nexport function normalize(p) {\n const absolute = String(p).startsWith('/')\n const parts = []\n for (const part of String(p).split('/')) {\n if (!part || part === '.') continue\n if (part === '..') {\n if (parts.length && parts[parts.length - 1] !== '..') parts.pop()\n else if (!absolute) parts.push('..')\n } else parts.push(part)\n }\n const joined = parts.join('/')\n if (absolute) return '/' + joined\n return joined || '.'\n}\nexport function join(...parts) {\n const joined = parts.filter((part) => part !== '' && part != null).join('/')\n return joined === '' ? '.' : normalize(joined)\n}\nexport function isAbsolute(p) { return String(p).startsWith('/') }\nexport function resolve(...parts) {\n let resolved = ''\n for (let i = parts.length - 1; i >= 0; i--) {\n const part = parts[i]\n if (!part) continue\n resolved = resolved ? part + '/' + resolved : String(part)\n if (isAbsolute(part)) break\n }\n if (!isAbsolute(resolved)) resolved = '/' + resolved\n return normalize(resolved)\n}\nexport function dirname(p) {\n const s = String(p)\n const at = s.lastIndexOf('/')\n if (at === -1) return '.'\n if (at === 0) return '/'\n return s.slice(0, at)\n}\nexport function basename(p, ext) {\n const s = String(p)\n let base = s.slice(s.lastIndexOf('/') + 1)\n if (ext && base.endsWith(ext) && base !== ext) base = base.slice(0, -ext.length)\n return base\n}\nexport function extname(p) {\n const base = basename(p)\n const at = base.lastIndexOf('.')\n return at <= 0 ? '' : base.slice(at)\n}\nexport function relative(from, to) {\n const a = resolve(from).split('/').filter(Boolean)\n const b = resolve(to).split('/').filter(Boolean)\n let i = 0\n while (i < a.length && i < b.length && a[i] === b[i]) i++\n return [...a.slice(i).map(() => '..'), ...b.slice(i)].join('/')\n}\nexport function parse(p) {\n const dir = dirname(p)\n const base = basename(p)\n const ext = extname(p)\n return { root: isAbsolute(p) ? '/' : '', dir, base, ext, name: ext ? base.slice(0, -ext.length) : base }\n}\nexport function format(o) {\n const base = o.base || (o.name || '') + (o.ext || '')\n return o.dir ? join(o.dir, base) : base\n}\nexport function toNamespacedPath(p) { return p }\nconst posix = { sep, delimiter, normalize, join, isAbsolute, resolve, dirname, basename, extname, relative, parse, format, toNamespacedPath }\nposix.posix = posix\nposix.win32 = posix\nexport { sep, delimiter, posix }\nexport const win32 = posix\nexport default posix\n"
87
+ };
88
+
89
+ /**
90
+ * Builtins the isolate provides, re-exported through a bundled module.
91
+ *
92
+ * Not a stub -- these forward to the real thing. The reason they need a module
93
+ * at all is that a package requiring a builtin through CJS (`require("fs")`,
94
+ * which is what the TypeScript compiler does) becomes rolldown's `__require`
95
+ * against an external, and that throws at startup:
96
+ *
97
+ * Calling `require` for "fs" in an environment that doesn't expose the
98
+ * `require` function
99
+ *
100
+ * Routing the specifier to a bundled module turns that CJS require into a
101
+ * static ESM import of `node:fs`, which the isolate answers. That is the whole
102
+ * job: this is a CJS-to-ESM bridge, not a substitute runtime.
103
+ *
104
+ * The export names are ENUMERATED FROM NODE at build time rather than listed by
105
+ * hand. `export * from 'node:crypto'` cannot be checked against an external --
106
+ * rolldown does not know what the isolate's `node:crypto` exports, so a named
107
+ * import of it fails the build with "createPublicKey is not exported". Listing
108
+ * names by hand works and is endless: `fileURLToPath`, then `Module`, then
109
+ * `createPublicKey`, each discovered by a failed build.
110
+ *
111
+ * This CLI runs on Node, so the real module is right there to ask. A name Node
112
+ * has and the isolate does not yields `undefined`, which is what the real
113
+ * module would give.
114
+ *
115
+ * The list is every builtin the platform's dependencies have been seen to
116
+ * import, minus `path` (bundled above) -- NOT every builtin that exists.
117
+ * Importing one here costs a module load in this CLI, and the deprecated and
118
+ * experimental ones (`sys`, `wasi`, `repl`, `domain`, `trace_events`) print
119
+ * warnings for a name nothing emits. Add a name when something emits it; the
120
+ * audit will say so.
121
+ */
122
+ var REEXPORT = ["assert", "async_hooks", "buffer", "child_process", "constants", "crypto", "diagnostics_channel", "dns", "events", "fs", "fs/promises", "http", "http2", "https", "inspector", "module", "net", "os", "perf_hooks", "process", "punycode", "querystring", "readline", "stream", "stream/consumers", "stream/promises", "stream/web", "string_decoder", "timers", "timers/promises", "tls", "tty", "url", "util", "util/types", "v8", "vm", "worker_threads", "zlib"];
123
+
124
+ /**
125
+ * The re-export shims, built by asking Node what each builtin exports.
126
+ *
127
+ * Built on demand rather than at module scope, which it used to be. A top-level
128
+ * `await import('node:fs')` cannot be compiled to CommonJS at all -- the build
129
+ * of this package stops with INVALID_TLA_FORMAT -- and it was fine only for as
130
+ * long as this file was loaded as source by a runner that strips types.
131
+ *
132
+ * Memoised, so the twenty-odd dynamic imports happen once per process however
133
+ * many targets a layer build has.
134
+ */
135
+ var shims = null;
136
+ function buildShims() {
137
+ return _buildShims.apply(this, arguments);
138
+ }
139
+ /** Every shim, hand-written and generated, by builtin name. */
140
+ function _buildShims() {
141
+ _buildShims = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
142
+ var all, _iterator, _step, name, real, names, isCrypto, _t;
143
+ return _regenerator().w(function (_context) {
144
+ while (1) switch (_context.p = _context.n) {
145
+ case 0:
146
+ all = _objectSpread2({}, NODE_SHIMS);
147
+ _iterator = _createForOfIteratorHelper(REEXPORT);
148
+ _context.p = 1;
149
+ _iterator.s();
150
+ case 2:
151
+ if ((_step = _iterator.n()).done) {
152
+ _context.n = 5;
153
+ break;
154
+ }
155
+ name = _step.value;
156
+ _context.n = 3;
157
+ return import("node:".concat(name));
158
+ case 3:
159
+ real = _context.v;
160
+ names = Object.keys(real).filter(function (key) {
161
+ return key !== "default" && /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key);
162
+ }); // `ns.default ?? ns`, because the isolate's builtins are not all shaped like
163
+ // Node's. workerd's `node:path` exposes its functions on the DEFAULT export
164
+ // and not as named ones, so `import * as ns from 'node:path'; ns.join` is
165
+ // undefined -- which surfaced as a minified `I.join is not a function` from
166
+ // inside Val, with nothing pointing at the shim.
167
+ // Three sources, in order: the CJS default, the namespace, and -- for crypto
168
+ // -- the WEB global. This is the third time a re-export has been wrong about
169
+ // a builtin's shape: `path.join` was undefined (fixed by bundling path
170
+ // outright), then `crypto.randomUUID` was, because a Worker puts Web Crypto
171
+ // on `globalThis.crypto` and does not necessarily mirror every name onto
172
+ // `node:crypto`. Each failure surfaces as `X is not a function` from inside
173
+ // minified dependency code, naming nothing.
174
+ //
175
+ // `pick` binds only what it takes from the web global, and only when it is a
176
+ // function: `globalThis.crypto.subtle` is an object, and calling `.bind` on
177
+ // it is a startup crash of its own.
178
+ isCrypto = name === "crypto";
179
+ all[name] = ["import * as ns from 'node:".concat(name, "'"), "const mod = ns.default ?? ns", isCrypto ? "const web = globalThis.crypto\nconst pick = (key) => {\n const own = mod[key] ?? ns[key]\n if (own !== undefined) return own\n const fromWeb = web?.[key]\n return typeof fromWeb === 'function' ? fromWeb.bind(web) : fromWeb\n}" : "const pick = (key) => mod[key] ?? ns[key]", isCrypto ? "export default new Proxy(mod, { get: (t, p) => t[p] ?? pick(p) })" : "export default mod"].concat(_toConsumableArray(names.map(function (exported) {
180
+ return "export const ".concat(exported, " = pick(").concat(JSON.stringify(exported), ")");
181
+ }))).join("\n") + "\n";
182
+ case 4:
183
+ _context.n = 2;
184
+ break;
185
+ case 5:
186
+ _context.n = 7;
187
+ break;
188
+ case 6:
189
+ _context.p = 6;
190
+ _t = _context.v;
191
+ _iterator.e(_t);
192
+ case 7:
193
+ _context.p = 7;
194
+ _iterator.f();
195
+ return _context.f(7);
196
+ case 8:
197
+ return _context.a(2, all);
198
+ }
199
+ }, _callee, null, [[1, 6, 7, 8]]);
200
+ }));
201
+ return _buildShims.apply(this, arguments);
202
+ }
203
+ function nodeShimSources() {
204
+ if (!shims) shims = buildShims();
205
+ return shims;
206
+ }
207
+
208
+ /**
209
+ * The resolved-id prefix for a shim module. Exported so a test can ask the
210
+ * resolver what it does with a shim's own imports -- see scripts/shims-test.ts.
211
+ */
212
+ var SHIM_PREFIX = "\0platform-node-shim:";
213
+ var PREFIX = SHIM_PREFIX;
214
+
215
+ /**
216
+ * Routes a builtin specifier to a bundled module that forwards to the real one.
217
+ *
218
+ * Bundled rather than external on purpose, and the reason is the whole point of
219
+ * the file: an external leaves the CJS `require("fs")` as rolldown's
220
+ * `__require`, which an isolate with no `require` cannot answer. A bundled
221
+ * module turns it into an ESM import the isolate can.
222
+ */
223
+ function nodeShims(_x) {
224
+ return _nodeShims.apply(this, arguments);
225
+ }
226
+ function _nodeShims() {
227
+ _nodeShims = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(enabled) {
228
+ var sources;
229
+ return _regenerator().w(function (_context2) {
230
+ while (1) switch (_context2.n) {
231
+ case 0:
232
+ _context2.n = 1;
233
+ return nodeShimSources();
234
+ case 1:
235
+ sources = _context2.v;
236
+ return _context2.a(2, {
237
+ name: "platform:node-shims",
238
+ resolveId: function resolveId(source, importer) {
239
+ // Already one of ours, by its resolved id.
240
+ if (source.startsWith(PREFIX)) return source;
241
+ // `enabled` is the WORKER target. The browser has no node builtins to
242
+ // bridge to, so a package reaching for one there has to reach the audit.
243
+ if (!enabled) return null;
244
+ /*
245
+ * A SHIM reaching for the real builtin. External, always.
246
+ *
247
+ * Without this the rule below catches it and hands the shim back its own
248
+ * id, so every re-export shim imports itself: `import * as ns from
249
+ * 'node:stream'` inside the `stream` shim resolves to the `stream` shim.
250
+ * `const mod = ns.default ?? ns` then reads its own uninitialised
251
+ * binding, and the minifier -- which can see that `ns.default` IS `mod`
252
+ * -- emits `const mod = mod ?? ns` verbatim. That is a TDZ, and it threw
253
+ * on the first request that touched TanStack's SSR path:
254
+ *
255
+ * ReferenceError: Cannot access 'fs' before initialization
256
+ *
257
+ * naming a minified identifier that has nothing to do with `fs`.
258
+ *
259
+ * It was also silently wrong everywhere it did not throw: a shim that
260
+ * imports itself never reaches the builtin, so `pick()` answers
261
+ * `undefined` for every name. That is why `crypto.randomUUID` needed a
262
+ * Web Crypto fallback to work -- the `node:crypto` half was never
263
+ * reaching `node:crypto`.
264
+ *
265
+ * Safe as an external: every name in REEXPORT is in the audit's
266
+ * RUNTIME_BUILTINS, so the emitted `node:...` specifier is one the
267
+ * isolate answers.
268
+ */
269
+ if (importer !== null && importer !== void 0 && importer.startsWith(PREFIX)) {
270
+ return {
271
+ id: source,
272
+ external: true
273
+ };
274
+ }
275
+ var name = source.replace(/^node:/, "");
276
+ return name in sources ? "".concat(PREFIX).concat(name) : null;
277
+ },
278
+ load: function load(id) {
279
+ if (!id.startsWith(PREFIX)) return null;
280
+ return sources[id.slice(PREFIX.length)];
281
+ }
282
+ });
283
+ }
284
+ }, _callee2);
285
+ }));
286
+ return _nodeShims.apply(this, arguments);
287
+ }
288
+
289
+ /**
290
+ * Packages the base layer already provides.
291
+ *
292
+ * A project declares these and must -- `packages/verify` fails a project that
293
+ * does not -- but they are supplied by the platform, so building them into a
294
+ * project layer would be the duplication described above.
295
+ */
296
+ var BASE_PROVIDED = new Set(["react", "react-dom", "@tanstack/react-router", "@tanstack/react-start"]);
297
+
298
+ /**
299
+ * Chunk filename for a package.
300
+ *
301
+ * `@scope/name` becomes `scope__name`: a flat, filesystem-safe name, since
302
+ * these are module-map keys and URL segments. A package literally named
303
+ * `scope__name` would collide with a scoped one; that is unlikely enough to
304
+ * take, and it would be caught here as a duplicate rather than silently.
305
+ */
306
+ var chunkNameFor = function chunkNameFor(specifier) {
307
+ return specifier.replace(/^@/, "").replace(/\//g, "__").replace(/[^\w.-]/g, "-");
308
+ };
309
+
310
+ /**
311
+ * Stub source for one project dependency.
312
+ *
313
+ * The *base* vendor build asks Node what a package exports and writes explicit
314
+ * re-exports, because `export *` from an external CommonJS module yields no
315
+ * static named exports. That reasoning does not carry here, and copying it is
316
+ * actively wrong:
317
+ *
318
+ * - These packages are bundled, not externalised, so rolldown resolves their
319
+ * named exports statically.
320
+ * - Node's `import()` resolves under Node's conditions; the bundle resolves
321
+ * under workerd's or the browser's. For a package with no `exports` map
322
+ * those are different files with different shapes -- `react-error-boundary`
323
+ * is exactly this, and the introspected stub fails with "Missing export".
324
+ *
325
+ * So the bundler does the resolving. The default export is derived at runtime
326
+ * rather than probed, which keeps `import x from 'pkg'` working for CommonJS
327
+ * packages; a package with genuinely no default hands back its namespace, which
328
+ * is laxer than Vite but cannot fail the build.
329
+ */
330
+ var stubSource = function stubSource(specifier) {
331
+ return "import * as __ns from ".concat(JSON.stringify(specifier), "\n") + "export * from ".concat(JSON.stringify(specifier), "\n") + "export default (__ns.default ?? __ns)\n";
332
+ };
333
+
334
+ /**
335
+ * Where each target's chunks address the base layer from.
336
+ *
337
+ * Module-map specifiers resolve against the *importing* module, so a project
338
+ * chunk at `pvendor/zod.js` importing `./vendor/react.js` would look for
339
+ * `pvendor/vendor/react.js` and fail at isolate startup. Hence `../vendor/`.
340
+ * The browser has no such problem because its paths are absolute URLs.
341
+ */
342
+
343
+ /**
344
+ * The platform a layer is built against, as facts rather than as imports.
345
+ *
346
+ * This module used to read `@valbuild/vendor/externals` and
347
+ * `@valbuild/vendor/resolve` directly, which is what kept it in the same
348
+ * repository as the vendor package -- the same knot `BuildTarget` untied for
349
+ * the browser builder, one level down. The facts have not changed and they are
350
+ * still the platform's; they now ARRIVE.
351
+ *
352
+ * The three are separate because they answer at different times.
353
+ * {@link base} crosses a wire, so it is data. The other two cannot: one
354
+ * resolves against a node_modules that only the platform's own checkout has,
355
+ * and the other is a directory in it. A host that has neither passes
356
+ * `() => null` and `null`, and says so by doing it.
357
+ */
358
+
359
+ /**
360
+ * Where each target's chunks address the base layer from.
361
+ *
362
+ * Module-map specifiers resolve against the *importing* module, so a project
363
+ * chunk at `pvendor/zod.js` importing `./vendor/react.js` would look for
364
+ * `pvendor/vendor/react.js` and fail at isolate startup. Hence `../vendor/`,
365
+ * which the platform names as `paths.baseFromProject`. The browser has no such
366
+ * problem because its paths are absolute URLs, so its prefix is a literal
367
+ * here: it is a URL this package mints, not a path the platform owns.
368
+ */
369
+ var targetsFor = function targetsFor(platform) {
370
+ return [{
371
+ name: "worker",
372
+ platform: "neutral",
373
+ conditions: ["workerd", "worker", "import", "module", "default"],
374
+ // The 'neutral' platform configures no main fields, so a package with no
375
+ // `exports` map resolves to nothing and is silently left EXTERNAL -- a bare
376
+ // specifier with no module-map entry, so the cold isolate refuses to boot.
377
+ // The tell is a suspiciously tiny chunk re-exporting its own package name.
378
+ mainFields: ["module", "main"],
379
+ baseFrom: platform.base.paths.baseFromProject
380
+ }, {
381
+ name: "browser",
382
+ platform: "browser",
383
+ conditions: ["browser", "import", "module", "default"],
384
+ baseFrom: "/_vendor/"
385
+ }];
386
+ };
387
+ /** Digest of the dependency stylesheets, for the layer revision. */
388
+ var cssRev = function cssRev(css) {
389
+ var entries = Object.entries(css).sort();
390
+ if (entries.length === 0) return "";
391
+ var digest = createHash("sha256");
392
+ var _iterator = _createForOfIteratorHelper(entries),
393
+ _step;
394
+ try {
395
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
396
+ var _step$value = _slicedToArray(_step.value, 2),
397
+ specifier = _step$value[0],
398
+ text = _step$value[1];
399
+ digest.update(specifier);
400
+ digest.update(text);
401
+ }
402
+ } catch (err) {
403
+ _iterator.e(err);
404
+ } finally {
405
+ _iterator.f();
406
+ }
407
+ return digest.digest("hex").slice(0, 8);
408
+ };
409
+
410
+ /** Rolldown's errors run to dozens of lines of code frame; the first is enough. */
411
+ var firstLine = function firstLine(message) {
412
+ return message.split("\n")
413
+ // An ANSI escape IS a control character; stripping them is the point.
414
+ // eslint-disable-next-line no-control-regex
415
+ .map(function (line) {
416
+ return line.replace(/\u001b\[[0-9;]*m/g, "").trim();
417
+ }).filter(function (line) {
418
+ return line && !/^[╭│╰─]/.test(line);
419
+ }).slice(0, 2).join(" ").slice(0, 220);
420
+ };
421
+
422
+ /**
423
+ * A throwaway build, used only to find out whether a set of entries compiles.
424
+ *
425
+ * Worker target only: it is the stricter of the two (neutral platform, workerd
426
+ * conditions), so anything that survives it is very unlikely to fail the
427
+ * browser build for a reason worth attributing separately.
428
+ */
429
+ function buildTargets(_x, _x2, _x3, _x4, _x5) {
430
+ return _buildTargets.apply(this, arguments);
431
+ }
432
+ /**
433
+ * Start's per-project `imports` subpaths, stubbed for the project layer.
434
+ *
435
+ * `@tanstack/start-server-core` dynamically imports the app's router and server
436
+ * entry through these, and Start's Vite plugin fills them in per project. It is
437
+ * not in the base layer -- the shell needs its own copy, with those resolved
438
+ * for real -- so a project dependency that merely *reaches* start-server-core
439
+ * has nothing to resolve them to and cannot be built at all.
440
+ *
441
+ * Stubbed here rather than left unresolved, because the dependency almost
442
+ * certainly wants a request helper or the storage context, not a second Start
443
+ * handler. If one really does create a handler, this throws with a message
444
+ * saying so instead of failing the layer build with a bare specifier.
445
+ */
446
+ function _buildTargets() {
447
+ _buildTargets = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(names, input, outRoot, quiet, platform) {
448
+ var out, digest, _iterator6, _step6, target, forTarget, dir, shims, _iterator7, _step7, file, code, _t, _t2, _t3;
449
+ return _regenerator().w(function (_context2) {
450
+ while (1) switch (_context2.p = _context2.n) {
451
+ case 0:
452
+ out = {
453
+ worker: {},
454
+ browser: {}
455
+ };
456
+ digest = createHash("sha256");
457
+ _iterator6 = _createForOfIteratorHelper(targetsFor(platform));
458
+ _context2.p = 1;
459
+ _iterator6.s();
460
+ case 2:
461
+ if ((_step6 = _iterator6.n()).done) {
462
+ _context2.n = 17;
463
+ break;
464
+ }
465
+ target = _step6.value;
466
+ forTarget = Array.isArray(names) ? names : names[target.name]; // Nothing for this side: a dependency can be server-only, and building an
467
+ // empty bundle is both pointless and an error.
468
+ if (!(forTarget.length === 0)) {
469
+ _context2.n = 3;
470
+ break;
471
+ }
472
+ return _context2.a(3, 16);
473
+ case 3:
474
+ dir = join(outRoot, target.name);
475
+ /*
476
+ * Cleared first, because this function EMITS WHATEVER IT FINDS HERE.
477
+ *
478
+ * `buildVendorLayer` calls it twice against the same directory: once with
479
+ * every dependency, and again with the survivors when that fails and the
480
+ * per-dependency probe has worked out which to drop. rolldown writes
481
+ * before the import audit runs, so a first pass that fails IN THE AUDIT
482
+ * has already left chunks on disk -- including the chunk for the
483
+ * dependency about to be dropped.
484
+ *
485
+ * Left in place, the `readdir` below picks that chunk up again, so the
486
+ * retry re-audits the very thing it exists to exclude and fails the same
487
+ * way; and where the first pass failed for some other reason, the dropped
488
+ * dependency's code is shipped and folded into `rev`. rolldown has no
489
+ * `emptyOutDir`, so nothing else clears it.
490
+ */
491
+ _context2.n = 4;
492
+ return rm(dir, {
493
+ recursive: true,
494
+ force: true
495
+ });
496
+ case 4:
497
+ _context2.n = 5;
498
+ return nodeShims(target.name === "worker");
499
+ case 5:
500
+ shims = _context2.v;
501
+ _context2.n = 6;
502
+ return build({
503
+ input: Object.fromEntries(forTarget.map(function (name) {
504
+ return [name, input[name]];
505
+ })),
506
+ platform: target.platform,
507
+ plugins: [externaliseBase(target.baseFrom, platform), pinPlatformTanstack(platform), stubStartEntries(), stubServerEntries(target.name === "browser"),
508
+ // Worker only: a browser has no Node builtins to bridge to, and a
509
+ // package reaching for one there is a real error rather than a missing
510
+ // runtime.
511
+ shims],
512
+ transform: {
513
+ define: _objectSpread2({
514
+ "process.env.NODE_ENV": JSON.stringify("production")
515
+ }, target.name === "worker" ? {
516
+ __filename: JSON.stringify("/worker.js"),
517
+ __dirname: JSON.stringify("/"),
518
+ "import.meta.url": JSON.stringify("file:///worker.js"),
519
+ /*
520
+ * There is no disk in here, and Val is the one dependency that
521
+ * assumes there is.
522
+ *
523
+ * It picks its storage mode by inference -- a content service
524
+ * when it finds an api key, the local filesystem otherwise --
525
+ * and the third mode, where the HOST hands over the source,
526
+ * cannot be inferred at all: it is chosen by passing
527
+ * `sourceFiles`, which only the app's own server file can do.
528
+ * `wireUp` writes that file, so a project the platform wired is
529
+ * already in the right mode.
530
+ *
531
+ * A project that brings its OWN server file is not, and the
532
+ * failure was `patch-error /bundle/.val/patches.lock: EPERM` --
533
+ * the isolate's read-only filesystem, named two layers below
534
+ * the decision that led there.
535
+ *
536
+ * So this says where the code is running and lets Val decide
537
+ * what that implies, rather than naming a Val mode. Which mode
538
+ * an isolate with no disk needs is Val's to know; that it IS an
539
+ * isolate with no disk is the only part the platform can
540
+ * actually vouch for, and the part that stays true if the modes
541
+ * are ever renamed or split. Harmless to every other
542
+ * dependency, and to a Val too old to look.
543
+ */
544
+ "process.env.VAL_ENV": JSON.stringify("app")
545
+ } : {})
546
+ },
547
+ resolve: _objectSpread2({
548
+ conditionNames: target.conditions
549
+ }, "mainFields" in target ? {
550
+ mainFields: target.mainFields
551
+ } : {}),
552
+ output: {
553
+ dir: dir,
554
+ format: "esm",
555
+ entryFileNames: "[name].js",
556
+ chunkFileNames: "_p-[hash].js",
557
+ minify: true
558
+ },
559
+ onLog: function onLog(level, log, handler) {
560
+ // Quiet during the attribution probes: they are *expected* to fail, and
561
+ // the failures are reported afterwards with the specifier attached.
562
+ if (quiet) return;
563
+ // `__ns.default ?? __ns` warns for every package with no default
564
+ // export, which is the case the fallback exists for -- see stubSource.
565
+ if (log.code === "IMPORT_IS_UNDEFINED") return;
566
+ /*
567
+ * "use client" in a package being bundled for the worker.
568
+ *
569
+ * Every React package that ships the directive warns, once per module,
570
+ * and TanStack's router alone accounts for a dozen. They are expected
571
+ * and they are not actionable: this build has no client boundary to
572
+ * preserve, the shell owns that split, and nothing here reads the
573
+ * directive.
574
+ *
575
+ * Silenced because the noise did real harm. A successful publish ended
576
+ * with twenty of these and the reader took it for a failed one -- the
577
+ * line that says `published <project> @ <hash>` was the last of about
578
+ * two hundred, and everything above it looked like an error.
579
+ */
580
+ if (log.code === "MODULE_LEVEL_DIRECTIVE") return;
581
+ /*
582
+ * NOT silenced: UNRESOLVED_IMPORT. rolldown downgrades it to a warning
583
+ * and externalises the specifier, which is how an unresolvable bare
584
+ * import reaches the isolate and refuses to start. The audit below is
585
+ * what turns it into an error, and the warning is worth seeing.
586
+ */
587
+ handler(level, log);
588
+ }
589
+ });
590
+ case 6:
591
+ _t = _createForOfIteratorHelper;
592
+ _context2.n = 7;
593
+ return readdir(dir);
594
+ case 7:
595
+ _iterator7 = _t(_context2.v.sort());
596
+ _context2.p = 8;
597
+ _iterator7.s();
598
+ case 9:
599
+ if ((_step7 = _iterator7.n()).done) {
600
+ _context2.n = 13;
601
+ break;
602
+ }
603
+ file = _step7.value;
604
+ _context2.n = 10;
605
+ return readFile(join(dir, file), "utf8");
606
+ case 10:
607
+ code = _context2.v;
608
+ _context2.n = 11;
609
+ return auditImports(target, file, code, platform);
610
+ case 11:
611
+ // Worker entries are module-map keys and carry the directory; browser
612
+ // entries are served under `/_pvendor/<rev>/` and do not.
613
+ out[target.name][target.name === "worker" ? "pvendor/".concat(file) : file] = code;
614
+ digest.update("".concat(target.name, "/").concat(file));
615
+ digest.update(code);
616
+ case 12:
617
+ _context2.n = 9;
618
+ break;
619
+ case 13:
620
+ _context2.n = 15;
621
+ break;
622
+ case 14:
623
+ _context2.p = 14;
624
+ _t2 = _context2.v;
625
+ _iterator7.e(_t2);
626
+ case 15:
627
+ _context2.p = 15;
628
+ _iterator7.f();
629
+ return _context2.f(15);
630
+ case 16:
631
+ _context2.n = 2;
632
+ break;
633
+ case 17:
634
+ _context2.n = 19;
635
+ break;
636
+ case 18:
637
+ _context2.p = 18;
638
+ _t3 = _context2.v;
639
+ _iterator6.e(_t3);
640
+ case 19:
641
+ _context2.p = 19;
642
+ _iterator6.f();
643
+ return _context2.f(19);
644
+ case 20:
645
+ return _context2.a(2, _objectSpread2(_objectSpread2({}, out), {}, {
646
+ rev: digest.digest("hex").slice(0, 16)
647
+ }));
648
+ }
649
+ }, _callee2, null, [[8, 14, 15, 16], [1, 18, 19, 20]]);
650
+ }));
651
+ return _buildTargets.apply(this, arguments);
652
+ }
653
+ var START_ENTRY_STUB = "\nexport function getRouter() {\n throw new Error(\n 'A project dependency tried to create a TanStack Start handler. The platform ' +\n 'shell is the handler here, so a dependency cannot create a second one.',\n )\n}\nexport default { getRouter }\n";
654
+ var PER_PROJECT_ENTRIES = ["#tanstack-router-entry", "#tanstack-start-entry"];
655
+
656
+ /**
657
+ * TanStack Start's server entries, for the BROWSER side of a project layer.
658
+ *
659
+ * Reaching these from a browser bundle is never right, and one real package
660
+ * does it by accident. `@valbuild/tanstack`'s root entry -- the one its
661
+ * components come from -- has, inside a server-only helper:
662
+ *
663
+ * async function isValEnabled() {
664
+ * try {
665
+ * const { getCookie } = await import('@tanstack/react-start/server')
666
+ * ...
667
+ * } catch { return false }
668
+ * }
669
+ *
670
+ * At runtime in a browser that is already correct: the import fails, the catch
671
+ * returns false, which is what the function's own documentation says it does
672
+ * anywhere but a server. A bundler cannot know that. It follows the dynamic
673
+ * import, pulls in Start's whole SSR path, lands on `node:stream`, and the
674
+ * import audit rejects the chunk -- so the package is layered for the worker
675
+ * only and every component that imports it fails PLATFORM404.
676
+ *
677
+ * Stubbing restores the runtime truth at build time. The module throws when
678
+ * evaluated, so `await import(...)` rejects into the catch that is already
679
+ * there, and a STATIC import of it -- which no correct browser code has --
680
+ * fails loudly at load rather than silently shipping a server bundle.
681
+ */
682
+ var SERVER_ENTRIES = ["@tanstack/react-start/server", "@tanstack/react-start-server", "@tanstack/start-server-core"];
683
+ var SERVER_ENTRY_STUB = "\nthrow new Error(\n 'TanStack Start\\'s server entry is not available in the browser. A project ' +\n 'dependency reached it from client code; on this platform the shell owns ' +\n 'the server side. If this came from a server-only branch guarded by ' +\n 'try/catch, this is the failure it expects.',\n)\n";
684
+ function stubServerEntries(browser) {
685
+ var prefix = "\0platform:server-entry:";
686
+ return {
687
+ name: "platform:server-entries",
688
+ resolveId: function resolveId(source) {
689
+ if (!browser) return null;
690
+ return SERVER_ENTRIES.includes(source) ? prefix + source : null;
691
+ },
692
+ load: function load(id) {
693
+ return id.startsWith(prefix) ? SERVER_ENTRY_STUB : null;
694
+ }
695
+ };
696
+ }
697
+ function stubStartEntries() {
698
+ var prefix = "\0platform:start-entry:";
699
+ return {
700
+ name: "platform:start-entries",
701
+ resolveId: function resolveId(source) {
702
+ return PER_PROJECT_ENTRIES.includes(source) ? prefix + source : null;
703
+ },
704
+ load: function load(id) {
705
+ return id.startsWith(prefix) ? START_ENTRY_STUB : null;
706
+ }
707
+ };
708
+ }
709
+
710
+ /**
711
+ * TanStack is the PLATFORM'S, all of it -- not just the half in the base layer.
712
+ *
713
+ * `externaliseBase` sends the specifiers in VENDOR_MODULES to the base chunks,
714
+ * so a project's own `@tanstack/react-router` is already ignored. What it does
715
+ * not cover is the rest of the family: `@tanstack/start-server-core` is
716
+ * deliberately NOT vendored (it holds `createStartHandler`, which dynamically
717
+ * imports the app's own entry -- see externals.js), so the project layer
718
+ * bundled the PROJECT's copy of it, while that copy's imports of
719
+ * `@tanstack/start-client-core` went to the base layer.
720
+ *
721
+ * TanStack ships those two in lockstep. Splitting the pair across two layers
722
+ * pinned at different versions is a link error, and it is a link error in the
723
+ * worst available place: the module is reached through
724
+ * `await import('@tanstack/react-start/server')`, so nothing loads it until
725
+ * something asks. The isolate starts, every page renders, and the first
726
+ * request that touches a request helper answers
727
+ *
728
+ * SyntaxError: The requested module '../vendor/tanstack-start-client-core.js'
729
+ * does not provide an export named 'getSerovalPlugins'
730
+ *
731
+ * from inside a Dynamic Worker, whose console reaches no tail stream. What a
732
+ * user saw was a 500 on signing in and nothing else wrong with the site. The
733
+ * project was two patch versions ahead of the base layer: start-server-core
734
+ * 1.169.37 against start-client-core 1.170.30.
735
+ *
736
+ * So every `@tanstack/*` specifier the platform can resolve is resolved HERE,
737
+ * from `@valbuild/vendor`'s own node_modules, and the project's copy is not
738
+ * consulted. That is the contract PINS.md already states -- "the platform pins
739
+ * these versions, so a project has to use the ones carried here" -- applied
740
+ * rather than hoped for, and it is the same trade already made for react and
741
+ * the router, extended to the packages that have to agree with them.
742
+ *
743
+ * What is NOT pinned falls through to the project, which is the common case
744
+ * and the point: `@tanstack/react-devtools` and `@tanstack/react-router-devtools`
745
+ * are ordinary project dependencies the platform does not carry, and they layer
746
+ * from the project's node_modules exactly as any other dependency does.
747
+ *
748
+ * Ordered AFTER `externaliseBase`, which is what keeps the base set external:
749
+ * rolldown takes the first plugin that answers, and a base specifier resolved
750
+ * to a real file here would be bundled into the project layer instead -- a
751
+ * second React, which is the one failure this whole architecture exists to
752
+ * prevent.
753
+ */
754
+ function pinPlatformTanstack(platform) {
755
+ // Memoised because rolldown asks for the same specifier once per importer,
756
+ // and resolution walks the filesystem.
757
+ var resolved = new Map();
758
+ return {
759
+ name: "platform:pin-platform-tanstack",
760
+ resolveId: function resolveId(source) {
761
+ if (!source.startsWith("@tanstack/")) return null;
762
+ if (!resolved.has(source)) resolved.set(source, platform.resolvePlatformModule(source));
763
+ var id = resolved.get(source);
764
+ // Null is the ordinary answer for a package the platform does not carry:
765
+ // fall through, and the project's own copy is layered as usual.
766
+ return id ? {
767
+ id: id
768
+ } : null;
769
+ }
770
+ };
771
+ }
772
+
773
+ /** Externalise every base-layer specifier to its chunk in the base layer. */
774
+ function externaliseBase(baseFrom, platform) {
775
+ var modules = platform.base.modules;
776
+ return {
777
+ name: "platform:externalise-base",
778
+ resolveId: function resolveId(source) {
779
+ // One line, and deliberately: `resolveVendor` in the platform's own
780
+ // externals.js says exactly this. The RULE stays with the side that owns
781
+ // the chunks; what crosses the wire is the map it reads.
782
+ var chunk = modules[source];
783
+ return chunk ? {
784
+ id: "".concat(baseFrom).concat(chunk, ".js"),
785
+ external: true
786
+ } : null;
787
+ }
788
+ };
789
+ }
790
+
791
+ /**
792
+ * Node builtins the Worker runtime provides.
793
+ *
794
+ * The isolate runs with node compat (implied by its compatibility date), so
795
+ * these resolve at runtime and leaving them external is correct rather than a
796
+ * hole. Without this the audit rejects them, and a dependency that touches
797
+ * streams -- which on the server is most of them -- cannot be layered at all.
798
+ *
799
+ * A list rather than "anything starting with node:", because the point of the
800
+ * audit is to catch specifiers that will *not* resolve. Both spellings: bare
801
+ * `stream` and `node:stream` both occur in real packages, and node compat
802
+ * accepts either.
803
+ *
804
+ * DO NOT EDIT THIS BY HAND FROM MEMORY. It is a claim about someone else's
805
+ * runtime, and it was wrong for months in the expensive direction: it listed
806
+ * twenty names, so `fs`, `os`, `vm`, `module`, `http` and `https` read as
807
+ * unavailable, `@valbuild/tanstack/server` could not be layered, and the answer
808
+ * looked like `--node-shims` -- a whole memory filesystem bundled into every
809
+ * project to supply builtins the isolate already had. Ask the runtime instead:
810
+ *
811
+ * curl -s localhost:8787/__api/builtins | jq .both
812
+ *
813
+ * That endpoint loads a Dynamic Worker at the loader's compatibility date and
814
+ * imports each name, so its answer is the audit's ground truth. Re-run it when
815
+ * the compatibility date moves.
816
+ *
817
+ * Resolving is not the same as working: workerd's `node:fs` has no disk behind
818
+ * it and its calls fail at runtime. That is the right line for this audit all
819
+ * the same -- it exists to catch an import that breaks the isolate at STARTUP,
820
+ * which a resolvable builtin does not, and a dependency that genuinely needs a
821
+ * filesystem is a problem no import list can catch.
822
+ */
823
+ var RUNTIME_BUILTINS = new Set(["assert", "async_hooks", "buffer", "child_process", "cluster", "console", "constants", "crypto", "dgram", "diagnostics_channel", "dns", "domain", "events", "fs", "fs/promises", "http", "http2", "https", "inspector", "module", "net", "os", "path", "perf_hooks", "process", "punycode", "querystring", "readline", "repl", "stream", "stream/consumers", "stream/promises", "stream/web", "string_decoder", "sys", "timers", "timers/promises", "tls", "trace_events", "tty", "url", "util", "util/types", "v8", "vm", "wasi", "worker_threads", "zlib"]);
824
+ var isRuntimeBuiltin = function isRuntimeBuiltin(specifier) {
825
+ return RUNTIME_BUILTINS.has(specifier.replace(/^node:/, ""));
826
+ };
827
+
828
+ /**
829
+ * Every import a project chunk emits has to resolve inside the isolate: into
830
+ * the base layer, at a sibling chunk, or at a Node builtin the runtime
831
+ * provides. Anything else is a bare specifier with no module-map entry, and it
832
+ * fails at *startup* rather than at build time -- so it is checked here, where
833
+ * the cause is still in view.
834
+ *
835
+ * Parsed, not matched. This used to scan the emitted text with
836
+ * `/from\s*["']([^"']+)["']/`, which also matches inside string literals -- and
837
+ * TypeScript's diagnostic messages contain
838
+ * `Consider using 'import * as ns from "mod"'`. So bundling the TypeScript
839
+ * compiler was rejected for importing a package called `mod`, which does not
840
+ * exist and which nothing imported. `prettier` was rejected the same way. Both
841
+ * looked exactly like a genuine unresolvable dependency.
842
+ */
843
+
844
+ var nameOf = function nameOf(node) {
845
+ return typeof (node === null || node === void 0 ? void 0 : node.name) === "string" ? node.name : typeof (node === null || node === void 0 ? void 0 : node.value) === "string" ?
846
+ // `import { "a-b" as c } from` -- a string module-export-name.
847
+ node.value : null;
848
+ };
849
+ var parseModule = /*#__PURE__*/function () {
850
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(code, file) {
851
+ return _regenerator().w(function (_context) {
852
+ while (1) switch (_context.n) {
853
+ case 0:
854
+ _context.n = 1;
855
+ return parseAstAsync(code, {
856
+ lang: "js"
857
+ }, file);
858
+ case 1:
859
+ return _context.a(2, _context.v);
860
+ }
861
+ }, _callee);
862
+ }));
863
+ return function parseModule(_x6, _x7) {
864
+ return _ref.apply(this, arguments);
865
+ };
866
+ }();
867
+
868
+ /** Every import and re-export a chunk emits, with the names it takes. */
869
+ function auditableImports(_x8, _x9) {
870
+ return _auditableImports.apply(this, arguments);
871
+ }
872
+ function _auditableImports() {
873
+ _auditableImports = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(code, file) {
874
+ var ast, imports, _iterator8, _step8, _statement$source, _statement$specifiers, statement, source, names, _iterator9, _step9, specifier, name, _name, _t4;
875
+ return _regenerator().w(function (_context3) {
876
+ while (1) switch (_context3.p = _context3.n) {
877
+ case 0:
878
+ _context3.n = 1;
879
+ return parseModule(code, file);
880
+ case 1:
881
+ ast = _context3.v;
882
+ imports = [];
883
+ _iterator8 = _createForOfIteratorHelper(ast.body);
884
+ _context3.p = 2;
885
+ _iterator8.s();
886
+ case 3:
887
+ if ((_step8 = _iterator8.n()).done) {
888
+ _context3.n = 7;
889
+ break;
890
+ }
891
+ statement = _step8.value;
892
+ if (!(statement.type !== "ImportDeclaration" && statement.type !== "ExportNamedDeclaration" && statement.type !== "ExportAllDeclaration")) {
893
+ _context3.n = 4;
894
+ break;
895
+ }
896
+ return _context3.a(3, 6);
897
+ case 4:
898
+ source = (_statement$source = statement.source) === null || _statement$source === void 0 ? void 0 : _statement$source.value;
899
+ if (!(typeof source !== "string")) {
900
+ _context3.n = 5;
901
+ break;
902
+ }
903
+ return _context3.a(3, 6);
904
+ case 5:
905
+ names = [];
906
+ _iterator9 = _createForOfIteratorHelper((_statement$specifiers = statement.specifiers) !== null && _statement$specifiers !== void 0 ? _statement$specifiers : []);
907
+ try {
908
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
909
+ specifier = _step9.value;
910
+ if (specifier.type === "ImportDefaultSpecifier") names.push("default");else if (specifier.type === "ImportSpecifier") {
911
+ name = nameOf(specifier.imported);
912
+ if (name) names.push(name);
913
+ } else if (specifier.type === "ExportSpecifier") {
914
+ // Re-export: the name wanted from the OTHER module is the local one.
915
+ _name = nameOf(specifier.local);
916
+ if (_name) names.push(_name);
917
+ }
918
+ // ImportNamespaceSpecifier contributes nothing: a namespace object links
919
+ // whatever is there.
920
+ }
921
+ } catch (err) {
922
+ _iterator9.e(err);
923
+ } finally {
924
+ _iterator9.f();
925
+ }
926
+ imports.push({
927
+ source: source,
928
+ names: names
929
+ });
930
+ case 6:
931
+ _context3.n = 3;
932
+ break;
933
+ case 7:
934
+ _context3.n = 9;
935
+ break;
936
+ case 8:
937
+ _context3.p = 8;
938
+ _t4 = _context3.v;
939
+ _iterator8.e(_t4);
940
+ case 9:
941
+ _context3.p = 9;
942
+ _iterator8.f();
943
+ return _context3.f(9);
944
+ case 10:
945
+ return _context3.a(2, imports);
946
+ }
947
+ }, _callee3, null, [[2, 8, 9, 10]]);
948
+ }));
949
+ return _auditableImports.apply(this, arguments);
950
+ }
951
+ function auditableSpecifiers(_x0, _x1) {
952
+ return _auditableSpecifiers.apply(this, arguments);
953
+ }
954
+
955
+ /**
956
+ * What a BASE-layer chunk actually exports.
957
+ *
958
+ * Null means "could not be determined, do not check" -- the artifacts are not
959
+ * built, or the chunk re-exports from somewhere this does not follow. A check
960
+ * that cannot be made has to say so rather than report an empty set, which
961
+ * would fail every import into that chunk.
962
+ */
963
+ function _auditableSpecifiers() {
964
+ _auditableSpecifiers = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(code, file) {
965
+ return _regenerator().w(function (_context4) {
966
+ while (1) switch (_context4.n) {
967
+ case 0:
968
+ _context4.n = 1;
969
+ return auditableImports(code, file);
970
+ case 1:
971
+ return _context4.a(2, _context4.v.map(function (entry) {
972
+ return entry.source;
973
+ }));
974
+ }
975
+ }, _callee4);
976
+ }));
977
+ return _auditableSpecifiers.apply(this, arguments);
978
+ }
979
+ function baseChunkExports(_x10, _x11, _x12) {
980
+ return _baseChunkExports.apply(this, arguments);
981
+ }
982
+ function _baseChunkExports() {
983
+ _baseChunkExports = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(target, specifier, platform) {
984
+ var dist, file, code, ast, exported, _iterator0, _step0, _declaration$id, _statement$specifiers2, _declaration$declarat, statement, _iterator1, _step1, specifierNode, name, declaration, _iterator10, _step10, _declarator$id, declarator, _t6;
985
+ return _regenerator().w(function (_context5) {
986
+ while (1) switch (_context5.p = _context5.n) {
987
+ case 0:
988
+ dist = platform.baseLayerDir;
989
+ if (dist) {
990
+ _context5.n = 1;
991
+ break;
992
+ }
993
+ return _context5.a(2, null);
994
+ case 1:
995
+ file = join(dist, target.name, "vendor", specifier.slice(target.baseFrom.length));
996
+ _context5.p = 2;
997
+ _context5.n = 3;
998
+ return readFile(file, "utf8");
999
+ case 3:
1000
+ code = _context5.v;
1001
+ _context5.n = 5;
1002
+ break;
1003
+ case 4:
1004
+ _context5.p = 4;
1005
+ _context5.v;
1006
+ return _context5.a(2, null);
1007
+ case 5:
1008
+ _context5.n = 6;
1009
+ return parseModule(code, file);
1010
+ case 6:
1011
+ ast = _context5.v;
1012
+ exported = new Set();
1013
+ _iterator0 = _createForOfIteratorHelper(ast.body);
1014
+ _context5.p = 7;
1015
+ _iterator0.s();
1016
+ case 8:
1017
+ if ((_step0 = _iterator0.n()).done) {
1018
+ _context5.n = 13;
1019
+ break;
1020
+ }
1021
+ statement = _step0.value;
1022
+ if (!(statement.type === "ExportAllDeclaration")) {
1023
+ _context5.n = 9;
1024
+ break;
1025
+ }
1026
+ return _context5.a(2, null);
1027
+ case 9:
1028
+ if (!(statement.type === "ExportDefaultDeclaration")) {
1029
+ _context5.n = 10;
1030
+ break;
1031
+ }
1032
+ exported.add("default");
1033
+ return _context5.a(3, 12);
1034
+ case 10:
1035
+ if (!(statement.type !== "ExportNamedDeclaration")) {
1036
+ _context5.n = 11;
1037
+ break;
1038
+ }
1039
+ return _context5.a(3, 12);
1040
+ case 11:
1041
+ _iterator1 = _createForOfIteratorHelper((_statement$specifiers2 = statement.specifiers) !== null && _statement$specifiers2 !== void 0 ? _statement$specifiers2 : []);
1042
+ try {
1043
+ for (_iterator1.s(); !(_step1 = _iterator1.n()).done;) {
1044
+ specifierNode = _step1.value;
1045
+ name = nameOf(specifierNode.exported);
1046
+ if (name) exported.add(name);
1047
+ }
1048
+ // `export const x = ...` / `export function x() {}`, which a hand-written
1049
+ // chunk can carry even though a bundled one usually does not.
1050
+ } catch (err) {
1051
+ _iterator1.e(err);
1052
+ } finally {
1053
+ _iterator1.f();
1054
+ }
1055
+ declaration = statement.declaration;
1056
+ if (declaration !== null && declaration !== void 0 && (_declaration$id = declaration.id) !== null && _declaration$id !== void 0 && _declaration$id.name) exported.add(declaration.id.name);
1057
+ _iterator10 = _createForOfIteratorHelper((_declaration$declarat = declaration === null || declaration === void 0 ? void 0 : declaration.declarations) !== null && _declaration$declarat !== void 0 ? _declaration$declarat : []);
1058
+ try {
1059
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1060
+ declarator = _step10.value;
1061
+ if (((_declarator$id = declarator.id) === null || _declarator$id === void 0 ? void 0 : _declarator$id.type) === "Identifier" && declarator.id.name) {
1062
+ exported.add(declarator.id.name);
1063
+ }
1064
+ }
1065
+ } catch (err) {
1066
+ _iterator10.e(err);
1067
+ } finally {
1068
+ _iterator10.f();
1069
+ }
1070
+ case 12:
1071
+ _context5.n = 8;
1072
+ break;
1073
+ case 13:
1074
+ _context5.n = 15;
1075
+ break;
1076
+ case 14:
1077
+ _context5.p = 14;
1078
+ _t6 = _context5.v;
1079
+ _iterator0.e(_t6);
1080
+ case 15:
1081
+ _context5.p = 15;
1082
+ _iterator0.f();
1083
+ return _context5.f(15);
1084
+ case 16:
1085
+ return _context5.a(2, exported);
1086
+ }
1087
+ }, _callee5, null, [[7, 14, 15, 16], [2, 4]]);
1088
+ }));
1089
+ return _baseChunkExports.apply(this, arguments);
1090
+ }
1091
+ function auditImports(_x13, _x14, _x15, _x16) {
1092
+ return _auditImports.apply(this, arguments);
1093
+ }
1094
+ /**
1095
+ * RESOLVING IS NOT LINKING, and the gap between them cost a day.
1096
+ *
1097
+ * The check above asks whether a specifier will resolve. A base chunk always
1098
+ * does -- it is in the module map by construction -- so an import into the
1099
+ * base layer used to be waved through whatever it asked for. But an ES module
1100
+ * links by NAME, and the base layer is built from the platform's pinned
1101
+ * versions while a project's chunks are built from the project's: ask for an
1102
+ * export the platform's copy does not have and the isolate throws
1103
+ *
1104
+ * SyntaxError: The requested module '../vendor/tanstack-start-client-core.js'
1105
+ * does not provide an export named 'getSerovalPlugins'
1106
+ *
1107
+ * at the moment that module is first imported. `pinPlatformTanstack` closes
1108
+ * the case that produced that line, and this closes the CLASS: it holds for
1109
+ * any package pair the base layer splits, for a project that reaches a vendored
1110
+ * package directly, and for the next version of this that nobody has thought
1111
+ * of. PINS.md records the same failure once before, on
1112
+ * `createServerHistory` -- both would have been refused here.
1113
+ *
1114
+ * It matters most where it is least visible. A statically imported chunk fails
1115
+ * at isolate STARTUP, which is loud. A chunk behind `await import(...)` --
1116
+ * which is how `@valbuild/tanstack` reaches TanStack's server half -- fails on
1117
+ * whichever request first touches it, so the site serves every page, and one
1118
+ * endpoint answers 500 forever.
1119
+ */
1120
+ function _auditImports() {
1121
+ _auditImports = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(target, file, code, platform) {
1122
+ var _iterator11, _step11, _step11$value, specifier, names, intoBase, intoSelf, builtin, _t7, _t8;
1123
+ return _regenerator().w(function (_context6) {
1124
+ while (1) switch (_context6.p = _context6.n) {
1125
+ case 0:
1126
+ _t7 = _createForOfIteratorHelper;
1127
+ _context6.n = 1;
1128
+ return auditableImports(code, file);
1129
+ case 1:
1130
+ _iterator11 = _t7(_context6.v);
1131
+ _context6.p = 2;
1132
+ _iterator11.s();
1133
+ case 3:
1134
+ if ((_step11 = _iterator11.n()).done) {
1135
+ _context6.n = 6;
1136
+ break;
1137
+ }
1138
+ _step11$value = _step11.value, specifier = _step11$value.source, names = _step11$value.names;
1139
+ intoBase = specifier.startsWith(target.baseFrom);
1140
+ intoSelf = specifier.startsWith("./") || specifier.startsWith("../pvendor/"); // Only the worker target: a browser has no Node builtins, and a chunk that
1141
+ // reached for one there is a genuine error rather than a runtime import.
1142
+ builtin = target.name === "worker" && isRuntimeBuiltin(specifier);
1143
+ if (!(!intoBase && !intoSelf && !builtin)) {
1144
+ _context6.n = 4;
1145
+ break;
1146
+ }
1147
+ throw new Error("".concat(target.name, "/").concat(file, " imports '").concat(specifier, "', which is neither a base-layer chunk, ") + "a sibling, nor a Node builtin the runtime provides. It would be an unresolvable " + "bare specifier in the isolate.");
1148
+ case 4:
1149
+ if (!(intoBase && names.length)) {
1150
+ _context6.n = 5;
1151
+ break;
1152
+ }
1153
+ _context6.n = 5;
1154
+ return auditBaseExports(target, file, specifier, names, platform);
1155
+ case 5:
1156
+ _context6.n = 3;
1157
+ break;
1158
+ case 6:
1159
+ _context6.n = 8;
1160
+ break;
1161
+ case 7:
1162
+ _context6.p = 7;
1163
+ _t8 = _context6.v;
1164
+ _iterator11.e(_t8);
1165
+ case 8:
1166
+ _context6.p = 8;
1167
+ _iterator11.f();
1168
+ return _context6.f(8);
1169
+ case 9:
1170
+ return _context6.a(2);
1171
+ }
1172
+ }, _callee6, null, [[2, 7, 8, 9]]);
1173
+ }));
1174
+ return _auditImports.apply(this, arguments);
1175
+ }
1176
+ function auditBaseExports(_x17, _x18, _x19, _x20, _x21) {
1177
+ return _auditBaseExports.apply(this, arguments);
1178
+ }
1179
+ /** Bare specifiers that point at a stylesheet rather than a module. */
1180
+ function _auditBaseExports() {
1181
+ _auditBaseExports = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(target, file, specifier, names, platform) {
1182
+ var exported, missing;
1183
+ return _regenerator().w(function (_context7) {
1184
+ while (1) switch (_context7.n) {
1185
+ case 0:
1186
+ _context7.n = 1;
1187
+ return baseChunkExports(target, specifier, platform);
1188
+ case 1:
1189
+ exported = _context7.v;
1190
+ if (exported) {
1191
+ _context7.n = 2;
1192
+ break;
1193
+ }
1194
+ return _context7.a(2);
1195
+ case 2:
1196
+ missing = names.filter(function (name) {
1197
+ return !exported.has(name);
1198
+ });
1199
+ if (!(missing.length === 0)) {
1200
+ _context7.n = 3;
1201
+ break;
1202
+ }
1203
+ return _context7.a(2);
1204
+ case 3:
1205
+ throw new Error("".concat(target.name, "/").concat(file, " imports ").concat(missing.map(function (name) {
1206
+ return "'".concat(name, "'");
1207
+ }).join(", "), " from ") + "'".concat(specifier, "', which the base layer does not export. The base layer is built from the ") + "platform's pinned versions (packages/vendor/package.json, and PINS.md for why they are " + "exact), so this is a project resolving a version of that package which disagrees with " + "the platform's. It would link in the isolate only until something imported it, and then " + "throw \"does not provide an export named '".concat(missing[0], "'\"."));
1208
+ case 4:
1209
+ return _context7.a(2);
1210
+ }
1211
+ }, _callee7);
1212
+ }));
1213
+ return _auditBaseExports.apply(this, arguments);
1214
+ }
1215
+ function cssSpecifiersOf(files) {
1216
+ var found = new Set();
1217
+ for (var _i = 0, _Object$entries = Object.entries(files); _i < _Object$entries.length; _i++) {
1218
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
1219
+ path = _Object$entries$_i[0],
1220
+ code = _Object$entries$_i[1];
1221
+ if (!/\.(tsx?|jsx?|mjs|cjs)$/.test(path)) continue;
1222
+ var _iterator2 = _createForOfIteratorHelper(code.matchAll(/(?:from|import)\s*["']([^"'.][^"']*\.css)["']/g)),
1223
+ _step2;
1224
+ try {
1225
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1226
+ var match = _step2.value;
1227
+ found.add(match[1]);
1228
+ }
1229
+ } catch (err) {
1230
+ _iterator2.e(err);
1231
+ } finally {
1232
+ _iterator2.f();
1233
+ }
1234
+ }
1235
+ return _toConsumableArray(found);
1236
+ }
1237
+
1238
+ /** The package a bare specifier belongs to. `@scope/pkg/sub` -> `@scope/pkg`. */
1239
+ function packageOf(specifier) {
1240
+ var parts = specifier.split("/");
1241
+ return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
1242
+ }
1243
+
1244
+ /** Bare specifiers imported anywhere in the project's own source. */
1245
+ function importedSpecifiers(files) {
1246
+ var found = new Set();
1247
+ // A regex rather than a parse: this runs over every file in the project and
1248
+ // only needs the specifier, which is unambiguous in both forms. A false
1249
+ // positive costs one unused chunk; the builder's own resolver is what
1250
+ // actually decides, and it reports anything this missed.
1251
+ var IMPORT = /(?:from|import)\s*["']([^"'.][^"']*)["']|import\s*\(\s*["']([^"'.][^"']*)["']/g;
1252
+ for (var _i2 = 0, _Object$entries2 = Object.entries(files); _i2 < _Object$entries2.length; _i2++) {
1253
+ var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
1254
+ path = _Object$entries2$_i[0],
1255
+ code = _Object$entries2$_i[1];
1256
+ if (!/\.(tsx?|jsx?|mjs|cjs)$/.test(path)) continue;
1257
+ var _iterator3 = _createForOfIteratorHelper(code.matchAll(IMPORT)),
1258
+ _step3;
1259
+ try {
1260
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1261
+ var _match$;
1262
+ var match = _step3.value;
1263
+ var specifier = (_match$ = match[1]) !== null && _match$ !== void 0 ? _match$ : match[2];
1264
+ if (specifier && !specifier.startsWith("#")) found.add(specifier);
1265
+ }
1266
+ } catch (err) {
1267
+ _iterator3.e(err);
1268
+ } finally {
1269
+ _iterator3.f();
1270
+ }
1271
+ }
1272
+ return found;
1273
+ }
1274
+
1275
+ /**
1276
+ * What the layer has to carry: every specifier the project imports, not every
1277
+ * package it declares.
1278
+ *
1279
+ * Specifiers rather than package names, because a subpath is a different entry
1280
+ * point with a different module graph -- the starter template imports
1281
+ * `@valbuild/tanstack`, `@valbuild/tanstack/client` *and*
1282
+ * `@valbuild/tanstack/server`, and a layer built from package names alone
1283
+ * resolves one of the three.
1284
+ *
1285
+ * Intersected with the manifest, so a typo'd import does not silently become a
1286
+ * layer entry and an undeclared dependency still fails the verify gate.
1287
+ */
1288
+ function layerDepsOf(manifest) {
1289
+ var _manifest$dependencie;
1290
+ var files = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1291
+ // Declared dependencies only: a devDependency is tooling, and bundling it
1292
+ // into what the isolate loads would be both wasteful and surprising.
1293
+ var declared = new Set(Object.keys((_manifest$dependencie = manifest.dependencies) !== null && _manifest$dependencie !== void 0 ? _manifest$dependencie : {}).filter(function (name) {
1294
+ return !BASE_PROVIDED.has(name);
1295
+ }));
1296
+ var specifiers = new Set();
1297
+ // Packages reached only for a stylesheet. Those are collected as text by
1298
+ // collectDependencyCss; building them as code entries fails, because a
1299
+ // package like that may have no JS entry point at all.
1300
+ var cssOnly = new Set();
1301
+ var _iterator4 = _createForOfIteratorHelper(importedSpecifiers(files)),
1302
+ _step4;
1303
+ try {
1304
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1305
+ var specifier = _step4.value;
1306
+ var pkg = packageOf(specifier);
1307
+ if (!declared.has(pkg) || BASE_PROVIDED.has(pkg)) continue;
1308
+ if (specifier.endsWith(".css")) {
1309
+ cssOnly.add(pkg);
1310
+ continue;
1311
+ }
1312
+ specifiers.add(specifier);
1313
+ }
1314
+
1315
+ // A declared dependency nothing imports still gets an entry, so that a
1316
+ // project can add one and import it from the studio without a CI round-trip.
1317
+ } catch (err) {
1318
+ _iterator4.e(err);
1319
+ } finally {
1320
+ _iterator4.f();
1321
+ }
1322
+ var _iterator5 = _createForOfIteratorHelper(declared),
1323
+ _step5;
1324
+ try {
1325
+ var _loop = function _loop() {
1326
+ var name = _step5.value;
1327
+ if (cssOnly.has(name)) return 1; // continue
1328
+ if (!_toConsumableArray(specifiers).some(function (specifier) {
1329
+ return packageOf(specifier) === name;
1330
+ })) specifiers.add(name);
1331
+ };
1332
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1333
+ if (_loop()) continue;
1334
+ }
1335
+ } catch (err) {
1336
+ _iterator5.e(err);
1337
+ } finally {
1338
+ _iterator5.f();
1339
+ }
1340
+ return _toConsumableArray(specifiers).sort();
1341
+ }
1342
+
1343
+ /**
1344
+ * Scratch directory for the entry stubs.
1345
+ *
1346
+ * Inside the project, not in the system temp dir, and that is load-bearing
1347
+ * rather than tidy: a stub is resolved from where it sits, so one in /tmp finds
1348
+ * no node_modules at all and every dependency is silently left external. The
1349
+ * import audit turns that into an error, but the fix is to put the stubs where
1350
+ * the project's own installed versions are -- which is also the only correct
1351
+ * place, since the layer is meant to carry exactly what the project resolves.
1352
+ */
1353
+ var STUB_DIR = ".platform-vendor-stubs";
1354
+
1355
+ /**
1356
+ * Builds the layer, from the dependencies installed in `dir`.
1357
+ *
1358
+ * Returns `null` when the project declares nothing beyond the base set, which
1359
+ * is the same thing as having no layer -- not an empty one, because the head
1360
+ * pointer distinguishes "no layer" from "a layer that is missing".
1361
+ */
1362
+ /**
1363
+ * Reads the stylesheets a project imports from its dependencies.
1364
+ *
1365
+ * Separate from the code build: these are not bundled, they are concatenated
1366
+ * into the project's stylesheet by the builder's CSS pass. Resolution is the
1367
+ * project's own, so the version matches whatever its lockfile pinned.
1368
+ */
1369
+ function collectDependencyCss(_x22, _x23) {
1370
+ return _collectDependencyCss.apply(this, arguments);
1371
+ }
1372
+ function _collectDependencyCss() {
1373
+ _collectDependencyCss = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(dir, specifiers) {
1374
+ var require, css, _iterator12, _step12, specifier, _t0;
1375
+ return _regenerator().w(function (_context8) {
1376
+ while (1) switch (_context8.p = _context8.n) {
1377
+ case 0:
1378
+ if (!(specifiers.length === 0)) {
1379
+ _context8.n = 1;
1380
+ break;
1381
+ }
1382
+ return _context8.a(2, {});
1383
+ case 1:
1384
+ require = createRequire(join(resolve(dir), "package.json"));
1385
+ css = {};
1386
+ _iterator12 = _createForOfIteratorHelper(specifiers);
1387
+ _context8.p = 2;
1388
+ _iterator12.s();
1389
+ case 3:
1390
+ if ((_step12 = _iterator12.n()).done) {
1391
+ _context8.n = 8;
1392
+ break;
1393
+ }
1394
+ specifier = _step12.value;
1395
+ _context8.p = 4;
1396
+ _context8.n = 5;
1397
+ return readFile(require.resolve(specifier), "utf8");
1398
+ case 5:
1399
+ css[specifier] = _context8.v;
1400
+ _context8.n = 7;
1401
+ break;
1402
+ case 6:
1403
+ _context8.p = 6;
1404
+ _context8.v;
1405
+ case 7:
1406
+ _context8.n = 3;
1407
+ break;
1408
+ case 8:
1409
+ _context8.n = 10;
1410
+ break;
1411
+ case 9:
1412
+ _context8.p = 9;
1413
+ _t0 = _context8.v;
1414
+ _iterator12.e(_t0);
1415
+ case 10:
1416
+ _context8.p = 10;
1417
+ _iterator12.f();
1418
+ return _context8.f(10);
1419
+ case 11:
1420
+ return _context8.a(2, css);
1421
+ }
1422
+ }, _callee8, null, [[4, 6], [2, 9, 10, 11]]);
1423
+ }));
1424
+ return _collectDependencyCss.apply(this, arguments);
1425
+ }
1426
+ function buildVendorLayer(_x24, _x25, _x26, _x27) {
1427
+ return _buildVendorLayer.apply(this, arguments);
1428
+ }
1429
+ function _buildVendorLayer() {
1430
+ _buildVendorLayer = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(dir, deps, css, platform) {
1431
+ var modules, _iterator13, _step13, _loop2, stubs, input, _i3, _Object$entries3, _Object$entries3$_i, specifier, name, file, skipped, workerOnly, workerOnlyReasons, specifierOf, usable, built, _i4, _Object$values, _name2, worked, reasons, _iterator14, _step14, target, _message, _reasons$, _i5, _Object$entries4, _Object$entries4$_i, _specifier, _name3, _t1, _t10, _t11;
1432
+ return _regenerator().w(function (_context0) {
1433
+ while (1) switch (_context0.p = _context0.n) {
1434
+ case 0:
1435
+ if (!(deps.length === 0 && Object.keys(css).length === 0)) {
1436
+ _context0.n = 1;
1437
+ break;
1438
+ }
1439
+ return _context0.a(2, null);
1440
+ case 1:
1441
+ if (!(deps.length === 0)) {
1442
+ _context0.n = 2;
1443
+ break;
1444
+ }
1445
+ return _context0.a(2, {
1446
+ rev: cssRev(css),
1447
+ modules: {},
1448
+ worker: {},
1449
+ browser: {},
1450
+ css: css,
1451
+ skipped: [],
1452
+ workerOnly: [],
1453
+ workerOnlyReasons: {}
1454
+ });
1455
+ case 2:
1456
+ modules = {};
1457
+ _iterator13 = _createForOfIteratorHelper(deps);
1458
+ _context0.p = 3;
1459
+ _loop2 = /*#__PURE__*/_regenerator().m(function _loop2() {
1460
+ var specifier, name, clash;
1461
+ return _regenerator().w(function (_context9) {
1462
+ while (1) switch (_context9.n) {
1463
+ case 0:
1464
+ specifier = _step13.value;
1465
+ name = chunkNameFor(specifier);
1466
+ clash = Object.entries(modules).find(function (_ref4) {
1467
+ var _ref5 = _slicedToArray(_ref4, 2),
1468
+ existing = _ref5[1];
1469
+ return existing === name;
1470
+ });
1471
+ if (!clash) {
1472
+ _context9.n = 1;
1473
+ break;
1474
+ }
1475
+ throw new Error("'".concat(specifier, "' and '").concat(clash[0], "' both map to the chunk name '").concat(name, "'. ") + "Rename is not an option, so this needs chunkNameFor to disambiguate.");
1476
+ case 1:
1477
+ modules[specifier] = name;
1478
+ case 2:
1479
+ return _context9.a(2);
1480
+ }
1481
+ }, _loop2);
1482
+ });
1483
+ _iterator13.s();
1484
+ case 4:
1485
+ if ((_step13 = _iterator13.n()).done) {
1486
+ _context0.n = 6;
1487
+ break;
1488
+ }
1489
+ return _context0.d(_regeneratorValues(_loop2()), 5);
1490
+ case 5:
1491
+ _context0.n = 4;
1492
+ break;
1493
+ case 6:
1494
+ _context0.n = 8;
1495
+ break;
1496
+ case 7:
1497
+ _context0.p = 7;
1498
+ _t1 = _context0.v;
1499
+ _iterator13.e(_t1);
1500
+ case 8:
1501
+ _context0.p = 8;
1502
+ _iterator13.f();
1503
+ return _context0.f(8);
1504
+ case 9:
1505
+ // `resolve` rather than `join`, and the CLI's own default argument is why.
1506
+ //
1507
+ // A stub's path becomes a rolldown entry, and rolldown resolves a relative
1508
+ // entry against its own working directory rather than this one. `platform-
1509
+ // publish .` -- the usage line in cli.ts, and the natural thing to type --
1510
+ // made every entry `.platform-vendor-stubs/<name>.js`, which resolved
1511
+ // nowhere, so EVERY dependency failed with UNRESOLVED_ENTRY and the project
1512
+ // was reported as declaring nothing beyond the base set. The per-dependency
1513
+ // retry then repeated the same failure once per dependency, which reads as
1514
+ // nine unrelated problems rather than one.
1515
+ //
1516
+ // Nothing caught it because every caller that existed passed an absolute
1517
+ // path: the suites all build in a mkdtemp. The one caller that does not is
1518
+ // the one a person uses.
1519
+ stubs = join(resolve(dir), STUB_DIR);
1520
+ _context0.n = 10;
1521
+ return rm(stubs, {
1522
+ recursive: true,
1523
+ force: true
1524
+ });
1525
+ case 10:
1526
+ _context0.n = 11;
1527
+ return mkdir(stubs, {
1528
+ recursive: true
1529
+ });
1530
+ case 11:
1531
+ _context0.p = 11;
1532
+ input = {};
1533
+ _i3 = 0, _Object$entries3 = Object.entries(modules);
1534
+ case 12:
1535
+ if (!(_i3 < _Object$entries3.length)) {
1536
+ _context0.n = 15;
1537
+ break;
1538
+ }
1539
+ _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2), specifier = _Object$entries3$_i[0], name = _Object$entries3$_i[1];
1540
+ file = join(stubs, "".concat(name, ".js"));
1541
+ _context0.n = 13;
1542
+ return writeFile(file, stubSource(specifier));
1543
+ case 13:
1544
+ input[name] = file;
1545
+ case 14:
1546
+ _i3++;
1547
+ _context0.n = 12;
1548
+ break;
1549
+ case 15:
1550
+ // Fast path: one build with every entry, so shared code is shared. When it
1551
+ // fails, rolldown reports against a file deep inside a package rather than
1552
+ // against the entry that pulled it in, so the only way to learn *which*
1553
+ // dependency is at fault is to try them one at a time.
1554
+ skipped = [];
1555
+ /** Built for the worker but not the browser: server-only dependencies. */
1556
+ workerOnly = [];
1557
+ /** Why each of those failed its browser build. Reporting only. */
1558
+ workerOnlyReasons = {};
1559
+ specifierOf = function specifierOf(chunk) {
1560
+ return Object.entries(modules).find(function (_ref2) {
1561
+ var _ref3 = _slicedToArray(_ref2, 2),
1562
+ name = _ref3[1];
1563
+ return name === chunk;
1564
+ })[0];
1565
+ };
1566
+ usable = Object.values(modules);
1567
+ _context0.n = 16;
1568
+ return buildTargets(usable, input, join(stubs, "out"), false, platform)["catch"](function () {
1569
+ return null;
1570
+ });
1571
+ case 16:
1572
+ built = _context0.v;
1573
+ if (built) {
1574
+ _context0.n = 32;
1575
+ break;
1576
+ }
1577
+ usable = [];
1578
+ _i4 = 0, _Object$values = Object.values(modules);
1579
+ case 17:
1580
+ if (!(_i4 < _Object$values.length)) {
1581
+ _context0.n = 29;
1582
+ break;
1583
+ }
1584
+ _name2 = _Object$values[_i4];
1585
+ // Probed per target, because the two sides are not the same question.
1586
+ // `@valbuild/tanstack/server` cannot build for a browser -- it reaches
1587
+ // TanStack's SSR path, which lands on `node:stream/web` -- and it has no
1588
+ // business being in a browser bundle either. Failing it outright would
1589
+ // mean a server-only dependency can never be layered at all, so a
1590
+ // package that builds for the worker and not the browser is kept as
1591
+ // server-only, and importing it from client code is rejected later by
1592
+ // the builder, naming it.
1593
+ worked = {};
1594
+ reasons = [];
1595
+ _iterator14 = _createForOfIteratorHelper(targetsFor(platform));
1596
+ _context0.p = 18;
1597
+ _iterator14.s();
1598
+ case 19:
1599
+ if ((_step14 = _iterator14.n()).done) {
1600
+ _context0.n = 24;
1601
+ break;
1602
+ }
1603
+ target = _step14.value;
1604
+ _context0.p = 20;
1605
+ _context0.n = 21;
1606
+ return buildTargets({
1607
+ worker: target.name === "worker" ? [_name2] : [],
1608
+ browser: target.name === "browser" ? [_name2] : []
1609
+ }, input, join(stubs, "probe", target.name, _name2), true, platform);
1610
+ case 21:
1611
+ worked[target.name] = true;
1612
+ _context0.n = 23;
1613
+ break;
1614
+ case 22:
1615
+ _context0.p = 22;
1616
+ _t10 = _context0.v;
1617
+ worked[target.name] = false;
1618
+ reasons.push(firstLine(String((_message = _t10 === null || _t10 === void 0 ? void 0 : _t10.message) !== null && _message !== void 0 ? _message : _t10)));
1619
+ case 23:
1620
+ _context0.n = 19;
1621
+ break;
1622
+ case 24:
1623
+ _context0.n = 26;
1624
+ break;
1625
+ case 25:
1626
+ _context0.p = 25;
1627
+ _t11 = _context0.v;
1628
+ _iterator14.e(_t11);
1629
+ case 26:
1630
+ _context0.p = 26;
1631
+ _iterator14.f();
1632
+ return _context0.f(26);
1633
+ case 27:
1634
+ if (worked.worker && worked.browser) usable.push(_name2);else if (worked.worker) {
1635
+ usable.push(_name2);
1636
+ workerOnly.push(specifierOf(_name2));
1637
+ // Kept, because throwing it away is what made this class of failure
1638
+ // undebuggable. `workerOnly` says a dependency is server-only and
1639
+ // PLATFORM404 says importing it from a component is an error, and
1640
+ // between them they never said WHY it could not be built for a
1641
+ // browser -- which is the only thing that tells you whether to change
1642
+ // the import or fix the package.
1643
+ if (reasons[0]) workerOnlyReasons[specifierOf(_name2)] = reasons[0];
1644
+ } else {
1645
+ skipped.push({
1646
+ specifier: specifierOf(_name2),
1647
+ reason: (_reasons$ = reasons[0]) !== null && _reasons$ !== void 0 ? _reasons$ : "build failed"
1648
+ });
1649
+ }
1650
+ case 28:
1651
+ _i4++;
1652
+ _context0.n = 17;
1653
+ break;
1654
+ case 29:
1655
+ for (_i5 = 0, _Object$entries4 = Object.entries(modules); _i5 < _Object$entries4.length; _i5++) {
1656
+ _Object$entries4$_i = _slicedToArray(_Object$entries4[_i5], 2), _specifier = _Object$entries4$_i[0], _name3 = _Object$entries4$_i[1];
1657
+ if (!usable.includes(_name3)) delete modules[_specifier];
1658
+ }
1659
+ // Everything failed: a layer with no entries is the same as no layer, and
1660
+ // the skip list is what the caller reports.
1661
+ if (!(usable.length === 0)) {
1662
+ _context0.n = 30;
1663
+ break;
1664
+ }
1665
+ return _context0.a(2, {
1666
+ rev: "none",
1667
+ modules: {},
1668
+ worker: {},
1669
+ browser: {},
1670
+ css: css,
1671
+ skipped: skipped,
1672
+ workerOnly: workerOnly,
1673
+ workerOnlyReasons: workerOnlyReasons
1674
+ });
1675
+ case 30:
1676
+ _context0.n = 31;
1677
+ return buildTargets({
1678
+ worker: usable,
1679
+ browser: usable.filter(function (name) {
1680
+ return !workerOnly.includes(specifierOf(name));
1681
+ })
1682
+ }, input, join(stubs, "out"), false, platform);
1683
+ case 31:
1684
+ built = _context0.v;
1685
+ case 32:
1686
+ return _context0.a(2, {
1687
+ rev: "".concat(built.rev).concat(cssRev(css) ? "-".concat(cssRev(css)) : ""),
1688
+ modules: modules,
1689
+ worker: built.worker,
1690
+ browser: built.browser,
1691
+ css: css,
1692
+ skipped: skipped,
1693
+ workerOnly: workerOnly,
1694
+ workerOnlyReasons: workerOnlyReasons
1695
+ });
1696
+ case 33:
1697
+ _context0.p = 33;
1698
+ _context0.n = 34;
1699
+ return rm(stubs, {
1700
+ recursive: true,
1701
+ force: true
1702
+ });
1703
+ case 34:
1704
+ return _context0.f(33);
1705
+ case 35:
1706
+ return _context0.a(2);
1707
+ }
1708
+ }, _callee9, null, [[20, 22], [18, 25, 26, 27], [11,, 33, 35], [3, 7, 8, 9]]);
1709
+ }));
1710
+ return _buildVendorLayer.apply(this, arguments);
1711
+ }
1712
+
1713
+ /**
1714
+ * `import(url)`, out of reach of the CommonJS build.
1715
+ *
1716
+ * Rollup compiles a dynamic `import(x)` in this package's CJS output to
1717
+ * `require(x)`, and `require` does not accept a `file://` URL. So the three
1718
+ * places that load a module BY PATH at runtime — a project's Tailwind plugin,
1719
+ * and TanStack's two code-splitter internals — failed with
1720
+ *
1721
+ * Cannot find module 'file:///…/node_modules/@tailwindcss/typography/src/index.js'
1722
+ *
1723
+ * naming a file that is plainly there. Nothing caught it before this package
1724
+ * moved to npm, because the only thing that had ever loaded this code was a
1725
+ * runner that strips types and leaves the ESM alone.
1726
+ *
1727
+ * `new Function` because the point is to be invisible to the bundler: any
1728
+ * spelling rollup can see, it rewrites. Node-only code, so there is no CSP to
1729
+ * be hostile to.
1730
+ *
1731
+ * **Absolute `file://` URLs only.** The function body has no module of its own,
1732
+ * so a bare specifier would resolve against the process's working directory
1733
+ * rather than against the caller — which is a different module or none at all.
1734
+ * A bare specifier stays an ordinary `import()`: `require()` of a package is
1735
+ * something Node answers, including for an ESM-only one.
1736
+ */
1737
+ var importByUrl = new Function("url", "return import(url)");
1738
+ function dynamicImport(url) {
1739
+ return importByUrl(url);
1740
+ }
1741
+
1742
+ function cssModuleLoader(dir) {
1743
+ // Absolute: the dir arrives however the caller spelled it, and createRequire
1744
+ // rejects a relative path.
1745
+ var require = createRequire(join(resolve(dir), "package.json"));
1746
+ return /*#__PURE__*/function () {
1747
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(id, base, hint) {
1748
+ var _loaded$default;
1749
+ var resolved, loaded;
1750
+ return _regenerator().w(function (_context) {
1751
+ while (1) switch (_context.p = _context.n) {
1752
+ case 0:
1753
+ _context.p = 0;
1754
+ resolved = require.resolve(id, {
1755
+ paths: [base, dir]
1756
+ });
1757
+ _context.n = 2;
1758
+ break;
1759
+ case 1:
1760
+ _context.p = 1;
1761
+ _context.v;
1762
+ throw new Error("Tailwind's '@".concat(hint, " \"").concat(id, "\"' could not be resolved from the project. ") + "Add it to package.json and install, or remove the directive.");
1763
+ case 2:
1764
+ _context.n = 3;
1765
+ return dynamicImport(pathToFileURL(resolved).href);
1766
+ case 3:
1767
+ loaded = _context.v;
1768
+ return _context.a(2, {
1769
+ path: resolved,
1770
+ base: dirname(resolved),
1771
+ module: (_loaded$default = loaded["default"]) !== null && _loaded$default !== void 0 ? _loaded$default : loaded
1772
+ });
1773
+ }
1774
+ }, _callee, null, [[0, 1]]);
1775
+ }));
1776
+ return function (_x, _x2, _x3) {
1777
+ return _ref.apply(this, arguments);
1778
+ };
1779
+ }();
1780
+ }
1781
+
1782
+ /**
1783
+ * What the compilers are given, which is only ever what `shared()` below builds.
1784
+ *
1785
+ * Typed here rather than left as `any` because this side constructs it: the
1786
+ * plugin's own types are not reachable (these are internals, loaded by file
1787
+ * path, and its `exports` map does not list them), but the shape handed over
1788
+ * is not a mystery.
1789
+ */
1790
+ /**
1791
+ * Loads the compilers from the installed plugin.
1792
+ *
1793
+ * By file path, not by specifier: these are internals and the package's
1794
+ * `exports` does not list them, so a subpath import is refused. That is also
1795
+ * why valbuild/home's `packages/upstream` pins the file -- if it moves, this
1796
+ * breaks, and that drift check is what says so first. It stays there rather
1797
+ * than moving with this code: it compares a pin against an INSTALLED tree, and
1798
+ * the platform is where both the pin and the installed TanStack live.
1799
+ *
1800
+ * "Not installed" and "installed but moved" are different outcomes on purpose.
1801
+ * The first is fine, and means no splitting. The second is the thing worth
1802
+ * hearing about, and a bare catch around both would have hidden it -- as it
1803
+ * did, the first time this was written.
1804
+ *
1805
+ * `from` is where to resolve the plugin, and it belongs to the PUBLISHER
1806
+ * rather than to the project. Splitting is a property of what is doing the
1807
+ * building -- this same code in a browser tab does not split at all, because
1808
+ * the plugin is built on Babel -- so a project must not have to install a build
1809
+ * plugin to get it. A publisher that carries the plugin passes its own
1810
+ * location; one that does not passes anything and gets null.
1811
+ *
1812
+ * It is a parameter at all because `import.meta.url` is not available here:
1813
+ * this package is built to CommonJS as well as ESM, and `import.meta` is a
1814
+ * syntax error there.
1815
+ */
1816
+ function loadCompilers(_x) {
1817
+ return _loadCompilers.apply(this, arguments);
1818
+ }
1819
+ /**
1820
+ * Returns a splitter, or null when `@tanstack/router-plugin` is not installed
1821
+ * where `from` can see it.
1822
+ *
1823
+ * Null rather than throwing: not splitting is a valid outcome, and a project
1824
+ * that has not asked for it should not be made to install a build plugin.
1825
+ *
1826
+ * `from` is a DIRECTORY to resolve the plugin from, and it is the publisher's
1827
+ * own -- see `loadCompilers`. A caller that wants the project's copy instead
1828
+ * can pass the project directory, but that is a different decision from the
1829
+ * one this was written for.
1830
+ */
1831
+ function _loadCompilers() {
1832
+ _loadCompilers = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(from) {
1833
+ var core, require, compilers, constants, _message, _t2;
1834
+ return _regenerator().w(function (_context) {
1835
+ while (1) switch (_context.p = _context.n) {
1836
+ case 0:
1837
+ _context.p = 0;
1838
+ // Absolute: `createRequire` rejects a relative path, and the path arrives
1839
+ // however the caller spelled it.
1840
+ require = createRequire(join(resolve(from), "package.json"));
1841
+ core = join(dirname(require.resolve("@tanstack/router-plugin/package.json")), "dist/esm/core");
1842
+ _context.n = 2;
1843
+ break;
1844
+ case 1:
1845
+ _context.p = 1;
1846
+ _context.v;
1847
+ return _context.a(2, null);
1848
+ case 2:
1849
+ _context.p = 2;
1850
+ _context.n = 3;
1851
+ return dynamicImport(pathToFileURL(join(core, "code-splitter/compilers.js")).href);
1852
+ case 3:
1853
+ compilers = _context.v;
1854
+ _context.n = 4;
1855
+ return dynamicImport(pathToFileURL(join(core, "constants.js")).href);
1856
+ case 4:
1857
+ constants = _context.v;
1858
+ return _context.a(2, _objectSpread2(_objectSpread2({}, compilers), {}, {
1859
+ groupings: constants.defaultCodeSplitGroupings
1860
+ }));
1861
+ case 5:
1862
+ _context.p = 5;
1863
+ _t2 = _context.v;
1864
+ throw new Error("@tanstack/router-plugin is installed but its code splitter could not be loaded: " + "".concat(String((_message = _t2 === null || _t2 === void 0 ? void 0 : _t2.message) !== null && _message !== void 0 ? _message : _t2).split("\n")[0], ". ") + "Its internals have moved.", {
1865
+ cause: _t2
1866
+ });
1867
+ case 6:
1868
+ return _context.a(2);
1869
+ }
1870
+ }, _callee, null, [[2, 5], [0, 1]]);
1871
+ }));
1872
+ return _loadCompilers.apply(this, arguments);
1873
+ }
1874
+ function routeSplitter(_x2) {
1875
+ return _routeSplitter.apply(this, arguments);
1876
+ }
1877
+ function _routeSplitter() {
1878
+ _routeSplitter = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(from) {
1879
+ var compilers, shared;
1880
+ return _regenerator().w(function (_context2) {
1881
+ while (1) switch (_context2.n) {
1882
+ case 0:
1883
+ _context2.n = 1;
1884
+ return loadCompilers(from);
1885
+ case 1:
1886
+ compilers = _context2.v;
1887
+ if (compilers) {
1888
+ _context2.n = 2;
1889
+ break;
1890
+ }
1891
+ return _context2.a(2, null);
1892
+ case 2:
1893
+ shared = function shared(id, code) {
1894
+ return {
1895
+ code: code,
1896
+ filename: id,
1897
+ id: id,
1898
+ codeSplitGroupings: compilers.groupings,
1899
+ targetFramework: "react",
1900
+ runtimeEnv: "prod"
1901
+ };
1902
+ };
1903
+ return _context2.a(2, {
1904
+ reference: function reference(id, code) {
1905
+ // Null when the file has nothing to split, which is the common case --
1906
+ // a route with only a loader, or one whose component is already lazy.
1907
+ return compilers.compileCodeSplitReferenceRoute(shared(id, code));
1908
+ },
1909
+ virtual: function virtual(id, code, targets) {
1910
+ return compilers.compileCodeSplitVirtualRoute(_objectSpread2(_objectSpread2({}, shared(id, code)), {}, {
1911
+ splitTargets: targets
1912
+ }));
1913
+ }
1914
+ });
1915
+ }
1916
+ }, _callee2);
1917
+ }));
1918
+ return _routeSplitter.apply(this, arguments);
1919
+ }
1920
+
1921
+ /**
1922
+ * The project's own route-generator config.
1923
+ *
1924
+ * `tsr.config.json` is what TanStack's standalone CLI reads, and a project that
1925
+ * needs it needs it here too. The starter template is the case in point: it
1926
+ * keeps content modules beside route files (`products.$sku.val.ts` serves
1927
+ * `products.$sku.tsx`), and without its `routeFileIgnorePattern` the generator
1928
+ * reads that as a route at `/products/$sku/val`.
1929
+ *
1930
+ * Only the keys that change what is generated are honoured; output shape stays
1931
+ * this platform's, because the builder consumes it.
1932
+ */
1933
+ var HONOURED = ["routeFileIgnorePattern", "routeFileIgnorePrefix", "routesDirectory", "indexToken", "routeToken", "pathParamsAllowedCharacters"];
1934
+ function projectRouterConfig(_x) {
1935
+ return _projectRouterConfig.apply(this, arguments);
1936
+ }
1937
+ /** A project is file-based if it has a routes directory. */
1938
+ function _projectRouterConfig() {
1939
+ _projectRouterConfig = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(dir) {
1940
+ var _i, _arr, name, parsed, kept, _iterator, _step, key, _t;
1941
+ return _regenerator().w(function (_context) {
1942
+ while (1) switch (_context.p = _context.n) {
1943
+ case 0:
1944
+ _i = 0, _arr = ["tsr.config.json"];
1945
+ case 1:
1946
+ if (!(_i < _arr.length)) {
1947
+ _context.n = 6;
1948
+ break;
1949
+ }
1950
+ name = _arr[_i];
1951
+ _context.p = 2;
1952
+ _t = JSON;
1953
+ _context.n = 3;
1954
+ return readFile(join(dir, name), "utf8");
1955
+ case 3:
1956
+ parsed = _t.parse.call(_t, _context.v);
1957
+ kept = {};
1958
+ _iterator = _createForOfIteratorHelper(HONOURED);
1959
+ try {
1960
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1961
+ key = _step.value;
1962
+ if (key in parsed) kept[key] = parsed[key];
1963
+ }
1964
+ } catch (err) {
1965
+ _iterator.e(err);
1966
+ } finally {
1967
+ _iterator.f();
1968
+ }
1969
+ return _context.a(2, kept);
1970
+ case 4:
1971
+ _context.p = 4;
1972
+ _context.v;
1973
+ case 5:
1974
+ _i++;
1975
+ _context.n = 1;
1976
+ break;
1977
+ case 6:
1978
+ return _context.a(2, {});
1979
+ }
1980
+ }, _callee, null, [[2, 4]]);
1981
+ }));
1982
+ return _projectRouterConfig.apply(this, arguments);
1983
+ }
1984
+ function isFileBased(_x2) {
1985
+ return _isFileBased.apply(this, arguments);
1986
+ }
1987
+
1988
+ /**
1989
+ * The one line the platform needs from a file-based project.
1990
+ *
1991
+ * `src/app.tsx` is the entry the builder looks for, and for a routes-as-data
1992
+ * project the user writes it. A file-based project has no such file -- its
1993
+ * entry *is* the generated tree -- so this bridges the two contracts. A real
1994
+ * integration would emit it rather than ask for it, which is what this is.
1995
+ */
1996
+ function _isFileBased() {
1997
+ _isFileBased = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(dir) {
1998
+ return _regenerator().w(function (_context2) {
1999
+ while (1) switch (_context2.n) {
2000
+ case 0:
2001
+ return _context2.a(2, stat(join(dir, "src", "routes")).then(function (entry) {
2002
+ return entry.isDirectory();
2003
+ }, function () {
2004
+ return false;
2005
+ }));
2006
+ }
2007
+ }, _callee2);
2008
+ }));
2009
+ return _isFileBased.apply(this, arguments);
2010
+ }
2011
+ var ENTRY_SHIM = "export { routeTree } from './routeTree.gen'\n";
2012
+
2013
+ /**
2014
+ * Generates `routeTree.gen.ts` and returns the file map with it (and the entry
2015
+ * shim) added.
2016
+ *
2017
+ * The generator's only interface is the filesystem, so this does write into the
2018
+ * project -- and then puts it back exactly as it was. An earlier version left
2019
+ * the file there, on the reasoning that the tree "is normally gitignored and
2020
+ * regenerated, so writing it is not a surprise". That is false often enough to
2021
+ * matter: `valbuild/template-tanstack-starter` *tracks* its `routeTree.gen.ts`,
2022
+ * and running `pnpm report:project` against a checkout of it silently rewrote a
2023
+ * committed file with different formatting and no eslint header. Inspecting a
2024
+ * project should not modify it, least of all one the caller only pointed at.
2025
+ *
2026
+ * Only the in-memory copy is used for the build, so nothing needs the file to
2027
+ * survive. A developer who wants it on disk runs `tsr generate`, which is the
2028
+ * command that is supposed to produce it.
2029
+ */
2030
+ function generateRouteTree(_x3, _x4) {
2031
+ return _generateRouteTree.apply(this, arguments);
2032
+ }
2033
+ function _generateRouteTree() {
2034
+ _generateRouteTree = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(dir, files) {
2035
+ var _files$srcAppTsx;
2036
+ var _yield$import, Generator, projectConfig, root, generator, treePath, before, tanstackDir, hadTanstackDir, tree;
2037
+ return _regenerator().w(function (_context3) {
2038
+ while (1) switch (_context3.p = _context3.n) {
2039
+ case 0:
2040
+ _context3.n = 1;
2041
+ return import('@tanstack/router-generator');
2042
+ case 1:
2043
+ _yield$import = _context3.v;
2044
+ Generator = _yield$import.Generator;
2045
+ _context3.n = 2;
2046
+ return projectRouterConfig(dir);
2047
+ case 2:
2048
+ projectConfig = _context3.v;
2049
+ // Absolute, because the generator resolves `routesDirectory` and
2050
+ // `generatedRouteTree` against `root` when they are relative -- and we build
2051
+ // both by joining `dir`, which is also `root`. A relative `dir` therefore
2052
+ // doubles the prefix: `pnpm report:project templates/kitchen-sink` wrote its
2053
+ // tree to `templates/kitchen-sink/templates/kitchen-sink/src/`, found no
2054
+ // routes at the doubled path, and generated nothing, silently.
2055
+ //
2056
+ // This was latent for a long time. The read below happened to succeed because
2057
+ // a correct tree from some earlier absolute-path run was still lying in the
2058
+ // project, so every relative-path publish quietly consumed a STALE tree. The
2059
+ // restore added above deletes that file, which is what finally surfaced it as
2060
+ // a PLATFORM301 on the next run.
2061
+ root = resolve(dir);
2062
+ generator = new Generator({
2063
+ root: root,
2064
+ config: _objectSpread2({
2065
+ routesDirectory: join(root, "src", "routes"),
2066
+ generatedRouteTree: join(root, "src", "routeTree.gen.ts"),
2067
+ routeFileIgnorePrefix: "-",
2068
+ quoteStyle: "single",
2069
+ semicolons: false,
2070
+ disableLogging: true,
2071
+ routeTreeFileHeader: [],
2072
+ routeTreeFileFooter: [],
2073
+ indexToken: "index",
2074
+ routeToken: "route",
2075
+ enableRouteTreeFormatting: false,
2076
+ // `verboseFileRoutes: true` was here and is gone. The object was cast to
2077
+ // `any` on the way into the constructor, which is what let it stay: the
2078
+ // key is not in the generator's config -- not in its types and not
2079
+ // anywhere in its dist -- so it had been inert for however long. The cast
2080
+ // is gone with it, so the next key that stops existing is a type error.
2081
+ // The builder strips types anyway, and the generated declarations are by
2082
+ // far the largest part of the file.
2083
+ disableTypes: true,
2084
+ addExtensions: false,
2085
+ // Not the plugin's auto-splitting, which is a separate transform this
2086
+ // platform does not run. `.lazy.tsx` still works: the generator expresses
2087
+ // it as an `import()`, which the builder splits.
2088
+ autoCodeSplitting: false,
2089
+ experimental: {},
2090
+ plugins: [],
2091
+ tmpDir: join(root, ".tanstack", "tmp"),
2092
+ target: "react",
2093
+ pathParamsAllowedCharacters: [],
2094
+ // The generator's default, spelled out because its config type is the
2095
+ // POST-defaults one and so requires every key. It was being supplied by
2096
+ // zod all along; the cast is what stopped the compiler saying so.
2097
+ importRoutesUsingAbsolutePaths: false
2098
+ }, projectConfig)
2099
+ }); // What was there before, so it can go back. `null` means there was no file,
2100
+ // and the restore is a delete.
2101
+ treePath = join(root, "src", "routeTree.gen.ts");
2102
+ _context3.n = 3;
2103
+ return readFile(treePath, "utf8")["catch"](function () {
2104
+ return null;
2105
+ });
2106
+ case 3:
2107
+ before = _context3.v;
2108
+ tanstackDir = join(root, ".tanstack");
2109
+ _context3.n = 4;
2110
+ return stat(tanstackDir).then(function () {
2111
+ return true;
2112
+ }, function () {
2113
+ return false;
2114
+ });
2115
+ case 4:
2116
+ hadTanstackDir = _context3.v;
2117
+ _context3.p = 5;
2118
+ _context3.n = 6;
2119
+ return generator.run();
2120
+ case 6:
2121
+ _context3.n = 7;
2122
+ return readFile(treePath, "utf8");
2123
+ case 7:
2124
+ tree = _context3.v;
2125
+ case 8:
2126
+ _context3.p = 8;
2127
+ if (!(before === null)) {
2128
+ _context3.n = 10;
2129
+ break;
2130
+ }
2131
+ _context3.n = 9;
2132
+ return rm(treePath, {
2133
+ force: true
2134
+ });
2135
+ case 9:
2136
+ _context3.n = 11;
2137
+ break;
2138
+ case 10:
2139
+ _context3.n = 11;
2140
+ return writeFile(treePath, before);
2141
+ case 11:
2142
+ if (hadTanstackDir) {
2143
+ _context3.n = 12;
2144
+ break;
2145
+ }
2146
+ _context3.n = 12;
2147
+ return rm(tanstackDir, {
2148
+ recursive: true,
2149
+ force: true
2150
+ });
2151
+ case 12:
2152
+ return _context3.f(8);
2153
+ case 13:
2154
+ return _context3.a(2, _objectSpread2(_objectSpread2({}, files), {}, {
2155
+ "src/routeTree.gen.ts": tree,
2156
+ // Only when the project has not written its own.
2157
+ "src/app.tsx": (_files$srcAppTsx = files["src/app.tsx"]) !== null && _files$srcAppTsx !== void 0 ? _files$srcAppTsx : ENTRY_SHIM
2158
+ }));
2159
+ }
2160
+ }, _callee3, null, [[5,, 8, 13]]);
2161
+ }));
2162
+ return _generateRouteTree.apply(this, arguments);
2163
+ }
2164
+
2165
+ export { BASE_PROVIDED, NODE_SHIMS, REEXPORT, SHIM_PREFIX, auditableImports, auditableSpecifiers, buildVendorLayer, chunkNameFor, collectDependencyCss, cssModuleLoader, cssSpecifiersOf, generateRouteTree, isFileBased, layerDepsOf, nodeShimSources, nodeShims, packageOf, routeSplitter };