@timber-js/app 0.2.0-alpha.214 → 0.2.0-alpha.216
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/dist/_chunks/als-registry-BZqHCtq-.js.map +1 -1
- package/dist/_chunks/{chains-CjK1Eu6a.js → chains-YKZ8WpIW.js} +2 -2
- package/dist/_chunks/{chains-CjK1Eu6a.js.map → chains-YKZ8WpIW.js.map} +1 -1
- package/dist/_chunks/{classify-GAdt6aiA.js → classify-2Yp3xJY1.js} +3 -3
- package/dist/_chunks/{classify-GAdt6aiA.js.map → classify-2Yp3xJY1.js.map} +1 -1
- package/dist/_chunks/{cli-check-DOzjlycg.js → cli-check-D2WtbNqo.js} +3 -3
- package/dist/_chunks/{cli-check-DOzjlycg.js.map → cli-check-D2WtbNqo.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-B9wDaQvW.js → cli-schema-sync-CySLKrO3.js} +2 -2
- package/dist/_chunks/{cli-schema-sync-B9wDaQvW.js.map → cli-schema-sync-CySLKrO3.js.map} +1 -1
- package/dist/_chunks/{client-dep-entries-DyDqXOF9.js → client-dep-entries-BOkpKjj1.js} +47 -3
- package/dist/_chunks/client-dep-entries-BOkpKjj1.js.map +1 -0
- package/dist/_chunks/{convention-lint-B3QEGJX7.js → convention-lint-ByKJ6aqD.js} +2 -2
- package/dist/_chunks/{convention-lint-B3QEGJX7.js.map → convention-lint-ByKJ6aqD.js.map} +1 -1
- package/dist/_chunks/{dev-server-_9L4KWC-.js → dev-server-B8zsT-ee.js} +4 -4
- package/dist/_chunks/{dev-server-_9L4KWC-.js.map → dev-server-B8zsT-ee.js.map} +1 -1
- package/dist/_chunks/{live-graph-Cd3YHvrH.js → live-graph-BhtrZpRd.js} +4 -4
- package/dist/_chunks/{live-graph-Cd3YHvrH.js.map → live-graph-BhtrZpRd.js.map} +1 -1
- package/dist/_chunks/{metadata-routes-DSDjM_hJ.js → metadata-routes-B3XJNyIH.js} +1 -2
- package/dist/_chunks/metadata-routes-B3XJNyIH.js.map +1 -0
- package/dist/_chunks/{poison-scan-BnJjBOkn.js → poison-scan-C4FgMxFl.js} +2 -2
- package/dist/_chunks/{poison-scan-BnJjBOkn.js.map → poison-scan-C4FgMxFl.js.map} +1 -1
- package/dist/_chunks/{scanner-CKAT5gRx.js → scanner-Cb3fSjAC.js} +4 -4
- package/dist/_chunks/{scanner-CKAT5gRx.js.map → scanner-Cb3fSjAC.js.map} +1 -1
- package/dist/_chunks/{walkers-DwCXEyRu.js → walkers-Ber9bamD.js} +3 -3
- package/dist/_chunks/{walkers-DwCXEyRu.js.map → walkers-Ber9bamD.js.map} +1 -1
- package/dist/adapters/types.d.ts +3 -1
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/analyze/crawl-entry.js +3 -3
- package/dist/analyze/graph-command.js +2 -2
- package/dist/cli.d.ts +5 -5
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +15 -14
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -53
- package/dist/index.js.map +1 -1
- package/dist/plugins/client-dep-entries.d.ts +36 -0
- package/dist/plugins/client-dep-entries.d.ts.map +1 -1
- package/dist/routing/index.js +2 -2
- package/dist/server/als-registry.d.ts +2 -0
- package/dist/server/als-registry.d.ts.map +1 -1
- package/dist/server/internal.js +2 -2
- package/dist/server/internal.js.map +1 -1
- package/dist/server/metadata-collector.d.ts +2 -0
- package/dist/server/metadata-collector.d.ts.map +1 -1
- package/dist/server/metadata-route-links.d.ts +70 -0
- package/dist/server/metadata-route-links.d.ts.map +1 -0
- package/dist/server/metadata-routes.d.ts +0 -24
- package/dist/server/metadata-routes.d.ts.map +1 -1
- package/dist/server/port-resolution.d.ts +3 -12
- package/dist/server/port-resolution.d.ts.map +1 -1
- package/dist/server/route-element-builder.d.ts.map +1 -1
- package/dist/server/route-matcher.d.ts +7 -0
- package/dist/server/route-matcher.d.ts.map +1 -1
- package/docs/api/36-cli.mdx +8 -4
- package/docs/learn/13-deploying.mdx +2 -0
- package/package.json +1 -1
- package/src/adapters/types.ts +3 -1
- package/src/cli.ts +18 -16
- package/src/index.ts +48 -71
- package/src/plugins/client-dep-entries.ts +46 -0
- package/src/server/als-registry.ts +2 -0
- package/src/server/metadata-collector.ts +15 -17
- package/src/server/metadata-route-links.ts +200 -0
- package/src/server/metadata-routes.ts +0 -106
- package/src/server/port-resolution.ts +6 -16
- package/src/server/route-element-builder.ts +1 -0
- package/src/server/route-matcher.ts +2 -2
- package/dist/_chunks/client-dep-entries-DyDqXOF9.js.map +0 -1
- package/dist/_chunks/metadata-routes-DSDjM_hJ.js.map +0 -1
|
@@ -29,6 +29,8 @@ export interface MetadataCollectorProps {
|
|
|
29
29
|
metadataExport: Metadata | (() => Promise<Metadata>);
|
|
30
30
|
segmentName: string;
|
|
31
31
|
isPage: boolean;
|
|
32
|
+
/** Index of the owning segment in the route chain. */
|
|
33
|
+
segmentIndex: number;
|
|
32
34
|
children: ReactNode;
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata-collector.d.ts","sourceRoot":"","sources":["../../src/server/metadata-collector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"metadata-collector.d.ts","sourceRoot":"","sources":["../../src/server/metadata-collector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAyC9D,MAAM,WAAW,sBAAsB;IACrC,cAAc,EAAE,QAAQ,GAAG,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IACrD,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,sDAAsD;IACtD,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,SAAS,CAmB1E;AAID,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,mBAAmB,EAAE,CAAC;IAChC,8FAA8F;IAC9F,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,mBAAmB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,SAAS,CAAC,CAgC/E"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-linking: turn the metadata route files in a page's segment chain into
|
|
3
|
+
* the <link>/<meta> tags its <head> carries, and decide precedence between
|
|
4
|
+
* those files and the metadata the app declares.
|
|
5
|
+
*
|
|
6
|
+
* Every link must name a file the metadata route matcher actually serves at
|
|
7
|
+
* that URL, so the OG winner is chosen by asking the matcher rather than by
|
|
8
|
+
* modelling its precedence here.
|
|
9
|
+
*
|
|
10
|
+
* See design/16-metadata.md §"Auto-Linking".
|
|
11
|
+
*/
|
|
12
|
+
import type { HeadElement } from './metadata.ts';
|
|
13
|
+
import type { Metadata } from './types.ts';
|
|
14
|
+
import { type ManifestSegmentNode } from './route-matcher.ts';
|
|
15
|
+
/**
|
|
16
|
+
* Segment index whose metadata export supplied the resolved `openGraph.images`
|
|
17
|
+
* and `twitter.images`, or -1 when none did. A file-based `opengraph-image`
|
|
18
|
+
* replaces declared images only from a deeper segment.
|
|
19
|
+
*/
|
|
20
|
+
export interface DeclaredImageOwners {
|
|
21
|
+
openGraph: number;
|
|
22
|
+
twitter: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Find which segment's export supplied the resolved `openGraph.images` and
|
|
26
|
+
* `twitter.images`: the deepest entry whose images are the resolved value.
|
|
27
|
+
* Read off the merge result rather than re-deriving `resolveMetadata`'s merge
|
|
28
|
+
* rule, so the two cannot drift.
|
|
29
|
+
*/
|
|
30
|
+
export declare function findDeclaredImageOwners(entries: {
|
|
31
|
+
metadata: Metadata;
|
|
32
|
+
segmentIndex: number;
|
|
33
|
+
}[], resolved: Metadata): DeclaredImageOwners;
|
|
34
|
+
/** Auto-linked head elements, and the declared metadata they leave in force. */
|
|
35
|
+
export interface MetadataRouteLinks {
|
|
36
|
+
/** `resolvedMetadata` minus any declared images a deeper file replaced. */
|
|
37
|
+
metadata: Metadata;
|
|
38
|
+
elements: HeadElement[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Link metadata route files in the segment chain into the page's head.
|
|
42
|
+
*
|
|
43
|
+
* Walks each segment's metadataRoutes, resolves serve paths and URLs, and
|
|
44
|
+
* emits HeadElement descriptors for <link> and <meta> tags that React Float
|
|
45
|
+
* hoists into <head>.
|
|
46
|
+
*
|
|
47
|
+
* A metadata file is served under the URL of the segment that owns it, not
|
|
48
|
+
* under every descendant URL: a root `app/icon.tsx` rendered on `/map` links
|
|
49
|
+
* `/icon.png`, and `app/posts/[id]/opengraph-image.tsx` on `/posts/42/comments`
|
|
50
|
+
* links `/posts/42/opengraph-image.png`. The owner's prefix is the URL parts
|
|
51
|
+
* the chain has consumed through that segment (`extractUrlParts`, the same
|
|
52
|
+
* walk slot matching uses), filled with the request's raw param values — the
|
|
53
|
+
* parts the metadata route matcher walks back to the same owner.
|
|
54
|
+
*
|
|
55
|
+
* Segments at or below an intercepting segment are skipped: the metadata
|
|
56
|
+
* matcher only walks the canonical tree, so nothing serves their files.
|
|
57
|
+
*
|
|
58
|
+
* Precedence, so no tag is ever emitted twice:
|
|
59
|
+
* - Icon and apple-icon files link from every segment, root to leaf, unless
|
|
60
|
+
* the metadata declares `icons.icon` / `icons.apple`. A declared manifest
|
|
61
|
+
* likewise replaces `app/manifest.*`.
|
|
62
|
+
* - Only the deepest served `opengraph-image` links. It replaces declared
|
|
63
|
+
* `openGraph.images` / `twitter.images` from a shallower segment (those are
|
|
64
|
+
* dropped from the returned metadata) and yields to images declared at its
|
|
65
|
+
* own segment or deeper.
|
|
66
|
+
*
|
|
67
|
+
* See design/16-metadata.md §"Auto-Linking"
|
|
68
|
+
*/
|
|
69
|
+
export declare function linkMetadataRoutes(segments: ManifestSegmentNode[], resolvedMetadata: Metadata, declaredImages: DeclaredImageOwners, requestUrl: URL, rawSegmentParams: Record<string, string | string[]>, metadataRouteHashes?: Record<string, string>): MetadataRouteLinks;
|
|
70
|
+
//# sourceMappingURL=metadata-route-links.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata-route-links.d.ts","sourceRoot":"","sources":["../../src/server/metadata-route-links.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAsB,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAiBlF;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,EAAE,EACvD,QAAQ,EAAE,QAAQ,GACjB,mBAAmB,CASrB;AAED,gFAAgF;AAChF,MAAM,WAAW,kBAAkB;IACjC,2EAA2E;IAC3E,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,mBAAmB,EAAE,EAC/B,gBAAgB,EAAE,QAAQ,EAC1B,cAAc,EAAE,mBAAmB,EACnC,UAAU,EAAE,GAAG,EACf,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EACnD,mBAAmB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC3C,kBAAkB,CA8FpB"}
|
|
@@ -9,9 +9,6 @@
|
|
|
9
9
|
*
|
|
10
10
|
* See design/16-metadata.md §"Metadata Routes"
|
|
11
11
|
*/
|
|
12
|
-
import type { HeadElement } from './metadata.ts';
|
|
13
|
-
import type { Metadata } from './types.ts';
|
|
14
|
-
import type { ManifestSegmentNode } from './route-matcher.ts';
|
|
15
12
|
/** Classification of a metadata route file. */
|
|
16
13
|
export interface MetadataRouteInfo {
|
|
17
14
|
/** The metadata route type. */
|
|
@@ -130,25 +127,4 @@ export type AutoLinkTag = AutoLinkLink | AutoLinkMeta;
|
|
|
130
127
|
* @returns Tag descriptor(s) for the <head>, or null if no auto-link
|
|
131
128
|
*/
|
|
132
129
|
export declare function getMetadataRouteAutoLink(type: MetadataRouteType, href: string): AutoLinkTag[];
|
|
133
|
-
/**
|
|
134
|
-
* Collect auto-linked head elements from metadata route files in the segment chain.
|
|
135
|
-
*
|
|
136
|
-
* Walks each segment's metadataRoutes, resolves serve paths and URLs, and
|
|
137
|
-
* emits HeadElement descriptors for <link> and <meta> tags that React Float
|
|
138
|
-
* hoists into <head>.
|
|
139
|
-
*
|
|
140
|
-
* A metadata file is served under the URL of the segment that owns it, not
|
|
141
|
-
* under every descendant URL: a root `app/icon.tsx` rendered on `/map` links
|
|
142
|
-
* `/icon.png`, and `app/posts/[id]/opengraph-image.tsx` on `/posts/42/comments`
|
|
143
|
-
* links `/posts/42/opengraph-image.png`. The owner's prefix is the URL parts
|
|
144
|
-
* the chain has consumed through that segment (`extractUrlParts`, the same
|
|
145
|
-
* walk slot matching uses), filled with the request's raw param values — the
|
|
146
|
-
* parts the metadata route matcher walks back to the same owner.
|
|
147
|
-
*
|
|
148
|
-
* Segments at or below an intercepting segment are skipped: the metadata
|
|
149
|
-
* matcher only walks the canonical tree, so nothing serves their files.
|
|
150
|
-
*
|
|
151
|
-
* See design/16-metadata.md §"Auto-Linking"
|
|
152
|
-
*/
|
|
153
|
-
export declare function collectMetadataRouteHeadElements(segments: ManifestSegmentNode[], firstDeniedIndex: number, resolvedMetadata: Metadata, requestUrl: URL, rawSegmentParams: Record<string, string | string[]>, metadataRouteHashes?: Record<string, string>): HeadElement[];
|
|
154
130
|
//# sourceMappingURL=metadata-routes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata-routes.d.ts","sourceRoot":"","sources":["../../src/server/metadata-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"metadata-routes.d.ts","sourceRoot":"","sources":["../../src/server/metadata-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAQH,+CAA+C;AAC/C,MAAM,WAAW,iBAAiB;IAChC,+BAA+B;IAC/B,IAAI,EAAE,iBAAiB,CAAC;IACxB,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,QAAQ,GACR,UAAU,GACV,SAAS,GACT,MAAM,GACN,iBAAiB,GACjB,YAAY,CAAC;AAIjB;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,EAAE,MAAM,CAC7C,MAAM,EACN;IACE,IAAI,EAAE,iB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B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,YAAY,CAAC;AAEtD;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,CAgB7F"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/** Port input precedence for dev
|
|
2
|
-
/** Default port used by `timber dev
|
|
1
|
+
/** Port input precedence for dev. Vite owns binding and restart reuse. */
|
|
2
|
+
/** Default port used by `timber dev`. */
|
|
3
3
|
export declare const DEFAULT_PORT = 3000;
|
|
4
4
|
export interface ResolvePortInput {
|
|
5
5
|
/**
|
|
@@ -13,19 +13,10 @@ export interface ResolvePortInput {
|
|
|
13
13
|
/** Default port to use when neither `configPort` nor `envPort` is set. */
|
|
14
14
|
defaultPort?: number;
|
|
15
15
|
}
|
|
16
|
-
export interface ResolvedPortInput {
|
|
17
|
-
/** Port to start binding from. */
|
|
18
|
-
port: number;
|
|
19
|
-
/**
|
|
20
|
-
* `true` if the port came from an explicit user override (config or
|
|
21
|
-
* env). Preview uses this to default to strict port binding.
|
|
22
|
-
*/
|
|
23
|
-
explicit: boolean;
|
|
24
|
-
}
|
|
25
16
|
/**
|
|
26
17
|
* Pure: compute the starting port from config / env / defaults.
|
|
27
18
|
*
|
|
28
19
|
* Performs no I/O.
|
|
29
20
|
*/
|
|
30
|
-
export declare function resolveStartPort(input: ResolvePortInput):
|
|
21
|
+
export declare function resolveStartPort(input: ResolvePortInput): number;
|
|
31
22
|
//# sourceMappingURL=port-resolution.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"port-resolution.d.ts","sourceRoot":"","sources":["../../src/server/port-resolution.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"port-resolution.d.ts","sourceRoot":"","sources":["../../src/server/port-resolution.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAE1E,yCAAyC;AACzC,eAAO,MAAM,YAAY,OAAO,CAAC;AAIjC,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,0EAA0E;IAC1E,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAiBhE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-element-builder.d.ts","sourceRoot":"","sources":["../../src/server/route-element-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAQ9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAMhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAS5D;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,mBAAmB,EAAE,EAC/B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,UAAU,GAChB,MAAM,EAAE,CAGV;AAED;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAID,+CAA+C;AAC/C,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,CAAC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,OAAO,EAAE,MAAM,EAG1B;CACF;AAID,+CAA+C;AAC/C,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;IAC3C,OAAO,EAAE,mBAAmB,CAAC;CAC9B;AAED,+CAA+C;AAC/C,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,OAAO,EAAE,cAAc,CAAC;IACxB,wDAAwD;IACxD,gBAAgB,EAAE,oBAAoB,EAAE,CAAC;IACzC,qCAAqC;IACrC,QAAQ,EAAE,mBAAmB,EAAE,CAAC;IAChC,4DAA4D;IAC5D,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;;;OAKG;IACH,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B;;;;OAIG;IACH,YAAY,EAAE,aAAa,EAAE,CAAC;IAC9B;;;;OAIG;IACH,aAAa,CAAC,EAAE,aAAa,EAAE,CAAC;CACjC;AA4DD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,UAAU,EACjB,YAAY,CAAC,EAAE,mBAAmB,EAClC,eAAe,CAAC,EAAE,eAAe,GAAG,IAAI,EACxC,mBAAmB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC3C,OAAO,CAAC,kBAAkB,CAAC,CAua7B"}
|
|
@@ -97,4 +97,11 @@ export interface MetadataRouteMatch {
|
|
|
97
97
|
* See design/16-metadata.md §"Metadata Routes"
|
|
98
98
|
*/
|
|
99
99
|
export declare function createMetadataRouteMatcher(manifest: ManifestRoot): (pathname: string) => MetadataRouteMatch | null;
|
|
100
|
+
/**
|
|
101
|
+
* Match a pathname against metadata routes in the segment tree.
|
|
102
|
+
*
|
|
103
|
+
* Checks if the last URL part is a known metadata route serve path,
|
|
104
|
+
* then walks the tree to find the segment that owns the route.
|
|
105
|
+
*/
|
|
106
|
+
export declare function matchMetadataRoute(root: ManifestSegmentNode, pathname: string): MetadataRouteMatch | null;
|
|
100
107
|
//# sourceMappingURL=route-matcher.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-matcher.d.ts","sourceRoot":"","sources":["../../src/server/route-matcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAKL,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAY9B,6DAA6D;AAC7D,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,mBAAmB,GAAG,WAAW,CAAC,YAAY,CAAC,CAAC;AAE5D;;;;;;;;GAQG;AACH,MAAM,WAAW,YAAa,SAAQ,SAAS,CAAC,YAAY,CAAC;IAC3D,QAAQ,EAAE,MAAM,CAAC;CAClB;AAID;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,YAAY,GACrB,CAAC,QAAQ,EAAE,MAAM,KAAK,UAAU,GAAG,IAAI,CAEzC;AAwBD;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,mBAAmB,EAAE,GAAG,YAAY,EAAE,CAcnF;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,SAAS,mBAAmB,EAAE,GAAG,OAAO,CAGjF;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,SAAS,mBAAmB,EAAE,GAAG,OAAO,CAEnF;AAID,2CAA2C;AAC3C,MAAM,WAAW,kBAA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AM,KAAK,UAAU,GAAG,IAAI,CAEzC;AAwBD;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,mBAAmB,EAAE,GAAG,YAAY,EAAE,CAcnF;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,SAAS,mBAAmB,EAAE,GAAG,OAAO,CAGjF;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,SAAS,mBAAmB,EAAE,GAAG,OAAO,CAEnF;AAID,2CAA2C;AAC3C,MAAM,WAAW,kBAAkB;IACjC,4DAA4D;IAC5D,IAAI,EAAE,iBAAiB,CAAC;IACxB,4CAA4C;IAC5C,WAAW,EAAE,MAAM,CAAC;IACpB,0DAA0D;IAC1D,IAAI,EAAE,YAAY,CAAC;IACnB,0DAA0D;IAC1D,OAAO,EAAE,mBAAmB,CAAC;IAC7B;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB,wEAAwE;IACxE,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;CAClD;AAcD;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,YAAY,GACrB,CAAC,QAAQ,EAAE,MAAM,KAAK,kBAAkB,GAAG,IAAI,CAEjD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,mBAAmB,EACzB,QAAQ,EAAE,MAAM,GACf,kBAAkB,GAAG,IAAI,CAqE3B"}
|
package/docs/api/36-cli.mdx
CHANGED
|
@@ -29,7 +29,7 @@ When the requested port is available, the server shows a loading page while Vite
|
|
|
29
29
|
|
|
30
30
|
#### Port selection
|
|
31
31
|
|
|
32
|
-
The default port
|
|
32
|
+
The default port for `timber dev` is **`3000`** (matching Next.js and most Node web frameworks). If `3000` is already in use, timber automatically bumps to `3001`, then `3002`, and so on until it finds a free port:
|
|
33
33
|
|
|
34
34
|
```
|
|
35
35
|
Port 3000 is in use, trying another one...
|
|
@@ -42,7 +42,7 @@ To override the default, use any of the following (highest precedence first):
|
|
|
42
42
|
|
|
43
43
|
> **Note:** `timber dev --port 4000` is an error, not a silent no-op. `timber dev` accepts only `--config` — use `PORT` or `server.port` to change the port.
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
An occupied port produces a notice and the server tries the next free port. Set `server.strictPort: true` in `vite.config.ts` to fail on a conflict instead.
|
|
46
46
|
|
|
47
47
|
Editing `timber.config.ts` triggers a full process restart so the updated config takes effect. The dev server briefly shuts down and restarts on the same port. Changing the configured port takes effect on restart.
|
|
48
48
|
|
|
@@ -78,7 +78,7 @@ Serve the production build locally for testing.
|
|
|
78
78
|
timber preview
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
If your adapter
|
|
81
|
+
Preview runs your adapter's `preview()`. The Cloudflare and Nitro adapters both provide one. If no adapter is configured, or your adapter has no `preview()`, preview exits with an error that says so. It does not fall back to Vite's preview server, because that would serve your build directory, server bundles included, as static files.
|
|
82
82
|
|
|
83
83
|
Preview reads your project the same way `timber build` does: it resolves your Vite config, so options passed inline to `timber({ ... })`, a custom `--config`, and `build.outDir` all apply. It serves your last build using the `output` mode your config sets now. If you change `output`, rebuild before you preview:
|
|
84
84
|
|
|
@@ -90,7 +90,11 @@ Preview reads your project the same way `timber build` does: it resolves your Vi
|
|
|
90
90
|
|
|
91
91
|
The Nitro static preview serves under your `base` path, but it does not apply `_redirects` or `_headers` rules. Check those on your hosting platform.
|
|
92
92
|
|
|
93
|
-
A `timber.config.ts` that exists but fails to load is a hard error naming the file
|
|
93
|
+
A `timber.config.ts` that exists but fails to load is a hard error naming the file, so preview never runs with your adapter ignored.
|
|
94
|
+
|
|
95
|
+
The adapter picks the preview port, not `server.port`. The Nitro preview server starts at `3000` and tries the next free port, unless you set `PORT`, in which case a conflict is an error. Cloudflare preview uses wrangler's own default port.
|
|
96
|
+
|
|
97
|
+
Running `vite preview` directly is an error. It would serve your build directory, server bundles included, as static files.
|
|
94
98
|
|
|
95
99
|
Always run `timber build` before `timber preview`.
|
|
96
100
|
|
|
@@ -200,6 +200,8 @@ export default {
|
|
|
200
200
|
|
|
201
201
|
Pre-renders every route to HTML at build time. Add `clientJavascript: false` for zero-JavaScript output. Deploy to any static file host — S3, CloudFront, Cloudflare Pages, GitHub Pages, Netlify, or any HTTP server.
|
|
202
202
|
|
|
203
|
+
`timber preview` runs an adapter, so a static build with no adapter can't be previewed. Add `adapter: nitro()` to preview it locally. A static Nitro build doesn't need a Nitro server, and its preview works with any preset.
|
|
204
|
+
|
|
203
205
|
### Serving from a sub-path
|
|
204
206
|
|
|
205
207
|
To deploy under a path instead of a domain root — `https://user.github.io/repo/` on GitHub Pages, for example — set Vite's `base`:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timber-js/app",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.216",
|
|
4
4
|
"description": "Vite-native React framework built for Servers and Serverless Platforms — correct HTTP semantics, real status codes, pages that work without JavaScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare-workers",
|
package/src/adapters/types.ts
CHANGED
|
@@ -152,7 +152,9 @@ export interface TimberPlatformAdapter {
|
|
|
152
152
|
|
|
153
153
|
/**
|
|
154
154
|
* Start a local preview server for the built output.
|
|
155
|
-
*
|
|
155
|
+
* Without it, `timber preview` fails with an error naming the adapter —
|
|
156
|
+
* there is no fallback to Vite preview, which would serve the build
|
|
157
|
+
* directory (server bundles included) as static files.
|
|
156
158
|
*
|
|
157
159
|
* Runs in a later process than the build (`timber preview`); see
|
|
158
160
|
* {@link PreviewTarget}.
|
package/src/cli.ts
CHANGED
|
@@ -140,7 +140,6 @@ export function parseArgs(args: string[]): ParsedArgs {
|
|
|
140
140
|
export interface ViteDeps {
|
|
141
141
|
createServer?: typeof import('vite').createServer;
|
|
142
142
|
createBuilder?: typeof import('vite').createBuilder;
|
|
143
|
-
preview?: typeof import('vite').preview;
|
|
144
143
|
resolveViteConfig?: ResolveViteConfig;
|
|
145
144
|
}
|
|
146
145
|
|
|
@@ -231,16 +230,17 @@ export async function runBuild(options: CommandOptions, _deps?: ViteDeps): Promi
|
|
|
231
230
|
|
|
232
231
|
/**
|
|
233
232
|
* Serve the production build for local testing.
|
|
234
|
-
*
|
|
235
|
-
*
|
|
233
|
+
* The adapter's preview() serves it; without one, preview fails (TIM-1565).
|
|
234
|
+
* There is no fallback to Vite preview: it would serve the build directory
|
|
235
|
+
* itself — the server bundles as static files, with no root `index.html` —
|
|
236
|
+
* which is useless in either output mode.
|
|
236
237
|
*
|
|
237
238
|
* The project is resolved through Vite, as `timber check` resolves it
|
|
238
239
|
* (`cli-context.ts`), so the adapter, the output mode, and the build
|
|
239
240
|
* directory are the ones `timber build` used — including `--config`, inline
|
|
240
241
|
* `timber({ ... })` options, Vite's `root`, and `build.outDir`, none of which
|
|
241
242
|
* a re-read of `timber.config.ts` can see (TIM-1531). A config file that
|
|
242
|
-
* exists but fails to load throws
|
|
243
|
-
* degrading to plain Vite preview (TIM-1066).
|
|
243
|
+
* exists but fails to load throws, naming the file (TIM-1066).
|
|
244
244
|
*/
|
|
245
245
|
export async function runPreview(options: CommandOptions, _deps?: ViteDeps): Promise<void> {
|
|
246
246
|
const { resolveTimberContext } = await import('./cli-context.ts');
|
|
@@ -249,20 +249,22 @@ export async function runPreview(options: CommandOptions, _deps?: ViteDeps): Pro
|
|
|
249
249
|
const ctx = await resolveTimberContext('preview', options.config, _deps?.resolveViteConfig);
|
|
250
250
|
const adapter = contextAdapter(ctx);
|
|
251
251
|
|
|
252
|
-
if (typeof adapter?.preview
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
252
|
+
if (typeof adapter?.preview !== 'function') {
|
|
253
|
+
const missing = adapter
|
|
254
|
+
? `The adapter '${adapter.name}' has no preview(), so \`timber preview\` cannot serve this build.`
|
|
255
|
+
: `No adapter is configured, so \`timber preview\` has nothing to serve this build with.`;
|
|
256
|
+
throw new Error(
|
|
257
|
+
`[timber] ${missing} Use an adapter that implements preview() — ` +
|
|
258
|
+
`cloudflare() from '@timber-js/app/adapters/cloudflare', or nitro() from ` +
|
|
259
|
+
`'@timber-js/app/adapters/nitro' (any preset for a static build; node-server or bun ` +
|
|
260
|
+
`for a server build) — or serve the build with your platform's own tooling.`
|
|
261
|
+
);
|
|
258
262
|
}
|
|
259
263
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
configFile: options.config,
|
|
264
|
+
await adapter.preview(adapterConfig(ctx), {
|
|
265
|
+
output: ctx.config.output ?? 'server',
|
|
266
|
+
outputDir: ctx.buildDir,
|
|
264
267
|
});
|
|
265
|
-
server.printUrls();
|
|
266
268
|
}
|
|
267
269
|
|
|
268
270
|
/**
|
package/src/index.ts
CHANGED
|
@@ -270,6 +270,19 @@ export function timber(config?: TimberUserConfig): PluginOption[] {
|
|
|
270
270
|
api: { getContext: () => ctx } satisfies TimberPluginApi,
|
|
271
271
|
|
|
272
272
|
async config(userConfig, { command, isPreview }) {
|
|
273
|
+
// `vite preview` serves Vite's build.outDir as static files, and timber
|
|
274
|
+
// sets that to the whole build directory (below): the rsc/ and ssr/
|
|
275
|
+
// server bundles, with no root index.html in either output mode. Refuse
|
|
276
|
+
// it rather than expose the server code. `timber preview` resolves the
|
|
277
|
+
// project under `build`, so it never lands here. TIM-1565, design/25.
|
|
278
|
+
if (isPreview) {
|
|
279
|
+
throw new Error(
|
|
280
|
+
'[timber] `vite preview` cannot serve a timber build: it would serve the build ' +
|
|
281
|
+
'directory, server bundles included, as static files. Run `timber preview`, ' +
|
|
282
|
+
"which runs your adapter's preview()."
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
|
|
273
286
|
// ── Load timber.config.ts from the correct root ───────────────
|
|
274
287
|
// Vite's `config` hook fires before `configResolved`. The user's
|
|
275
288
|
// `root` option (if set) tells us where the project lives.
|
|
@@ -319,23 +332,12 @@ export function timber(config?: TimberUserConfig): PluginOption[] {
|
|
|
319
332
|
// production jsx-runtime doesn't export jsxDEV). The oxc.jsx
|
|
320
333
|
// override below fixes Vite's native path; plugin-react's compiler
|
|
321
334
|
// plugin is handled by patchReactCompilerForProdJsx above.
|
|
322
|
-
// ── Resolve dev
|
|
335
|
+
// ── Resolve dev port (TIM-842) ───────────────────────────────
|
|
323
336
|
// Default port is 3000. Vite handles conflicts and honors server.strictPort.
|
|
324
|
-
//
|
|
325
|
-
// For dev (`command === 'serve' && !isPreview`) we start the
|
|
326
|
-
// holding server on the requested port when available.
|
|
327
|
-
//
|
|
328
|
-
// For `vite preview` (`command === 'serve' && isPreview`) we
|
|
329
|
-
// resolve the config/env port but delegate the actual bind +
|
|
330
|
-
// auto-bump to Vite's own preview server. Starting the holding
|
|
331
|
-
// server in preview mode would self-conflict because the dev
|
|
332
|
-
// plugin's `configureServer` handoff does not run for preview;
|
|
333
|
-
// the holding server would keep the port occupied while Vite's
|
|
334
|
-
// preview tried to bind the same port.
|
|
337
|
+
// We start the holding server on the requested port when available.
|
|
335
338
|
//
|
|
336
339
|
// See design/21-dev-server.md §"Default Port and Auto-Bump".
|
|
337
340
|
let resolvedDevPort: number | null = null;
|
|
338
|
-
let resolvedDevPortExplicit = false;
|
|
339
341
|
// Middleware-mode embeddings (the analyze crawl, custom servers)
|
|
340
342
|
// never bind a port, and the dev-server plugin's listen() handoff
|
|
341
343
|
// that closes the holding server never runs — starting it would
|
|
@@ -351,39 +353,20 @@ export function timber(config?: TimberUserConfig): PluginOption[] {
|
|
|
351
353
|
: userConfig.server?.host === true
|
|
352
354
|
? undefined
|
|
353
355
|
: 'localhost';
|
|
354
|
-
if (command === 'serve' && !
|
|
355
|
-
const start = resolveStartPort({
|
|
356
|
-
configPort: userConfig.server?.port,
|
|
357
|
-
envPort: process.env.PORT,
|
|
358
|
-
});
|
|
356
|
+
if (command === 'serve' && !isMiddlewareMode) {
|
|
359
357
|
// Vite owns port selection and remembers its bound port on restart.
|
|
360
358
|
// Never forward a probed/bumped port: replacement config runs while
|
|
361
359
|
// the old listener still owns the port. The holding page is optional.
|
|
362
|
-
resolvedDevPort =
|
|
363
|
-
|
|
364
|
-
|
|
360
|
+
resolvedDevPort = resolveStartPort({
|
|
361
|
+
configPort: userConfig.server?.port,
|
|
362
|
+
envPort: process.env.PORT,
|
|
363
|
+
});
|
|
364
|
+
if (resolvedDevPort !== 0) {
|
|
365
365
|
ctx.holdingServer = createHoldingServer();
|
|
366
|
-
await ctx.holdingServer.listen(
|
|
366
|
+
await ctx.holdingServer.listen(resolvedDevPort, resolvedHost).catch(() => {
|
|
367
367
|
ctx.holdingServer = null;
|
|
368
368
|
});
|
|
369
369
|
}
|
|
370
|
-
} else if (command === 'serve' && isPreview) {
|
|
371
|
-
// Preview mode: resolve the starting port from config/env/
|
|
372
|
-
// default but do NOT probe. Vite's preview server handles the
|
|
373
|
-
// bind itself, with `preview.strictPort` controlling whether
|
|
374
|
-
// an in-use port auto-bumps (implicit) or errors (explicit).
|
|
375
|
-
const previewConfigPort =
|
|
376
|
-
typeof userConfig.preview?.port === 'number'
|
|
377
|
-
? userConfig.preview.port
|
|
378
|
-
: typeof userConfig.server?.port === 'number'
|
|
379
|
-
? userConfig.server.port
|
|
380
|
-
: undefined;
|
|
381
|
-
const start = resolveStartPort({
|
|
382
|
-
configPort: previewConfigPort,
|
|
383
|
-
envPort: process.env.PORT,
|
|
384
|
-
});
|
|
385
|
-
resolvedDevPort = start.port;
|
|
386
|
-
resolvedDevPortExplicit = start.explicit;
|
|
387
370
|
}
|
|
388
371
|
|
|
389
372
|
// Derive relative buildOutDir from the absolute buildDir (set above)
|
|
@@ -429,32 +412,20 @@ export function timber(config?: TimberUserConfig): PluginOption[] {
|
|
|
429
412
|
};
|
|
430
413
|
}
|
|
431
414
|
|
|
432
|
-
// Dev
|
|
433
|
-
//
|
|
415
|
+
// Dev mode: set outDir so dev-time references are consistent, and
|
|
416
|
+
// surface the resolved port to Vite.
|
|
434
417
|
//
|
|
435
418
|
// Dev auto-bumps unless the user sets server.strictPort.
|
|
436
419
|
// Always forward the requested port so Vite can recognize unchanged
|
|
437
420
|
// config and reuse its actual bound port across restarts (TIM-1456).
|
|
438
|
-
//
|
|
439
|
-
// For `vite preview`, we set `preview.strictPort` based on
|
|
440
|
-
// whether the user explicitly set the port. Implicit (default)
|
|
441
|
-
// preview uses strictPort: false so Vite's preview server can
|
|
442
|
-
// auto-bump from 3000. Explicit preview uses strictPort: true
|
|
443
|
-
// so conflicts fail loudly, matching the dev behavior and the
|
|
444
|
-
// TIM-842 spec.
|
|
445
421
|
const serverConfig: {
|
|
446
422
|
port?: number;
|
|
447
423
|
strictPort?: boolean;
|
|
448
424
|
forwardConsole?: boolean | { unhandledErrors?: boolean; logLevels?: string[] };
|
|
449
425
|
} = {};
|
|
450
|
-
const previewConfig: { port?: number; strictPort?: boolean } = {};
|
|
451
426
|
if (resolvedDevPort != null) {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
serverConfig.strictPort = resolvedDevPortExplicit;
|
|
455
|
-
}
|
|
456
|
-
previewConfig.port = resolvedDevPort;
|
|
457
|
-
previewConfig.strictPort = resolvedDevPortExplicit;
|
|
427
|
+
serverConfig.port = resolvedDevPort;
|
|
428
|
+
serverConfig.strictPort = userConfig.server?.strictPort ?? false;
|
|
458
429
|
}
|
|
459
430
|
|
|
460
431
|
// Enable Vite 8's built-in browser→terminal console forwarding.
|
|
@@ -476,29 +447,35 @@ export function timber(config?: TimberUserConfig): PluginOption[] {
|
|
|
476
447
|
// Seed the client optimizer's startup crawl with every 'use client'
|
|
477
448
|
// file so client-only packages are pre-bundled before the first
|
|
478
449
|
// request, not discovered mid-load (which full-reloads the page).
|
|
479
|
-
// Vite concatenates these with any entries the user sets.
|
|
450
|
+
// Vite concatenates these with any entries the user sets. The scan
|
|
451
|
+
// plugin keeps that crawl out of 'use server' modules, whose imports
|
|
452
|
+
// the browser never loads; Vite's mergeConfig concatenates it with any
|
|
453
|
+
// user or plugin-rsc rolldownOptions.plugins rather than replacing them. Its per-file
|
|
454
|
+
// cost lands inside Vite's own scan, not in client-deps-scan.
|
|
480
455
|
// See design/21-dev-server.md §"Client Dependency Pre-Bundling".
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
ctx.timer.end('client-deps-scan');
|
|
489
|
-
environments = {
|
|
490
|
-
...envOutDirs,
|
|
491
|
-
client: { ...envOutDirs.client, optimizeDeps: { entries } },
|
|
492
|
-
};
|
|
493
|
-
}
|
|
456
|
+
ctx.timer.start('client-deps-scan');
|
|
457
|
+
// Loaded lazily: directive detection pulls in @vitejs/plugin-rsc's
|
|
458
|
+
// transforms, which builds never need.
|
|
459
|
+
const { clientOptimizeDepsEntries, skipUseServerScanPlugin } =
|
|
460
|
+
await import('./plugins/client-dep-entries.ts');
|
|
461
|
+
const entries = await clientOptimizeDepsEntries(resolvedRoot, BROWSER_ENTRY_FILE, buildDir);
|
|
462
|
+
ctx.timer.end('client-deps-scan');
|
|
494
463
|
|
|
495
464
|
return {
|
|
496
465
|
build: { outDir: buildOutDir },
|
|
497
|
-
environments
|
|
466
|
+
environments: {
|
|
467
|
+
...envOutDirs,
|
|
468
|
+
client: {
|
|
469
|
+
...envOutDirs.client,
|
|
470
|
+
optimizeDeps: {
|
|
471
|
+
entries,
|
|
472
|
+
rolldownOptions: { plugins: [skipUseServerScanPlugin()] },
|
|
473
|
+
},
|
|
474
|
+
},
|
|
475
|
+
},
|
|
498
476
|
optimizeDeps: { exclude: timberOptimizeDepsExclude },
|
|
499
477
|
customLogger,
|
|
500
478
|
server: serverConfig,
|
|
501
|
-
preview: previewConfig,
|
|
502
479
|
};
|
|
503
480
|
},
|
|
504
481
|
configResolved(resolved) {
|
|
@@ -18,6 +18,14 @@
|
|
|
18
18
|
* the browser entry is listed too. Files that gain the directive after
|
|
19
19
|
* startup still fall back to Vite's late discovery.
|
|
20
20
|
*
|
|
21
|
+
* The crawl follows those entries' imports into `'use server'` modules
|
|
22
|
+
* too, because Vite's scanner does not run plugin-rsc's transforms — at
|
|
23
|
+
* runtime the browser only ever sees server references in their place.
|
|
24
|
+
* Without help the optimizer pre-bundles the actions' server-only
|
|
25
|
+
* packages (database clients, cloud SDKs) for the browser, slowing cold
|
|
26
|
+
* start or failing the whole client optimizer when one cannot bundle.
|
|
27
|
+
* `skipUseServerScanPlugin` stubs those modules out of the crawl.
|
|
28
|
+
*
|
|
21
29
|
* Design docs: 21-dev-server.md §"Client Dependency Pre-Bundling".
|
|
22
30
|
*/
|
|
23
31
|
|
|
@@ -53,6 +61,44 @@ export async function findUseClientFiles(root: string, excludeDir?: string): Pro
|
|
|
53
61
|
return matches.filter((file): file is string => file !== null);
|
|
54
62
|
}
|
|
55
63
|
|
|
64
|
+
/**
|
|
65
|
+
* The scanner's replacement for an app source file whose directive
|
|
66
|
+
* prologue holds `'use server'`: an empty module, so the crawl stops
|
|
67
|
+
* there. Returns null (load normally) for every other file. A
|
|
68
|
+
* `'use server'` inside a function body (an inline action in a server
|
|
69
|
+
* component) is not a module directive and leaves the file alone.
|
|
70
|
+
*/
|
|
71
|
+
export async function useServerScanStub(id: string): Promise<string | null> {
|
|
72
|
+
const file = normalizeSlashes(id);
|
|
73
|
+
if (file.includes('/node_modules/') || !PARSEABLE_EXTENSIONS.test(file)) return null;
|
|
74
|
+
const code = await readFile(id, 'utf8').catch(() => null);
|
|
75
|
+
if (code === null || !code.includes('use server')) return null;
|
|
76
|
+
return detectDirective(code, file) === 'use server' ? 'export {}' : null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* A rolldown plugin for the client environment's
|
|
81
|
+
* `optimizeDeps.rolldownOptions.plugins`. Vite's scanner runs these
|
|
82
|
+
* before its own scan plugin, so this `load` hook decides what the crawl
|
|
83
|
+
* sees of each app source file (Vite has no JS load hook of its own
|
|
84
|
+
* there; rolldown reads the file).
|
|
85
|
+
*
|
|
86
|
+
* Vite also runs these plugins in the optimizer's bundle step. That step
|
|
87
|
+
* bundles the discovered dependencies, which live in node_modules, so the
|
|
88
|
+
* node_modules guard makes the hook a no-op there. The exception is a
|
|
89
|
+
* linked package outside node_modules listed in `optimizeDeps.include`
|
|
90
|
+
* with a module-level `'use server'` file: named imports from the stub
|
|
91
|
+
* fail that bundle (MISSING_EXPORT). Unstubbed, it would ship the server
|
|
92
|
+
* code to the browser instead, so such a package must not be
|
|
93
|
+
* pre-bundled either way.
|
|
94
|
+
*/
|
|
95
|
+
export function skipUseServerScanPlugin(): {
|
|
96
|
+
name: string;
|
|
97
|
+
load: (id: string) => Promise<string | null>;
|
|
98
|
+
} {
|
|
99
|
+
return { name: 'timber:client-deps-skip-use-server', load: useServerScanStub };
|
|
100
|
+
}
|
|
101
|
+
|
|
56
102
|
/**
|
|
57
103
|
* Escape a path for use as an `optimizeDeps.entries` pattern. Vite globs
|
|
58
104
|
* entries, and route directories are full of glob syntax: `(group)`,
|
|
@@ -184,6 +184,8 @@ export interface RequestContextStore {
|
|
|
184
184
|
_metadataEntries?: Array<{
|
|
185
185
|
metadata: import('./types.ts').Metadata | Promise<import('./types.ts').Metadata | null>;
|
|
186
186
|
isPage: boolean;
|
|
187
|
+
/** Index of the owning segment in the route chain. */
|
|
188
|
+
segmentIndex: number;
|
|
187
189
|
}>;
|
|
188
190
|
}
|
|
189
191
|
|