@ultimat3/cli 31.49.0 → 31.51.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.
Files changed (68) hide show
  1. package/CLAUDE.md +1 -1
  2. package/package.json +30 -30
  3. package/src/api-registration.ts +18 -1
  4. package/src/api-routes.ts +1 -0
  5. package/src/app-boundaries.ts +2 -0
  6. package/src/app-dev-imports.ts +77 -0
  7. package/src/app-load-import-chain.ts +112 -0
  8. package/src/app-load-unresolved.ts +173 -16
  9. package/src/app-load.ts +23 -7
  10. package/src/app-openapi.ts +7 -1
  11. package/src/budgets.ts +2 -1
  12. package/src/cmd-i18n.ts +33 -1
  13. package/src/codemods/engine-fs.ts +9 -2
  14. package/src/codemods/merge-drivers.ts +85 -4
  15. package/src/dev-only-imports.ts +59 -0
  16. package/src/error-codes-boundary.ts +2 -0
  17. package/src/evaluated-walk.ts +103 -0
  18. package/src/exercise-services.ts +13 -3
  19. package/src/framework-schema.ts +15 -5
  20. package/src/guard-sources.ts +1 -2
  21. package/src/index.ts +2 -0
  22. package/src/mcp-errors.ts +3 -1
  23. package/src/messages-upgrade.ts +4 -0
  24. package/src/module-imports.ts +26 -15
  25. package/src/page-navigation.ts +5 -2
  26. package/src/page-route.ts +75 -0
  27. package/src/pwa-artifacts.ts +1 -1
  28. package/src/retained-assets-boot.ts +1 -1
  29. package/src/runtime-assets-site.ts +2 -2
  30. package/src/runtime-assets.ts +1 -1
  31. package/src/runtime-render-document.ts +1 -2
  32. package/src/scan-ways.ts +145 -0
  33. package/src/site-asset-routes.ts +2 -2
  34. package/src/site-assets.ts +5 -158
  35. package/src/sw-precache-plan.ts +1 -1
  36. package/src/templates/guard-raw-motion.ts +96 -0
  37. package/src/templates/guard-released-forms.ts +4 -1
  38. package/src/templates/scaffold-repo.ts +1 -1
  39. package/src/test-only-shipped.ts +29 -2
  40. package/src/test-shards.ts +20 -8
  41. package/src/upgrade-coverage-ratchet.ts +95 -0
  42. package/src/upgrade-gate.ts +31 -11
  43. package/src/upgrade-report.ts +14 -0
  44. package/src/verify-checks.ts +7 -3
  45. package/src/verify-e2e.ts +21 -3
  46. package/src/workspace-checks.ts +4 -1
  47. package/wiki/Actions.md +64 -2
  48. package/wiki/Auth.md +6 -2
  49. package/wiki/CLI-Reference.md +8 -2
  50. package/wiki/Client-Navigation.md +34 -4
  51. package/wiki/Configuration.md +2 -1
  52. package/wiki/Entities-And-Migrations.md +12 -2
  53. package/wiki/Home.md +2 -2
  54. package/wiki/I18n.md +1 -1
  55. package/wiki/Interface-Rules.md +3 -1
  56. package/wiki/Known-Gaps.md +1 -1
  57. package/wiki/MCP-And-AI.md +41 -9
  58. package/wiki/Notify.md +4 -2
  59. package/wiki/Outbound-HTTP.md +53 -2
  60. package/wiki/Policies-And-Authz.md +1 -1
  61. package/wiki/Realtime.md +14 -6
  62. package/wiki/Routes-And-Render-Modes.md +1 -1
  63. package/wiki/Static-Assets.md +5 -3
  64. package/wiki/Testing.md +82 -3
  65. package/wiki/Theming.md +6 -3
  66. package/wiki/Troubleshooting.md +1 -1
  67. package/wiki/UI-Components.md +1 -0
  68. package/wiki/Upgrading.md +2 -0
@@ -0,0 +1,75 @@
1
+ // Single responsibility: a registered page's GET through the real `httpPipeline`, for a unit test —
2
+ // what a visitor RECEIVES (status, headers, cookies set, redirect, document), where `renderRoute`
3
+ // answers what the page renders. It lives in cli because the page handler (`appRoutes`) does.
4
+
5
+ import { assert } from '@ultimat3/core';
6
+ import { defineHttpConfig, httpPipeline, httpRouter } from '@ultimat3/http';
7
+ import { attachedIsr } from './runtime-isr';
8
+ import { appRoutes } from './runtime-render';
9
+
10
+ export interface PageRouteOptions {
11
+ /** Request headers, as a browser sends them (`accept-language`, `if-none-match` …). */
12
+ readonly headers?: Readonly<Record<string, string>>;
13
+ /**
14
+ * Cookies the request carries, by name; each value is percent-encoded as `useRequestCookie`
15
+ * decodes it. Pass either this or a `cookie` header, never both.
16
+ */
17
+ readonly cookies?: Readonly<Record<string, string>>;
18
+ /** The build the document names. Default `'page-route'`. */
19
+ readonly buildId?: string;
20
+ }
21
+
22
+ const ORIGIN = 'http://localhost';
23
+
24
+ const cookieHeader = (cookies: Readonly<Record<string, string>>): string =>
25
+ Object.entries(cookies)
26
+ .map(([name, value]) => `${name}=${encodeURIComponent(value)}`)
27
+ .join('; ');
28
+
29
+ /**
30
+ * `GET <path>` against the pages registered in this process (`registerRoute`, or `loadApp`), as the
31
+ * response a visitor gets. `path` is the URL path and query (`/es/precios?page=2`), starting with
32
+ * `/`. A path no page claims answers the pipeline's own 404.
33
+ *
34
+ * ```ts
35
+ * const response = await pageRoute('/dashboard', { cookies: { sid: 's-1' } });
36
+ * expect(response.status).toBe(200);
37
+ * expect(response.headers.getSetCookie()).toEqual([]);
38
+ * ```
39
+ */
40
+ export async function pageRoute(path: string, options: PageRouteOptions = {}): Promise<Response> {
41
+ assert(
42
+ path.startsWith('/'),
43
+ 'pageRoute requires a URL path starting with a slash',
44
+ "pageRoute('/dashboard?tab=2')",
45
+ );
46
+ const headers = new Headers(options.headers);
47
+ if (options.cookies !== undefined) {
48
+ assert(
49
+ !headers.has('cookie'),
50
+ 'pageRoute was handed both `cookies` and a `cookie` header',
51
+ "pageRoute('/dashboard', { cookies: { sid: 's-1' } })",
52
+ );
53
+ if (Object.keys(options.cookies).length > 0) {
54
+ headers.set('cookie', cookieHeader(options.cookies));
55
+ }
56
+ }
57
+ const buildId = options.buildId ?? 'page-route';
58
+ // One ISR controller per call, released after it: `appRoutes` would otherwise attach one it
59
+ // never detaches, and every call of a suite would leave a revalidator behind.
60
+ const { isr, release } = attachedIsr({ buildId });
61
+ try {
62
+ const pipeline = httpPipeline({
63
+ table: httpRouter(appRoutes({ buildId, isr })),
64
+ config: defineHttpConfig({
65
+ dev: false,
66
+ buildId,
67
+ hostname: '127.0.0.1',
68
+ rateLimit: { scope: 'process' },
69
+ }),
70
+ });
71
+ return await pipeline.handle(new Request(`${ORIGIN}${path}`, { headers }), { role: 'web' });
72
+ } finally {
73
+ release();
74
+ }
75
+ }
@@ -30,12 +30,12 @@ import {
30
30
  } from '@ultimat3/pwa';
31
31
  import type { AssetPath } from '@ultimat3/render';
32
32
  import { assetPathProblem } from '@ultimat3/render';
33
+ import { parseHashedAssetUrl, siteAssetTable } from '@ultimat3/render/server';
33
34
  import { loadAppConfig } from './app-config-load';
34
35
  import { assetRouteMeta } from './asset-route-meta';
35
36
  import { hasSourceIcon, iconPlan, iconRenderer } from './icon-assets';
36
37
  import type { AppLocales } from './pwa-manifest-locales';
37
38
  import { appLocales, localeMembers, spellIn } from './pwa-manifest-locales';
38
- import { parseHashedAssetUrl, siteAssetTable } from './site-assets';
39
39
 
40
40
  /** What a browser fetches from `<link rel="manifest">`. The spec's own extension, not `.json`. */
41
41
  export const WEB_MANIFEST_PATH = '/manifest.webmanifest';
@@ -10,6 +10,7 @@ import {
10
10
  renderFixLiteral,
11
11
  UltimateError,
12
12
  } from '@ultimat3/core';
13
+ import { siteAssetTable } from '@ultimat3/render/server';
13
14
  import type { Storage } from '@ultimat3/storage';
14
15
  import type { IslandBundle } from './island-bundle';
15
16
  import type { BuildAsset, PublishReport, RetainLog } from './retained-assets';
@@ -18,7 +19,6 @@ import { retainedPrefix } from './retained-assets-layout';
18
19
  import type { RetainedAssets } from './retained-assets-read';
19
20
  import { retainedAssets } from './retained-assets-read';
20
21
  import { retainedBuildOnce } from './runtime-boot-warnings';
21
- import { siteAssetTable } from './site-assets';
22
22
  import type { StyleBundle } from './style-bundle';
23
23
  import type { FrameworkScript } from './worker-bundle';
24
24
 
@@ -6,6 +6,8 @@
6
6
  import { finiteCount, probeImage, sniffImageFormat } from '@ultimat3/core';
7
7
  import type { Route, UltimateRequest } from '@ultimat3/http';
8
8
  import { applyCacheHeaders, jsonResponse } from '@ultimat3/http';
9
+ import type { SiteAsset, SiteAssetTable } from '@ultimat3/render/server';
10
+ import { parseHashedAssetUrl } from '@ultimat3/render/server';
9
11
  import type { ImageQuery, ImageTransformDriver } from '@ultimat3/seo';
10
12
  import {
11
13
  builtinImageDriver,
@@ -16,8 +18,6 @@ import {
16
18
  } from '@ultimat3/seo';
17
19
  import { variantLru } from './runtime-assets-site-cache';
18
20
  import { SITE_ASSET_CACHE, siteAssetRoutes } from './site-asset-routes';
19
- import type { SiteAsset, SiteAssetTable } from './site-assets';
20
- import { parseHashedAssetUrl } from './site-assets';
21
21
 
22
22
  /** What one process holds of decoded variants. Bounded: an edited asset in `x dev` adds entries. */
23
23
  export const SITE_VARIANT_CACHE_BYTES = 64 * 1024 * 1024;
@@ -10,6 +10,7 @@
10
10
  import { probeImage } from '@ultimat3/core';
11
11
  import type { ObjectSource, RequestContext, Route, UltimateRequest } from '@ultimat3/http';
12
12
  import { applyCacheHeaders, notModified, objectResponse } from '@ultimat3/http';
13
+ import { siteAssetTable } from '@ultimat3/render/server';
13
14
  import type { ImageQuery, ImageTransformDriver } from '@ultimat3/seo';
14
15
  import { builtinImageDriver, DEFAULT_WIDTHS, parseImageQuery, usableWidths } from '@ultimat3/seo';
15
16
  import type { ImageTransform, Storage, StorageObject, VariantFormat } from '@ultimat3/storage';
@@ -40,7 +41,6 @@ import {
40
41
  readStorageObject,
41
42
  STORAGE_READ_PERMISSION,
42
43
  } from './runtime-storage';
43
- import { siteAssetTable } from './site-assets';
44
44
 
45
45
  /**
46
46
  * Storage-backed images. `responsiveImage({ src: '/media/<key>' })` mints its variants under it.
@@ -20,7 +20,7 @@ import {
20
20
  seoRenderers,
21
21
  } from '@ultimat3/render';
22
22
  import type { HoleSink } from '@ultimat3/render/server';
23
- import { ROOT_ELEMENT_ID, renderComponent } from '@ultimat3/render/server';
23
+ import { ROOT_ELEMENT_ID, renderComponent, siteAssetTable } from '@ultimat3/render/server';
24
24
  import { loadAppConfig } from './app-config-load';
25
25
  import type { DocumentOptions } from './document-options';
26
26
  import { routeQuery } from './isr-query-guard';
@@ -28,7 +28,6 @@ import { navigationTagsOf } from './page-navigation';
28
28
  import { servedPins } from './page-pins';
29
29
  import { bootScript, collectorFor } from './route-islands';
30
30
  import { linkHeader, preloadTagsOf, preloadUrls } from './route-islands-preload';
31
- import { siteAssetTable } from './site-assets';
32
31
  import { styleBundle } from './style-bundle';
33
32
 
34
33
  /**
@@ -0,0 +1,145 @@
1
+ // Every way the boot scan has into each module holding a development import: the holder itself when
2
+ // it is scanned, else one chain per scanned edge towards it through modules outside the scan. One
3
+ // pass backwards from all the holders at once, each module read once per distance it is reached at
4
+ // and not once per holder: helpers that reconverge carry every holder below them together.
5
+
6
+ import type { ChainStep, EvaluatedImport } from './evaluated-walk';
7
+
8
+ /** A set of holders, one bit each: what reached a module together is moved and compared at once. */
9
+ type Holders = bigint;
10
+
11
+ /** The holders below a module, by how many imports below it they are. */
12
+ type Below = ReadonlyMap<number, Holders>;
13
+
14
+ /** One import of a module's, and the holders it is the first step of the shortest way to. */
15
+ interface Hop {
16
+ readonly edge: EvaluatedImport;
17
+ readonly target: string;
18
+ readonly holders: Holders;
19
+ }
20
+
21
+ /** `edges` by `key`, in the order given: a module's own stay in the order it writes them. */
22
+ function indexed(
23
+ edges: readonly EvaluatedImport[],
24
+ key: (edge: EvaluatedImport) => string | undefined,
25
+ ): ReadonlyMap<string | undefined, readonly EvaluatedImport[]> {
26
+ const index = new Map<string | undefined, EvaluatedImport[]>();
27
+ for (const edge of edges) {
28
+ const known = index.get(key(edge)) ?? [];
29
+ known.push(edge);
30
+ index.set(key(edge), known);
31
+ }
32
+ return index;
33
+ }
34
+
35
+ const together = (below: Below | undefined): Holders =>
36
+ [...(below?.values() ?? [])].reduce((all, holders) => all | holders, 0n);
37
+
38
+ /** Which bits are set, read off the digits: the clear ones between them cost no step each. */
39
+ function bitsOf(holders: Holders): readonly number[] {
40
+ const digits = holders.toString(2);
41
+ const found: number[] = [];
42
+ for (let at = digits.indexOf('1'); at !== -1; at = digits.indexOf('1', at + 1)) {
43
+ found.push(digits.length - 1 - at);
44
+ }
45
+ return found;
46
+ }
47
+
48
+ /** How far below each module outside the scan every holder is, shortest way. */
49
+ function distances(
50
+ bits: ReadonlyMap<string, Holders>,
51
+ scanned: ReadonlySet<string>,
52
+ into: ReadonlyMap<string | undefined, readonly EvaluatedImport[]>,
53
+ ): ReadonlyMap<string, Below> {
54
+ const below = new Map<string, Map<number, Holders>>();
55
+ const reached = new Map(bits);
56
+ let frontier: ReadonlyMap<string, Holders> = bits;
57
+ for (let distance = 0; frontier.size > 0; distance += 1) {
58
+ const next = new Map<string, Holders>();
59
+ for (const [path, holders] of frontier) {
60
+ const known = below.get(path) ?? new Map<number, Holders>();
61
+ below.set(path, known.set(distance, holders));
62
+ for (const { from } of into.get(path) ?? []) {
63
+ if (scanned.has(from)) continue;
64
+ const had = reached.get(from) ?? 0n;
65
+ const fresh = holders & ~had;
66
+ if (fresh === 0n) continue;
67
+ reached.set(from, had | fresh);
68
+ next.set(from, (next.get(from) ?? 0n) | fresh);
69
+ }
70
+ }
71
+ frontier = next;
72
+ }
73
+ return below;
74
+ }
75
+
76
+ /**
77
+ * The ways into each of `holders` over the app's followed `edges`. Shortest, and of two as short the
78
+ * one the module higher up imports first. Never through a scanned module: its own edge is the cut.
79
+ */
80
+ export function scanWays(
81
+ holders: readonly string[],
82
+ scanned: ReadonlySet<string>,
83
+ edges: readonly EvaluatedImport[],
84
+ ): (holder: string) => readonly (readonly ChainStep[])[] {
85
+ const outside = [...new Set(holders)].filter((holder) => !scanned.has(holder));
86
+ const bits = new Map(
87
+ outside.map((holder, index): [string, Holders] => [holder, 1n << BigInt(index)]),
88
+ );
89
+ const into = indexed(edges, (edge) => edge.target());
90
+ const below = distances(bits, scanned, into);
91
+ const onward = indexed(edges, (edge) => edge.from);
92
+ const hops = new Map<string, readonly Hop[]>();
93
+
94
+ /** Told once per module, whichever chains pass through it. */
95
+ function hopsOf(path: string): readonly Hop[] {
96
+ const known = hops.get(path);
97
+ if (known !== undefined) return known;
98
+ const here = below.get(path);
99
+ let left = together(here);
100
+ const found: Hop[] = [];
101
+ for (const edge of onward.get(path) ?? []) {
102
+ if (left === 0n) break;
103
+ const target = edge.target();
104
+ if (target === undefined) continue;
105
+ const closer = below.get(target);
106
+ let nearer = 0n;
107
+ for (const [distance, at] of here ?? []) nearer |= at & (closer?.get(distance - 1) ?? 0n);
108
+ // A holder an earlier import already leads to is that one's.
109
+ if ((nearer & left) === 0n) continue;
110
+ left &= ~nearer;
111
+ found.push({ edge, target, holders: nearer });
112
+ }
113
+ hops.set(path, found);
114
+ return found;
115
+ }
116
+
117
+ /** From a module the holder is below, down to it: the steps after the module itself. */
118
+ function down(from: string, bit: Holders): readonly ChainStep[] {
119
+ const steps: ChainStep[] = [];
120
+ const hopAt = (path: string): Hop | undefined =>
121
+ hopsOf(path).find((hop) => (hop.holders & bit) !== 0n);
122
+ for (let hop = hopAt(from); hop !== undefined; hop = hopAt(hop.target)) {
123
+ steps.push({ path: hop.target, specifier: hop.edge.specifier });
124
+ }
125
+ return steps;
126
+ }
127
+
128
+ /** The scanned edges into the modules each holder is below, in the order given. */
129
+ const cuts = new Map(outside.map((holder): [string, Hop[]] => [holder, []]));
130
+ for (const edge of edges) {
131
+ const target = (scanned.has(edge.from) ? edge.target() : undefined) ?? '';
132
+ const holders = together(below.get(target));
133
+ for (const bit of bitsOf(holders))
134
+ cuts.get(outside[bit] ?? '')?.push({ edge, target, holders });
135
+ }
136
+
137
+ return (holder) =>
138
+ scanned.has(holder)
139
+ ? [[{ path: holder }]]
140
+ : (cuts.get(holder) ?? []).map(({ edge, target }) => [
141
+ { path: edge.from },
142
+ { path: target, specifier: edge.specifier },
143
+ ...down(target, bits.get(holder) ?? 0n),
144
+ ]);
145
+ }
@@ -12,9 +12,9 @@ import {
12
12
  parseByteRange,
13
13
  RANGE_UNSATISFIABLE,
14
14
  } from '@ultimat3/http';
15
+ import type { SiteAsset, SiteAssetTable } from '@ultimat3/render/server';
16
+ import { parseHashedAssetUrl, SITE_ASSET_BASE_PATH } from '@ultimat3/render/server';
15
17
  import { assetRouteMeta } from './asset-route-meta';
16
- import type { SiteAsset, SiteAssetTable } from './site-assets';
17
- import { parseHashedAssetUrl, SITE_ASSET_BASE_PATH } from './site-assets';
18
18
 
19
19
  /** The URL is the content, so the answer is `public, max-age=31536000, immutable`. */
20
20
  export const SITE_ASSET_CACHE: CacheHint = { mode: 'immutable' };
@@ -1,163 +1,10 @@
1
- // The site asset table: every file under `apps/web/site/assets/`, named by a content-hashed URL.
2
- // One table per app root answers all three questions — the URL `asset()` returns while a page
3
- // renders, the file `/assets/*` serves, and the copy `x build --target static` writes — so the
4
- // page, the container and the CDN can never name one file three ways.
1
+ // The static export's half of the site asset table: every asset copied under its hashed URL. The
2
+ // table itself is `@ultimat3/render/server`'s, shared with the test preload.
5
3
 
6
- // why: `asset()` is called from a synchronous render, so the table answers synchronously — and Bun
7
- // ships no sync stat or sync read; `join`/`relative` because Bun ships no path API either.
8
- import { copyFileSync, mkdirSync, readFileSync, statSync } from 'node:fs';
4
+ // why: Bun ships no sync copy or mkdir, and the export walks the table synchronously.
5
+ import { copyFileSync, mkdirSync } from 'node:fs';
9
6
  import { dirname, join } from 'node:path'; // why: Bun ships no path API.
10
- import type { AssetExtension, AssetPath } from '@ultimat3/render';
11
- import { ASSET_DIR, AssetMissingError, assetPathProblem } from '@ultimat3/render';
12
- import { contentHash } from '@ultimat3/render/server';
13
-
14
- /** App-root-relative, beside `favicon.ico`: `apps/web/site/` is where an app's public files live. */
15
- export const SITE_ASSETS_SOURCE = `apps/web/site/${ASSET_DIR}`;
16
-
17
- /** The URL prefix every hashed asset is served under, and the export directory it is copied to. */
18
- export const SITE_ASSET_BASE_PATH = `/${ASSET_DIR}`;
19
-
20
- /** What each served extension IS. `vtt` carries a charset: captions are text a player decodes. */
21
- export const ASSET_CONTENT_TYPES: Readonly<Record<AssetExtension, string>> = {
22
- avif: 'image/avif',
23
- webp: 'image/webp',
24
- png: 'image/png',
25
- jpg: 'image/jpeg',
26
- jpeg: 'image/jpeg',
27
- gif: 'image/gif',
28
- svg: 'image/svg+xml',
29
- ico: 'image/x-icon',
30
- woff2: 'font/woff2',
31
- mp4: 'video/mp4',
32
- webm: 'video/webm',
33
- vtt: 'text/vtt; charset=utf-8',
34
- };
35
-
36
- export interface SiteAsset {
37
- /** As `asset()` names it: `assets/brand/logo.svg`. */
38
- readonly path: AssetPath;
39
- /** Absolute path on disk. */
40
- readonly file: string;
41
- /** `@ultimat3/render`'s `contentHash` of the bytes, 8 hex characters — the one CSS and HTML get. */
42
- readonly hash: string;
43
- /** `/assets/brand/logo.<hash>.svg`. */
44
- readonly url: string;
45
- readonly contentType: string;
46
- readonly bytes: number;
47
- }
48
-
49
- const splitExtension = (path: string): { readonly stem: string; readonly extension: string } => {
50
- const dot = path.lastIndexOf('.');
51
- return { stem: path.slice(0, dot), extension: path.slice(dot + 1) };
52
- };
53
-
54
- /** The hash goes before the extension, so a static host still infers the type from the name. */
55
- export function hashedAssetUrl(path: AssetPath, hash: string): string {
56
- const { stem, extension } = splitExtension(path);
57
- return `/${stem}.${hash}.${extension}`;
58
- }
59
-
60
- const HASHED = /^\/(assets\/.+)\.([0-9a-f]{8})\.([a-z0-9]+)$/i;
61
-
62
- /** The inverse of `hashedAssetUrl`: which asset a request names, and at which content. */
63
- export function parseHashedAssetUrl(
64
- pathname: string,
65
- ): { readonly path: AssetPath; readonly hash: string } | undefined {
66
- const match = HASHED.exec(pathname);
67
- if (match === null) return undefined;
68
- const path = `${match[1] ?? ''}.${match[3] ?? ''}`;
69
- if (assetPathProblem(path) !== undefined) return undefined;
70
- return { path: path as AssetPath, hash: match[2] ?? '' };
71
- }
72
-
73
- export interface SiteAssetTable {
74
- /** The asset `asset()` named, hashed as the bytes are NOW. Throws `X_ASSET_MISSING`. */
75
- resolve(path: AssetPath): SiteAsset;
76
- /** Every servable file under the source directory, sorted by path. */
77
- all(): readonly SiteAsset[];
78
- }
79
-
80
- const missing = (path: string, cause: string): AssetMissingError =>
81
- new AssetMissingError(
82
- `asset(${JSON.stringify(path)}): ${cause}`,
83
- `add the file at ${SITE_ASSETS_SOURCE}/${path.slice(ASSET_DIR.length + 1)}, or correct the path passed to asset(), then x build --target static --json`,
84
- );
85
-
86
- /**
87
- * A stat per call, a read only when the file changed: `x dev` sees an edited image under a new URL
88
- * on the next render with no watcher, and the container — whose files never change — pays one
89
- * `stat` per `asset()` call and nothing else. One behaviour in both, never a dev-only rescan.
90
- */
91
- export function createSiteAssetTable(root: string): SiteAssetTable {
92
- const source = join(root, SITE_ASSETS_SOURCE);
93
- const cache = new Map<string, { readonly stamp: string; readonly asset: SiteAsset }>();
94
-
95
- const resolve = (path: AssetPath): SiteAsset => {
96
- const problem = assetPathProblem(path);
97
- if (problem !== undefined) throw missing(path, problem);
98
- const file = join(source, path.slice(ASSET_DIR.length + 1));
99
- let stamp: string;
100
- try {
101
- const stat = statSync(file);
102
- if (!stat.isFile()) throw missing(path, `${file} is not a file`);
103
- stamp = `${String(stat.mtimeMs)}:${String(stat.size)}`;
104
- } catch (error) {
105
- if (error instanceof AssetMissingError) throw error;
106
- throw missing(path, `no file at ${SITE_ASSETS_SOURCE}/${path.slice(ASSET_DIR.length + 1)}`);
107
- }
108
- const cached = cache.get(path);
109
- if (cached !== undefined && cached.stamp === stamp) return cached.asset;
110
- const bytes = readFileSync(file);
111
- const hash = contentHash(bytes);
112
- // `assetPathProblem` already refused an unknown extension; the guard keeps `constructor` from
113
- // ever answering an `Object` member if that check is loosened.
114
- const extension = splitExtension(path).extension.toLowerCase();
115
- const asset: SiteAsset = {
116
- path,
117
- file,
118
- hash,
119
- url: hashedAssetUrl(path, hash),
120
- contentType: Object.hasOwn(ASSET_CONTENT_TYPES, extension)
121
- ? ASSET_CONTENT_TYPES[extension as AssetExtension]
122
- : 'application/octet-stream',
123
- bytes: bytes.byteLength,
124
- };
125
- cache.set(path, { stamp, asset });
126
- return asset;
127
- };
128
-
129
- const all = (): readonly SiteAsset[] => {
130
- const found: SiteAsset[] = [];
131
- let files: string[];
132
- try {
133
- files = [...new Bun.Glob('**/*').scanSync({ cwd: source, onlyFiles: true })];
134
- } catch {
135
- // No `assets/` directory is an app with no assets, not an error.
136
- return [];
137
- }
138
- for (const relativePath of files.sort()) {
139
- const path = `${ASSET_DIR}/${relativePath.split('\\').join('/')}`;
140
- // A source file beside its renditions (a `.psd`, a `README.md`) is not a served asset.
141
- if (assetPathProblem(path) !== undefined) continue;
142
- found.push(resolve(path as AssetPath));
143
- }
144
- return found;
145
- };
146
-
147
- return { resolve, all };
148
- }
149
-
150
- /** One table per root, so the renderer and the route read the same cache. */
151
- const tables = new Map<string, SiteAssetTable>();
152
-
153
- export function siteAssetTable(root: string): SiteAssetTable {
154
- let table = tables.get(root);
155
- if (table === undefined) {
156
- table = createSiteAssetTable(root);
157
- tables.set(root, table);
158
- }
159
- return table;
160
- }
7
+ import { siteAssetTable } from '@ultimat3/render/server';
161
8
 
162
9
  /**
163
10
  * Every asset, copied into the static export under its hashed URL — a static host serves with no
@@ -6,8 +6,8 @@ import { localeSegment, localizePath } from '@ultimat3/core';
6
6
  import type { PrecacheAsset, PwaRoute } from '@ultimat3/pwa';
7
7
  import { strategyFor } from '@ultimat3/pwa';
8
8
  import type { RouteDescriptor } from '@ultimat3/render';
9
+ import { parseHashedAssetUrl } from '@ultimat3/render/server';
9
10
  import type { IslandBundle } from './island-bundle';
10
- import { parseHashedAssetUrl } from './site-assets';
11
11
  import type { StyleBundle } from './style-bundle';
12
12
 
13
13
  /**
@@ -66,6 +66,47 @@ const MOTION_PROPERTY = /^(?:transition|animation)(?:-|$)|^--/;
66
66
  const TOKEN_CALL = /(?<![\\w-])(?:var|(?:[\\w-]+\\.)[\\w-]+|duration|easing)\\([^()]*\\)/g;
67
67
  const TIME = /(?<![\\w.#-])(\\d*\\.?\\d+)(ms|s)\\b/g;
68
68
  const CURVE = /cubic-bezier\\(([^)]*)\\)/g;
69
+ /** A property the scale itself declares: \`--duration-base\`, \`--easing-in-out\`. */
70
+ const SCALE_PROPERTY = /^--(duration|easing)-([\\w-]+)$/;
71
+
72
+ /**
73
+ * The scale rung a custom property re-declares, or \`undefined\`. Rewriting its value to a token
74
+ * would make the property read itself; the app's tempo is the theme's \`motion\` slot instead.
75
+ */
76
+ const scaleRung = (property: string): { scale: string; name: string } | undefined => {
77
+ const [, scale = '', name = ''] = SCALE_PROPERTY.exec(property) ?? [];
78
+ const names = scale === 'duration' ? DURATIONS.map(([rung]) => rung) : Object.values(EASINGS);
79
+ return names.includes(name) ? { scale, name } : undefined;
80
+ };
81
+
82
+ /** \`defineTheme\`'s own grammar for a duration; it refuses any other spelling at boot. */
83
+ const THEME_TIME = /^(0|\\d+(\\.\\d+)?(ms|s))$/;
84
+ const CSS_NUMBER = /^-?\\d*\\.?\\d+$/;
85
+ /** \`.5\` and \`+0.5\` are valid CSS; the theme spells both \`0.5\`. */
86
+ const themeNumber = (text: string): string =>
87
+ text.replace(/^\\+/, '').replace(/^(-?)\\./, (_match, sign: string) => \`\${sign}0.\`);
88
+
89
+ /** The value as \`defineTheme\` takes it, or \`undefined\` when no spelling of it is one. */
90
+ const themeValue = (scale: string, value: string): string | undefined => {
91
+ if (scale === 'duration') {
92
+ const time = themeNumber(value);
93
+ return THEME_TIME.test(time) ? time : undefined;
94
+ }
95
+ const points = /^cubic-bezier\\(([^()]*)\\)$/
96
+ .exec(value)?.[1]
97
+ ?.split(',')
98
+ .map((n) => themeNumber(n.trim()));
99
+ if (points?.length !== 4 || !points.every((n) => CSS_NUMBER.test(n))) return undefined;
100
+ // x1 and x2 are points in time: the theme refuses a curve with either outside [0, 1].
101
+ const inTime = [points[0], points[2]].every((x) => Number(x) >= 0 && Number(x) <= 1);
102
+ return inTime ? \`cubic-bezier(\${points.join(', ')})\` : undefined;
103
+ };
104
+
105
+ /** The value the scale ships for a rung — a call that always boots. */
106
+ const shippedValue = (scale: string, name: string): string =>
107
+ scale === 'duration'
108
+ ? \`\${DURATIONS.find(([rung]) => rung === name)?.[1] ?? 0}ms\`
109
+ : \`cubic-bezier(\${(Object.entries(EASINGS).find(([, rung]) => rung === name)?.[0] ?? '').split(',').join(', ')})\`;
69
110
 
70
111
  /** The step a duration means: exact where it is one, the nearest where it is not. */
71
112
  const durationFor = (ms: number): string => {
@@ -124,6 +165,38 @@ export function rawMotion(files: readonly StyleFile[]): readonly Finding[] {
124
165
  if (literals.length === 0) continue;
125
166
  written += value.slice(cursor);
126
167
  const line = lineOf(scss, match.index);
168
+ const rung = scaleRung(property);
169
+ if (rung !== undefined) {
170
+ const key = /^\\w+$/.test(rung.name) ? rung.name : \`'\${rung.name}'\`;
171
+ // \`!important\` is the declaration's priority, not its value: the theme takes the time.
172
+ const important = /\\s*!important$/i.exec(value);
173
+ const accepted = themeValue(rung.scale, value.slice(0, important?.index));
174
+ const priority = important
175
+ ? ' (the theme sets it without !important, so a later declaration of the property wins)'
176
+ : '';
177
+ const call = (themed: string): string =>
178
+ \`defineTheme({ motion: { \${rung.scale}: { \${key}: '\${themed}' } } }) in apps/web/shared/theme.ts\`;
179
+ if (accepted === undefined) {
180
+ const grammar =
181
+ rung.scale === 'duration'
182
+ ? "a time such as '180ms' or '0.3s'"
183
+ : "cubic-bezier() of four numbers, x1 and x2 between 0 and 1, such as 'cubic-bezier(0.2, 0, 0, 1)'";
184
+ findings.push({
185
+ code: CODE,
186
+ cause: \`\${file.path}:\${line} re-declares \\\`\${property}: \${value}\\\`, which a theme cannot hold — a \${rung.scale} rung takes \${grammar}\`,
187
+ fix: \`\${call(shippedValue(rung.scale, rung.name))} — the shipped value; change it to \${grammar}, delete the line at \${file.path}:\${line}, then: x verify --only boundaries\`,
188
+ at: \`\${file.path}:\${line}\`,
189
+ });
190
+ continue;
191
+ }
192
+ findings.push({
193
+ code: CODE,
194
+ cause: \`\${file.path}:\${line} re-declares \\\`\${property}: \${value}\\\` — the motion scale's own property, set from a stylesheet\`,
195
+ fix: \`\${call(accepted)} — every \${ns}.\${rung.scale}(\${rung.name}) then moves at it\${priority}; delete the line at \${file.path}:\${line}, then: x verify --only boundaries\`,
196
+ at: \`\${file.path}:\${line}\`,
197
+ });
198
+ continue;
199
+ }
127
200
  findings.push({
128
201
  code: CODE,
129
202
  cause: \`\${file.path}:\${line} writes \\\`\${property}: \${value}\\\` — \${literals.join(' and ')} off the motion scale, a tempo of this file's own\`,
@@ -200,6 +273,29 @@ unitTest('a custom property holding a raw curve or time is refused, the fix inte
200
273
  expect(fixes(':root { --wait: 0.4s; --gap: 12px; --ok: var(--duration-fast); }')).toHaveLength(1);
201
274
  });
202
275
 
276
+ unitTest('re-declaring a property of the scale itself is sent to the theme slot', () => {
277
+ expect(fixes(':root { --duration-base: 180ms; }')[0]).toStartWith(
278
+ "defineTheme({ motion: { duration: { base: '180ms' } } }) in apps/web/shared/theme.ts",
279
+ );
280
+ expect(fixes(':root { --easing-in-out: cubic-bezier(0.4, 0, 0.2, 1); }')[0]).toStartWith(
281
+ "defineTheme({ motion: { easing: { 'in-out': 'cubic-bezier(0.4, 0, 0.2, 1)' } } })",
282
+ );
283
+ });
284
+
285
+ unitTest('a rung the theme spells differently is normalized; one it cannot hold says so', () => {
286
+ expect(fixes(':root { --duration-base: .5s; }')[0]).toStartWith(
287
+ "defineTheme({ motion: { duration: { base: '0.5s' } } })",
288
+ );
289
+ expect(fixes(':root { --easing-out: cubic-bezier(0,0,1,1); }')[0]).toStartWith(
290
+ "defineTheme({ motion: { easing: { out: 'cubic-bezier(0, 0, 1, 1)' } } })",
291
+ );
292
+ const refused = rawMotion(sheet(':root { --easing-out: cubic-bezier(1.5, 0, 0, 1); }'));
293
+ expect(refused[0]?.cause).toContain('which a theme cannot hold');
294
+ expect(refused[0]?.fix).toStartWith(
295
+ "defineTheme({ motion: { easing: { out: 'cubic-bezier(0.16, 1, 0.3, 1)' } } })",
296
+ );
297
+ });
298
+
203
299
  unitTest('the fix speaks the namespace the sheet uses the tokens under', () => {
204
300
  const scss = "@use '../shared/tokens' as t;\\n.a { transition-duration: 120ms; }";
205
301
  expect(fixes(scss)[0]).toStartWith('transition-duration: t.duration(fast) — ');
@@ -79,6 +79,9 @@ export const RELEASED_GUARD_FORMS: Readonly<
79
79
  ],
80
80
  'raw-motion': [
81
81
  ['14c1bs20ysc1u', 'error'],
82
+ ['23t5nj717gkf0', 'error'],
83
+ ['3azasze78buvt', 'error'],
84
+ ['3tk0sdgns06ck', 'error'],
82
85
  ['u6julhh0et2k', 'error'],
83
86
  ['w8aw0q20tfsz', 'error'],
84
87
  ],
@@ -176,7 +179,7 @@ export const RELEASED_GUARD_TEST_FORMS: Readonly<Record<string, readonly string[
176
179
  'raw-fetch': ['2lips924uo00f'],
177
180
  'raw-interval': ['1z55givy4sst0'],
178
181
  'raw-length': ['1hpgz9jowk5qu'],
179
- 'raw-motion': ['6420344uhv97', 'g6cs0de9jmr7'],
182
+ 'raw-motion': ['2kg7ezhf8u7a9', '6420344uhv97', 'g6cs0de9jmr7', 'xes72msaf3a3'],
180
183
  'raw-shadow': ['3kg8ft6y3ia0y'],
181
184
  'raw-z-index': ['3fb40f6bwp8kq'],
182
185
  'repo-await-in-loop': ['2axgbb82wldt4'],
@@ -29,7 +29,7 @@ import { verifyFloor } from './scaffold-verify-floor';
29
29
  * config as out of date on every `bun run lint`. A formatter is a build input: a floating range
30
30
  * is a `lint` step whose verdict depends on the day the app was installed.
31
31
  */
32
- const BIOME_VERSION = '2.6.4';
32
+ const BIOME_VERSION = '2.6.6';
33
33
 
34
34
  /**
35
35
  * The checker a scaffolded app typechecks with, and it must not lag the one the FRAMEWORK is built