@valbuild/tanstack-build 0.0.1-alpha.0 → 0.136.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +97 -0
- package/constants/dist/valbuild-tanstack-build-constants.cjs.d.ts +2 -0
- package/constants/dist/valbuild-tanstack-build-constants.cjs.dev.js +15 -0
- package/constants/dist/valbuild-tanstack-build-constants.cjs.js +7 -0
- package/constants/dist/valbuild-tanstack-build-constants.cjs.prod.js +15 -0
- package/constants/dist/valbuild-tanstack-build-constants.esm.js +2 -0
- package/constants/package.json +4 -0
- package/dist/artifactKeys-3a40f3a0.esm.js +50 -0
- package/dist/artifactKeys-700b9044.cjs.prod.js +53 -0
- package/dist/artifactKeys-ad3e41fc.cjs.dev.js +53 -0
- package/dist/declarations/src/artifactKeys.d.ts +46 -0
- package/dist/declarations/src/artifacts.d.ts +72 -0
- package/dist/declarations/src/assets.d.ts +34 -0
- package/dist/declarations/src/build.d.ts +260 -0
- package/dist/declarations/src/buildTarget.d.ts +44 -0
- package/dist/declarations/src/constants/index.d.ts +19 -0
- package/dist/declarations/src/contract.d.ts +135 -0
- package/dist/declarations/src/gitTree.d.ts +20 -0
- package/dist/declarations/src/index.d.ts +34 -0
- package/dist/declarations/src/node/cssModules.d.ts +2 -0
- package/dist/declarations/src/node/index.d.ts +18 -0
- package/dist/declarations/src/node/nodeShims.d.ts +74 -0
- package/dist/declarations/src/node/routeSplitter.d.ts +14 -0
- package/dist/declarations/src/node/routes.d.ts +27 -0
- package/dist/declarations/src/node/vendorLayer.d.ts +175 -0
- package/dist/declarations/src/paths.d.ts +4 -0
- package/dist/declarations/src/projectPaths.d.ts +24 -0
- package/dist/declarations/src/routeSplit.d.ts +29 -0
- package/dist/declarations/src/tailwind.d.ts +59 -0
- package/dist/declarations/src/tsconfigPaths.d.ts +34 -0
- package/dist/declarations/src/wire.d.ts +113 -0
- package/dist/projectPaths-5e4defea.esm.js +30 -0
- package/dist/projectPaths-9cbecebf.cjs.prod.js +35 -0
- package/dist/projectPaths-f222255a.cjs.dev.js +35 -0
- package/dist/slicedToArray-12869836.cjs.dev.js +311 -0
- package/dist/slicedToArray-149a2518.cjs.prod.js +311 -0
- package/dist/slicedToArray-d71360f4.esm.js +303 -0
- package/dist/valbuild-tanstack-build.cjs.d.ts +2 -2
- package/dist/valbuild-tanstack-build.cjs.dev.js +3556 -0
- package/dist/valbuild-tanstack-build.cjs.js +6 -15
- package/dist/valbuild-tanstack-build.cjs.prod.js +3556 -0
- package/dist/valbuild-tanstack-build.esm.js +3525 -0
- package/node/dist/valbuild-tanstack-build-node.cjs.d.ts +2 -2
- package/node/dist/valbuild-tanstack-build-node.cjs.dev.js +2201 -0
- package/node/dist/valbuild-tanstack-build-node.cjs.js +6 -15
- package/node/dist/valbuild-tanstack-build-node.cjs.prod.js +2201 -0
- package/node/dist/valbuild-tanstack-build-node.esm.js +2162 -0
- package/package.json +12 -5
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import type { BuildTarget } from "./contract.js";
|
|
2
|
+
import { type CssModuleLoader } from "./tailwind.js";
|
|
3
|
+
import { type RouteSplitter } from "./routeSplit.js";
|
|
4
|
+
export { isAsset, INLINE_LIMIT, base64Bytes } from "./assets.js";
|
|
5
|
+
export { fetchBuildTarget, fetchBuildTargetRev, type BuildTargetRequest, } from "./buildTarget.js";
|
|
6
|
+
export type { BuildTarget, BuildTargetRev } from "./contract.js";
|
|
7
|
+
export type { CssModuleLoader, LoadedCssModule } from "./tailwind.js";
|
|
8
|
+
export type { RouteSplitter } from "./routeSplit.js";
|
|
9
|
+
export { ENTRY, ROUTES_DIR, TREE } from "./projectPaths.js";
|
|
10
|
+
/**
|
|
11
|
+
* Filename of the entry chunk, in every target.
|
|
12
|
+
*
|
|
13
|
+
* Fixed rather than hashed because it is addressed by name from outside the
|
|
14
|
+
* build: `app.js` in the isolate's module map, `/_app/app.js` from the shell's
|
|
15
|
+
* client half. Everything the build splits off is content-addressed instead.
|
|
16
|
+
*/
|
|
17
|
+
export declare const ENTRY_CHUNK = "app.js";
|
|
18
|
+
/**
|
|
19
|
+
* Env vars whose names start with this are inlined into the *client* bundle as
|
|
20
|
+
* well as the server one, and are therefore public: anyone can read them from
|
|
21
|
+
* the served JavaScript. Everything else is inlined only server-side.
|
|
22
|
+
*
|
|
23
|
+
* An explicit prefix rather than a separate list, so the exposure of a variable
|
|
24
|
+
* is visible at every use site in the user's code.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* The project's own source, importable by the app that is made from it.
|
|
28
|
+
*
|
|
29
|
+
* `import { FILES } from 'platform:project-source'` -- how a host hands a CMS its
|
|
30
|
+
* content when there is no filesystem to read it from. Val's in-memory store is
|
|
31
|
+
* the case this exists for.
|
|
32
|
+
*
|
|
33
|
+
* Emitted by the BUILD, from the same record the build is made of, and that is
|
|
34
|
+
* the whole point. It used to be a chunk of the project's VENDOR LAYER, which
|
|
35
|
+
* made it dependency-shaped: the layer changes when `package.json` does, so a
|
|
36
|
+
* publisher reusing a layer by reference -- which is every publish from the
|
|
37
|
+
* studio tab, because a tab cannot build one -- shipped new code beside a
|
|
38
|
+
* frozen copy of the source. The symptom was precise and awful: the edit WAS in
|
|
39
|
+
* the client bundle, so the page hydrated with the new content, while anything
|
|
40
|
+
* read on the SERVER (`head` metadata, a redirect) still saw the source as it
|
|
41
|
+
* was at the last CLI publish.
|
|
42
|
+
*
|
|
43
|
+
* Server-side only. A client bundle carrying every source file of the project
|
|
44
|
+
* would be both a leak and, for a real app, enormous.
|
|
45
|
+
*/
|
|
46
|
+
export declare const PROJECT_SOURCE = "platform:project-source";
|
|
47
|
+
export declare const PUBLIC_PREFIX = "PUBLIC_";
|
|
48
|
+
export interface BuildInput {
|
|
49
|
+
/** Virtual file tree, keyed by posix path relative to the project root. */
|
|
50
|
+
files: Record<string, string>;
|
|
51
|
+
/**
|
|
52
|
+
* The platform this build targets: its base layer, and this project's.
|
|
53
|
+
*
|
|
54
|
+
* Replaces `vendorRev` and `projectVendor`, which were the same two facts
|
|
55
|
+
* arriving separately -- and which left the third fact, the externalisation
|
|
56
|
+
* rules, to be imported at COMPILE TIME from `@valbuild/vendor/externals`.
|
|
57
|
+
* A builder that reads those can only be built in the platform's own
|
|
58
|
+
* repository. Taking them as a parameter is what lets the Studio carry one.
|
|
59
|
+
*
|
|
60
|
+
* `GET /__api/build-target` on the loader answers this shape, and
|
|
61
|
+
* `GET /v1/build-target` on content proxies it.
|
|
62
|
+
*/
|
|
63
|
+
target: BuildTarget;
|
|
64
|
+
/** Project env vars, inlined at build time. See PUBLIC_PREFIX. */
|
|
65
|
+
env?: Record<string, string>;
|
|
66
|
+
/**
|
|
67
|
+
* Files under `public/`, base64-encoded, keyed by project-relative path.
|
|
68
|
+
*
|
|
69
|
+
* Different from `assets` in the way that matters: these are never imported,
|
|
70
|
+
* so nothing in the module graph refers to them and their *path* is the
|
|
71
|
+
* contract. `public/favicon.ico` is requested as `/favicon.ico`, which is why
|
|
72
|
+
* they cannot be content-addressed the way an imported asset is.
|
|
73
|
+
*/
|
|
74
|
+
publicFiles?: Record<string, string>;
|
|
75
|
+
/**
|
|
76
|
+
* Binary assets, base64-encoded, keyed by project-relative path.
|
|
77
|
+
*
|
|
78
|
+
* Separate from `files` because that map is text. Small ones become data
|
|
79
|
+
* URIs; larger ones are published and served, which is why the build reports
|
|
80
|
+
* back which it kept.
|
|
81
|
+
*/
|
|
82
|
+
assets?: Record<string, string>;
|
|
83
|
+
/**
|
|
84
|
+
* What `platform:project-source` resolves to, when the app imports it.
|
|
85
|
+
*
|
|
86
|
+
* Defaults to {@link files}. Passed separately because `files` may carry
|
|
87
|
+
* GENERATED entries -- a file-based project's route tree and entry shim are
|
|
88
|
+
* added before the build -- and handing those to a CMS as though they were
|
|
89
|
+
* the project's own content is how a generated file ends up published back
|
|
90
|
+
* as source.
|
|
91
|
+
*/
|
|
92
|
+
projectSource?: Record<string, string>;
|
|
93
|
+
/**
|
|
94
|
+
* Splits route files: Start's `autoCodeSplitting`.
|
|
95
|
+
*
|
|
96
|
+
* A capability rather than something the builder does, because the split is
|
|
97
|
+
* @babel/core's and does not run in a browser. Absent, routes are not split
|
|
98
|
+
* -- which costs bundle size, not behaviour. See route-split.ts.
|
|
99
|
+
*/
|
|
100
|
+
routeSplitter?: RouteSplitter;
|
|
101
|
+
/**
|
|
102
|
+
* Resolves and evaluates a JS module for Tailwind's `@plugin` / `@config`.
|
|
103
|
+
*
|
|
104
|
+
* A capability rather than something the builder can do: it needs real module
|
|
105
|
+
* resolution. `packages/publish` supplies one; a browser build does not, and
|
|
106
|
+
* a project using those directives fails there rather than losing its styles
|
|
107
|
+
* silently.
|
|
108
|
+
*/
|
|
109
|
+
loadCssModule?: CssModuleLoader;
|
|
110
|
+
/**
|
|
111
|
+
* Also build for React Server Components.
|
|
112
|
+
*
|
|
113
|
+
* A third pass over the same files, resolving React from the `react-server`
|
|
114
|
+
* layer. Off by default: it costs a build and produces a bundle nothing will
|
|
115
|
+
* load unless the project actually renders server components.
|
|
116
|
+
*/
|
|
117
|
+
rsc?: boolean;
|
|
118
|
+
}
|
|
119
|
+
export interface BuildOutput {
|
|
120
|
+
/** ESM module for the Dynamic Worker module map, at key `app.js`. */
|
|
121
|
+
serverCode: string;
|
|
122
|
+
/** ESM module served as the asset `/_app/app.js`. */
|
|
123
|
+
clientCode: string;
|
|
124
|
+
/**
|
|
125
|
+
* Everything the build split off, keyed by content-addressed filename.
|
|
126
|
+
*
|
|
127
|
+
* Empty for an app with no dynamic imports, which is most of them. The names
|
|
128
|
+
* are what the entry imports, relatively, so they double as module-map keys
|
|
129
|
+
* on the server and as paths under `/_app/` in the browser.
|
|
130
|
+
*/
|
|
131
|
+
serverChunks: Record<string, string>;
|
|
132
|
+
clientChunks: Record<string, string>;
|
|
133
|
+
/** As above, for the rsc bundle. Keyed without the `rsc/` prefix. */
|
|
134
|
+
rscChunks?: Record<string, string>;
|
|
135
|
+
/**
|
|
136
|
+
* Files served at the root path, base64, keyed by URL path without the
|
|
137
|
+
* leading slash (`favicon.ico`, `val/logo.svg`).
|
|
138
|
+
*/
|
|
139
|
+
publicFiles: Record<string, string>;
|
|
140
|
+
/**
|
|
141
|
+
* Assets too large to inline, base64, keyed by their content-addressed name.
|
|
142
|
+
*
|
|
143
|
+
* Served under `/_app/a/`. Empty for a project whose assets all fit under the
|
|
144
|
+
* inline limit, which for an app with a few icons is usually all of them.
|
|
145
|
+
*/
|
|
146
|
+
assetFiles: Record<string, string>;
|
|
147
|
+
/** Concatenated stylesheet, served as `/_app/app.css`. Empty when unused. */
|
|
148
|
+
cssCode: string;
|
|
149
|
+
/**
|
|
150
|
+
* Whether the project imported its stylesheet by URL and links it itself.
|
|
151
|
+
*
|
|
152
|
+
* The loader injects a `<link>` for projects that do not, because with
|
|
153
|
+
* file-based routing the user owns `<head>` and the shell has nowhere to
|
|
154
|
+
* write. A project using `?url` has already done it, and injecting a second
|
|
155
|
+
* one is a duplicate request for the same file.
|
|
156
|
+
*/
|
|
157
|
+
linksOwnCss: boolean;
|
|
158
|
+
/** `"use client"` modules found, when `rsc` was requested. */
|
|
159
|
+
clientModules?: Array<{
|
|
160
|
+
id: string;
|
|
161
|
+
path: string;
|
|
162
|
+
exports: Array<string>;
|
|
163
|
+
}>;
|
|
164
|
+
/**
|
|
165
|
+
* ESM module for the module-map key `rsc/app.js`, when `rsc` was requested.
|
|
166
|
+
*
|
|
167
|
+
* A separate key rather than a variant of `app.js`, because the RSC shell
|
|
168
|
+
* entry lives in `rsc/` and so its `./app.js` resolves there -- the two user
|
|
169
|
+
* builds coexist in one map without either knowing about the other.
|
|
170
|
+
*/
|
|
171
|
+
rscCode?: string;
|
|
172
|
+
hash: string;
|
|
173
|
+
vendorRev: string;
|
|
174
|
+
/** Wall-clock milliseconds per phase; the number the whole design lives on. */
|
|
175
|
+
timings: {
|
|
176
|
+
server: number;
|
|
177
|
+
client: number;
|
|
178
|
+
tailwind: number;
|
|
179
|
+
total: number;
|
|
180
|
+
};
|
|
181
|
+
warnings: Array<string>;
|
|
182
|
+
}
|
|
183
|
+
export declare function buildUserApp(input: BuildInput): Promise<BuildOutput>;
|
|
184
|
+
/**
|
|
185
|
+
* Exactly what `POST /__api/publish` expects, from a build.
|
|
186
|
+
*
|
|
187
|
+
* A function rather than "spread the whole build", because BuildOutput also
|
|
188
|
+
* carries things the loader has no use for -- timings, warnings, the client
|
|
189
|
+
* module list -- and rather than a hand-written literal at every call site,
|
|
190
|
+
* because split chunks were the third output to be added and the third time
|
|
191
|
+
* every publisher had to be found and edited.
|
|
192
|
+
*/
|
|
193
|
+
export declare function publishPayload(build: BuildOutput, extra?: {
|
|
194
|
+
projectVendor?: {
|
|
195
|
+
rev: string;
|
|
196
|
+
worker: Record<string, string>;
|
|
197
|
+
browser: Record<string, string>;
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Keep using the layer already stored under this revision.
|
|
201
|
+
*
|
|
202
|
+
* For a publisher that did not build the dependency layer and cannot: the
|
|
203
|
+
* layer is a rolldown pass over `node_modules`, and the studio tab has
|
|
204
|
+
* neither. Sending nothing at all is NOT the same thing -- the loader would
|
|
205
|
+
* read the head's layer as absent and the next render would lose every
|
|
206
|
+
* dependency.
|
|
207
|
+
*/
|
|
208
|
+
projectVendorRev?: string;
|
|
209
|
+
/**
|
|
210
|
+
* The source this build was made from, stored so the next editor can start
|
|
211
|
+
* from what is live rather than re-importing the repository.
|
|
212
|
+
*/
|
|
213
|
+
projectSource?: Record<string, string>;
|
|
214
|
+
/**
|
|
215
|
+
* The commit this build was made from.
|
|
216
|
+
*
|
|
217
|
+
* Required by a project whose pointer is configured, and the CLAIM that
|
|
218
|
+
* pointer checks: the loader reads the branch head itself and links the
|
|
219
|
+
* build only if the two agree, so a publisher naming a stale commit is
|
|
220
|
+
* refused rather than believed.
|
|
221
|
+
*/
|
|
222
|
+
commit?: string;
|
|
223
|
+
/**
|
|
224
|
+
* The git tree of that commit's source.
|
|
225
|
+
*
|
|
226
|
+
* Optional, and a publisher that cannot honestly produce one must LEAVE IT
|
|
227
|
+
* OUT rather than approximate it. The loader compares it against the tree
|
|
228
|
+
* the commit actually holds, so a value that is nearly right refuses every
|
|
229
|
+
* publish -- which is worse than not checking, because it looks like the
|
|
230
|
+
* platform being broken. A checkout has it for free; a tab whose record has
|
|
231
|
+
* been modified since the checkout (this platform wires `val.server.ts`
|
|
232
|
+
* before building) does not.
|
|
233
|
+
*/
|
|
234
|
+
sourceHash?: string;
|
|
235
|
+
/** A browser tab or a repository's CI. Defaults to `client` at the loader. */
|
|
236
|
+
origin?: "client" | "repo";
|
|
237
|
+
}): {
|
|
238
|
+
projectVendor?: {
|
|
239
|
+
rev: string;
|
|
240
|
+
worker: Record<string, string>;
|
|
241
|
+
browser: Record<string, string>;
|
|
242
|
+
};
|
|
243
|
+
projectVendorRev?: string;
|
|
244
|
+
projectSource?: Record<string, string>;
|
|
245
|
+
commit?: string;
|
|
246
|
+
sourceHash?: string;
|
|
247
|
+
origin?: "client" | "repo";
|
|
248
|
+
serverCode: string;
|
|
249
|
+
clientCode: string;
|
|
250
|
+
serverChunks: Record<string, string>;
|
|
251
|
+
clientChunks: Record<string, string>;
|
|
252
|
+
cssCode: string;
|
|
253
|
+
linksOwnCss: boolean;
|
|
254
|
+
rscCode: string | undefined;
|
|
255
|
+
rscChunks: Record<string, string> | undefined;
|
|
256
|
+
assetFiles: Record<string, string>;
|
|
257
|
+
publicFiles: Record<string, string>;
|
|
258
|
+
hash: string;
|
|
259
|
+
vendorRev: string;
|
|
260
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a build is targeting, fetched from the platform.
|
|
3
|
+
*
|
|
4
|
+
* One implementation, because there used to be two calls and everybody made
|
|
5
|
+
* them by hand: `/__api/artifacts` for the base revision and `/__api/vendor`
|
|
6
|
+
* for the project's layer, assembled at eighteen call sites. Two calls to
|
|
7
|
+
* build one answer is also two chances to assemble a mismatched one -- a base
|
|
8
|
+
* from after a deploy with a project layer built against the one before it.
|
|
9
|
+
*
|
|
10
|
+
* In THIS package, beside the `BuildInput.target` it produces, because the
|
|
11
|
+
* callers that have to ask are the ones that carry the builder: a CLI on npm
|
|
12
|
+
* and a Studio in a tab, neither of which can be given the answer at compile
|
|
13
|
+
* time. `@valbuild/contract` would be the other candidate and is deliberately
|
|
14
|
+
* types-only -- a user app must not need a runtime import from the platform.
|
|
15
|
+
*
|
|
16
|
+
* The route is no longer public. It says what a project depends on, which was
|
|
17
|
+
* readable by anyone; it now takes the project's own `VAL_API_KEY`, or the
|
|
18
|
+
* operator token, or nothing at all when the loader is running with
|
|
19
|
+
* `CONTROL_PLANE_AUTH: open` -- which is how `wrangler dev` runs and why the
|
|
20
|
+
* suites need no credential.
|
|
21
|
+
*
|
|
22
|
+
* NOT a project token, which the loader refuses on every route but
|
|
23
|
+
* `/__api/publish`. A publisher that holds one asks content's
|
|
24
|
+
* `GET /v1/build-target` instead, which resolves the project from the token
|
|
25
|
+
* and asks the loader with the project's api key.
|
|
26
|
+
*/
|
|
27
|
+
import type { BuildTarget } from "./contract.js";
|
|
28
|
+
export interface BuildTargetRequest {
|
|
29
|
+
loader: string;
|
|
30
|
+
/** Which project's layer to report. The base half is the same for all. */
|
|
31
|
+
project: string;
|
|
32
|
+
/** The project's api key or the operator token, when the loader wants one. */
|
|
33
|
+
token?: string;
|
|
34
|
+
}
|
|
35
|
+
export declare function fetchBuildTarget(request: BuildTargetRequest): Promise<BuildTarget>;
|
|
36
|
+
/**
|
|
37
|
+
* Just this project's layer revision.
|
|
38
|
+
*
|
|
39
|
+
* The one question a publisher asks before it has built anything -- must I
|
|
40
|
+
* send my dependency layer at all -- and the full answer reads the whole layer
|
|
41
|
+
* out of storage for its specifier map, which is several megabytes to
|
|
42
|
+
* establish a string comparison.
|
|
43
|
+
*/
|
|
44
|
+
export declare function fetchBuildTargetRev(request: BuildTargetRequest): Promise<string | null>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract's constants, and nothing else: `@valbuild/tanstack-build/constants`.
|
|
3
|
+
*
|
|
4
|
+
* The same values the root exports, from an entrypoint that imports nothing
|
|
5
|
+
* else. It exists for callers that must not take the builder with them, because
|
|
6
|
+
* the root pulls in `@rolldown/browser`, whose loader fetches 10.9 MB of wasm at
|
|
7
|
+
* module evaluation:
|
|
8
|
+
*
|
|
9
|
+
* - the platform's browser route generator, which bundles its own code -- from
|
|
10
|
+
* the root it went from 4.1 MB to 5.4 MB, and would have fetched the bundler
|
|
11
|
+
* to write a route tree;
|
|
12
|
+
* - content's `loaderPayload.ts`, a Node server that takes a publish's
|
|
13
|
+
* artifacts apart by these keys.
|
|
14
|
+
*
|
|
15
|
+
* An entrypoint rather than literals in those places because these ARE the
|
|
16
|
+
* contract with the builder, and a copy is what drifts.
|
|
17
|
+
*/
|
|
18
|
+
export { ENTRY, ENTRY_SHIM, ROUTES_DIR, TREE } from "../projectPaths.js";
|
|
19
|
+
export { ARTIFACT_KEYS, ARTIFACT_PREFIXES } from "../artifactKeys.js";
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from "react";
|
|
2
|
+
export interface UserRoute {
|
|
3
|
+
/** TanStack Router path syntax, e.g. '/', '/about', '/posts/$postId'. */
|
|
4
|
+
path: string;
|
|
5
|
+
/**
|
|
6
|
+
* `never` rather than `any`, and it means "this side supplies no props".
|
|
7
|
+
*
|
|
8
|
+
* A component's props are contravariant, so every component -- including one
|
|
9
|
+
* that declares props of its own -- is assignable to `ComponentType<never>`,
|
|
10
|
+
* which is what a route component has to be: the router renders it, and
|
|
11
|
+
* nothing here can know or pass what it declares.
|
|
12
|
+
*/
|
|
13
|
+
component: ComponentType<never>;
|
|
14
|
+
/** Runs on the server during SSR and on the client during navigation. */
|
|
15
|
+
loader?: (ctx: {
|
|
16
|
+
params: Record<string, string>;
|
|
17
|
+
}) => unknown;
|
|
18
|
+
}
|
|
19
|
+
export interface UserApp {
|
|
20
|
+
routes: Array<UserRoute>;
|
|
21
|
+
/** Optional wrapper rendered inside the shell's root route. */
|
|
22
|
+
layout?: ComponentType<{
|
|
23
|
+
children: ReactNode;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
/** Shape of the module the browser build emits, for both targets. */
|
|
27
|
+
export interface UserAppModule {
|
|
28
|
+
default: UserApp;
|
|
29
|
+
}
|
|
30
|
+
/** What the studio uploads and the loader Worker stores per publish. */
|
|
31
|
+
export interface PublishManifest {
|
|
32
|
+
projectId: string;
|
|
33
|
+
/** sha256 of serverCode + clientCode; used as the LOADER.get() cache id. */
|
|
34
|
+
hash: string;
|
|
35
|
+
/** Vendor artifact revision the app was built against. */
|
|
36
|
+
vendorRev: string;
|
|
37
|
+
createdAt: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Everything a build needs to know about the platform it is targeting.
|
|
41
|
+
*
|
|
42
|
+
* ## Why this exists
|
|
43
|
+
*
|
|
44
|
+
* `@valbuild/builder` used to import `@valbuild/vendor/externals` at COMPILE
|
|
45
|
+
* TIME to learn which specifiers are externalised and where their chunks live.
|
|
46
|
+
* That made the builder unmovable: it could only ever be built in the same
|
|
47
|
+
* repository as the vendor package it read, so the Studio could not carry its
|
|
48
|
+
* own copy and a published build could not be made anywhere but here.
|
|
49
|
+
*
|
|
50
|
+
* The facts have not changed -- they are still the platform's -- but they now
|
|
51
|
+
* ARRIVE rather than being compiled in. `GET /__api/build-target` answers this
|
|
52
|
+
* shape, content proxies it at `GET /v1/build-target`, and `BuildInput` takes
|
|
53
|
+
* it as a parameter.
|
|
54
|
+
*
|
|
55
|
+
* ## The two halves move on different clocks
|
|
56
|
+
*
|
|
57
|
+
* `base` changes when the platform is deployed: new chunks, a new shell. It is
|
|
58
|
+
* immutable for the life of a loader deployment, which is what makes it
|
|
59
|
+
* cacheable by revision.
|
|
60
|
+
*
|
|
61
|
+
* `project` changes when a project's dependencies do, which is rarely and on
|
|
62
|
+
* nobody else's schedule. It has to be revalidated per project.
|
|
63
|
+
*
|
|
64
|
+
* Together in one response because a build needs both and two round trips to
|
|
65
|
+
* assemble one answer is two chances to get a mismatched pair -- a base layer
|
|
66
|
+
* from after a deploy and a project layer built against the one before it.
|
|
67
|
+
*/
|
|
68
|
+
export interface BuildTarget {
|
|
69
|
+
base: {
|
|
70
|
+
/** The base vendor layer's revision. Every build is pinned to one. */
|
|
71
|
+
rev: string;
|
|
72
|
+
/** The shell this loader serves, and the RSC shell beside it. */
|
|
73
|
+
shellRev: string;
|
|
74
|
+
rscShellRev: string;
|
|
75
|
+
/**
|
|
76
|
+
* Specifier -> chunk name for the base layer, e.g. `{ react: 'react' }`.
|
|
77
|
+
*
|
|
78
|
+
* The map rather than a resolve function, because a function cannot cross
|
|
79
|
+
* a wire. Resolving is `base + modules[specifier] + '.js'`, which the
|
|
80
|
+
* builder does itself -- one line, and it keeps the RULE on the side that
|
|
81
|
+
* owns the chunks.
|
|
82
|
+
*/
|
|
83
|
+
modules: Record<string, string>;
|
|
84
|
+
/** The same, for the react-server layer. Empty when RSC is not served. */
|
|
85
|
+
rscModules: Record<string, string>;
|
|
86
|
+
/** Where the chunks live, as seen from each kind of importer. */
|
|
87
|
+
paths: {
|
|
88
|
+
/** The base layer, from a project-layer chunk. */
|
|
89
|
+
baseFromProject: string;
|
|
90
|
+
/** The project's own layer, inside the isolate's module map. */
|
|
91
|
+
projectVendorDir: string;
|
|
92
|
+
/** The react-server layer, from a module in `rsc/`. */
|
|
93
|
+
rscVendorBase: string;
|
|
94
|
+
/** The specifier an RSC bundle imports its runtime as, and its path. */
|
|
95
|
+
rscRuntimeSpecifier: string;
|
|
96
|
+
rscRuntimePath: string;
|
|
97
|
+
/** Where `registerClientReference` comes from, for the rsc target. */
|
|
98
|
+
flightServer: string;
|
|
99
|
+
/** Where the shell dispatches server functions. */
|
|
100
|
+
serverFnBase: string;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
project: {
|
|
104
|
+
/**
|
|
105
|
+
* This project's layer revision, or null when it declares nothing beyond
|
|
106
|
+
* the base set. Null is a real answer, not a missing one.
|
|
107
|
+
*/
|
|
108
|
+
rev: string | null;
|
|
109
|
+
/** Whether this project's published build renders server components. */
|
|
110
|
+
rsc: boolean;
|
|
111
|
+
/** Specifier -> chunk name for the project's own layer. */
|
|
112
|
+
modules: Record<string, string>;
|
|
113
|
+
/** Stylesheets the project imports from its dependencies. */
|
|
114
|
+
css: Record<string, string>;
|
|
115
|
+
/**
|
|
116
|
+
* Specifiers layered for the worker only. Importing one from client code
|
|
117
|
+
* is an error the client build reports, rather than a chunk URL that 404s
|
|
118
|
+
* in the browser.
|
|
119
|
+
*/
|
|
120
|
+
workerOnly: Array<string>;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The cheap half, for the one question a publisher asks before it has built
|
|
125
|
+
* anything: must I send my dependency layer at all?
|
|
126
|
+
*
|
|
127
|
+
* Answered by `?only=rev`, because the full response reads the whole layer out
|
|
128
|
+
* of storage to get its specifier map -- several megabytes to establish a
|
|
129
|
+
* string comparison.
|
|
130
|
+
*/
|
|
131
|
+
export interface BuildTargetRev {
|
|
132
|
+
project: {
|
|
133
|
+
rev: string | null;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** `blob <length>\0<content>`, hashed. The same value as `git hash-object`. */
|
|
2
|
+
export declare function blobSha(content: Uint8Array): Promise<string>;
|
|
3
|
+
/** A file, as this record holds it: its bytes and whether git marks it executable. */
|
|
4
|
+
export interface TreeFile {
|
|
5
|
+
content: Uint8Array;
|
|
6
|
+
executable?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The tree hash of a whole file record.
|
|
10
|
+
*
|
|
11
|
+
* Paths are `/`-separated and may or may not start with one -- a leading slash
|
|
12
|
+
* is stripped, because a record keyed `/src/a.ts` and one keyed `src/a.ts` are
|
|
13
|
+
* the same tree and must not hash differently.
|
|
14
|
+
*
|
|
15
|
+
* An empty record hashes to git's empty tree, which is a real object with a
|
|
16
|
+
* well-known id rather than a special case.
|
|
17
|
+
*/
|
|
18
|
+
export declare function treeSha(files: Record<string, TreeFile>): Promise<string>;
|
|
19
|
+
/** The common case: a record of text files, none executable. */
|
|
20
|
+
export declare function treeShaOfText(files: Record<string, string>): Promise<string>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Building a TanStack Start app from a Val project's files.
|
|
3
|
+
*
|
|
4
|
+
* Three things that used to be three packages in valbuild/home -- the browser
|
|
5
|
+
* builder, the wiring that turns an imported checkout into something a host can
|
|
6
|
+
* serve, and the types the two sides of the wire agree on. They are one package
|
|
7
|
+
* because they are one decision: what a published build IS.
|
|
8
|
+
*
|
|
9
|
+
* ## Why here, and not there
|
|
10
|
+
*
|
|
11
|
+
* The builder had already been severed from the platform's vendor package --
|
|
12
|
+
* it takes a {@link BuildTarget} as a parameter rather than importing the
|
|
13
|
+
* platform's externals at compile time -- and severing it was what made it
|
|
14
|
+
* movable at all. What forced the move was the WIRING: it writes code against
|
|
15
|
+
* `initValServer`'s signature, and it lived in another repository on another
|
|
16
|
+
* release train, so a signature change here could not break it until someone
|
|
17
|
+
* published. Now it is beside the function it calls.
|
|
18
|
+
*
|
|
19
|
+
* ## Two entrypoints, and the line between them
|
|
20
|
+
*
|
|
21
|
+
* This one runs anywhere: a browser tab, a Worker, Node. The `/node`
|
|
22
|
+
* entrypoint is the half that cannot -- it reads `node_modules` and shells out
|
|
23
|
+
* to the native bundler to build a project's dependency layer. `@valbuild/ui`
|
|
24
|
+
* imports THIS one and must never reach the other; `noNodeFromBrowser.test.ts`
|
|
25
|
+
* is what keeps that true.
|
|
26
|
+
*/
|
|
27
|
+
export * from "./build.js";
|
|
28
|
+
export { aliasMap, type AliasMap } from "./tsconfigPaths.js";
|
|
29
|
+
export { resolveInFiles } from "./paths.js";
|
|
30
|
+
export { scanCandidates, usesTailwind } from "./tailwind.js";
|
|
31
|
+
export * from "./contract.js";
|
|
32
|
+
export * from "./artifacts.js";
|
|
33
|
+
export * from "./gitTree.js";
|
|
34
|
+
export * from "./wire.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The half of the build that needs Node.
|
|
3
|
+
*
|
|
4
|
+
* A project's dependency layer is built from its `node_modules` with the
|
|
5
|
+
* native bundler, its route tree is generated by TanStack's own generator, and
|
|
6
|
+
* both of those read a filesystem. None of it can run in the tab that runs the
|
|
7
|
+
* rest of the build, which is the whole reason this is a separate entrypoint
|
|
8
|
+
* rather than a few more exports: importing it pulls `rolldown` and
|
|
9
|
+
* `@tanstack/router-generator` in, and `@valbuild/ui` ships to a browser.
|
|
10
|
+
*
|
|
11
|
+
* Nothing in here is reachable from the package root. See
|
|
12
|
+
* `noNodeFromBrowser.test.ts`.
|
|
13
|
+
*/
|
|
14
|
+
export { BASE_PROVIDED, auditableImports, auditableSpecifiers, buildVendorLayer, chunkNameFor, collectDependencyCss, cssSpecifiersOf, layerDepsOf, packageOf, type VendorLayer, type VendorPlatform, } from "./vendorLayer.js";
|
|
15
|
+
export { nodeShims, nodeShimSources, NODE_SHIMS, REEXPORT, SHIM_PREFIX, } from "./nodeShims.js";
|
|
16
|
+
export { cssModuleLoader } from "./cssModules.js";
|
|
17
|
+
export { routeSplitter } from "./routeSplitter.js";
|
|
18
|
+
export { generateRouteTree, isFileBased } from "./routes.js";
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shims that are NOT a re-export of the real builtin.
|
|
3
|
+
*
|
|
4
|
+
* There used to be a long list here: a memory filesystem, a stubbed `os`, and a
|
|
5
|
+
* dozen modules whose every access threw by name. All of it rested on this
|
|
6
|
+
* file's original premise -- that the isolate does not provide these. It does.
|
|
7
|
+
* `/__api/builtins` on the loader asks a Dynamic Worker directly, and at
|
|
8
|
+
* compatibility date 2026-08-20 all 48 candidates import under both spellings,
|
|
9
|
+
* `fs` with 105 exports. The stubs were answering questions the runtime could
|
|
10
|
+
* answer better, and they were answering some of them WRONG: a hand-written
|
|
11
|
+
* `os` grew a member at a time, each discovered as `X is not a function` at
|
|
12
|
+
* runtime.
|
|
13
|
+
*
|
|
14
|
+
* So everything that can be is now a re-export (REEXPORT, below), and this is
|
|
15
|
+
* what is left.
|
|
16
|
+
*/
|
|
17
|
+
export declare const NODE_SHIMS: Record<string, string>;
|
|
18
|
+
/**
|
|
19
|
+
* Builtins the isolate provides, re-exported through a bundled module.
|
|
20
|
+
*
|
|
21
|
+
* Not a stub -- these forward to the real thing. The reason they need a module
|
|
22
|
+
* at all is that a package requiring a builtin through CJS (`require("fs")`,
|
|
23
|
+
* which is what the TypeScript compiler does) becomes rolldown's `__require`
|
|
24
|
+
* against an external, and that throws at startup:
|
|
25
|
+
*
|
|
26
|
+
* Calling `require` for "fs" in an environment that doesn't expose the
|
|
27
|
+
* `require` function
|
|
28
|
+
*
|
|
29
|
+
* Routing the specifier to a bundled module turns that CJS require into a
|
|
30
|
+
* static ESM import of `node:fs`, which the isolate answers. That is the whole
|
|
31
|
+
* job: this is a CJS-to-ESM bridge, not a substitute runtime.
|
|
32
|
+
*
|
|
33
|
+
* The export names are ENUMERATED FROM NODE at build time rather than listed by
|
|
34
|
+
* hand. `export * from 'node:crypto'` cannot be checked against an external --
|
|
35
|
+
* rolldown does not know what the isolate's `node:crypto` exports, so a named
|
|
36
|
+
* import of it fails the build with "createPublicKey is not exported". Listing
|
|
37
|
+
* names by hand works and is endless: `fileURLToPath`, then `Module`, then
|
|
38
|
+
* `createPublicKey`, each discovered by a failed build.
|
|
39
|
+
*
|
|
40
|
+
* This CLI runs on Node, so the real module is right there to ask. A name Node
|
|
41
|
+
* has and the isolate does not yields `undefined`, which is what the real
|
|
42
|
+
* module would give.
|
|
43
|
+
*
|
|
44
|
+
* The list is every builtin the platform's dependencies have been seen to
|
|
45
|
+
* import, minus `path` (bundled above) -- NOT every builtin that exists.
|
|
46
|
+
* Importing one here costs a module load in this CLI, and the deprecated and
|
|
47
|
+
* experimental ones (`sys`, `wasi`, `repl`, `domain`, `trace_events`) print
|
|
48
|
+
* warnings for a name nothing emits. Add a name when something emits it; the
|
|
49
|
+
* audit will say so.
|
|
50
|
+
*/
|
|
51
|
+
export declare const REEXPORT: string[];
|
|
52
|
+
/** Every shim, hand-written and generated, by builtin name. */
|
|
53
|
+
export declare function nodeShimSources(): Promise<Record<string, string>>;
|
|
54
|
+
/**
|
|
55
|
+
* The resolved-id prefix for a shim module. Exported so a test can ask the
|
|
56
|
+
* resolver what it does with a shim's own imports -- see scripts/shims-test.ts.
|
|
57
|
+
*/
|
|
58
|
+
export declare const SHIM_PREFIX = "\0platform-node-shim:";
|
|
59
|
+
/**
|
|
60
|
+
* Routes a builtin specifier to a bundled module that forwards to the real one.
|
|
61
|
+
*
|
|
62
|
+
* Bundled rather than external on purpose, and the reason is the whole point of
|
|
63
|
+
* the file: an external leaves the CJS `require("fs")` as rolldown's
|
|
64
|
+
* `__require`, which an isolate with no `require` cannot answer. A bundled
|
|
65
|
+
* module turns it into an ESM import the isolate can.
|
|
66
|
+
*/
|
|
67
|
+
export declare function nodeShims(enabled: boolean): Promise<{
|
|
68
|
+
name: string;
|
|
69
|
+
resolveId(source: string, importer: string | undefined): string | {
|
|
70
|
+
id: string;
|
|
71
|
+
external: boolean;
|
|
72
|
+
} | null;
|
|
73
|
+
load(id: string): string | null;
|
|
74
|
+
}>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RouteSplitter } from "../build.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns a splitter, or null when `@tanstack/router-plugin` is not installed
|
|
4
|
+
* where `from` can see it.
|
|
5
|
+
*
|
|
6
|
+
* Null rather than throwing: not splitting is a valid outcome, and a project
|
|
7
|
+
* that has not asked for it should not be made to install a build plugin.
|
|
8
|
+
*
|
|
9
|
+
* `from` is a DIRECTORY to resolve the plugin from, and it is the publisher's
|
|
10
|
+
* own -- see `loadCompilers`. A caller that wants the project's copy instead
|
|
11
|
+
* can pass the project directory, but that is a different decision from the
|
|
12
|
+
* one this was written for.
|
|
13
|
+
*/
|
|
14
|
+
export declare function routeSplitter(from: string): Promise<RouteSplitter | null>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** A project is file-based if it has a routes directory. */
|
|
2
|
+
export declare function isFileBased(dir: string): Promise<boolean>;
|
|
3
|
+
/**
|
|
4
|
+
* The one line the platform needs from a file-based project. Declared beside
|
|
5
|
+
* the other contract paths, so the browser's route generator adds exactly the
|
|
6
|
+
* same one; re-exported here because this is where it has always been read.
|
|
7
|
+
*/
|
|
8
|
+
import { ENTRY_SHIM } from "../projectPaths.js";
|
|
9
|
+
export { ENTRY_SHIM };
|
|
10
|
+
/**
|
|
11
|
+
* Generates `routeTree.gen.ts` and returns the file map with it (and the entry
|
|
12
|
+
* shim) added.
|
|
13
|
+
*
|
|
14
|
+
* The generator's only interface is the filesystem, so this does write into the
|
|
15
|
+
* project -- and then puts it back exactly as it was. An earlier version left
|
|
16
|
+
* the file there, on the reasoning that the tree "is normally gitignored and
|
|
17
|
+
* regenerated, so writing it is not a surprise". That is false often enough to
|
|
18
|
+
* matter: `valbuild/template-tanstack-starter` *tracks* its `routeTree.gen.ts`,
|
|
19
|
+
* and running `pnpm report:project` against a checkout of it silently rewrote a
|
|
20
|
+
* committed file with different formatting and no eslint header. Inspecting a
|
|
21
|
+
* project should not modify it, least of all one the caller only pointed at.
|
|
22
|
+
*
|
|
23
|
+
* Only the in-memory copy is used for the build, so nothing needs the file to
|
|
24
|
+
* survive. A developer who wants it on disk runs `tsr generate`, which is the
|
|
25
|
+
* command that is supposed to produce it.
|
|
26
|
+
*/
|
|
27
|
+
export declare function generateRouteTree(dir: string, files: Record<string, string>): Promise<Record<string, string>>;
|