@valbuild/tanstack-build 0.0.1-alpha.0 → 0.135.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 +80 -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/contract.d.ts +135 -0
- package/dist/declarations/src/gitTree.d.ts +20 -0
- package/dist/declarations/src/index.d.ts +33 -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 +29 -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 +14 -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 +95 -0
- package/dist/slicedToArray-44c37acc.esm.js +303 -0
- package/dist/slicedToArray-7afed0af.cjs.prod.js +310 -0
- package/dist/slicedToArray-80b0ffd7.cjs.dev.js +310 -0
- package/dist/valbuild-tanstack-build.cjs.d.ts +2 -2
- package/dist/valbuild-tanstack-build.cjs.dev.js +3431 -0
- package/dist/valbuild-tanstack-build.cjs.js +6 -15
- package/dist/valbuild-tanstack-build.cjs.prod.js +3431 -0
- package/dist/valbuild-tanstack-build.esm.js +3402 -0
- package/node/dist/valbuild-tanstack-build-node.cjs.d.ts +2 -2
- package/node/dist/valbuild-tanstack-build-node.cjs.dev.js +2204 -0
- package/node/dist/valbuild-tanstack-build-node.cjs.js +6 -15
- package/node/dist/valbuild-tanstack-build-node.cjs.prod.js +2204 -0
- package/node/dist/valbuild-tanstack-build-node.esm.js +2165 -0
- package/package.json +3 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# @valbuild/tanstack-build
|
|
2
|
+
|
|
3
|
+
## 0.135.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#712](https://github.com/valbuild/val/pull/712) [`8181db8`](https://github.com/valbuild/val/commit/8181db81050d94fe9080a7bc50c051e570165213) Thanks [@freekh](https://github.com/freekh)! - New package: `@valbuild/tanstack-build` builds a TanStack Start app from a Val
|
|
8
|
+
project's files — in the browser, and in Node.
|
|
9
|
+
|
|
10
|
+
It carries three things that were previously in the platform repository:
|
|
11
|
+
|
|
12
|
+
- **the build** — `buildUserApp(input)` produces the server, client and RSC
|
|
13
|
+
bundles, the CSS, the assets and the chunk map, on `@rolldown/browser`, so it
|
|
14
|
+
runs in a tab;
|
|
15
|
+
- **the wiring** — `wireUp(files, options)` writes a project's
|
|
16
|
+
`src/val/val.server.ts` against `@valbuild/tanstack/server`;
|
|
17
|
+
- **the contract** — `BuildTarget`, `UserApp`, `PublishManifest` and the rest of
|
|
18
|
+
the types a host and a build have to agree on.
|
|
19
|
+
|
|
20
|
+
The wiring is the reason for the move rather than a passenger of it. It writes
|
|
21
|
+
code against `initValServer`'s signature, and it used to do that from another
|
|
22
|
+
repository on another release train — so a change to that signature could not
|
|
23
|
+
break it until somebody published, which is to say a user found it. It is now
|
|
24
|
+
beside the function it calls.
|
|
25
|
+
|
|
26
|
+
Everything that needs Node is behind the `@valbuild/tanstack-build/node`
|
|
27
|
+
subpath: the project dependency layer, the route tree, Tailwind's `@plugin` and
|
|
28
|
+
`autoCodeSplitting`. The root entrypoint reaches none of it, and a test walks
|
|
29
|
+
the import graph to keep that true — a browser bundle that pulled in `rolldown`
|
|
30
|
+
or a `node:` builtin would fail in the consuming app's build rather than here.
|
|
31
|
+
`rolldown`, `@tanstack/router-generator` and `@tanstack/router-plugin` are
|
|
32
|
+
optional peer dependencies for the same reason: they are things a project asks
|
|
33
|
+
for.
|
|
34
|
+
|
|
35
|
+
Type-checking this code for the first time, and reviewing it once it was here,
|
|
36
|
+
found several things that had been invisible where it lived — that build strips
|
|
37
|
+
types rather than checking them, and its one check of the generated server file
|
|
38
|
+
runs `tsc --noResolve`, so it cannot see across an import at all.
|
|
39
|
+
|
|
40
|
+
The one that mattered most is about a rename that has gone both ways.
|
|
41
|
+
`ValHttpMode` took `gitCommit`/`gitBranch` up to 0.132, a nested `git` from
|
|
42
|
+
0.133.0, and is flat again here — and the generated `val.server.ts` is compiled
|
|
43
|
+
and run against whatever `@valbuild/tanstack` the PROJECT installed, which the
|
|
44
|
+
platform writing the file has no say in. Sending only the name this release
|
|
45
|
+
knows drops the commit for every app still on 0.133.x, silently: the publish
|
|
46
|
+
then produces no mirrored `.val.ts`, so a save commits and hands over nothing,
|
|
47
|
+
and the site keeps serving its old content with the patches already consumed.
|
|
48
|
+
The template now sends all three keys, and each version reads its own and
|
|
49
|
+
ignores the rest.
|
|
50
|
+
|
|
51
|
+
There is also a test that compiles the generated file against the real package,
|
|
52
|
+
with resolution — the platform's own check runs `tsc --noResolve`, so it cannot
|
|
53
|
+
see across an import at all. It is the right tool for a name that no longer
|
|
54
|
+
exists and the wrong one for this, and it says so: the compiler in this
|
|
55
|
+
repository is looking at a different version of `@valbuild/tanstack` than the
|
|
56
|
+
app is.
|
|
57
|
+
|
|
58
|
+
Two more, both of which changed behaviour:
|
|
59
|
+
|
|
60
|
+
- A split route's deferred half skipped every source transform, so
|
|
61
|
+
`<ClientOnly>` and `createIsomorphicFn()` in a route component were rewritten
|
|
62
|
+
when no splitter was supplied and left alone when one was. Splitting is
|
|
63
|
+
allowed to cost bytes and not to change behaviour.
|
|
64
|
+
- The project dependency-layer build re-audited chunks it had just dropped,
|
|
65
|
+
because its fast path and its retry shared an output directory that nothing
|
|
66
|
+
cleared — so the recovery failed for exactly the case it exists for.
|
|
67
|
+
|
|
68
|
+
And the four the compiler found on its own:
|
|
69
|
+
|
|
70
|
+
- Tailwind's `loadModule` contract was restated by hand and restated wrongly —
|
|
71
|
+
Tailwind also wants a `path`, and the CLI's loader had never sent one. The
|
|
72
|
+
type is now derived from Tailwind's own option, so an upgrade that changes the
|
|
73
|
+
shape is a compile error rather than an `undefined` handed to someone else's
|
|
74
|
+
code.
|
|
75
|
+
- The rolldown output filter was `(chunk: any) => chunk.type === 'chunk'`, which
|
|
76
|
+
does not narrow, so every `.code` read after it was unchecked.
|
|
77
|
+
- The route generator was handed `verboseFileRoutes: true`, a key that is not in
|
|
78
|
+
its config, its types, or anywhere in its dist — inert, behind an `as any`.
|
|
79
|
+
- The same cast was hiding a key the generator does require. Both are gone, and
|
|
80
|
+
so is the cast.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare const extensionOf: (path: string) => string;
|
|
2
|
+
export declare const isAsset: (path: string) => boolean;
|
|
3
|
+
export declare const mimeOf: (path: string) => string;
|
|
4
|
+
/**
|
|
5
|
+
* Below this many decoded bytes, an asset is inlined as a data URI.
|
|
6
|
+
*
|
|
7
|
+
* 4 kB, matching Vite's `assetsInlineLimit` default. The trade is the same one
|
|
8
|
+
* Vite is making: an extra request costs more than 4 kB of base64 does, and
|
|
9
|
+
* above that it stops being true.
|
|
10
|
+
*/
|
|
11
|
+
export declare const INLINE_LIMIT = 4096;
|
|
12
|
+
/** Decoded byte length of base64, without decoding it. */
|
|
13
|
+
export declare function base64Bytes(base64: string): number;
|
|
14
|
+
export interface ResolvedAsset {
|
|
15
|
+
/** What the importing module's default export becomes. */
|
|
16
|
+
url: string;
|
|
17
|
+
/** Set when the asset needs publishing; absent when it was inlined. */
|
|
18
|
+
file?: {
|
|
19
|
+
name: string;
|
|
20
|
+
base64: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Where an asset import resolves to, for one target.
|
|
25
|
+
*
|
|
26
|
+
* Server and client get the *same* URL. An asset is a URL in both, and SSR has
|
|
27
|
+
* to emit the same `src` the browser will hydrate against -- a server bundle
|
|
28
|
+
* with a different URL would be a hydration mismatch on every image.
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolveAsset(path: string, base64: string): Promise<ResolvedAsset>;
|
|
31
|
+
/** Where published assets are served from. Matched by the loader. */
|
|
32
|
+
export declare const ASSET_BASE = "/_app/a/";
|
|
33
|
+
/** The module a resolved asset import becomes. */
|
|
34
|
+
export declare const assetModule: (url: string) => string;
|
|
@@ -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,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,33 @@
|
|
|
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 "./gitTree.js";
|
|
33
|
+
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";
|