@valbuild/tanstack-build 0.0.0 → 0.135.0

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