@valbuild/tanstack-build 0.135.0 → 0.136.3

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 (30) hide show
  1. package/CHANGELOG.md +27 -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/constants/index.d.ts +19 -0
  14. package/dist/declarations/src/index.d.ts +1 -0
  15. package/dist/declarations/src/node/routes.d.ts +5 -7
  16. package/dist/declarations/src/projectPaths.d.ts +10 -0
  17. package/dist/declarations/src/wire.d.ts +40 -22
  18. package/dist/projectPaths-5e4defea.esm.js +30 -0
  19. package/dist/projectPaths-9cbecebf.cjs.prod.js +35 -0
  20. package/dist/projectPaths-f222255a.cjs.dev.js +35 -0
  21. package/dist/{slicedToArray-7afed0af.cjs.prod.js → slicedToArray-12869836.cjs.dev.js} +1 -0
  22. package/dist/{slicedToArray-80b0ffd7.cjs.dev.js → slicedToArray-149a2518.cjs.prod.js} +1 -0
  23. package/dist/{slicedToArray-44c37acc.esm.js → slicedToArray-d71360f4.esm.js} +1 -1
  24. package/dist/valbuild-tanstack-build.cjs.dev.js +183 -58
  25. package/dist/valbuild-tanstack-build.cjs.prod.js +183 -58
  26. package/dist/valbuild-tanstack-build.esm.js +173 -50
  27. package/node/dist/valbuild-tanstack-build-node.cjs.dev.js +6 -9
  28. package/node/dist/valbuild-tanstack-build-node.cjs.prod.js +6 -9
  29. package/node/dist/valbuild-tanstack-build-node.esm.js +5 -8
  30. package/package.json +10 -3
@@ -2,28 +2,12 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var slicedToArray = require('./slicedToArray-7afed0af.cjs.prod.js');
5
+ var slicedToArray = require('./slicedToArray-149a2518.cjs.prod.js');
6
6
  var browser = require('@rolldown/browser');
7
+ var projectPaths = require('./projectPaths-9cbecebf.cjs.prod.js');
7
8
  var parseAst = require('@rolldown/browser/parseAst');
8
9
  var tailwindcss = require('tailwindcss');
9
-
10
- /**
11
- * Paths the platform's contract fixes, in one place.
12
- *
13
- * These are not conventions this package chose -- `src/app.tsx` is the module
14
- * the builder resolves as its entry, and `src/routeTree.gen.ts` is what
15
- * TanStack's generator is configured to write. They are here so that a change
16
- * on either side is one edit rather than a search for string literals.
17
- */
18
-
19
- /** The module the builder uses as the project's entry. */
20
- var ENTRY = "src/app.tsx";
21
-
22
- /** Where TanStack's generator writes the route tree. */
23
- var TREE = "src/routeTree.gen.ts";
24
-
25
- /** Where a file-based project keeps its route files. */
26
- var ROUTES_DIR = "src/routes";
10
+ var artifactKeys = require('./artifactKeys-700b9044.cjs.prod.js');
27
11
 
28
12
  // A minimal posix path resolver. The builder runs in the browser, so node:path
29
13
  // is unavailable, and pulling a polyfill in for two functions is not worth it.
@@ -2381,7 +2365,7 @@ function projectPlugin(files, projectSource, splitter, cssModules, aliases, asse
2381
2365
  return module.path === id;
2382
2366
  });
2383
2367
  if (clientModule && isRsc) return clientReferenceStub(clientModule, vendor.paths.flightServer);
2384
- if (id !== ENTRY) return files[id];
2368
+ if (id !== projectPaths.ENTRY) return files[id];
2385
2369
  // The entry carries the registry across the module boundary: the shell
2386
2370
  // reads `__serverFns` off the user app, not off a module it cannot name.
2387
2371
  // The rsc build has no use for the registry: it holds references, not
@@ -2557,7 +2541,7 @@ function _buildOnce() {
2557
2541
  // Only the vendor layer differs.
2558
2542
  _context2.n = 1;
2559
2543
  return browser.build({
2560
- input: isRsc ? RSC_ENTRY_ID : ENTRY,
2544
+ input: isRsc ? RSC_ENTRY_ID : projectPaths.ENTRY,
2561
2545
  // Required in the browser. rolldown computes `cwd: inputOptions.cwd ??
2562
2546
  // process.cwd()` unguarded, so omitting this throws "process is not
2563
2547
  // defined" from inside the wasm loader -- which surfaces only as a build
@@ -2719,7 +2703,7 @@ function _buildUserApp() {
2719
2703
  return warnings.push(message);
2720
2704
  });
2721
2705
  _context3.n = 8;
2722
- return collectCss(input.files, ENTRY, input.target.project.css, aliases);
2706
+ return collectCss(input.files, projectPaths.ENTRY, input.target.project.css, aliases);
2723
2707
  case 8:
2724
2708
  css = _context3.v;
2725
2709
  // Tailwind runs over the *concatenated* stylesheet, so the project's own
@@ -2849,6 +2833,105 @@ function publishPayload(build, extra) {
2849
2833
  }, extra);
2850
2834
  }
2851
2835
 
2836
+ /** One artifact, ready to declare and to upload. */
2837
+
2838
+ /**
2839
+ * Every artifact a build publishes, by key.
2840
+ *
2841
+ * Async because the hashes are, and the hashes are because `crypto.subtle` is
2842
+ * the one digest available both in a tab and in Node -- see `hash.ts`.
2843
+ *
2844
+ * An empty stylesheet is omitted rather than uploaded as an empty artifact: a
2845
+ * project with no CSS has no `css` key, which is what `loaderPayload.ts` reads
2846
+ * `text("css") !== undefined` to decide.
2847
+ */
2848
+ function publishArtifacts(_x) {
2849
+ return _publishArtifacts.apply(this, arguments);
2850
+ }
2851
+ function _publishArtifacts() {
2852
+ _publishArtifacts = slicedToArray._asyncToGenerator(/*#__PURE__*/slicedToArray._regenerator().m(function _callee2(build) {
2853
+ var options,
2854
+ encoder,
2855
+ out,
2856
+ single,
2857
+ group,
2858
+ _args2 = arguments;
2859
+ return slicedToArray._regenerator().w(function (_context2) {
2860
+ while (1) switch (_context2.n) {
2861
+ case 0:
2862
+ options = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {};
2863
+ encoder = new TextEncoder();
2864
+ out = [];
2865
+ single = function single(key, body) {
2866
+ if (body === undefined || body === "") return;
2867
+ out.push({
2868
+ key: key,
2869
+ body: body
2870
+ });
2871
+ };
2872
+ single(artifactKeys.ARTIFACT_KEYS.server, build.serverCode);
2873
+ single(artifactKeys.ARTIFACT_KEYS.client, build.clientCode);
2874
+ single(artifactKeys.ARTIFACT_KEYS.css, build.cssCode);
2875
+ single(artifactKeys.ARTIFACT_KEYS.rsc, build.rscCode);
2876
+ if (options.projectSource !== undefined) {
2877
+ single(artifactKeys.ARTIFACT_KEYS.source, JSON.stringify(options.projectSource));
2878
+ }
2879
+ group = function group(prefix, record) {
2880
+ for (var _i = 0, _Object$entries = Object.entries(record !== null && record !== void 0 ? record : {}); _i < _Object$entries.length; _i++) {
2881
+ var _Object$entries$_i = slicedToArray._slicedToArray(_Object$entries[_i], 2),
2882
+ name = _Object$entries$_i[0],
2883
+ body = _Object$entries$_i[1];
2884
+ /*
2885
+ * The name is appended and nothing else touches it. An asset is addressed
2886
+ * by the path the built code imports it at, so normalising it here --
2887
+ * stripping, lowercasing, re-joining -- produces a bundle whose imports
2888
+ * resolve to nothing, at runtime, in the isolate. `loaderPayload.ts` says
2889
+ * the same thing on the way back.
2890
+ */
2891
+ out.push({
2892
+ key: "".concat(prefix).concat(name),
2893
+ body: body
2894
+ });
2895
+ }
2896
+ };
2897
+ group(artifactKeys.ARTIFACT_PREFIXES.serverChunks, build.serverChunks);
2898
+ group(artifactKeys.ARTIFACT_PREFIXES.clientChunks, build.clientChunks);
2899
+ group(artifactKeys.ARTIFACT_PREFIXES.rscChunks, build.rscChunks);
2900
+ group(artifactKeys.ARTIFACT_PREFIXES.assetFiles, build.assetFiles);
2901
+ group(artifactKeys.ARTIFACT_PREFIXES.publicFiles, build.publicFiles);
2902
+ return _context2.a(2, Promise.all(out.map(/*#__PURE__*/function () {
2903
+ var _ref2 = slicedToArray._asyncToGenerator(/*#__PURE__*/slicedToArray._regenerator().m(function _callee(_ref) {
2904
+ var key, body, _t, _t2, _t3, _t4;
2905
+ return slicedToArray._regenerator().w(function (_context) {
2906
+ while (1) switch (_context.n) {
2907
+ case 0:
2908
+ key = _ref.key, body = _ref.body;
2909
+ _t = key;
2910
+ _t2 = body;
2911
+ _context.n = 1;
2912
+ return sha256Hex(body);
2913
+ case 1:
2914
+ _t3 = _context.v;
2915
+ _t4 = encoder.encode(body).length;
2916
+ return _context.a(2, {
2917
+ key: _t,
2918
+ body: _t2,
2919
+ sha256: _t3,
2920
+ bytes: _t4
2921
+ });
2922
+ }
2923
+ }, _callee);
2924
+ }));
2925
+ return function (_x2) {
2926
+ return _ref2.apply(this, arguments);
2927
+ };
2928
+ }())));
2929
+ }
2930
+ }, _callee2);
2931
+ }));
2932
+ return _publishArtifacts.apply(this, arguments);
2933
+ }
2934
+
2852
2935
  /*
2853
2936
  * The git tree hash of a file record, computed the way git computes it.
2854
2937
  *
@@ -3172,24 +3255,34 @@ function _typeof(o) {
3172
3255
  * Where a Val project keeps the module this replaces.
3173
3256
  *
3174
3257
  * Exported because a caller has to be able to rewrite JUST this file. The
3175
- * commit is baked into it (see `BUILT_FROM` in the template), and the files a publish
3176
- * hands over are the `.val.ts` ones it patched -- this is never among them, so a tab
3177
- * that merged a save and rebuilt would compile the NEW content against the OLD
3178
- * commit and read the wrong version of it back.
3258
+ * commit is baked into it (see `BUILT_FROM` in the template), and the files a save
3259
+ * writes are the `.val.ts` ones it patched -- this is never among them, so a tab
3260
+ * that laid a save over the project and rebuilt would compile the NEW content
3261
+ * against the OLD commit and read the wrong version of it back. `rebakeGit` is
3262
+ * what the Studio calls.
3179
3263
  */
3180
3264
  var VAL_SERVER_PATH = "src/val/val.server.ts";
3181
3265
  var VAL_SERVER = VAL_SERVER_PATH;
3182
3266
  var PROJECT_SOURCE_TYPES = "src/val/project-source.d.ts";
3183
3267
 
3184
3268
  /**
3185
- * The sentinel host a wired app reaches its platform at.
3269
+ * The first line of every `val.server.ts` this file generates, and how
3270
+ * {@link isWired} recognises one.
3186
3271
  *
3187
- * Spelled out here rather than imported from the loader: this package is built
3188
- * into a browser bundle and the loader's into a Worker. One name in two
3189
- * spellings is the risk, which is why this is a constant used by both the
3190
- * template it goes into and the check that reads it back out.
3272
+ * A comment rather than anything the file DOES, because a wired file no longer
3273
+ * does anything no other Val host does: it used to post the files a save
3274
+ * committed to `platform.internal`, for a builder tab to pick up, and that
3275
+ * sentinel host was the marker. A managed project's Studio builds in its own
3276
+ * tab now, the loader refuses that door, and the post went with it.
3277
+ */
3278
+ var WIRED_MARKER = "// Wired for the Val platform by @valbuild/tanstack-build. Regenerated on publish.";
3279
+
3280
+ /**
3281
+ * The sentinel host a file wired BEFORE {@link WIRED_MARKER} existed posted to.
3282
+ * Still recognised by {@link isWired}, so a project published by an older
3283
+ * publisher is not wired twice.
3191
3284
  */
3192
- var CONTROL_HOST = "platform.internal";
3285
+ var LEGACY_CONTROL_HOST = "platform.internal";
3193
3286
 
3194
3287
  /**
3195
3288
  * The editing backend, as this platform needs it.
@@ -3203,14 +3296,8 @@ var CONTROL_HOST = "platform.internal";
3203
3296
  * buffered every draft image through the isolate. Two behaviours nobody chose,
3204
3297
  * out of one word.
3205
3298
  *
3206
- * Two things differ, and each is load bearing:
3299
+ * One thing differs, and it is load bearing:
3207
3300
  *
3208
- * - **`publishOverride`** is the seam, and the only place this platform is
3209
- * unlike any other host. A publish here commits -- the default, handed over as
3210
- * `commitToGit` -- AND puts the files it committed where the platform can
3211
- * reach them, because there is no bundler in the isolate: the studio tab picks
3212
- * them up, builds, and the result
3213
- * is served immediately instead of a host noticing the commit and redeploying.
3214
3301
  * - **no formatter.** A repository passes prettier here so a patch written to
3215
3302
  * disk comes out formatted like the rest of the code. Prettier's bundle
3216
3303
  * TDZ-crashes in a Worker isolate ("Cannot access 'y' before
@@ -3223,9 +3310,8 @@ var CONTROL_HOST = "platform.internal";
3223
3310
  * running needs.
3224
3311
  */
3225
3312
  var valServerSource = function valServerSource(_ref) {
3226
- var project = _ref.project,
3227
- git = _ref.git;
3228
- return "import {\n initValContent,\n initValServer,\n} from \"@valbuild/tanstack/server\";\nimport { config } from \"../../val.config\";\nimport valModules from \"../../val.modules\";\n\n/**\n * A secret, as the platform hands it over at RUNTIME.\n *\n * Preferred over `process.env`, which the builder inlines as a literal into\n * this bundle: that puts the value in storage inside the code, copies it into\n * every isolate that loads it, and makes rotating it a republish.\n *\n * Falls back to the build-time value, so an app published before secrets\n * existed keeps working.\n */\nfunction secret(name: string): string | undefined {\n return (globalThis.__PLATFORM_SECRETS ?? {})[name] ?? process.env[name];\n}\n\n/**\n * Hand the files a publish committed back to the platform, to be built.\n *\n * There is no bundler in the isolate, so the commit a publish just made cannot\n * become a running site on its own. This writes what the commit contained, with\n * the commit's own sha, to the platform's pending source, and the studio tab\n * picks that up and builds. The sha is not a receipt: it is what the next build\n * is wired AT, so handing over the wrong one produces a build that reads a\n * different version of its content than it was compiled from.\n *\n * Named for `putPendingSource` in the loader's storage, which is what the\n * other side of this request calls -- along with `getPendingSource` and\n * `clearPendingSource`, which the studio tab uses to pick it up and let it go.\n * One mechanism, one noun, however many processes it crosses.\n */\nasync function putPendingSource(\n patchedSourceFiles: Record<string, string | null>,\n commitSha?: string,\n /**\n * What the commit was built ON, and what it points AT.\n *\n * Both optional, and absent is meaningful rather than lazy: a Val too old to\n * report them sends neither, and the platform has to be able to tell that\n * apart from a commit that genuinely has no parent. It falls back to treating\n * the hand-over as unchained -- correct but conservative -- rather than\n * assuming it is a root commit and concluding the history starts here.\n */\n parentSha?: string,\n treeSha?: string,\n) {\n try {\n /*\n * A name the PLATFORM serves, not a URL on the internet.\n *\n * This used to post to the loader's public address, which works in dev --\n * a different port on loopback -- and cannot work deployed: a Worker may\n * not fetch the hostname it is itself served on, so Cloudflare resolved\n * the subrequest away and answered 404. A save then failed with Val's\n * `HTTPError` and the real cause only in the isolate's log.\n *\n * The platform intercepts this host and answers it from inside, so the\n * door is one it holds rather than one this file knows the address of.\n * `.internal` resolves nowhere, so if interception ever stopped, this\n * fails closed instead of reaching a stranger.\n */\n const res = await fetch(\"https://".concat(CONTROL_HOST, "/__api/source\", {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n /*\n * The project this isolate is actually SERVING, not the one it was\n * generated for.\n *\n * The platform sets __PLATFORM_PROJECT_ID per request from the id the loader\n * resolved off the hostname. The literal is only a fallback, for a build\n * served by a platform too old to set it -- and it is a bad one: publish\n * the same bundle to two projects and every edit made on either lands\n * under whichever name was baked in here.\n */\n project: projectId(),\n files: patchedSourceFiles,\n commitSha,\n /*\n * Spread, so a Val that did not report them leaves the keys out of the\n * body entirely. `parentSha: undefined` would serialise to nothing\n * anyway, but the platform reads this body with a schema, and an\n * explicitly-absent key is what lets it distinguish \"this build's Val\n * cannot tell me\" from \"there is no parent\".\n */\n ...(parentSha !== undefined ? { parentSha } : {}),\n ...(treeSha !== undefined ? { treeSha } : {}),\n }),\n });\n if (!res.ok) {\n throw new Error(`source endpoint returned ${res.status}`);\n }\n } catch (error) {\n throw new Error(`PENDING_SOURCE_FAILED: ${String(error)}`);\n }\n}\n\n/** The project this isolate is serving. See the note in `putPendingSource`. */\nfunction projectId() {\n return globalThis.__PLATFORM_PROJECT_ID ?? ").concat(JSON.stringify(project), ";\n}\n\n/**\n * The commit this build was made from, and the branch it commits to.\n *\n * Baked in rather than handed over at runtime, unlike a secret, because it is\n * not configuration -- it is a property OF THIS BUILD. Every read of a\n * `.val.ts` in http mode fetches that path from the content service at this\n * sha, so a build served with somebody else's commit renders and edits a\n * version of its files it was not compiled from. A secret can be rotated under\n * a running build; this cannot, and publishing again is how it changes.\n *\n * WHAT THIS IS NOT. It is not every read: a committed render reads the source\n * bundled into this build and asks the content service nothing. It is the\n * PUBLISH path -- turning pending patches into new `.val.ts` text means\n * fetching the current text to patch, and that is the read that happens at\n * this sha. The docblock used to say \"every read\", which sent readers looking\n * for a content call on the serving path that is not there.\n *\n * `null` when the source came from no commit -- a record assembled in a tab,\n * a fixture, or ANY build this platform makes, which is the common case rather\n * than the exception. Such a build has no repository to mirror commits into,\n * and does not need one: the content service is the store of record for\n * content and mints its own commit shas. Val is in http mode on credentials\n * alone.\n */\nconst BUILT_FROM = ").concat(git ? JSON.stringify(git) : "null", ";\n\n/**\n * What puts Val in http mode: its content service owns the content.\n *\n * The same three things any deployed Val app is configured with. Note what is\n * NOT here: no `sourceFiles`, so patches are relayed to the content service\n * instead of being kept by this platform, and the browser uploads an image\n * straight there on a presigned URL instead of streaming it through here.\n *\n * `undefined` when a credential or the commit is missing, and deliberately not\n * a throw at module scope: that would take the isolate down with it, page\n * renders included. Val is left to refuse the request and name what it wanted\n * -- `VAL_ENV=app` is set on this build precisely so that a missing credential\n * is an error instead of a fall-through to `fs` mode, looking for a working\n * tree that is not in here.\n */\nconst apiKey = secret(\"VAL_API_KEY\");\nconst valSecret = secret(\"VAL_SECRET\");\n/*\n * Which content service, for a project that is not pointed at the real one.\n *\n * A secret rather than a baked literal, because unlike the commit this IS\n * configuration: the same build should be servable against a stand-in and\n * against production. It is what makes the editing path testable at all --\n * Val's own `e2e/mock-content-host` implements this wire protocol with no git\n * repository behind it -- and without it a build could only ever talk to\n * content.val.build.\n *\n * It does NOT redirect everything, and the gap is in Val rather than here:\n * `getSettings`, which remote FILES use, reads `process.env.VAL_CONTENT_URL`\n * at module scope inside @valbuild/server. This platform bundles its\n * dependencies separately from the app, so nothing it sets reaches that read --\n * the same reason `apiKey` has to be passed in rather than found. So patches,\n * commits and source reads go where this says, and remote file uploads still\n * address the real host.\n */\nconst valContentUrl = secret(\"VAL_CONTENT_URL\");\n/*\n * WHICH project's content this is, at the content service.\n *\n * Val's own name for the project (`org/name`), which is not the platform's\n * project id and cannot be derived from it. A repository that is deployed\n * anywhere else puts it in `val.config.ts`; one imported here need not have,\n * so it is configuration the platform can supply -- and it goes through\n * `secret` rather than `--env` for a second reason: a build-time literal\n * would have to be baked into the shared dependency layer, where\n * @valbuild/server reads `process.env.VAL_PROJECT`, and that layer is reused\n * by every project with the same dependencies.\n *\n * What the app configured wins over nothing at all, so a repository that does\n * name its project keeps working with no secret set.\n */\nconst valProject = secret(\"VAL_PROJECT\");\nconst valConfig = {\n ...config,\n ...(valProject !== undefined ? { project: valProject } : {}),\n};\n/*\n * CREDENTIALS ALONE. A commit is not part of what puts Val in http mode.\n *\n * It used to be: `GIT !== null` was in this condition, and a build with no\n * commit fell through to `undefined` -- which meant every site this platform\n * seeded was silently unable to edit, because a shared build cannot know a\n * commit. The binding that worked around it (`VAL_GIT_COMMIT` /\n * `VAL_GIT_BRANCH` out of the project's secrets) is gone with it: it named a\n * commit in the TEMPLATE's repository, which was true only for as long as\n * seeding and repository creation shared a template, and it was one more thing\n * in KV that could go stale.\n *\n * The commit is optional NOW, and it is still sent where there is one -- see\n * the note at the spread below. What is gone is the binding that supplied one\n * from KV, so there is one source per environment and no precedence rule\n * between a baked value and a bound one.\n */\nconst http =\n apiKey !== undefined && valSecret !== undefined\n ? {\n apiKey,\n valSecret,\n /*\n * BOTH SPELLINGS OF THE COMMIT, because the APP decides which one is\n * read and this file cannot know which app it is being written into.\n *\n * `ValHttpMode` has been renamed in both directions. Up to 0.132 it\n * took `gitCommit`/`gitBranch`; 0.133.0 replaced that pair with a\n * nested `git`; the version this package ships beside flattens it\n * back again. The generated file is compiled against whatever\n * `@valbuild/tanstack` the PROJECT installed -- the starter pins\n * 0.133.0 -- and a platform writing this file has no say in that. So\n * this is not one rename behind or ahead: it is on both sides of one at\n * once, and will be until every app it publishes has moved.\n *\n * Sending only the wrong one is SILENT, which is why this is belt and\n * braces rather than a version check. An unknown key on the options\n * object is ignored, so the commit is simply dropped and a build wired\n * FROM A COMMIT runs as though it had none -- which means a publish\n * produces no mirrored `.val.ts`, so a save commits and hands over\n * nothing, and the site keeps serving its old content with the patches\n * already consumed. Nothing reports it. valbuild/home's loop is the one\n * thing that sees it, and it was bisected there: 25/25 with the key the\n * installed version reads, 21/23 without, failing at exactly \"the save\n * left the file it rewrote pending\".\n *\n * Whichever version is installed reads its own key and ignores the\n * other two. Drop this to one spelling when every app this platform\n * publishes is past the rename -- not before, and not on the say-so of\n * a compiler in the Val repository, which is looking at a different\n * version of `@valbuild/tanstack` than the app is.\n */\n ...(BUILT_FROM !== null\n ? {\n git: BUILT_FROM,\n gitCommit: BUILT_FROM.commit,\n gitBranch: BUILT_FROM.branch,\n }\n : {}),\n ...(valContentUrl !== undefined ? { valContentUrl } : {}),\n }\n : undefined;\n\nconst { valApiHandler, draftMode } = initValServer(\n valModules,\n valConfig,\n {\n ...(http ? { http } : {}),\n /*\n * The one thing this platform does differently from any other Val host.\n *\n * A publish in http mode is a git commit, and that stays: `commitToGit` is\n * the default, handed over rather than skipped, and calling it is what makes\n * the content service mark the patches published and the repository carry\n * the change. What is ADDED is the build -- the tab picks the pending\n * source up, compiles it, and the result is served immediately, rather than\n * a host noticing the commit and redeploying minutes later.\n *\n * ORDER: commit, then hand over. The commit is the source of truth, and\n * writing the pending source first would mean a build whose content the\n * content service does not have yet, so every read in it would resolve the\n * previous commit -- the site showing pre-save content with the edits\n * already consumed.\n *\n * A hand-over that fails after a commit that succeeded is NOT reported as a\n * failed publish, which is deliberate: the commit happened, and saying it\n * did not is the more misleading of the two. What is lost is the immediate\n * rebuild, so the site serves its previous build until the next publish --\n * recoverable, and the tab can reload the repository at the new commit to\n * do it.\n */\n publishOverride: async ({ patchedSourceFiles, commitToGit }) => {\n const committed = await commitToGit();\n if (committed.error) {\n return committed;\n }\n try {\n await putPendingSource(\n patchedSourceFiles,\n committed.commit,\n /*\n * Added by @valbuild/server after 0.132.0. An older one has neither\n * field and the platform is told nothing rather than told wrongly --\n * see the note on the parameters.\n */\n committed.parent,\n committed.tree,\n );\n } catch (error) {\n console.error(\n \"Val: the commit landed, but the platform could not be given the \" +\n \"files to build. The site serves its previous build until it is \" +\n \"published again.\",\n error,\n );\n }\n return committed;\n },\n },\n);\n\nconst {\n fetchValStega: fetchVal,\n fetchValKeyStega: fetchValKey,\n fetchValRouteStega: fetchValRoute,\n fetchValRouteUrl,\n} = initValContent(valConfig, valModules, {\n draftMode,\n /*\n * The SAME object the API got.\n *\n * These readers resolve content through a Val server of their own rather than\n * by calling the API over HTTP, so the mode question is put to them\n * separately -- configuring only `initValServer` left them inferring `fs`\n * mode, looking for a working tree that is not in here. `gitCommit` is the\n * field that would be silently wrong rather than loudly missing: two\n * different shas means the API edits one version of a file while the page\n * renders another.\n */\n ...(http ? { http } : {}),\n});\n\n/**\n * A build that is MEANT to edit and cannot, refusing instead of pretending to.\n *\n * `BUILT_FROM` being non-null says this build came from a commit, so it was\n * made to edit against a content service. If the credentials for that service are not\n * here, the configuration is broken -- and the failure that was reaching people\n * was not an error at all. Val picks its storage mode by inference, so an\n * isolate with no api key lands in a mode that ACCEPTS the write and keeps it\n * in the isolate. Cloudflare starts an isolate per concurrent request, so the\n * save answers 200 and the next request, served by a different isolate, has\n * never heard of it. The edit is simply gone, and nothing anywhere said so.\n *\n * That is the worst available outcome: a person is told their work is saved\n * when it is not. Refusing is strictly better, and naming the missing secret\n * turns an evening of reading logs into one line in a response body.\n *\n * WHY HERE rather than relying on `VAL_ENV=app`: that is a build-time\n * substitution into the shared dependency layer, so whether a build fails\n * loudly depends on which layer it happens to be pinned to. This file is\n * written on every build, by the platform, and cannot be missing from one.\n *\n * Only the editing API. Page renders do not come through here, and a site whose\n * content cannot be edited should still serve the content it has.\n */\nconst editingApiHandler =\n http === undefined\n ? async () => {\n const missing = [\n apiKey === undefined ? \"VAL_API_KEY\" : null,\n valSecret === undefined ? \"VAL_SECRET\" : null,\n /*\n * A build from no commit is listed the same way, because from the\n * outside the two are one state. It is not a secret somebody can set\n * -- a commit is a property OF THE BUILD, and the only cure is\n * publishing this project's own repository over whatever is serving\n * it. Named anyway, because \"it was built from no commit\" is the\n * sentence that ends the search.\n */\n BUILT_FROM === null ? \"a commit (this build was made from none)\" : null,\n ].filter(Boolean);\n return Response.json(\n {\n error:\n \"This site cannot be edited. Its content lives in a content service, and \" +\n missing.join(\", \") +\n \" \" +\n (missing.length > 1 ? \"are\" : \"is\") +\n \" missing, so there is nothing to edit against. Editing is refused rather \" +\n \"than kept in this isolate's memory, where it would be lost without being \" +\n \"reported.\" +\n (BUILT_FROM === null\n ? \" A build made from no commit is usually one SEEDED from a template: \" +\n \"publish this project's own repository to replace it.\"\n : \" This build was made from commit \" + BUILT_FROM.commit.slice(0, 8) + \".\"),\n missing,\n },\n { status: 503 },\n );\n }\n : valApiHandler;\n\nexport {\n editingApiHandler as valApiHandler,\n draftMode,\n fetchVal,\n fetchValKey,\n fetchValRoute,\n fetchValRouteUrl,\n};\n");
3313
+ var git = _ref.git;
3314
+ return "".concat(WIRED_MARKER, "\nimport {\n initValContent,\n initValServer,\n} from \"@valbuild/tanstack/server\";\nimport { config } from \"../../val.config\";\nimport valModules from \"../../val.modules\";\n/*\n * This build's own source, which a publish patches. A project with no\n * repository has no other copy of its `.val.ts` text: content keeps its\n * content as data. Ignored by a @valbuild/tanstack that predates it.\n */\nimport { FILES } from \"platform:project-source\";\n\n/**\n * A secret, as the platform hands it over at RUNTIME.\n *\n * Preferred over `process.env`, which the builder inlines as a literal into\n * this bundle: that puts the value in storage inside the code, copies it into\n * every isolate that loads it, and makes rotating it a republish.\n *\n * Falls back to the build-time value, so an app published before secrets\n * existed keeps working.\n */\nfunction secret(name: string): string | undefined {\n return (globalThis.__PLATFORM_SECRETS ?? {})[name] ?? process.env[name];\n}\n\n/**\n * The commit this build was made from, and the branch it commits to.\n *\n * Baked in rather than handed over at runtime, unlike a secret, because it is\n * not configuration -- it is a property OF THIS BUILD. Every read of a\n * `.val.ts` in http mode fetches that path from the content service at this\n * sha, so a build served with somebody else's commit renders and edits a\n * version of its files it was not compiled from. A secret can be rotated under\n * a running build; this cannot, and publishing again is how it changes.\n *\n * WHAT THIS IS NOT. It is not every read: a committed render reads the source\n * bundled into this build and asks the content service nothing. It is the\n * PUBLISH path -- turning pending patches into new `.val.ts` text means\n * fetching the current text to patch, and that is the read that happens at\n * this sha. The docblock used to say \"every read\", which sent readers looking\n * for a content call on the serving path that is not there.\n *\n * `null` when the source came from no commit -- a record assembled in a tab,\n * a fixture, or ANY build this platform makes, which is the common case rather\n * than the exception. Such a build has no repository to mirror commits into,\n * and does not need one: the content service is the store of record for\n * content and mints its own commit shas. Val is in http mode on credentials\n * alone.\n */\nconst BUILT_FROM = ").concat(git ? JSON.stringify(git) : "null", ";\n\n/**\n * What puts Val in http mode: its content service owns the content.\n *\n * The same three things any deployed Val app is configured with. Note what is\n * NOT here: no `sourceFiles`, so patches are relayed to the content service\n * instead of being kept by this platform, and the browser uploads an image\n * straight there on a presigned URL instead of streaming it through here.\n *\n * `undefined` when a credential or the commit is missing, and deliberately not\n * a throw at module scope: that would take the isolate down with it, page\n * renders included. Val is left to refuse the request and name what it wanted\n * -- `VAL_ENV=app` is set on this build precisely so that a missing credential\n * is an error instead of a fall-through to `fs` mode, looking for a working\n * tree that is not in here.\n */\nconst apiKey = secret(\"VAL_API_KEY\");\nconst valSecret = secret(\"VAL_SECRET\");\n/*\n * Which content service, for a project that is not pointed at the real one.\n *\n * A secret rather than a baked literal, because unlike the commit this IS\n * configuration: the same build should be servable against a stand-in and\n * against production. It is what makes the editing path testable at all --\n * Val's own `e2e/mock-content-host` implements this wire protocol with no git\n * repository behind it -- and without it a build could only ever talk to\n * content.val.build.\n *\n * It does NOT redirect everything, and the gap is in Val rather than here:\n * `getSettings`, which remote FILES use, reads `process.env.VAL_CONTENT_URL`\n * at module scope inside @valbuild/server. This platform bundles its\n * dependencies separately from the app, so nothing it sets reaches that read --\n * the same reason `apiKey` has to be passed in rather than found. So patches,\n * commits and source reads go where this says, and remote file uploads still\n * address the real host.\n */\nconst valContentUrl = secret(\"VAL_CONTENT_URL\");\n/*\n * WHICH project's content this is, at the content service.\n *\n * Val's own name for the project (`org/name`), which is not the platform's\n * project id and cannot be derived from it. A repository that is deployed\n * anywhere else puts it in `val.config.ts`; one imported here need not have,\n * so it is configuration the platform can supply -- and it goes through\n * `secret` rather than `--env` for a second reason: a build-time literal\n * would have to be baked into the shared dependency layer, where\n * @valbuild/server reads `process.env.VAL_PROJECT`, and that layer is reused\n * by every project with the same dependencies.\n *\n * What the app configured wins over nothing at all, so a repository that does\n * name its project keeps working with no secret set.\n */\nconst valProject = secret(\"VAL_PROJECT\");\nconst valConfig = {\n ...config,\n ...(valProject !== undefined ? { project: valProject } : {}),\n};\n/*\n * CREDENTIALS ALONE. A commit is not part of what puts Val in http mode.\n *\n * It used to be: `GIT !== null` was in this condition, and a build with no\n * commit fell through to `undefined` -- which meant every site this platform\n * seeded was silently unable to edit, because a shared build cannot know a\n * commit. The binding that worked around it (`VAL_GIT_COMMIT` /\n * `VAL_GIT_BRANCH` out of the project's secrets) is gone with it: it named a\n * commit in the TEMPLATE's repository, which was true only for as long as\n * seeding and repository creation shared a template, and it was one more thing\n * in KV that could go stale.\n *\n * The commit is optional NOW, and it is still sent where there is one -- see\n * the note at the spread below. What is gone is the binding that supplied one\n * from KV, so there is one source per environment and no precedence rule\n * between a baked value and a bound one.\n */\nconst http =\n apiKey !== undefined && valSecret !== undefined\n ? {\n apiKey,\n valSecret,\n /*\n * BOTH SPELLINGS OF THE COMMIT, because the APP decides which one is\n * read and this file cannot know which app it is being written into.\n *\n * `ValHttpMode` has been renamed in both directions. Up to 0.132 it\n * took `gitCommit`/`gitBranch`; 0.133.0 replaced that pair with a\n * nested `git`; the version this package ships beside flattens it\n * back again. The generated file is compiled against whatever\n * `@valbuild/tanstack` the PROJECT installed -- the starter pins\n * 0.133.0 -- and a platform writing this file has no say in that. So\n * this is not one rename behind or ahead: it is on both sides of one at\n * once, and will be until every app it publishes has moved.\n *\n * Sending only the wrong one is SILENT, which is why this is belt and\n * braces rather than a version check. An unknown key on the options\n * object is ignored, so the commit is simply dropped and a build wired\n * FROM A COMMIT runs as though it had none -- which means a publish\n * produces no mirrored `.val.ts`, so a save commits and hands over\n * nothing, and the site keeps serving its old content with the patches\n * already consumed. Nothing reports it. valbuild/home's loop is the one\n * thing that sees it, and it was bisected there: 25/25 with the key the\n * installed version reads, 21/23 without, failing at exactly \"the save\n * left the file it rewrote pending\".\n *\n * Whichever version is installed reads its own key and ignores the\n * other two. Drop this to one spelling when every app this platform\n * publishes is past the rename -- not before, and not on the say-so of\n * a compiler in the Val repository, which is looking at a different\n * version of `@valbuild/tanstack` than the app is.\n */\n ...(BUILT_FROM !== null\n ? {\n git: BUILT_FROM,\n gitCommit: BUILT_FROM.commit,\n gitBranch: BUILT_FROM.branch,\n }\n : {}),\n ...(valContentUrl !== undefined ? { valContentUrl } : {}),\n projectSource: FILES,\n }\n : undefined;\n\nconst { valApiHandler, draftMode } = initValServer(\n valModules,\n valConfig,\n {\n ...(http ? { http } : {}),\n },\n);\n\nconst {\n fetchValStega: fetchVal,\n fetchValKeyStega: fetchValKey,\n fetchValRouteStega: fetchValRoute,\n fetchValRouteUrl,\n} = initValContent(valConfig, valModules, {\n draftMode,\n /*\n * The SAME object the API got.\n *\n * These readers resolve content through a Val server of their own rather than\n * by calling the API over HTTP, so the mode question is put to them\n * separately -- configuring only `initValServer` left them inferring `fs`\n * mode, looking for a working tree that is not in here. `gitCommit` is the\n * field that would be silently wrong rather than loudly missing: two\n * different shas means the API edits one version of a file while the page\n * renders another.\n */\n ...(http ? { http } : {}),\n});\n\n/**\n * A build that is MEANT to edit and cannot, refusing instead of pretending to.\n *\n * `BUILT_FROM` being non-null says this build came from a commit, so it was\n * made to edit against a content service. If the credentials for that service are not\n * here, the configuration is broken -- and the failure that was reaching people\n * was not an error at all. Val picks its storage mode by inference, so an\n * isolate with no api key lands in a mode that ACCEPTS the write and keeps it\n * in the isolate. Cloudflare starts an isolate per concurrent request, so the\n * save answers 200 and the next request, served by a different isolate, has\n * never heard of it. The edit is simply gone, and nothing anywhere said so.\n *\n * That is the worst available outcome: a person is told their work is saved\n * when it is not. Refusing is strictly better, and naming the missing secret\n * turns an evening of reading logs into one line in a response body.\n *\n * WHY HERE rather than relying on `VAL_ENV=app`: that is a build-time\n * substitution into the shared dependency layer, so whether a build fails\n * loudly depends on which layer it happens to be pinned to. This file is\n * written on every build, by the platform, and cannot be missing from one.\n *\n * Only the editing API. Page renders do not come through here, and a site whose\n * content cannot be edited should still serve the content it has.\n */\nconst editingApiHandler =\n http === undefined\n ? async () => {\n const missing = [\n apiKey === undefined ? \"VAL_API_KEY\" : null,\n valSecret === undefined ? \"VAL_SECRET\" : null,\n /*\n * A build from no commit is listed the same way, because from the\n * outside the two are one state. It is not a secret somebody can set\n * -- a commit is a property OF THE BUILD, and the only cure is\n * publishing this project's own repository over whatever is serving\n * it. Named anyway, because \"it was built from no commit\" is the\n * sentence that ends the search.\n */\n BUILT_FROM === null ? \"a commit (this build was made from none)\" : null,\n ].filter(Boolean);\n return Response.json(\n {\n error:\n \"This site cannot be edited. Its content lives in a content service, and \" +\n missing.join(\", \") +\n \" \" +\n (missing.length > 1 ? \"are\" : \"is\") +\n \" missing, so there is nothing to edit against. Editing is refused rather \" +\n \"than kept in this isolate's memory, where it would be lost without being \" +\n \"reported.\" +\n (BUILT_FROM === null\n ? \" A build made from no commit is usually one SEEDED from a template: \" +\n \"publish this project's own repository to replace it.\"\n : \" This build was made from commit \" + BUILT_FROM.commit.slice(0, 8) + \".\"),\n missing,\n },\n { status: 503 },\n );\n }\n : valApiHandler;\n\nexport {\n editingApiHandler as valApiHandler,\n draftMode,\n fetchVal,\n fetchValKey,\n fetchValRoute,\n fetchValRouteUrl,\n};\n");
3229
3315
  };
3230
3316
 
3231
3317
  /**
@@ -3262,6 +3348,14 @@ function wiredValServer(options) {
3262
3348
  * build IS the published source, and the commit it was published at is a
3263
3349
  * literal inside its own `val.server.ts`.
3264
3350
  */
3351
+ /**
3352
+ * The one line that carries the commit.
3353
+ *
3354
+ * Shared by the reader below and the rewriter under it, so the two cannot
3355
+ * disagree about the format -- which they would silently, since a failed parse
3356
+ * and a build made from no commit are the same answer.
3357
+ */
3358
+ var BUILT_FROM_LINE = /^const BUILT_FROM = (.+);$/m;
3265
3359
  function bakedGit(files) {
3266
3360
  var source = files[VAL_SERVER];
3267
3361
  if (source === undefined) return undefined;
@@ -3275,7 +3369,7 @@ function bakedGit(files) {
3275
3369
  * platform build bakes nothing and binds nothing, and this returns
3276
3370
  * `undefined` for one -- which is the truth about it.
3277
3371
  */
3278
- var match = /^const BUILT_FROM = (.+);$/m.exec(source);
3372
+ var match = BUILT_FROM_LINE.exec(source);
3279
3373
  if (!(match !== null && match !== void 0 && match[1]) || match[1] === "null") return undefined;
3280
3374
  try {
3281
3375
  var parsed = JSON.parse(match[1]);
@@ -3294,6 +3388,35 @@ function bakedGit(files) {
3294
3388
  }
3295
3389
  }
3296
3390
 
3391
+ /**
3392
+ * The same record, wired at a different commit.
3393
+ *
3394
+ * The inverse of {@link bakedGit}, and the whole of what a rebuild has to
3395
+ * change: `BUILT_FROM` is the only place the commit appears, and every other
3396
+ * use in the generated file reads it.
3397
+ *
3398
+ * REWRITES one line rather than regenerating the file, and that is the point.
3399
+ * `wiredValServer` needs the project id and the platform's address, which the
3400
+ * publisher that has them is the tab; a Studio publishing from inside the
3401
+ * deployment has neither, and reconstructing the file from what it could guess
3402
+ * would throw away wiring it cannot see. Replacing the literal cannot.
3403
+ *
3404
+ * Returns the record unchanged when there is nothing to rewrite -- no
3405
+ * `val.server.ts`, or one this does not recognise. Unchanged rather than
3406
+ * thrown, because the caller's next step is a build, and a build of a record
3407
+ * with no wired server is a project that was never wired: a real thing, which
3408
+ * fails with its own message rather than this one.
3409
+ *
3410
+ * Non-destructive, like {@link wireUp}: the caller's record is what gets
3411
+ * published back as source.
3412
+ */
3413
+ function rebakeGit(files, git) {
3414
+ var source = files[VAL_SERVER];
3415
+ if (source === undefined) return files;
3416
+ if (!BUILT_FROM_LINE.test(source)) return files;
3417
+ return slicedToArray._objectSpread2(slicedToArray._objectSpread2({}, files), {}, slicedToArray._defineProperty({}, VAL_SERVER, source.replace(BUILT_FROM_LINE, "const BUILT_FROM = ".concat(git === null ? "null" : JSON.stringify(git), ";"))));
3418
+ }
3419
+
3297
3420
  /** Is this a Val project at all? */
3298
3421
  function isValProject(files) {
3299
3422
  return "val.config.ts" in files && "val.modules.ts" in files;
@@ -3302,17 +3425,15 @@ function isValProject(files) {
3302
3425
  /**
3303
3426
  * Has this record already been wired up?
3304
3427
  *
3305
- * The control host is the marker. It used to be `platform:project-source`,
3306
- * which the generated file imported while Val was in memory mode and no longer
3307
- * does -- the project's source stopped being shipped into the isolate when the
3308
- * content service became what answers for it. The pending-source POST is the
3309
- * thing that cannot be anything but this platform's: no repository posts to a
3310
- * host that resolves
3311
- * nowhere, and every wired file has to, because an isolate cannot build.
3428
+ * {@link WIRED_MARKER} is the marker, or -- for a file generated before it
3429
+ * existed -- the sentinel host that file posted its saves to. It used to be
3430
+ * `platform:project-source` before that, which the generated file imported
3431
+ * while Val was in memory mode.
3312
3432
  */
3313
3433
  function isWired(files) {
3314
- var _files$VAL_SERVER$inc, _files$VAL_SERVER;
3315
- return (_files$VAL_SERVER$inc = (_files$VAL_SERVER = files[VAL_SERVER]) === null || _files$VAL_SERVER === void 0 ? void 0 : _files$VAL_SERVER.includes(CONTROL_HOST)) !== null && _files$VAL_SERVER$inc !== void 0 ? _files$VAL_SERVER$inc : false;
3434
+ var source = files[VAL_SERVER];
3435
+ if (source === undefined) return false;
3436
+ return source.startsWith(WIRED_MARKER) || source.includes(LEGACY_CONTROL_HOST);
3316
3437
  }
3317
3438
 
3318
3439
  /**
@@ -3385,10 +3506,10 @@ function wireUp(files, options) {
3385
3506
  * then publish BACK as project source, so the record would slowly fill with
3386
3507
  * generated files that are never read.
3387
3508
  */
3388
- if (TREE in out) {
3389
- delete out[TREE];
3509
+ if (projectPaths.TREE in out) {
3510
+ delete out[projectPaths.TREE];
3390
3511
  changes.push({
3391
- what: "".concat(TREE, " dropped"),
3512
+ what: "".concat(projectPaths.TREE, " dropped"),
3392
3513
  why: "it is generated per build; a tracked copy would be published back as project source"
3393
3514
  });
3394
3515
  }
@@ -3403,13 +3524,15 @@ function wireUp(files, options) {
3403
3524
  };
3404
3525
  }
3405
3526
 
3406
- exports.ENTRY = ENTRY;
3527
+ exports.ENTRY = projectPaths.ENTRY;
3528
+ exports.ROUTES_DIR = projectPaths.ROUTES_DIR;
3529
+ exports.TREE = projectPaths.TREE;
3530
+ exports.ARTIFACT_KEYS = artifactKeys.ARTIFACT_KEYS;
3531
+ exports.ARTIFACT_PREFIXES = artifactKeys.ARTIFACT_PREFIXES;
3407
3532
  exports.ENTRY_CHUNK = ENTRY_CHUNK;
3408
3533
  exports.INLINE_LIMIT = INLINE_LIMIT;
3409
3534
  exports.PROJECT_SOURCE = PROJECT_SOURCE;
3410
3535
  exports.PUBLIC_PREFIX = PUBLIC_PREFIX;
3411
- exports.ROUTES_DIR = ROUTES_DIR;
3412
- exports.TREE = TREE;
3413
3536
  exports.VAL_SERVER_PATH = VAL_SERVER_PATH;
3414
3537
  exports.aliasMap = aliasMap;
3415
3538
  exports.bakedGit = bakedGit;
@@ -3421,7 +3544,9 @@ exports.fetchBuildTargetRev = fetchBuildTargetRev;
3421
3544
  exports.isAsset = isAsset;
3422
3545
  exports.isValProject = isValProject;
3423
3546
  exports.isWired = isWired;
3547
+ exports.publishArtifacts = publishArtifacts;
3424
3548
  exports.publishPayload = publishPayload;
3549
+ exports.rebakeGit = rebakeGit;
3425
3550
  exports.resolveInFiles = resolveInFiles;
3426
3551
  exports.scanCandidates = scanCandidates;
3427
3552
  exports.treeSha = treeSha;