@tanstack/start-plugin-core 1.167.17 → 1.167.19
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/esm/config-context.d.ts +26 -0
- package/dist/esm/config-context.js +81 -0
- package/dist/esm/config-context.js.map +1 -0
- package/dist/esm/constants.d.ts +6 -1
- package/dist/esm/constants.js +3 -2
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/import-protection-plugin/extensionlessAbsoluteIdResolver.js +1 -1
- package/dist/esm/import-protection-plugin/plugin.js +1 -1
- package/dist/esm/import-protection-plugin/virtualModules.js +1 -1
- package/dist/esm/index.d.ts +5 -3
- package/dist/esm/index.js +3 -4
- package/dist/esm/planning.d.ts +40 -0
- package/dist/esm/planning.js +107 -0
- package/dist/esm/planning.js.map +1 -0
- package/dist/esm/schema.d.ts +3093 -44
- package/dist/esm/schema.js +5 -5
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/serialization-adapters-module.d.ts +17 -0
- package/dist/esm/serialization-adapters-module.js +39 -0
- package/dist/esm/serialization-adapters-module.js.map +1 -0
- package/dist/esm/{start-compiler-plugin → start-compiler}/compiler.d.ts +2 -3
- package/dist/esm/{start-compiler-plugin → start-compiler}/compiler.js +17 -16
- package/dist/esm/start-compiler/compiler.js.map +1 -0
- package/dist/esm/start-compiler/config.d.ts +4 -0
- package/dist/esm/start-compiler/config.js +54 -0
- package/dist/esm/start-compiler/config.js.map +1 -0
- package/dist/esm/{start-compiler-plugin → start-compiler}/handleClientOnlyJSX.js +1 -1
- package/dist/esm/start-compiler/handleClientOnlyJSX.js.map +1 -0
- package/dist/esm/{start-compiler-plugin → start-compiler}/handleCreateIsomorphicFn.js +1 -1
- package/dist/esm/start-compiler/handleCreateIsomorphicFn.js.map +1 -0
- package/dist/esm/{start-compiler-plugin → start-compiler}/handleCreateMiddleware.js +1 -1
- package/dist/esm/start-compiler/handleCreateMiddleware.js.map +1 -0
- package/dist/esm/{start-compiler-plugin → start-compiler}/handleCreateServerFn.js +6 -17
- package/dist/esm/start-compiler/handleCreateServerFn.js.map +1 -0
- package/dist/esm/{start-compiler-plugin → start-compiler}/handleEnvOnly.js +1 -1
- package/dist/esm/start-compiler/handleEnvOnly.js.map +1 -0
- package/dist/esm/start-compiler/host.d.ts +20 -0
- package/dist/esm/start-compiler/host.js +38 -0
- package/dist/esm/start-compiler/host.js.map +1 -0
- package/dist/esm/start-compiler/load-module.d.ts +14 -0
- package/dist/esm/start-compiler/load-module.js +18 -0
- package/dist/esm/start-compiler/load-module.js.map +1 -0
- package/dist/esm/start-compiler/server-fn-resolver-module.d.ts +8 -0
- package/dist/esm/start-compiler/server-fn-resolver-module.js +77 -0
- package/dist/esm/start-compiler/server-fn-resolver-module.js.map +1 -0
- package/dist/esm/{start-compiler-plugin → start-compiler}/types.d.ts +4 -0
- package/dist/esm/{start-compiler-plugin → start-compiler}/utils.js +1 -1
- package/dist/esm/start-compiler/utils.js.map +1 -0
- package/dist/esm/start-manifest-plugin/manifestBuilder.d.ts +16 -16
- package/dist/esm/start-manifest-plugin/manifestBuilder.js +14 -45
- package/dist/esm/start-manifest-plugin/manifestBuilder.js.map +1 -1
- package/dist/esm/start-router-plugin/route-tree-footer.d.ts +6 -0
- package/dist/esm/start-router-plugin/route-tree-footer.js +44 -0
- package/dist/esm/start-router-plugin/route-tree-footer.js.map +1 -0
- package/dist/esm/types.d.ts +44 -10
- package/dist/esm/{dev-server-plugin → vite/dev-server-plugin}/dev-styles.js +1 -1
- package/dist/esm/vite/dev-server-plugin/dev-styles.js.map +1 -0
- package/dist/esm/{dev-server-plugin → vite/dev-server-plugin}/extract-html-scripts.js +1 -1
- package/dist/esm/vite/dev-server-plugin/extract-html-scripts.js.map +1 -0
- package/dist/esm/vite/dev-server-plugin/plugin.d.ts +7 -0
- package/dist/esm/{dev-server-plugin → vite/dev-server-plugin}/plugin.js +5 -6
- package/dist/esm/vite/dev-server-plugin/plugin.js.map +1 -0
- package/dist/esm/{load-env-plugin → vite/load-env-plugin}/plugin.js +1 -1
- package/dist/esm/vite/load-env-plugin/plugin.js.map +1 -0
- package/dist/esm/{output-directory.js → vite/output-directory.js} +2 -2
- package/dist/esm/vite/output-directory.js.map +1 -0
- package/dist/esm/vite/planning.d.ts +105 -0
- package/dist/esm/vite/planning.js +116 -0
- package/dist/esm/vite/planning.js.map +1 -0
- package/dist/esm/vite/plugin.d.ts +4 -0
- package/dist/esm/vite/plugin.js +169 -0
- package/dist/esm/vite/plugin.js.map +1 -0
- package/dist/esm/vite/plugins.d.ts +17 -0
- package/dist/esm/vite/plugins.js +50 -0
- package/dist/esm/vite/plugins.js.map +1 -0
- package/dist/esm/{post-server-build.d.ts → vite/post-server-build.d.ts} +1 -1
- package/dist/esm/{post-server-build.js → vite/post-server-build.js} +4 -4
- package/dist/esm/vite/post-server-build.js.map +1 -0
- package/dist/esm/{prerender.d.ts → vite/prerender.d.ts} +1 -1
- package/dist/esm/{prerender.js → vite/prerender.js} +5 -10
- package/dist/esm/vite/prerender.js.map +1 -0
- package/dist/esm/{preview-server-plugin → vite/preview-server-plugin}/plugin.js +4 -4
- package/dist/esm/vite/preview-server-plugin/plugin.js.map +1 -0
- package/dist/esm/vite/schema.d.ts +3373 -0
- package/dist/esm/vite/schema.js +12 -0
- package/dist/esm/vite/schema.js.map +1 -0
- package/dist/esm/vite/serialization-adapters-plugin.d.ts +5 -0
- package/dist/esm/vite/serialization-adapters-plugin.js +42 -0
- package/dist/esm/vite/serialization-adapters-plugin.js.map +1 -0
- package/dist/esm/vite/start-compiler-plugin/module-specifier.d.ts +3 -0
- package/dist/esm/vite/start-compiler-plugin/module-specifier.js +19 -0
- package/dist/esm/vite/start-compiler-plugin/module-specifier.js.map +1 -0
- package/dist/esm/{start-compiler-plugin → vite/start-compiler-plugin}/plugin.d.ts +4 -3
- package/dist/esm/vite/start-compiler-plugin/plugin.js +202 -0
- package/dist/esm/vite/start-compiler-plugin/plugin.js.map +1 -0
- package/dist/esm/vite/start-manifest-plugin/normalized-client-build.d.ts +6 -0
- package/dist/esm/vite/start-manifest-plugin/normalized-client-build.js +81 -0
- package/dist/esm/vite/start-manifest-plugin/normalized-client-build.js.map +1 -0
- package/dist/esm/vite/start-manifest-plugin/plugin.d.ts +6 -0
- package/dist/esm/{start-manifest-plugin → vite/start-manifest-plugin}/plugin.js +14 -9
- package/dist/esm/vite/start-manifest-plugin/plugin.js.map +1 -0
- package/dist/esm/{start-router-plugin → vite/start-router-plugin}/plugin.d.ts +3 -2
- package/dist/esm/{start-router-plugin → vite/start-router-plugin}/plugin.js +14 -37
- package/dist/esm/vite/start-router-plugin/plugin.js.map +1 -0
- package/dist/esm/vite/types.d.ts +15 -0
- package/package.json +14 -3
- package/src/config-context.ts +138 -0
- package/src/constants.ts +7 -3
- package/src/index.ts +5 -5
- package/src/planning.ts +151 -0
- package/src/schema.ts +93 -93
- package/src/serialization-adapters-module.ts +82 -0
- package/src/{start-compiler-plugin → start-compiler}/compiler.ts +67 -61
- package/src/start-compiler/config.ts +73 -0
- package/src/{start-compiler-plugin → start-compiler}/handleCreateServerFn.ts +14 -41
- package/src/start-compiler/host.ts +80 -0
- package/src/start-compiler/load-module.ts +31 -0
- package/src/start-compiler/server-fn-resolver-module.ts +129 -0
- package/src/{start-compiler-plugin → start-compiler}/types.ts +5 -0
- package/src/start-manifest-plugin/manifestBuilder.ts +65 -107
- package/src/start-router-plugin/route-tree-footer.ts +99 -0
- package/src/types.ts +53 -10
- package/src/{dev-server-plugin → vite/dev-server-plugin}/plugin.ts +7 -6
- package/src/{output-directory.ts → vite/output-directory.ts} +2 -2
- package/src/vite/planning.ts +234 -0
- package/src/vite/plugin.ts +276 -0
- package/src/vite/plugins.ts +81 -0
- package/src/{post-server-build.ts → vite/post-server-build.ts} +4 -6
- package/src/{prerender.ts → vite/prerender.ts} +21 -46
- package/src/{preview-server-plugin → vite/preview-server-plugin}/plugin.ts +2 -2
- package/src/vite/schema.ts +30 -0
- package/src/vite/serialization-adapters-plugin.ts +69 -0
- package/src/vite/start-compiler-plugin/module-specifier.ts +31 -0
- package/src/vite/start-compiler-plugin/plugin.ts +345 -0
- package/src/vite/start-manifest-plugin/normalized-client-build.ts +131 -0
- package/src/{start-manifest-plugin → vite/start-manifest-plugin}/plugin.ts +21 -13
- package/src/{start-router-plugin → vite/start-router-plugin}/plugin.ts +14 -80
- package/src/vite/types.ts +18 -0
- package/dist/esm/dev-server-plugin/dev-styles.js.map +0 -1
- package/dist/esm/dev-server-plugin/extract-html-scripts.js.map +0 -1
- package/dist/esm/dev-server-plugin/plugin.d.ts +0 -6
- package/dist/esm/dev-server-plugin/plugin.js.map +0 -1
- package/dist/esm/load-env-plugin/plugin.js.map +0 -1
- package/dist/esm/output-directory.js.map +0 -1
- package/dist/esm/plugin.d.ts +0 -4
- package/dist/esm/plugin.js +0 -301
- package/dist/esm/plugin.js.map +0 -1
- package/dist/esm/post-server-build.js.map +0 -1
- package/dist/esm/prerender.js.map +0 -1
- package/dist/esm/preview-server-plugin/plugin.js.map +0 -1
- package/dist/esm/start-compiler-plugin/compiler.js.map +0 -1
- package/dist/esm/start-compiler-plugin/handleClientOnlyJSX.js.map +0 -1
- package/dist/esm/start-compiler-plugin/handleCreateIsomorphicFn.js.map +0 -1
- package/dist/esm/start-compiler-plugin/handleCreateMiddleware.js.map +0 -1
- package/dist/esm/start-compiler-plugin/handleCreateServerFn.js.map +0 -1
- package/dist/esm/start-compiler-plugin/handleEnvOnly.js.map +0 -1
- package/dist/esm/start-compiler-plugin/plugin.js +0 -297
- package/dist/esm/start-compiler-plugin/plugin.js.map +0 -1
- package/dist/esm/start-compiler-plugin/utils.js.map +0 -1
- package/dist/esm/start-manifest-plugin/plugin.d.ts +0 -6
- package/dist/esm/start-manifest-plugin/plugin.js.map +0 -1
- package/dist/esm/start-router-plugin/plugin.js.map +0 -1
- package/src/plugin.ts +0 -471
- package/src/start-compiler-plugin/plugin.ts +0 -478
- /package/dist/esm/{start-compiler-plugin → start-compiler}/handleClientOnlyJSX.d.ts +0 -0
- /package/dist/esm/{start-compiler-plugin → start-compiler}/handleCreateIsomorphicFn.d.ts +0 -0
- /package/dist/esm/{start-compiler-plugin → start-compiler}/handleCreateMiddleware.d.ts +0 -0
- /package/dist/esm/{start-compiler-plugin → start-compiler}/handleCreateServerFn.d.ts +0 -0
- /package/dist/esm/{start-compiler-plugin → start-compiler}/handleEnvOnly.d.ts +0 -0
- /package/dist/esm/{start-compiler-plugin → start-compiler}/utils.d.ts +0 -0
- /package/dist/esm/{dev-server-plugin → vite/dev-server-plugin}/dev-styles.d.ts +0 -0
- /package/dist/esm/{dev-server-plugin → vite/dev-server-plugin}/extract-html-scripts.d.ts +0 -0
- /package/dist/esm/{load-env-plugin → vite/load-env-plugin}/plugin.d.ts +0 -0
- /package/dist/esm/{output-directory.d.ts → vite/output-directory.d.ts} +0 -0
- /package/dist/esm/{preview-server-plugin → vite/preview-server-plugin}/plugin.d.ts +0 -0
- /package/src/{start-compiler-plugin → start-compiler}/handleClientOnlyJSX.ts +0 -0
- /package/src/{start-compiler-plugin → start-compiler}/handleCreateIsomorphicFn.ts +0 -0
- /package/src/{start-compiler-plugin → start-compiler}/handleCreateMiddleware.ts +0 -0
- /package/src/{start-compiler-plugin → start-compiler}/handleEnvOnly.ts +0 -0
- /package/src/{start-compiler-plugin → start-compiler}/utils.ts +0 -0
- /package/src/{dev-server-plugin → vite/dev-server-plugin}/dev-styles.ts +0 -0
- /package/src/{dev-server-plugin → vite/dev-server-plugin}/extract-html-scripts.ts +0 -0
- /package/src/{load-env-plugin → vite/load-env-plugin}/plugin.ts +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { parseStartConfig as parseStartConfig$1, tanstackStartOptionsObjectSchema } from "../schema.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/vite/schema.ts
|
|
4
|
+
var tanstackStartViteOptionsSchema = tanstackStartOptionsObjectSchema.extend({ vite: z.object({ installDevServerMiddleware: z.boolean().optional() }).optional() }).optional().default({});
|
|
5
|
+
function parseStartConfig(opts, corePluginOpts, root) {
|
|
6
|
+
const { vite: _vite, ...coreOptions } = tanstackStartViteOptionsSchema.parse(opts);
|
|
7
|
+
return parseStartConfig$1(coreOptions, corePluginOpts, root);
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { parseStartConfig };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../../../src/vite/schema.ts"],"sourcesContent":["import { z } from 'zod'\nimport {\n parseStartConfig as parseCoreStartConfig,\n tanstackStartOptionsObjectSchema,\n} from '../schema'\nimport type { CompileStartFrameworkOptions } from '../types'\n\nexport const tanstackStartViteOptionsSchema = tanstackStartOptionsObjectSchema\n .extend({\n vite: z\n .object({ installDevServerMiddleware: z.boolean().optional() })\n .optional(),\n })\n .optional()\n .default({})\n\nexport function parseStartConfig(\n opts: z.input<typeof tanstackStartViteOptionsSchema>,\n corePluginOpts: { framework: CompileStartFrameworkOptions },\n root: string,\n) {\n const { vite: _vite, ...coreOptions } =\n tanstackStartViteOptionsSchema.parse(opts)\n\n return parseCoreStartConfig(coreOptions, corePluginOpts, root)\n}\n\nexport type TanStackStartViteInputConfig = z.input<\n typeof tanstackStartViteOptionsSchema\n>\n"],"mappings":";;;AAOA,IAAa,iCAAiC,iCAC3C,OAAO,EACN,MAAM,EACH,OAAO,EAAE,4BAA4B,EAAE,SAAS,CAAC,UAAU,EAAE,CAAC,CAC9D,UAAU,EACd,CAAC,CACD,UAAU,CACV,QAAQ,EAAE,CAAC;AAEd,SAAgB,iBACd,MACA,gBACA,MACA;CACA,MAAM,EAAE,MAAM,OAAO,GAAG,gBACtB,+BAA+B,MAAM,KAAK;AAE5C,QAAO,mBAAqB,aAAa,gBAAgB,KAAK"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { START_ENVIRONMENT_NAMES } from "../constants.js";
|
|
2
|
+
import { resolveViteId } from "../utils.js";
|
|
3
|
+
import { EMPTY_SERIALIZATION_ADAPTERS_MODULE, generateSerializationAdaptersModule } from "../serialization-adapters-module.js";
|
|
4
|
+
import { VIRTUAL_MODULES } from "@tanstack/start-server-core";
|
|
5
|
+
//#region src/vite/serialization-adapters-plugin.ts
|
|
6
|
+
var resolvedModuleId = resolveViteId(VIRTUAL_MODULES.pluginAdapters.replace("#", "%23"));
|
|
7
|
+
function escapeRegex(str) {
|
|
8
|
+
return str.replace(/[.*+?^${}()|[\]\\#]/g, "\\$&");
|
|
9
|
+
}
|
|
10
|
+
function serializationAdaptersPlugin(opts) {
|
|
11
|
+
return {
|
|
12
|
+
name: "tanstack-start:plugin-adapters",
|
|
13
|
+
enforce: "pre",
|
|
14
|
+
resolveId: {
|
|
15
|
+
filter: { id: new RegExp(escapeRegex(VIRTUAL_MODULES.pluginAdapters)) },
|
|
16
|
+
handler(id) {
|
|
17
|
+
if (id === VIRTUAL_MODULES.pluginAdapters) return resolvedModuleId;
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
load: {
|
|
21
|
+
filter: { id: new RegExp(escapeRegex(resolvedModuleId)) },
|
|
22
|
+
handler(id) {
|
|
23
|
+
if (id !== resolvedModuleId) return;
|
|
24
|
+
const adapters = opts.adapters;
|
|
25
|
+
if (!adapters || adapters.length === 0) return EMPTY_SERIALIZATION_ADAPTERS_MODULE;
|
|
26
|
+
if (this.environment.name === START_ENVIRONMENT_NAMES.client) return generateSerializationAdaptersModule({
|
|
27
|
+
adapters,
|
|
28
|
+
runtime: "client"
|
|
29
|
+
});
|
|
30
|
+
if (this.environment.name === START_ENVIRONMENT_NAMES.server) return generateSerializationAdaptersModule({
|
|
31
|
+
adapters,
|
|
32
|
+
runtime: "server"
|
|
33
|
+
});
|
|
34
|
+
return EMPTY_SERIALIZATION_ADAPTERS_MODULE;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { serializationAdaptersPlugin };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=serialization-adapters-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization-adapters-plugin.js","names":[],"sources":["../../../src/vite/serialization-adapters-plugin.ts"],"sourcesContent":["import { VIRTUAL_MODULES } from '@tanstack/start-server-core'\nimport {\n EMPTY_SERIALIZATION_ADAPTERS_MODULE,\n generateSerializationAdaptersModule,\n} from '../serialization-adapters-module'\nimport { START_ENVIRONMENT_NAMES } from '../constants'\nimport { resolveViteId } from '../utils'\nimport type { SerializationAdapterConfig } from '../types'\nimport type { PluginOption } from 'vite'\n\n// Encode '#' as '%23' in the resolved ID to avoid browser treating it as URL fragment.\n// The browser requests /@id/__x00__%23tanstack-start-plugin-adapters instead of\n// /@id/__x00__#tanstack-start-plugin-adapters (which would truncate at #).\nconst resolvedModuleId = resolveViteId(\n VIRTUAL_MODULES.pluginAdapters.replace('#', '%23'),\n)\n\nfunction escapeRegex(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\#]/g, '\\\\$&')\n}\n\nexport function serializationAdaptersPlugin(opts: {\n adapters: Array<SerializationAdapterConfig> | undefined\n}): PluginOption {\n return {\n name: 'tanstack-start:plugin-adapters',\n enforce: 'pre',\n resolveId: {\n filter: { id: new RegExp(escapeRegex(VIRTUAL_MODULES.pluginAdapters)) },\n handler(id: string) {\n if (id === VIRTUAL_MODULES.pluginAdapters) {\n return resolvedModuleId\n }\n return undefined\n },\n },\n load: {\n filter: {\n id: new RegExp(escapeRegex(resolvedModuleId)),\n },\n handler(this: { environment: { name: string } }, id: string) {\n if (id !== resolvedModuleId) {\n return undefined\n }\n\n const adapters = opts.adapters\n if (!adapters || adapters.length === 0) {\n return EMPTY_SERIALIZATION_ADAPTERS_MODULE\n }\n\n if (this.environment.name === START_ENVIRONMENT_NAMES.client) {\n return generateSerializationAdaptersModule({\n adapters,\n runtime: 'client',\n })\n }\n\n if (this.environment.name === START_ENVIRONMENT_NAMES.server) {\n return generateSerializationAdaptersModule({\n adapters,\n runtime: 'server',\n })\n }\n\n return EMPTY_SERIALIZATION_ADAPTERS_MODULE\n },\n },\n }\n}\n"],"mappings":";;;;;AAaA,IAAM,mBAAmB,cACvB,gBAAgB,eAAe,QAAQ,KAAK,MAAM,CACnD;AAED,SAAS,YAAY,KAAqB;AACxC,QAAO,IAAI,QAAQ,wBAAwB,OAAO;;AAGpD,SAAgB,4BAA4B,MAE3B;AACf,QAAO;EACL,MAAM;EACN,SAAS;EACT,WAAW;GACT,QAAQ,EAAE,IAAI,IAAI,OAAO,YAAY,gBAAgB,eAAe,CAAC,EAAE;GACvE,QAAQ,IAAY;AAClB,QAAI,OAAO,gBAAgB,eACzB,QAAO;;GAIZ;EACD,MAAM;GACJ,QAAQ,EACN,IAAI,IAAI,OAAO,YAAY,iBAAiB,CAAC,EAC9C;GACD,QAAiD,IAAY;AAC3D,QAAI,OAAO,iBACT;IAGF,MAAM,WAAW,KAAK;AACtB,QAAI,CAAC,YAAY,SAAS,WAAW,EACnC,QAAO;AAGT,QAAI,KAAK,YAAY,SAAS,wBAAwB,OACpD,QAAO,oCAAoC;KACzC;KACA,SAAS;KACV,CAAC;AAGJ,QAAI,KAAK,YAAY,SAAS,wBAAwB,OACpD,QAAO,oCAAoC;KACzC;KACA,SAAS;KACV,CAAC;AAGJ,WAAO;;GAEV;EACF"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DevServerFnModuleSpecifierEncoder } from '../../start-compiler/types.js';
|
|
2
|
+
export declare function createViteDevServerFnModuleSpecifierEncoder(root: string): DevServerFnModuleSpecifierEncoder;
|
|
3
|
+
export declare function decodeViteDevServerModuleSpecifier(moduleSpecifier: string): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/vite/start-compiler-plugin/module-specifier.ts
|
|
2
|
+
function createViteDevServerFnModuleSpecifierEncoder(root) {
|
|
3
|
+
const rootWithTrailingSlash = root.endsWith("/") ? root : `${root}/`;
|
|
4
|
+
return ({ extractedFilename }) => {
|
|
5
|
+
let file = extractedFilename;
|
|
6
|
+
if (file.startsWith(rootWithTrailingSlash)) file = file.slice(rootWithTrailingSlash.length);
|
|
7
|
+
return `/@id/${file}`;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function decodeViteDevServerModuleSpecifier(moduleSpecifier) {
|
|
11
|
+
let sourceFile = moduleSpecifier;
|
|
12
|
+
if (sourceFile.startsWith("/@id/")) sourceFile = sourceFile.slice(5);
|
|
13
|
+
const queryIndex = sourceFile.indexOf("?");
|
|
14
|
+
return queryIndex === -1 ? sourceFile : sourceFile.slice(0, queryIndex);
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { createViteDevServerFnModuleSpecifierEncoder, decodeViteDevServerModuleSpecifier };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=module-specifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-specifier.js","names":[],"sources":["../../../../src/vite/start-compiler-plugin/module-specifier.ts"],"sourcesContent":["import type { DevServerFnModuleSpecifierEncoder } from '../../start-compiler/types'\n\nexport function createViteDevServerFnModuleSpecifierEncoder(\n root: string,\n): DevServerFnModuleSpecifierEncoder {\n const rootWithTrailingSlash = root.endsWith('/') ? root : `${root}/`\n\n return ({ extractedFilename }) => {\n let file = extractedFilename\n\n if (file.startsWith(rootWithTrailingSlash)) {\n file = file.slice(rootWithTrailingSlash.length)\n }\n\n return `/@id/${file}`\n }\n}\n\nexport function decodeViteDevServerModuleSpecifier(\n moduleSpecifier: string,\n): string {\n let sourceFile = moduleSpecifier\n\n if (sourceFile.startsWith('/@id/')) {\n sourceFile = sourceFile.slice('/@id/'.length)\n }\n\n const queryIndex = sourceFile.indexOf('?')\n\n return queryIndex === -1 ? sourceFile : sourceFile.slice(0, queryIndex)\n}\n"],"mappings":";AAEA,SAAgB,4CACd,MACmC;CACnC,MAAM,wBAAwB,KAAK,SAAS,IAAI,GAAG,OAAO,GAAG,KAAK;AAElE,SAAQ,EAAE,wBAAwB;EAChC,IAAI,OAAO;AAEX,MAAI,KAAK,WAAW,sBAAsB,CACxC,QAAO,KAAK,MAAM,sBAAsB,OAAO;AAGjD,SAAO,QAAQ;;;AAInB,SAAgB,mCACd,iBACQ;CACR,IAAI,aAAa;AAEjB,KAAI,WAAW,WAAW,QAAQ,CAChC,cAAa,WAAW,MAAM,EAAe;CAG/C,MAAM,aAAa,WAAW,QAAQ,IAAI;AAE1C,QAAO,eAAe,KAAK,aAAa,WAAW,MAAM,GAAG,WAAW"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SERVER_FN_LOOKUP } from '
|
|
2
|
-
import { CompileStartFrameworkOptions } from '
|
|
3
|
-
import { GenerateFunctionIdFnOptional } from '
|
|
1
|
+
import { SERVER_FN_LOOKUP } from '../../constants.js';
|
|
2
|
+
import { CompileStartFrameworkOptions } from '../../types.js';
|
|
3
|
+
import { GenerateFunctionIdFnOptional } from '../../start-compiler/types.js';
|
|
4
4
|
import { PluginOption } from 'vite';
|
|
5
5
|
export { SERVER_FN_LOOKUP };
|
|
6
6
|
export interface StartCompilerPluginOptions {
|
|
@@ -8,6 +8,7 @@ export interface StartCompilerPluginOptions {
|
|
|
8
8
|
environments: Array<{
|
|
9
9
|
name: string;
|
|
10
10
|
type: 'client' | 'server';
|
|
11
|
+
getServerFnById?: string;
|
|
11
12
|
}>;
|
|
12
13
|
/**
|
|
13
14
|
* Custom function ID generator (optional).
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { SERVER_FN_LOOKUP, TRANSFORM_ID_REGEX, VITE_ENVIRONMENT_NAMES } from "../../constants.js";
|
|
2
|
+
import { cleanId } from "../../start-compiler/utils.js";
|
|
3
|
+
import { detectKindsInCode } from "../../start-compiler/compiler.js";
|
|
4
|
+
import { getTransformCodeFilterForEnv } from "../../start-compiler/config.js";
|
|
5
|
+
import { createStartCompiler, mergeServerFnsById } from "../../start-compiler/host.js";
|
|
6
|
+
import { loadModuleForViteCompiler } from "../../start-compiler/load-module.js";
|
|
7
|
+
import { generateServerFnResolverModule } from "../../start-compiler/server-fn-resolver-module.js";
|
|
8
|
+
import { createViteDevServerFnModuleSpecifierEncoder, decodeViteDevServerModuleSpecifier } from "./module-specifier.js";
|
|
9
|
+
import { resolve } from "pathe";
|
|
10
|
+
import assert from "node:assert";
|
|
11
|
+
import { VIRTUAL_MODULES } from "@tanstack/start-server-core";
|
|
12
|
+
//#region src/vite/start-compiler-plugin/plugin.ts
|
|
13
|
+
function resolveViteId(id) {
|
|
14
|
+
return `\0${id}`;
|
|
15
|
+
}
|
|
16
|
+
var validateServerFnIdVirtualModule = `virtual:tanstack-start-validate-server-fn-id`;
|
|
17
|
+
function getDevServerFnValidatorModule() {
|
|
18
|
+
return `
|
|
19
|
+
export async function getServerFnById(id, _access) {
|
|
20
|
+
const validateIdImport = ${JSON.stringify(validateServerFnIdVirtualModule)} + '?id=' + id
|
|
21
|
+
await import(/* @vite-ignore */ '/@id/__x00__' + validateIdImport)
|
|
22
|
+
const decoded = Buffer.from(id, 'base64url').toString('utf8')
|
|
23
|
+
const devServerFn = JSON.parse(decoded)
|
|
24
|
+
const mod = await import(/* @vite-ignore */ devServerFn.file)
|
|
25
|
+
return mod[devServerFn.export]
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
}
|
|
29
|
+
function parseIdQuery(id) {
|
|
30
|
+
if (!id.includes("?")) return {
|
|
31
|
+
filename: id,
|
|
32
|
+
query: {}
|
|
33
|
+
};
|
|
34
|
+
const [filename, rawQuery] = id.split(`?`, 2);
|
|
35
|
+
return {
|
|
36
|
+
filename,
|
|
37
|
+
query: Object.fromEntries(new URLSearchParams(rawQuery))
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function startCompilerPlugin(opts) {
|
|
41
|
+
const compilers = /* @__PURE__ */ new Map();
|
|
42
|
+
const serverFnsById = {};
|
|
43
|
+
const onServerFnsById = (d) => {
|
|
44
|
+
mergeServerFnsById(serverFnsById, d);
|
|
45
|
+
};
|
|
46
|
+
let root = process.cwd();
|
|
47
|
+
const resolvedResolverVirtualImportId = resolveViteId(VIRTUAL_MODULES.serverFnResolver);
|
|
48
|
+
const ssrEnvName = VITE_ENVIRONMENT_NAMES.server;
|
|
49
|
+
const ssrIsProvider = opts.providerEnvName === ssrEnvName;
|
|
50
|
+
const appliedResolverEnvironments = new Set(ssrIsProvider ? [opts.providerEnvName] : [ssrEnvName, opts.providerEnvName]);
|
|
51
|
+
function perEnvServerFnPlugin(environment) {
|
|
52
|
+
const transformCodeFilter = getTransformCodeFilterForEnv(environment.type);
|
|
53
|
+
return {
|
|
54
|
+
name: `tanstack-start-core::server-fn:${environment.name}`,
|
|
55
|
+
enforce: "pre",
|
|
56
|
+
applyToEnvironment(env) {
|
|
57
|
+
return env.name === environment.name;
|
|
58
|
+
},
|
|
59
|
+
configResolved(config) {
|
|
60
|
+
root = config.root;
|
|
61
|
+
},
|
|
62
|
+
transform: {
|
|
63
|
+
filter: {
|
|
64
|
+
id: {
|
|
65
|
+
exclude: new RegExp(`${SERVER_FN_LOOKUP}$`),
|
|
66
|
+
include: TRANSFORM_ID_REGEX
|
|
67
|
+
},
|
|
68
|
+
code: { include: transformCodeFilter }
|
|
69
|
+
},
|
|
70
|
+
async handler(code, id) {
|
|
71
|
+
let compiler = compilers.get(this.environment.name);
|
|
72
|
+
if (!compiler) {
|
|
73
|
+
const mode = this.environment.mode === "build" ? "build" : "dev";
|
|
74
|
+
compiler = createStartCompiler({
|
|
75
|
+
env: environment.type,
|
|
76
|
+
envName: environment.name,
|
|
77
|
+
root,
|
|
78
|
+
mode,
|
|
79
|
+
framework: opts.framework,
|
|
80
|
+
providerEnvName: opts.providerEnvName,
|
|
81
|
+
generateFunctionId: opts.generateFunctionId,
|
|
82
|
+
onServerFnsById,
|
|
83
|
+
getKnownServerFns: () => serverFnsById,
|
|
84
|
+
encodeModuleSpecifierInDev: mode === "dev" ? createViteDevServerFnModuleSpecifierEncoder(root) : void 0,
|
|
85
|
+
loadModule: async (id) => {
|
|
86
|
+
await loadModuleForViteCompiler({
|
|
87
|
+
compiler,
|
|
88
|
+
mode: this.environment.mode,
|
|
89
|
+
fetchModule: this.environment.mode === "dev" ? this.environment.fetchModule.bind(this.environment) : void 0,
|
|
90
|
+
loadModule: this.load.bind(this),
|
|
91
|
+
id
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
resolveId: async (source, importer) => {
|
|
95
|
+
const r = await this.resolve(source, importer);
|
|
96
|
+
if (r) {
|
|
97
|
+
if (!r.external) return cleanId(r.id);
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
compilers.set(this.environment.name, compiler);
|
|
103
|
+
}
|
|
104
|
+
const detectedKinds = detectKindsInCode(code, environment.type);
|
|
105
|
+
return await compiler.compile({
|
|
106
|
+
id,
|
|
107
|
+
code,
|
|
108
|
+
detectedKinds
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
hotUpdate(ctx) {
|
|
113
|
+
const compiler = compilers.get(this.environment.name);
|
|
114
|
+
ctx.modules.forEach((m) => {
|
|
115
|
+
if (m.id) {
|
|
116
|
+
if (compiler?.invalidateModule(m.id)) m.importers.forEach((importer) => {
|
|
117
|
+
if (importer.id) compiler?.invalidateModule(importer.id);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return [
|
|
125
|
+
...opts.environments.map(perEnvServerFnPlugin),
|
|
126
|
+
{
|
|
127
|
+
name: "tanstack-start-core:capture-server-fn-module-lookup",
|
|
128
|
+
apply: "serve",
|
|
129
|
+
applyToEnvironment(env) {
|
|
130
|
+
return !!opts.environments.find((e) => e.name === env.name);
|
|
131
|
+
},
|
|
132
|
+
transform: {
|
|
133
|
+
filter: { id: new RegExp(`${SERVER_FN_LOOKUP}$`) },
|
|
134
|
+
handler(code, id) {
|
|
135
|
+
compilers.get(this.environment.name)?.ingestModule({
|
|
136
|
+
code,
|
|
137
|
+
id: cleanId(id)
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: "tanstack-start-core:validate-server-fn-id",
|
|
144
|
+
apply: "serve",
|
|
145
|
+
load: {
|
|
146
|
+
filter: { id: new RegExp(resolveViteId(validateServerFnIdVirtualModule)) },
|
|
147
|
+
async handler(id) {
|
|
148
|
+
const fnId = parseIdQuery(id).query.id;
|
|
149
|
+
if (fnId && serverFnsById[fnId]) return `export {}`;
|
|
150
|
+
if (fnId) try {
|
|
151
|
+
const decoded = JSON.parse(Buffer.from(fnId, "base64url").toString("utf8"));
|
|
152
|
+
if (typeof decoded.file === "string" && typeof decoded.export === "string") {
|
|
153
|
+
const sourceFile = decodeViteDevServerModuleSpecifier(decoded.file);
|
|
154
|
+
if (sourceFile) {
|
|
155
|
+
const absPath = resolve(root, sourceFile);
|
|
156
|
+
assert(this.environment.mode === "dev");
|
|
157
|
+
await this.environment.fetchModule(absPath);
|
|
158
|
+
if (serverFnsById[fnId]) return `export {}`;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
} catch {}
|
|
162
|
+
this.error(`Invalid server function ID: ${fnId}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: "tanstack-start-core:server-fn-resolver",
|
|
168
|
+
enforce: "pre",
|
|
169
|
+
applyToEnvironment: (env) => {
|
|
170
|
+
return appliedResolverEnvironments.has(env.name);
|
|
171
|
+
},
|
|
172
|
+
configResolved(config) {
|
|
173
|
+
root = config.root;
|
|
174
|
+
},
|
|
175
|
+
resolveId: {
|
|
176
|
+
filter: { id: new RegExp(VIRTUAL_MODULES.serverFnResolver) },
|
|
177
|
+
handler() {
|
|
178
|
+
return resolvedResolverVirtualImportId;
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
load: {
|
|
182
|
+
filter: { id: new RegExp(resolvedResolverVirtualImportId) },
|
|
183
|
+
handler() {
|
|
184
|
+
if (this.environment.name !== opts.providerEnvName) {
|
|
185
|
+
const mod = opts.environments.find((e) => e.name === this.environment.name)?.getServerFnById;
|
|
186
|
+
if (mod) return mod;
|
|
187
|
+
else this.error(`No getServerFnById implementation found for caller environment: ${this.environment.name}`);
|
|
188
|
+
}
|
|
189
|
+
if (this.environment.mode !== "build") return getDevServerFnValidatorModule();
|
|
190
|
+
return generateServerFnResolverModule({
|
|
191
|
+
serverFnsById,
|
|
192
|
+
includeClientReferencedCheck: !ssrIsProvider
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
//#endregion
|
|
200
|
+
export { startCompilerPlugin };
|
|
201
|
+
|
|
202
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","names":[],"sources":["../../../../src/vite/start-compiler-plugin/plugin.ts"],"sourcesContent":["import assert from 'node:assert'\nimport { VIRTUAL_MODULES } from '@tanstack/start-server-core'\nimport { resolve as resolvePath } from 'pathe'\nimport {\n SERVER_FN_LOOKUP,\n TRANSFORM_ID_REGEX,\n VITE_ENVIRONMENT_NAMES,\n} from '../../constants'\nimport { detectKindsInCode } from '../../start-compiler/compiler'\nimport { getTransformCodeFilterForEnv } from '../../start-compiler/config'\nimport {\n createStartCompiler,\n mergeServerFnsById,\n} from '../../start-compiler/host'\nimport { loadModuleForViteCompiler } from '../../start-compiler/load-module'\nimport { generateServerFnResolverModule } from '../../start-compiler/server-fn-resolver-module'\nimport { cleanId } from '../../start-compiler/utils'\nimport {\n createViteDevServerFnModuleSpecifierEncoder,\n decodeViteDevServerModuleSpecifier,\n} from './module-specifier'\nimport type { CompileStartFrameworkOptions } from '../../types'\nimport type {\n GenerateFunctionIdFnOptional,\n ServerFn,\n} from '../../start-compiler/types'\nimport type { PluginOption } from 'vite'\n\n// Re-export from shared constants for backwards compatibility\nexport { SERVER_FN_LOOKUP }\n\nfunction resolveViteId(id: string) {\n return `\\0${id}`\n}\n\nconst validateServerFnIdVirtualModule = `virtual:tanstack-start-validate-server-fn-id`\n\nfunction getDevServerFnValidatorModule(): string {\n return `\nexport async function getServerFnById(id, _access) {\n const validateIdImport = ${JSON.stringify(validateServerFnIdVirtualModule)} + '?id=' + id\n await import(/* @vite-ignore */ '/@id/__x00__' + validateIdImport)\n const decoded = Buffer.from(id, 'base64url').toString('utf8')\n const devServerFn = JSON.parse(decoded)\n const mod = await import(/* @vite-ignore */ devServerFn.file)\n return mod[devServerFn.export]\n}\n`\n}\n\nfunction parseIdQuery(id: string): {\n filename: string\n query: {\n [k: string]: string\n }\n} {\n if (!id.includes('?')) return { filename: id, query: {} }\n const [filename, rawQuery] = id.split(`?`, 2) as [string, string]\n const query = Object.fromEntries(new URLSearchParams(rawQuery))\n return { filename, query }\n}\n\nexport interface StartCompilerPluginOptions {\n framework: CompileStartFrameworkOptions\n environments: Array<{\n name: string\n type: 'client' | 'server'\n getServerFnById?: string\n }>\n /**\n * Custom function ID generator (optional).\n */\n generateFunctionId?: GenerateFunctionIdFnOptional\n /**\n * The Vite environment name for the server function provider.\n */\n providerEnvName: string\n}\n\nexport function startCompilerPlugin(\n opts: StartCompilerPluginOptions,\n): PluginOption {\n const compilers = new Map<string, ReturnType<typeof createStartCompiler>>()\n\n // Shared registry of server functions across all environments\n const serverFnsById: Record<string, ServerFn> = {}\n\n const onServerFnsById = (d: Record<string, ServerFn>) => {\n mergeServerFnsById(serverFnsById, d)\n }\n\n let root = process.cwd()\n const resolvedResolverVirtualImportId = resolveViteId(\n VIRTUAL_MODULES.serverFnResolver,\n )\n\n // Determine which environments need the resolver (getServerFnById)\n // SSR environment always needs the resolver for server-side calls\n // Provider environment needs it for the actual implementation\n const ssrEnvName = VITE_ENVIRONMENT_NAMES.server\n\n // SSR is the provider when the provider environment is the default server environment\n const ssrIsProvider = opts.providerEnvName === ssrEnvName\n\n // Environments that need the resolver: SSR (for server calls) and provider (for implementation)\n const appliedResolverEnvironments = new Set(\n ssrIsProvider ? [opts.providerEnvName] : [ssrEnvName, opts.providerEnvName],\n )\n\n function perEnvServerFnPlugin(environment: {\n name: string\n type: 'client' | 'server'\n }): PluginOption {\n // Derive transform code filter from KindDetectionPatterns (single source of truth)\n const transformCodeFilter = getTransformCodeFilterForEnv(environment.type)\n return {\n name: `tanstack-start-core::server-fn:${environment.name}`,\n enforce: 'pre',\n applyToEnvironment(env) {\n return env.name === environment.name\n },\n configResolved(config) {\n root = config.root\n },\n transform: {\n filter: {\n id: {\n exclude: new RegExp(`${SERVER_FN_LOOKUP}$`),\n include: TRANSFORM_ID_REGEX,\n },\n code: {\n include: transformCodeFilter,\n },\n },\n async handler(code, id) {\n let compiler = compilers.get(this.environment.name)\n\n if (!compiler) {\n // Default to 'dev' mode for unknown environments (conservative: no caching)\n const mode = this.environment.mode === 'build' ? 'build' : 'dev'\n\n compiler = createStartCompiler({\n env: environment.type,\n envName: environment.name,\n root,\n mode,\n framework: opts.framework,\n providerEnvName: opts.providerEnvName,\n generateFunctionId: opts.generateFunctionId,\n onServerFnsById,\n getKnownServerFns: () => serverFnsById,\n encodeModuleSpecifierInDev:\n mode === 'dev'\n ? createViteDevServerFnModuleSpecifierEncoder(root)\n : undefined,\n loadModule: async (id: string) => {\n await loadModuleForViteCompiler({\n compiler: compiler!,\n mode: this.environment.mode,\n fetchModule:\n this.environment.mode === 'dev'\n ? this.environment.fetchModule.bind(this.environment)\n : undefined,\n loadModule: this.load.bind(this),\n id,\n })\n },\n\n resolveId: async (source: string, importer?: string) => {\n const r = await this.resolve(source, importer)\n\n if (r) {\n if (!r.external) {\n return cleanId(r.id)\n }\n }\n\n return null\n },\n })\n\n compilers.set(this.environment.name, compiler)\n }\n\n // Detect which kinds are present in this file before parsing\n const detectedKinds = detectKindsInCode(code, environment.type)\n\n const result = await compiler.compile({\n id,\n code,\n detectedKinds,\n })\n return result\n },\n },\n\n hotUpdate(ctx) {\n const compiler = compilers.get(this.environment.name)\n\n ctx.modules.forEach((m) => {\n if (m.id) {\n const deleted = compiler?.invalidateModule(m.id)\n if (deleted) {\n m.importers.forEach((importer) => {\n if (importer.id) {\n compiler?.invalidateModule(importer.id)\n }\n })\n }\n }\n })\n },\n }\n }\n\n return [\n ...opts.environments.map(perEnvServerFnPlugin),\n {\n name: 'tanstack-start-core:capture-server-fn-module-lookup',\n // we only need this plugin in dev mode\n apply: 'serve',\n applyToEnvironment(env) {\n return !!opts.environments.find((e) => e.name === env.name)\n },\n transform: {\n filter: {\n id: new RegExp(`${SERVER_FN_LOOKUP}$`),\n },\n handler(code, id) {\n const compiler = compilers.get(this.environment.name)\n compiler?.ingestModule({ code, id: cleanId(id) })\n },\n },\n },\n // Validate server function ID in dev mode\n {\n name: 'tanstack-start-core:validate-server-fn-id',\n apply: 'serve',\n load: {\n filter: {\n id: new RegExp(resolveViteId(validateServerFnIdVirtualModule)),\n },\n async handler(id) {\n const parsed = parseIdQuery(id)\n const fnId = parsed.query.id\n if (fnId && serverFnsById[fnId]) {\n return `export {}`\n }\n\n // ID not yet registered — the source file may not have been\n // transformed in this dev session yet (e.g. cold restart with\n // cached client). Try to decode the ID, discover the source\n // file, trigger its compilation, and re-check.\n if (fnId) {\n try {\n const decoded = JSON.parse(\n Buffer.from(fnId, 'base64url').toString('utf8'),\n )\n if (\n typeof decoded.file === 'string' &&\n typeof decoded.export === 'string'\n ) {\n // Use the Vite strategy to decode the module specifier\n // back to the original source file path.\n const sourceFile = decodeViteDevServerModuleSpecifier(\n decoded.file,\n )\n\n if (sourceFile) {\n // Resolve to absolute path\n const absPath = resolvePath(root, sourceFile)\n\n // Trigger transform of the source file in this environment,\n // which will compile createServerFn calls and populate\n // serverFnsById as a side effect.\n // This plugin only runs in dev (apply: 'serve'), so mode\n // must be 'dev' — assert to narrow to DevEnvironment.\n assert(this.environment.mode === 'dev')\n await this.environment.fetchModule(absPath)\n\n // Re-check after lazy compilation\n if (serverFnsById[fnId]) {\n return `export {}`\n }\n }\n }\n } catch {\n // Decoding or fetching failed — fall through to error\n }\n }\n\n this.error(`Invalid server function ID: ${fnId}`)\n },\n },\n },\n // Manifest plugin for server environments\n {\n name: 'tanstack-start-core:server-fn-resolver',\n enforce: 'pre',\n applyToEnvironment: (env) => {\n return appliedResolverEnvironments.has(env.name)\n },\n configResolved(config) {\n root = config.root\n },\n resolveId: {\n filter: { id: new RegExp(VIRTUAL_MODULES.serverFnResolver) },\n handler() {\n return resolvedResolverVirtualImportId\n },\n },\n load: {\n filter: { id: new RegExp(resolvedResolverVirtualImportId) },\n handler() {\n if (this.environment.name !== opts.providerEnvName) {\n const mod = opts.environments.find(\n (e) => e.name === this.environment.name,\n )?.getServerFnById\n if (mod) {\n return mod\n } else {\n this.error(\n `No getServerFnById implementation found for caller environment: ${this.environment.name}`,\n )\n }\n }\n\n if (this.environment.mode !== 'build') {\n return getDevServerFnValidatorModule()\n }\n\n // When SSR is the provider, server-only-referenced functions aren't in the manifest,\n // so no isClientReferenced check is needed.\n // When SSR is NOT the provider (custom provider env), server-only-referenced\n // functions ARE in the manifest and need the isClientReferenced check to\n // block direct client HTTP requests to server-only-referenced functions.\n return generateServerFnResolverModule({\n serverFnsById,\n includeClientReferencedCheck: !ssrIsProvider,\n })\n },\n },\n },\n ]\n}\n"],"mappings":";;;;;;;;;;;;AA+BA,SAAS,cAAc,IAAY;AACjC,QAAO,KAAK;;AAGd,IAAM,kCAAkC;AAExC,SAAS,gCAAwC;AAC/C,QAAO;;6BAEoB,KAAK,UAAU,gCAAgC,CAAC;;;;;;;;;AAU7E,SAAS,aAAa,IAKpB;AACA,KAAI,CAAC,GAAG,SAAS,IAAI,CAAE,QAAO;EAAE,UAAU;EAAI,OAAO,EAAE;EAAE;CACzD,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';
|
|
3
|
+
export declare function normalizeViteClientChunk(chunk: Rollup.OutputChunk): NormalizedClientChunk;
|
|
4
|
+
export declare function normalizeViteClientChunks(clientBundle: Rollup.OutputBundle): ReadonlyMap<string, NormalizedClientChunk>;
|
|
5
|
+
export declare function normalizeViteClientBuild(clientBundle: Rollup.OutputBundle): NormalizedClientBuild;
|
|
6
|
+
export declare function getRouteFilePathsFromModuleIds(moduleIds: Array<string>): string[];
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { tsrSplit } from "@tanstack/router-plugin";
|
|
2
|
+
//#region src/vite/start-manifest-plugin/normalized-client-build.ts
|
|
3
|
+
function normalizeViteClientChunk(chunk) {
|
|
4
|
+
return {
|
|
5
|
+
fileName: chunk.fileName,
|
|
6
|
+
isEntry: chunk.isEntry,
|
|
7
|
+
imports: chunk.imports,
|
|
8
|
+
dynamicImports: chunk.dynamicImports,
|
|
9
|
+
css: Array.from(chunk.viteMetadata?.importedCss ?? []),
|
|
10
|
+
routeFilePaths: getRouteFilePathsFromModuleIds(chunk.moduleIds)
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function normalizeViteClientChunks(clientBundle) {
|
|
14
|
+
const chunksByFileName = /* @__PURE__ */ new Map();
|
|
15
|
+
for (const fileName in clientBundle) {
|
|
16
|
+
const bundleEntry = clientBundle[fileName];
|
|
17
|
+
if (bundleEntry.type !== "chunk") continue;
|
|
18
|
+
const normalizedChunk = normalizeViteClientChunk(bundleEntry);
|
|
19
|
+
chunksByFileName.set(normalizedChunk.fileName, normalizedChunk);
|
|
20
|
+
}
|
|
21
|
+
return chunksByFileName;
|
|
22
|
+
}
|
|
23
|
+
function normalizeViteClientBuild(clientBundle) {
|
|
24
|
+
let entryChunkFileName;
|
|
25
|
+
const chunksByFileName = normalizeViteClientChunks(clientBundle);
|
|
26
|
+
const chunkFileNamesByRouteFilePath = /* @__PURE__ */ new Map();
|
|
27
|
+
const cssFilesBySourcePath = /* @__PURE__ */ new Map();
|
|
28
|
+
for (const chunk of chunksByFileName.values()) {
|
|
29
|
+
if (chunk.isEntry) {
|
|
30
|
+
if (entryChunkFileName) throw new Error(`multiple entries detected: ${entryChunkFileName} ${chunk.fileName}`);
|
|
31
|
+
entryChunkFileName = chunk.fileName;
|
|
32
|
+
}
|
|
33
|
+
for (const routeFilePath of chunk.routeFilePaths) {
|
|
34
|
+
let chunkFileNames = chunkFileNamesByRouteFilePath.get(routeFilePath);
|
|
35
|
+
if (chunkFileNames === void 0) {
|
|
36
|
+
chunkFileNames = [];
|
|
37
|
+
chunkFileNamesByRouteFilePath.set(routeFilePath, chunkFileNames);
|
|
38
|
+
}
|
|
39
|
+
chunkFileNames.push(chunk.fileName);
|
|
40
|
+
}
|
|
41
|
+
const bundleEntry = clientBundle[chunk.fileName];
|
|
42
|
+
if (bundleEntry?.type === "chunk") for (const moduleId of bundleEntry.moduleIds) {
|
|
43
|
+
const queryIndex = moduleId.indexOf("?");
|
|
44
|
+
const sourcePath = queryIndex >= 0 ? moduleId.slice(0, queryIndex) : moduleId;
|
|
45
|
+
if (!sourcePath) continue;
|
|
46
|
+
const existing = cssFilesBySourcePath.get(sourcePath);
|
|
47
|
+
cssFilesBySourcePath.set(sourcePath, existing ? Array.from(new Set([...existing, ...chunk.css])) : chunk.css.slice());
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (!entryChunkFileName) throw new Error("No entry file found");
|
|
51
|
+
return {
|
|
52
|
+
entryChunkFileName,
|
|
53
|
+
chunksByFileName,
|
|
54
|
+
chunkFileNamesByRouteFilePath,
|
|
55
|
+
cssFilesBySourcePath
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function getRouteFilePathsFromModuleIds(moduleIds) {
|
|
59
|
+
let routeFilePaths;
|
|
60
|
+
let seenRouteFilePaths;
|
|
61
|
+
for (const moduleId of moduleIds) {
|
|
62
|
+
const queryIndex = moduleId.indexOf("?");
|
|
63
|
+
if (queryIndex < 0) continue;
|
|
64
|
+
const query = moduleId.slice(queryIndex + 1);
|
|
65
|
+
if (!query.includes(tsrSplit)) continue;
|
|
66
|
+
if (!new URLSearchParams(query).has(tsrSplit)) continue;
|
|
67
|
+
const routeFilePath = moduleId.slice(0, queryIndex);
|
|
68
|
+
if (seenRouteFilePaths?.has(routeFilePath)) continue;
|
|
69
|
+
if (routeFilePaths === void 0 || seenRouteFilePaths === void 0) {
|
|
70
|
+
routeFilePaths = [];
|
|
71
|
+
seenRouteFilePaths = /* @__PURE__ */ new Set();
|
|
72
|
+
}
|
|
73
|
+
routeFilePaths.push(routeFilePath);
|
|
74
|
+
seenRouteFilePaths.add(routeFilePath);
|
|
75
|
+
}
|
|
76
|
+
return routeFilePaths ?? [];
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
export { getRouteFilePathsFromModuleIds, normalizeViteClientBuild, normalizeViteClientChunk };
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=normalized-client-build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalized-client-build.js","names":[],"sources":["../../../../src/vite/start-manifest-plugin/normalized-client-build.ts"],"sourcesContent":["import { tsrSplit } from '@tanstack/router-plugin'\nimport type { Rollup } from 'vite'\nimport type { NormalizedClientBuild, NormalizedClientChunk } from '../../types'\n\nexport function normalizeViteClientChunk(\n chunk: Rollup.OutputChunk,\n): NormalizedClientChunk {\n return {\n fileName: chunk.fileName,\n isEntry: chunk.isEntry,\n imports: chunk.imports,\n dynamicImports: chunk.dynamicImports,\n css: Array.from(chunk.viteMetadata?.importedCss ?? []),\n routeFilePaths: getRouteFilePathsFromModuleIds(chunk.moduleIds),\n }\n}\n\nexport function normalizeViteClientChunks(\n clientBundle: Rollup.OutputBundle,\n): ReadonlyMap<string, NormalizedClientChunk> {\n const chunksByFileName = new Map<string, NormalizedClientChunk>()\n\n for (const fileName in clientBundle) {\n const bundleEntry = clientBundle[fileName]!\n if (bundleEntry.type !== 'chunk') {\n continue\n }\n\n const normalizedChunk = normalizeViteClientChunk(bundleEntry)\n chunksByFileName.set(normalizedChunk.fileName, normalizedChunk)\n }\n\n return chunksByFileName\n}\n\nexport function normalizeViteClientBuild(\n clientBundle: Rollup.OutputBundle,\n): NormalizedClientBuild {\n let entryChunkFileName: string | undefined\n const chunksByFileName = normalizeViteClientChunks(clientBundle)\n const chunkFileNamesByRouteFilePath = new Map<string, Array<string>>()\n const cssFilesBySourcePath = new Map<string, Array<string>>()\n\n for (const chunk of chunksByFileName.values()) {\n if (chunk.isEntry) {\n if (entryChunkFileName) {\n throw new Error(\n `multiple entries detected: ${entryChunkFileName} ${chunk.fileName}`,\n )\n }\n entryChunkFileName = chunk.fileName\n }\n\n for (const routeFilePath of chunk.routeFilePaths) {\n let chunkFileNames = chunkFileNamesByRouteFilePath.get(routeFilePath)\n if (chunkFileNames === undefined) {\n chunkFileNames = []\n chunkFileNamesByRouteFilePath.set(routeFilePath, chunkFileNames)\n }\n chunkFileNames.push(chunk.fileName)\n }\n\n const bundleEntry = clientBundle[chunk.fileName]\n if (bundleEntry?.type === 'chunk') {\n for (const moduleId of bundleEntry.moduleIds) {\n const queryIndex = moduleId.indexOf('?')\n const sourcePath =\n queryIndex >= 0 ? moduleId.slice(0, queryIndex) : moduleId\n if (!sourcePath) continue\n\n const existing = cssFilesBySourcePath.get(sourcePath)\n cssFilesBySourcePath.set(\n sourcePath,\n existing\n ? Array.from(new Set([...existing, ...chunk.css]))\n : chunk.css.slice(),\n )\n }\n }\n }\n\n if (!entryChunkFileName) {\n throw new Error('No entry file found')\n }\n\n return {\n entryChunkFileName,\n chunksByFileName,\n chunkFileNamesByRouteFilePath,\n cssFilesBySourcePath,\n }\n}\n\nexport function getRouteFilePathsFromModuleIds(moduleIds: Array<string>) {\n let routeFilePaths: Array<string> | undefined\n let seenRouteFilePaths: Set<string> | undefined\n\n for (const moduleId of moduleIds) {\n const queryIndex = moduleId.indexOf('?')\n\n if (queryIndex < 0) {\n continue\n }\n\n const query = moduleId.slice(queryIndex + 1)\n\n if (!query.includes(tsrSplit)) {\n continue\n }\n\n if (!new URLSearchParams(query).has(tsrSplit)) {\n continue\n }\n\n const routeFilePath = moduleId.slice(0, queryIndex)\n\n if (seenRouteFilePaths?.has(routeFilePath)) {\n continue\n }\n\n if (routeFilePaths === undefined || seenRouteFilePaths === undefined) {\n routeFilePaths = []\n seenRouteFilePaths = new Set<string>()\n }\n\n routeFilePaths.push(routeFilePath)\n seenRouteFilePaths.add(routeFilePath)\n }\n\n return routeFilePaths ?? []\n}\n"],"mappings":";;AAIA,SAAgB,yBACd,OACuB;AACvB,QAAO;EACL,UAAU,MAAM;EAChB,SAAS,MAAM;EACf,SAAS,MAAM;EACf,gBAAgB,MAAM;EACtB,KAAK,MAAM,KAAK,MAAM,cAAc,eAAe,EAAE,CAAC;EACtD,gBAAgB,+BAA+B,MAAM,UAAU;EAChE;;AAGH,SAAgB,0BACd,cAC4C;CAC5C,MAAM,mCAAmB,IAAI,KAAoC;AAEjE,MAAK,MAAM,YAAY,cAAc;EACnC,MAAM,cAAc,aAAa;AACjC,MAAI,YAAY,SAAS,QACvB;EAGF,MAAM,kBAAkB,yBAAyB,YAAY;AAC7D,mBAAiB,IAAI,gBAAgB,UAAU,gBAAgB;;AAGjE,QAAO;;AAGT,SAAgB,yBACd,cACuB;CACvB,IAAI;CACJ,MAAM,mBAAmB,0BAA0B,aAAa;CAChE,MAAM,gDAAgC,IAAI,KAA4B;CACtE,MAAM,uCAAuB,IAAI,KAA4B;AAE7D,MAAK,MAAM,SAAS,iBAAiB,QAAQ,EAAE;AAC7C,MAAI,MAAM,SAAS;AACjB,OAAI,mBACF,OAAM,IAAI,MACR,8BAA8B,mBAAmB,GAAG,MAAM,WAC3D;AAEH,wBAAqB,MAAM;;AAG7B,OAAK,MAAM,iBAAiB,MAAM,gBAAgB;GAChD,IAAI,iBAAiB,8BAA8B,IAAI,cAAc;AACrE,OAAI,mBAAmB,KAAA,GAAW;AAChC,qBAAiB,EAAE;AACnB,kCAA8B,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INTS, START_ENVIRONMENT_NAMES } from "../../constants.js";
|
|
2
|
+
import { resolveViteId } from "../../utils.js";
|
|
3
|
+
import { buildStartManifest } from "../../start-manifest-plugin/manifestBuilder.js";
|
|
5
4
|
import { VIRTUAL_MODULES } from "@tanstack/start-server-core";
|
|
6
|
-
|
|
5
|
+
import { joinURL } from "ufo";
|
|
6
|
+
//#region src/vite/start-manifest-plugin/plugin.ts
|
|
7
7
|
var resolvedModuleId = resolveViteId(VIRTUAL_MODULES.startManifest);
|
|
8
8
|
function startManifestPlugin(opts) {
|
|
9
9
|
return {
|
|
@@ -20,16 +20,21 @@ function startManifestPlugin(opts) {
|
|
|
20
20
|
handler(id) {
|
|
21
21
|
const { resolvedStartConfig } = opts.getConfig();
|
|
22
22
|
if (id === resolvedModuleId) {
|
|
23
|
-
if (this.environment.name !==
|
|
23
|
+
if (this.environment.name !== START_ENVIRONMENT_NAMES.server) return "export default {}";
|
|
24
24
|
if (this.environment.config.command === "serve") return `export const tsrStartManifest = () => ({
|
|
25
25
|
routes: {},
|
|
26
|
-
clientEntry: '${joinURL(resolvedStartConfig.
|
|
26
|
+
clientEntry: '${joinURL(resolvedStartConfig.basePaths.publicBase, "@id", ENTRY_POINTS.client)}',
|
|
27
27
|
})`;
|
|
28
28
|
const routeTreeRoutes = globalThis.TSS_ROUTES_MANIFEST;
|
|
29
|
+
const clientBuild = opts.getClientBuild();
|
|
30
|
+
if (!clientBuild) return `export const tsrStartManifest = () => ({
|
|
31
|
+
routes: {},
|
|
32
|
+
clientEntry: '${joinURL(resolvedStartConfig.basePaths.publicBase, "@id", ENTRY_POINTS.client)}',
|
|
33
|
+
})`;
|
|
29
34
|
const startManifest = buildStartManifest({
|
|
30
|
-
|
|
35
|
+
clientBuild,
|
|
31
36
|
routeTreeRoutes,
|
|
32
|
-
basePath: resolvedStartConfig.
|
|
37
|
+
basePath: resolvedStartConfig.basePaths.publicBase
|
|
33
38
|
});
|
|
34
39
|
return `export const tsrStartManifest = () => (${JSON.stringify(startManifest)})`;
|
|
35
40
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","names":[],"sources":["../../../../src/vite/start-manifest-plugin/plugin.ts"],"sourcesContent":["import { joinURL } from 'ufo'\nimport { VIRTUAL_MODULES } from '@tanstack/start-server-core'\nimport { resolveViteId } from '../../utils'\nimport { ENTRY_POINTS, START_ENVIRONMENT_NAMES } from '../../constants'\nimport { buildStartManifest } from '../../start-manifest-plugin/manifestBuilder'\nimport type { GetConfigFn, NormalizedClientBuild } from '../../types'\nimport type { PluginOption } from 'vite'\n\nconst resolvedModuleId = resolveViteId(VIRTUAL_MODULES.startManifest)\n\nexport function startManifestPlugin(opts: {\n getClientBuild: () => NormalizedClientBuild | undefined\n getConfig: GetConfigFn\n}): PluginOption {\n return {\n name: 'tanstack-start:start-manifest-plugin',\n enforce: 'pre',\n resolveId: {\n filter: { id: new RegExp(VIRTUAL_MODULES.startManifest) },\n handler(id) {\n if (id === VIRTUAL_MODULES.startManifest) {\n return resolvedModuleId\n }\n return undefined\n },\n },\n load: {\n filter: {\n id: new RegExp(resolvedModuleId),\n },\n handler(id) {\n const { resolvedStartConfig } = opts.getConfig()\n if (id === resolvedModuleId) {\n if (this.environment.name !== START_ENVIRONMENT_NAMES.server) {\n return 'export default {}'\n }\n\n if (this.environment.config.command === 'serve') {\n return `export const tsrStartManifest = () => ({\n routes: {},\n clientEntry: '${joinURL(resolvedStartConfig.basePaths.publicBase, '@id', ENTRY_POINTS.client)}',\n })`\n }\n\n const routeTreeRoutes = globalThis.TSS_ROUTES_MANIFEST\n const clientBuild = opts.getClientBuild()\n // TODO this needs further discussion with vite-rsc, this is a temporary workaround\n // If the client bundle isn't available yet (e.g., during RSC scan builds),\n // return a dummy manifest. The real manifest will be generated in the actual build.\n if (!clientBuild) {\n return `export const tsrStartManifest = () => ({\n routes: {},\n clientEntry: '${joinURL(resolvedStartConfig.basePaths.publicBase, '@id', ENTRY_POINTS.client)}',\n })`\n }\n const startManifest = buildStartManifest({\n clientBuild,\n routeTreeRoutes,\n basePath: resolvedStartConfig.basePaths.publicBase,\n })\n\n return `export const tsrStartManifest = () => (${JSON.stringify(startManifest)})`\n }\n\n return undefined\n },\n },\n }\n}\n"],"mappings":";;;;;;AAQA,IAAM,mBAAmB,cAAc,gBAAgB,cAAc;AAErE,SAAgB,oBAAoB,MAGnB;AACf,QAAO;EACL,MAAM;EACN,SAAS;EACT,WAAW;GACT,QAAQ,EAAE,IAAI,IAAI,OAAO,gBAAgB,cAAc,EAAE;GACzD,QAAQ,IAAI;AACV,QAAI,OAAO,gBAAgB,cACzB,QAAO;;GAIZ;EACD,MAAM;GACJ,QAAQ,EACN,IAAI,IAAI,OAAO,iBAAiB,EACjC;GACD,QAAQ,IAAI;IACV,MAAM,EAAE,wBAAwB,KAAK,WAAW;AAChD,QAAI,OAAO,kBAAkB;AAC3B,SAAI,KAAK,YAAY,SAAS,wBAAwB,OACpD,QAAO;AAGT,SAAI,KAAK,YAAY,OAAO,YAAY,QACtC,QAAO;;4BAES,QAAQ,oBAAoB,UAAU,YAAY,OAAO,aAAa,OAAO,CAAC;;KAIhG,MAAM,kBAAkB,WAAW;KACnC,MAAM,cAAc,KAAK,gBAAgB;AAIzC,SAAI,CAAC,YACH,QAAO;;8BAEW,QAAQ,oBAAoB,UAAU,YAAY,OAAO,aAAa,OAAO,CAAC;;KAGlG,MAAM,gBAAgB,mBAAmB;MACvC;MACA;MACA,UAAU,oBAAoB,UAAU;MACzC,CAAC;AAEF,YAAO,0CAA0C,KAAK,UAAU,cAAc,CAAC;;;GAKpF;EACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { GetConfigFn
|
|
1
|
+
import { GetConfigFn } from '../../types.js';
|
|
2
|
+
import { TanStackStartVitePluginCoreOptions } from '../types.js';
|
|
2
3
|
import { PluginOption } from 'vite';
|
|
3
|
-
import { TanStackStartInputConfig } from '
|
|
4
|
+
import { TanStackStartInputConfig } from '../../schema.js';
|
|
4
5
|
export declare function tanStackStartRouter(startPluginOpts: TanStackStartInputConfig, getConfig: GetConfigFn, corePluginOpts: TanStackStartVitePluginCoreOptions): Array<PluginOption>;
|
|
@@ -1,35 +1,17 @@
|
|
|
1
|
-
import { VITE_ENVIRONMENT_NAMES } from "
|
|
2
|
-
import { routesManifestPlugin } from "
|
|
3
|
-
import { prerenderRoutesPlugin } from "
|
|
4
|
-
import "
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
1
|
+
import { VITE_ENVIRONMENT_NAMES } from "../../constants.js";
|
|
2
|
+
import { routesManifestPlugin } from "../../start-router-plugin/generator-plugins/routes-manifest-plugin.js";
|
|
3
|
+
import { prerenderRoutesPlugin } from "../../start-router-plugin/generator-plugins/prerender-routes-plugin.js";
|
|
4
|
+
import { buildRouteTreeFileFooterFromConfig } from "../../start-router-plugin/route-tree-footer.js";
|
|
5
|
+
import "../../start-router-plugin/constants.js";
|
|
6
|
+
import { pruneServerOnlySubtrees } from "../../start-router-plugin/pruneServerOnlySubtrees.js";
|
|
7
7
|
import path from "pathe";
|
|
8
|
+
import { normalizePath } from "vite";
|
|
8
9
|
import { tanStackRouterCodeSplitter, tanstackRouterAutoImport, tanstackRouterGenerator } from "@tanstack/router-plugin/vite";
|
|
9
|
-
//#region src/start-router-plugin/plugin.ts
|
|
10
|
+
//#region src/vite/start-router-plugin/plugin.ts
|
|
10
11
|
function isServerOnlyNode(node) {
|
|
11
12
|
if (!node?.createFileRouteProps) return false;
|
|
12
13
|
return node.createFileRouteProps.has("server") && node.createFileRouteProps.size === 1;
|
|
13
14
|
}
|
|
14
|
-
function moduleDeclaration({ startFilePath, routerFilePath, corePluginOpts, generatedRouteTreePath }) {
|
|
15
|
-
function getImportPath(absolutePath) {
|
|
16
|
-
let relativePath = path.relative(path.dirname(generatedRouteTreePath), absolutePath);
|
|
17
|
-
if (!relativePath.startsWith(".")) relativePath = "./" + relativePath;
|
|
18
|
-
relativePath = relativePath.split(path.sep).join("/");
|
|
19
|
-
return relativePath;
|
|
20
|
-
}
|
|
21
|
-
const result = [`import type { getRouter } from '${getImportPath(routerFilePath)}'`];
|
|
22
|
-
if (startFilePath) result.push(`import type { startInstance } from '${getImportPath(startFilePath)}'`);
|
|
23
|
-
else result.push(`import type { createStart } from '@tanstack/${corePluginOpts.framework}-start'`);
|
|
24
|
-
result.push(`declare module '@tanstack/${corePluginOpts.framework}-start' {
|
|
25
|
-
interface Register {
|
|
26
|
-
ssr: true
|
|
27
|
-
router: Awaited<ReturnType<typeof getRouter>>`);
|
|
28
|
-
if (startFilePath) result.push(` config: Awaited<ReturnType<typeof startInstance.getOptions>>`);
|
|
29
|
-
result.push(` }
|
|
30
|
-
}`);
|
|
31
|
-
return result.join("\n");
|
|
32
|
-
}
|
|
33
15
|
function tanStackStartRouter(startPluginOpts, getConfig, corePluginOpts) {
|
|
34
16
|
const getGeneratedRouteTreePath = () => {
|
|
35
17
|
const { startConfig } = getConfig();
|
|
@@ -58,16 +40,11 @@ function tanStackStartRouter(startPluginOpts, getConfig, corePluginOpts) {
|
|
|
58
40
|
let routeTreeFileFooter = null;
|
|
59
41
|
function getRouteTreeFileFooter() {
|
|
60
42
|
if (routeTreeFileFooter) return routeTreeFileFooter;
|
|
61
|
-
|
|
62
|
-
const ogRouteTreeFileFooter = startConfig.router.routeTreeFileFooter;
|
|
63
|
-
if (ogRouteTreeFileFooter) if (Array.isArray(ogRouteTreeFileFooter)) routeTreeFileFooter = ogRouteTreeFileFooter;
|
|
64
|
-
else routeTreeFileFooter = ogRouteTreeFileFooter();
|
|
65
|
-
routeTreeFileFooter = [moduleDeclaration({
|
|
43
|
+
routeTreeFileFooter = [...buildRouteTreeFileFooterFromConfig({
|
|
66
44
|
generatedRouteTreePath: getGeneratedRouteTreePath(),
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}), ...routeTreeFileFooter ?? []];
|
|
45
|
+
getConfig,
|
|
46
|
+
corePluginOpts
|
|
47
|
+
})];
|
|
71
48
|
return routeTreeFileFooter;
|
|
72
49
|
}
|
|
73
50
|
let resolvedGeneratedRouteTreePath = null;
|
|
@@ -114,7 +91,7 @@ function tanStackStartRouter(startPluginOpts, getConfig, corePluginOpts) {
|
|
|
114
91
|
tanstackRouterGenerator(() => {
|
|
115
92
|
const routerConfig = getConfig().startConfig.router;
|
|
116
93
|
const plugins = [clientTreeGeneratorPlugin, routesManifestPlugin()];
|
|
117
|
-
if (startPluginOpts
|
|
94
|
+
if (startPluginOpts.prerender?.enabled === true) plugins.push(prerenderRoutesPlugin());
|
|
118
95
|
return {
|
|
119
96
|
...routerConfig,
|
|
120
97
|
target: corePluginOpts.framework,
|
|
@@ -149,7 +126,7 @@ function tanStackStartRouter(startPluginOpts, getConfig, corePluginOpts) {
|
|
|
149
126
|
plugin: { vite: { environmentName: VITE_ENVIRONMENT_NAMES.server } }
|
|
150
127
|
};
|
|
151
128
|
}),
|
|
152
|
-
tanstackRouterAutoImport(startPluginOpts
|
|
129
|
+
tanstackRouterAutoImport(startPluginOpts.router)
|
|
153
130
|
];
|
|
154
131
|
}
|
|
155
132
|
//#endregion
|