@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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var regeneratorValues = require('./regeneratorValues-f5d7ce8a.cjs.dev.js');
6
- var projectPaths = require('./projectPaths-f222255a.cjs.dev.js');
6
+ var projectPaths = require('./projectPaths-cb474a60.cjs.dev.js');
7
7
  var tailwindcss = require('tailwindcss');
8
8
  var artifactKeys = require('./artifactKeys-ad3e41fc.cjs.dev.js');
9
9
 
@@ -64,15 +64,40 @@ function useRolldown(rolldown) {
64
64
  */
65
65
  function loadRolldown() {
66
66
  if (chosen === null) {
67
- var loading = Promise.all([Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@rolldown/browser')); }), Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@rolldown/browser/parseAst')); })]).then(function (_ref) {
68
- var _ref2 = regeneratorValues._slicedToArray(_ref, 2),
69
- bundler = _ref2[0],
70
- parser = _ref2[1];
71
- return {
72
- build: bundler.build,
73
- parseAstAsync: parser.parseAstAsync
67
+ /*
68
+ * One after the other, never together. Both import the WASI binding,
69
+ * whose top-level `await` fetches and instantiates the WebAssembly, and
70
+ * Safari (every iPhone browser) can settle the second import of a graph
71
+ * whose shared module is still awaiting before that import's own body
72
+ * has run. `build` is a hoisted function there and `rolldown` a `const`,
73
+ * so the build got a `build` it could call, which threw "Cannot access
74
+ * 'Ha' before initialization." (minified) on its first line -- home's
75
+ * upgrade page, on an iPhone, while Chrome built the same upgrade. Once
76
+ * the bundler has loaded, the binding has finished, and the parser's
77
+ * import has nothing left to wait for.
78
+ */
79
+ var loading = Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@rolldown/browser')); }).then(/*#__PURE__*/function () {
80
+ var _ref = regeneratorValues._asyncToGenerator(/*#__PURE__*/regeneratorValues._regenerator().m(function _callee(bundler) {
81
+ var _t, _t2;
82
+ return regeneratorValues._regenerator().w(function (_context) {
83
+ while (1) switch (_context.n) {
84
+ case 0:
85
+ _t = bundler.build;
86
+ _context.n = 1;
87
+ return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@rolldown/browser/parseAst')); });
88
+ case 1:
89
+ _t2 = _context.v.parseAstAsync;
90
+ return _context.a(2, {
91
+ build: _t,
92
+ parseAstAsync: _t2
93
+ });
94
+ }
95
+ }, _callee);
96
+ }));
97
+ return function (_x) {
98
+ return _ref.apply(this, arguments);
74
99
  };
75
- });
100
+ }());
76
101
  // A load that failed is tried again by the next caller, not kept.
77
102
  loading["catch"](function () {
78
103
  if (chosen === loading) chosen = null;
@@ -1185,7 +1210,7 @@ var packageJson = {
1185
1210
  url: "git+https://github.com/valbuild/val.git"
1186
1211
  },
1187
1212
  license: "MIT",
1188
- version: "0.150.9",
1213
+ version: "0.151.0",
1189
1214
  sideEffects: false,
1190
1215
  main: "dist/valbuild-tanstack-build.cjs.js",
1191
1216
  module: "dist/valbuild-tanstack-build.esm.js",
@@ -1349,7 +1374,14 @@ var LEGACY_CONTROL_HOST = "platform.internal";
1349
1374
  * existed -- which is every project already published, since a build in a tab
1350
1375
  * rewrites single lines of its `val.server.ts` and never regenerates it.
1351
1376
  */
1352
- 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";
1377
+ 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";
1378
+ /**
1379
+ * {@link PROPOSAL_BLOCK} as it was generated before it read which modules
1380
+ * are staged and what the build was made of: rewritten to the current block
1381
+ * by {@link rebakeProposal}, exactly, so a site wired before it learns both
1382
+ * at its next build. Never generated.
1383
+ */
1384
+ 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";
1353
1385
  /**
1354
1386
  * THE CONTENT VERSION the site serves, when it differs from the one this build
1355
1387
  * bundles (\`VAL_CONTENT\`). See valbuild/home \`docs/hosted-publishing.md\`,
@@ -1461,6 +1493,14 @@ function bakedJob(files) {
1461
1493
  * as it is, and serves a proposal's address as its base build.
1462
1494
  */
1463
1495
  function rebakeProposal(source) {
1496
+ // A block from before staged code was read: the current one in its place,
1497
+ // where it is exactly as generated.
1498
+ var at = source.indexOf(PROPOSAL_BLOCK_V1);
1499
+ if (at !== -1 && source.indexOf(PROPOSAL_BLOCK_V1, at + 1) === -1) {
1500
+ return source.replace(PROPOSAL_BLOCK_V1, function () {
1501
+ return PROPOSAL_BLOCK;
1502
+ });
1503
+ }
1464
1504
  if (source.includes("const proposal = (() => {")) return source;
1465
1505
  var once = function once(needle) {
1466
1506
  var at = source.indexOf(needle);
@@ -1870,78 +1910,474 @@ function canonicalJson(value) {
1870
1910
  return JSON.stringify(value);
1871
1911
  }
1872
1912
 
1873
- /** Cheap pre-filter: skip the parse unless one of these appears in the source. */
1874
- var MARKERS = ["createIsomorphicFn", "createServerOnlyFn", "createClientOnlyFn", "createMiddleware", "ClientOnly"];
1875
-
1876
- /** Walks a `foo().bar().baz()` chain down to its root callee identifier. */
1877
- function chainRoot(node) {
1878
- var current = node;
1879
- while (current) {
1880
- if (current.type === "CallExpression") {
1881
- var callee = current.callee;
1882
- if ((callee === null || callee === void 0 ? void 0 : callee.type) === "Identifier") return String(callee.name);
1883
- if ((callee === null || callee === void 0 ? void 0 : callee.type) === "MemberExpression") {
1884
- current = callee.object;
1885
- continue;
1913
+ /**
1914
+ * JSON with comments and trailing commas, which is what tsconfig.json is.
1915
+ *
1916
+ * Written as a scanner rather than a regex on purpose: `"url": "https://x"`
1917
+ * contains `//`, and a regex that strips comments without tracking string state
1918
+ * truncates the file there and throws a parse error pointing at the wrong line.
1919
+ */
1920
+ function parseJsonc(text) {
1921
+ var out = "";
1922
+ var i = 0;
1923
+ while (i < text.length) {
1924
+ var ch = text[i];
1925
+ if (ch === '"') {
1926
+ // Copy the whole string literal, escapes included, untouched.
1927
+ out += ch;
1928
+ i++;
1929
+ while (i < text.length) {
1930
+ var c = text[i];
1931
+ out += c;
1932
+ i++;
1933
+ if (c === "\\") {
1934
+ if (i < text.length) out += text[i++];
1935
+ continue;
1936
+ }
1937
+ if (c === '"') break;
1886
1938
  }
1887
- return null;
1939
+ continue;
1888
1940
  }
1889
- return null;
1941
+ if (ch === "/" && text[i + 1] === "/") {
1942
+ while (i < text.length && text[i] !== "\n") i++;
1943
+ continue;
1944
+ }
1945
+ if (ch === "/" && text[i + 1] === "*") {
1946
+ i += 2;
1947
+ while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) i++;
1948
+ i += 2;
1949
+ continue;
1950
+ }
1951
+ out += ch;
1952
+ i++;
1890
1953
  }
1891
- return null;
1954
+ // Trailing commas, now that every remaining comma is structural.
1955
+ return JSON.parse(out.replace(/,(\s*[}\]])/g, "$1"));
1892
1956
  }
1893
1957
 
1958
+ /** One `paths` entry, pre-split on its wildcard. */
1959
+
1894
1960
  /**
1895
- * True when this call is the whole chain rather than a link in a longer one.
1961
+ * Reads tsconfig.json out of the file record and builds the matcher.
1896
1962
  *
1897
- * Without this, `createIsomorphicFn().client(a).server(b)` matches three times
1898
- * and the inner replacements land inside text the outer one is about to
1899
- * replace.
1963
+ * Returns null when the project configures no aliases, which is the common
1964
+ * case and costs nothing.
1900
1965
  */
1901
- function isOutermost(node, stack) {
1902
- var parent = stack[stack.length - 1];
1903
- var grandparent = stack[stack.length - 2];
1904
- return !((parent === null || parent === void 0 ? void 0 : parent.type) === "MemberExpression" && parent.object === node && (grandparent === null || grandparent === void 0 ? void 0 : grandparent.type) === "CallExpression");
1905
- }
1966
+ function aliasMap(files, warn) {
1967
+ var _config$compilerOptio, _config$compilerOptio2;
1968
+ var entry = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "tsconfig.json";
1969
+ var config = readConfig(files, entry, warn, new Set());
1970
+ var paths = config === null || config === void 0 || (_config$compilerOptio = config.compilerOptions) === null || _config$compilerOptio === void 0 ? void 0 : _config$compilerOptio.paths;
1971
+ var baseUrl = config === null || config === void 0 || (_config$compilerOptio2 = config.compilerOptions) === null || _config$compilerOptio2 === void 0 ? void 0 : _config$compilerOptio2.baseUrl;
1972
+ // A project can configure either one without the other, and baseUrl alone is
1973
+ // enough to change how a bare specifier resolves.
1974
+ if ((!paths || Object.keys(paths).length === 0) && baseUrl === undefined) return null;
1906
1975
 
1907
- /** Collects `.method(arg)` calls along a chain, nearest-root first. */
1908
- function methodsOf(node) {
1909
- var found = new Map();
1910
- var current = node;
1911
- while (((_current = current) === null || _current === void 0 ? void 0 : _current.type) === "CallExpression") {
1912
- var _current, _name, _callee$property, _current$arguments;
1913
- var callee = current.callee;
1914
- if ((callee === null || callee === void 0 ? void 0 : callee.type) !== "MemberExpression") break;
1915
- var name = String((_name = (_callee$property = callee.property) === null || _callee$property === void 0 ? void 0 : _callee$property.name) !== null && _name !== void 0 ? _name : "");
1916
- // Nearest-to-root wins, so a later duplicate does not shadow the first.
1917
- found.set(name, {
1918
- call: current,
1919
- arg: (_current$arguments = current.arguments) === null || _current$arguments === void 0 ? void 0 : _current$arguments[0],
1920
- objectEnd: callee.object.end
1976
+ // `baseUrl` is relative to the tsconfig that declared it. Since TS 4.1 paths
1977
+ // work without one, resolved against the tsconfig's own directory -- so the
1978
+ // fallback here is the directory, not the project root.
1979
+ var base = resolve(dirname(entry), baseUrl !== null && baseUrl !== void 0 ? baseUrl : ".");
1980
+ var patterns = [];
1981
+ for (var _i = 0, _Object$entries = Object.entries(paths !== null && paths !== void 0 ? paths : {}); _i < _Object$entries.length; _i++) {
1982
+ var _Object$entries$_i = regeneratorValues._slicedToArray(_Object$entries[_i], 2),
1983
+ pattern = _Object$entries$_i[0],
1984
+ targets = _Object$entries$_i[1];
1985
+ var star = pattern.indexOf("*");
1986
+ if (star !== pattern.lastIndexOf("*")) {
1987
+ warn("tsconfig paths pattern '".concat(pattern, "' has more than one '*' and is ignored."));
1988
+ continue;
1989
+ }
1990
+ patterns.push({
1991
+ prefix: star === -1 ? pattern : pattern.slice(0, star),
1992
+ suffix: star === -1 ? "" : pattern.slice(star + 1),
1993
+ wildcard: star !== -1,
1994
+ targets: targets.map(function (target) {
1995
+ return resolve(base, target);
1996
+ })
1921
1997
  });
1922
- current = callee.object;
1923
1998
  }
1924
- return found;
1999
+
2000
+ // TypeScript picks the pattern with the longest literal prefix, so `@/ui/*`
2001
+ // beats `@/*` for `@/ui/card` regardless of declaration order.
2002
+ patterns.sort(function (a, b) {
2003
+ return b.prefix.length - a.prefix.length;
2004
+ });
2005
+ return {
2006
+ patterns: Object.keys(paths !== null && paths !== void 0 ? paths : {}),
2007
+ baseUrlCandidate: function baseUrlCandidate(specifier) {
2008
+ return baseUrl === undefined ? null : resolve(base, specifier);
2009
+ },
2010
+ candidates: function candidates(specifier) {
2011
+ var _loop = function _loop() {
2012
+ var pattern = _patterns[_i2];
2013
+ if (!pattern.wildcard) {
2014
+ if (specifier === pattern.prefix) return {
2015
+ v: regeneratorValues._toConsumableArray(pattern.targets)
2016
+ };
2017
+ return 0; // continue
2018
+ }
2019
+ if (!specifier.startsWith(pattern.prefix) || !specifier.endsWith(pattern.suffix) || specifier.length < pattern.prefix.length + pattern.suffix.length) {
2020
+ return 0; // continue
2021
+ }
2022
+ var matched = specifier.slice(pattern.prefix.length, specifier.length - pattern.suffix.length);
2023
+ return {
2024
+ v: pattern.targets.map(function (target) {
2025
+ return target.replace("*", matched);
2026
+ })
2027
+ };
2028
+ },
2029
+ _ret;
2030
+ for (var _i2 = 0, _patterns = patterns; _i2 < _patterns.length; _i2++) {
2031
+ _ret = _loop();
2032
+ if (_ret === 0) continue;
2033
+ if (_ret) return _ret.v;
2034
+ }
2035
+ return [];
2036
+ }
2037
+ };
2038
+ }
2039
+
2040
+ /** Follows `extends` through the file record. Package extends cannot be read. */
2041
+ function readConfig(files, path, warn, seen) {
2042
+ var _config, _config$compilerOptio4, _config$compilerOptio5, _parent$compilerOptio;
2043
+ if (seen.has(path)) return null; // a cycle; whatever we have is enough
2044
+ seen.add(path);
2045
+ var text = files[path];
2046
+ if (text === undefined) return null;
2047
+ var config;
2048
+ try {
2049
+ config = parseJsonc(text);
2050
+ } catch (error) {
2051
+ var _message;
2052
+ warn("Could not parse ".concat(path, ": ").concat(String((_message = error === null || error === void 0 ? void 0 : error.message) !== null && _message !== void 0 ? _message : error)));
2053
+ return null;
2054
+ }
2055
+ if (!((_config = config) !== null && _config !== void 0 && _config["extends"])) return config;
2056
+
2057
+ // Only a relative extends can be followed: a package one ("extends":
2058
+ // "@tsconfig/node20/tsconfig.json") lives in node_modules, which a browser
2059
+ // build does not have. Worth saying out loud rather than silently resolving
2060
+ // half the aliases, because the base config is where a monorepo usually puts
2061
+ // them.
2062
+ if (!config["extends"].startsWith(".")) {
2063
+ var _config$compilerOptio3;
2064
+ if (!((_config$compilerOptio3 = config.compilerOptions) !== null && _config$compilerOptio3 !== void 0 && _config$compilerOptio3.paths)) {
2065
+ 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."));
2066
+ }
2067
+ return config;
2068
+ }
2069
+ var parentPath = resolveConfigPath(files, resolve(dirname(path), config["extends"]));
2070
+ var parent = parentPath ? readConfig(files, parentPath, warn, seen) : null;
2071
+ if (!parent) return config;
2072
+
2073
+ // The child wins, and `paths` replaces rather than merges -- which is what
2074
+ // TypeScript does.
2075
+ return {
2076
+ compilerOptions: regeneratorValues._objectSpread2(regeneratorValues._objectSpread2(regeneratorValues._objectSpread2({}, parent.compilerOptions), config.compilerOptions), {}, {
2077
+ // baseUrl in the parent was relative to the *parent*, and readConfig
2078
+ // returns it unresolved, so a parent baseUrl with a child that sets none
2079
+ // is the one case this gets wrong. Rare enough to name rather than model.
2080
+ 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
2081
+ })
2082
+ };
2083
+ }
2084
+
2085
+ /** `extends: './base'` may omit the .json. */
2086
+ function resolveConfigPath(files, path) {
2087
+ for (var _i3 = 0, _arr = [path, "".concat(path, ".json")]; _i3 < _arr.length; _i3++) {
2088
+ var candidate = _arr[_i3];
2089
+ if (candidate in files) return candidate;
2090
+ }
2091
+ return null;
1925
2092
  }
2093
+
1926
2094
  /**
1927
- * Rewrites the environment markers in one module for one target.
2095
+ * A project's `val.modules.ts`, bundled to run: every `.val.ts` it imports,
2096
+ * the `val.config` they share and the `.val.json` entries they name, as ONE
2097
+ * ES module -- so it can be imported from a `blob:` URL, which cannot resolve
2098
+ * a relative chunk -- with every npm import pointing at the site's own
2099
+ * vendor chunks, at absolute URLs under `origin`.
1928
2100
  *
1929
- * Returns `null` when the module contains none, so the caller leaves it alone
1930
- * and pays no parse.
2101
+ * What the builder tab evaluates to learn a tree's schemas: Update from the
2102
+ * site with code (valbuild/home `docs/hosted-publishing.md` step 8.2, slice
2103
+ * 1b). The project's own `@valbuild/*` and dependencies are what run, as the
2104
+ * site runs them -- the browser half of its layer, from `/_pvendor/<rev>/`,
2105
+ * and the base layer from `/_vendor/`. Whoever imports it should do so off
2106
+ * the Studio's page: `@valbuild/tanstack` brings React and patches its JSX.
2107
+ *
2108
+ * Nothing else of a build happens here: no route splitting, no server
2109
+ * functions, no CSS -- a `.val.ts` has none of it.
1931
2110
  */
1932
- function transformEnvMarkers(_x, _x2, _x3) {
1933
- return _transformEnvMarkers.apply(this, arguments);
2111
+ function bundleValModules(_x) {
2112
+ return _bundleValModules.apply(this, arguments);
1934
2113
  }
1935
- function _transformEnvMarkers() {
1936
- _transformEnvMarkers = regeneratorValues._asyncToGenerator(/*#__PURE__*/regeneratorValues._regenerator().m(function _callee(moduleId, code, target) {
1937
- var ast, imported, edits, applied, text;
1938
- return regeneratorValues._regenerator().w(function (_context) {
1939
- while (1) switch (_context.n) {
1940
- case 0:
1941
- if (MARKERS.some(function (marker) {
1942
- return code.includes(marker);
1943
- })) {
1944
- _context.n = 1;
2114
+
2115
+ /**
2116
+ * A build's `val.modules` registry, as the build emits it beside its client
2117
+ * chunks: `{ "val-modules-<build>.js": code }`, served at `/_app/` with
2118
+ * them, its npm imports pointing at the site's vendor chunks on its own
2119
+ * origin (`/_vendor/`, `/_pvendor/<rev>/`) as the client bundle's do.
2120
+ *
2121
+ * What a Studio opened on an older build imports, once the server's
2122
+ * manifest names it (`registry`, from the build's name the platform hands
2123
+ * the server: `VAL_BUILD`), to take this build's schemas in WITHOUT
2124
+ * reloading the page: `HostStore.reloadCode` in `@valbuild/ui`, and phase 9
2125
+ * of `docs/plans/one-content-model.md` in valbuild/val.
2126
+ *
2127
+ * Empty -- and the build goes on -- for a project with no `val.modules.ts`,
2128
+ * or one whose Val modules cannot be bundled for the browser (a `.val.ts`
2129
+ * importing something server-only): such a build has no entry, and a Studio
2130
+ * that cannot import one reloads the page instead, as it did before. Said
2131
+ * in the build's warnings.
2132
+ */
2133
+ function _bundleValModules() {
2134
+ _bundleValModules = regeneratorValues._asyncToGenerator(/*#__PURE__*/regeneratorValues._regenerator().m(function _callee(input) {
2135
+ var _input$entry;
2136
+ var files, target, origin, entry, warnings, aliases, base, project, resolveProjectPath, _yield$loadRolldown, build, result, chunks, _t;
2137
+ return regeneratorValues._regenerator().w(function (_context) {
2138
+ while (1) switch (_context.p = _context.n) {
2139
+ case 0:
2140
+ files = input.files, target = input.target, origin = input.origin;
2141
+ entry = (_input$entry = input.entry) !== null && _input$entry !== void 0 ? _input$entry : ["val.modules.ts", "val.modules.js"].find(function (path) {
2142
+ return path in files;
2143
+ });
2144
+ if (!(entry === undefined || !(entry in files))) {
2145
+ _context.n = 1;
2146
+ break;
2147
+ }
2148
+ throw new Error("This project has no val.modules.ts, so its Val modules cannot be read.");
2149
+ case 1:
2150
+ warnings = [];
2151
+ aliases = aliasMap(files, function (message) {
2152
+ return warnings.push(message);
2153
+ });
2154
+ base = "".concat(origin, "/_vendor/");
2155
+ project = target.project.rev === null ? null : "".concat(origin, "/_pvendor/").concat(target.project.rev, "/");
2156
+ resolveProjectPath = function resolveProjectPath(path) {
2157
+ return resolveInFiles(path, files);
2158
+ };
2159
+ _context.n = 2;
2160
+ return loadRolldown();
2161
+ case 2:
2162
+ _yield$loadRolldown = _context.v;
2163
+ build = _yield$loadRolldown.build;
2164
+ _context.p = 3;
2165
+ _context.n = 4;
2166
+ return build({
2167
+ input: entry,
2168
+ // See `buildOnce`: required in the browser, inert here.
2169
+ cwd: "/",
2170
+ moduleTypes: {
2171
+ ".css": "empty"
2172
+ },
2173
+ plugins: [{
2174
+ name: "val:modules",
2175
+ resolveId: function resolveId(source, importer) {
2176
+ if (source.startsWith(".")) {
2177
+ return resolveProjectPath(resolve(dirname(importer !== null && importer !== void 0 ? importer : entry), source));
2178
+ }
2179
+ if (source in files) return source;
2180
+ var baseChunk = target.base.modules[source];
2181
+ if (baseChunk) {
2182
+ return {
2183
+ id: "".concat(base).concat(baseChunk, ".js"),
2184
+ external: true
2185
+ };
2186
+ }
2187
+ var projectChunk = target.project.modules[source];
2188
+ if (projectChunk && project !== null) {
2189
+ if (target.project.workerOnly.includes(source)) {
2190
+ 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."));
2191
+ }
2192
+ return {
2193
+ id: "".concat(project).concat(projectChunk, ".js"),
2194
+ external: true
2195
+ };
2196
+ }
2197
+ if (aliases) {
2198
+ var _iterator = regeneratorValues._createForOfIteratorHelper(aliases.candidates(source)),
2199
+ _step;
2200
+ try {
2201
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
2202
+ var candidate = _step.value;
2203
+ var _hit = resolveProjectPath(candidate);
2204
+ if (_hit) return _hit;
2205
+ }
2206
+ } catch (err) {
2207
+ _iterator.e(err);
2208
+ } finally {
2209
+ _iterator.f();
2210
+ }
2211
+ var fromBaseUrl = aliases.baseUrlCandidate(source);
2212
+ var hit = fromBaseUrl && resolveProjectPath(fromBaseUrl);
2213
+ if (hit) return hit;
2214
+ }
2215
+ // An error, not a warning: rolldown would otherwise leave the
2216
+ // specifier as it is, and it would fail when imported, unnamed.
2217
+ throw new Error("'".concat(source, "' is not an available dependency. Available: ").concat([].concat(regeneratorValues._toConsumableArray(Object.keys(target.base.modules)), regeneratorValues._toConsumableArray(Object.keys(target.project.modules))).join(", "), "."));
2218
+ },
2219
+ load: function load(id) {
2220
+ return id in files ? files[id] : null;
2221
+ }
2222
+ }],
2223
+ transform: {
2224
+ jsx: {
2225
+ runtime: "automatic",
2226
+ importSource: "react"
2227
+ }
2228
+ },
2229
+ output: {
2230
+ format: "esm",
2231
+ minify: false,
2232
+ // One module: `def: () => import("./x.val")` stays a dynamic import of
2233
+ // something already in the file.
2234
+ codeSplitting: false
2235
+ },
2236
+ write: false
2237
+ });
2238
+ case 4:
2239
+ result = _context.v;
2240
+ _context.n = 6;
2241
+ break;
2242
+ case 5:
2243
+ _context.p = 5;
2244
+ _t = _context.v;
2245
+ throw new Error(["The Val modules could not be bundled."].concat(warnings, [_t instanceof Error ? _t.message : String(_t)]).join("\n"), {
2246
+ cause: _t
2247
+ });
2248
+ case 6:
2249
+ chunks = result.output.filter(function (output) {
2250
+ return output.type === "chunk";
2251
+ });
2252
+ if (!(chunks.length !== 1)) {
2253
+ _context.n = 7;
2254
+ break;
2255
+ }
2256
+ throw new Error("Bundling the Val modules made ".concat(chunks.length, " chunks rather than one."));
2257
+ case 7:
2258
+ return _context.a(2, {
2259
+ code: chunks[0].code
2260
+ });
2261
+ }
2262
+ }, _callee, null, [[3, 5]]);
2263
+ }));
2264
+ return _bundleValModules.apply(this, arguments);
2265
+ }
2266
+ function valModulesEntry(_x2, _x3, _x4) {
2267
+ return _valModulesEntry.apply(this, arguments);
2268
+ }
2269
+ function _valModulesEntry() {
2270
+ _valModulesEntry = regeneratorValues._asyncToGenerator(/*#__PURE__*/regeneratorValues._regenerator().m(function _callee2(input, build, warnings) {
2271
+ var entry, _yield$bundleValModul, code, _t2;
2272
+ return regeneratorValues._regenerator().w(function (_context2) {
2273
+ while (1) switch (_context2.p = _context2.n) {
2274
+ case 0:
2275
+ entry = ["val.modules.ts", "val.modules.js"].find(function (path) {
2276
+ return path in input.files;
2277
+ });
2278
+ if (!(entry === undefined)) {
2279
+ _context2.n = 1;
2280
+ break;
2281
+ }
2282
+ return _context2.a(2, {});
2283
+ case 1:
2284
+ _context2.p = 1;
2285
+ _context2.n = 2;
2286
+ return bundleValModules({
2287
+ files: input.files,
2288
+ target: input.target,
2289
+ // Root-relative, as the client bundle names its vendor chunks: the
2290
+ // entry is served on the site's own origin.
2291
+ origin: "",
2292
+ entry: entry
2293
+ });
2294
+ case 2:
2295
+ _yield$bundleValModul = _context2.v;
2296
+ code = _yield$bundleValModul.code;
2297
+ return _context2.a(2, regeneratorValues._defineProperty({}, projectPaths.valModulesEntryFile(build), code));
2298
+ case 3:
2299
+ _context2.p = 3;
2300
+ _t2 = _context2.v;
2301
+ 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)));
2302
+ return _context2.a(2, {});
2303
+ }
2304
+ }, _callee2, null, [[1, 3]]);
2305
+ }));
2306
+ return _valModulesEntry.apply(this, arguments);
2307
+ }
2308
+
2309
+ /** Cheap pre-filter: skip the parse unless one of these appears in the source. */
2310
+ var MARKERS = ["createIsomorphicFn", "createServerOnlyFn", "createClientOnlyFn", "createMiddleware", "ClientOnly"];
2311
+
2312
+ /** Walks a `foo().bar().baz()` chain down to its root callee identifier. */
2313
+ function chainRoot(node) {
2314
+ var current = node;
2315
+ while (current) {
2316
+ if (current.type === "CallExpression") {
2317
+ var callee = current.callee;
2318
+ if ((callee === null || callee === void 0 ? void 0 : callee.type) === "Identifier") return String(callee.name);
2319
+ if ((callee === null || callee === void 0 ? void 0 : callee.type) === "MemberExpression") {
2320
+ current = callee.object;
2321
+ continue;
2322
+ }
2323
+ return null;
2324
+ }
2325
+ return null;
2326
+ }
2327
+ return null;
2328
+ }
2329
+
2330
+ /**
2331
+ * True when this call is the whole chain rather than a link in a longer one.
2332
+ *
2333
+ * Without this, `createIsomorphicFn().client(a).server(b)` matches three times
2334
+ * and the inner replacements land inside text the outer one is about to
2335
+ * replace.
2336
+ */
2337
+ function isOutermost(node, stack) {
2338
+ var parent = stack[stack.length - 1];
2339
+ var grandparent = stack[stack.length - 2];
2340
+ return !((parent === null || parent === void 0 ? void 0 : parent.type) === "MemberExpression" && parent.object === node && (grandparent === null || grandparent === void 0 ? void 0 : grandparent.type) === "CallExpression");
2341
+ }
2342
+
2343
+ /** Collects `.method(arg)` calls along a chain, nearest-root first. */
2344
+ function methodsOf(node) {
2345
+ var found = new Map();
2346
+ var current = node;
2347
+ while (((_current = current) === null || _current === void 0 ? void 0 : _current.type) === "CallExpression") {
2348
+ var _current, _name, _callee$property, _current$arguments;
2349
+ var callee = current.callee;
2350
+ if ((callee === null || callee === void 0 ? void 0 : callee.type) !== "MemberExpression") break;
2351
+ var name = String((_name = (_callee$property = callee.property) === null || _callee$property === void 0 ? void 0 : _callee$property.name) !== null && _name !== void 0 ? _name : "");
2352
+ // Nearest-to-root wins, so a later duplicate does not shadow the first.
2353
+ found.set(name, {
2354
+ call: current,
2355
+ arg: (_current$arguments = current.arguments) === null || _current$arguments === void 0 ? void 0 : _current$arguments[0],
2356
+ objectEnd: callee.object.end
2357
+ });
2358
+ current = callee.object;
2359
+ }
2360
+ return found;
2361
+ }
2362
+ /**
2363
+ * Rewrites the environment markers in one module for one target.
2364
+ *
2365
+ * Returns `null` when the module contains none, so the caller leaves it alone
2366
+ * and pays no parse.
2367
+ */
2368
+ function transformEnvMarkers(_x, _x2, _x3) {
2369
+ return _transformEnvMarkers.apply(this, arguments);
2370
+ }
2371
+ function _transformEnvMarkers() {
2372
+ _transformEnvMarkers = regeneratorValues._asyncToGenerator(/*#__PURE__*/regeneratorValues._regenerator().m(function _callee(moduleId, code, target) {
2373
+ var ast, imported, edits, applied, text;
2374
+ return regeneratorValues._regenerator().w(function (_context) {
2375
+ while (1) switch (_context.n) {
2376
+ case 0:
2377
+ if (MARKERS.some(function (marker) {
2378
+ return code.includes(marker);
2379
+ })) {
2380
+ _context.n = 1;
1945
2381
  break;
1946
2382
  }
1947
2383
  return _context.a(2, null);
@@ -2731,202 +3167,21 @@ function _transformRouteNodes() {
2731
3167
  _iterator.f();
2732
3168
  }
2733
3169
  if (doomed.size) edits.push.apply(edits, regeneratorValues._toConsumableArray(deleteProperties(code, properties, doomed)));
2734
- });
2735
- if (!(edits.length === 0)) {
2736
- _context.n = 5;
2737
- break;
2738
- }
2739
- return _context.a(2, null);
2740
- case 5:
2741
- return _context.a(2, {
2742
- code: applyEdits(code, edits),
2743
- removed: removed
2744
- });
2745
- }
2746
- }, _callee);
2747
- }));
2748
- return _transformRouteNodes.apply(this, arguments);
2749
- }
2750
-
2751
- /**
2752
- * JSON with comments and trailing commas, which is what tsconfig.json is.
2753
- *
2754
- * Written as a scanner rather than a regex on purpose: `"url": "https://x"`
2755
- * contains `//`, and a regex that strips comments without tracking string state
2756
- * truncates the file there and throws a parse error pointing at the wrong line.
2757
- */
2758
- function parseJsonc(text) {
2759
- var out = "";
2760
- var i = 0;
2761
- while (i < text.length) {
2762
- var ch = text[i];
2763
- if (ch === '"') {
2764
- // Copy the whole string literal, escapes included, untouched.
2765
- out += ch;
2766
- i++;
2767
- while (i < text.length) {
2768
- var c = text[i];
2769
- out += c;
2770
- i++;
2771
- if (c === "\\") {
2772
- if (i < text.length) out += text[i++];
2773
- continue;
2774
- }
2775
- if (c === '"') break;
2776
- }
2777
- continue;
2778
- }
2779
- if (ch === "/" && text[i + 1] === "/") {
2780
- while (i < text.length && text[i] !== "\n") i++;
2781
- continue;
2782
- }
2783
- if (ch === "/" && text[i + 1] === "*") {
2784
- i += 2;
2785
- while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) i++;
2786
- i += 2;
2787
- continue;
2788
- }
2789
- out += ch;
2790
- i++;
2791
- }
2792
- // Trailing commas, now that every remaining comma is structural.
2793
- return JSON.parse(out.replace(/,(\s*[}\]])/g, "$1"));
2794
- }
2795
-
2796
- /** One `paths` entry, pre-split on its wildcard. */
2797
-
2798
- /**
2799
- * Reads tsconfig.json out of the file record and builds the matcher.
2800
- *
2801
- * Returns null when the project configures no aliases, which is the common
2802
- * case and costs nothing.
2803
- */
2804
- function aliasMap(files, warn) {
2805
- var _config$compilerOptio, _config$compilerOptio2;
2806
- var entry = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "tsconfig.json";
2807
- var config = readConfig(files, entry, warn, new Set());
2808
- var paths = config === null || config === void 0 || (_config$compilerOptio = config.compilerOptions) === null || _config$compilerOptio === void 0 ? void 0 : _config$compilerOptio.paths;
2809
- var baseUrl = config === null || config === void 0 || (_config$compilerOptio2 = config.compilerOptions) === null || _config$compilerOptio2 === void 0 ? void 0 : _config$compilerOptio2.baseUrl;
2810
- // A project can configure either one without the other, and baseUrl alone is
2811
- // enough to change how a bare specifier resolves.
2812
- if ((!paths || Object.keys(paths).length === 0) && baseUrl === undefined) return null;
2813
-
2814
- // `baseUrl` is relative to the tsconfig that declared it. Since TS 4.1 paths
2815
- // work without one, resolved against the tsconfig's own directory -- so the
2816
- // fallback here is the directory, not the project root.
2817
- var base = resolve(dirname(entry), baseUrl !== null && baseUrl !== void 0 ? baseUrl : ".");
2818
- var patterns = [];
2819
- for (var _i = 0, _Object$entries = Object.entries(paths !== null && paths !== void 0 ? paths : {}); _i < _Object$entries.length; _i++) {
2820
- var _Object$entries$_i = regeneratorValues._slicedToArray(_Object$entries[_i], 2),
2821
- pattern = _Object$entries$_i[0],
2822
- targets = _Object$entries$_i[1];
2823
- var star = pattern.indexOf("*");
2824
- if (star !== pattern.lastIndexOf("*")) {
2825
- warn("tsconfig paths pattern '".concat(pattern, "' has more than one '*' and is ignored."));
2826
- continue;
2827
- }
2828
- patterns.push({
2829
- prefix: star === -1 ? pattern : pattern.slice(0, star),
2830
- suffix: star === -1 ? "" : pattern.slice(star + 1),
2831
- wildcard: star !== -1,
2832
- targets: targets.map(function (target) {
2833
- return resolve(base, target);
2834
- })
2835
- });
2836
- }
2837
-
2838
- // TypeScript picks the pattern with the longest literal prefix, so `@/ui/*`
2839
- // beats `@/*` for `@/ui/card` regardless of declaration order.
2840
- patterns.sort(function (a, b) {
2841
- return b.prefix.length - a.prefix.length;
2842
- });
2843
- return {
2844
- patterns: Object.keys(paths !== null && paths !== void 0 ? paths : {}),
2845
- baseUrlCandidate: function baseUrlCandidate(specifier) {
2846
- return baseUrl === undefined ? null : resolve(base, specifier);
2847
- },
2848
- candidates: function candidates(specifier) {
2849
- var _loop = function _loop() {
2850
- var pattern = _patterns[_i2];
2851
- if (!pattern.wildcard) {
2852
- if (specifier === pattern.prefix) return {
2853
- v: regeneratorValues._toConsumableArray(pattern.targets)
2854
- };
2855
- return 0; // continue
2856
- }
2857
- if (!specifier.startsWith(pattern.prefix) || !specifier.endsWith(pattern.suffix) || specifier.length < pattern.prefix.length + pattern.suffix.length) {
2858
- return 0; // continue
3170
+ });
3171
+ if (!(edits.length === 0)) {
3172
+ _context.n = 5;
3173
+ break;
2859
3174
  }
2860
- var matched = specifier.slice(pattern.prefix.length, specifier.length - pattern.suffix.length);
2861
- return {
2862
- v: pattern.targets.map(function (target) {
2863
- return target.replace("*", matched);
2864
- })
2865
- };
2866
- },
2867
- _ret;
2868
- for (var _i2 = 0, _patterns = patterns; _i2 < _patterns.length; _i2++) {
2869
- _ret = _loop();
2870
- if (_ret === 0) continue;
2871
- if (_ret) return _ret.v;
3175
+ return _context.a(2, null);
3176
+ case 5:
3177
+ return _context.a(2, {
3178
+ code: applyEdits(code, edits),
3179
+ removed: removed
3180
+ });
2872
3181
  }
2873
- return [];
2874
- }
2875
- };
2876
- }
2877
-
2878
- /** Follows `extends` through the file record. Package extends cannot be read. */
2879
- function readConfig(files, path, warn, seen) {
2880
- var _config, _config$compilerOptio4, _config$compilerOptio5, _parent$compilerOptio;
2881
- if (seen.has(path)) return null; // a cycle; whatever we have is enough
2882
- seen.add(path);
2883
- var text = files[path];
2884
- if (text === undefined) return null;
2885
- var config;
2886
- try {
2887
- config = parseJsonc(text);
2888
- } catch (error) {
2889
- var _message;
2890
- warn("Could not parse ".concat(path, ": ").concat(String((_message = error === null || error === void 0 ? void 0 : error.message) !== null && _message !== void 0 ? _message : error)));
2891
- return null;
2892
- }
2893
- if (!((_config = config) !== null && _config !== void 0 && _config["extends"])) return config;
2894
-
2895
- // Only a relative extends can be followed: a package one ("extends":
2896
- // "@tsconfig/node20/tsconfig.json") lives in node_modules, which a browser
2897
- // build does not have. Worth saying out loud rather than silently resolving
2898
- // half the aliases, because the base config is where a monorepo usually puts
2899
- // them.
2900
- if (!config["extends"].startsWith(".")) {
2901
- var _config$compilerOptio3;
2902
- if (!((_config$compilerOptio3 = config.compilerOptions) !== null && _config$compilerOptio3 !== void 0 && _config$compilerOptio3.paths)) {
2903
- 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."));
2904
- }
2905
- return config;
2906
- }
2907
- var parentPath = resolveConfigPath(files, resolve(dirname(path), config["extends"]));
2908
- var parent = parentPath ? readConfig(files, parentPath, warn, seen) : null;
2909
- if (!parent) return config;
2910
-
2911
- // The child wins, and `paths` replaces rather than merges -- which is what
2912
- // TypeScript does.
2913
- return {
2914
- compilerOptions: regeneratorValues._objectSpread2(regeneratorValues._objectSpread2(regeneratorValues._objectSpread2({}, parent.compilerOptions), config.compilerOptions), {}, {
2915
- // baseUrl in the parent was relative to the *parent*, and readConfig
2916
- // returns it unresolved, so a parent baseUrl with a child that sets none
2917
- // is the one case this gets wrong. Rare enough to name rather than model.
2918
- 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
2919
- })
2920
- };
2921
- }
2922
-
2923
- /** `extends: './base'` may omit the .json. */
2924
- function resolveConfigPath(files, path) {
2925
- for (var _i3 = 0, _arr = [path, "".concat(path, ".json")]; _i3 < _arr.length; _i3++) {
2926
- var candidate = _arr[_i3];
2927
- if (candidate in files) return candidate;
2928
- }
2929
- return null;
3182
+ }, _callee);
3183
+ }));
3184
+ return _transformRouteNodes.apply(this, arguments);
2930
3185
  }
2931
3186
 
2932
3187
  // autoCodeSplitting.
@@ -3995,7 +4250,7 @@ function buildUserApp(_x6) {
3995
4250
  function _buildUserApp() {
3996
4251
  _buildUserApp = regeneratorValues._asyncToGenerator(/*#__PURE__*/regeneratorValues._regenerator().m(function _callee3(input) {
3997
4252
  var _input$target$project;
3998
- 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;
4253
+ 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;
3999
4254
  return regeneratorValues._regenerator().w(function (_context3) {
4000
4255
  while (1) switch (_context3.n) {
4001
4256
  case 0:
@@ -4095,14 +4350,27 @@ function _buildUserApp() {
4095
4350
  return buildOnce(input, "/_vendor/", "/_pvendor/".concat(rev, "/"), "client", warnings, clientModules, false, assetUrls, css.modules, aliases);
4096
4351
  case 12:
4097
4352
  clientBuild = _context3.v;
4098
- client = performance.now() - clientStarted; // Paths are relative to `rsc/app.js`, one directory down, so both layers are
4099
- // addressed with a leading `../`. Getting this wrong does not fail the build;
4100
- // the cold isolate simply refuses to boot.
4353
+ client = performance.now() - clientStarted;
4354
+ /*
4355
+ * The build's `val.modules` registry, as an ES module of its own beside
4356
+ * the client chunks and named after the build: what a Studio opened on an
4357
+ * older build imports to take this one's code in, rather than reloading
4358
+ * the page (`valModulesEntry`). The build's name is a hash of its inputs,
4359
+ * so it is known before anything is emitted.
4360
+ */
4361
+ _context3.n = 13;
4362
+ return buildInputId(input);
4363
+ case 13:
4364
+ hash = _context3.v;
4365
+ _context3.n = 14;
4366
+ return valModulesEntry(input, hash, warnings);
4367
+ case 14:
4368
+ registryEntry = _context3.v;
4101
4369
  if (!input.rsc) {
4102
- _context3.n = 14;
4370
+ _context3.n = 16;
4103
4371
  break;
4104
4372
  }
4105
- _context3.n = 13;
4373
+ _context3.n = 15;
4106
4374
  return buildOnce(
4107
4375
  // `../pvendor/`, with no revision segment: the revision belongs in the
4108
4376
  // browser URL, where it buys immutable caching. Inside the module map
@@ -4110,13 +4378,13 @@ function _buildUserApp() {
4110
4378
  // revision here is a path segment that does not exist -- and the cold
4111
4379
  // isolate is where you would find that out.
4112
4380
  input, "../vendor-rsc/", "../pvendor/", "server", warnings, clientModules, true, assetUrls, css.modules, aliases);
4113
- case 13:
4381
+ case 15:
4114
4382
  _t2 = _context3.v;
4115
- _context3.n = 15;
4383
+ _context3.n = 17;
4116
4384
  break;
4117
- case 14:
4385
+ case 16:
4118
4386
  _t2 = undefined;
4119
- case 15:
4387
+ case 17:
4120
4388
  rscBuild = _t2;
4121
4389
  // Stripped of the `public/` prefix here rather than at every consumer: the
4122
4390
  // prefix is a convention of the project layout, and what the loader needs is
@@ -4129,7 +4397,7 @@ function _buildUserApp() {
4129
4397
  _t3 = serverBuild.code;
4130
4398
  _t4 = clientBuild.code;
4131
4399
  _t5 = serverBuild.chunks;
4132
- _t6 = clientBuild.chunks;
4400
+ _t6 = regeneratorValues._objectSpread2(regeneratorValues._objectSpread2({}, clientBuild.chunks), registryEntry);
4133
4401
  _t7 = assetFiles;
4134
4402
  _t8 = publicFiles;
4135
4403
  _t9 = styles;
@@ -4140,15 +4408,12 @@ function _buildUserApp() {
4140
4408
  _t10 = rscBuild === null || rscBuild === void 0 ? void 0 : rscBuild.chunks;
4141
4409
  _t11 = input.rsc ? clientModules : undefined;
4142
4410
  _t12 = input.target.base.rev;
4143
- _context3.n = 16;
4144
- return buildInputId(input);
4145
- case 16:
4146
- _t13 = _context3.v;
4147
- _context3.n = 17;
4411
+ _t13 = hash;
4412
+ _context3.n = 18;
4148
4413
  return regeneratorValues.sha256Hex([input.target.base.rev, rev, styles].concat(regeneratorValues._toConsumableArray(Object.entries(assetFiles).flat()), regeneratorValues._toConsumableArray(Object.entries(publicFiles).flat()), regeneratorValues._toConsumableArray([serverBuild, clientBuild, rscBuild].flatMap(function (built) {
4149
4414
  return built ? [built.code].concat(regeneratorValues._toConsumableArray(Object.entries(built.chunks).flat())) : [];
4150
- }))).join("\0"));
4151
- case 17:
4415
+ })), regeneratorValues._toConsumableArray(Object.entries(registryEntry).flat())).join("\0"));
4416
+ case 18:
4152
4417
  _t14 = _context3.v.slice(0, 32);
4153
4418
  _t15 = {
4154
4419
  server: server,
@@ -4605,160 +4870,6 @@ function treeShaOfText(files) {
4605
4870
  })));
4606
4871
  }
4607
4872
 
4608
- /**
4609
- * A project's `val.modules.ts`, bundled to run: every `.val.ts` it imports,
4610
- * the `val.config` they share and the `.val.json` entries they name, as ONE
4611
- * ES module -- so it can be imported from a `blob:` URL, which cannot resolve
4612
- * a relative chunk -- with every npm import pointing at the site's own
4613
- * vendor chunks, at absolute URLs under `origin`.
4614
- *
4615
- * What the builder tab evaluates to learn a tree's schemas: Update from the
4616
- * site with code (valbuild/home `docs/hosted-publishing.md` step 8.2, slice
4617
- * 1b). The project's own `@valbuild/*` and dependencies are what run, as the
4618
- * site runs them -- the browser half of its layer, from `/_pvendor/<rev>/`,
4619
- * and the base layer from `/_vendor/`. Whoever imports it should do so off
4620
- * the Studio's page: `@valbuild/tanstack` brings React and patches its JSX.
4621
- *
4622
- * Nothing else of a build happens here: no route splitting, no server
4623
- * functions, no CSS -- a `.val.ts` has none of it.
4624
- */
4625
- function bundleValModules(_x) {
4626
- return _bundleValModules.apply(this, arguments);
4627
- }
4628
- function _bundleValModules() {
4629
- _bundleValModules = regeneratorValues._asyncToGenerator(/*#__PURE__*/regeneratorValues._regenerator().m(function _callee(input) {
4630
- var _input$entry;
4631
- var files, target, origin, entry, warnings, aliases, base, project, resolveProjectPath, _yield$loadRolldown, build, result, chunks, _t;
4632
- return regeneratorValues._regenerator().w(function (_context) {
4633
- while (1) switch (_context.p = _context.n) {
4634
- case 0:
4635
- files = input.files, target = input.target, origin = input.origin;
4636
- entry = (_input$entry = input.entry) !== null && _input$entry !== void 0 ? _input$entry : ["val.modules.ts", "val.modules.js"].find(function (path) {
4637
- return path in files;
4638
- });
4639
- if (!(entry === undefined || !(entry in files))) {
4640
- _context.n = 1;
4641
- break;
4642
- }
4643
- throw new Error("This project has no val.modules.ts, so its Val modules cannot be read.");
4644
- case 1:
4645
- warnings = [];
4646
- aliases = aliasMap(files, function (message) {
4647
- return warnings.push(message);
4648
- });
4649
- base = "".concat(origin, "/_vendor/");
4650
- project = target.project.rev === null ? null : "".concat(origin, "/_pvendor/").concat(target.project.rev, "/");
4651
- resolveProjectPath = function resolveProjectPath(path) {
4652
- return resolveInFiles(path, files);
4653
- };
4654
- _context.n = 2;
4655
- return loadRolldown();
4656
- case 2:
4657
- _yield$loadRolldown = _context.v;
4658
- build = _yield$loadRolldown.build;
4659
- _context.p = 3;
4660
- _context.n = 4;
4661
- return build({
4662
- input: entry,
4663
- // See `buildOnce`: required in the browser, inert here.
4664
- cwd: "/",
4665
- moduleTypes: {
4666
- ".css": "empty"
4667
- },
4668
- plugins: [{
4669
- name: "val:modules",
4670
- resolveId: function resolveId(source, importer) {
4671
- if (source.startsWith(".")) {
4672
- return resolveProjectPath(resolve(dirname(importer !== null && importer !== void 0 ? importer : entry), source));
4673
- }
4674
- if (source in files) return source;
4675
- var baseChunk = target.base.modules[source];
4676
- if (baseChunk) {
4677
- return {
4678
- id: "".concat(base).concat(baseChunk, ".js"),
4679
- external: true
4680
- };
4681
- }
4682
- var projectChunk = target.project.modules[source];
4683
- if (projectChunk && project !== null) {
4684
- if (target.project.workerOnly.includes(source)) {
4685
- 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."));
4686
- }
4687
- return {
4688
- id: "".concat(project).concat(projectChunk, ".js"),
4689
- external: true
4690
- };
4691
- }
4692
- if (aliases) {
4693
- var _iterator = regeneratorValues._createForOfIteratorHelper(aliases.candidates(source)),
4694
- _step;
4695
- try {
4696
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
4697
- var candidate = _step.value;
4698
- var _hit = resolveProjectPath(candidate);
4699
- if (_hit) return _hit;
4700
- }
4701
- } catch (err) {
4702
- _iterator.e(err);
4703
- } finally {
4704
- _iterator.f();
4705
- }
4706
- var fromBaseUrl = aliases.baseUrlCandidate(source);
4707
- var hit = fromBaseUrl && resolveProjectPath(fromBaseUrl);
4708
- if (hit) return hit;
4709
- }
4710
- // An error, not a warning: rolldown would otherwise leave the
4711
- // specifier as it is, and it would fail when imported, unnamed.
4712
- throw new Error("'".concat(source, "' is not an available dependency. Available: ").concat([].concat(regeneratorValues._toConsumableArray(Object.keys(target.base.modules)), regeneratorValues._toConsumableArray(Object.keys(target.project.modules))).join(", "), "."));
4713
- },
4714
- load: function load(id) {
4715
- return id in files ? files[id] : null;
4716
- }
4717
- }],
4718
- transform: {
4719
- jsx: {
4720
- runtime: "automatic",
4721
- importSource: "react"
4722
- }
4723
- },
4724
- output: {
4725
- format: "esm",
4726
- minify: false,
4727
- // One module: `def: () => import("./x.val")` stays a dynamic import of
4728
- // something already in the file.
4729
- codeSplitting: false
4730
- },
4731
- write: false
4732
- });
4733
- case 4:
4734
- result = _context.v;
4735
- _context.n = 6;
4736
- break;
4737
- case 5:
4738
- _context.p = 5;
4739
- _t = _context.v;
4740
- throw new Error(["The Val modules could not be bundled."].concat(warnings, [_t instanceof Error ? _t.message : String(_t)]).join("\n"), {
4741
- cause: _t
4742
- });
4743
- case 6:
4744
- chunks = result.output.filter(function (output) {
4745
- return output.type === "chunk";
4746
- });
4747
- if (!(chunks.length !== 1)) {
4748
- _context.n = 7;
4749
- break;
4750
- }
4751
- throw new Error("Bundling the Val modules made ".concat(chunks.length, " chunks rather than one."));
4752
- case 7:
4753
- return _context.a(2, {
4754
- code: chunks[0].code
4755
- });
4756
- }
4757
- }, _callee, null, [[3, 5]]);
4758
- }));
4759
- return _bundleValModules.apply(this, arguments);
4760
- }
4761
-
4762
4873
  exports.INLINE_LIMIT = regeneratorValues.INLINE_LIMIT;
4763
4874
  exports.base64Bytes = regeneratorValues.base64Bytes;
4764
4875
  exports.isAsset = regeneratorValues.isAsset;