@valbuild/tanstack-build 0.150.9 → 0.151.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
- import { _ as _slicedToArray, a as _createForOfIteratorHelper, b as _asyncToGenerator, c as _regenerator, d as _toConsumableArray, s as sha256Hex, e as _typeof, f as _objectSpread2, g as _defineProperty, h as _regeneratorValues, r as resolveAsset, i as assetModule, j as isAsset } from './regeneratorValues-a8bd356a.esm.js';
2
- export { I as INLINE_LIMIT, k as base64Bytes, j as isAsset } from './regeneratorValues-a8bd356a.esm.js';
3
- import { T as TREE, E as ENTRY } from './projectPaths-5e4defea.esm.js';
4
- export { E as ENTRY, R as ROUTES_DIR, T as TREE } from './projectPaths-5e4defea.esm.js';
1
+ import { _ as _asyncToGenerator, a as _regenerator, b as _createForOfIteratorHelper, c as _toConsumableArray, d as _slicedToArray, s as sha256Hex, e as _typeof, f as _objectSpread2, g as _defineProperty, h as _regeneratorValues, r as resolveAsset, i as assetModule, j as isAsset } from './regeneratorValues-56b72784.esm.js';
2
+ export { I as INLINE_LIMIT, k as base64Bytes, j as isAsset } from './regeneratorValues-56b72784.esm.js';
3
+ import { T as TREE, v as valModulesEntryFile, E as ENTRY } from './projectPaths-521a37ed.esm.js';
4
+ export { E as ENTRY, R as ROUTES_DIR, T as TREE } from './projectPaths-521a37ed.esm.js';
5
5
  import { compile } from 'tailwindcss';
6
6
  import { A as ARTIFACT_KEYS, a as ARTIFACT_PREFIXES } from './artifactKeys-3a40f3a0.esm.js';
7
7
  export { A as ARTIFACT_KEYS, a as ARTIFACT_PREFIXES } from './artifactKeys-3a40f3a0.esm.js';
@@ -45,15 +45,40 @@ function useRolldown(rolldown) {
45
45
  */
46
46
  function loadRolldown() {
47
47
  if (chosen === null) {
48
- var loading = Promise.all([import('@rolldown/browser'), import('@rolldown/browser/parseAst')]).then(function (_ref) {
49
- var _ref2 = _slicedToArray(_ref, 2),
50
- bundler = _ref2[0],
51
- parser = _ref2[1];
52
- return {
53
- build: bundler.build,
54
- parseAstAsync: parser.parseAstAsync
48
+ /*
49
+ * One after the other, never together. Both import the WASI binding,
50
+ * whose top-level `await` fetches and instantiates the WebAssembly, and
51
+ * Safari (every iPhone browser) can settle the second import of a graph
52
+ * whose shared module is still awaiting before that import's own body
53
+ * has run. `build` is a hoisted function there and `rolldown` a `const`,
54
+ * so the build got a `build` it could call, which threw "Cannot access
55
+ * 'Ha' before initialization." (minified) on its first line -- home's
56
+ * upgrade page, on an iPhone, while Chrome built the same upgrade. Once
57
+ * the bundler has loaded, the binding has finished, and the parser's
58
+ * import has nothing left to wait for.
59
+ */
60
+ var loading = import('@rolldown/browser').then(/*#__PURE__*/function () {
61
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(bundler) {
62
+ var _t, _t2;
63
+ return _regenerator().w(function (_context) {
64
+ while (1) switch (_context.n) {
65
+ case 0:
66
+ _t = bundler.build;
67
+ _context.n = 1;
68
+ return import('@rolldown/browser/parseAst');
69
+ case 1:
70
+ _t2 = _context.v.parseAstAsync;
71
+ return _context.a(2, {
72
+ build: _t,
73
+ parseAstAsync: _t2
74
+ });
75
+ }
76
+ }, _callee);
77
+ }));
78
+ return function (_x) {
79
+ return _ref.apply(this, arguments);
55
80
  };
56
- });
81
+ }());
57
82
  // A load that failed is tried again by the next caller, not kept.
58
83
  loading["catch"](function () {
59
84
  if (chosen === loading) chosen = null;
@@ -1166,7 +1191,7 @@ var packageJson = {
1166
1191
  url: "git+https://github.com/valbuild/val.git"
1167
1192
  },
1168
1193
  license: "MIT",
1169
- version: "0.150.9",
1194
+ version: "0.151.0",
1170
1195
  sideEffects: false,
1171
1196
  main: "dist/valbuild-tanstack-build.cjs.js",
1172
1197
  module: "dist/valbuild-tanstack-build.esm.js",
@@ -1330,7 +1355,14 @@ var LEGACY_CONTROL_HOST = "platform.internal";
1330
1355
  * existed -- which is every project already published, since a build in a tab
1331
1356
  * rewrites single lines of its `val.server.ts` and never regenerates it.
1332
1357
  */
1333
- var PROPOSAL_BLOCK = "/*\n * THE PROPOSAL this isolate serves the address of, when it does: its name and\n * content branch, and the content it has saved (`VAL_OVERLAY`: the save's\n * commit, its Source by module and its `.val.ts` text by path). Val reads\n * that Source instead of the bundle's, commits a save to the proposal, and\n * names the save as its position. valbuild/home `docs/proposals.md`,\n * \"Saving\".\n *\n * Parsed here rather than with `proposalFromEnv` from @valbuild/server,\n * because this file is compiled against whatever @valbuild/tanstack the\n * PROJECT installed, and one from before proposals has no such export -- it\n * also ignores the `proposal` key below, and serves the base build, which\n * is the best an old app can do. A snapshot that does not parse is thrown,\n * not served as the base: a reviewer must not be shown the wrong content as\n * though it were the proposal.\n */\nconst proposal = (() => {\n const name = secret(\"VAL_PROPOSAL\");\n const branch = secret(\"VAL_BRANCH\");\n if (!name || !branch) return undefined;\n const overlay: {\n commit?: string | null;\n modules?: Record<string, unknown>;\n files?: Record<string, string>;\n } = JSON.parse(secret(\"VAL_OVERLAY\") ?? \"{}\");\n return {\n name,\n branch,\n commit: overlay.commit ?? null,\n modules: overlay.modules ?? {},\n files: overlay.files ?? {},\n };\n})();\n";
1358
+ var PROPOSAL_BLOCK = "/*\n * THE PROPOSAL this isolate serves the address of, when it does: its name and\n * content branch, and the content it has saved (`VAL_OVERLAY`: the save's\n * commit, its Source by module, its `.val.ts` text by path, and which\n * modules' code is staged). Val reads that Source instead of the bundle's,\n * commits a save to the proposal, and names the save as its position. And\n * which staging this build was made of (`VAL_BUILD_INPUTS`), so Val can tell\n * a staged module this build evaluated from one staged after it.\n * valbuild/home `docs/proposals.md`, \"Saving\" and \"Staged schemas\".\n *\n * Parsed here rather than with `proposalFromEnv` from @valbuild/server,\n * because this file is compiled against whatever @valbuild/tanstack the\n * PROJECT installed, and one from before proposals has no such export -- it\n * also ignores the `proposal` key below, and serves the base build, which\n * is the best an old app can do. A snapshot that does not parse is thrown,\n * not served as the base: a reviewer must not be shown the wrong content as\n * though it were the proposal.\n */\nconst proposal = (() => {\n const name = secret(\"VAL_PROPOSAL\");\n const branch = secret(\"VAL_BRANCH\");\n if (!name || !branch) return undefined;\n const overlay: {\n commit?: string | null;\n modules?: Record<string, unknown>;\n files?: Record<string, string>;\n staged?: Record<string, string>;\n } = JSON.parse(secret(\"VAL_OVERLAY\") ?? \"{}\");\n // Checked as `proposalFromEnv` checks them: read wrong, a save would\n // apply to staged code as though the build had it, or the other way round.\n const staged = overlay.staged ?? {};\n for (const [path, version] of Object.entries(staged)) {\n if (\n !path.startsWith(\"/\") ||\n typeof version !== \"string\" ||\n !version.startsWith(\"staged:\")\n ) {\n throw new Error(\n `Val: proposal ${name}: VAL_OVERLAY's staged must name module files with staged:<inputs> versions (${JSON.stringify(path)})`,\n );\n }\n }\n const inputs = secret(\"VAL_BUILD_INPUTS\");\n if (inputs && !/^[0-9a-f]{64}$/.test(inputs)) {\n throw new Error(\n `Val: proposal ${name}: VAL_BUILD_INPUTS is not a build's staged inputs (64 hex)`,\n );\n }\n return {\n name,\n branch,\n commit: overlay.commit ?? null,\n modules: overlay.modules ?? {},\n files: overlay.files ?? {},\n staged,\n buildInputs: inputs || null,\n };\n})();\n";
1359
+ /**
1360
+ * {@link PROPOSAL_BLOCK} as it was generated before it read which modules
1361
+ * are staged and what the build was made of: rewritten to the current block
1362
+ * by {@link rebakeProposal}, exactly, so a site wired before it learns both
1363
+ * at its next build. Never generated.
1364
+ */
1365
+ var PROPOSAL_BLOCK_V1 = "/*\n * THE PROPOSAL this isolate serves the address of, when it does: its name and\n * content branch, and the content it has saved (`VAL_OVERLAY`: the save's\n * commit, its Source by module and its `.val.ts` text by path). Val reads\n * that Source instead of the bundle's, commits a save to the proposal, and\n * names the save as its position. valbuild/home `docs/proposals.md`,\n * \"Saving\".\n *\n * Parsed here rather than with `proposalFromEnv` from @valbuild/server,\n * because this file is compiled against whatever @valbuild/tanstack the\n * PROJECT installed, and one from before proposals has no such export -- it\n * also ignores the `proposal` key below, and serves the base build, which\n * is the best an old app can do. A snapshot that does not parse is thrown,\n * not served as the base: a reviewer must not be shown the wrong content as\n * though it were the proposal.\n */\nconst proposal = (() => {\n const name = secret(\"VAL_PROPOSAL\");\n const branch = secret(\"VAL_BRANCH\");\n if (!name || !branch) return undefined;\n const overlay: {\n commit?: string | null;\n modules?: Record<string, unknown>;\n files?: Record<string, string>;\n } = JSON.parse(secret(\"VAL_OVERLAY\") ?? \"{}\");\n return {\n name,\n branch,\n commit: overlay.commit ?? null,\n modules: overlay.modules ?? {},\n files: overlay.files ?? {},\n };\n})();\n";
1334
1366
  /**
1335
1367
  * THE CONTENT VERSION the site serves, when it differs from the one this build
1336
1368
  * bundles (\`VAL_CONTENT\`). See valbuild/home \`docs/hosted-publishing.md\`,
@@ -1442,6 +1474,14 @@ function bakedJob(files) {
1442
1474
  * as it is, and serves a proposal's address as its base build.
1443
1475
  */
1444
1476
  function rebakeProposal(source) {
1477
+ // A block from before staged code was read: the current one in its place,
1478
+ // where it is exactly as generated.
1479
+ var at = source.indexOf(PROPOSAL_BLOCK_V1);
1480
+ if (at !== -1 && source.indexOf(PROPOSAL_BLOCK_V1, at + 1) === -1) {
1481
+ return source.replace(PROPOSAL_BLOCK_V1, function () {
1482
+ return PROPOSAL_BLOCK;
1483
+ });
1484
+ }
1445
1485
  if (source.includes("const proposal = (() => {")) return source;
1446
1486
  var once = function once(needle) {
1447
1487
  var at = source.indexOf(needle);
@@ -1851,78 +1891,474 @@ function canonicalJson(value) {
1851
1891
  return JSON.stringify(value);
1852
1892
  }
1853
1893
 
1854
- /** Cheap pre-filter: skip the parse unless one of these appears in the source. */
1855
- var MARKERS = ["createIsomorphicFn", "createServerOnlyFn", "createClientOnlyFn", "createMiddleware", "ClientOnly"];
1856
-
1857
- /** Walks a `foo().bar().baz()` chain down to its root callee identifier. */
1858
- function chainRoot(node) {
1859
- var current = node;
1860
- while (current) {
1861
- if (current.type === "CallExpression") {
1862
- var callee = current.callee;
1863
- if ((callee === null || callee === void 0 ? void 0 : callee.type) === "Identifier") return String(callee.name);
1864
- if ((callee === null || callee === void 0 ? void 0 : callee.type) === "MemberExpression") {
1865
- current = callee.object;
1866
- continue;
1894
+ /**
1895
+ * JSON with comments and trailing commas, which is what tsconfig.json is.
1896
+ *
1897
+ * Written as a scanner rather than a regex on purpose: `"url": "https://x"`
1898
+ * contains `//`, and a regex that strips comments without tracking string state
1899
+ * truncates the file there and throws a parse error pointing at the wrong line.
1900
+ */
1901
+ function parseJsonc(text) {
1902
+ var out = "";
1903
+ var i = 0;
1904
+ while (i < text.length) {
1905
+ var ch = text[i];
1906
+ if (ch === '"') {
1907
+ // Copy the whole string literal, escapes included, untouched.
1908
+ out += ch;
1909
+ i++;
1910
+ while (i < text.length) {
1911
+ var c = text[i];
1912
+ out += c;
1913
+ i++;
1914
+ if (c === "\\") {
1915
+ if (i < text.length) out += text[i++];
1916
+ continue;
1917
+ }
1918
+ if (c === '"') break;
1867
1919
  }
1868
- return null;
1920
+ continue;
1869
1921
  }
1870
- return null;
1922
+ if (ch === "/" && text[i + 1] === "/") {
1923
+ while (i < text.length && text[i] !== "\n") i++;
1924
+ continue;
1925
+ }
1926
+ if (ch === "/" && text[i + 1] === "*") {
1927
+ i += 2;
1928
+ while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) i++;
1929
+ i += 2;
1930
+ continue;
1931
+ }
1932
+ out += ch;
1933
+ i++;
1871
1934
  }
1872
- return null;
1935
+ // Trailing commas, now that every remaining comma is structural.
1936
+ return JSON.parse(out.replace(/,(\s*[}\]])/g, "$1"));
1873
1937
  }
1874
1938
 
1939
+ /** One `paths` entry, pre-split on its wildcard. */
1940
+
1875
1941
  /**
1876
- * True when this call is the whole chain rather than a link in a longer one.
1942
+ * Reads tsconfig.json out of the file record and builds the matcher.
1877
1943
  *
1878
- * Without this, `createIsomorphicFn().client(a).server(b)` matches three times
1879
- * and the inner replacements land inside text the outer one is about to
1880
- * replace.
1944
+ * Returns null when the project configures no aliases, which is the common
1945
+ * case and costs nothing.
1881
1946
  */
1882
- function isOutermost(node, stack) {
1883
- var parent = stack[stack.length - 1];
1884
- var grandparent = stack[stack.length - 2];
1885
- return !((parent === null || parent === void 0 ? void 0 : parent.type) === "MemberExpression" && parent.object === node && (grandparent === null || grandparent === void 0 ? void 0 : grandparent.type) === "CallExpression");
1886
- }
1947
+ function aliasMap(files, warn) {
1948
+ var _config$compilerOptio, _config$compilerOptio2;
1949
+ var entry = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "tsconfig.json";
1950
+ var config = readConfig(files, entry, warn, new Set());
1951
+ var paths = config === null || config === void 0 || (_config$compilerOptio = config.compilerOptions) === null || _config$compilerOptio === void 0 ? void 0 : _config$compilerOptio.paths;
1952
+ var baseUrl = config === null || config === void 0 || (_config$compilerOptio2 = config.compilerOptions) === null || _config$compilerOptio2 === void 0 ? void 0 : _config$compilerOptio2.baseUrl;
1953
+ // A project can configure either one without the other, and baseUrl alone is
1954
+ // enough to change how a bare specifier resolves.
1955
+ if ((!paths || Object.keys(paths).length === 0) && baseUrl === undefined) return null;
1887
1956
 
1888
- /** Collects `.method(arg)` calls along a chain, nearest-root first. */
1889
- function methodsOf(node) {
1890
- var found = new Map();
1891
- var current = node;
1892
- while (((_current = current) === null || _current === void 0 ? void 0 : _current.type) === "CallExpression") {
1893
- var _current, _name, _callee$property, _current$arguments;
1894
- var callee = current.callee;
1895
- if ((callee === null || callee === void 0 ? void 0 : callee.type) !== "MemberExpression") break;
1896
- var name = String((_name = (_callee$property = callee.property) === null || _callee$property === void 0 ? void 0 : _callee$property.name) !== null && _name !== void 0 ? _name : "");
1897
- // Nearest-to-root wins, so a later duplicate does not shadow the first.
1898
- found.set(name, {
1899
- call: current,
1900
- arg: (_current$arguments = current.arguments) === null || _current$arguments === void 0 ? void 0 : _current$arguments[0],
1901
- objectEnd: callee.object.end
1957
+ // `baseUrl` is relative to the tsconfig that declared it. Since TS 4.1 paths
1958
+ // work without one, resolved against the tsconfig's own directory -- so the
1959
+ // fallback here is the directory, not the project root.
1960
+ var base = resolve(dirname(entry), baseUrl !== null && baseUrl !== void 0 ? baseUrl : ".");
1961
+ var patterns = [];
1962
+ for (var _i = 0, _Object$entries = Object.entries(paths !== null && paths !== void 0 ? paths : {}); _i < _Object$entries.length; _i++) {
1963
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
1964
+ pattern = _Object$entries$_i[0],
1965
+ targets = _Object$entries$_i[1];
1966
+ var star = pattern.indexOf("*");
1967
+ if (star !== pattern.lastIndexOf("*")) {
1968
+ warn("tsconfig paths pattern '".concat(pattern, "' has more than one '*' and is ignored."));
1969
+ continue;
1970
+ }
1971
+ patterns.push({
1972
+ prefix: star === -1 ? pattern : pattern.slice(0, star),
1973
+ suffix: star === -1 ? "" : pattern.slice(star + 1),
1974
+ wildcard: star !== -1,
1975
+ targets: targets.map(function (target) {
1976
+ return resolve(base, target);
1977
+ })
1902
1978
  });
1903
- current = callee.object;
1904
1979
  }
1905
- return found;
1980
+
1981
+ // TypeScript picks the pattern with the longest literal prefix, so `@/ui/*`
1982
+ // beats `@/*` for `@/ui/card` regardless of declaration order.
1983
+ patterns.sort(function (a, b) {
1984
+ return b.prefix.length - a.prefix.length;
1985
+ });
1986
+ return {
1987
+ patterns: Object.keys(paths !== null && paths !== void 0 ? paths : {}),
1988
+ baseUrlCandidate: function baseUrlCandidate(specifier) {
1989
+ return baseUrl === undefined ? null : resolve(base, specifier);
1990
+ },
1991
+ candidates: function candidates(specifier) {
1992
+ var _loop = function _loop() {
1993
+ var pattern = _patterns[_i2];
1994
+ if (!pattern.wildcard) {
1995
+ if (specifier === pattern.prefix) return {
1996
+ v: _toConsumableArray(pattern.targets)
1997
+ };
1998
+ return 0; // continue
1999
+ }
2000
+ if (!specifier.startsWith(pattern.prefix) || !specifier.endsWith(pattern.suffix) || specifier.length < pattern.prefix.length + pattern.suffix.length) {
2001
+ return 0; // continue
2002
+ }
2003
+ var matched = specifier.slice(pattern.prefix.length, specifier.length - pattern.suffix.length);
2004
+ return {
2005
+ v: pattern.targets.map(function (target) {
2006
+ return target.replace("*", matched);
2007
+ })
2008
+ };
2009
+ },
2010
+ _ret;
2011
+ for (var _i2 = 0, _patterns = patterns; _i2 < _patterns.length; _i2++) {
2012
+ _ret = _loop();
2013
+ if (_ret === 0) continue;
2014
+ if (_ret) return _ret.v;
2015
+ }
2016
+ return [];
2017
+ }
2018
+ };
2019
+ }
2020
+
2021
+ /** Follows `extends` through the file record. Package extends cannot be read. */
2022
+ function readConfig(files, path, warn, seen) {
2023
+ var _config, _config$compilerOptio4, _config$compilerOptio5, _parent$compilerOptio;
2024
+ if (seen.has(path)) return null; // a cycle; whatever we have is enough
2025
+ seen.add(path);
2026
+ var text = files[path];
2027
+ if (text === undefined) return null;
2028
+ var config;
2029
+ try {
2030
+ config = parseJsonc(text);
2031
+ } catch (error) {
2032
+ var _message;
2033
+ warn("Could not parse ".concat(path, ": ").concat(String((_message = error === null || error === void 0 ? void 0 : error.message) !== null && _message !== void 0 ? _message : error)));
2034
+ return null;
2035
+ }
2036
+ if (!((_config = config) !== null && _config !== void 0 && _config["extends"])) return config;
2037
+
2038
+ // Only a relative extends can be followed: a package one ("extends":
2039
+ // "@tsconfig/node20/tsconfig.json") lives in node_modules, which a browser
2040
+ // build does not have. Worth saying out loud rather than silently resolving
2041
+ // half the aliases, because the base config is where a monorepo usually puts
2042
+ // them.
2043
+ if (!config["extends"].startsWith(".")) {
2044
+ var _config$compilerOptio3;
2045
+ if (!((_config$compilerOptio3 = config.compilerOptions) !== null && _config$compilerOptio3 !== void 0 && _config$compilerOptio3.paths)) {
2046
+ warn("".concat(path, " extends '").concat(config["extends"], "', which is a package and cannot be read here. ") + "Any 'paths' it declares will not apply -- declare them in ".concat(path, " instead."));
2047
+ }
2048
+ return config;
2049
+ }
2050
+ var parentPath = resolveConfigPath(files, resolve(dirname(path), config["extends"]));
2051
+ var parent = parentPath ? readConfig(files, parentPath, warn, seen) : null;
2052
+ if (!parent) return config;
2053
+
2054
+ // The child wins, and `paths` replaces rather than merges -- which is what
2055
+ // TypeScript does.
2056
+ return {
2057
+ compilerOptions: _objectSpread2(_objectSpread2(_objectSpread2({}, parent.compilerOptions), config.compilerOptions), {}, {
2058
+ // baseUrl in the parent was relative to the *parent*, and readConfig
2059
+ // returns it unresolved, so a parent baseUrl with a child that sets none
2060
+ // is the one case this gets wrong. Rare enough to name rather than model.
2061
+ paths: (_config$compilerOptio4 = (_config$compilerOptio5 = config.compilerOptions) === null || _config$compilerOptio5 === void 0 ? void 0 : _config$compilerOptio5.paths) !== null && _config$compilerOptio4 !== void 0 ? _config$compilerOptio4 : (_parent$compilerOptio = parent.compilerOptions) === null || _parent$compilerOptio === void 0 ? void 0 : _parent$compilerOptio.paths
2062
+ })
2063
+ };
2064
+ }
2065
+
2066
+ /** `extends: './base'` may omit the .json. */
2067
+ function resolveConfigPath(files, path) {
2068
+ for (var _i3 = 0, _arr = [path, "".concat(path, ".json")]; _i3 < _arr.length; _i3++) {
2069
+ var candidate = _arr[_i3];
2070
+ if (candidate in files) return candidate;
2071
+ }
2072
+ return null;
1906
2073
  }
2074
+
1907
2075
  /**
1908
- * Rewrites the environment markers in one module for one target.
2076
+ * A project's `val.modules.ts`, bundled to run: every `.val.ts` it imports,
2077
+ * the `val.config` they share and the `.val.json` entries they name, as ONE
2078
+ * ES module -- so it can be imported from a `blob:` URL, which cannot resolve
2079
+ * a relative chunk -- with every npm import pointing at the site's own
2080
+ * vendor chunks, at absolute URLs under `origin`.
1909
2081
  *
1910
- * Returns `null` when the module contains none, so the caller leaves it alone
1911
- * and pays no parse.
2082
+ * What the builder tab evaluates to learn a tree's schemas: Update from the
2083
+ * site with code (valbuild/home `docs/hosted-publishing.md` step 8.2, slice
2084
+ * 1b). The project's own `@valbuild/*` and dependencies are what run, as the
2085
+ * site runs them -- the browser half of its layer, from `/_pvendor/<rev>/`,
2086
+ * and the base layer from `/_vendor/`. Whoever imports it should do so off
2087
+ * the Studio's page: `@valbuild/tanstack` brings React and patches its JSX.
2088
+ *
2089
+ * Nothing else of a build happens here: no route splitting, no server
2090
+ * functions, no CSS -- a `.val.ts` has none of it.
1912
2091
  */
1913
- function transformEnvMarkers(_x, _x2, _x3) {
1914
- return _transformEnvMarkers.apply(this, arguments);
2092
+ function bundleValModules(_x) {
2093
+ return _bundleValModules.apply(this, arguments);
1915
2094
  }
1916
- function _transformEnvMarkers() {
1917
- _transformEnvMarkers = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(moduleId, code, target) {
1918
- var ast, imported, edits, applied, text;
1919
- return _regenerator().w(function (_context) {
1920
- while (1) switch (_context.n) {
1921
- case 0:
1922
- if (MARKERS.some(function (marker) {
1923
- return code.includes(marker);
1924
- })) {
1925
- _context.n = 1;
2095
+
2096
+ /**
2097
+ * A build's `val.modules` registry, as the build emits it beside its client
2098
+ * chunks: `{ "val-modules-<build>.js": code }`, served at `/_app/` with
2099
+ * them, its npm imports pointing at the site's vendor chunks on its own
2100
+ * origin (`/_vendor/`, `/_pvendor/<rev>/`) as the client bundle's do.
2101
+ *
2102
+ * What a Studio opened on an older build imports, once the server's
2103
+ * manifest names it (`registry`, from the build's name the platform hands
2104
+ * the server: `VAL_BUILD`), to take this build's schemas in WITHOUT
2105
+ * reloading the page: `HostStore.reloadCode` in `@valbuild/ui`, and phase 9
2106
+ * of `docs/plans/one-content-model.md` in valbuild/val.
2107
+ *
2108
+ * Empty -- and the build goes on -- for a project with no `val.modules.ts`,
2109
+ * or one whose Val modules cannot be bundled for the browser (a `.val.ts`
2110
+ * importing something server-only): such a build has no entry, and a Studio
2111
+ * that cannot import one reloads the page instead, as it did before. Said
2112
+ * in the build's warnings.
2113
+ */
2114
+ function _bundleValModules() {
2115
+ _bundleValModules = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(input) {
2116
+ var _input$entry;
2117
+ var files, target, origin, entry, warnings, aliases, base, project, resolveProjectPath, _yield$loadRolldown, build, result, chunks, _t;
2118
+ return _regenerator().w(function (_context) {
2119
+ while (1) switch (_context.p = _context.n) {
2120
+ case 0:
2121
+ files = input.files, target = input.target, origin = input.origin;
2122
+ entry = (_input$entry = input.entry) !== null && _input$entry !== void 0 ? _input$entry : ["val.modules.ts", "val.modules.js"].find(function (path) {
2123
+ return path in files;
2124
+ });
2125
+ if (!(entry === undefined || !(entry in files))) {
2126
+ _context.n = 1;
2127
+ break;
2128
+ }
2129
+ throw new Error("This project has no val.modules.ts, so its Val modules cannot be read.");
2130
+ case 1:
2131
+ warnings = [];
2132
+ aliases = aliasMap(files, function (message) {
2133
+ return warnings.push(message);
2134
+ });
2135
+ base = "".concat(origin, "/_vendor/");
2136
+ project = target.project.rev === null ? null : "".concat(origin, "/_pvendor/").concat(target.project.rev, "/");
2137
+ resolveProjectPath = function resolveProjectPath(path) {
2138
+ return resolveInFiles(path, files);
2139
+ };
2140
+ _context.n = 2;
2141
+ return loadRolldown();
2142
+ case 2:
2143
+ _yield$loadRolldown = _context.v;
2144
+ build = _yield$loadRolldown.build;
2145
+ _context.p = 3;
2146
+ _context.n = 4;
2147
+ return build({
2148
+ input: entry,
2149
+ // See `buildOnce`: required in the browser, inert here.
2150
+ cwd: "/",
2151
+ moduleTypes: {
2152
+ ".css": "empty"
2153
+ },
2154
+ plugins: [{
2155
+ name: "val:modules",
2156
+ resolveId: function resolveId(source, importer) {
2157
+ if (source.startsWith(".")) {
2158
+ return resolveProjectPath(resolve(dirname(importer !== null && importer !== void 0 ? importer : entry), source));
2159
+ }
2160
+ if (source in files) return source;
2161
+ var baseChunk = target.base.modules[source];
2162
+ if (baseChunk) {
2163
+ return {
2164
+ id: "".concat(base).concat(baseChunk, ".js"),
2165
+ external: true
2166
+ };
2167
+ }
2168
+ var projectChunk = target.project.modules[source];
2169
+ if (projectChunk && project !== null) {
2170
+ if (target.project.workerOnly.includes(source)) {
2171
+ throw new Error("'".concat(source, "' is server-only in this project's vendor layer, so a .val.ts importing it cannot be read in the browser."));
2172
+ }
2173
+ return {
2174
+ id: "".concat(project).concat(projectChunk, ".js"),
2175
+ external: true
2176
+ };
2177
+ }
2178
+ if (aliases) {
2179
+ var _iterator = _createForOfIteratorHelper(aliases.candidates(source)),
2180
+ _step;
2181
+ try {
2182
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
2183
+ var candidate = _step.value;
2184
+ var _hit = resolveProjectPath(candidate);
2185
+ if (_hit) return _hit;
2186
+ }
2187
+ } catch (err) {
2188
+ _iterator.e(err);
2189
+ } finally {
2190
+ _iterator.f();
2191
+ }
2192
+ var fromBaseUrl = aliases.baseUrlCandidate(source);
2193
+ var hit = fromBaseUrl && resolveProjectPath(fromBaseUrl);
2194
+ if (hit) return hit;
2195
+ }
2196
+ // An error, not a warning: rolldown would otherwise leave the
2197
+ // specifier as it is, and it would fail when imported, unnamed.
2198
+ throw new Error("'".concat(source, "' is not an available dependency. Available: ").concat([].concat(_toConsumableArray(Object.keys(target.base.modules)), _toConsumableArray(Object.keys(target.project.modules))).join(", "), "."));
2199
+ },
2200
+ load: function load(id) {
2201
+ return id in files ? files[id] : null;
2202
+ }
2203
+ }],
2204
+ transform: {
2205
+ jsx: {
2206
+ runtime: "automatic",
2207
+ importSource: "react"
2208
+ }
2209
+ },
2210
+ output: {
2211
+ format: "esm",
2212
+ minify: false,
2213
+ // One module: `def: () => import("./x.val")` stays a dynamic import of
2214
+ // something already in the file.
2215
+ codeSplitting: false
2216
+ },
2217
+ write: false
2218
+ });
2219
+ case 4:
2220
+ result = _context.v;
2221
+ _context.n = 6;
2222
+ break;
2223
+ case 5:
2224
+ _context.p = 5;
2225
+ _t = _context.v;
2226
+ throw new Error(["The Val modules could not be bundled."].concat(warnings, [_t instanceof Error ? _t.message : String(_t)]).join("\n"), {
2227
+ cause: _t
2228
+ });
2229
+ case 6:
2230
+ chunks = result.output.filter(function (output) {
2231
+ return output.type === "chunk";
2232
+ });
2233
+ if (!(chunks.length !== 1)) {
2234
+ _context.n = 7;
2235
+ break;
2236
+ }
2237
+ throw new Error("Bundling the Val modules made ".concat(chunks.length, " chunks rather than one."));
2238
+ case 7:
2239
+ return _context.a(2, {
2240
+ code: chunks[0].code
2241
+ });
2242
+ }
2243
+ }, _callee, null, [[3, 5]]);
2244
+ }));
2245
+ return _bundleValModules.apply(this, arguments);
2246
+ }
2247
+ function valModulesEntry(_x2, _x3, _x4) {
2248
+ return _valModulesEntry.apply(this, arguments);
2249
+ }
2250
+ function _valModulesEntry() {
2251
+ _valModulesEntry = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(input, build, warnings) {
2252
+ var entry, _yield$bundleValModul, code, _t2;
2253
+ return _regenerator().w(function (_context2) {
2254
+ while (1) switch (_context2.p = _context2.n) {
2255
+ case 0:
2256
+ entry = ["val.modules.ts", "val.modules.js"].find(function (path) {
2257
+ return path in input.files;
2258
+ });
2259
+ if (!(entry === undefined)) {
2260
+ _context2.n = 1;
2261
+ break;
2262
+ }
2263
+ return _context2.a(2, {});
2264
+ case 1:
2265
+ _context2.p = 1;
2266
+ _context2.n = 2;
2267
+ return bundleValModules({
2268
+ files: input.files,
2269
+ target: input.target,
2270
+ // Root-relative, as the client bundle names its vendor chunks: the
2271
+ // entry is served on the site's own origin.
2272
+ origin: "",
2273
+ entry: entry
2274
+ });
2275
+ case 2:
2276
+ _yield$bundleValModul = _context2.v;
2277
+ code = _yield$bundleValModul.code;
2278
+ return _context2.a(2, _defineProperty({}, valModulesEntryFile(build), code));
2279
+ case 3:
2280
+ _context2.p = 3;
2281
+ _t2 = _context2.v;
2282
+ warnings.push("The Val modules were not emitted for the Studio, so an open Studio reloads the page to take this build's code: ".concat(_t2 instanceof Error ? _t2.message : String(_t2)));
2283
+ return _context2.a(2, {});
2284
+ }
2285
+ }, _callee2, null, [[1, 3]]);
2286
+ }));
2287
+ return _valModulesEntry.apply(this, arguments);
2288
+ }
2289
+
2290
+ /** Cheap pre-filter: skip the parse unless one of these appears in the source. */
2291
+ var MARKERS = ["createIsomorphicFn", "createServerOnlyFn", "createClientOnlyFn", "createMiddleware", "ClientOnly"];
2292
+
2293
+ /** Walks a `foo().bar().baz()` chain down to its root callee identifier. */
2294
+ function chainRoot(node) {
2295
+ var current = node;
2296
+ while (current) {
2297
+ if (current.type === "CallExpression") {
2298
+ var callee = current.callee;
2299
+ if ((callee === null || callee === void 0 ? void 0 : callee.type) === "Identifier") return String(callee.name);
2300
+ if ((callee === null || callee === void 0 ? void 0 : callee.type) === "MemberExpression") {
2301
+ current = callee.object;
2302
+ continue;
2303
+ }
2304
+ return null;
2305
+ }
2306
+ return null;
2307
+ }
2308
+ return null;
2309
+ }
2310
+
2311
+ /**
2312
+ * True when this call is the whole chain rather than a link in a longer one.
2313
+ *
2314
+ * Without this, `createIsomorphicFn().client(a).server(b)` matches three times
2315
+ * and the inner replacements land inside text the outer one is about to
2316
+ * replace.
2317
+ */
2318
+ function isOutermost(node, stack) {
2319
+ var parent = stack[stack.length - 1];
2320
+ var grandparent = stack[stack.length - 2];
2321
+ return !((parent === null || parent === void 0 ? void 0 : parent.type) === "MemberExpression" && parent.object === node && (grandparent === null || grandparent === void 0 ? void 0 : grandparent.type) === "CallExpression");
2322
+ }
2323
+
2324
+ /** Collects `.method(arg)` calls along a chain, nearest-root first. */
2325
+ function methodsOf(node) {
2326
+ var found = new Map();
2327
+ var current = node;
2328
+ while (((_current = current) === null || _current === void 0 ? void 0 : _current.type) === "CallExpression") {
2329
+ var _current, _name, _callee$property, _current$arguments;
2330
+ var callee = current.callee;
2331
+ if ((callee === null || callee === void 0 ? void 0 : callee.type) !== "MemberExpression") break;
2332
+ var name = String((_name = (_callee$property = callee.property) === null || _callee$property === void 0 ? void 0 : _callee$property.name) !== null && _name !== void 0 ? _name : "");
2333
+ // Nearest-to-root wins, so a later duplicate does not shadow the first.
2334
+ found.set(name, {
2335
+ call: current,
2336
+ arg: (_current$arguments = current.arguments) === null || _current$arguments === void 0 ? void 0 : _current$arguments[0],
2337
+ objectEnd: callee.object.end
2338
+ });
2339
+ current = callee.object;
2340
+ }
2341
+ return found;
2342
+ }
2343
+ /**
2344
+ * Rewrites the environment markers in one module for one target.
2345
+ *
2346
+ * Returns `null` when the module contains none, so the caller leaves it alone
2347
+ * and pays no parse.
2348
+ */
2349
+ function transformEnvMarkers(_x, _x2, _x3) {
2350
+ return _transformEnvMarkers.apply(this, arguments);
2351
+ }
2352
+ function _transformEnvMarkers() {
2353
+ _transformEnvMarkers = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(moduleId, code, target) {
2354
+ var ast, imported, edits, applied, text;
2355
+ return _regenerator().w(function (_context) {
2356
+ while (1) switch (_context.n) {
2357
+ case 0:
2358
+ if (MARKERS.some(function (marker) {
2359
+ return code.includes(marker);
2360
+ })) {
2361
+ _context.n = 1;
1926
2362
  break;
1927
2363
  }
1928
2364
  return _context.a(2, null);
@@ -2712,202 +3148,21 @@ function _transformRouteNodes() {
2712
3148
  _iterator.f();
2713
3149
  }
2714
3150
  if (doomed.size) edits.push.apply(edits, _toConsumableArray(deleteProperties(code, properties, doomed)));
2715
- });
2716
- if (!(edits.length === 0)) {
2717
- _context.n = 5;
2718
- break;
2719
- }
2720
- return _context.a(2, null);
2721
- case 5:
2722
- return _context.a(2, {
2723
- code: applyEdits(code, edits),
2724
- removed: removed
2725
- });
2726
- }
2727
- }, _callee);
2728
- }));
2729
- return _transformRouteNodes.apply(this, arguments);
2730
- }
2731
-
2732
- /**
2733
- * JSON with comments and trailing commas, which is what tsconfig.json is.
2734
- *
2735
- * Written as a scanner rather than a regex on purpose: `"url": "https://x"`
2736
- * contains `//`, and a regex that strips comments without tracking string state
2737
- * truncates the file there and throws a parse error pointing at the wrong line.
2738
- */
2739
- function parseJsonc(text) {
2740
- var out = "";
2741
- var i = 0;
2742
- while (i < text.length) {
2743
- var ch = text[i];
2744
- if (ch === '"') {
2745
- // Copy the whole string literal, escapes included, untouched.
2746
- out += ch;
2747
- i++;
2748
- while (i < text.length) {
2749
- var c = text[i];
2750
- out += c;
2751
- i++;
2752
- if (c === "\\") {
2753
- if (i < text.length) out += text[i++];
2754
- continue;
2755
- }
2756
- if (c === '"') break;
2757
- }
2758
- continue;
2759
- }
2760
- if (ch === "/" && text[i + 1] === "/") {
2761
- while (i < text.length && text[i] !== "\n") i++;
2762
- continue;
2763
- }
2764
- if (ch === "/" && text[i + 1] === "*") {
2765
- i += 2;
2766
- while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) i++;
2767
- i += 2;
2768
- continue;
2769
- }
2770
- out += ch;
2771
- i++;
2772
- }
2773
- // Trailing commas, now that every remaining comma is structural.
2774
- return JSON.parse(out.replace(/,(\s*[}\]])/g, "$1"));
2775
- }
2776
-
2777
- /** One `paths` entry, pre-split on its wildcard. */
2778
-
2779
- /**
2780
- * Reads tsconfig.json out of the file record and builds the matcher.
2781
- *
2782
- * Returns null when the project configures no aliases, which is the common
2783
- * case and costs nothing.
2784
- */
2785
- function aliasMap(files, warn) {
2786
- var _config$compilerOptio, _config$compilerOptio2;
2787
- var entry = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "tsconfig.json";
2788
- var config = readConfig(files, entry, warn, new Set());
2789
- var paths = config === null || config === void 0 || (_config$compilerOptio = config.compilerOptions) === null || _config$compilerOptio === void 0 ? void 0 : _config$compilerOptio.paths;
2790
- var baseUrl = config === null || config === void 0 || (_config$compilerOptio2 = config.compilerOptions) === null || _config$compilerOptio2 === void 0 ? void 0 : _config$compilerOptio2.baseUrl;
2791
- // A project can configure either one without the other, and baseUrl alone is
2792
- // enough to change how a bare specifier resolves.
2793
- if ((!paths || Object.keys(paths).length === 0) && baseUrl === undefined) return null;
2794
-
2795
- // `baseUrl` is relative to the tsconfig that declared it. Since TS 4.1 paths
2796
- // work without one, resolved against the tsconfig's own directory -- so the
2797
- // fallback here is the directory, not the project root.
2798
- var base = resolve(dirname(entry), baseUrl !== null && baseUrl !== void 0 ? baseUrl : ".");
2799
- var patterns = [];
2800
- for (var _i = 0, _Object$entries = Object.entries(paths !== null && paths !== void 0 ? paths : {}); _i < _Object$entries.length; _i++) {
2801
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
2802
- pattern = _Object$entries$_i[0],
2803
- targets = _Object$entries$_i[1];
2804
- var star = pattern.indexOf("*");
2805
- if (star !== pattern.lastIndexOf("*")) {
2806
- warn("tsconfig paths pattern '".concat(pattern, "' has more than one '*' and is ignored."));
2807
- continue;
2808
- }
2809
- patterns.push({
2810
- prefix: star === -1 ? pattern : pattern.slice(0, star),
2811
- suffix: star === -1 ? "" : pattern.slice(star + 1),
2812
- wildcard: star !== -1,
2813
- targets: targets.map(function (target) {
2814
- return resolve(base, target);
2815
- })
2816
- });
2817
- }
2818
-
2819
- // TypeScript picks the pattern with the longest literal prefix, so `@/ui/*`
2820
- // beats `@/*` for `@/ui/card` regardless of declaration order.
2821
- patterns.sort(function (a, b) {
2822
- return b.prefix.length - a.prefix.length;
2823
- });
2824
- return {
2825
- patterns: Object.keys(paths !== null && paths !== void 0 ? paths : {}),
2826
- baseUrlCandidate: function baseUrlCandidate(specifier) {
2827
- return baseUrl === undefined ? null : resolve(base, specifier);
2828
- },
2829
- candidates: function candidates(specifier) {
2830
- var _loop = function _loop() {
2831
- var pattern = _patterns[_i2];
2832
- if (!pattern.wildcard) {
2833
- if (specifier === pattern.prefix) return {
2834
- v: _toConsumableArray(pattern.targets)
2835
- };
2836
- return 0; // continue
2837
- }
2838
- if (!specifier.startsWith(pattern.prefix) || !specifier.endsWith(pattern.suffix) || specifier.length < pattern.prefix.length + pattern.suffix.length) {
2839
- return 0; // continue
3151
+ });
3152
+ if (!(edits.length === 0)) {
3153
+ _context.n = 5;
3154
+ break;
2840
3155
  }
2841
- var matched = specifier.slice(pattern.prefix.length, specifier.length - pattern.suffix.length);
2842
- return {
2843
- v: pattern.targets.map(function (target) {
2844
- return target.replace("*", matched);
2845
- })
2846
- };
2847
- },
2848
- _ret;
2849
- for (var _i2 = 0, _patterns = patterns; _i2 < _patterns.length; _i2++) {
2850
- _ret = _loop();
2851
- if (_ret === 0) continue;
2852
- if (_ret) return _ret.v;
3156
+ return _context.a(2, null);
3157
+ case 5:
3158
+ return _context.a(2, {
3159
+ code: applyEdits(code, edits),
3160
+ removed: removed
3161
+ });
2853
3162
  }
2854
- return [];
2855
- }
2856
- };
2857
- }
2858
-
2859
- /** Follows `extends` through the file record. Package extends cannot be read. */
2860
- function readConfig(files, path, warn, seen) {
2861
- var _config, _config$compilerOptio4, _config$compilerOptio5, _parent$compilerOptio;
2862
- if (seen.has(path)) return null; // a cycle; whatever we have is enough
2863
- seen.add(path);
2864
- var text = files[path];
2865
- if (text === undefined) return null;
2866
- var config;
2867
- try {
2868
- config = parseJsonc(text);
2869
- } catch (error) {
2870
- var _message;
2871
- warn("Could not parse ".concat(path, ": ").concat(String((_message = error === null || error === void 0 ? void 0 : error.message) !== null && _message !== void 0 ? _message : error)));
2872
- return null;
2873
- }
2874
- if (!((_config = config) !== null && _config !== void 0 && _config["extends"])) return config;
2875
-
2876
- // Only a relative extends can be followed: a package one ("extends":
2877
- // "@tsconfig/node20/tsconfig.json") lives in node_modules, which a browser
2878
- // build does not have. Worth saying out loud rather than silently resolving
2879
- // half the aliases, because the base config is where a monorepo usually puts
2880
- // them.
2881
- if (!config["extends"].startsWith(".")) {
2882
- var _config$compilerOptio3;
2883
- if (!((_config$compilerOptio3 = config.compilerOptions) !== null && _config$compilerOptio3 !== void 0 && _config$compilerOptio3.paths)) {
2884
- warn("".concat(path, " extends '").concat(config["extends"], "', which is a package and cannot be read here. ") + "Any 'paths' it declares will not apply -- declare them in ".concat(path, " instead."));
2885
- }
2886
- return config;
2887
- }
2888
- var parentPath = resolveConfigPath(files, resolve(dirname(path), config["extends"]));
2889
- var parent = parentPath ? readConfig(files, parentPath, warn, seen) : null;
2890
- if (!parent) return config;
2891
-
2892
- // The child wins, and `paths` replaces rather than merges -- which is what
2893
- // TypeScript does.
2894
- return {
2895
- compilerOptions: _objectSpread2(_objectSpread2(_objectSpread2({}, parent.compilerOptions), config.compilerOptions), {}, {
2896
- // baseUrl in the parent was relative to the *parent*, and readConfig
2897
- // returns it unresolved, so a parent baseUrl with a child that sets none
2898
- // is the one case this gets wrong. Rare enough to name rather than model.
2899
- paths: (_config$compilerOptio4 = (_config$compilerOptio5 = config.compilerOptions) === null || _config$compilerOptio5 === void 0 ? void 0 : _config$compilerOptio5.paths) !== null && _config$compilerOptio4 !== void 0 ? _config$compilerOptio4 : (_parent$compilerOptio = parent.compilerOptions) === null || _parent$compilerOptio === void 0 ? void 0 : _parent$compilerOptio.paths
2900
- })
2901
- };
2902
- }
2903
-
2904
- /** `extends: './base'` may omit the .json. */
2905
- function resolveConfigPath(files, path) {
2906
- for (var _i3 = 0, _arr = [path, "".concat(path, ".json")]; _i3 < _arr.length; _i3++) {
2907
- var candidate = _arr[_i3];
2908
- if (candidate in files) return candidate;
2909
- }
2910
- return null;
3163
+ }, _callee);
3164
+ }));
3165
+ return _transformRouteNodes.apply(this, arguments);
2911
3166
  }
2912
3167
 
2913
3168
  // autoCodeSplitting.
@@ -3976,7 +4231,7 @@ function buildUserApp(_x6) {
3976
4231
  function _buildUserApp() {
3977
4232
  _buildUserApp = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(input) {
3978
4233
  var _input$target$project;
3979
- var warnings, started, rev, clientModules, assetUrls, assetFiles, _i3, _Object$entries3, _input$assets2, _Object$entries3$_i, path, base64, resolved, aliases, css, styles, tailwindMs, compiled, serverStarted, serverBuild, server, clientStarted, clientBuild, client, rscBuild, publicFiles, _i4, _Object$entries4, _input$publicFiles, _Object$entries4$_i, _path, _base, _t, _t2, _t3, _t4, _t5, _t6, _t7, _t8, _t9, _t0, _t1, _t10, _t11, _t12, _t13, _t14, _t15, _t16;
4234
+ var warnings, started, rev, clientModules, assetUrls, assetFiles, _i3, _Object$entries3, _input$assets2, _Object$entries3$_i, path, base64, resolved, aliases, css, styles, tailwindMs, compiled, serverStarted, serverBuild, server, clientStarted, clientBuild, client, hash, registryEntry, rscBuild, publicFiles, _i4, _Object$entries4, _input$publicFiles, _Object$entries4$_i, _path, _base, _t, _t2, _t3, _t4, _t5, _t6, _t7, _t8, _t9, _t0, _t1, _t10, _t11, _t12, _t13, _t14, _t15, _t16;
3980
4235
  return _regenerator().w(function (_context3) {
3981
4236
  while (1) switch (_context3.n) {
3982
4237
  case 0:
@@ -4076,14 +4331,27 @@ function _buildUserApp() {
4076
4331
  return buildOnce(input, "/_vendor/", "/_pvendor/".concat(rev, "/"), "client", warnings, clientModules, false, assetUrls, css.modules, aliases);
4077
4332
  case 12:
4078
4333
  clientBuild = _context3.v;
4079
- client = performance.now() - clientStarted; // Paths are relative to `rsc/app.js`, one directory down, so both layers are
4080
- // addressed with a leading `../`. Getting this wrong does not fail the build;
4081
- // the cold isolate simply refuses to boot.
4334
+ client = performance.now() - clientStarted;
4335
+ /*
4336
+ * The build's `val.modules` registry, as an ES module of its own beside
4337
+ * the client chunks and named after the build: what a Studio opened on an
4338
+ * older build imports to take this one's code in, rather than reloading
4339
+ * the page (`valModulesEntry`). The build's name is a hash of its inputs,
4340
+ * so it is known before anything is emitted.
4341
+ */
4342
+ _context3.n = 13;
4343
+ return buildInputId(input);
4344
+ case 13:
4345
+ hash = _context3.v;
4346
+ _context3.n = 14;
4347
+ return valModulesEntry(input, hash, warnings);
4348
+ case 14:
4349
+ registryEntry = _context3.v;
4082
4350
  if (!input.rsc) {
4083
- _context3.n = 14;
4351
+ _context3.n = 16;
4084
4352
  break;
4085
4353
  }
4086
- _context3.n = 13;
4354
+ _context3.n = 15;
4087
4355
  return buildOnce(
4088
4356
  // `../pvendor/`, with no revision segment: the revision belongs in the
4089
4357
  // browser URL, where it buys immutable caching. Inside the module map
@@ -4091,13 +4359,13 @@ function _buildUserApp() {
4091
4359
  // revision here is a path segment that does not exist -- and the cold
4092
4360
  // isolate is where you would find that out.
4093
4361
  input, "../vendor-rsc/", "../pvendor/", "server", warnings, clientModules, true, assetUrls, css.modules, aliases);
4094
- case 13:
4362
+ case 15:
4095
4363
  _t2 = _context3.v;
4096
- _context3.n = 15;
4364
+ _context3.n = 17;
4097
4365
  break;
4098
- case 14:
4366
+ case 16:
4099
4367
  _t2 = undefined;
4100
- case 15:
4368
+ case 17:
4101
4369
  rscBuild = _t2;
4102
4370
  // Stripped of the `public/` prefix here rather than at every consumer: the
4103
4371
  // prefix is a convention of the project layout, and what the loader needs is
@@ -4110,7 +4378,7 @@ function _buildUserApp() {
4110
4378
  _t3 = serverBuild.code;
4111
4379
  _t4 = clientBuild.code;
4112
4380
  _t5 = serverBuild.chunks;
4113
- _t6 = clientBuild.chunks;
4381
+ _t6 = _objectSpread2(_objectSpread2({}, clientBuild.chunks), registryEntry);
4114
4382
  _t7 = assetFiles;
4115
4383
  _t8 = publicFiles;
4116
4384
  _t9 = styles;
@@ -4121,15 +4389,12 @@ function _buildUserApp() {
4121
4389
  _t10 = rscBuild === null || rscBuild === void 0 ? void 0 : rscBuild.chunks;
4122
4390
  _t11 = input.rsc ? clientModules : undefined;
4123
4391
  _t12 = input.target.base.rev;
4124
- _context3.n = 16;
4125
- return buildInputId(input);
4126
- case 16:
4127
- _t13 = _context3.v;
4128
- _context3.n = 17;
4392
+ _t13 = hash;
4393
+ _context3.n = 18;
4129
4394
  return sha256Hex([input.target.base.rev, rev, styles].concat(_toConsumableArray(Object.entries(assetFiles).flat()), _toConsumableArray(Object.entries(publicFiles).flat()), _toConsumableArray([serverBuild, clientBuild, rscBuild].flatMap(function (built) {
4130
4395
  return built ? [built.code].concat(_toConsumableArray(Object.entries(built.chunks).flat())) : [];
4131
- }))).join("\0"));
4132
- case 17:
4396
+ })), _toConsumableArray(Object.entries(registryEntry).flat())).join("\0"));
4397
+ case 18:
4133
4398
  _t14 = _context3.v.slice(0, 32);
4134
4399
  _t15 = {
4135
4400
  server: server,
@@ -4586,158 +4851,4 @@ function treeShaOfText(files) {
4586
4851
  })));
4587
4852
  }
4588
4853
 
4589
- /**
4590
- * A project's `val.modules.ts`, bundled to run: every `.val.ts` it imports,
4591
- * the `val.config` they share and the `.val.json` entries they name, as ONE
4592
- * ES module -- so it can be imported from a `blob:` URL, which cannot resolve
4593
- * a relative chunk -- with every npm import pointing at the site's own
4594
- * vendor chunks, at absolute URLs under `origin`.
4595
- *
4596
- * What the builder tab evaluates to learn a tree's schemas: Update from the
4597
- * site with code (valbuild/home `docs/hosted-publishing.md` step 8.2, slice
4598
- * 1b). The project's own `@valbuild/*` and dependencies are what run, as the
4599
- * site runs them -- the browser half of its layer, from `/_pvendor/<rev>/`,
4600
- * and the base layer from `/_vendor/`. Whoever imports it should do so off
4601
- * the Studio's page: `@valbuild/tanstack` brings React and patches its JSX.
4602
- *
4603
- * Nothing else of a build happens here: no route splitting, no server
4604
- * functions, no CSS -- a `.val.ts` has none of it.
4605
- */
4606
- function bundleValModules(_x) {
4607
- return _bundleValModules.apply(this, arguments);
4608
- }
4609
- function _bundleValModules() {
4610
- _bundleValModules = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(input) {
4611
- var _input$entry;
4612
- var files, target, origin, entry, warnings, aliases, base, project, resolveProjectPath, _yield$loadRolldown, build, result, chunks, _t;
4613
- return _regenerator().w(function (_context) {
4614
- while (1) switch (_context.p = _context.n) {
4615
- case 0:
4616
- files = input.files, target = input.target, origin = input.origin;
4617
- entry = (_input$entry = input.entry) !== null && _input$entry !== void 0 ? _input$entry : ["val.modules.ts", "val.modules.js"].find(function (path) {
4618
- return path in files;
4619
- });
4620
- if (!(entry === undefined || !(entry in files))) {
4621
- _context.n = 1;
4622
- break;
4623
- }
4624
- throw new Error("This project has no val.modules.ts, so its Val modules cannot be read.");
4625
- case 1:
4626
- warnings = [];
4627
- aliases = aliasMap(files, function (message) {
4628
- return warnings.push(message);
4629
- });
4630
- base = "".concat(origin, "/_vendor/");
4631
- project = target.project.rev === null ? null : "".concat(origin, "/_pvendor/").concat(target.project.rev, "/");
4632
- resolveProjectPath = function resolveProjectPath(path) {
4633
- return resolveInFiles(path, files);
4634
- };
4635
- _context.n = 2;
4636
- return loadRolldown();
4637
- case 2:
4638
- _yield$loadRolldown = _context.v;
4639
- build = _yield$loadRolldown.build;
4640
- _context.p = 3;
4641
- _context.n = 4;
4642
- return build({
4643
- input: entry,
4644
- // See `buildOnce`: required in the browser, inert here.
4645
- cwd: "/",
4646
- moduleTypes: {
4647
- ".css": "empty"
4648
- },
4649
- plugins: [{
4650
- name: "val:modules",
4651
- resolveId: function resolveId(source, importer) {
4652
- if (source.startsWith(".")) {
4653
- return resolveProjectPath(resolve(dirname(importer !== null && importer !== void 0 ? importer : entry), source));
4654
- }
4655
- if (source in files) return source;
4656
- var baseChunk = target.base.modules[source];
4657
- if (baseChunk) {
4658
- return {
4659
- id: "".concat(base).concat(baseChunk, ".js"),
4660
- external: true
4661
- };
4662
- }
4663
- var projectChunk = target.project.modules[source];
4664
- if (projectChunk && project !== null) {
4665
- if (target.project.workerOnly.includes(source)) {
4666
- throw new Error("'".concat(source, "' is server-only in this project's vendor layer, so a .val.ts importing it cannot be read in the browser."));
4667
- }
4668
- return {
4669
- id: "".concat(project).concat(projectChunk, ".js"),
4670
- external: true
4671
- };
4672
- }
4673
- if (aliases) {
4674
- var _iterator = _createForOfIteratorHelper(aliases.candidates(source)),
4675
- _step;
4676
- try {
4677
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
4678
- var candidate = _step.value;
4679
- var _hit = resolveProjectPath(candidate);
4680
- if (_hit) return _hit;
4681
- }
4682
- } catch (err) {
4683
- _iterator.e(err);
4684
- } finally {
4685
- _iterator.f();
4686
- }
4687
- var fromBaseUrl = aliases.baseUrlCandidate(source);
4688
- var hit = fromBaseUrl && resolveProjectPath(fromBaseUrl);
4689
- if (hit) return hit;
4690
- }
4691
- // An error, not a warning: rolldown would otherwise leave the
4692
- // specifier as it is, and it would fail when imported, unnamed.
4693
- throw new Error("'".concat(source, "' is not an available dependency. Available: ").concat([].concat(_toConsumableArray(Object.keys(target.base.modules)), _toConsumableArray(Object.keys(target.project.modules))).join(", "), "."));
4694
- },
4695
- load: function load(id) {
4696
- return id in files ? files[id] : null;
4697
- }
4698
- }],
4699
- transform: {
4700
- jsx: {
4701
- runtime: "automatic",
4702
- importSource: "react"
4703
- }
4704
- },
4705
- output: {
4706
- format: "esm",
4707
- minify: false,
4708
- // One module: `def: () => import("./x.val")` stays a dynamic import of
4709
- // something already in the file.
4710
- codeSplitting: false
4711
- },
4712
- write: false
4713
- });
4714
- case 4:
4715
- result = _context.v;
4716
- _context.n = 6;
4717
- break;
4718
- case 5:
4719
- _context.p = 5;
4720
- _t = _context.v;
4721
- throw new Error(["The Val modules could not be bundled."].concat(warnings, [_t instanceof Error ? _t.message : String(_t)]).join("\n"), {
4722
- cause: _t
4723
- });
4724
- case 6:
4725
- chunks = result.output.filter(function (output) {
4726
- return output.type === "chunk";
4727
- });
4728
- if (!(chunks.length !== 1)) {
4729
- _context.n = 7;
4730
- break;
4731
- }
4732
- throw new Error("Bundling the Val modules made ".concat(chunks.length, " chunks rather than one."));
4733
- case 7:
4734
- return _context.a(2, {
4735
- code: chunks[0].code
4736
- });
4737
- }
4738
- }, _callee, null, [[3, 5]]);
4739
- }));
4740
- return _bundleValModules.apply(this, arguments);
4741
- }
4742
-
4743
4854
  export { ENTRY_CHUNK, PROJECT_SOURCE, PUBLIC_PREFIX, VAL_SERVER_PATH, aliasMap, bakedGit, bakedJob, blobSha, buildInputId, buildUserApp, bundleValModules, fetchBuildTarget, fetchBuildTargetRev, isValProject, isWired, loadRolldown, publishArtifacts, publishPayload, rebakeGit, resolveInFiles, scanCandidates, treeSha, treeShaOfText, useRolldown, usesTailwind, wireUp, wiredValServer, withoutBakedJob };