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

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