@brust/core 2.0.0-alpha.2 → 2.0.0-alpha.20
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/README.md +66 -6
- package/native/index.d.ts +89 -4
- package/native/index.js +60 -54
- package/package.json +25 -9
- package/src/actions/client.ts +22 -5
- package/src/actions/load.ts +2 -1
- package/src/actions/prefix.ts +24 -2
- package/src/actions-bridge.ts +29 -11
- package/src/browser.ts +3 -1
- package/src/build/actions-only.ts +86 -0
- package/src/build/build-eval.ts +332 -0
- package/src/build/build-icons.ts +69 -0
- package/src/build/bundle.ts +462 -52
- package/src/build/cf-assets.ts +83 -0
- package/src/build/cf-core.ts +90 -0
- package/src/build/cf-entry.ts +76 -0
- package/src/build/cf-wrangler.ts +169 -0
- package/src/build/cloudflare.ts +320 -0
- package/src/build/compile.ts +114 -5
- package/src/build/config.ts +294 -11
- package/src/build/css.ts +275 -0
- package/src/build/esm-resolve.ts +170 -0
- package/src/build/features.ts +114 -0
- package/src/build/index.ts +264 -20
- package/src/build/manifest.ts +85 -7
- package/src/build/pkg-src.ts +514 -0
- package/src/build/recognised.ts +19 -0
- package/src/build/scan.ts +71 -20
- package/src/build/server-only.ts +39 -0
- package/src/build/ssg-render.ts +65 -0
- package/src/build/ssg.ts +146 -0
- package/src/build/static-worker.ts +91 -0
- package/src/build/static.ts +258 -0
- package/src/build/tailwind.ts +117 -0
- package/src/build/tsconfig-paths.ts +67 -0
- package/src/build-time.ts +10 -0
- package/src/cache-adapter/bridge.ts +91 -0
- package/src/cache-adapter/conformance.ts +226 -0
- package/src/cache-adapter/index.ts +10 -0
- package/src/cache-adapter/load.ts +144 -0
- package/src/cache-adapter/memory.ts +229 -0
- package/src/cache-adapter/runtime.ts +124 -0
- package/src/cache-adapter/types.ts +96 -0
- package/src/cache-adapter/workers.ts +118 -0
- package/src/cache.ts +4 -1
- package/src/cf.ts +19 -0
- package/src/cli.ts +71 -2
- package/src/config.ts +127 -25
- package/src/css-modules.d.ts +8 -0
- package/src/dev/bun.ts +371 -0
- package/src/dev/client.ts +92 -0
- package/src/dev/devtools-data.ts +23 -0
- package/src/dev/devtools.ts +356 -0
- package/src/dev/diag.ts +30 -0
- package/src/dev/proxy.ts +236 -0
- package/src/dev/tui.ts +144 -0
- package/src/dev/watch.ts +130 -0
- package/src/dev.ts +97 -0
- package/src/handlers.ts +282 -0
- package/src/index.ts +3 -1
- package/src/native.ts +38 -1
- package/src/routes.ts +20 -1
- package/src/run.ts +59 -12
- package/src/server-handlers.ts +32 -0
- package/src/shadcn/init.ts +513 -0
- package/src/shadcn/jsonc.ts +129 -0
- package/src/shadcn/registry.ts +149 -0
- package/src/worker.ts +127 -245
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brust/core",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.20",
|
|
4
4
|
"description": "brust v2 — React components compiled to Rust-rendered templates",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"homepage": "https://brust.dev",
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/AssetsArt/brust.git"
|
|
9
|
+
"url": "git+https://github.com/AssetsArt/brust.git",
|
|
10
|
+
"directory": "packages/brust"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/AssetsArt/brust/issues"
|
|
9
14
|
},
|
|
10
15
|
"type": "module",
|
|
11
16
|
"bin": {
|
|
@@ -13,11 +18,17 @@
|
|
|
13
18
|
},
|
|
14
19
|
"exports": {
|
|
15
20
|
".": {
|
|
21
|
+
"workerd": "./src/cf.ts",
|
|
16
22
|
"browser": "./src/browser.ts",
|
|
17
23
|
"default": "./src/index.ts"
|
|
18
24
|
},
|
|
25
|
+
"./build-time": "./src/build-time.ts",
|
|
19
26
|
"./routes": "./src/routes.ts",
|
|
20
27
|
"./server": "./src/server.ts",
|
|
28
|
+
"./server-handlers": "./src/server-handlers.ts",
|
|
29
|
+
"./server-handlers/actions": "./src/actions/load.ts",
|
|
30
|
+
"./cache-adapter": "./src/cache-adapter/index.ts",
|
|
31
|
+
"./cache-adapter/conformance": "./src/cache-adapter/conformance.ts",
|
|
21
32
|
"./store": "./src/store/index.ts",
|
|
22
33
|
"./store/react": "./src/store/react.ts",
|
|
23
34
|
"./elysia": "./src/actions/elysia.ts",
|
|
@@ -44,7 +55,8 @@
|
|
|
44
55
|
]
|
|
45
56
|
},
|
|
46
57
|
"dependencies": {
|
|
47
|
-
"@brust/runtime-dom": "2.0.0-alpha.
|
|
58
|
+
"@brust/runtime-dom": "2.0.0-alpha.20",
|
|
59
|
+
"tsconfig-paths": "4.2.0"
|
|
48
60
|
},
|
|
49
61
|
"peerDependencies": {
|
|
50
62
|
"react": "^19.0.0",
|
|
@@ -63,9 +75,12 @@
|
|
|
63
75
|
"devDependencies": {
|
|
64
76
|
"@elysia/eden": "2.0.0-beta.6",
|
|
65
77
|
"@napi-rs/cli": "^3.0.0",
|
|
78
|
+
"@radix-ui/react-collection": "1.2.0",
|
|
79
|
+
"@radix-ui/react-slot": "1.5.0",
|
|
66
80
|
"@types/bun": "^1.4.0",
|
|
67
81
|
"@types/react": "^19.2.0",
|
|
68
82
|
"elysia": "2.0.0-beta.30",
|
|
83
|
+
"lucide-react": "1.55.0",
|
|
69
84
|
"react": "^19.2.0",
|
|
70
85
|
"react-dom": "^19.2.0",
|
|
71
86
|
"typescript": "^7.0.2"
|
|
@@ -81,11 +96,12 @@
|
|
|
81
96
|
"access": "public"
|
|
82
97
|
},
|
|
83
98
|
"optionalDependencies": {
|
|
84
|
-
"@brust/native-darwin-x64": "2.0.0-alpha.
|
|
85
|
-
"@brust/native-darwin-arm64": "2.0.0-alpha.
|
|
86
|
-
"@brust/native-linux-x64-gnu": "2.0.0-alpha.
|
|
87
|
-
"@brust/native-linux-arm64-gnu": "2.0.0-alpha.
|
|
88
|
-
"@brust/native-linux-x64-musl": "2.0.0-alpha.
|
|
89
|
-
"@brust/native-linux-arm64-musl": "2.0.0-alpha.
|
|
99
|
+
"@brust/native-darwin-x64": "2.0.0-alpha.20",
|
|
100
|
+
"@brust/native-darwin-arm64": "2.0.0-alpha.20",
|
|
101
|
+
"@brust/native-linux-x64-gnu": "2.0.0-alpha.20",
|
|
102
|
+
"@brust/native-linux-arm64-gnu": "2.0.0-alpha.20",
|
|
103
|
+
"@brust/native-linux-x64-musl": "2.0.0-alpha.20",
|
|
104
|
+
"@brust/native-linux-arm64-musl": "2.0.0-alpha.20",
|
|
105
|
+
"@brust/core-cf": "2.0.0-alpha.20"
|
|
90
106
|
}
|
|
91
107
|
}
|
package/src/actions/client.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// elysia is type-only here. Differences from 0.1.x runtime/treaty.ts: docs/actions.md "The client".
|
|
3
3
|
import { type Treaty, treaty } from '@elysia/eden/treaty2'
|
|
4
4
|
import type { AnyElysia } from 'elysia'
|
|
5
|
-
import { DEFAULT_ACTION_PREFIX } from './prefix'
|
|
5
|
+
import { type ActionCredentials, DEFAULT_ACTION_PREFIX } from './prefix'
|
|
6
6
|
|
|
7
7
|
export { DEFAULT_ACTION_PREFIX }
|
|
8
8
|
export type { Treaty }
|
|
@@ -19,7 +19,17 @@ export interface ClientOptions<Head extends Record<string, unknown> = {}>
|
|
|
19
19
|
init?: Treaty.Config<Head>['fetch']
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
interface PageGlobals {
|
|
23
|
+
__BRUST_ACTION_PREFIX__?: string
|
|
24
|
+
/** L16 R16.1: injected from `[actions] base_url` / BRUST_ACTIONS_BASE_URL / run({ config: { actionsBaseUrl } }). */
|
|
25
|
+
__BRUST_ACTION_BASE__?: string
|
|
26
|
+
/** L16 R16.2: injected from `[actions] credentials`. */
|
|
27
|
+
__BRUST_ACTION_CREDENTIALS__?: ActionCredentials
|
|
28
|
+
}
|
|
29
|
+
const page = () => globalThis as PageGlobals
|
|
30
|
+
|
|
31
|
+
/** 0.1.x runtime/treaty.ts:86-93, verbatim order. A per-call `baseUrl` keeps the default prefix; a base that comes
|
|
32
|
+
* from the page global (L16) pairs with the page's injected prefix, both being the same deployment's config. */
|
|
23
33
|
export function resolvePrefix(opts?: { prefix?: string; baseUrl?: string }): string {
|
|
24
34
|
if (opts?.prefix) return opts.prefix
|
|
25
35
|
if (opts?.baseUrl !== undefined) return DEFAULT_ACTION_PREFIX
|
|
@@ -31,7 +41,8 @@ export function resolvePrefix(opts?: { prefix?: string; baseUrl?: string }): str
|
|
|
31
41
|
|
|
32
42
|
/** 0.1.x runtime/treaty.ts:95-106; message names `client`. */
|
|
33
43
|
export function resolveBaseUrl(opts?: { baseUrl?: string }): string {
|
|
34
|
-
|
|
44
|
+
// R16.1 order: opts.baseUrl, the page's __BRUST_ACTION_BASE__, relative.
|
|
45
|
+
const b = opts?.baseUrl ?? page().__BRUST_ACTION_BASE__
|
|
35
46
|
if (b === undefined) return ''
|
|
36
47
|
if (!/^https?:\/\//.test(b))
|
|
37
48
|
throw new Error(
|
|
@@ -44,11 +55,17 @@ export function client<const App extends AnyElysia, Head extends Record<string,
|
|
|
44
55
|
opts: ClientOptions<Head> = {},
|
|
45
56
|
): Treaty.Instance<App, Head> {
|
|
46
57
|
const { prefix: _p, baseUrl: _b, fetch: fetcher, init, ...rest } = opts
|
|
58
|
+
// R16.2: the page's credentials default (`opts.init` wins); only when it differs from the browser default.
|
|
59
|
+
const creds = page().__BRUST_ACTION_CREDENTIALS__
|
|
60
|
+
const defaults = creds !== undefined && creds !== 'same-origin' && typeof init !== 'function' ? { credentials: creds } : undefined
|
|
47
61
|
// keepDomain: Eden would rewrite a relative base to `https:///…` (probe kd.ts).
|
|
48
|
-
|
|
62
|
+
// The root prefix (an actions-only deployment) adds nothing to the base: `https://api.example.com/team`, not `//team`.
|
|
63
|
+
const base = resolveBaseUrl(opts)
|
|
64
|
+
const prefix = resolvePrefix(opts)
|
|
65
|
+
return treaty<App, Head>(base !== '' && prefix === '/' ? base : base + prefix, {
|
|
49
66
|
...rest,
|
|
50
67
|
keepDomain: true,
|
|
51
68
|
...(fetcher ? { fetcher } : {}),
|
|
52
|
-
...(init ? { fetch: init } : {}),
|
|
69
|
+
...(init || defaults ? { fetch: typeof init === 'function' ? init : { ...defaults, ...init } } : {}),
|
|
53
70
|
})
|
|
54
71
|
}
|
package/src/actions/load.ts
CHANGED
|
@@ -14,7 +14,8 @@ export function mountActions(app: unknown, prefix: string, what = 'actions entry
|
|
|
14
14
|
throw new Error(
|
|
15
15
|
`${what}: build the app with new Elysia({ adapter: brust() }) — import { brust } from '@brust/core/elysia'`,
|
|
16
16
|
)
|
|
17
|
-
|
|
17
|
+
// L16 R16.4: the root prefix of an actions-only build is no prefix at all (`prefix: '/'` would double the slash).
|
|
18
|
+
return new Elysia({ adapter: brust(), ...(prefix === '/' ? {} : { prefix }) }).use(app)
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export async function loadActionsApp(file: string, prefix: string): Promise<AnyElysia> {
|
package/src/actions/prefix.ts
CHANGED
|
@@ -5,8 +5,10 @@ export const DEFAULT_MAX_RESPONSE_BYTES = 8_388_608
|
|
|
5
5
|
export const MAX_ACTION_BYTES = 67_108_864
|
|
6
6
|
const SEG = /^[A-Za-z0-9._~-]+$/
|
|
7
7
|
|
|
8
|
-
/** Why `p` cannot be the actions prefix, or null. Segment-safe like the server's match.
|
|
9
|
-
|
|
8
|
+
/** Why `p` cannot be the actions prefix, or null. Segment-safe like the server's match. `root`: an actions-only
|
|
9
|
+
* build (L16 R16.4) may mount at `/`; a normal build never may (its page routes would be unreachable). */
|
|
10
|
+
export function prefixError(p: unknown, root = false): string | null {
|
|
11
|
+
if (root && p === '/') return null
|
|
10
12
|
if (typeof p !== 'string' || !p.startsWith('/') || p.length < 2 || p.endsWith('/'))
|
|
11
13
|
return `must start with '/', be longer than '/' and have no trailing '/' (got ${JSON.stringify(p)})`
|
|
12
14
|
const segs = p.slice(1).split('/')
|
|
@@ -21,3 +23,23 @@ export function prefixError(p: unknown): string | null {
|
|
|
21
23
|
return `${p} is reserved for the server's own /_brust/ paths`
|
|
22
24
|
return null
|
|
23
25
|
}
|
|
26
|
+
|
|
27
|
+
/** L16 R16.1: `base_url` is an absolute http(s) origin: scheme, host, optional port; no path, query, fragment or userinfo. */
|
|
28
|
+
export function baseUrlError(v: unknown): string | null {
|
|
29
|
+
if (typeof v !== 'string' || !/^https?:\/\//.test(v))
|
|
30
|
+
return `must be an absolute http(s) origin such as https://api.example.com (got ${JSON.stringify(v)})`
|
|
31
|
+
let u: URL
|
|
32
|
+
try {
|
|
33
|
+
u = new URL(v)
|
|
34
|
+
} catch {
|
|
35
|
+
return `is not a valid URL (got ${JSON.stringify(v)})`
|
|
36
|
+
}
|
|
37
|
+
const authority = v.replace(/^https?:\/\//, '')
|
|
38
|
+
if (u.search !== '' || u.hash !== '' || u.username !== '' || u.password !== '' || /[/?#@\\\s]/.test(authority))
|
|
39
|
+
return `must be an origin only: no path, query, fragment or credentials (got ${JSON.stringify(v)})`
|
|
40
|
+
return null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** L16 R16.2: the default `RequestInit.credentials` of the browser client. */
|
|
44
|
+
export const ACTION_CREDENTIALS = ['same-origin', 'include', 'omit'] as const
|
|
45
|
+
export type ActionCredentials = (typeof ACTION_CREDENTIALS)[number]
|
package/src/actions-bridge.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface FetchRequest {
|
|
|
22
22
|
method: string
|
|
23
23
|
url: string
|
|
24
24
|
headers: [string, string][]
|
|
25
|
-
/** `{heap: n}` (F82): more than 262144 bytes, fetched with `takeFetchBody(slot)`. */
|
|
25
|
+
/** `{heap: n}` (F82): more than 262144 bytes (`ACTION_INLINE_BODY_BYTES`, independent of the slot size), fetched with `takeFetchBody(slot)`. */
|
|
26
26
|
body: { text: string } | { b64: string } | { heap: number } | null
|
|
27
27
|
req: LoaderReq
|
|
28
28
|
}
|
|
@@ -112,8 +112,34 @@ export function readFramed(view: Uint8Array, slot: number, slots: number, len: n
|
|
|
112
112
|
|
|
113
113
|
const fail = (view: Uint8Array, slot: number, slots: number, msg: string) => writeFramed(view, slot, slots, 500, TEXT_PLAIN, enc.encode(msg))
|
|
114
114
|
|
|
115
|
+
/** The store-scoped core shared by `runFetch` and `fetchInScope`: R1/E5 — one store scope around the handler AND the
|
|
116
|
+
* body read (a lazy body may still touch stores); set-cookie values kept apart. */
|
|
117
|
+
export async function fetchParts(a: ActionsApp, req: Request): Promise<{ status: number; pairs: [string, string][]; body: Uint8Array }> {
|
|
118
|
+
return runInStoreContext(async () => {
|
|
119
|
+
const res = await a.fetch(req)
|
|
120
|
+
const pairs: [string, string][] = []
|
|
121
|
+
res.headers.forEach((v, k) => {
|
|
122
|
+
if (k !== 'set-cookie') pairs.push([k, v])
|
|
123
|
+
})
|
|
124
|
+
for (const c of res.headers.getSetCookie()) pairs.push(['set-cookie', c])
|
|
125
|
+
return { status: res.status, pairs, body: new Uint8Array(await res.arrayBuffer()) }
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Host-agnostic entry (Cloudflare `action(req)`): the same scope and framing-free parts as `runFetch`, as a Response. */
|
|
130
|
+
export async function fetchInScope(a: ActionsApp, req: Request): Promise<Response> {
|
|
131
|
+
const { status, pairs, body } = await fetchParts(a, req)
|
|
132
|
+
const headers = new Headers()
|
|
133
|
+
for (const [k, v] of pairs) headers.append(k, v)
|
|
134
|
+
return new Response([101, 204, 205, 304].includes(status) ? null : (body as BodyInit), { status, headers })
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The `action` export of a worker whose app has no `[actions]`. */
|
|
138
|
+
export const noActions = async (_: Request): Promise<Response> =>
|
|
139
|
+
new Response('brust: actions are not configured in this worker', { status: 500, headers: { 'content-type': 'text/plain; charset=utf-8' } })
|
|
140
|
+
|
|
115
141
|
/** The `fetch` call (makeDispatch). Never rejects, never writes JSON: every outcome is a frame. A body of
|
|
116
|
-
* more than 262144 bytes arrives by `io.takeBody` (A1 `{heap}`); a response that does not fit the slot leaves
|
|
142
|
+
* more than 262144 bytes (`ACTION_INLINE_BODY_BYTES`, not the slot size) arrives by `io.takeBody` (A1 `{heap}`); a response that does not fit the slot leaves
|
|
117
143
|
* by `io.putReply` with only status/headers/`heap` in the slot (F82), unless it exceeds `max_response_bytes`. */
|
|
118
144
|
export async function runFetch(requestJson: string, view: Uint8Array, slot: number, slots: number, io: HeapIo = nativeHeapIo): Promise<number> {
|
|
119
145
|
const a = app
|
|
@@ -128,15 +154,7 @@ export async function runFetch(requestJson: string, view: Uint8Array, slot: numb
|
|
|
128
154
|
}
|
|
129
155
|
const req = toRequest(fr, heapBody)
|
|
130
156
|
// R1/E5: one store scope around the handler AND the body read (a lazy body may still touch stores).
|
|
131
|
-
const out = await
|
|
132
|
-
const res = await a.fetch(req)
|
|
133
|
-
const pairs: [string, string][] = []
|
|
134
|
-
res.headers.forEach((v, k) => {
|
|
135
|
-
if (k !== 'set-cookie') pairs.push([k, v])
|
|
136
|
-
})
|
|
137
|
-
for (const c of res.headers.getSetCookie()) pairs.push(['set-cookie', c])
|
|
138
|
-
return { status: res.status, pairs, body: new Uint8Array(await res.arrayBuffer()) }
|
|
139
|
-
})
|
|
157
|
+
const out = await fetchParts(a, req)
|
|
140
158
|
const sub = Math.floor(view.byteLength / Math.max(1, slots))
|
|
141
159
|
const metaLen = (m: FetchMeta) => enc.encode(JSON.stringify(m)).length
|
|
142
160
|
if (4 + metaLen({ status: out.status, headers: out.pairs }) + out.body.length <= sub) return writeFramed(view, slot, slots, out.status, out.pairs, out.body)
|
package/src/browser.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
/// <reference path="./css-modules.d.ts" />
|
|
1
2
|
// `@brust/core` under the `browser` export condition (and what every browser bundle of
|
|
2
3
|
// `brust build` resolves the package root to): only the side-effect-free pieces. No `run`, no
|
|
3
4
|
// config, no napi addon — a react island may import `cache` from the package root.
|
|
4
5
|
import { cacheComponent } from './cache-core'
|
|
6
|
+
export { buildTime } from './build-time'
|
|
5
7
|
import type { InvalidateArgs, InvalidateResult } from './native'
|
|
6
8
|
|
|
7
9
|
function invalidate(_args: InvalidateArgs): InvalidateResult {
|
|
@@ -26,4 +28,4 @@ export {
|
|
|
26
28
|
Outlet,
|
|
27
29
|
redirect,
|
|
28
30
|
} from './routes'
|
|
29
|
-
export type { ComponentType, FlatRoute, HttpErrorOpts, HttpErrorTrigger, LoaderCtx, LoaderReq, Route, RouteCacheConfig, Verdict } from './routes'
|
|
31
|
+
export type { ComponentType, FlatRoute, HttpErrorOpts, HttpErrorTrigger, LoaderCtx, LoaderReq, Route, RouteCacheConfig, RouteSsgConfig, Verdict } from './routes'
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// `brust build --actions-only` (gaps round L16, R16.3/R16.4): a dist with NO page routes: the actions app behind
|
|
2
|
+
// the same Rust admission (method gate, body caps, `Content-Encoding`, the cross-site guard, CORS), every other
|
|
3
|
+
// path a 404 problem+json. With `--target cloudflare` it also writes `<out>/cf/`: a Worker serving only actions
|
|
4
|
+
// (no Static Assets). The routes entry is neither read nor required.
|
|
5
|
+
import { existsSync, mkdirSync, renameSync, rmSync, writeFileSync } from 'node:fs'
|
|
6
|
+
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path'
|
|
7
|
+
import { buildActions } from './bundle'
|
|
8
|
+
import { type CfPrepared, buildCloudflare, prepareCloudflare } from './cloudflare'
|
|
9
|
+
import type { ActionsBuildConfig, BuildConfig } from './config'
|
|
10
|
+
import { BuildError } from './errors'
|
|
11
|
+
import { MANIFEST_VERSION, type ManifestJson } from './manifest'
|
|
12
|
+
|
|
13
|
+
const MARKER = '.brust'
|
|
14
|
+
|
|
15
|
+
export async function runActionsOnly(o: {
|
|
16
|
+
appRoot: string
|
|
17
|
+
dist: string
|
|
18
|
+
config: BuildConfig
|
|
19
|
+
target: 'bun' | 'cloudflare' | 'static' | undefined
|
|
20
|
+
wasmFromSource: boolean
|
|
21
|
+
statOk: (p: string) => boolean
|
|
22
|
+
assertSafeOutDir: (dist: string, appRoot: string, keep: string[]) => void
|
|
23
|
+
log: (s: string) => void
|
|
24
|
+
}): Promise<void> {
|
|
25
|
+
const { appRoot, dist, config } = o
|
|
26
|
+
const actions: ActionsBuildConfig | null = config.actions
|
|
27
|
+
if (!actions) throw new BuildError('actions-only', '--actions-only needs an [actions] table in brust.toml')
|
|
28
|
+
if (o.target === 'static') throw new BuildError('actions-only', '--actions-only builds no pages: it cannot be combined with --target static')
|
|
29
|
+
const entry = resolve(appRoot, actions.entry)
|
|
30
|
+
const rel = relative(appRoot, entry)
|
|
31
|
+
if (isAbsolute(actions.entry) || rel === '..' || rel.startsWith('../') || isAbsolute(rel) || !o.statOk(entry))
|
|
32
|
+
throw new BuildError('actions-entry', `actions.entry ${actions.entry} is not a file inside the app`)
|
|
33
|
+
o.assertSafeOutDir(dist, appRoot, [entry])
|
|
34
|
+
if (config.cache) o.log('[brust] actions-only: [cache] and route options do not apply (ignored)')
|
|
35
|
+
if (actions.baseUrl !== undefined) o.log('[brust] actions-only: [actions] base_url is for the pages that call these actions (ignored here)')
|
|
36
|
+
const cf: CfPrepared | null = o.target === 'cloudflare' ? await prepareCloudflare(appRoot, config.cloudflare, { fromSource: o.wasmFromSource, env: process.env }) : null
|
|
37
|
+
|
|
38
|
+
const tmp = join(dirname(dist), `.${basename(dist)}.brust-tmp`)
|
|
39
|
+
rmSync(tmp, { recursive: true, force: true })
|
|
40
|
+
mkdirSync(tmp, { recursive: true })
|
|
41
|
+
try {
|
|
42
|
+
const manifest: ManifestJson = {
|
|
43
|
+
version: MANIFEST_VERSION,
|
|
44
|
+
routes: [],
|
|
45
|
+
components: {},
|
|
46
|
+
assets: { runtime: '', features: {} },
|
|
47
|
+
jobs_module: 'jobs.js',
|
|
48
|
+
actions: { entry: await buildActions(tmp, entry), prefix: actions.prefix, maxBodyBytes: actions.maxBodyBytes, maxResponseBytes: actions.maxResponseBytes, crossSite: actions.crossSite },
|
|
49
|
+
actions_only: true,
|
|
50
|
+
}
|
|
51
|
+
mkdirSync(join(tmp, 'jinja'), { recursive: true })
|
|
52
|
+
writeFileSync(join(tmp, 'jobs.js'), '// generated by `brust build --actions-only`: no pages, so no jobs\nexport default {}\n')
|
|
53
|
+
writeFileSync(join(tmp, 'manifest.json'), `${JSON.stringify(manifest, null, 2)}\n`)
|
|
54
|
+
writeFileSync(join(tmp, MARKER), 'generated by `brust build`: this directory is replaced on every build\n')
|
|
55
|
+
writeFileSync(
|
|
56
|
+
join(tmp, 'index.js'),
|
|
57
|
+
[
|
|
58
|
+
'// generated by `brust build --actions-only` — `bun dist/index.js` serves the actions (do not edit)',
|
|
59
|
+
"process.env.BRUST_PREBUILT = '1'",
|
|
60
|
+
'process.env.BRUST_DIST_DIR = import.meta.dir',
|
|
61
|
+
"const { run } = await import('@brust/core')",
|
|
62
|
+
'await run()',
|
|
63
|
+
'',
|
|
64
|
+
].join('\n'),
|
|
65
|
+
)
|
|
66
|
+
if (cf) {
|
|
67
|
+
const warnings = await buildCloudflare(
|
|
68
|
+
tmp,
|
|
69
|
+
{ appRoot, entry, dist, compiled: new Map(), manifest, sourceOf: new Map(), actionsEntry: entry, actionsOnly: true, log: o.log },
|
|
70
|
+
cf,
|
|
71
|
+
)
|
|
72
|
+
for (const w of warnings) o.log(w)
|
|
73
|
+
}
|
|
74
|
+
rmSync(join(tmp, '.stage'), { recursive: true, force: true })
|
|
75
|
+
if (existsSync(dist)) {
|
|
76
|
+
const old = join(dirname(dist), `.${basename(dist)}.brust-old`)
|
|
77
|
+
rmSync(old, { recursive: true, force: true })
|
|
78
|
+
renameSync(dist, old)
|
|
79
|
+
renameSync(tmp, dist)
|
|
80
|
+
rmSync(old, { recursive: true, force: true })
|
|
81
|
+
} else renameSync(tmp, dist)
|
|
82
|
+
} catch (e) {
|
|
83
|
+
rmSync(tmp, { recursive: true, force: true })
|
|
84
|
+
throw e
|
|
85
|
+
}
|
|
86
|
+
}
|