@tanstack/start-server-core 1.166.9 → 1.166.10

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.
@@ -1,113 +1,102 @@
1
1
  import { rootRouteId } from "@tanstack/router-core";
2
+ //#region src/transformAssetUrls.ts
3
+ /**
4
+ * Resolves a TransformAssetUrls value (string prefix, callback, or options
5
+ * object) into a concrete transform function and cache flag.
6
+ */
2
7
  function resolveTransformConfig(transform) {
3
- if (typeof transform === "string") {
4
- const prefix = transform;
5
- return {
6
- type: "transform",
7
- transformFn: ({ url }) => `${prefix}${url}`,
8
- cache: true
9
- };
10
- }
11
- if (typeof transform === "function") {
12
- return {
13
- type: "transform",
14
- transformFn: transform,
15
- cache: true
16
- };
17
- }
18
- if ("createTransform" in transform && transform.createTransform) {
19
- return {
20
- type: "createTransform",
21
- createTransform: transform.createTransform,
22
- cache: transform.cache !== false
23
- };
24
- }
25
- const transformFn = typeof transform.transform === "string" ? (({ url }) => `${transform.transform}${url}`) : transform.transform;
26
- return {
27
- type: "transform",
28
- transformFn,
29
- cache: transform.cache !== false
30
- };
8
+ if (typeof transform === "string") {
9
+ const prefix = transform;
10
+ return {
11
+ type: "transform",
12
+ transformFn: ({ url }) => `${prefix}${url}`,
13
+ cache: true
14
+ };
15
+ }
16
+ if (typeof transform === "function") return {
17
+ type: "transform",
18
+ transformFn: transform,
19
+ cache: true
20
+ };
21
+ if ("createTransform" in transform && transform.createTransform) return {
22
+ type: "createTransform",
23
+ createTransform: transform.createTransform,
24
+ cache: transform.cache !== false
25
+ };
26
+ return {
27
+ type: "transform",
28
+ transformFn: typeof transform.transform === "string" ? (({ url }) => `${transform.transform}${url}`) : transform.transform,
29
+ cache: transform.cache !== false
30
+ };
31
31
  }
32
+ /**
33
+ * Builds the client entry `<script>` tag from a (possibly transformed) client
34
+ * entry URL and optional injected head scripts.
35
+ */
32
36
  function buildClientEntryScriptTag(clientEntry, injectedHeadScripts) {
33
- const clientEntryLiteral = JSON.stringify(clientEntry);
34
- let script = `import(${clientEntryLiteral})`;
35
- if (injectedHeadScripts) {
36
- script = `${injectedHeadScripts};${script}`;
37
- }
38
- return {
39
- tag: "script",
40
- attrs: {
41
- type: "module",
42
- async: true
43
- },
44
- children: script
45
- };
37
+ let script = `import(${JSON.stringify(clientEntry)})`;
38
+ if (injectedHeadScripts) script = `${injectedHeadScripts};${script}`;
39
+ return {
40
+ tag: "script",
41
+ attrs: {
42
+ type: "module",
43
+ async: true
44
+ },
45
+ children: script
46
+ };
46
47
  }
48
+ /**
49
+ * Applies a URL transform to every asset URL in the manifest and returns a
50
+ * new manifest with a client entry script tag appended to the root route's
51
+ * assets.
52
+ *
53
+ * The source manifest is deep-cloned so the cached original is never mutated.
54
+ */
47
55
  function transformManifestUrls(source, transformFn, opts) {
48
- return (async () => {
49
- const manifest = opts?.clone ? structuredClone(source.manifest) : source.manifest;
50
- for (const route of Object.values(manifest.routes)) {
51
- if (route.preloads) {
52
- route.preloads = await Promise.all(
53
- route.preloads.map(
54
- (url) => Promise.resolve(transformFn({ url, type: "modulepreload" }))
55
- )
56
- );
57
- }
58
- if (route.assets) {
59
- for (const asset of route.assets) {
60
- if (asset.tag === "link" && asset.attrs?.href) {
61
- asset.attrs.href = await Promise.resolve(
62
- transformFn({
63
- url: asset.attrs.href,
64
- type: "stylesheet"
65
- })
66
- );
67
- }
68
- }
69
- }
70
- }
71
- const transformedClientEntry = await Promise.resolve(
72
- transformFn({
73
- url: source.clientEntry,
74
- type: "clientEntry"
75
- })
76
- );
77
- const rootRoute = manifest.routes[rootRouteId];
78
- if (rootRoute) {
79
- rootRoute.assets = rootRoute.assets || [];
80
- rootRoute.assets.push(
81
- buildClientEntryScriptTag(
82
- transformedClientEntry,
83
- source.injectedHeadScripts
84
- )
85
- );
86
- }
87
- return manifest;
88
- })();
56
+ return (async () => {
57
+ const manifest = opts?.clone ? structuredClone(source.manifest) : source.manifest;
58
+ for (const route of Object.values(manifest.routes)) {
59
+ if (route.preloads) route.preloads = await Promise.all(route.preloads.map((url) => Promise.resolve(transformFn({
60
+ url,
61
+ type: "modulepreload"
62
+ }))));
63
+ if (route.assets) {
64
+ for (const asset of route.assets) if (asset.tag === "link" && asset.attrs?.href) asset.attrs.href = await Promise.resolve(transformFn({
65
+ url: asset.attrs.href,
66
+ type: "stylesheet"
67
+ }));
68
+ }
69
+ }
70
+ const transformedClientEntry = await Promise.resolve(transformFn({
71
+ url: source.clientEntry,
72
+ type: "clientEntry"
73
+ }));
74
+ const rootRoute = manifest.routes[rootRouteId];
75
+ if (rootRoute) {
76
+ rootRoute.assets = rootRoute.assets || [];
77
+ rootRoute.assets.push(buildClientEntryScriptTag(transformedClientEntry, source.injectedHeadScripts));
78
+ }
79
+ return manifest;
80
+ })();
89
81
  }
82
+ /**
83
+ * Builds a final Manifest from a StartManifestWithClientEntry without any
84
+ * URL transforms. Used when no transformAssetUrls option is provided.
85
+ *
86
+ * Returns a new manifest object so the cached base manifest is never mutated.
87
+ */
90
88
  function buildManifestWithClientEntry(source) {
91
- const scriptTag = buildClientEntryScriptTag(
92
- source.clientEntry,
93
- source.injectedHeadScripts
94
- );
95
- const baseRootRoute = source.manifest.routes[rootRouteId];
96
- const routes = {
97
- ...source.manifest.routes,
98
- ...baseRootRoute ? {
99
- [rootRouteId]: {
100
- ...baseRootRoute,
101
- assets: [...baseRootRoute.assets || [], scriptTag]
102
- }
103
- } : {}
104
- };
105
- return { routes };
89
+ const scriptTag = buildClientEntryScriptTag(source.clientEntry, source.injectedHeadScripts);
90
+ const baseRootRoute = source.manifest.routes[rootRouteId];
91
+ return { routes: {
92
+ ...source.manifest.routes,
93
+ ...baseRootRoute ? { [rootRouteId]: {
94
+ ...baseRootRoute,
95
+ assets: [...baseRootRoute.assets || [], scriptTag]
96
+ } } : {}
97
+ } };
106
98
  }
107
- export {
108
- buildClientEntryScriptTag,
109
- buildManifestWithClientEntry,
110
- resolveTransformConfig,
111
- transformManifestUrls
112
- };
113
- //# sourceMappingURL=transformAssetUrls.js.map
99
+ //#endregion
100
+ export { buildManifestWithClientEntry, resolveTransformConfig, transformManifestUrls };
101
+
102
+ //# sourceMappingURL=transformAssetUrls.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"transformAssetUrls.js","sources":["../../src/transformAssetUrls.ts"],"sourcesContent":["import { rootRouteId } from '@tanstack/router-core'\n\nimport type {\n Awaitable,\n Manifest,\n RouterManagedTag,\n} from '@tanstack/router-core'\n\nexport type AssetUrlType = 'modulepreload' | 'stylesheet' | 'clientEntry'\n\nexport interface TransformAssetUrlsContext {\n url: string\n type: AssetUrlType\n}\n\nexport type TransformAssetUrlsFn = (\n context: TransformAssetUrlsContext,\n) => Awaitable<string>\n\nexport type CreateTransformAssetUrlsContext =\n | {\n /** True when the server is computing the cached manifest during startup warmup. */\n warmup: true\n }\n | {\n /**\n * The current Request.\n *\n * Only available during request handling (i.e. when `warmup: false`).\n */\n request: Request\n /** False when transforming URLs as part of request handling. */\n warmup: false\n }\n\n/**\n * Async factory that runs once per manifest computation and returns the\n * per-asset transform.\n */\nexport type CreateTransformAssetUrlsFn = (\n ctx: CreateTransformAssetUrlsContext,\n) => Awaitable<TransformAssetUrlsFn>\n\ntype TransformAssetUrlsOptionsBase = {\n /**\n * Whether to cache the transformed manifest after the first request.\n *\n * When `true` (default), the transform runs once on the first request and\n * the resulting manifest is reused for all subsequent requests in production.\n *\n * Set to `false` for per-request transforms (e.g. geo-routing to different\n * CDNs based on request headers).\n *\n * @default true\n */\n cache?: boolean\n\n /**\n * When `true`, warms up the cached transformed manifest in the background when\n * the server starts (production only).\n *\n * This can reduce latency for the first request when `cache` is `true`.\n * Has no effect when `cache: false` (per-request transforms) or in dev mode.\n *\n * @default false\n */\n warmup?: boolean\n}\n\nexport type TransformAssetUrlsOptions =\n | (TransformAssetUrlsOptionsBase & {\n /**\n * The transform to apply to asset URLs. Can be a string prefix or a callback.\n *\n * **String** — prepended to every asset URL.\n * **Callback** — receives `{ url, type }` and returns a new URL.\n */\n transform: string | TransformAssetUrlsFn\n createTransform?: never\n })\n | (TransformAssetUrlsOptionsBase & {\n /**\n * Create a per-asset transform function.\n *\n * This factory runs once per manifest computation (per request when\n * `cache: false`, or once per server when `cache: true`). It can do async\n * setup work (fetch config, read from a KV, etc.) and return a fast\n * per-asset transformer.\n */\n createTransform: CreateTransformAssetUrlsFn\n transform?: never\n })\n\nexport type TransformAssetUrls =\n | string\n | TransformAssetUrlsFn\n | TransformAssetUrlsOptions\n\nexport type ResolvedTransformAssetUrlsConfig =\n | {\n type: 'transform'\n transformFn: TransformAssetUrlsFn\n cache: boolean\n }\n | {\n type: 'createTransform'\n createTransform: CreateTransformAssetUrlsFn\n cache: boolean\n }\n\n/**\n * Resolves a TransformAssetUrls value (string prefix, callback, or options\n * object) into a concrete transform function and cache flag.\n */\nexport function resolveTransformConfig(\n transform: TransformAssetUrls,\n): ResolvedTransformAssetUrlsConfig {\n // String shorthand\n if (typeof transform === 'string') {\n const prefix = transform\n return {\n type: 'transform',\n transformFn: ({ url }) => `${prefix}${url}`,\n cache: true,\n }\n }\n\n // Callback shorthand\n if (typeof transform === 'function') {\n return {\n type: 'transform',\n transformFn: transform,\n cache: true,\n }\n }\n\n // Options object\n if ('createTransform' in transform && transform.createTransform) {\n return {\n type: 'createTransform',\n createTransform: transform.createTransform,\n cache: transform.cache !== false,\n }\n }\n\n const transformFn =\n typeof transform.transform === 'string'\n ? ((({ url }: TransformAssetUrlsContext) =>\n `${transform.transform}${url}`) as TransformAssetUrlsFn)\n : transform.transform\n\n return {\n type: 'transform',\n transformFn,\n cache: transform.cache !== false,\n }\n}\n\nexport interface StartManifestWithClientEntry {\n manifest: Manifest\n clientEntry: string\n /** Script content prepended before the client entry import (dev only) */\n injectedHeadScripts?: string\n}\n\n/**\n * Builds the client entry `<script>` tag from a (possibly transformed) client\n * entry URL and optional injected head scripts.\n */\nexport function buildClientEntryScriptTag(\n clientEntry: string,\n injectedHeadScripts?: string,\n): RouterManagedTag {\n const clientEntryLiteral = JSON.stringify(clientEntry)\n let script = `import(${clientEntryLiteral})`\n if (injectedHeadScripts) {\n script = `${injectedHeadScripts};${script}`\n }\n return {\n tag: 'script',\n attrs: {\n type: 'module',\n async: true,\n },\n children: script,\n }\n}\n\n/**\n * Applies a URL transform to every asset URL in the manifest and returns a\n * new manifest with a client entry script tag appended to the root route's\n * assets.\n *\n * The source manifest is deep-cloned so the cached original is never mutated.\n */\nexport function transformManifestUrls(\n source: StartManifestWithClientEntry,\n transformFn: TransformAssetUrlsFn,\n opts?: {\n /** When true, clone the source manifest before mutating it. */\n clone?: boolean\n },\n): Promise<Manifest> {\n return (async () => {\n const manifest = opts?.clone\n ? structuredClone(source.manifest)\n : source.manifest\n\n for (const route of Object.values(manifest.routes)) {\n // Transform preload URLs (modulepreload)\n if (route.preloads) {\n route.preloads = await Promise.all(\n route.preloads.map((url) =>\n Promise.resolve(transformFn({ url, type: 'modulepreload' })),\n ),\n )\n }\n\n // Transform asset tag URLs\n if (route.assets) {\n for (const asset of route.assets) {\n if (asset.tag === 'link' && asset.attrs?.href) {\n asset.attrs.href = await Promise.resolve(\n transformFn({\n url: asset.attrs.href,\n type: 'stylesheet',\n }),\n )\n }\n }\n }\n }\n\n // Transform and append the client entry script tag\n const transformedClientEntry = await Promise.resolve(\n transformFn({\n url: source.clientEntry,\n type: 'clientEntry',\n }),\n )\n\n const rootRoute = manifest.routes[rootRouteId]\n if (rootRoute) {\n rootRoute.assets = rootRoute.assets || []\n rootRoute.assets.push(\n buildClientEntryScriptTag(\n transformedClientEntry,\n source.injectedHeadScripts,\n ),\n )\n }\n\n return manifest\n })()\n}\n\n/**\n * Builds a final Manifest from a StartManifestWithClientEntry without any\n * URL transforms. Used when no transformAssetUrls option is provided.\n *\n * Returns a new manifest object so the cached base manifest is never mutated.\n */\nexport function buildManifestWithClientEntry(\n source: StartManifestWithClientEntry,\n): Manifest {\n const scriptTag = buildClientEntryScriptTag(\n source.clientEntry,\n source.injectedHeadScripts,\n )\n\n const baseRootRoute = source.manifest.routes[rootRouteId]\n const routes = {\n ...source.manifest.routes,\n ...(baseRootRoute\n ? {\n [rootRouteId]: {\n ...baseRootRoute,\n assets: [...(baseRootRoute.assets || []), scriptTag],\n },\n }\n : {}),\n }\n\n return { routes }\n}\n"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"transformAssetUrls.js","names":[],"sources":["../../src/transformAssetUrls.ts"],"sourcesContent":["import { rootRouteId } from '@tanstack/router-core'\n\nimport type {\n Awaitable,\n Manifest,\n RouterManagedTag,\n} from '@tanstack/router-core'\n\nexport type AssetUrlType = 'modulepreload' | 'stylesheet' | 'clientEntry'\n\nexport interface TransformAssetUrlsContext {\n url: string\n type: AssetUrlType\n}\n\nexport type TransformAssetUrlsFn = (\n context: TransformAssetUrlsContext,\n) => Awaitable<string>\n\nexport type CreateTransformAssetUrlsContext =\n | {\n /** True when the server is computing the cached manifest during startup warmup. */\n warmup: true\n }\n | {\n /**\n * The current Request.\n *\n * Only available during request handling (i.e. when `warmup: false`).\n */\n request: Request\n /** False when transforming URLs as part of request handling. */\n warmup: false\n }\n\n/**\n * Async factory that runs once per manifest computation and returns the\n * per-asset transform.\n */\nexport type CreateTransformAssetUrlsFn = (\n ctx: CreateTransformAssetUrlsContext,\n) => Awaitable<TransformAssetUrlsFn>\n\ntype TransformAssetUrlsOptionsBase = {\n /**\n * Whether to cache the transformed manifest after the first request.\n *\n * When `true` (default), the transform runs once on the first request and\n * the resulting manifest is reused for all subsequent requests in production.\n *\n * Set to `false` for per-request transforms (e.g. geo-routing to different\n * CDNs based on request headers).\n *\n * @default true\n */\n cache?: boolean\n\n /**\n * When `true`, warms up the cached transformed manifest in the background when\n * the server starts (production only).\n *\n * This can reduce latency for the first request when `cache` is `true`.\n * Has no effect when `cache: false` (per-request transforms) or in dev mode.\n *\n * @default false\n */\n warmup?: boolean\n}\n\nexport type TransformAssetUrlsOptions =\n | (TransformAssetUrlsOptionsBase & {\n /**\n * The transform to apply to asset URLs. Can be a string prefix or a callback.\n *\n * **String** — prepended to every asset URL.\n * **Callback** — receives `{ url, type }` and returns a new URL.\n */\n transform: string | TransformAssetUrlsFn\n createTransform?: never\n })\n | (TransformAssetUrlsOptionsBase & {\n /**\n * Create a per-asset transform function.\n *\n * This factory runs once per manifest computation (per request when\n * `cache: false`, or once per server when `cache: true`). It can do async\n * setup work (fetch config, read from a KV, etc.) and return a fast\n * per-asset transformer.\n */\n createTransform: CreateTransformAssetUrlsFn\n transform?: never\n })\n\nexport type TransformAssetUrls =\n | string\n | TransformAssetUrlsFn\n | TransformAssetUrlsOptions\n\nexport type ResolvedTransformAssetUrlsConfig =\n | {\n type: 'transform'\n transformFn: TransformAssetUrlsFn\n cache: boolean\n }\n | {\n type: 'createTransform'\n createTransform: CreateTransformAssetUrlsFn\n cache: boolean\n }\n\n/**\n * Resolves a TransformAssetUrls value (string prefix, callback, or options\n * object) into a concrete transform function and cache flag.\n */\nexport function resolveTransformConfig(\n transform: TransformAssetUrls,\n): ResolvedTransformAssetUrlsConfig {\n // String shorthand\n if (typeof transform === 'string') {\n const prefix = transform\n return {\n type: 'transform',\n transformFn: ({ url }) => `${prefix}${url}`,\n cache: true,\n }\n }\n\n // Callback shorthand\n if (typeof transform === 'function') {\n return {\n type: 'transform',\n transformFn: transform,\n cache: true,\n }\n }\n\n // Options object\n if ('createTransform' in transform && transform.createTransform) {\n return {\n type: 'createTransform',\n createTransform: transform.createTransform,\n cache: transform.cache !== false,\n }\n }\n\n const transformFn =\n typeof transform.transform === 'string'\n ? ((({ url }: TransformAssetUrlsContext) =>\n `${transform.transform}${url}`) as TransformAssetUrlsFn)\n : transform.transform\n\n return {\n type: 'transform',\n transformFn,\n cache: transform.cache !== false,\n }\n}\n\nexport interface StartManifestWithClientEntry {\n manifest: Manifest\n clientEntry: string\n /** Script content prepended before the client entry import (dev only) */\n injectedHeadScripts?: string\n}\n\n/**\n * Builds the client entry `<script>` tag from a (possibly transformed) client\n * entry URL and optional injected head scripts.\n */\nexport function buildClientEntryScriptTag(\n clientEntry: string,\n injectedHeadScripts?: string,\n): RouterManagedTag {\n const clientEntryLiteral = JSON.stringify(clientEntry)\n let script = `import(${clientEntryLiteral})`\n if (injectedHeadScripts) {\n script = `${injectedHeadScripts};${script}`\n }\n return {\n tag: 'script',\n attrs: {\n type: 'module',\n async: true,\n },\n children: script,\n }\n}\n\n/**\n * Applies a URL transform to every asset URL in the manifest and returns a\n * new manifest with a client entry script tag appended to the root route's\n * assets.\n *\n * The source manifest is deep-cloned so the cached original is never mutated.\n */\nexport function transformManifestUrls(\n source: StartManifestWithClientEntry,\n transformFn: TransformAssetUrlsFn,\n opts?: {\n /** When true, clone the source manifest before mutating it. */\n clone?: boolean\n },\n): Promise<Manifest> {\n return (async () => {\n const manifest = opts?.clone\n ? structuredClone(source.manifest)\n : source.manifest\n\n for (const route of Object.values(manifest.routes)) {\n // Transform preload URLs (modulepreload)\n if (route.preloads) {\n route.preloads = await Promise.all(\n route.preloads.map((url) =>\n Promise.resolve(transformFn({ url, type: 'modulepreload' })),\n ),\n )\n }\n\n // Transform asset tag URLs\n if (route.assets) {\n for (const asset of route.assets) {\n if (asset.tag === 'link' && asset.attrs?.href) {\n asset.attrs.href = await Promise.resolve(\n transformFn({\n url: asset.attrs.href,\n type: 'stylesheet',\n }),\n )\n }\n }\n }\n }\n\n // Transform and append the client entry script tag\n const transformedClientEntry = await Promise.resolve(\n transformFn({\n url: source.clientEntry,\n type: 'clientEntry',\n }),\n )\n\n const rootRoute = manifest.routes[rootRouteId]\n if (rootRoute) {\n rootRoute.assets = rootRoute.assets || []\n rootRoute.assets.push(\n buildClientEntryScriptTag(\n transformedClientEntry,\n source.injectedHeadScripts,\n ),\n )\n }\n\n return manifest\n })()\n}\n\n/**\n * Builds a final Manifest from a StartManifestWithClientEntry without any\n * URL transforms. Used when no transformAssetUrls option is provided.\n *\n * Returns a new manifest object so the cached base manifest is never mutated.\n */\nexport function buildManifestWithClientEntry(\n source: StartManifestWithClientEntry,\n): Manifest {\n const scriptTag = buildClientEntryScriptTag(\n source.clientEntry,\n source.injectedHeadScripts,\n )\n\n const baseRootRoute = source.manifest.routes[rootRouteId]\n const routes = {\n ...source.manifest.routes,\n ...(baseRootRoute\n ? {\n [rootRouteId]: {\n ...baseRootRoute,\n assets: [...(baseRootRoute.assets || []), scriptTag],\n },\n }\n : {}),\n }\n\n return { routes }\n}\n"],"mappings":";;;;;;AAkHA,SAAgB,uBACd,WACkC;AAElC,KAAI,OAAO,cAAc,UAAU;EACjC,MAAM,SAAS;AACf,SAAO;GACL,MAAM;GACN,cAAc,EAAE,UAAU,GAAG,SAAS;GACtC,OAAO;GACR;;AAIH,KAAI,OAAO,cAAc,WACvB,QAAO;EACL,MAAM;EACN,aAAa;EACb,OAAO;EACR;AAIH,KAAI,qBAAqB,aAAa,UAAU,gBAC9C,QAAO;EACL,MAAM;EACN,iBAAiB,UAAU;EAC3B,OAAO,UAAU,UAAU;EAC5B;AASH,QAAO;EACL,MAAM;EACN,aAPA,OAAO,UAAU,cAAc,aACxB,EAAE,UACH,GAAG,UAAU,YAAY,SAC3B,UAAU;EAKd,OAAO,UAAU,UAAU;EAC5B;;;;;;AAcH,SAAgB,0BACd,aACA,qBACkB;CAElB,IAAI,SAAS,UADc,KAAK,UAAU,YAAY,CACZ;AAC1C,KAAI,oBACF,UAAS,GAAG,oBAAoB,GAAG;AAErC,QAAO;EACL,KAAK;EACL,OAAO;GACL,MAAM;GACN,OAAO;GACR;EACD,UAAU;EACX;;;;;;;;;AAUH,SAAgB,sBACd,QACA,aACA,MAImB;AACnB,SAAQ,YAAY;EAClB,MAAM,WAAW,MAAM,QACnB,gBAAgB,OAAO,SAAS,GAChC,OAAO;AAEX,OAAK,MAAM,SAAS,OAAO,OAAO,SAAS,OAAO,EAAE;AAElD,OAAI,MAAM,SACR,OAAM,WAAW,MAAM,QAAQ,IAC7B,MAAM,SAAS,KAAK,QAClB,QAAQ,QAAQ,YAAY;IAAE;IAAK,MAAM;IAAiB,CAAC,CAAC,CAC7D,CACF;AAIH,OAAI,MAAM;SACH,MAAM,SAAS,MAAM,OACxB,KAAI,MAAM,QAAQ,UAAU,MAAM,OAAO,KACvC,OAAM,MAAM,OAAO,MAAM,QAAQ,QAC/B,YAAY;KACV,KAAK,MAAM,MAAM;KACjB,MAAM;KACP,CAAC,CACH;;;EAOT,MAAM,yBAAyB,MAAM,QAAQ,QAC3C,YAAY;GACV,KAAK,OAAO;GACZ,MAAM;GACP,CAAC,CACH;EAED,MAAM,YAAY,SAAS,OAAO;AAClC,MAAI,WAAW;AACb,aAAU,SAAS,UAAU,UAAU,EAAE;AACzC,aAAU,OAAO,KACf,0BACE,wBACA,OAAO,oBACR,CACF;;AAGH,SAAO;KACL;;;;;;;;AASN,SAAgB,6BACd,QACU;CACV,MAAM,YAAY,0BAChB,OAAO,aACP,OAAO,oBACR;CAED,MAAM,gBAAgB,OAAO,SAAS,OAAO;AAa7C,QAAO,EAAE,QAZM;EACb,GAAG,OAAO,SAAS;EACnB,GAAI,gBACA,GACG,cAAc;GACb,GAAG;GACH,QAAQ,CAAC,GAAI,cAAc,UAAU,EAAE,EAAG,UAAU;GACrD,EACF,GACD,EAAE;EACP,EAEgB"}
@@ -1,9 +1,10 @@
1
- const VIRTUAL_MODULES = {
2
- startManifest: "tanstack-start-manifest:v",
3
- injectedHeadScripts: "tanstack-start-injected-head-scripts:v",
4
- serverFnResolver: "#tanstack-start-server-fn-resolver"
1
+ //#region src/virtual-modules.ts
2
+ var VIRTUAL_MODULES = {
3
+ startManifest: "tanstack-start-manifest:v",
4
+ injectedHeadScripts: "tanstack-start-injected-head-scripts:v",
5
+ serverFnResolver: "#tanstack-start-server-fn-resolver"
5
6
  };
6
- export {
7
- VIRTUAL_MODULES
8
- };
9
- //# sourceMappingURL=virtual-modules.js.map
7
+ //#endregion
8
+ export { VIRTUAL_MODULES };
9
+
10
+ //# sourceMappingURL=virtual-modules.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"virtual-modules.js","sources":["../../src/virtual-modules.ts"],"sourcesContent":["export const VIRTUAL_MODULES = {\n startManifest: 'tanstack-start-manifest:v',\n injectedHeadScripts: 'tanstack-start-injected-head-scripts:v',\n serverFnResolver: '#tanstack-start-server-fn-resolver',\n} as const\n"],"names":[],"mappings":"AAAO,MAAM,kBAAkB;AAAA,EAC7B,eAAe;AAAA,EACf,qBAAqB;AAAA,EACrB,kBAAkB;AACpB;"}
1
+ {"version":3,"file":"virtual-modules.js","names":[],"sources":["../../src/virtual-modules.ts"],"sourcesContent":["export const VIRTUAL_MODULES = {\n startManifest: 'tanstack-start-manifest:v',\n injectedHeadScripts: 'tanstack-start-injected-head-scripts:v',\n serverFnResolver: '#tanstack-start-server-fn-resolver',\n} as const\n"],"mappings":";AAAA,IAAa,kBAAkB;CAC7B,eAAe;CACf,qBAAqB;CACrB,kBAAkB;CACnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/start-server-core",
3
- "version": "1.166.9",
3
+ "version": "1.166.10",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -63,10 +63,10 @@
63
63
  "h3-v2": "npm:h3@2.0.1-rc.16",
64
64
  "seroval": "^1.4.2",
65
65
  "tiny-invariant": "^1.3.3",
66
- "@tanstack/history": "1.161.5",
67
- "@tanstack/router-core": "1.167.1",
68
- "@tanstack/start-client-core": "1.166.9",
69
- "@tanstack/start-storage-context": "1.166.9"
66
+ "@tanstack/history": "1.161.6",
67
+ "@tanstack/router-core": "1.167.2",
68
+ "@tanstack/start-client-core": "1.166.10",
69
+ "@tanstack/start-storage-context": "1.166.10"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@standard-schema/spec": "^1.0.0",
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}