@valbuild/tanstack-build 0.150.12 → 0.153.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.
- package/CHANGELOG.md +75 -0
- package/README.md +5 -0
- package/constants/dist/valbuild-tanstack-build-constants.cjs.dev.js +1 -1
- package/constants/dist/valbuild-tanstack-build-constants.cjs.prod.js +1 -1
- package/constants/dist/valbuild-tanstack-build-constants.esm.js +1 -1
- package/dist/declarations/src/build.d.ts +10 -1
- package/dist/declarations/src/projectPaths.d.ts +12 -0
- package/dist/declarations/src/valModules.d.ts +36 -0
- package/dist/{projectPaths-5e4defea.esm.js → projectPaths-521a37ed.esm.js} +16 -1
- package/dist/{projectPaths-9cbecebf.cjs.prod.js → projectPaths-cb474a60.cjs.dev.js} +16 -0
- package/dist/{projectPaths-f222255a.cjs.dev.js → projectPaths-d08a9ea7.cjs.prod.js} +16 -0
- package/dist/valbuild-tanstack-build.cjs.dev.js +808 -517
- package/dist/valbuild-tanstack-build.cjs.prod.js +808 -517
- package/dist/valbuild-tanstack-build.esm.js +809 -519
- package/node/dist/valbuild-tanstack-build-node.cjs.dev.js +1 -1
- package/node/dist/valbuild-tanstack-build-node.cjs.prod.js +1 -1
- package/node/dist/valbuild-tanstack-build-node.esm.js +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
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
2
|
export { I as INLINE_LIMIT, k as base64Bytes, j as isAsset } from './regeneratorValues-56b72784.esm.js';
|
|
3
|
-
import { T as TREE, E as ENTRY } from './projectPaths-
|
|
4
|
-
export { E as ENTRY, R as ROUTES_DIR, T as TREE } from './projectPaths-
|
|
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';
|
|
@@ -1191,7 +1191,7 @@ var packageJson = {
|
|
|
1191
1191
|
url: "git+https://github.com/valbuild/val.git"
|
|
1192
1192
|
},
|
|
1193
1193
|
license: "MIT",
|
|
1194
|
-
version: "0.
|
|
1194
|
+
version: "0.153.0",
|
|
1195
1195
|
sideEffects: false,
|
|
1196
1196
|
main: "dist/valbuild-tanstack-build.cjs.js",
|
|
1197
1197
|
module: "dist/valbuild-tanstack-build.esm.js",
|
|
@@ -1355,7 +1355,14 @@ var LEGACY_CONTROL_HOST = "platform.internal";
|
|
|
1355
1355
|
* existed -- which is every project already published, since a build in a tab
|
|
1356
1356
|
* rewrites single lines of its `val.server.ts` and never regenerates it.
|
|
1357
1357
|
*/
|
|
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
|
|
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";
|
|
1359
1366
|
/**
|
|
1360
1367
|
* THE CONTENT VERSION the site serves, when it differs from the one this build
|
|
1361
1368
|
* bundles (\`VAL_CONTENT\`). See valbuild/home \`docs/hosted-publishing.md\`,
|
|
@@ -1363,6 +1370,16 @@ var PROPOSAL_BLOCK = "/*\n * THE PROPOSAL this isolate serves the address of, wh
|
|
|
1363
1370
|
* arrives in files wired before it the same way: {@link rebakeContent}.
|
|
1364
1371
|
*/
|
|
1365
1372
|
var CONTENT_BLOCK = "/*\n * THE CONTENT VERSION the site serves, when the platform says it differs from\n * the one this build bundles (`VAL_CONTENT`: its id, the publish that made\n * it, and the Source and Val files that differ). Val reads that Source instead\n * of the bundle's and names that publish as its position. valbuild/home\n * `docs/hosted-publishing.md`, step 2.\n *\n * Parsed here, like the proposal above, because this file is compiled against\n * whatever @valbuild/tanstack the PROJECT installed. One from before content\n * versions ignores the `contentVersion` key below and serves the bundle --\n * and never says it applied the version, which is how the platform knows not\n * to serve this build a version it does not bundle. A version that does not\n * parse is thrown, not served as the bundle.\n *\n * A version too large for one variable names others under `refs`\n * (`\"env://VAL_CONTENT_1\"`), each holding one module's Source or one file's\n * text. Only `refs` is resolved, never a string inside Source, and only\n * `VAL_CONTENT_<n>` is read: Source is text editors write, and resolving a\n * reference in there would read `VAL_SECRET` into a page. The same rules as\n * `contentFromEnv` in @valbuild/server.\n */\nconst contentVersion = (() => {\n const handed = secret(\"VAL_CONTENT\");\n if (!handed) return undefined;\n const isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n const parsed: unknown = JSON.parse(handed);\n if (!isRecord(parsed)) throw new Error(\"Val: VAL_CONTENT is not an object\");\n const id = parsed.id;\n if (typeof id !== \"string\" || id === \"\") {\n throw new Error(\"Val: VAL_CONTENT has no id\");\n }\n const where = \"Val: content version \" + id;\n const nullableString = (key: string): string | null => {\n const value = parsed[key] ?? null;\n if (value !== null && typeof value !== \"string\") {\n throw new Error(where + \": \" + key + \" must be a string or null\");\n }\n return value;\n };\n const record = (value: unknown, name: string): Record<string, unknown> => {\n const found = value ?? {};\n if (!isRecord(found)) throw new Error(where + \": \" + name + \" must be an object\");\n return found;\n };\n const job = nullableString(\"job\");\n const commit = nullableString(\"commit\");\n const modules: Record<string, unknown> = { ...record(parsed.modules, \"modules\") };\n const filesIn = record(parsed.files, \"files\");\n const files: Record<string, string> = {};\n for (const [path, text] of Object.entries(filesIn)) {\n if (typeof text === \"string\") files[path] = text;\n }\n const refs = record(parsed.refs, \"refs\");\n const read = (kind: string, path: string, ref: unknown): string => {\n const at = where + \": refs.\" + kind + \"[\" + path + \"]\";\n if (typeof ref !== \"string\" || !ref.startsWith(\"env://\")) {\n throw new Error(at + \" is \" + String(ref) + \": only env://VAL_CONTENT_<n> is read\");\n }\n const name = ref.slice(\"env://\".length);\n if (!/^VAL_CONTENT_[0-9]+$/.test(name)) {\n throw new Error(at + \" names \" + name + \": only VAL_CONTENT_<n> is read\");\n }\n const value = secret(name);\n if (value === undefined) {\n throw new Error(at + \" names \" + name + \", which is not set\");\n }\n return value;\n };\n for (const [path, ref] of Object.entries(record(refs.modules, \"refs.modules\"))) {\n if (Object.prototype.hasOwnProperty.call(modules, path)) {\n throw new Error(where + \": \" + path + \" is in modules and refs.modules\");\n }\n modules[path] = JSON.parse(read(\"modules\", path, ref));\n }\n for (const [path, ref] of Object.entries(record(refs.files, \"refs.files\"))) {\n if (Object.prototype.hasOwnProperty.call(filesIn, path)) {\n throw new Error(where + \": \" + path + \" is in files and refs.files\");\n }\n files[path] = read(\"files\", path, ref);\n }\n if (job === null && commit === null) {\n throw new Error(where + \" must name a job or a commit, or it would be placed at the build it runs in\");\n }\n return { id, job, commit, modules, files };\n})();\n";
|
|
1373
|
+
/**
|
|
1374
|
+
* What each Val module depends on, as the build resolved its imports
|
|
1375
|
+
* (`valModulesEntry` in this package): the build defines it as a global
|
|
1376
|
+
* (`MODULE_DEPENDENCIES_GLOBAL`), and this hands it to Val's server as
|
|
1377
|
+
* `moduleDependencies`. After {@link CONTENT_BLOCK}, where a rebake puts it
|
|
1378
|
+
* in a file wired before it.
|
|
1379
|
+
*/
|
|
1380
|
+
var DEPENDENCIES_BLOCK = "/*\n * WHAT EACH VAL MODULE DEPENDS ON, as this build resolved its imports.\n *\n * At a proposal's address it is how Val knows that a module whose own file\n * is not staged is still of code this build was not made of, through a file\n * it imports. Defined by the build; `undefined` from a builder that\n * predates it, and then only staged module files count.\n */\nconst MODULE_DEPENDENCIES = globalThis.__VAL_MODULE_DEPENDENCIES__;\n\n";
|
|
1381
|
+
/** And the option that hands it to Val, after the content version's. */
|
|
1382
|
+
var DEPENDENCIES_OPTION = " ...(MODULE_DEPENDENCIES !== undefined\n ? { moduleDependencies: MODULE_DEPENDENCIES }\n : {}),\n";
|
|
1366
1383
|
/** Where {@link PROPOSAL_BLOCK} goes: right after this line. */
|
|
1367
1384
|
var SERVED_BUILD_LINE = 'const servedBuild = secret("VAL_BUILD");\n';
|
|
1368
1385
|
/** And the option that hands it to Val, after the build's. */
|
|
@@ -1372,7 +1389,7 @@ var CONTENT_OPTION = " ...(contentVersion !== undefined ? { contentVersio
|
|
|
1372
1389
|
var PUBLISH_BUILD_OPTION = " ...(servedBuild !== undefined ? { publishBuild: servedBuild } : {}),\n";
|
|
1373
1390
|
var valServerSource = function valServerSource(_ref) {
|
|
1374
1391
|
var git = _ref.git;
|
|
1375
|
-
return "".concat(WIRED_MARKER, "\nimport {\n initValContent,\n initValServer,\n} from \"@valbuild/tanstack/server\";\nimport { config } from \"../../val.config\";\nimport valModules from \"../../val.modules\";\n/*\n * This build's own source, which a publish patches. A project with no\n * repository has no other copy of its `.val.ts` text: content keeps its\n * content as data. Ignored by a @valbuild/tanstack that predates it.\n */\nimport { FILES } from \"platform:project-source\";\n\n/**\n * A secret, as the platform hands it over at RUNTIME.\n *\n * Preferred over `process.env`, which the builder inlines as a literal into\n * this bundle: that puts the value in storage inside the code, copies it into\n * every isolate that loads it, and makes rotating it a republish.\n *\n * Falls back to the build-time value, so an app published before secrets\n * existed keeps working.\n */\nfunction secret(name: string): string | undefined {\n return (globalThis.__PLATFORM_SECRETS ?? {})[name] ?? process.env[name];\n}\n\n/**\n * The commit this build was made from, and the branch it commits to.\n *\n * Baked in rather than handed over at runtime, unlike a secret, because it is\n * not configuration -- it is a property OF THIS BUILD. Every read of a\n * `.val.ts` in http mode fetches that path from the content service at this\n * sha, so a build served with somebody else's commit renders and edits a\n * version of its files it was not compiled from. A secret can be rotated under\n * a running build; this cannot, and publishing again is how it changes.\n *\n * WHAT THIS IS NOT. It is not every read: a committed render reads the source\n * bundled into this build and asks the content service nothing. It is the\n * PUBLISH path -- turning pending patches into new `.val.ts` text means\n * fetching the current text to patch, and that is the read that happens at\n * this sha. The docblock used to say \"every read\", which sent readers looking\n * for a content call on the serving path that is not there.\n *\n * `null` when the source came from no commit -- a record assembled in a tab,\n * a fixture, or ANY build this platform makes, which is the common case rather\n * than the exception. Such a build has no repository to mirror commits into,\n * and does not need one: the content service is the store of record for\n * content and mints its own commit shas. Val is in http mode on credentials\n * alone.\n */\nconst BUILT_FROM = ").concat(git ? JSON.stringify(git) : "null", ";\n\n/**\n * The publish job this build was made for, when a Studio built it in a tab.\n *\n * A tab's build has no commit to bake -- the job's is minted at the seal, after\n * the build -- so this is how it says where it sits in the content service's\n * chain. Without it the service places it at whatever build is live, which is\n * a different build for a request this one is still serving when the pointer\n * moves. Set by the Studio (`rebakeGit`), `null` for any other build.\n */\nconst BUILT_FOR_JOB = null;\n\n/**\n * What puts Val in http mode: its content service owns the content.\n *\n * The same three things any deployed Val app is configured with. Note what is\n * NOT here: no `sourceFiles`, so patches are relayed to the content service\n * instead of being kept by this platform, and the browser uploads an image\n * straight there on a presigned URL instead of streaming it through here.\n *\n * `undefined` when a credential or the commit is missing, and deliberately not\n * a throw at module scope: that would take the isolate down with it, page\n * renders included. Val is left to refuse the request and name what it wanted\n * -- `VAL_ENV=app` is set on this build precisely so that a missing credential\n * is an error instead of a fall-through to `fs` mode, looking for a working\n * tree that is not in here.\n */\nconst apiKey = secret(\"VAL_API_KEY\");\nconst valSecret = secret(\"VAL_SECRET\");\n/*\n * Which content service, for a project that is not pointed at the real one.\n *\n * A secret rather than a baked literal, because unlike the commit this IS\n * configuration: the same build should be servable against a stand-in and\n * against production. It is what makes the editing path testable at all --\n * Val's own `e2e/mock-content-host` implements this wire protocol with no git\n * repository behind it -- and without it a build could only ever talk to\n * content.val.build.\n *\n * It does NOT redirect everything, and the gap is in Val rather than here:\n * `getSettings`, which remote FILES use, reads `process.env.VAL_CONTENT_URL`\n * at module scope inside @valbuild/server. This platform bundles its\n * dependencies separately from the app, so nothing it sets reaches that read --\n * the same reason `apiKey` has to be passed in rather than found. So patches,\n * commits and source reads go where this says, and remote file uploads still\n * address the real host.\n */\nconst valContentUrl = secret(\"VAL_CONTENT_URL\");\n/*\n * WHICH project's content this is, at the content service.\n *\n * Val's own name for the project (`org/name`), which is not the platform's\n * project id and cannot be derived from it. A repository that is deployed\n * anywhere else puts it in `val.config.ts`; one imported here need not have,\n * so it is configuration the platform can supply -- and it goes through\n * `secret` rather than `--env` for a second reason: a build-time literal\n * would have to be baked into the shared dependency layer, where\n * @valbuild/server reads `process.env.VAL_PROJECT`, and that layer is reused\n * by every project with the same dependencies.\n *\n * What the app configured wins over nothing at all, so a repository that does\n * name its project keeps working with no secret set.\n */\nconst valProject = secret(\"VAL_PROJECT\");\n/*\n * WHICH BUILD this is, as the platform running it says.\n *\n * Not baked like `BUILT_FROM`, because it cannot be: a build's hash is taken\n * of its output, this file included. The platform hands it over at runtime,\n * and Val sends it to the content service, which places this build's overlay\n * by it -- the one answer that holds for the minute after a publish in which\n * the edge still serves this build while the pointer already names the next.\n * Ignored by a @valbuild/tanstack that predates it.\n */\nconst servedBuild = secret(\"VAL_BUILD\");\n").concat(PROPOSAL_BLOCK).concat(CONTENT_BLOCK, "const valConfig = {\n ...config,\n ...(valProject !== undefined ? { project: valProject } : {}),\n};\n/*\n * CREDENTIALS ALONE. A commit is not part of what puts Val in http mode.\n *\n * It used to be: `GIT !== null` was in this condition, and a build with no\n * commit fell through to `undefined` -- which meant every site this platform\n * seeded was silently unable to edit, because a shared build cannot know a\n * commit. The binding that worked around it (`VAL_GIT_COMMIT` /\n * `VAL_GIT_BRANCH` out of the project's secrets) is gone with it: it named a\n * commit in the TEMPLATE's repository, which was true only for as long as\n * seeding and repository creation shared a template, and it was one more thing\n * in KV that could go stale.\n *\n * The commit is optional NOW, and it is still sent where there is one -- see\n * the note at the spread below. What is gone is the binding that supplied one\n * from KV, so there is one source per environment and no precedence rule\n * between a baked value and a bound one.\n */\nconst http =\n apiKey !== undefined && valSecret !== undefined\n ? {\n apiKey,\n valSecret,\n /*\n * BOTH SPELLINGS OF THE COMMIT, because the APP decides which one is\n * read and this file cannot know which app it is being written into.\n *\n * `ValHttpMode` has been renamed in both directions. Up to 0.132 it\n * took `gitCommit`/`gitBranch`; 0.133.0 replaced that pair with a\n * nested `git`; the version this package ships beside flattens it\n * back again. The generated file is compiled against whatever\n * `@valbuild/tanstack` the PROJECT installed -- the starter pins\n * 0.133.0 -- and a platform writing this file has no say in that. So\n * this is not one rename behind or ahead: it is on both sides of one at\n * once, and will be until every app it publishes has moved.\n *\n * Sending only the wrong one is SILENT, which is why this is belt and\n * braces rather than a version check. An unknown key on the options\n * object is ignored, so the commit is simply dropped and a build wired\n * FROM A COMMIT runs as though it had none -- which means a publish\n * produces no mirrored `.val.ts`, so a save commits and hands over\n * nothing, and the site keeps serving its old content with the patches\n * already consumed. Nothing reports it. valbuild/home's loop is the one\n * thing that sees it, and it was bisected there: 25/25 with the key the\n * installed version reads, 21/23 without, failing at exactly \"the save\n * left the file it rewrote pending\".\n *\n * Whichever version is installed reads its own key and ignores the\n * other two. Drop this to one spelling when every app this platform\n * publishes is past the rename -- not before, and not on the say-so of\n * a compiler in the Val repository, which is looking at a different\n * version of `@valbuild/tanstack` than the app is.\n */\n ...(BUILT_FROM !== null\n ? {\n git: BUILT_FROM,\n gitCommit: BUILT_FROM.commit,\n gitBranch: BUILT_FROM.branch,\n }\n : {}),\n ...(valContentUrl !== undefined ? { valContentUrl } : {}),\n projectSource: FILES,\n ...(BUILT_FOR_JOB !== null ? { publishJob: BUILT_FOR_JOB } : {}),\n ...(servedBuild !== undefined ? { publishBuild: servedBuild } : {}),\n").concat(PROPOSAL_OPTION).concat(CONTENT_OPTION, " }\n : undefined;\n\nconst { valApiHandler, draftMode } = initValServer(\n valModules,\n valConfig,\n {\n ...(http ? { http } : {}),\n },\n);\n\nconst content = initValContent(valConfig, valModules, {\n draftMode,\n /*\n * The SAME object the API got.\n *\n * These readers resolve content through a Val server of their own rather than\n * by calling the API over HTTP, so the mode question is put to them\n * separately -- configuring only `initValServer` left them inferring `fs`\n * mode, looking for a working tree that is not in here. `gitCommit` is the\n * field that would be silently wrong rather than loudly missing: two\n * different shas means the API edits one version of a file while the page\n * renders another.\n */\n ...(http ? { http } : {}),\n});\n\nconst {\n fetchValStega: fetchVal,\n fetchValKeyStega: fetchValKey,\n fetchValRouteStega: fetchValRoute,\n fetchValRouteUrl,\n} = content;\n\n/**\n * The draft a page renders with in preview: `<ValProvider draft>`, read in the\n * site layout's loader. The starter imports it from this file, so a file\n * without it fails the build with a missing export.\n *\n * Asked of the result rather than destructured, because this file is compiled\n * against whatever `@valbuild/tanstack` the PROJECT installed, and one from\n * before 0.140 has no such reader. There it is \"no draft\", which is the\n * render that version had anyway -- and it is still a function either way, so\n * a page that calls it compiles against both.\n */\nconst fetchValDraft = async () =>\n \"fetchValDraft\" in content && typeof content.fetchValDraft === \"function\"\n ? content.fetchValDraft()\n : null;\n\n/**\n * Content analytics for `<ValProvider analytics>`, read in the site layout's\n * loader beside `fetchValDraft`: whether it is on, and the content version.\n *\n * A setting of the project, which its owner turns on in the project's settings\n * and the platform hands over as the `VAL_ANALYTICS` secret -- at RUNTIME,\n * like every secret, so switching it is not a rebuild. The value reaches the\n * browser in the layout's loader data, which a prerendered page has baked in;\n * the platform keeps a prerendered page only for the secrets it was rendered\n * with, so after a switch pages render live until they are prerendered again.\n * Off unless that secret says `true`. A `@valbuild/tanstack` from before analytics ignores the\n * prop, so this is safe to call against any version.\n *\n * With it, the id of the content version this render serves\n * (`VAL_CONTENT_VERSION`, which the loader hands every isolate it starts for\n * the site, whether the version is the bundle's own or handed over), so every\n * count is stored with the version it was seen in.\n *\n * What the platform handed over ONLY, not `secret()`: that falls back to\n * `process.env`, which the builder bakes into this bundle, so a\n * `VAL_ANALYTICS` set at build time would be a second switch in the code --\n * and one that keeps counting after the owner has turned it off.\n */\nconst fetchValAnalytics = async (): Promise<{\n enabled: boolean;\n contentVersion?: string;\n}> => {\n const handed = globalThis.__PLATFORM_SECRETS ?? {};\n const contentVersion = handed[\"VAL_CONTENT_VERSION\"];\n return {\n enabled: handed[\"VAL_ANALYTICS\"] === \"true\",\n ...(contentVersion ? { contentVersion } : {}),\n };\n};\n\n/**\n * A build that is MEANT to edit and cannot, refusing instead of pretending to.\n *\n * `BUILT_FROM` being non-null says this build came from a commit, so it was\n * made to edit against a content service. If the credentials for that service are not\n * here, the configuration is broken -- and the failure that was reaching people\n * was not an error at all. Val picks its storage mode by inference, so an\n * isolate with no api key lands in a mode that ACCEPTS the write and keeps it\n * in the isolate. Cloudflare starts an isolate per concurrent request, so the\n * save answers 200 and the next request, served by a different isolate, has\n * never heard of it. The edit is simply gone, and nothing anywhere said so.\n *\n * That is the worst available outcome: a person is told their work is saved\n * when it is not. Refusing is strictly better, and naming the missing secret\n * turns an evening of reading logs into one line in a response body.\n *\n * WHY HERE rather than relying on `VAL_ENV=app`: that is a build-time\n * substitution into the shared dependency layer, so whether a build fails\n * loudly depends on which layer it happens to be pinned to. This file is\n * written on every build, by the platform, and cannot be missing from one.\n *\n * Only the editing API. Page renders do not come through here, and a site whose\n * content cannot be edited should still serve the content it has.\n */\nconst editingApiHandler =\n http === undefined\n ? async () => {\n const missing = [\n apiKey === undefined ? \"VAL_API_KEY\" : null,\n valSecret === undefined ? \"VAL_SECRET\" : null,\n /*\n * A build from no commit is listed the same way, because from the\n * outside the two are one state. It is not a secret somebody can set\n * -- a commit is a property OF THE BUILD, and the only cure is\n * publishing this project's own repository over whatever is serving\n * it. Named anyway, because \"it was built from no commit\" is the\n * sentence that ends the search.\n */\n BUILT_FROM === null ? \"a commit (this build was made from none)\" : null,\n ].filter(Boolean);\n return Response.json(\n {\n error:\n \"This site cannot be edited. Its content lives in a content service, and \" +\n missing.join(\", \") +\n \" \" +\n (missing.length > 1 ? \"are\" : \"is\") +\n \" missing, so there is nothing to edit against. Editing is refused rather \" +\n \"than kept in this isolate's memory, where it would be lost without being \" +\n \"reported.\" +\n (BUILT_FROM === null\n ? \" A build made from no commit is usually one SEEDED from a template: \" +\n \"publish this project's own repository to replace it.\"\n : \" This build was made from commit \" + BUILT_FROM.commit.slice(0, 8) + \".\"),\n missing,\n },\n { status: 503 },\n );\n }\n : valApiHandler;\n\nexport {\n editingApiHandler as valApiHandler,\n draftMode,\n fetchVal,\n fetchValKey,\n fetchValRoute,\n fetchValRouteUrl,\n fetchValDraft,\n fetchValAnalytics,\n};\n");
|
|
1392
|
+
return "".concat(WIRED_MARKER, "\nimport {\n initValContent,\n initValServer,\n} from \"@valbuild/tanstack/server\";\nimport { config } from \"../../val.config\";\nimport valModules from \"../../val.modules\";\n/*\n * This build's own source, which a publish patches. A project with no\n * repository has no other copy of its `.val.ts` text: content keeps its\n * content as data. Ignored by a @valbuild/tanstack that predates it.\n */\nimport { FILES } from \"platform:project-source\";\n\n/**\n * A secret, as the platform hands it over at RUNTIME.\n *\n * Preferred over `process.env`, which the builder inlines as a literal into\n * this bundle: that puts the value in storage inside the code, copies it into\n * every isolate that loads it, and makes rotating it a republish.\n *\n * Falls back to the build-time value, so an app published before secrets\n * existed keeps working.\n */\nfunction secret(name: string): string | undefined {\n return (globalThis.__PLATFORM_SECRETS ?? {})[name] ?? process.env[name];\n}\n\n/**\n * The commit this build was made from, and the branch it commits to.\n *\n * Baked in rather than handed over at runtime, unlike a secret, because it is\n * not configuration -- it is a property OF THIS BUILD. Every read of a\n * `.val.ts` in http mode fetches that path from the content service at this\n * sha, so a build served with somebody else's commit renders and edits a\n * version of its files it was not compiled from. A secret can be rotated under\n * a running build; this cannot, and publishing again is how it changes.\n *\n * WHAT THIS IS NOT. It is not every read: a committed render reads the source\n * bundled into this build and asks the content service nothing. It is the\n * PUBLISH path -- turning pending patches into new `.val.ts` text means\n * fetching the current text to patch, and that is the read that happens at\n * this sha. The docblock used to say \"every read\", which sent readers looking\n * for a content call on the serving path that is not there.\n *\n * `null` when the source came from no commit -- a record assembled in a tab,\n * a fixture, or ANY build this platform makes, which is the common case rather\n * than the exception. Such a build has no repository to mirror commits into,\n * and does not need one: the content service is the store of record for\n * content and mints its own commit shas. Val is in http mode on credentials\n * alone.\n */\nconst BUILT_FROM = ").concat(git ? JSON.stringify(git) : "null", ";\n\n/**\n * The publish job this build was made for, when a Studio built it in a tab.\n *\n * A tab's build has no commit to bake -- the job's is minted at the seal, after\n * the build -- so this is how it says where it sits in the content service's\n * chain. Without it the service places it at whatever build is live, which is\n * a different build for a request this one is still serving when the pointer\n * moves. Set by the Studio (`rebakeGit`), `null` for any other build.\n */\nconst BUILT_FOR_JOB = null;\n\n/**\n * What puts Val in http mode: its content service owns the content.\n *\n * The same three things any deployed Val app is configured with. Note what is\n * NOT here: no `sourceFiles`, so patches are relayed to the content service\n * instead of being kept by this platform, and the browser uploads an image\n * straight there on a presigned URL instead of streaming it through here.\n *\n * `undefined` when a credential or the commit is missing, and deliberately not\n * a throw at module scope: that would take the isolate down with it, page\n * renders included. Val is left to refuse the request and name what it wanted\n * -- `VAL_ENV=app` is set on this build precisely so that a missing credential\n * is an error instead of a fall-through to `fs` mode, looking for a working\n * tree that is not in here.\n */\nconst apiKey = secret(\"VAL_API_KEY\");\nconst valSecret = secret(\"VAL_SECRET\");\n/*\n * Which content service, for a project that is not pointed at the real one.\n *\n * A secret rather than a baked literal, because unlike the commit this IS\n * configuration: the same build should be servable against a stand-in and\n * against production. It is what makes the editing path testable at all --\n * Val's own `e2e/mock-content-host` implements this wire protocol with no git\n * repository behind it -- and without it a build could only ever talk to\n * content.val.build.\n *\n * It does NOT redirect everything, and the gap is in Val rather than here:\n * `getSettings`, which remote FILES use, reads `process.env.VAL_CONTENT_URL`\n * at module scope inside @valbuild/server. This platform bundles its\n * dependencies separately from the app, so nothing it sets reaches that read --\n * the same reason `apiKey` has to be passed in rather than found. So patches,\n * commits and source reads go where this says, and remote file uploads still\n * address the real host.\n */\nconst valContentUrl = secret(\"VAL_CONTENT_URL\");\n/*\n * WHICH project's content this is, at the content service.\n *\n * Val's own name for the project (`org/name`), which is not the platform's\n * project id and cannot be derived from it. A repository that is deployed\n * anywhere else puts it in `val.config.ts`; one imported here need not have,\n * so it is configuration the platform can supply -- and it goes through\n * `secret` rather than `--env` for a second reason: a build-time literal\n * would have to be baked into the shared dependency layer, where\n * @valbuild/server reads `process.env.VAL_PROJECT`, and that layer is reused\n * by every project with the same dependencies.\n *\n * What the app configured wins over nothing at all, so a repository that does\n * name its project keeps working with no secret set.\n */\nconst valProject = secret(\"VAL_PROJECT\");\n/*\n * WHICH BUILD this is, as the platform running it says.\n *\n * Not baked like `BUILT_FROM`, because it cannot be: a build's hash is taken\n * of its output, this file included. The platform hands it over at runtime,\n * and Val sends it to the content service, which places this build's overlay\n * by it -- the one answer that holds for the minute after a publish in which\n * the edge still serves this build while the pointer already names the next.\n * Ignored by a @valbuild/tanstack that predates it.\n */\nconst servedBuild = secret(\"VAL_BUILD\");\n").concat(PROPOSAL_BLOCK).concat(CONTENT_BLOCK).concat(DEPENDENCIES_BLOCK, "const valConfig = {\n ...config,\n ...(valProject !== undefined ? { project: valProject } : {}),\n};\n/*\n * CREDENTIALS ALONE. A commit is not part of what puts Val in http mode.\n *\n * It used to be: `GIT !== null` was in this condition, and a build with no\n * commit fell through to `undefined` -- which meant every site this platform\n * seeded was silently unable to edit, because a shared build cannot know a\n * commit. The binding that worked around it (`VAL_GIT_COMMIT` /\n * `VAL_GIT_BRANCH` out of the project's secrets) is gone with it: it named a\n * commit in the TEMPLATE's repository, which was true only for as long as\n * seeding and repository creation shared a template, and it was one more thing\n * in KV that could go stale.\n *\n * The commit is optional NOW, and it is still sent where there is one -- see\n * the note at the spread below. What is gone is the binding that supplied one\n * from KV, so there is one source per environment and no precedence rule\n * between a baked value and a bound one.\n */\nconst http =\n apiKey !== undefined && valSecret !== undefined\n ? {\n apiKey,\n valSecret,\n /*\n * BOTH SPELLINGS OF THE COMMIT, because the APP decides which one is\n * read and this file cannot know which app it is being written into.\n *\n * `ValHttpMode` has been renamed in both directions. Up to 0.132 it\n * took `gitCommit`/`gitBranch`; 0.133.0 replaced that pair with a\n * nested `git`; the version this package ships beside flattens it\n * back again. The generated file is compiled against whatever\n * `@valbuild/tanstack` the PROJECT installed -- the starter pins\n * 0.133.0 -- and a platform writing this file has no say in that. So\n * this is not one rename behind or ahead: it is on both sides of one at\n * once, and will be until every app it publishes has moved.\n *\n * Sending only the wrong one is SILENT, which is why this is belt and\n * braces rather than a version check. An unknown key on the options\n * object is ignored, so the commit is simply dropped and a build wired\n * FROM A COMMIT runs as though it had none -- which means a publish\n * produces no mirrored `.val.ts`, so a save commits and hands over\n * nothing, and the site keeps serving its old content with the patches\n * already consumed. Nothing reports it. valbuild/home's loop is the one\n * thing that sees it, and it was bisected there: 25/25 with the key the\n * installed version reads, 21/23 without, failing at exactly \"the save\n * left the file it rewrote pending\".\n *\n * Whichever version is installed reads its own key and ignores the\n * other two. Drop this to one spelling when every app this platform\n * publishes is past the rename -- not before, and not on the say-so of\n * a compiler in the Val repository, which is looking at a different\n * version of `@valbuild/tanstack` than the app is.\n */\n ...(BUILT_FROM !== null\n ? {\n git: BUILT_FROM,\n gitCommit: BUILT_FROM.commit,\n gitBranch: BUILT_FROM.branch,\n }\n : {}),\n ...(valContentUrl !== undefined ? { valContentUrl } : {}),\n projectSource: FILES,\n ...(BUILT_FOR_JOB !== null ? { publishJob: BUILT_FOR_JOB } : {}),\n ...(servedBuild !== undefined ? { publishBuild: servedBuild } : {}),\n").concat(PROPOSAL_OPTION).concat(CONTENT_OPTION).concat(DEPENDENCIES_OPTION, " }\n : undefined;\n\nconst { valApiHandler, draftMode } = initValServer(\n valModules,\n valConfig,\n {\n ...(http ? { http } : {}),\n },\n);\n\nconst content = initValContent(valConfig, valModules, {\n draftMode,\n /*\n * The SAME object the API got.\n *\n * These readers resolve content through a Val server of their own rather than\n * by calling the API over HTTP, so the mode question is put to them\n * separately -- configuring only `initValServer` left them inferring `fs`\n * mode, looking for a working tree that is not in here. `gitCommit` is the\n * field that would be silently wrong rather than loudly missing: two\n * different shas means the API edits one version of a file while the page\n * renders another.\n */\n ...(http ? { http } : {}),\n});\n\nconst {\n fetchValStega: fetchVal,\n fetchValKeyStega: fetchValKey,\n fetchValRouteStega: fetchValRoute,\n fetchValRouteUrl,\n} = content;\n\n/**\n * The draft a page renders with in preview: `<ValProvider draft>`, read in the\n * site layout's loader. The starter imports it from this file, so a file\n * without it fails the build with a missing export.\n *\n * Asked of the result rather than destructured, because this file is compiled\n * against whatever `@valbuild/tanstack` the PROJECT installed, and one from\n * before 0.140 has no such reader. There it is \"no draft\", which is the\n * render that version had anyway -- and it is still a function either way, so\n * a page that calls it compiles against both.\n */\nconst fetchValDraft = async () =>\n \"fetchValDraft\" in content && typeof content.fetchValDraft === \"function\"\n ? content.fetchValDraft()\n : null;\n\n/**\n * Content analytics for `<ValProvider analytics>`, read in the site layout's\n * loader beside `fetchValDraft`: whether it is on, and the content version.\n *\n * A setting of the project, which its owner turns on in the project's settings\n * and the platform hands over as the `VAL_ANALYTICS` secret -- at RUNTIME,\n * like every secret, so switching it is not a rebuild. The value reaches the\n * browser in the layout's loader data, which a prerendered page has baked in;\n * the platform keeps a prerendered page only for the secrets it was rendered\n * with, so after a switch pages render live until they are prerendered again.\n * Off unless that secret says `true`. A `@valbuild/tanstack` from before analytics ignores the\n * prop, so this is safe to call against any version.\n *\n * With it, the id of the content version this render serves\n * (`VAL_CONTENT_VERSION`, which the loader hands every isolate it starts for\n * the site, whether the version is the bundle's own or handed over), so every\n * count is stored with the version it was seen in.\n *\n * What the platform handed over ONLY, not `secret()`: that falls back to\n * `process.env`, which the builder bakes into this bundle, so a\n * `VAL_ANALYTICS` set at build time would be a second switch in the code --\n * and one that keeps counting after the owner has turned it off.\n */\nconst fetchValAnalytics = async (): Promise<{\n enabled: boolean;\n contentVersion?: string;\n}> => {\n const handed = globalThis.__PLATFORM_SECRETS ?? {};\n const contentVersion = handed[\"VAL_CONTENT_VERSION\"];\n return {\n enabled: handed[\"VAL_ANALYTICS\"] === \"true\",\n ...(contentVersion ? { contentVersion } : {}),\n };\n};\n\n/**\n * A build that is MEANT to edit and cannot, refusing instead of pretending to.\n *\n * `BUILT_FROM` being non-null says this build came from a commit, so it was\n * made to edit against a content service. If the credentials for that service are not\n * here, the configuration is broken -- and the failure that was reaching people\n * was not an error at all. Val picks its storage mode by inference, so an\n * isolate with no api key lands in a mode that ACCEPTS the write and keeps it\n * in the isolate. Cloudflare starts an isolate per concurrent request, so the\n * save answers 200 and the next request, served by a different isolate, has\n * never heard of it. The edit is simply gone, and nothing anywhere said so.\n *\n * That is the worst available outcome: a person is told their work is saved\n * when it is not. Refusing is strictly better, and naming the missing secret\n * turns an evening of reading logs into one line in a response body.\n *\n * WHY HERE rather than relying on `VAL_ENV=app`: that is a build-time\n * substitution into the shared dependency layer, so whether a build fails\n * loudly depends on which layer it happens to be pinned to. This file is\n * written on every build, by the platform, and cannot be missing from one.\n *\n * Only the editing API. Page renders do not come through here, and a site whose\n * content cannot be edited should still serve the content it has.\n */\nconst editingApiHandler =\n http === undefined\n ? async () => {\n const missing = [\n apiKey === undefined ? \"VAL_API_KEY\" : null,\n valSecret === undefined ? \"VAL_SECRET\" : null,\n /*\n * A build from no commit is listed the same way, because from the\n * outside the two are one state. It is not a secret somebody can set\n * -- a commit is a property OF THE BUILD, and the only cure is\n * publishing this project's own repository over whatever is serving\n * it. Named anyway, because \"it was built from no commit\" is the\n * sentence that ends the search.\n */\n BUILT_FROM === null ? \"a commit (this build was made from none)\" : null,\n ].filter(Boolean);\n return Response.json(\n {\n error:\n \"This site cannot be edited. Its content lives in a content service, and \" +\n missing.join(\", \") +\n \" \" +\n (missing.length > 1 ? \"are\" : \"is\") +\n \" missing, so there is nothing to edit against. Editing is refused rather \" +\n \"than kept in this isolate's memory, where it would be lost without being \" +\n \"reported.\" +\n (BUILT_FROM === null\n ? \" A build made from no commit is usually one SEEDED from a template: \" +\n \"publish this project's own repository to replace it.\"\n : \" This build was made from commit \" + BUILT_FROM.commit.slice(0, 8) + \".\"),\n missing,\n },\n { status: 503 },\n );\n }\n : valApiHandler;\n\nexport {\n editingApiHandler as valApiHandler,\n draftMode,\n fetchVal,\n fetchValKey,\n fetchValRoute,\n fetchValRouteUrl,\n fetchValDraft,\n fetchValAnalytics,\n};\n");
|
|
1376
1393
|
};
|
|
1377
1394
|
|
|
1378
1395
|
/**
|
|
@@ -1390,7 +1407,7 @@ var valServerSource = function valServerSource(_ref) {
|
|
|
1390
1407
|
* declaration, and a top-level `declare var` is a global without needing
|
|
1391
1408
|
* `declare global`, which a script may not contain.
|
|
1392
1409
|
*/
|
|
1393
|
-
var PROJECT_SOURCE_DECLARATIONS = "// Generated by the Val studio when this project was wired up to the platform.\n// The build resolves this specifier to the project's own source, shipped into\n// the isolate as a module.\n//\n// Deliberately not a module: an `export` anywhere in this file would turn the\n// declaration below into an augmentation, and the import would stop resolving.\ndeclare module 'platform:project-source' {\n /** Every source file of this project, keyed by its path from the root. */\n export const FILES: Record<string, string>\n}\n\n/**\n * The project this isolate is serving, set per request by the platform from\n * the id the loader resolved off the hostname.\n *\n * Absent when server-rendering outside the platform, and in the browser.\n */\n// eslint-disable-next-line no-var\ndeclare var __PLATFORM_PROJECT_ID: string | undefined\n/**\n * This project's secrets, handed over per request rather than built in.\n *\n * SERVER ONLY -- set by the platform's Worker entry, which never runs in a\n * browser. Absent outside the platform.\n */\n// eslint-disable-next-line no-var\ndeclare var __PLATFORM_SECRETS: Record<string, string> | undefined\n";
|
|
1410
|
+
var PROJECT_SOURCE_DECLARATIONS = "// Generated by the Val studio when this project was wired up to the platform.\n// The build resolves this specifier to the project's own source, shipped into\n// the isolate as a module.\n//\n// Deliberately not a module: an `export` anywhere in this file would turn the\n// declaration below into an augmentation, and the import would stop resolving.\ndeclare module 'platform:project-source' {\n /** Every source file of this project, keyed by its path from the root. */\n export const FILES: Record<string, string>\n}\n\n/**\n * The project this isolate is serving, set per request by the platform from\n * the id the loader resolved off the hostname.\n *\n * Absent when server-rendering outside the platform, and in the browser.\n */\n// eslint-disable-next-line no-var\ndeclare var __PLATFORM_PROJECT_ID: string | undefined\n/**\n * This project's secrets, handed over per request rather than built in.\n *\n * SERVER ONLY -- set by the platform's Worker entry, which never runs in a\n * browser. Absent outside the platform.\n */\n// eslint-disable-next-line no-var\ndeclare var __PLATFORM_SECRETS: Record<string, string> | undefined\n/**\n * What each Val module of this build depends on, by path, as the build\n * resolved its imports. Defined by the platform's build; absent from a\n * builder that predates it.\n */\n// eslint-disable-next-line no-var\ndeclare var __VAL_MODULE_DEPENDENCIES__: Record<string, string[]> | undefined\n";
|
|
1394
1411
|
|
|
1395
1412
|
/**
|
|
1396
1413
|
* The wired `val.server.ts`, on its own.
|
|
@@ -1467,6 +1484,14 @@ function bakedJob(files) {
|
|
|
1467
1484
|
* as it is, and serves a proposal's address as its base build.
|
|
1468
1485
|
*/
|
|
1469
1486
|
function rebakeProposal(source) {
|
|
1487
|
+
// A block from before staged code was read: the current one in its place,
|
|
1488
|
+
// where it is exactly as generated.
|
|
1489
|
+
var at = source.indexOf(PROPOSAL_BLOCK_V1);
|
|
1490
|
+
if (at !== -1 && source.indexOf(PROPOSAL_BLOCK_V1, at + 1) === -1) {
|
|
1491
|
+
return source.replace(PROPOSAL_BLOCK_V1, function () {
|
|
1492
|
+
return PROPOSAL_BLOCK;
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1470
1495
|
if (source.includes("const proposal = (() => {")) return source;
|
|
1471
1496
|
var once = function once(needle) {
|
|
1472
1497
|
var at = source.indexOf(needle);
|
|
@@ -1502,6 +1527,38 @@ function rebakeContent(source) {
|
|
|
1502
1527
|
});
|
|
1503
1528
|
}
|
|
1504
1529
|
|
|
1530
|
+
/**
|
|
1531
|
+
* `source` handing Val each module's dependencies: {@link DEPENDENCIES_BLOCK}
|
|
1532
|
+
* and its option added after the content version's, to a file wired before
|
|
1533
|
+
* they existed. Idempotent, and only where both places are exactly as
|
|
1534
|
+
* generated -- a file somebody edited is left as it is, and Val counts only
|
|
1535
|
+
* staged module files at a proposal's address, as before.
|
|
1536
|
+
*/
|
|
1537
|
+
function rebakeDependencies(source) {
|
|
1538
|
+
var once = function once(needle) {
|
|
1539
|
+
var at = source.indexOf(needle);
|
|
1540
|
+
return at !== -1 && source.indexOf(needle, at + 1) === -1;
|
|
1541
|
+
};
|
|
1542
|
+
if (!once(CONTENT_BLOCK) || !once(CONTENT_OPTION)) return source;
|
|
1543
|
+
var hasBlock = source.includes(DEPENDENCIES_BLOCK);
|
|
1544
|
+
var hasOption = source.includes(DEPENDENCIES_OPTION);
|
|
1545
|
+
if (hasBlock && hasOption) return source;
|
|
1546
|
+
// Each piece once, whatever left the other there: an option without its
|
|
1547
|
+
// block names a constant that does not exist.
|
|
1548
|
+
var next = source;
|
|
1549
|
+
if (!hasBlock) {
|
|
1550
|
+
next = next.replace(CONTENT_BLOCK, function () {
|
|
1551
|
+
return CONTENT_BLOCK + DEPENDENCIES_BLOCK;
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
if (!hasOption) {
|
|
1555
|
+
next = next.replace(CONTENT_OPTION, function () {
|
|
1556
|
+
return CONTENT_OPTION + DEPENDENCIES_OPTION;
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1559
|
+
return next;
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1505
1562
|
/** `source` with its job set, or `source` itself when it cannot carry one. */
|
|
1506
1563
|
function rebakeJob(source, job) {
|
|
1507
1564
|
var line = "const BUILT_FOR_JOB = ".concat(job === null ? "null" : JSON.stringify(job), ";");
|
|
@@ -1585,7 +1642,7 @@ job) {
|
|
|
1585
1642
|
if (!BUILT_FROM_LINE.test(source)) return files;
|
|
1586
1643
|
var withGit = source.replace(BUILT_FROM_LINE, "const BUILT_FROM = ".concat(git === null ? "null" : JSON.stringify(git), ";"));
|
|
1587
1644
|
var withJob = job === undefined ? withGit : rebakeJob(withGit, job);
|
|
1588
|
-
return _objectSpread2(_objectSpread2({}, files), {}, _defineProperty({}, VAL_SERVER, rebakeContent(rebakeProposal(withJob))));
|
|
1645
|
+
return _objectSpread2(_objectSpread2({}, files), {}, _defineProperty({}, VAL_SERVER, rebakeDependencies(rebakeContent(rebakeProposal(withJob)))));
|
|
1589
1646
|
}
|
|
1590
1647
|
|
|
1591
1648
|
/** Is this a Val project at all? */
|
|
@@ -1876,75 +1933,570 @@ function canonicalJson(value) {
|
|
|
1876
1933
|
return JSON.stringify(value);
|
|
1877
1934
|
}
|
|
1878
1935
|
|
|
1879
|
-
/**
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1936
|
+
/**
|
|
1937
|
+
* JSON with comments and trailing commas, which is what tsconfig.json is.
|
|
1938
|
+
*
|
|
1939
|
+
* Written as a scanner rather than a regex on purpose: `"url": "https://x"`
|
|
1940
|
+
* contains `//`, and a regex that strips comments without tracking string state
|
|
1941
|
+
* truncates the file there and throws a parse error pointing at the wrong line.
|
|
1942
|
+
*/
|
|
1943
|
+
function parseJsonc(text) {
|
|
1944
|
+
var out = "";
|
|
1945
|
+
var i = 0;
|
|
1946
|
+
while (i < text.length) {
|
|
1947
|
+
var ch = text[i];
|
|
1948
|
+
if (ch === '"') {
|
|
1949
|
+
// Copy the whole string literal, escapes included, untouched.
|
|
1950
|
+
out += ch;
|
|
1951
|
+
i++;
|
|
1952
|
+
while (i < text.length) {
|
|
1953
|
+
var c = text[i];
|
|
1954
|
+
out += c;
|
|
1955
|
+
i++;
|
|
1956
|
+
if (c === "\\") {
|
|
1957
|
+
if (i < text.length) out += text[i++];
|
|
1958
|
+
continue;
|
|
1959
|
+
}
|
|
1960
|
+
if (c === '"') break;
|
|
1892
1961
|
}
|
|
1893
|
-
|
|
1962
|
+
continue;
|
|
1894
1963
|
}
|
|
1895
|
-
|
|
1964
|
+
if (ch === "/" && text[i + 1] === "/") {
|
|
1965
|
+
while (i < text.length && text[i] !== "\n") i++;
|
|
1966
|
+
continue;
|
|
1967
|
+
}
|
|
1968
|
+
if (ch === "/" && text[i + 1] === "*") {
|
|
1969
|
+
i += 2;
|
|
1970
|
+
while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) i++;
|
|
1971
|
+
i += 2;
|
|
1972
|
+
continue;
|
|
1973
|
+
}
|
|
1974
|
+
out += ch;
|
|
1975
|
+
i++;
|
|
1896
1976
|
}
|
|
1897
|
-
|
|
1977
|
+
// Trailing commas, now that every remaining comma is structural.
|
|
1978
|
+
return JSON.parse(out.replace(/,(\s*[}\]])/g, "$1"));
|
|
1898
1979
|
}
|
|
1899
1980
|
|
|
1981
|
+
/** One `paths` entry, pre-split on its wildcard. */
|
|
1982
|
+
|
|
1900
1983
|
/**
|
|
1901
|
-
*
|
|
1984
|
+
* Reads tsconfig.json out of the file record and builds the matcher.
|
|
1902
1985
|
*
|
|
1903
|
-
*
|
|
1904
|
-
* and
|
|
1905
|
-
* replace.
|
|
1986
|
+
* Returns null when the project configures no aliases, which is the common
|
|
1987
|
+
* case and costs nothing.
|
|
1906
1988
|
*/
|
|
1907
|
-
function
|
|
1908
|
-
var
|
|
1909
|
-
var
|
|
1910
|
-
|
|
1911
|
-
|
|
1989
|
+
function aliasMap(files, warn) {
|
|
1990
|
+
var _config$compilerOptio, _config$compilerOptio2;
|
|
1991
|
+
var entry = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "tsconfig.json";
|
|
1992
|
+
var config = readConfig(files, entry, warn, new Set());
|
|
1993
|
+
var paths = config === null || config === void 0 || (_config$compilerOptio = config.compilerOptions) === null || _config$compilerOptio === void 0 ? void 0 : _config$compilerOptio.paths;
|
|
1994
|
+
var baseUrl = config === null || config === void 0 || (_config$compilerOptio2 = config.compilerOptions) === null || _config$compilerOptio2 === void 0 ? void 0 : _config$compilerOptio2.baseUrl;
|
|
1995
|
+
// A project can configure either one without the other, and baseUrl alone is
|
|
1996
|
+
// enough to change how a bare specifier resolves.
|
|
1997
|
+
if ((!paths || Object.keys(paths).length === 0) && baseUrl === undefined) return null;
|
|
1912
1998
|
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
var
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
var
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1999
|
+
// `baseUrl` is relative to the tsconfig that declared it. Since TS 4.1 paths
|
|
2000
|
+
// work without one, resolved against the tsconfig's own directory -- so the
|
|
2001
|
+
// fallback here is the directory, not the project root.
|
|
2002
|
+
var base = resolve(dirname(entry), baseUrl !== null && baseUrl !== void 0 ? baseUrl : ".");
|
|
2003
|
+
var patterns = [];
|
|
2004
|
+
for (var _i = 0, _Object$entries = Object.entries(paths !== null && paths !== void 0 ? paths : {}); _i < _Object$entries.length; _i++) {
|
|
2005
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
2006
|
+
pattern = _Object$entries$_i[0],
|
|
2007
|
+
targets = _Object$entries$_i[1];
|
|
2008
|
+
var star = pattern.indexOf("*");
|
|
2009
|
+
if (star !== pattern.lastIndexOf("*")) {
|
|
2010
|
+
warn("tsconfig paths pattern '".concat(pattern, "' has more than one '*' and is ignored."));
|
|
2011
|
+
continue;
|
|
2012
|
+
}
|
|
2013
|
+
patterns.push({
|
|
2014
|
+
prefix: star === -1 ? pattern : pattern.slice(0, star),
|
|
2015
|
+
suffix: star === -1 ? "" : pattern.slice(star + 1),
|
|
2016
|
+
wildcard: star !== -1,
|
|
2017
|
+
targets: targets.map(function (target) {
|
|
2018
|
+
return resolve(base, target);
|
|
2019
|
+
})
|
|
1927
2020
|
});
|
|
1928
|
-
current = callee.object;
|
|
1929
2021
|
}
|
|
1930
|
-
|
|
2022
|
+
|
|
2023
|
+
// TypeScript picks the pattern with the longest literal prefix, so `@/ui/*`
|
|
2024
|
+
// beats `@/*` for `@/ui/card` regardless of declaration order.
|
|
2025
|
+
patterns.sort(function (a, b) {
|
|
2026
|
+
return b.prefix.length - a.prefix.length;
|
|
2027
|
+
});
|
|
2028
|
+
return {
|
|
2029
|
+
patterns: Object.keys(paths !== null && paths !== void 0 ? paths : {}),
|
|
2030
|
+
baseUrlCandidate: function baseUrlCandidate(specifier) {
|
|
2031
|
+
return baseUrl === undefined ? null : resolve(base, specifier);
|
|
2032
|
+
},
|
|
2033
|
+
candidates: function candidates(specifier) {
|
|
2034
|
+
var _loop = function _loop() {
|
|
2035
|
+
var pattern = _patterns[_i2];
|
|
2036
|
+
if (!pattern.wildcard) {
|
|
2037
|
+
if (specifier === pattern.prefix) return {
|
|
2038
|
+
v: _toConsumableArray(pattern.targets)
|
|
2039
|
+
};
|
|
2040
|
+
return 0; // continue
|
|
2041
|
+
}
|
|
2042
|
+
if (!specifier.startsWith(pattern.prefix) || !specifier.endsWith(pattern.suffix) || specifier.length < pattern.prefix.length + pattern.suffix.length) {
|
|
2043
|
+
return 0; // continue
|
|
2044
|
+
}
|
|
2045
|
+
var matched = specifier.slice(pattern.prefix.length, specifier.length - pattern.suffix.length);
|
|
2046
|
+
return {
|
|
2047
|
+
v: pattern.targets.map(function (target) {
|
|
2048
|
+
return target.replace("*", matched);
|
|
2049
|
+
})
|
|
2050
|
+
};
|
|
2051
|
+
},
|
|
2052
|
+
_ret;
|
|
2053
|
+
for (var _i2 = 0, _patterns = patterns; _i2 < _patterns.length; _i2++) {
|
|
2054
|
+
_ret = _loop();
|
|
2055
|
+
if (_ret === 0) continue;
|
|
2056
|
+
if (_ret) return _ret.v;
|
|
2057
|
+
}
|
|
2058
|
+
return [];
|
|
2059
|
+
}
|
|
2060
|
+
};
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
/** Follows `extends` through the file record. Package extends cannot be read. */
|
|
2064
|
+
function readConfig(files, path, warn, seen) {
|
|
2065
|
+
var _config, _config$compilerOptio4, _config$compilerOptio5, _parent$compilerOptio;
|
|
2066
|
+
if (seen.has(path)) return null; // a cycle; whatever we have is enough
|
|
2067
|
+
seen.add(path);
|
|
2068
|
+
var text = files[path];
|
|
2069
|
+
if (text === undefined) return null;
|
|
2070
|
+
var config;
|
|
2071
|
+
try {
|
|
2072
|
+
config = parseJsonc(text);
|
|
2073
|
+
} catch (error) {
|
|
2074
|
+
var _message;
|
|
2075
|
+
warn("Could not parse ".concat(path, ": ").concat(String((_message = error === null || error === void 0 ? void 0 : error.message) !== null && _message !== void 0 ? _message : error)));
|
|
2076
|
+
return null;
|
|
2077
|
+
}
|
|
2078
|
+
if (!((_config = config) !== null && _config !== void 0 && _config["extends"])) return config;
|
|
2079
|
+
|
|
2080
|
+
// Only a relative extends can be followed: a package one ("extends":
|
|
2081
|
+
// "@tsconfig/node20/tsconfig.json") lives in node_modules, which a browser
|
|
2082
|
+
// build does not have. Worth saying out loud rather than silently resolving
|
|
2083
|
+
// half the aliases, because the base config is where a monorepo usually puts
|
|
2084
|
+
// them.
|
|
2085
|
+
if (!config["extends"].startsWith(".")) {
|
|
2086
|
+
var _config$compilerOptio3;
|
|
2087
|
+
if (!((_config$compilerOptio3 = config.compilerOptions) !== null && _config$compilerOptio3 !== void 0 && _config$compilerOptio3.paths)) {
|
|
2088
|
+
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."));
|
|
2089
|
+
}
|
|
2090
|
+
return config;
|
|
2091
|
+
}
|
|
2092
|
+
var parentPath = resolveConfigPath(files, resolve(dirname(path), config["extends"]));
|
|
2093
|
+
var parent = parentPath ? readConfig(files, parentPath, warn, seen) : null;
|
|
2094
|
+
if (!parent) return config;
|
|
2095
|
+
|
|
2096
|
+
// The child wins, and `paths` replaces rather than merges -- which is what
|
|
2097
|
+
// TypeScript does.
|
|
2098
|
+
return {
|
|
2099
|
+
compilerOptions: _objectSpread2(_objectSpread2(_objectSpread2({}, parent.compilerOptions), config.compilerOptions), {}, {
|
|
2100
|
+
// baseUrl in the parent was relative to the *parent*, and readConfig
|
|
2101
|
+
// returns it unresolved, so a parent baseUrl with a child that sets none
|
|
2102
|
+
// is the one case this gets wrong. Rare enough to name rather than model.
|
|
2103
|
+
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
|
|
2104
|
+
})
|
|
2105
|
+
};
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
/** `extends: './base'` may omit the .json. */
|
|
2109
|
+
function resolveConfigPath(files, path) {
|
|
2110
|
+
for (var _i3 = 0, _arr = [path, "".concat(path, ".json")]; _i3 < _arr.length; _i3++) {
|
|
2111
|
+
var candidate = _arr[_i3];
|
|
2112
|
+
if (candidate in files) return candidate;
|
|
2113
|
+
}
|
|
2114
|
+
return null;
|
|
1931
2115
|
}
|
|
2116
|
+
|
|
1932
2117
|
/**
|
|
1933
|
-
*
|
|
2118
|
+
* A project's `val.modules.ts`, bundled to run: every `.val.ts` it imports,
|
|
2119
|
+
* the `val.config` they share and the `.val.json` entries they name, as ONE
|
|
2120
|
+
* ES module -- so it can be imported from a `blob:` URL, which cannot resolve
|
|
2121
|
+
* a relative chunk -- with every npm import pointing at the site's own
|
|
2122
|
+
* vendor chunks, at absolute URLs under `origin`.
|
|
1934
2123
|
*
|
|
1935
|
-
*
|
|
1936
|
-
*
|
|
2124
|
+
* What the builder tab evaluates to learn a tree's schemas: Update from the
|
|
2125
|
+
* site with code (valbuild/home `docs/hosted-publishing.md` step 8.2, slice
|
|
2126
|
+
* 1b). The project's own `@valbuild/*` and dependencies are what run, as the
|
|
2127
|
+
* site runs them -- the browser half of its layer, from `/_pvendor/<rev>/`,
|
|
2128
|
+
* and the base layer from `/_vendor/`. Whoever imports it should do so off
|
|
2129
|
+
* the Studio's page: `@valbuild/tanstack` brings React and patches its JSX.
|
|
2130
|
+
*
|
|
2131
|
+
* Nothing else of a build happens here: no route splitting, no server
|
|
2132
|
+
* functions, no CSS -- a `.val.ts` has none of it.
|
|
1937
2133
|
*/
|
|
1938
|
-
function
|
|
1939
|
-
return
|
|
2134
|
+
function bundleValModules(_x) {
|
|
2135
|
+
return _bundleValModules.apply(this, arguments);
|
|
1940
2136
|
}
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
2137
|
+
|
|
2138
|
+
/**
|
|
2139
|
+
* For each module file (`*.val.ts` / `*.val.js`) the graph reaches, every
|
|
2140
|
+
* project file it depends on, transitively, sorted: what tells Val's server
|
|
2141
|
+
* at a proposal's address that a module whose own file is not staged is of
|
|
2142
|
+
* code the build was not made of, through a file it imports
|
|
2143
|
+
* (`moduleDependencies`, `stagedAfterBuild` in `@valbuild/server`). From the
|
|
2144
|
+
* imports as this bundle resolved them -- relative, tsconfig aliases,
|
|
2145
|
+
* whatever resolved -- so it cannot disagree with what the build evaluated.
|
|
2146
|
+
* An entry's `.val.json` is left out: it is content, and a record of 10,000
|
|
2147
|
+
* entries would make the map that long.
|
|
2148
|
+
*/
|
|
2149
|
+
function _bundleValModules() {
|
|
2150
|
+
_bundleValModules = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(input) {
|
|
2151
|
+
var _input$entry;
|
|
2152
|
+
var files, target, origin, entry, warnings, aliases, base, project, entryPath, resolveProjectPath, imports, _yield$loadRolldown, build, result, resolveOne, chunks, _t;
|
|
2153
|
+
return _regenerator().w(function (_context) {
|
|
2154
|
+
while (1) switch (_context.p = _context.n) {
|
|
2155
|
+
case 0:
|
|
2156
|
+
resolveOne = function _resolveOne(source, importer) {
|
|
2157
|
+
if (source.startsWith(".")) {
|
|
2158
|
+
return resolveProjectPath(resolve(dirname(importer !== null && importer !== void 0 ? importer : entryPath), 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 _iterator4 = _createForOfIteratorHelper(aliases.candidates(source)),
|
|
2180
|
+
_step4;
|
|
2181
|
+
try {
|
|
2182
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
2183
|
+
var candidate = _step4.value;
|
|
2184
|
+
var _hit = resolveProjectPath(candidate);
|
|
2185
|
+
if (_hit) return _hit;
|
|
2186
|
+
}
|
|
2187
|
+
} catch (err) {
|
|
2188
|
+
_iterator4.e(err);
|
|
2189
|
+
} finally {
|
|
2190
|
+
_iterator4.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
|
+
files = input.files, target = input.target, origin = input.origin;
|
|
2201
|
+
entry = (_input$entry = input.entry) !== null && _input$entry !== void 0 ? _input$entry : ["val.modules.ts", "val.modules.js"].find(function (path) {
|
|
2202
|
+
return path in files;
|
|
2203
|
+
});
|
|
2204
|
+
if (!(entry === undefined || !(entry in files))) {
|
|
2205
|
+
_context.n = 1;
|
|
2206
|
+
break;
|
|
2207
|
+
}
|
|
2208
|
+
throw new Error("This project has no val.modules.ts, so its Val modules cannot be read.");
|
|
2209
|
+
case 1:
|
|
2210
|
+
warnings = [];
|
|
2211
|
+
aliases = aliasMap(files, function (message) {
|
|
2212
|
+
return warnings.push(message);
|
|
2213
|
+
});
|
|
2214
|
+
base = "".concat(origin, "/_vendor/");
|
|
2215
|
+
project = target.project.rev === null ? null : "".concat(origin, "/_pvendor/").concat(target.project.rev, "/");
|
|
2216
|
+
entryPath = entry;
|
|
2217
|
+
resolveProjectPath = function resolveProjectPath(path) {
|
|
2218
|
+
return resolveInFiles(path, files);
|
|
2219
|
+
};
|
|
2220
|
+
/** Which project file imports which, as resolved: one edge per import. */
|
|
2221
|
+
imports = new Map();
|
|
2222
|
+
_context.n = 2;
|
|
2223
|
+
return loadRolldown();
|
|
2224
|
+
case 2:
|
|
2225
|
+
_yield$loadRolldown = _context.v;
|
|
2226
|
+
build = _yield$loadRolldown.build;
|
|
2227
|
+
_context.p = 3;
|
|
2228
|
+
_context.n = 4;
|
|
2229
|
+
return build({
|
|
2230
|
+
input: entry,
|
|
2231
|
+
// See `buildOnce`: required in the browser, inert here.
|
|
2232
|
+
cwd: "/",
|
|
2233
|
+
moduleTypes: {
|
|
2234
|
+
".css": "empty"
|
|
2235
|
+
},
|
|
2236
|
+
plugins: [{
|
|
2237
|
+
name: "val:modules",
|
|
2238
|
+
resolveId: function resolveId(source, importer) {
|
|
2239
|
+
var resolved = resolveOne(source, importer);
|
|
2240
|
+
// A project file importing a project file: an edge of the graph
|
|
2241
|
+
// the dependencies are read from.
|
|
2242
|
+
if (importer !== undefined && importer in files && typeof resolved === "string" && resolved in files) {
|
|
2243
|
+
var from = imports.get(importer);
|
|
2244
|
+
if (from === undefined) {
|
|
2245
|
+
from = new Set();
|
|
2246
|
+
imports.set(importer, from);
|
|
2247
|
+
}
|
|
2248
|
+
from.add(resolved);
|
|
2249
|
+
}
|
|
2250
|
+
return resolved;
|
|
2251
|
+
},
|
|
2252
|
+
load: function load(id) {
|
|
2253
|
+
return id in files ? files[id] : null;
|
|
2254
|
+
}
|
|
2255
|
+
}],
|
|
2256
|
+
transform: {
|
|
2257
|
+
jsx: {
|
|
2258
|
+
runtime: "automatic",
|
|
2259
|
+
importSource: "react"
|
|
2260
|
+
}
|
|
2261
|
+
},
|
|
2262
|
+
output: {
|
|
2263
|
+
format: "esm",
|
|
2264
|
+
minify: false,
|
|
2265
|
+
// One module: `def: () => import("./x.val")` stays a dynamic import of
|
|
2266
|
+
// something already in the file.
|
|
2267
|
+
codeSplitting: false
|
|
2268
|
+
},
|
|
2269
|
+
write: false
|
|
2270
|
+
});
|
|
2271
|
+
case 4:
|
|
2272
|
+
result = _context.v;
|
|
2273
|
+
_context.n = 6;
|
|
2274
|
+
break;
|
|
2275
|
+
case 5:
|
|
2276
|
+
_context.p = 5;
|
|
2277
|
+
_t = _context.v;
|
|
2278
|
+
throw new Error(["The Val modules could not be bundled."].concat(warnings, [_t instanceof Error ? _t.message : String(_t)]).join("\n"), {
|
|
2279
|
+
cause: _t
|
|
2280
|
+
});
|
|
2281
|
+
case 6:
|
|
2282
|
+
chunks = result.output.filter(function (output) {
|
|
2283
|
+
return output.type === "chunk";
|
|
2284
|
+
});
|
|
2285
|
+
if (!(chunks.length !== 1)) {
|
|
2286
|
+
_context.n = 7;
|
|
2287
|
+
break;
|
|
2288
|
+
}
|
|
2289
|
+
throw new Error("Bundling the Val modules made ".concat(chunks.length, " chunks rather than one."));
|
|
2290
|
+
case 7:
|
|
2291
|
+
return _context.a(2, {
|
|
2292
|
+
code: chunks[0].code,
|
|
2293
|
+
dependencies: moduleDependenciesOf(imports)
|
|
2294
|
+
});
|
|
2295
|
+
}
|
|
2296
|
+
}, _callee, null, [[3, 5]]);
|
|
2297
|
+
}));
|
|
2298
|
+
return _bundleValModules.apply(this, arguments);
|
|
2299
|
+
}
|
|
2300
|
+
function moduleDependenciesOf(imports) {
|
|
2301
|
+
var dependencies = {};
|
|
2302
|
+
var isModule = function isModule(path) {
|
|
2303
|
+
return /\.val\.(ts|js)$/.test(path);
|
|
2304
|
+
};
|
|
2305
|
+
var isEntry = function isEntry(path) {
|
|
2306
|
+
return path.endsWith(".val.json");
|
|
2307
|
+
};
|
|
2308
|
+
var modules = new Set();
|
|
2309
|
+
var _iterator = _createForOfIteratorHelper(imports),
|
|
2310
|
+
_step;
|
|
2311
|
+
try {
|
|
2312
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
2313
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
2314
|
+
from = _step$value[0],
|
|
2315
|
+
to = _step$value[1];
|
|
2316
|
+
if (isModule(from)) modules.add(from);
|
|
2317
|
+
var _iterator3 = _createForOfIteratorHelper(to),
|
|
2318
|
+
_step3;
|
|
2319
|
+
try {
|
|
2320
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
2321
|
+
var path = _step3.value;
|
|
2322
|
+
if (isModule(path)) modules.add(path);
|
|
2323
|
+
}
|
|
2324
|
+
} catch (err) {
|
|
2325
|
+
_iterator3.e(err);
|
|
2326
|
+
} finally {
|
|
2327
|
+
_iterator3.f();
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
} catch (err) {
|
|
2331
|
+
_iterator.e(err);
|
|
2332
|
+
} finally {
|
|
2333
|
+
_iterator.f();
|
|
2334
|
+
}
|
|
2335
|
+
var _iterator2 = _createForOfIteratorHelper(_toConsumableArray(modules).sort()),
|
|
2336
|
+
_step2;
|
|
2337
|
+
try {
|
|
2338
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
2339
|
+
var _imports$get;
|
|
2340
|
+
var module = _step2.value;
|
|
2341
|
+
var seen = new Set();
|
|
2342
|
+
var queue = _toConsumableArray((_imports$get = imports.get(module)) !== null && _imports$get !== void 0 ? _imports$get : []);
|
|
2343
|
+
while (queue.length > 0) {
|
|
2344
|
+
var _imports$get2;
|
|
2345
|
+
var next = queue.pop();
|
|
2346
|
+
if (next === module || seen.has(next) || isEntry(next)) continue;
|
|
2347
|
+
seen.add(next);
|
|
2348
|
+
queue.push.apply(queue, _toConsumableArray((_imports$get2 = imports.get(next)) !== null && _imports$get2 !== void 0 ? _imports$get2 : []));
|
|
2349
|
+
}
|
|
2350
|
+
dependencies[module] = _toConsumableArray(seen).sort();
|
|
2351
|
+
}
|
|
2352
|
+
} catch (err) {
|
|
2353
|
+
_iterator2.e(err);
|
|
2354
|
+
} finally {
|
|
2355
|
+
_iterator2.f();
|
|
2356
|
+
}
|
|
2357
|
+
return dependencies;
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
/**
|
|
2361
|
+
* A build's `val.modules` registry, as the build emits it beside its client
|
|
2362
|
+
* chunks: `{ "val-modules-<build>.js": code }`, served at `/_app/` with
|
|
2363
|
+
* them, its npm imports pointing at the site's vendor chunks on its own
|
|
2364
|
+
* origin (`/_vendor/`, `/_pvendor/<rev>/`) as the client bundle's do.
|
|
2365
|
+
*
|
|
2366
|
+
* What a Studio opened on an older build imports, once the server's
|
|
2367
|
+
* manifest names it (`registry`, from the build's name the platform hands
|
|
2368
|
+
* the server: `VAL_BUILD`), to take this build's schemas in WITHOUT
|
|
2369
|
+
* reloading the page: `HostStore.reloadCode` in `@valbuild/ui`, and phase 9
|
|
2370
|
+
* of `docs/plans/one-content-model.md` in valbuild/val.
|
|
2371
|
+
*
|
|
2372
|
+
* Empty -- and the build goes on -- for a project with no `val.modules.ts`,
|
|
2373
|
+
* or one whose Val modules cannot be bundled for the browser (a `.val.ts`
|
|
2374
|
+
* importing something server-only): such a build has no entry, and a Studio
|
|
2375
|
+
* that cannot import one reloads the page instead, as it did before. Said
|
|
2376
|
+
* in the build's warnings.
|
|
2377
|
+
*/
|
|
2378
|
+
function valModulesEntry(_x2, _x3, _x4) {
|
|
2379
|
+
return _valModulesEntry.apply(this, arguments);
|
|
2380
|
+
}
|
|
2381
|
+
function _valModulesEntry() {
|
|
2382
|
+
_valModulesEntry = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(input, build, warnings) {
|
|
2383
|
+
var entry, _yield$bundleValModul, code, dependencies, _t2;
|
|
2384
|
+
return _regenerator().w(function (_context2) {
|
|
2385
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
2386
|
+
case 0:
|
|
2387
|
+
entry = ["val.modules.ts", "val.modules.js"].find(function (path) {
|
|
2388
|
+
return path in input.files;
|
|
2389
|
+
});
|
|
2390
|
+
if (!(entry === undefined)) {
|
|
2391
|
+
_context2.n = 1;
|
|
2392
|
+
break;
|
|
2393
|
+
}
|
|
2394
|
+
return _context2.a(2, {
|
|
2395
|
+
files: {},
|
|
2396
|
+
dependencies: null
|
|
2397
|
+
});
|
|
2398
|
+
case 1:
|
|
2399
|
+
_context2.p = 1;
|
|
2400
|
+
_context2.n = 2;
|
|
2401
|
+
return bundleValModules({
|
|
2402
|
+
files: input.files,
|
|
2403
|
+
target: input.target,
|
|
2404
|
+
// Root-relative, as the client bundle names its vendor chunks: the
|
|
2405
|
+
// entry is served on the site's own origin.
|
|
2406
|
+
origin: "",
|
|
2407
|
+
entry: entry
|
|
2408
|
+
});
|
|
2409
|
+
case 2:
|
|
2410
|
+
_yield$bundleValModul = _context2.v;
|
|
2411
|
+
code = _yield$bundleValModul.code;
|
|
2412
|
+
dependencies = _yield$bundleValModul.dependencies;
|
|
2413
|
+
return _context2.a(2, {
|
|
2414
|
+
files: _defineProperty({}, valModulesEntryFile(build), code),
|
|
2415
|
+
dependencies: dependencies
|
|
2416
|
+
});
|
|
2417
|
+
case 3:
|
|
2418
|
+
_context2.p = 3;
|
|
2419
|
+
_t2 = _context2.v;
|
|
2420
|
+
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)));
|
|
2421
|
+
return _context2.a(2, {
|
|
2422
|
+
files: {},
|
|
2423
|
+
dependencies: null
|
|
2424
|
+
});
|
|
2425
|
+
}
|
|
2426
|
+
}, _callee2, null, [[1, 3]]);
|
|
2427
|
+
}));
|
|
2428
|
+
return _valModulesEntry.apply(this, arguments);
|
|
2429
|
+
}
|
|
2430
|
+
|
|
2431
|
+
/** Cheap pre-filter: skip the parse unless one of these appears in the source. */
|
|
2432
|
+
var MARKERS = ["createIsomorphicFn", "createServerOnlyFn", "createClientOnlyFn", "createMiddleware", "ClientOnly"];
|
|
2433
|
+
|
|
2434
|
+
/** Walks a `foo().bar().baz()` chain down to its root callee identifier. */
|
|
2435
|
+
function chainRoot(node) {
|
|
2436
|
+
var current = node;
|
|
2437
|
+
while (current) {
|
|
2438
|
+
if (current.type === "CallExpression") {
|
|
2439
|
+
var callee = current.callee;
|
|
2440
|
+
if ((callee === null || callee === void 0 ? void 0 : callee.type) === "Identifier") return String(callee.name);
|
|
2441
|
+
if ((callee === null || callee === void 0 ? void 0 : callee.type) === "MemberExpression") {
|
|
2442
|
+
current = callee.object;
|
|
2443
|
+
continue;
|
|
2444
|
+
}
|
|
2445
|
+
return null;
|
|
2446
|
+
}
|
|
2447
|
+
return null;
|
|
2448
|
+
}
|
|
2449
|
+
return null;
|
|
2450
|
+
}
|
|
2451
|
+
|
|
2452
|
+
/**
|
|
2453
|
+
* True when this call is the whole chain rather than a link in a longer one.
|
|
2454
|
+
*
|
|
2455
|
+
* Without this, `createIsomorphicFn().client(a).server(b)` matches three times
|
|
2456
|
+
* and the inner replacements land inside text the outer one is about to
|
|
2457
|
+
* replace.
|
|
2458
|
+
*/
|
|
2459
|
+
function isOutermost(node, stack) {
|
|
2460
|
+
var parent = stack[stack.length - 1];
|
|
2461
|
+
var grandparent = stack[stack.length - 2];
|
|
2462
|
+
return !((parent === null || parent === void 0 ? void 0 : parent.type) === "MemberExpression" && parent.object === node && (grandparent === null || grandparent === void 0 ? void 0 : grandparent.type) === "CallExpression");
|
|
2463
|
+
}
|
|
2464
|
+
|
|
2465
|
+
/** Collects `.method(arg)` calls along a chain, nearest-root first. */
|
|
2466
|
+
function methodsOf(node) {
|
|
2467
|
+
var found = new Map();
|
|
2468
|
+
var current = node;
|
|
2469
|
+
while (((_current = current) === null || _current === void 0 ? void 0 : _current.type) === "CallExpression") {
|
|
2470
|
+
var _current, _name, _callee$property, _current$arguments;
|
|
2471
|
+
var callee = current.callee;
|
|
2472
|
+
if ((callee === null || callee === void 0 ? void 0 : callee.type) !== "MemberExpression") break;
|
|
2473
|
+
var name = String((_name = (_callee$property = callee.property) === null || _callee$property === void 0 ? void 0 : _callee$property.name) !== null && _name !== void 0 ? _name : "");
|
|
2474
|
+
// Nearest-to-root wins, so a later duplicate does not shadow the first.
|
|
2475
|
+
found.set(name, {
|
|
2476
|
+
call: current,
|
|
2477
|
+
arg: (_current$arguments = current.arguments) === null || _current$arguments === void 0 ? void 0 : _current$arguments[0],
|
|
2478
|
+
objectEnd: callee.object.end
|
|
2479
|
+
});
|
|
2480
|
+
current = callee.object;
|
|
2481
|
+
}
|
|
2482
|
+
return found;
|
|
2483
|
+
}
|
|
2484
|
+
/**
|
|
2485
|
+
* Rewrites the environment markers in one module for one target.
|
|
2486
|
+
*
|
|
2487
|
+
* Returns `null` when the module contains none, so the caller leaves it alone
|
|
2488
|
+
* and pays no parse.
|
|
2489
|
+
*/
|
|
2490
|
+
function transformEnvMarkers(_x, _x2, _x3) {
|
|
2491
|
+
return _transformEnvMarkers.apply(this, arguments);
|
|
2492
|
+
}
|
|
2493
|
+
function _transformEnvMarkers() {
|
|
2494
|
+
_transformEnvMarkers = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(moduleId, code, target) {
|
|
2495
|
+
var ast, imported, edits, applied, text;
|
|
2496
|
+
return _regenerator().w(function (_context) {
|
|
2497
|
+
while (1) switch (_context.n) {
|
|
2498
|
+
case 0:
|
|
2499
|
+
if (MARKERS.some(function (marker) {
|
|
1948
2500
|
return code.includes(marker);
|
|
1949
2501
|
})) {
|
|
1950
2502
|
_context.n = 1;
|
|
@@ -2666,273 +3218,92 @@ function deleteProperties(code, properties, doomed) {
|
|
|
2666
3218
|
});
|
|
2667
3219
|
}
|
|
2668
3220
|
i = j;
|
|
2669
|
-
}
|
|
2670
|
-
return edits;
|
|
2671
|
-
}
|
|
2672
|
-
|
|
2673
|
-
/**
|
|
2674
|
-
* Removes server-only route options from one module.
|
|
2675
|
-
*
|
|
2676
|
-
* Returns `null` when there is nothing to do, so the caller pays no parse.
|
|
2677
|
-
* Server and rsc targets always get `null`: they are the ones that need these.
|
|
2678
|
-
*/
|
|
2679
|
-
function transformRouteNodes(_x, _x2, _x3) {
|
|
2680
|
-
return _transformRouteNodes.apply(this, arguments);
|
|
2681
|
-
}
|
|
2682
|
-
function _transformRouteNodes() {
|
|
2683
|
-
_transformRouteNodes = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(moduleId, code, target) {
|
|
2684
|
-
var ast, imported, edits, removed;
|
|
2685
|
-
return _regenerator().w(function (_context) {
|
|
2686
|
-
while (1) switch (_context.n) {
|
|
2687
|
-
case 0:
|
|
2688
|
-
if (!(target !== "client")) {
|
|
2689
|
-
_context.n = 1;
|
|
2690
|
-
break;
|
|
2691
|
-
}
|
|
2692
|
-
return _context.a(2, null);
|
|
2693
|
-
case 1:
|
|
2694
|
-
if (shouldRun(code)) {
|
|
2695
|
-
_context.n = 2;
|
|
2696
|
-
break;
|
|
2697
|
-
}
|
|
2698
|
-
return _context.a(2, null);
|
|
2699
|
-
case 2:
|
|
2700
|
-
_context.n = 3;
|
|
2701
|
-
return parse(moduleId, code);
|
|
2702
|
-
case 3:
|
|
2703
|
-
ast = _context.v;
|
|
2704
|
-
imported = tanstackImports(ast);
|
|
2705
|
-
if (!(imported.size === 0)) {
|
|
2706
|
-
_context.n = 4;
|
|
2707
|
-
break;
|
|
2708
|
-
}
|
|
2709
|
-
return _context.a(2, null);
|
|
2710
|
-
case 4:
|
|
2711
|
-
edits = [];
|
|
2712
|
-
removed = [];
|
|
2713
|
-
walk(ast, function (node, stack) {
|
|
2714
|
-
var _options$properties;
|
|
2715
|
-
if (node.type !== "CallExpression") return;
|
|
2716
|
-
var callee = node.callee;
|
|
2717
|
-
if ((callee === null || callee === void 0 ? void 0 : callee.type) !== "Identifier") return;
|
|
2718
|
-
var name = String(callee.name);
|
|
2719
|
-
if (!ROUTE_FNS.has(name) || !imported.has(name)) return;
|
|
2720
|
-
var options = routeOptionsOf(node, stack);
|
|
2721
|
-
if (!options) return;
|
|
2722
|
-
var properties = (_options$properties = options.properties) !== null && _options$properties !== void 0 ? _options$properties : [];
|
|
2723
|
-
var doomed = new Set();
|
|
2724
|
-
var _iterator = _createForOfIteratorHelper(properties),
|
|
2725
|
-
_step;
|
|
2726
|
-
try {
|
|
2727
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
2728
|
-
var property = _step.value;
|
|
2729
|
-
var key = propertyName(property);
|
|
2730
|
-
if (!key || !SERVER_ONLY_OPTIONS.has(key)) continue;
|
|
2731
|
-
doomed.add(property);
|
|
2732
|
-
removed.push(key);
|
|
2733
|
-
}
|
|
2734
|
-
} catch (err) {
|
|
2735
|
-
_iterator.e(err);
|
|
2736
|
-
} finally {
|
|
2737
|
-
_iterator.f();
|
|
2738
|
-
}
|
|
2739
|
-
if (doomed.size) edits.push.apply(edits, _toConsumableArray(deleteProperties(code, properties, doomed)));
|
|
2740
|
-
});
|
|
2741
|
-
if (!(edits.length === 0)) {
|
|
2742
|
-
_context.n = 5;
|
|
2743
|
-
break;
|
|
2744
|
-
}
|
|
2745
|
-
return _context.a(2, null);
|
|
2746
|
-
case 5:
|
|
2747
|
-
return _context.a(2, {
|
|
2748
|
-
code: applyEdits(code, edits),
|
|
2749
|
-
removed: removed
|
|
2750
|
-
});
|
|
2751
|
-
}
|
|
2752
|
-
}, _callee);
|
|
2753
|
-
}));
|
|
2754
|
-
return _transformRouteNodes.apply(this, arguments);
|
|
2755
|
-
}
|
|
2756
|
-
|
|
2757
|
-
/**
|
|
2758
|
-
* JSON with comments and trailing commas, which is what tsconfig.json is.
|
|
2759
|
-
*
|
|
2760
|
-
* Written as a scanner rather than a regex on purpose: `"url": "https://x"`
|
|
2761
|
-
* contains `//`, and a regex that strips comments without tracking string state
|
|
2762
|
-
* truncates the file there and throws a parse error pointing at the wrong line.
|
|
2763
|
-
*/
|
|
2764
|
-
function parseJsonc(text) {
|
|
2765
|
-
var out = "";
|
|
2766
|
-
var i = 0;
|
|
2767
|
-
while (i < text.length) {
|
|
2768
|
-
var ch = text[i];
|
|
2769
|
-
if (ch === '"') {
|
|
2770
|
-
// Copy the whole string literal, escapes included, untouched.
|
|
2771
|
-
out += ch;
|
|
2772
|
-
i++;
|
|
2773
|
-
while (i < text.length) {
|
|
2774
|
-
var c = text[i];
|
|
2775
|
-
out += c;
|
|
2776
|
-
i++;
|
|
2777
|
-
if (c === "\\") {
|
|
2778
|
-
if (i < text.length) out += text[i++];
|
|
2779
|
-
continue;
|
|
2780
|
-
}
|
|
2781
|
-
if (c === '"') break;
|
|
2782
|
-
}
|
|
2783
|
-
continue;
|
|
2784
|
-
}
|
|
2785
|
-
if (ch === "/" && text[i + 1] === "/") {
|
|
2786
|
-
while (i < text.length && text[i] !== "\n") i++;
|
|
2787
|
-
continue;
|
|
2788
|
-
}
|
|
2789
|
-
if (ch === "/" && text[i + 1] === "*") {
|
|
2790
|
-
i += 2;
|
|
2791
|
-
while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) i++;
|
|
2792
|
-
i += 2;
|
|
2793
|
-
continue;
|
|
2794
|
-
}
|
|
2795
|
-
out += ch;
|
|
2796
|
-
i++;
|
|
2797
|
-
}
|
|
2798
|
-
// Trailing commas, now that every remaining comma is structural.
|
|
2799
|
-
return JSON.parse(out.replace(/,(\s*[}\]])/g, "$1"));
|
|
2800
|
-
}
|
|
2801
|
-
|
|
2802
|
-
/** One `paths` entry, pre-split on its wildcard. */
|
|
2803
|
-
|
|
2804
|
-
/**
|
|
2805
|
-
* Reads tsconfig.json out of the file record and builds the matcher.
|
|
2806
|
-
*
|
|
2807
|
-
* Returns null when the project configures no aliases, which is the common
|
|
2808
|
-
* case and costs nothing.
|
|
2809
|
-
*/
|
|
2810
|
-
function aliasMap(files, warn) {
|
|
2811
|
-
var _config$compilerOptio, _config$compilerOptio2;
|
|
2812
|
-
var entry = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "tsconfig.json";
|
|
2813
|
-
var config = readConfig(files, entry, warn, new Set());
|
|
2814
|
-
var paths = config === null || config === void 0 || (_config$compilerOptio = config.compilerOptions) === null || _config$compilerOptio === void 0 ? void 0 : _config$compilerOptio.paths;
|
|
2815
|
-
var baseUrl = config === null || config === void 0 || (_config$compilerOptio2 = config.compilerOptions) === null || _config$compilerOptio2 === void 0 ? void 0 : _config$compilerOptio2.baseUrl;
|
|
2816
|
-
// A project can configure either one without the other, and baseUrl alone is
|
|
2817
|
-
// enough to change how a bare specifier resolves.
|
|
2818
|
-
if ((!paths || Object.keys(paths).length === 0) && baseUrl === undefined) return null;
|
|
2819
|
-
|
|
2820
|
-
// `baseUrl` is relative to the tsconfig that declared it. Since TS 4.1 paths
|
|
2821
|
-
// work without one, resolved against the tsconfig's own directory -- so the
|
|
2822
|
-
// fallback here is the directory, not the project root.
|
|
2823
|
-
var base = resolve(dirname(entry), baseUrl !== null && baseUrl !== void 0 ? baseUrl : ".");
|
|
2824
|
-
var patterns = [];
|
|
2825
|
-
for (var _i = 0, _Object$entries = Object.entries(paths !== null && paths !== void 0 ? paths : {}); _i < _Object$entries.length; _i++) {
|
|
2826
|
-
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
2827
|
-
pattern = _Object$entries$_i[0],
|
|
2828
|
-
targets = _Object$entries$_i[1];
|
|
2829
|
-
var star = pattern.indexOf("*");
|
|
2830
|
-
if (star !== pattern.lastIndexOf("*")) {
|
|
2831
|
-
warn("tsconfig paths pattern '".concat(pattern, "' has more than one '*' and is ignored."));
|
|
2832
|
-
continue;
|
|
2833
|
-
}
|
|
2834
|
-
patterns.push({
|
|
2835
|
-
prefix: star === -1 ? pattern : pattern.slice(0, star),
|
|
2836
|
-
suffix: star === -1 ? "" : pattern.slice(star + 1),
|
|
2837
|
-
wildcard: star !== -1,
|
|
2838
|
-
targets: targets.map(function (target) {
|
|
2839
|
-
return resolve(base, target);
|
|
2840
|
-
})
|
|
2841
|
-
});
|
|
2842
|
-
}
|
|
2843
|
-
|
|
2844
|
-
// TypeScript picks the pattern with the longest literal prefix, so `@/ui/*`
|
|
2845
|
-
// beats `@/*` for `@/ui/card` regardless of declaration order.
|
|
2846
|
-
patterns.sort(function (a, b) {
|
|
2847
|
-
return b.prefix.length - a.prefix.length;
|
|
2848
|
-
});
|
|
2849
|
-
return {
|
|
2850
|
-
patterns: Object.keys(paths !== null && paths !== void 0 ? paths : {}),
|
|
2851
|
-
baseUrlCandidate: function baseUrlCandidate(specifier) {
|
|
2852
|
-
return baseUrl === undefined ? null : resolve(base, specifier);
|
|
2853
|
-
},
|
|
2854
|
-
candidates: function candidates(specifier) {
|
|
2855
|
-
var _loop = function _loop() {
|
|
2856
|
-
var pattern = _patterns[_i2];
|
|
2857
|
-
if (!pattern.wildcard) {
|
|
2858
|
-
if (specifier === pattern.prefix) return {
|
|
2859
|
-
v: _toConsumableArray(pattern.targets)
|
|
2860
|
-
};
|
|
2861
|
-
return 0; // continue
|
|
2862
|
-
}
|
|
2863
|
-
if (!specifier.startsWith(pattern.prefix) || !specifier.endsWith(pattern.suffix) || specifier.length < pattern.prefix.length + pattern.suffix.length) {
|
|
2864
|
-
return 0; // continue
|
|
2865
|
-
}
|
|
2866
|
-
var matched = specifier.slice(pattern.prefix.length, specifier.length - pattern.suffix.length);
|
|
2867
|
-
return {
|
|
2868
|
-
v: pattern.targets.map(function (target) {
|
|
2869
|
-
return target.replace("*", matched);
|
|
2870
|
-
})
|
|
2871
|
-
};
|
|
2872
|
-
},
|
|
2873
|
-
_ret;
|
|
2874
|
-
for (var _i2 = 0, _patterns = patterns; _i2 < _patterns.length; _i2++) {
|
|
2875
|
-
_ret = _loop();
|
|
2876
|
-
if (_ret === 0) continue;
|
|
2877
|
-
if (_ret) return _ret.v;
|
|
2878
|
-
}
|
|
2879
|
-
return [];
|
|
2880
|
-
}
|
|
2881
|
-
};
|
|
2882
|
-
}
|
|
2883
|
-
|
|
2884
|
-
/** Follows `extends` through the file record. Package extends cannot be read. */
|
|
2885
|
-
function readConfig(files, path, warn, seen) {
|
|
2886
|
-
var _config, _config$compilerOptio4, _config$compilerOptio5, _parent$compilerOptio;
|
|
2887
|
-
if (seen.has(path)) return null; // a cycle; whatever we have is enough
|
|
2888
|
-
seen.add(path);
|
|
2889
|
-
var text = files[path];
|
|
2890
|
-
if (text === undefined) return null;
|
|
2891
|
-
var config;
|
|
2892
|
-
try {
|
|
2893
|
-
config = parseJsonc(text);
|
|
2894
|
-
} catch (error) {
|
|
2895
|
-
var _message;
|
|
2896
|
-
warn("Could not parse ".concat(path, ": ").concat(String((_message = error === null || error === void 0 ? void 0 : error.message) !== null && _message !== void 0 ? _message : error)));
|
|
2897
|
-
return null;
|
|
2898
|
-
}
|
|
2899
|
-
if (!((_config = config) !== null && _config !== void 0 && _config["extends"])) return config;
|
|
2900
|
-
|
|
2901
|
-
// Only a relative extends can be followed: a package one ("extends":
|
|
2902
|
-
// "@tsconfig/node20/tsconfig.json") lives in node_modules, which a browser
|
|
2903
|
-
// build does not have. Worth saying out loud rather than silently resolving
|
|
2904
|
-
// half the aliases, because the base config is where a monorepo usually puts
|
|
2905
|
-
// them.
|
|
2906
|
-
if (!config["extends"].startsWith(".")) {
|
|
2907
|
-
var _config$compilerOptio3;
|
|
2908
|
-
if (!((_config$compilerOptio3 = config.compilerOptions) !== null && _config$compilerOptio3 !== void 0 && _config$compilerOptio3.paths)) {
|
|
2909
|
-
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."));
|
|
2910
|
-
}
|
|
2911
|
-
return config;
|
|
2912
|
-
}
|
|
2913
|
-
var parentPath = resolveConfigPath(files, resolve(dirname(path), config["extends"]));
|
|
2914
|
-
var parent = parentPath ? readConfig(files, parentPath, warn, seen) : null;
|
|
2915
|
-
if (!parent) return config;
|
|
2916
|
-
|
|
2917
|
-
// The child wins, and `paths` replaces rather than merges -- which is what
|
|
2918
|
-
// TypeScript does.
|
|
2919
|
-
return {
|
|
2920
|
-
compilerOptions: _objectSpread2(_objectSpread2(_objectSpread2({}, parent.compilerOptions), config.compilerOptions), {}, {
|
|
2921
|
-
// baseUrl in the parent was relative to the *parent*, and readConfig
|
|
2922
|
-
// returns it unresolved, so a parent baseUrl with a child that sets none
|
|
2923
|
-
// is the one case this gets wrong. Rare enough to name rather than model.
|
|
2924
|
-
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
|
|
2925
|
-
})
|
|
2926
|
-
};
|
|
3221
|
+
}
|
|
3222
|
+
return edits;
|
|
2927
3223
|
}
|
|
2928
3224
|
|
|
2929
|
-
/**
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
3225
|
+
/**
|
|
3226
|
+
* Removes server-only route options from one module.
|
|
3227
|
+
*
|
|
3228
|
+
* Returns `null` when there is nothing to do, so the caller pays no parse.
|
|
3229
|
+
* Server and rsc targets always get `null`: they are the ones that need these.
|
|
3230
|
+
*/
|
|
3231
|
+
function transformRouteNodes(_x, _x2, _x3) {
|
|
3232
|
+
return _transformRouteNodes.apply(this, arguments);
|
|
3233
|
+
}
|
|
3234
|
+
function _transformRouteNodes() {
|
|
3235
|
+
_transformRouteNodes = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(moduleId, code, target) {
|
|
3236
|
+
var ast, imported, edits, removed;
|
|
3237
|
+
return _regenerator().w(function (_context) {
|
|
3238
|
+
while (1) switch (_context.n) {
|
|
3239
|
+
case 0:
|
|
3240
|
+
if (!(target !== "client")) {
|
|
3241
|
+
_context.n = 1;
|
|
3242
|
+
break;
|
|
3243
|
+
}
|
|
3244
|
+
return _context.a(2, null);
|
|
3245
|
+
case 1:
|
|
3246
|
+
if (shouldRun(code)) {
|
|
3247
|
+
_context.n = 2;
|
|
3248
|
+
break;
|
|
3249
|
+
}
|
|
3250
|
+
return _context.a(2, null);
|
|
3251
|
+
case 2:
|
|
3252
|
+
_context.n = 3;
|
|
3253
|
+
return parse(moduleId, code);
|
|
3254
|
+
case 3:
|
|
3255
|
+
ast = _context.v;
|
|
3256
|
+
imported = tanstackImports(ast);
|
|
3257
|
+
if (!(imported.size === 0)) {
|
|
3258
|
+
_context.n = 4;
|
|
3259
|
+
break;
|
|
3260
|
+
}
|
|
3261
|
+
return _context.a(2, null);
|
|
3262
|
+
case 4:
|
|
3263
|
+
edits = [];
|
|
3264
|
+
removed = [];
|
|
3265
|
+
walk(ast, function (node, stack) {
|
|
3266
|
+
var _options$properties;
|
|
3267
|
+
if (node.type !== "CallExpression") return;
|
|
3268
|
+
var callee = node.callee;
|
|
3269
|
+
if ((callee === null || callee === void 0 ? void 0 : callee.type) !== "Identifier") return;
|
|
3270
|
+
var name = String(callee.name);
|
|
3271
|
+
if (!ROUTE_FNS.has(name) || !imported.has(name)) return;
|
|
3272
|
+
var options = routeOptionsOf(node, stack);
|
|
3273
|
+
if (!options) return;
|
|
3274
|
+
var properties = (_options$properties = options.properties) !== null && _options$properties !== void 0 ? _options$properties : [];
|
|
3275
|
+
var doomed = new Set();
|
|
3276
|
+
var _iterator = _createForOfIteratorHelper(properties),
|
|
3277
|
+
_step;
|
|
3278
|
+
try {
|
|
3279
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
3280
|
+
var property = _step.value;
|
|
3281
|
+
var key = propertyName(property);
|
|
3282
|
+
if (!key || !SERVER_ONLY_OPTIONS.has(key)) continue;
|
|
3283
|
+
doomed.add(property);
|
|
3284
|
+
removed.push(key);
|
|
3285
|
+
}
|
|
3286
|
+
} catch (err) {
|
|
3287
|
+
_iterator.e(err);
|
|
3288
|
+
} finally {
|
|
3289
|
+
_iterator.f();
|
|
3290
|
+
}
|
|
3291
|
+
if (doomed.size) edits.push.apply(edits, _toConsumableArray(deleteProperties(code, properties, doomed)));
|
|
3292
|
+
});
|
|
3293
|
+
if (!(edits.length === 0)) {
|
|
3294
|
+
_context.n = 5;
|
|
3295
|
+
break;
|
|
3296
|
+
}
|
|
3297
|
+
return _context.a(2, null);
|
|
3298
|
+
case 5:
|
|
3299
|
+
return _context.a(2, {
|
|
3300
|
+
code: applyEdits(code, edits),
|
|
3301
|
+
removed: removed
|
|
3302
|
+
});
|
|
3303
|
+
}
|
|
3304
|
+
}, _callee);
|
|
3305
|
+
}));
|
|
3306
|
+
return _transformRouteNodes.apply(this, arguments);
|
|
2936
3307
|
}
|
|
2937
3308
|
|
|
2938
3309
|
// autoCodeSplitting.
|
|
@@ -3459,6 +3830,11 @@ var CSS_URL_ID = "\0platform:css-url";
|
|
|
3459
3830
|
* would be both a leak and, for a real app, enormous.
|
|
3460
3831
|
*/
|
|
3461
3832
|
var PROJECT_SOURCE = "platform:project-source";
|
|
3833
|
+
/**
|
|
3834
|
+
* The global the server build defines as each Val module's project
|
|
3835
|
+
* dependencies (`valModulesEntry`), read by the generated `val.server.ts`.
|
|
3836
|
+
*/
|
|
3837
|
+
var MODULE_DEPENDENCIES_GLOBAL = "globalThis.__VAL_MODULE_DEPENDENCIES__";
|
|
3462
3838
|
var PROJECT_SOURCE_ID = "\0platform:project-source";
|
|
3463
3839
|
var PUBLIC_PREFIX = "PUBLIC_";
|
|
3464
3840
|
var VALID_KEY = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
@@ -3792,19 +4168,40 @@ function projectPlugin(files, projectSource, splitter, cssModules, aliases, asse
|
|
|
3792
4168
|
}
|
|
3793
4169
|
|
|
3794
4170
|
/**
|
|
3795
|
-
*
|
|
4171
|
+
* What `import.meta.env` is in a build: Vite's built-ins, inlined, and the
|
|
4172
|
+
* project's `PUBLIC_` variables, read at RUNTIME.
|
|
4173
|
+
*
|
|
4174
|
+
* Runtime because a hosted project's variables are set in Val Build, and a
|
|
4175
|
+
* build is made in an editor's browser tab: inlined, a value would sit in that
|
|
4176
|
+
* tab, and changing one would wait for somebody to build before it went live.
|
|
4177
|
+
* So `import.meta.env` is an identifier, and `inject` makes each module that
|
|
4178
|
+
* reads it import {@link RUNTIME_ENV_SPECIFIER} -- a real import, so it is
|
|
4179
|
+
* evaluated before any split chunk that reads it, top level included. That
|
|
4180
|
+
* module ({@link runtimeEnvSource}) reads the variables once:
|
|
3796
4181
|
*
|
|
3797
|
-
*
|
|
3798
|
-
*
|
|
3799
|
-
*
|
|
4182
|
+
* - in the browser, from the `<head>` script the platform's loader writes
|
|
4183
|
+
* (`globalThis.__PLATFORM_PUBLIC_ENV`), which runs before any module does;
|
|
4184
|
+
* - on the server, from `process.env`, which the isolate's env fills before the
|
|
4185
|
+
* app's modules run.
|
|
3800
4186
|
*
|
|
3801
|
-
*
|
|
3802
|
-
*
|
|
3803
|
-
*
|
|
4187
|
+
* Only `PUBLIC_` names, on both sides, as in Vite: a secret is
|
|
4188
|
+
* `process.env.NAME` on the server and nothing at all in the browser. The
|
|
4189
|
+
* platform refuses a secret by a `PUBLIC_` name, so nothing read here was ever
|
|
4190
|
+
* a secret.
|
|
4191
|
+
*
|
|
4192
|
+
* `env`, when a caller passes it, is still inlined as literals and wins -- the
|
|
4193
|
+
* CLI's `--env`, and every build from before this. Non-public keys of it
|
|
4194
|
+
* resolve to `undefined` in the client bundle rather than being left alone.
|
|
3804
4195
|
*/
|
|
3805
|
-
function
|
|
4196
|
+
function envFor(env, target, warnings) {
|
|
3806
4197
|
var define = {};
|
|
3807
|
-
|
|
4198
|
+
/**
|
|
4199
|
+
* What the `import.meta.env` OBJECT holds of `env`: the PUBLIC_ names, on
|
|
4200
|
+
* both sides, as Vite's does. A server-only name is still a literal where it
|
|
4201
|
+
* is read by name (above), and nowhere else -- in the object it would be in
|
|
4202
|
+
* the server bundle whether anything read it or not.
|
|
4203
|
+
*/
|
|
4204
|
+
var inObject = {};
|
|
3808
4205
|
for (var _i = 0, _Object$entries = Object.entries(env); _i < _Object$entries.length; _i++) {
|
|
3809
4206
|
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
3810
4207
|
key = _Object$entries$_i[0],
|
|
@@ -3817,7 +4214,7 @@ function defineFor(env, target, warnings) {
|
|
|
3817
4214
|
var literal = exposed ? JSON.stringify(value) : "undefined";
|
|
3818
4215
|
define["import.meta.env.".concat(key)] = literal;
|
|
3819
4216
|
define["process.env.".concat(key)] = literal;
|
|
3820
|
-
if (
|
|
4217
|
+
if (key.startsWith(PUBLIC_PREFIX)) inObject[key] = value;
|
|
3821
4218
|
}
|
|
3822
4219
|
|
|
3823
4220
|
// Vite's built-ins, and they win over a project env var of the same name as
|
|
@@ -3844,25 +4241,64 @@ function defineFor(env, target, warnings) {
|
|
|
3844
4241
|
// "development" -- so a published site's code was told it was in dev.
|
|
3845
4242
|
define["process.env.NODE_ENV"] = JSON.stringify("production");
|
|
3846
4243
|
|
|
3847
|
-
// Always defined
|
|
3848
|
-
//
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
4244
|
+
// Always defined: it makes `import.meta.env` destructuring work and stops a
|
|
4245
|
+
// bare reference from throwing. Specific keys above take precedence.
|
|
4246
|
+
define["import.meta.env"] = RUNTIME_ENV;
|
|
4247
|
+
// In the browser `process` does not exist, so an untouched
|
|
4248
|
+
// `process.env.PUBLIC_X` threw there. Read as the same object instead.
|
|
4249
|
+
if (target === "client") define["process.env"] = RUNTIME_ENV;
|
|
4250
|
+
return {
|
|
4251
|
+
define: define,
|
|
4252
|
+
runtime: runtimeEnvSource(target, _objectSpread2(_objectSpread2({}, inObject), builtins))
|
|
4253
|
+
};
|
|
4254
|
+
}
|
|
4255
|
+
|
|
4256
|
+
/**
|
|
4257
|
+
* The identifier `import.meta.env` becomes, and the module `inject` imports
|
|
4258
|
+
* for it. The specifier is resolved by {@link runtimeEnvPlugin} and nothing
|
|
4259
|
+
* else, and a project cannot name it: `platform:` is not a package.
|
|
4260
|
+
*/
|
|
4261
|
+
var RUNTIME_ENV = "__PLATFORM_RUNTIME_ENV__";
|
|
4262
|
+
var RUNTIME_ENV_SPECIFIER = "platform:runtime-env";
|
|
4263
|
+
var RUNTIME_ENV_ID = "\0platform:runtime-env";
|
|
4264
|
+
|
|
4265
|
+
/**
|
|
4266
|
+
* The module {@link RUNTIME_ENV} imports. `fixed` -- the built-ins, and any
|
|
4267
|
+
* `env` the caller inlined -- wins over a runtime value of the same name.
|
|
4268
|
+
*
|
|
4269
|
+
* `globalThis.process?.env` rather than `process.env`: a server bundle that
|
|
4270
|
+
* runs where there is no `process` reads no variables instead of throwing.
|
|
4271
|
+
*/
|
|
4272
|
+
function runtimeEnvSource(target, fixed) {
|
|
4273
|
+
var read = target === "client" ? "globalThis.__PLATFORM_PUBLIC_ENV" : "globalThis.process?.env";
|
|
4274
|
+
return "const source = ".concat(read, " ?? {};\n") + "const runtime = {};\n" + "for (const name of Object.keys(source)) {\n" + " if (name.startsWith(".concat(JSON.stringify(PUBLIC_PREFIX), ")) runtime[name] = source[name];\n") + "}\n" + "export default Object.freeze(Object.assign(runtime, ".concat(JSON.stringify(fixed, null, 2), "));\n");
|
|
4275
|
+
}
|
|
4276
|
+
function runtimeEnvPlugin(source) {
|
|
4277
|
+
return {
|
|
4278
|
+
name: "platform:runtime-env",
|
|
4279
|
+
resolveId: function resolveId(id) {
|
|
4280
|
+
return id === RUNTIME_ENV_SPECIFIER ? RUNTIME_ENV_ID : null;
|
|
4281
|
+
},
|
|
4282
|
+
load: function load(id) {
|
|
4283
|
+
return id === RUNTIME_ENV_ID ? source : null;
|
|
4284
|
+
}
|
|
4285
|
+
};
|
|
3852
4286
|
}
|
|
3853
4287
|
function buildOnce(_x, _x2, _x3, _x4, _x5) {
|
|
3854
4288
|
return _buildOnce.apply(this, arguments);
|
|
3855
4289
|
}
|
|
3856
4290
|
function _buildOnce() {
|
|
3857
4291
|
_buildOnce = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(input, vendorBase, projectVendorBase, target, warnings) {
|
|
3858
|
-
var _input$
|
|
4292
|
+
var _input$env, _input$projectSource, _input$assets;
|
|
3859
4293
|
var clientModules,
|
|
3860
4294
|
isRsc,
|
|
3861
4295
|
assetUrls,
|
|
3862
4296
|
cssModules,
|
|
3863
4297
|
aliases,
|
|
4298
|
+
moduleDependencies,
|
|
3864
4299
|
vendor,
|
|
3865
4300
|
projectVendor,
|
|
4301
|
+
env,
|
|
3866
4302
|
_yield$loadRolldown,
|
|
3867
4303
|
build,
|
|
3868
4304
|
result,
|
|
@@ -3881,6 +4317,7 @@ function _buildOnce() {
|
|
|
3881
4317
|
assetUrls = _args2.length > 7 && _args2[7] !== undefined ? _args2[7] : new Map();
|
|
3882
4318
|
cssModules = _args2.length > 8 && _args2[8] !== undefined ? _args2[8] : {};
|
|
3883
4319
|
aliases = _args2.length > 9 && _args2[9] !== undefined ? _args2[9] : null;
|
|
4320
|
+
moduleDependencies = _args2.length > 10 && _args2[10] !== undefined ? _args2[10] : null;
|
|
3884
4321
|
vendor = vendorRules(input.target);
|
|
3885
4322
|
/*
|
|
3886
4323
|
* The project's own layer, in the shape the plugin already reads.
|
|
@@ -3894,7 +4331,8 @@ function _buildOnce() {
|
|
|
3894
4331
|
modules: input.target.project.modules,
|
|
3895
4332
|
css: input.target.project.css,
|
|
3896
4333
|
workerOnly: input.target.project.workerOnly
|
|
3897
|
-
};
|
|
4334
|
+
};
|
|
4335
|
+
env = envFor((_input$env = input.env) !== null && _input$env !== void 0 ? _input$env : {}, target, warnings); // The RSC pass is a server build in every respect the transforms care about:
|
|
3898
4336
|
// it runs on the server, so server-only code stays and client-only code goes.
|
|
3899
4337
|
// Only the vendor layer differs.
|
|
3900
4338
|
_context2.n = 1;
|
|
@@ -3917,7 +4355,7 @@ function _buildOnce() {
|
|
|
3917
4355
|
moduleTypes: {
|
|
3918
4356
|
".css": "empty"
|
|
3919
4357
|
},
|
|
3920
|
-
plugins: [projectPlugin(input.files, (_input$projectSource = input.projectSource) !== null && _input$projectSource !== void 0 ? _input$projectSource : input.files, input.routeSplitter, cssModules, aliases, (_input$assets = input.assets) !== null && _input$assets !== void 0 ? _input$assets : {}, assetUrls, vendorBase, projectVendorBase, projectVendor, vendor, warnings, target, new Set(), clientModules, isRsc)],
|
|
4358
|
+
plugins: [runtimeEnvPlugin(env.runtime), projectPlugin(input.files, (_input$projectSource = input.projectSource) !== null && _input$projectSource !== void 0 ? _input$projectSource : input.files, input.routeSplitter, cssModules, aliases, (_input$assets = input.assets) !== null && _input$assets !== void 0 ? _input$assets : {}, assetUrls, vendorBase, projectVendorBase, projectVendor, vendor, warnings, target, new Set(), clientModules, isRsc)],
|
|
3921
4359
|
// oxc handles TS and JSX natively, so there is no separate transform pass
|
|
3922
4360
|
// and no type-checking on the publish path. Types are the editor's job.
|
|
3923
4361
|
transform: {
|
|
@@ -3925,7 +4363,8 @@ function _buildOnce() {
|
|
|
3925
4363
|
runtime: "automatic",
|
|
3926
4364
|
importSource: "react"
|
|
3927
4365
|
},
|
|
3928
|
-
define:
|
|
4366
|
+
define: _objectSpread2(_objectSpread2({}, env.define), target === "server" && moduleDependencies !== null ? _defineProperty({}, MODULE_DEPENDENCIES_GLOBAL, JSON.stringify(moduleDependencies)) : {}),
|
|
4367
|
+
inject: _defineProperty({}, RUNTIME_ENV, RUNTIME_ENV_SPECIFIER)
|
|
3929
4368
|
},
|
|
3930
4369
|
output: {
|
|
3931
4370
|
format: "esm",
|
|
@@ -4001,7 +4440,7 @@ function buildUserApp(_x6) {
|
|
|
4001
4440
|
function _buildUserApp() {
|
|
4002
4441
|
_buildUserApp = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(input) {
|
|
4003
4442
|
var _input$target$project;
|
|
4004
|
-
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;
|
|
4443
|
+
var warnings, started, rev, clientModules, assetUrls, assetFiles, _i3, _Object$entries3, _input$assets2, _Object$entries3$_i, path, base64, resolved, aliases, css, styles, tailwindMs, compiled, hash, registryEntry, 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;
|
|
4005
4444
|
return _regenerator().w(function (_context3) {
|
|
4006
4445
|
while (1) switch (_context3.n) {
|
|
4007
4446
|
case 0:
|
|
@@ -4090,39 +4529,47 @@ function _buildUserApp() {
|
|
|
4090
4529
|
tailwindMs = compiled.ms;
|
|
4091
4530
|
warnings.push.apply(warnings, _toConsumableArray(compiled.warnings));
|
|
4092
4531
|
case 10:
|
|
4093
|
-
serverStarted = performance.now();
|
|
4094
4532
|
_context3.n = 11;
|
|
4095
|
-
return
|
|
4533
|
+
return buildInputId(input);
|
|
4096
4534
|
case 11:
|
|
4535
|
+
hash = _context3.v;
|
|
4536
|
+
_context3.n = 12;
|
|
4537
|
+
return valModulesEntry(input, hash, warnings);
|
|
4538
|
+
case 12:
|
|
4539
|
+
registryEntry = _context3.v;
|
|
4540
|
+
serverStarted = performance.now();
|
|
4541
|
+
_context3.n = 13;
|
|
4542
|
+
return buildOnce(input, "./vendor/", "./pvendor/", "server", warnings, clientModules, false, assetUrls, css.modules, aliases, registryEntry.dependencies);
|
|
4543
|
+
case 13:
|
|
4097
4544
|
serverBuild = _context3.v;
|
|
4098
4545
|
server = performance.now() - serverStarted;
|
|
4099
4546
|
clientStarted = performance.now();
|
|
4100
|
-
_context3.n =
|
|
4547
|
+
_context3.n = 14;
|
|
4101
4548
|
return buildOnce(input, "/_vendor/", "/_pvendor/".concat(rev, "/"), "client", warnings, clientModules, false, assetUrls, css.modules, aliases);
|
|
4102
|
-
case
|
|
4549
|
+
case 14:
|
|
4103
4550
|
clientBuild = _context3.v;
|
|
4104
4551
|
client = performance.now() - clientStarted; // Paths are relative to `rsc/app.js`, one directory down, so both layers are
|
|
4105
4552
|
// addressed with a leading `../`. Getting this wrong does not fail the build;
|
|
4106
4553
|
// the cold isolate simply refuses to boot.
|
|
4107
4554
|
if (!input.rsc) {
|
|
4108
|
-
_context3.n =
|
|
4555
|
+
_context3.n = 16;
|
|
4109
4556
|
break;
|
|
4110
4557
|
}
|
|
4111
|
-
_context3.n =
|
|
4558
|
+
_context3.n = 15;
|
|
4112
4559
|
return buildOnce(
|
|
4113
4560
|
// `../pvendor/`, with no revision segment: the revision belongs in the
|
|
4114
4561
|
// browser URL, where it buys immutable caching. Inside the module map
|
|
4115
4562
|
// there is exactly one layer and the key is `pvendor/<name>.js`, so a
|
|
4116
4563
|
// revision here is a path segment that does not exist -- and the cold
|
|
4117
4564
|
// isolate is where you would find that out.
|
|
4118
|
-
input, "../vendor-rsc/", "../pvendor/", "server", warnings, clientModules, true, assetUrls, css.modules, aliases);
|
|
4119
|
-
case
|
|
4565
|
+
input, "../vendor-rsc/", "../pvendor/", "server", warnings, clientModules, true, assetUrls, css.modules, aliases, registryEntry.dependencies);
|
|
4566
|
+
case 15:
|
|
4120
4567
|
_t2 = _context3.v;
|
|
4121
|
-
_context3.n =
|
|
4568
|
+
_context3.n = 17;
|
|
4122
4569
|
break;
|
|
4123
|
-
case
|
|
4570
|
+
case 16:
|
|
4124
4571
|
_t2 = undefined;
|
|
4125
|
-
case
|
|
4572
|
+
case 17:
|
|
4126
4573
|
rscBuild = _t2;
|
|
4127
4574
|
// Stripped of the `public/` prefix here rather than at every consumer: the
|
|
4128
4575
|
// prefix is a convention of the project layout, and what the loader needs is
|
|
@@ -4135,7 +4582,7 @@ function _buildUserApp() {
|
|
|
4135
4582
|
_t3 = serverBuild.code;
|
|
4136
4583
|
_t4 = clientBuild.code;
|
|
4137
4584
|
_t5 = serverBuild.chunks;
|
|
4138
|
-
_t6 = clientBuild.chunks;
|
|
4585
|
+
_t6 = _objectSpread2(_objectSpread2({}, clientBuild.chunks), registryEntry.files);
|
|
4139
4586
|
_t7 = assetFiles;
|
|
4140
4587
|
_t8 = publicFiles;
|
|
4141
4588
|
_t9 = styles;
|
|
@@ -4146,15 +4593,12 @@ function _buildUserApp() {
|
|
|
4146
4593
|
_t10 = rscBuild === null || rscBuild === void 0 ? void 0 : rscBuild.chunks;
|
|
4147
4594
|
_t11 = input.rsc ? clientModules : undefined;
|
|
4148
4595
|
_t12 = input.target.base.rev;
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
case 16:
|
|
4152
|
-
_t13 = _context3.v;
|
|
4153
|
-
_context3.n = 17;
|
|
4596
|
+
_t13 = hash;
|
|
4597
|
+
_context3.n = 18;
|
|
4154
4598
|
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) {
|
|
4155
4599
|
return built ? [built.code].concat(_toConsumableArray(Object.entries(built.chunks).flat())) : [];
|
|
4156
|
-
}))).join("\0"));
|
|
4157
|
-
case
|
|
4600
|
+
})), _toConsumableArray(Object.entries(registryEntry).flat())).join("\0"));
|
|
4601
|
+
case 18:
|
|
4158
4602
|
_t14 = _context3.v.slice(0, 32);
|
|
4159
4603
|
_t15 = {
|
|
4160
4604
|
server: server,
|
|
@@ -4611,158 +5055,4 @@ function treeShaOfText(files) {
|
|
|
4611
5055
|
})));
|
|
4612
5056
|
}
|
|
4613
5057
|
|
|
4614
|
-
|
|
4615
|
-
* A project's `val.modules.ts`, bundled to run: every `.val.ts` it imports,
|
|
4616
|
-
* the `val.config` they share and the `.val.json` entries they name, as ONE
|
|
4617
|
-
* ES module -- so it can be imported from a `blob:` URL, which cannot resolve
|
|
4618
|
-
* a relative chunk -- with every npm import pointing at the site's own
|
|
4619
|
-
* vendor chunks, at absolute URLs under `origin`.
|
|
4620
|
-
*
|
|
4621
|
-
* What the builder tab evaluates to learn a tree's schemas: Update from the
|
|
4622
|
-
* site with code (valbuild/home `docs/hosted-publishing.md` step 8.2, slice
|
|
4623
|
-
* 1b). The project's own `@valbuild/*` and dependencies are what run, as the
|
|
4624
|
-
* site runs them -- the browser half of its layer, from `/_pvendor/<rev>/`,
|
|
4625
|
-
* and the base layer from `/_vendor/`. Whoever imports it should do so off
|
|
4626
|
-
* the Studio's page: `@valbuild/tanstack` brings React and patches its JSX.
|
|
4627
|
-
*
|
|
4628
|
-
* Nothing else of a build happens here: no route splitting, no server
|
|
4629
|
-
* functions, no CSS -- a `.val.ts` has none of it.
|
|
4630
|
-
*/
|
|
4631
|
-
function bundleValModules(_x) {
|
|
4632
|
-
return _bundleValModules.apply(this, arguments);
|
|
4633
|
-
}
|
|
4634
|
-
function _bundleValModules() {
|
|
4635
|
-
_bundleValModules = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(input) {
|
|
4636
|
-
var _input$entry;
|
|
4637
|
-
var files, target, origin, entry, warnings, aliases, base, project, resolveProjectPath, _yield$loadRolldown, build, result, chunks, _t;
|
|
4638
|
-
return _regenerator().w(function (_context) {
|
|
4639
|
-
while (1) switch (_context.p = _context.n) {
|
|
4640
|
-
case 0:
|
|
4641
|
-
files = input.files, target = input.target, origin = input.origin;
|
|
4642
|
-
entry = (_input$entry = input.entry) !== null && _input$entry !== void 0 ? _input$entry : ["val.modules.ts", "val.modules.js"].find(function (path) {
|
|
4643
|
-
return path in files;
|
|
4644
|
-
});
|
|
4645
|
-
if (!(entry === undefined || !(entry in files))) {
|
|
4646
|
-
_context.n = 1;
|
|
4647
|
-
break;
|
|
4648
|
-
}
|
|
4649
|
-
throw new Error("This project has no val.modules.ts, so its Val modules cannot be read.");
|
|
4650
|
-
case 1:
|
|
4651
|
-
warnings = [];
|
|
4652
|
-
aliases = aliasMap(files, function (message) {
|
|
4653
|
-
return warnings.push(message);
|
|
4654
|
-
});
|
|
4655
|
-
base = "".concat(origin, "/_vendor/");
|
|
4656
|
-
project = target.project.rev === null ? null : "".concat(origin, "/_pvendor/").concat(target.project.rev, "/");
|
|
4657
|
-
resolveProjectPath = function resolveProjectPath(path) {
|
|
4658
|
-
return resolveInFiles(path, files);
|
|
4659
|
-
};
|
|
4660
|
-
_context.n = 2;
|
|
4661
|
-
return loadRolldown();
|
|
4662
|
-
case 2:
|
|
4663
|
-
_yield$loadRolldown = _context.v;
|
|
4664
|
-
build = _yield$loadRolldown.build;
|
|
4665
|
-
_context.p = 3;
|
|
4666
|
-
_context.n = 4;
|
|
4667
|
-
return build({
|
|
4668
|
-
input: entry,
|
|
4669
|
-
// See `buildOnce`: required in the browser, inert here.
|
|
4670
|
-
cwd: "/",
|
|
4671
|
-
moduleTypes: {
|
|
4672
|
-
".css": "empty"
|
|
4673
|
-
},
|
|
4674
|
-
plugins: [{
|
|
4675
|
-
name: "val:modules",
|
|
4676
|
-
resolveId: function resolveId(source, importer) {
|
|
4677
|
-
if (source.startsWith(".")) {
|
|
4678
|
-
return resolveProjectPath(resolve(dirname(importer !== null && importer !== void 0 ? importer : entry), source));
|
|
4679
|
-
}
|
|
4680
|
-
if (source in files) return source;
|
|
4681
|
-
var baseChunk = target.base.modules[source];
|
|
4682
|
-
if (baseChunk) {
|
|
4683
|
-
return {
|
|
4684
|
-
id: "".concat(base).concat(baseChunk, ".js"),
|
|
4685
|
-
external: true
|
|
4686
|
-
};
|
|
4687
|
-
}
|
|
4688
|
-
var projectChunk = target.project.modules[source];
|
|
4689
|
-
if (projectChunk && project !== null) {
|
|
4690
|
-
if (target.project.workerOnly.includes(source)) {
|
|
4691
|
-
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."));
|
|
4692
|
-
}
|
|
4693
|
-
return {
|
|
4694
|
-
id: "".concat(project).concat(projectChunk, ".js"),
|
|
4695
|
-
external: true
|
|
4696
|
-
};
|
|
4697
|
-
}
|
|
4698
|
-
if (aliases) {
|
|
4699
|
-
var _iterator = _createForOfIteratorHelper(aliases.candidates(source)),
|
|
4700
|
-
_step;
|
|
4701
|
-
try {
|
|
4702
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
4703
|
-
var candidate = _step.value;
|
|
4704
|
-
var _hit = resolveProjectPath(candidate);
|
|
4705
|
-
if (_hit) return _hit;
|
|
4706
|
-
}
|
|
4707
|
-
} catch (err) {
|
|
4708
|
-
_iterator.e(err);
|
|
4709
|
-
} finally {
|
|
4710
|
-
_iterator.f();
|
|
4711
|
-
}
|
|
4712
|
-
var fromBaseUrl = aliases.baseUrlCandidate(source);
|
|
4713
|
-
var hit = fromBaseUrl && resolveProjectPath(fromBaseUrl);
|
|
4714
|
-
if (hit) return hit;
|
|
4715
|
-
}
|
|
4716
|
-
// An error, not a warning: rolldown would otherwise leave the
|
|
4717
|
-
// specifier as it is, and it would fail when imported, unnamed.
|
|
4718
|
-
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(", "), "."));
|
|
4719
|
-
},
|
|
4720
|
-
load: function load(id) {
|
|
4721
|
-
return id in files ? files[id] : null;
|
|
4722
|
-
}
|
|
4723
|
-
}],
|
|
4724
|
-
transform: {
|
|
4725
|
-
jsx: {
|
|
4726
|
-
runtime: "automatic",
|
|
4727
|
-
importSource: "react"
|
|
4728
|
-
}
|
|
4729
|
-
},
|
|
4730
|
-
output: {
|
|
4731
|
-
format: "esm",
|
|
4732
|
-
minify: false,
|
|
4733
|
-
// One module: `def: () => import("./x.val")` stays a dynamic import of
|
|
4734
|
-
// something already in the file.
|
|
4735
|
-
codeSplitting: false
|
|
4736
|
-
},
|
|
4737
|
-
write: false
|
|
4738
|
-
});
|
|
4739
|
-
case 4:
|
|
4740
|
-
result = _context.v;
|
|
4741
|
-
_context.n = 6;
|
|
4742
|
-
break;
|
|
4743
|
-
case 5:
|
|
4744
|
-
_context.p = 5;
|
|
4745
|
-
_t = _context.v;
|
|
4746
|
-
throw new Error(["The Val modules could not be bundled."].concat(warnings, [_t instanceof Error ? _t.message : String(_t)]).join("\n"), {
|
|
4747
|
-
cause: _t
|
|
4748
|
-
});
|
|
4749
|
-
case 6:
|
|
4750
|
-
chunks = result.output.filter(function (output) {
|
|
4751
|
-
return output.type === "chunk";
|
|
4752
|
-
});
|
|
4753
|
-
if (!(chunks.length !== 1)) {
|
|
4754
|
-
_context.n = 7;
|
|
4755
|
-
break;
|
|
4756
|
-
}
|
|
4757
|
-
throw new Error("Bundling the Val modules made ".concat(chunks.length, " chunks rather than one."));
|
|
4758
|
-
case 7:
|
|
4759
|
-
return _context.a(2, {
|
|
4760
|
-
code: chunks[0].code
|
|
4761
|
-
});
|
|
4762
|
-
}
|
|
4763
|
-
}, _callee, null, [[3, 5]]);
|
|
4764
|
-
}));
|
|
4765
|
-
return _bundleValModules.apply(this, arguments);
|
|
4766
|
-
}
|
|
4767
|
-
|
|
4768
|
-
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 };
|
|
5058
|
+
export { ENTRY_CHUNK, MODULE_DEPENDENCIES_GLOBAL, 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 };
|