@valbuild/tanstack-build 0.0.1-alpha.0 → 0.136.1

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