@tanstack/start-plugin-core 1.121.0-alpha.23 → 1.121.0-alpha.25
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/cjs/plugin.cjs +1 -1
- package/dist/cjs/plugin.cjs.map +1 -1
- package/dist/cjs/start-routes-manifest-plugin/plugin.cjs +1 -1
- package/dist/cjs/start-routes-manifest-plugin/plugin.cjs.map +1 -1
- package/dist/esm/plugin.js +1 -1
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/start-routes-manifest-plugin/plugin.js +1 -1
- package/dist/esm/start-routes-manifest-plugin/plugin.js.map +1 -1
- package/package.json +3 -3
- package/src/plugin.ts +1 -1
- package/src/start-routes-manifest-plugin/plugin.ts +1 -1
package/dist/cjs/plugin.cjs
CHANGED
package/dist/cjs/plugin.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs","sources":["../../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createNitro } from 'nitropack'\nimport { trimPathRight } from '@tanstack/router-core'\nimport { tanstackRouter } from '@tanstack/router-plugin/vite'\nimport { TanStackServerFnPluginEnv } from '@tanstack/server-functions-plugin'\nimport * as vite from 'vite'\nimport { createTanStackConfig } from './schema'\nimport { nitroPlugin } from './nitro-plugin/plugin'\nimport { startRoutesManifestPlugin } from './start-routes-manifest-plugin/plugin'\nimport { startCompilerPlugin } from './start-compiler-plugin'\nimport {\n CLIENT_DIST_DIR,\n SSR_ENTRY_FILE,\n VITE_ENVIRONMENT_NAMES,\n} from './constants'\nimport { TanStackStartServerRoutesVite } from './start-server-routes-plugin/plugin'\nimport { loadEnvPlugin } from './load-env-plugin/plugin'\nimport { devServerPlugin } from './dev-server-plugin/plugin'\nimport { resolveVirtualEntriesPlugin } from './resolve-virtual-entries-plugin/plugin'\nimport type { createTanStackStartOptionsSchema } from './schema'\nimport type { PluginOption, Rollup } from 'vite'\nimport type { z } from 'zod'\nimport type { CompileStartFrameworkOptions } from './compilers'\n\nexport type TanStackStartInputConfig = z.input<\n ReturnType<typeof createTanStackStartOptionsSchema>\n>\n\nconst defaultConfig = createTanStackConfig()\nexport function getTanStackStartOptions(opts?: TanStackStartInputConfig) {\n return defaultConfig.parse(opts)\n}\n\nexport type TanStackStartOutputConfig = ReturnType<\n typeof getTanStackStartOptions\n>\n\ndeclare global {\n // eslint-disable-next-line no-var\n var TSS_APP_BASE: string\n}\n\nexport interface TanStackStartVitePluginCoreOptions {\n framework: CompileStartFrameworkOptions\n getVirtualServerRootHandler: (ctx: {\n routerFilepath: string\n serverEntryFilepath: string\n }) => string\n getVirtualServerEntry: (ctx: { routerFilepath: string }) => string\n getVirtualClientEntry: (ctx: { routerFilepath: string }) => string\n}\n// this needs to live outside of the TanStackStartVitePluginCore since it will be invoked multiple times by vite\nlet ssrBundle: Rollup.OutputBundle\n\nexport function TanStackStartVitePluginCore(\n opts: TanStackStartVitePluginCoreOptions,\n startConfig: TanStackStartOutputConfig,\n): Array<PluginOption> {\n return [\n tanstackRouter({\n verboseFileRoutes: false,\n ...startConfig.tsr,\n target: opts.framework,\n enableRouteGeneration: true,\n autoCodeSplitting: true,\n }),\n resolveVirtualEntriesPlugin(opts, startConfig),\n {\n name: 'tanstack-start-core:config-client',\n async config(viteConfig) {\n const viteAppBase = trimPathRight(viteConfig.base || '/')\n globalThis.TSS_APP_BASE = viteAppBase\n\n const nitroOutputPublicDir = await (async () => {\n // Create a dummy nitro app to get the resolved public output path\n const dummyNitroApp = await createNitro({\n preset: startConfig.target,\n compatibilityDate: '2024-12-01',\n })\n\n const nitroOutputPublicDir = dummyNitroApp.options.output.publicDir\n await dummyNitroApp.close()\n\n return nitroOutputPublicDir\n })()\n\n const getClientEntryPath = (startConfig: TanStackStartOutputConfig) => {\n // when the user specifies a custom client entry path, we need to resolve it\n // relative to the root of the project, keeping in mind that if not specified\n // it will be /~start/default-client-entry which is a virtual path\n // that is resolved by vite to the actual client entry path\n const entry = startConfig.clientEntryPath.startsWith(\n '/~start/default-client-entry',\n )\n ? startConfig.clientEntryPath\n : vite.normalizePath(\n path.join(\n '/@fs',\n path.resolve(startConfig.root, startConfig.clientEntryPath),\n ),\n )\n\n return entry\n }\n\n return {\n base: viteAppBase,\n environments: {\n [VITE_ENVIRONMENT_NAMES.client]: {\n consumer: 'client',\n build: {\n manifest: true,\n rollupOptions: {\n input: {\n main: getClientEntryPath(startConfig),\n },\n output: {\n dir: path.resolve(startConfig.root, CLIENT_DIST_DIR),\n },\n // TODO: this should be removed\n external: ['node:fs', 'node:path', 'node:os', 'node:crypto'],\n },\n },\n },\n [VITE_ENVIRONMENT_NAMES.server]: {\n consumer: 'server',\n build: {\n ssr: true,\n // we don't write to the file system as the below 'capture-output' plugin will\n // capture the output and write it to the virtual file system\n write: false,\n copyPublicDir: false,\n rollupOptions: {\n output: {\n entryFileNames: SSR_ENTRY_FILE,\n },\n plugins: [\n {\n name: 'capture-output',\n generateBundle(_options, bundle) {\n // TODO: can this hook be called more than once?\n ssrBundle = bundle\n },\n },\n ],\n },\n commonjsOptions: {\n include: [/node_modules/],\n },\n },\n },\n },\n resolve: {\n noExternal: [\n '@tanstack/start-client',\n '@tanstack/start-client-core',\n '@tanstack/start-server',\n '@tanstack/start-server-core',\n '@tanstack/start-server-functions-fetcher',\n '@tanstack/start-server-functions-client',\n '@tanstack/start-server-functions-server',\n '@tanstack/start-router-manifest',\n '@tanstack/start-config',\n '@tanstack/server-functions-plugin',\n 'tanstack-start-router-manifest:v',\n 'tanstack-start-server-fn-manifest:v',\n 'nitropack',\n '@tanstack/**',\n ],\n },\n optimizeDeps: {\n exclude: [\n 'tanstack-start-server-fn-manifest:v',\n 'tanstack-start-router-manifest:v',\n 'tanstack-start-server-routes-manifest:v',\n ],\n },\n /* prettier-ignore */\n define: {\n // define is an esbuild function that replaces the any instances of given keys with the given values\n // i.e: __FRAMEWORK_NAME__ can be replaced with JSON.stringify(\"TanStack Start\")\n // This is not the same as injecting environment variables.\n\n ...defineReplaceEnv('TSS_CLIENT_ENTRY', getClientEntryPath(startConfig)), // This is consumed by the router-manifest, where the entry point is imported after the dev refresh runtime is resolved\n ...defineReplaceEnv('TSS_SERVER_FN_BASE', startConfig.serverFns.base),\n ...defineReplaceEnv('TSS_OUTPUT_PUBLIC_DIR', nitroOutputPublicDir),\n ...defineReplaceEnv('TSS_APP_BASE', viteAppBase)\n },\n }\n },\n },\n // N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv\n startCompilerPlugin(opts.framework, {\n client: { envName: VITE_ENVIRONMENT_NAMES.client },\n server: { envName: VITE_ENVIRONMENT_NAMES.server },\n }),\n TanStackServerFnPluginEnv({\n // This is the ID that will be available to look up and import\n // our server function manifest and resolve its module\n manifestVirtualImportId: 'tanstack-start-server-fn-manifest:v',\n manifestOutputFilename:\n '.tanstack-start/build/server/server-functions-manifest.json',\n client: {\n getRuntimeCode: () =>\n `import { createClientRpc } from '@tanstack/${opts.framework}-start/server-functions-client'`,\n replacer: (d) =>\n `createClientRpc('${d.functionId}', '${startConfig.serverFns.base}')`,\n envName: VITE_ENVIRONMENT_NAMES.client,\n },\n server: {\n getRuntimeCode: () =>\n `import { createServerRpc } from '@tanstack/${opts.framework}-start/server-functions-server'`,\n replacer: (d) =>\n `createServerRpc('${d.functionId}', '${startConfig.serverFns.base}', ${d.fn})`,\n envName: VITE_ENVIRONMENT_NAMES.server,\n },\n importer: (fn) => {\n const serverEnv = (globalThis as any).viteDevServer.environments[\n VITE_ENVIRONMENT_NAMES.server\n ]\n if (!serverEnv) {\n throw new Error(`'ssr' vite dev environment not found`)\n }\n return serverEnv.runner.import(fn.extractedFilename)\n },\n }),\n loadEnvPlugin(startConfig),\n startRoutesManifestPlugin(startConfig),\n devServerPlugin(),\n nitroPlugin(startConfig, () => ssrBundle),\n TanStackStartServerRoutesVite({\n ...startConfig.tsr,\n target: opts.framework,\n }),\n ]\n}\n\nfunction defineReplaceEnv<TKey extends string, TValue extends string>(\n key: TKey,\n value: TValue,\n): { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue } {\n return {\n [`process.env.${key}`]: JSON.stringify(value),\n [`import.meta.env.${key}`]: JSON.stringify(value),\n } as { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue }\n}\n"],"names":["createTanStackConfig","tanstackRouter","resolveVirtualEntriesPlugin","trimPathRight","createNitro","nitroOutputPublicDir","startConfig","vite","VITE_ENVIRONMENT_NAMES","CLIENT_DIST_DIR","SSR_ENTRY_FILE","startCompilerPlugin","TanStackServerFnPluginEnv","loadEnvPlugin","startRoutesManifestPlugin","devServerPlugin","nitroPlugin","TanStackStartServerRoutesVite"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BsBA,OAAqB,qBAAA;AAwB3C,IAAI;AAEY,SAAA,4BACd,MACA,aACqB;AACd,SAAA;AAAA,IACLC,oBAAe;AAAA,MACb,mBAAmB;AAAA,MACnB,GAAG,YAAY;AAAA,MACf,QAAQ,KAAK;AAAA,MACb,uBAAuB;AAAA,MACvB,mBAAmB;AAAA,IAAA,CACpB;AAAA,IACDC,OAAA,4BAA4B,MAAM,WAAW;AAAA,IAC7C;AAAA,MACE,MAAM;AAAA,MACN,MAAM,OAAO,YAAY;AACvB,cAAM,cAAcC,WAAA,cAAc,WAAW,QAAQ,GAAG;AACxD,mBAAW,eAAe;AAEpB,cAAA,uBAAuB,OAAO,YAAY;AAExC,gBAAA,gBAAgB,MAAMC,sBAAY;AAAA,YACtC,QAAQ,YAAY;AAAA,YACpB,mBAAmB;AAAA,UAAA,CACpB;AAEKC,gBAAAA,wBAAuB,cAAc,QAAQ,OAAO;AAC1D,gBAAM,cAAc,MAAM;AAEnBA,iBAAAA;AAAAA,QAAAA,GACN;AAEG,cAAA,qBAAqB,CAACC,iBAA2C;AAK/D,gBAAA,QAAQA,aAAY,gBAAgB;AAAA,YACxC;AAAA,UAAA,IAEEA,aAAY,kBACZC,gBAAK;AAAA,YAC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IACDK,SAAAA,cAAc,WAAW;AAAA,IACzBC,SAAAA,0BAA0B,WAAW;AAAA,IACrCC,yBAAgB;AAAA,IAChBC,qBAAY,aAAa,MAAM,SAAS;AAAA,IACxCC,uCAA8B;AAAA,MAC5B,GAAG,YAAY;AAAA,MACf,QAAQ,KAAK;AAAA,IACd,CAAA;AAAA,EACH;AACF;AAEA,SAAS,iBACP,KACA,OACsE;AAC/D,SAAA;AAAA,IACL,CAAC,eAAe,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,IAC5C,CAAC,mBAAmB,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,EAClD;AACF;;"}
|
|
1
|
+
{"version":3,"file":"plugin.cjs","sources":["../../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createNitro } from 'nitropack'\nimport { trimPathRight } from '@tanstack/router-core'\nimport { tanstackRouter } from '@tanstack/router-plugin/vite'\nimport { TanStackServerFnPluginEnv } from '@tanstack/server-functions-plugin'\nimport * as vite from 'vite'\nimport { createTanStackConfig } from './schema'\nimport { nitroPlugin } from './nitro-plugin/plugin'\nimport { startRoutesManifestPlugin } from './start-routes-manifest-plugin/plugin'\nimport { startCompilerPlugin } from './start-compiler-plugin'\nimport {\n CLIENT_DIST_DIR,\n SSR_ENTRY_FILE,\n VITE_ENVIRONMENT_NAMES,\n} from './constants'\nimport { TanStackStartServerRoutesVite } from './start-server-routes-plugin/plugin'\nimport { loadEnvPlugin } from './load-env-plugin/plugin'\nimport { devServerPlugin } from './dev-server-plugin/plugin'\nimport { resolveVirtualEntriesPlugin } from './resolve-virtual-entries-plugin/plugin'\nimport type { createTanStackStartOptionsSchema } from './schema'\nimport type { PluginOption, Rollup } from 'vite'\nimport type { z } from 'zod'\nimport type { CompileStartFrameworkOptions } from './compilers'\n\nexport type TanStackStartInputConfig = z.input<\n ReturnType<typeof createTanStackStartOptionsSchema>\n>\n\nconst defaultConfig = createTanStackConfig()\nexport function getTanStackStartOptions(opts?: TanStackStartInputConfig) {\n return defaultConfig.parse(opts)\n}\n\nexport type TanStackStartOutputConfig = ReturnType<\n typeof getTanStackStartOptions\n>\n\ndeclare global {\n // eslint-disable-next-line no-var\n var TSS_APP_BASE: string\n}\n\nexport interface TanStackStartVitePluginCoreOptions {\n framework: CompileStartFrameworkOptions\n getVirtualServerRootHandler: (ctx: {\n routerFilepath: string\n serverEntryFilepath: string\n }) => string\n getVirtualServerEntry: (ctx: { routerFilepath: string }) => string\n getVirtualClientEntry: (ctx: { routerFilepath: string }) => string\n}\n// this needs to live outside of the TanStackStartVitePluginCore since it will be invoked multiple times by vite\nlet ssrBundle: Rollup.OutputBundle\n\nexport function TanStackStartVitePluginCore(\n opts: TanStackStartVitePluginCoreOptions,\n startConfig: TanStackStartOutputConfig,\n): Array<PluginOption> {\n return [\n tanstackRouter({\n verboseFileRoutes: false,\n ...startConfig.tsr,\n target: opts.framework,\n enableRouteGeneration: true,\n autoCodeSplitting: true,\n }),\n resolveVirtualEntriesPlugin(opts, startConfig),\n {\n name: 'tanstack-start-core:config-client',\n async config(viteConfig) {\n const viteAppBase = trimPathRight(viteConfig.base || '/')\n globalThis.TSS_APP_BASE = viteAppBase\n\n const nitroOutputPublicDir = await (async () => {\n // Create a dummy nitro app to get the resolved public output path\n const dummyNitroApp = await createNitro({\n preset: startConfig.target,\n compatibilityDate: '2024-12-01',\n })\n\n const nitroOutputPublicDir = dummyNitroApp.options.output.publicDir\n await dummyNitroApp.close()\n\n return nitroOutputPublicDir\n })()\n\n const getClientEntryPath = (startConfig: TanStackStartOutputConfig) => {\n // when the user specifies a custom client entry path, we need to resolve it\n // relative to the root of the project, keeping in mind that if not specified\n // it will be /~start/default-client-entry which is a virtual path\n // that is resolved by vite to the actual client entry path\n const entry = startConfig.clientEntryPath.startsWith(\n '/~start/default-client-entry',\n )\n ? startConfig.clientEntryPath\n : vite.normalizePath(\n path.join(\n '/@fs',\n path.resolve(startConfig.root, startConfig.clientEntryPath),\n ),\n )\n\n return entry\n }\n\n return {\n base: viteAppBase,\n environments: {\n [VITE_ENVIRONMENT_NAMES.client]: {\n consumer: 'client',\n build: {\n manifest: true,\n rollupOptions: {\n input: {\n main: getClientEntryPath(startConfig),\n },\n output: {\n dir: path.resolve(startConfig.root, CLIENT_DIST_DIR),\n },\n // TODO: this should be removed\n external: ['node:fs', 'node:path', 'node:os', 'node:crypto'],\n },\n },\n },\n [VITE_ENVIRONMENT_NAMES.server]: {\n consumer: 'server',\n build: {\n ssr: true,\n // we don't write to the file system as the below 'capture-output' plugin will\n // capture the output and write it to the virtual file system\n write: false,\n copyPublicDir: false,\n rollupOptions: {\n output: {\n entryFileNames: SSR_ENTRY_FILE,\n },\n plugins: [\n {\n name: 'capture-output',\n generateBundle(_options, bundle) {\n // TODO: can this hook be called more than once?\n ssrBundle = bundle\n },\n },\n ],\n },\n commonjsOptions: {\n include: [/node_modules/],\n },\n },\n },\n },\n resolve: {\n noExternal: [\n '@tanstack/start-client',\n '@tanstack/start-client-core',\n '@tanstack/start-server',\n '@tanstack/start-server-core',\n '@tanstack/start-server-functions-fetcher',\n '@tanstack/start-server-functions-client',\n '@tanstack/start-server-functions-server',\n '@tanstack/start-router-manifest',\n '@tanstack/start-config',\n '@tanstack/server-functions-plugin',\n 'tanstack-start-router-manifest:v',\n 'tanstack-start-server-fn-manifest:v',\n 'nitropack',\n '@tanstack/**start**',\n ],\n },\n optimizeDeps: {\n exclude: [\n 'tanstack-start-server-fn-manifest:v',\n 'tanstack-start-router-manifest:v',\n 'tanstack-start-server-routes-manifest:v',\n ],\n },\n /* prettier-ignore */\n define: {\n // define is an esbuild function that replaces the any instances of given keys with the given values\n // i.e: __FRAMEWORK_NAME__ can be replaced with JSON.stringify(\"TanStack Start\")\n // This is not the same as injecting environment variables.\n\n ...defineReplaceEnv('TSS_CLIENT_ENTRY', getClientEntryPath(startConfig)), // This is consumed by the router-manifest, where the entry point is imported after the dev refresh runtime is resolved\n ...defineReplaceEnv('TSS_SERVER_FN_BASE', startConfig.serverFns.base),\n ...defineReplaceEnv('TSS_OUTPUT_PUBLIC_DIR', nitroOutputPublicDir),\n ...defineReplaceEnv('TSS_APP_BASE', viteAppBase)\n },\n }\n },\n },\n // N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv\n startCompilerPlugin(opts.framework, {\n client: { envName: VITE_ENVIRONMENT_NAMES.client },\n server: { envName: VITE_ENVIRONMENT_NAMES.server },\n }),\n TanStackServerFnPluginEnv({\n // This is the ID that will be available to look up and import\n // our server function manifest and resolve its module\n manifestVirtualImportId: 'tanstack-start-server-fn-manifest:v',\n manifestOutputFilename:\n '.tanstack-start/build/server/server-functions-manifest.json',\n client: {\n getRuntimeCode: () =>\n `import { createClientRpc } from '@tanstack/${opts.framework}-start/server-functions-client'`,\n replacer: (d) =>\n `createClientRpc('${d.functionId}', '${startConfig.serverFns.base}')`,\n envName: VITE_ENVIRONMENT_NAMES.client,\n },\n server: {\n getRuntimeCode: () =>\n `import { createServerRpc } from '@tanstack/${opts.framework}-start/server-functions-server'`,\n replacer: (d) =>\n `createServerRpc('${d.functionId}', '${startConfig.serverFns.base}', ${d.fn})`,\n envName: VITE_ENVIRONMENT_NAMES.server,\n },\n importer: (fn) => {\n const serverEnv = (globalThis as any).viteDevServer.environments[\n VITE_ENVIRONMENT_NAMES.server\n ]\n if (!serverEnv) {\n throw new Error(`'ssr' vite dev environment not found`)\n }\n return serverEnv.runner.import(fn.extractedFilename)\n },\n }),\n loadEnvPlugin(startConfig),\n startRoutesManifestPlugin(startConfig),\n devServerPlugin(),\n nitroPlugin(startConfig, () => ssrBundle),\n TanStackStartServerRoutesVite({\n ...startConfig.tsr,\n target: opts.framework,\n }),\n ]\n}\n\nfunction defineReplaceEnv<TKey extends string, TValue extends string>(\n key: TKey,\n value: TValue,\n): { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue } {\n return {\n [`process.env.${key}`]: JSON.stringify(value),\n [`import.meta.env.${key}`]: JSON.stringify(value),\n } as { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue }\n}\n"],"names":["createTanStackConfig","tanstackRouter","resolveVirtualEntriesPlugin","trimPathRight","createNitro","nitroOutputPublicDir","startConfig","vite","VITE_ENVIRONMENT_NAMES","CLIENT_DIST_DIR","SSR_ENTRY_FILE","startCompilerPlugin","TanStackServerFnPluginEnv","loadEnvPlugin","startRoutesManifestPlugin","devServerPlugin","nitroPlugin","TanStackStartServerRoutesVite"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BsBA,OAAqB,qBAAA;AAwB3C,IAAI;AAEY,SAAA,4BACd,MACA,aACqB;AACd,SAAA;AAAA,IACLC,oBAAe;AAAA,MACb,mBAAmB;AAAA,MACnB,GAAG,YAAY;AAAA,MACf,QAAQ,KAAK;AAAA,MACb,uBAAuB;AAAA,MACvB,mBAAmB;AAAA,IAAA,CACpB;AAAA,IACDC,OAAA,4BAA4B,MAAM,WAAW;AAAA,IAC7C;AAAA,MACE,MAAM;AAAA,MACN,MAAM,OAAO,YAAY;AACvB,cAAM,cAAcC,WAAA,cAAc,WAAW,QAAQ,GAAG;AACxD,mBAAW,eAAe;AAEpB,cAAA,uBAAuB,OAAO,YAAY;AAExC,gBAAA,gBAAgB,MAAMC,sBAAY;AAAA,YACtC,QAAQ,YAAY;AAAA,YACpB,mBAAmB;AAAA,UAAA,CACpB;AAEKC,gBAAAA,wBAAuB,cAAc,QAAQ,OAAO;AAC1D,gBAAM,cAAc,MAAM;AAEnBA,iBAAAA;AAAAA,QAAAA,GACN;AAEG,cAAA,qBAAqB,CAACC,iBAA2C;AAK/D,gBAAA,QAAQA,aAAY,gBAAgB;AAAA,YACxC;AAAA,UAAA,IAEEA,aAAY,kBACZC,gBAAK;AAAA,YACH,KAAK;AAAA,cACH;AAAA,cACA,KAAK,QAAQD,aAAY,MAAMA,aAAY,eAAe;AAAA,YAAA;AAAA,UAE9D;AAEG,iBAAA;AAAA,QACT;AAEO,eAAA;AAAA,UACL,MAAM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A,MAC5B,GAAG,YAAY;AAAA,MACf,QAAQ,KAAK;AAAA,IACd,CAAA;AAAA,EACH;AACF;AAEA,SAAS,iBACP,KACA,OACsE;AAC/D,SAAA;AAAA,IACL,CAAC,eAAe,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,IAC5C,CAAC,mBAAmB,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,EAClD;AACF;;"}
|
|
@@ -104,7 +104,7 @@ function startRoutesManifestPlugin(opts) {
|
|
|
104
104
|
opts.tsr.routesDirectory
|
|
105
105
|
);
|
|
106
106
|
Object.entries(routeTreeRoutes).forEach(([routeId, v]) => {
|
|
107
|
-
const file = filesByRouteFilePath[path.join(routesDirectoryFromRoot, v.filePath)];
|
|
107
|
+
const file = filesByRouteFilePath[path.posix.join(routesDirectoryFromRoot, v.filePath)];
|
|
108
108
|
if (file) {
|
|
109
109
|
const preloads = (file.imports ?? []).map((d) => {
|
|
110
110
|
const assetPath = ufo.joinURL(APP_BASE, viteManifest[d].file);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs","sources":["../../../src/start-routes-manifest-plugin/plugin.ts"],"sourcesContent":["import { mkdirSync, readFileSync, rmSync, writeFile } from 'node:fs'\nimport path from 'node:path'\nimport { joinURL } from 'ufo'\nimport { rootRouteId } from '@tanstack/router-core'\nimport { resolveViteId } from '../utils'\nimport type {\n PluginOption,\n ResolvedConfig,\n Manifest as ViteManifest,\n ManifestChunk as ViteManifestChunk,\n} from 'vite'\nimport type { Manifest, RouterManagedTag } from '@tanstack/router-core'\nimport type { TanStackStartOutputConfig } from '../plugin'\n\nconst getCSSRecursively = (\n file: ViteManifestChunk,\n filesByRouteFilePath: ViteManifest,\n basePath: string,\n) => {\n const result: Array<RouterManagedTag> = []\n\n // Get all css imports from the file\n for (const cssFile of file.css ?? []) {\n result.push({\n tag: 'link',\n attrs: {\n rel: 'stylesheet',\n href: joinURL(basePath, cssFile),\n type: 'text/css',\n },\n })\n }\n\n // Recursively get CSS from imports\n for (const imp of file.imports ?? []) {\n const importInfo = filesByRouteFilePath[imp]\n if (importInfo) {\n result.push(\n ...getCSSRecursively(importInfo, filesByRouteFilePath, basePath),\n )\n }\n }\n\n return result\n}\n\nexport function startRoutesManifestPlugin(\n opts: TanStackStartOutputConfig,\n): PluginOption {\n let config: ResolvedConfig\n\n const moduleId = 'tanstack-start-router-manifest:v'\n const resolvedModuleId = resolveViteId(moduleId)\n\n return {\n name: 'tsr-routes-manifest',\n enforce: 'pre',\n\n configResolved(resolvedConfig) {\n config = resolvedConfig\n },\n // configEnvironment(env, envConfig) {\n // config = envConfig.\n // },\n resolveId(id) {\n if (id === moduleId) {\n return resolvedModuleId\n }\n return\n },\n load(id) {\n if (id === resolvedModuleId) {\n if (this.environment.config.consumer !== 'server') {\n // this will ultimately fail the build if the plugin is used outside the server environment\n // TODO: do we need special handling for `serve`?\n return `export default {}`\n }\n\n // If we're in development, return a dummy manifest\n if (config.command === 'serve') {\n return `export const tsrStartManifest = () => ({\n routes: {}\n })`\n }\n\n // This is the basepath for the application\n const APP_BASE = globalThis.TSS_APP_BASE\n\n const clientViteManifestPath = path.resolve(\n opts.root,\n '.tanstack-start/build/client-dist/.vite/manifest.json',\n )\n\n let viteManifest: ViteManifest\n try {\n viteManifest = JSON.parse(\n readFileSync(clientViteManifestPath, 'utf-8'),\n )\n } catch (err) {\n console.error(err)\n throw new Error(\n `Could not find the production client vite manifest at '${clientViteManifestPath}'!`,\n )\n }\n\n const routeTreePath = path.resolve(opts.tsr.generatedRouteTree)\n\n let routeTreeContent: string\n try {\n routeTreeContent = readFileSync(routeTreePath, 'utf-8')\n } catch (err) {\n console.error(err)\n throw new Error(\n `Could not find the generated route tree at '${routeTreePath}'!`,\n )\n }\n\n // Extract the routesManifest JSON from the route tree file.\n // It's located between the /* ROUTE_MANIFEST_START and ROUTE_MANIFEST_END */ comment block.\n\n const routerManifest = JSON.parse(\n routeTreeContent.match(\n /\\/\\* ROUTE_MANIFEST_START([\\s\\S]*?)ROUTE_MANIFEST_END \\*\\//,\n )?.[1] || '{ routes: {} }',\n ) as Manifest\n\n // This the manifest pulled from the generated route tree and later used by the Router.\n // i.e what's located in `src/generatedRouteTree.gen.ts`\n const routeTreeRoutes = routerManifest.routes\n\n // This is where hydration will start, from when the SSR'd page reaches the browser.\n // By default, this'd be the virtual entry of `/~start/default-client-entry.tsx`, unless a custom entry is provided.\n let entryFile: ViteManifestChunk | undefined\n\n const filesByRouteFilePath: ViteManifest = Object.fromEntries(\n Object.entries(viteManifest).map(([k, v]) => {\n if (v.isEntry) {\n entryFile = v\n }\n\n const rPath = k.split('?')[0]\n\n return [rPath, v]\n }, {}),\n )\n\n const routesDirectoryFromRoot = path.relative(\n opts.root,\n opts.tsr.routesDirectory,\n )\n\n // Add preloads to the routes from the vite manifest\n Object.entries(routeTreeRoutes).forEach(([routeId, v]) => {\n const file =\n filesByRouteFilePath[\n path.join(routesDirectoryFromRoot, v.filePath as string)\n ]\n\n if (file) {\n // Map the relevant imports to their route paths,\n // so that it can be imported in the browser.\n const preloads = (file.imports ?? []).map((d) => {\n const assetPath = joinURL(APP_BASE, viteManifest[d]!.file)\n return assetPath\n })\n\n // Since this is the most important JS entry for the route,\n // it should be moved to the front of the preloads so that\n // it has the best chance of being loaded first.\n if (file.file) {\n preloads.unshift(path.join(APP_BASE, file.file))\n }\n\n const cssAssetsList = getCSSRecursively(\n file,\n filesByRouteFilePath,\n APP_BASE,\n )\n\n routeTreeRoutes[routeId] = {\n ...v,\n assets: [...(v.assets || []), ...cssAssetsList],\n preloads,\n }\n }\n })\n\n if (entryFile) {\n routeTreeRoutes[rootRouteId]!.preloads = [\n joinURL(APP_BASE, entryFile.file),\n ...(entryFile.imports?.map((d) =>\n joinURL(APP_BASE, viteManifest[d]!.file),\n ) || []),\n ]\n\n // Gather all the CSS files from the entry file in\n // the `css` key and add them to the root route\n const entryCssAssetsList = getCSSRecursively(\n entryFile,\n filesByRouteFilePath,\n APP_BASE,\n )\n\n routeTreeRoutes[rootRouteId]!.assets = [\n ...(routeTreeRoutes[rootRouteId]!.assets || []),\n ...entryCssAssetsList,\n {\n tag: 'script',\n attrs: {\n src: joinURL(APP_BASE, entryFile.file),\n type: 'module',\n },\n },\n ]\n }\n\n const recurseRoute = (\n route: {\n preloads?: Array<string>\n children?: Array<any>\n },\n seenPreloads = {} as Record<string, true>,\n ) => {\n route.preloads = route.preloads?.filter((preload) => {\n if (seenPreloads[preload]) {\n return false\n }\n seenPreloads[preload] = true\n return true\n })\n\n if (route.children) {\n route.children.forEach((child) => {\n const childRoute = routeTreeRoutes[child]!\n recurseRoute(childRoute, { ...seenPreloads })\n })\n }\n }\n\n // @ts-expect-error\n recurseRoute(routeTreeRoutes[rootRouteId])\n\n const routesManifest = {\n routes: routeTreeRoutes,\n }\n\n try {\n const routesManifestOutputDirPath = path.resolve(\n opts.root,\n '.tanstack-start/build/route-assets-manifest',\n )\n rmSync(routesManifestOutputDirPath, {\n recursive: true,\n force: true,\n })\n mkdirSync(routesManifestOutputDirPath, { recursive: true })\n writeFile(\n path.join(routesManifestOutputDirPath, 'manifest.json'),\n JSON.stringify(routesManifest),\n (err) => {\n if (err) {\n console.error(\n 'There was an error writing the routes manifest to disk.\\nYou can ignore this error. It does not affect the runtime of your application.',\n )\n console.error(err)\n }\n },\n )\n } catch (err) {\n console.error(\n 'There was an error writing the routes manifest to disk.\\nYou can ignore this error. It does not affect the runtime of your application.',\n )\n console.error(err)\n }\n\n return `export const tsrStartManifest = () => (${JSON.stringify(routesManifest)})`\n }\n\n return undefined\n },\n }\n}\n"],"names":["joinURL","resolveViteId","readFileSync","rootRouteId","_a","rmSync","mkdirSync","writeFile"],"mappings":";;;;;;;AAcA,MAAM,oBAAoB,CACxB,MACA,sBACA,aACG;AACH,QAAM,SAAkC,CAAC;AAGzC,aAAW,WAAW,KAAK,OAAO,CAAA,GAAI;AACpC,WAAO,KAAK;AAAA,MACV,KAAK;AAAA,MACL,OAAO;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ACDC,aAAAA,UAAU,6BAA6B,EAAE,WAAW,KAAA,CAAM;AAC1DC,aAAA;AAAA,YACE,KAAK,KAAK,6BAA6B,eAAe;AAAA,YACtD,KAAK,UAAU,cAAc;AAAA,YAC7B,CAAC,QAAQ;AACP,kBAAI,KAAK;AACC,wBAAA;AAAA,kBACN;AAAA,gBACF;AACA,wBAAQ,MAAM,GAAG;AAAA,cAAA;AAAA,YACnB;AAAA,UAEJ;AAAA,iBACO,KAAK;AACJ,kBAAA;AAAA,YACN;AAAA,UACF;AACA,kBAAQ,MAAM,GAAG;AAAA,QAAA;AAGnB,eAAO,0CAA0C,KAAK,UAAU,cAAc,CAAC;AAAA,MAAA;AAG1E,aAAA;AAAA,IAAA;AAAA,EAEX;AACF;;"}
|
|
1
|
+
{"version":3,"file":"plugin.cjs","sources":["../../../src/start-routes-manifest-plugin/plugin.ts"],"sourcesContent":["import { mkdirSync, readFileSync, rmSync, writeFile } from 'node:fs'\nimport path from 'node:path'\nimport { joinURL } from 'ufo'\nimport { rootRouteId } from '@tanstack/router-core'\nimport { resolveViteId } from '../utils'\nimport type {\n PluginOption,\n ResolvedConfig,\n Manifest as ViteManifest,\n ManifestChunk as ViteManifestChunk,\n} from 'vite'\nimport type { Manifest, RouterManagedTag } from '@tanstack/router-core'\nimport type { TanStackStartOutputConfig } from '../plugin'\n\nconst getCSSRecursively = (\n file: ViteManifestChunk,\n filesByRouteFilePath: ViteManifest,\n basePath: string,\n) => {\n const result: Array<RouterManagedTag> = []\n\n // Get all css imports from the file\n for (const cssFile of file.css ?? []) {\n result.push({\n tag: 'link',\n attrs: {\n rel: 'stylesheet',\n href: joinURL(basePath, cssFile),\n type: 'text/css',\n },\n })\n }\n\n // Recursively get CSS from imports\n for (const imp of file.imports ?? []) {\n const importInfo = filesByRouteFilePath[imp]\n if (importInfo) {\n result.push(\n ...getCSSRecursively(importInfo, filesByRouteFilePath, basePath),\n )\n }\n }\n\n return result\n}\n\nexport function startRoutesManifestPlugin(\n opts: TanStackStartOutputConfig,\n): PluginOption {\n let config: ResolvedConfig\n\n const moduleId = 'tanstack-start-router-manifest:v'\n const resolvedModuleId = resolveViteId(moduleId)\n\n return {\n name: 'tsr-routes-manifest',\n enforce: 'pre',\n\n configResolved(resolvedConfig) {\n config = resolvedConfig\n },\n // configEnvironment(env, envConfig) {\n // config = envConfig.\n // },\n resolveId(id) {\n if (id === moduleId) {\n return resolvedModuleId\n }\n return\n },\n load(id) {\n if (id === resolvedModuleId) {\n if (this.environment.config.consumer !== 'server') {\n // this will ultimately fail the build if the plugin is used outside the server environment\n // TODO: do we need special handling for `serve`?\n return `export default {}`\n }\n\n // If we're in development, return a dummy manifest\n if (config.command === 'serve') {\n return `export const tsrStartManifest = () => ({\n routes: {}\n })`\n }\n\n // This is the basepath for the application\n const APP_BASE = globalThis.TSS_APP_BASE\n\n const clientViteManifestPath = path.resolve(\n opts.root,\n '.tanstack-start/build/client-dist/.vite/manifest.json',\n )\n\n let viteManifest: ViteManifest\n try {\n viteManifest = JSON.parse(\n readFileSync(clientViteManifestPath, 'utf-8'),\n )\n } catch (err) {\n console.error(err)\n throw new Error(\n `Could not find the production client vite manifest at '${clientViteManifestPath}'!`,\n )\n }\n\n const routeTreePath = path.resolve(opts.tsr.generatedRouteTree)\n\n let routeTreeContent: string\n try {\n routeTreeContent = readFileSync(routeTreePath, 'utf-8')\n } catch (err) {\n console.error(err)\n throw new Error(\n `Could not find the generated route tree at '${routeTreePath}'!`,\n )\n }\n\n // Extract the routesManifest JSON from the route tree file.\n // It's located between the /* ROUTE_MANIFEST_START and ROUTE_MANIFEST_END */ comment block.\n\n const routerManifest = JSON.parse(\n routeTreeContent.match(\n /\\/\\* ROUTE_MANIFEST_START([\\s\\S]*?)ROUTE_MANIFEST_END \\*\\//,\n )?.[1] || '{ routes: {} }',\n ) as Manifest\n\n // This the manifest pulled from the generated route tree and later used by the Router.\n // i.e what's located in `src/generatedRouteTree.gen.ts`\n const routeTreeRoutes = routerManifest.routes\n\n // This is where hydration will start, from when the SSR'd page reaches the browser.\n // By default, this'd be the virtual entry of `/~start/default-client-entry.tsx`, unless a custom entry is provided.\n let entryFile: ViteManifestChunk | undefined\n\n const filesByRouteFilePath: ViteManifest = Object.fromEntries(\n Object.entries(viteManifest).map(([k, v]) => {\n if (v.isEntry) {\n entryFile = v\n }\n\n const rPath = k.split('?')[0]\n\n return [rPath, v]\n }, {}),\n )\n\n const routesDirectoryFromRoot = path.relative(\n opts.root,\n opts.tsr.routesDirectory,\n )\n\n // Add preloads to the routes from the vite manifest\n Object.entries(routeTreeRoutes).forEach(([routeId, v]) => {\n const file =\n filesByRouteFilePath[\n path.posix.join(routesDirectoryFromRoot, v.filePath as string)\n ]\n\n if (file) {\n // Map the relevant imports to their route paths,\n // so that it can be imported in the browser.\n const preloads = (file.imports ?? []).map((d) => {\n const assetPath = joinURL(APP_BASE, viteManifest[d]!.file)\n return assetPath\n })\n\n // Since this is the most important JS entry for the route,\n // it should be moved to the front of the preloads so that\n // it has the best chance of being loaded first.\n if (file.file) {\n preloads.unshift(path.join(APP_BASE, file.file))\n }\n\n const cssAssetsList = getCSSRecursively(\n file,\n filesByRouteFilePath,\n APP_BASE,\n )\n\n routeTreeRoutes[routeId] = {\n ...v,\n assets: [...(v.assets || []), ...cssAssetsList],\n preloads,\n }\n }\n })\n\n if (entryFile) {\n routeTreeRoutes[rootRouteId]!.preloads = [\n joinURL(APP_BASE, entryFile.file),\n ...(entryFile.imports?.map((d) =>\n joinURL(APP_BASE, viteManifest[d]!.file),\n ) || []),\n ]\n\n // Gather all the CSS files from the entry file in\n // the `css` key and add them to the root route\n const entryCssAssetsList = getCSSRecursively(\n entryFile,\n filesByRouteFilePath,\n APP_BASE,\n )\n\n routeTreeRoutes[rootRouteId]!.assets = [\n ...(routeTreeRoutes[rootRouteId]!.assets || []),\n ...entryCssAssetsList,\n {\n tag: 'script',\n attrs: {\n src: joinURL(APP_BASE, entryFile.file),\n type: 'module',\n },\n },\n ]\n }\n\n const recurseRoute = (\n route: {\n preloads?: Array<string>\n children?: Array<any>\n },\n seenPreloads = {} as Record<string, true>,\n ) => {\n route.preloads = route.preloads?.filter((preload) => {\n if (seenPreloads[preload]) {\n return false\n }\n seenPreloads[preload] = true\n return true\n })\n\n if (route.children) {\n route.children.forEach((child) => {\n const childRoute = routeTreeRoutes[child]!\n recurseRoute(childRoute, { ...seenPreloads })\n })\n }\n }\n\n // @ts-expect-error\n recurseRoute(routeTreeRoutes[rootRouteId])\n\n const routesManifest = {\n routes: routeTreeRoutes,\n }\n\n try {\n const routesManifestOutputDirPath = path.resolve(\n opts.root,\n '.tanstack-start/build/route-assets-manifest',\n )\n rmSync(routesManifestOutputDirPath, {\n recursive: true,\n force: true,\n })\n mkdirSync(routesManifestOutputDirPath, { recursive: true })\n writeFile(\n path.join(routesManifestOutputDirPath, 'manifest.json'),\n JSON.stringify(routesManifest),\n (err) => {\n if (err) {\n console.error(\n 'There was an error writing the routes manifest to disk.\\nYou can ignore this error. It does not affect the runtime of your application.',\n )\n console.error(err)\n }\n },\n )\n } catch (err) {\n console.error(\n 'There was an error writing the routes manifest to disk.\\nYou can ignore this error. It does not affect the runtime of your application.',\n )\n console.error(err)\n }\n\n return `export const tsrStartManifest = () => (${JSON.stringify(routesManifest)})`\n }\n\n return undefined\n },\n }\n}\n"],"names":["joinURL","resolveViteId","readFileSync","rootRouteId","_a","rmSync","mkdirSync","writeFile"],"mappings":";;;;;;;AAcA,MAAM,oBAAoB,CACxB,MACA,sBACA,aACG;AACH,QAAM,SAAkC,CAAC;AAGzC,aAAW,WAAW,KAAK,OAAO,CAAA,GAAI;AACpC,WAAO,KAAK;AAAA,MACV,KAAK;AAAA,MACL,OAAO;AAAA,QACL,KAAK;AAAA,QACL,MAAMA,IAAAA,QAAQ,UAAU,OAAO;AAAA,QAC/B,MAAM;AAAA,MAAA;AAAA,IACR,CACD;AAAA,EAAA;AAIH,aAAW,OAAO,KAAK,WAAW,CAAA,GAAI;AAC9B,UAAA,aAAa,qBA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ACC,wBAAA;AAAA,kBACN;AAAA,gBACF;AACA,wBAAQ,MAAM,GAAG;AAAA,cAAA;AAAA,YACnB;AAAA,UAEJ;AAAA,iBACO,KAAK;AACJ,kBAAA;AAAA,YACN;AAAA,UACF;AACA,kBAAQ,MAAM,GAAG;AAAA,QAAA;AAGnB,eAAO,0CAA0C,KAAK,UAAU,cAAc,CAAC;AAAA,MAAA;AAG1E,aAAA;AAAA,IAAA;AAAA,EAEX;AACF;;"}
|
package/dist/esm/plugin.js
CHANGED
package/dist/esm/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["../../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createNitro } from 'nitropack'\nimport { trimPathRight } from '@tanstack/router-core'\nimport { tanstackRouter } from '@tanstack/router-plugin/vite'\nimport { TanStackServerFnPluginEnv } from '@tanstack/server-functions-plugin'\nimport * as vite from 'vite'\nimport { createTanStackConfig } from './schema'\nimport { nitroPlugin } from './nitro-plugin/plugin'\nimport { startRoutesManifestPlugin } from './start-routes-manifest-plugin/plugin'\nimport { startCompilerPlugin } from './start-compiler-plugin'\nimport {\n CLIENT_DIST_DIR,\n SSR_ENTRY_FILE,\n VITE_ENVIRONMENT_NAMES,\n} from './constants'\nimport { TanStackStartServerRoutesVite } from './start-server-routes-plugin/plugin'\nimport { loadEnvPlugin } from './load-env-plugin/plugin'\nimport { devServerPlugin } from './dev-server-plugin/plugin'\nimport { resolveVirtualEntriesPlugin } from './resolve-virtual-entries-plugin/plugin'\nimport type { createTanStackStartOptionsSchema } from './schema'\nimport type { PluginOption, Rollup } from 'vite'\nimport type { z } from 'zod'\nimport type { CompileStartFrameworkOptions } from './compilers'\n\nexport type TanStackStartInputConfig = z.input<\n ReturnType<typeof createTanStackStartOptionsSchema>\n>\n\nconst defaultConfig = createTanStackConfig()\nexport function getTanStackStartOptions(opts?: TanStackStartInputConfig) {\n return defaultConfig.parse(opts)\n}\n\nexport type TanStackStartOutputConfig = ReturnType<\n typeof getTanStackStartOptions\n>\n\ndeclare global {\n // eslint-disable-next-line no-var\n var TSS_APP_BASE: string\n}\n\nexport interface TanStackStartVitePluginCoreOptions {\n framework: CompileStartFrameworkOptions\n getVirtualServerRootHandler: (ctx: {\n routerFilepath: string\n serverEntryFilepath: string\n }) => string\n getVirtualServerEntry: (ctx: { routerFilepath: string }) => string\n getVirtualClientEntry: (ctx: { routerFilepath: string }) => string\n}\n// this needs to live outside of the TanStackStartVitePluginCore since it will be invoked multiple times by vite\nlet ssrBundle: Rollup.OutputBundle\n\nexport function TanStackStartVitePluginCore(\n opts: TanStackStartVitePluginCoreOptions,\n startConfig: TanStackStartOutputConfig,\n): Array<PluginOption> {\n return [\n tanstackRouter({\n verboseFileRoutes: false,\n ...startConfig.tsr,\n target: opts.framework,\n enableRouteGeneration: true,\n autoCodeSplitting: true,\n }),\n resolveVirtualEntriesPlugin(opts, startConfig),\n {\n name: 'tanstack-start-core:config-client',\n async config(viteConfig) {\n const viteAppBase = trimPathRight(viteConfig.base || '/')\n globalThis.TSS_APP_BASE = viteAppBase\n\n const nitroOutputPublicDir = await (async () => {\n // Create a dummy nitro app to get the resolved public output path\n const dummyNitroApp = await createNitro({\n preset: startConfig.target,\n compatibilityDate: '2024-12-01',\n })\n\n const nitroOutputPublicDir = dummyNitroApp.options.output.publicDir\n await dummyNitroApp.close()\n\n return nitroOutputPublicDir\n })()\n\n const getClientEntryPath = (startConfig: TanStackStartOutputConfig) => {\n // when the user specifies a custom client entry path, we need to resolve it\n // relative to the root of the project, keeping in mind that if not specified\n // it will be /~start/default-client-entry which is a virtual path\n // that is resolved by vite to the actual client entry path\n const entry = startConfig.clientEntryPath.startsWith(\n '/~start/default-client-entry',\n )\n ? startConfig.clientEntryPath\n : vite.normalizePath(\n path.join(\n '/@fs',\n path.resolve(startConfig.root, startConfig.clientEntryPath),\n ),\n )\n\n return entry\n }\n\n return {\n base: viteAppBase,\n environments: {\n [VITE_ENVIRONMENT_NAMES.client]: {\n consumer: 'client',\n build: {\n manifest: true,\n rollupOptions: {\n input: {\n main: getClientEntryPath(startConfig),\n },\n output: {\n dir: path.resolve(startConfig.root, CLIENT_DIST_DIR),\n },\n // TODO: this should be removed\n external: ['node:fs', 'node:path', 'node:os', 'node:crypto'],\n },\n },\n },\n [VITE_ENVIRONMENT_NAMES.server]: {\n consumer: 'server',\n build: {\n ssr: true,\n // we don't write to the file system as the below 'capture-output' plugin will\n // capture the output and write it to the virtual file system\n write: false,\n copyPublicDir: false,\n rollupOptions: {\n output: {\n entryFileNames: SSR_ENTRY_FILE,\n },\n plugins: [\n {\n name: 'capture-output',\n generateBundle(_options, bundle) {\n // TODO: can this hook be called more than once?\n ssrBundle = bundle\n },\n },\n ],\n },\n commonjsOptions: {\n include: [/node_modules/],\n },\n },\n },\n },\n resolve: {\n noExternal: [\n '@tanstack/start-client',\n '@tanstack/start-client-core',\n '@tanstack/start-server',\n '@tanstack/start-server-core',\n '@tanstack/start-server-functions-fetcher',\n '@tanstack/start-server-functions-client',\n '@tanstack/start-server-functions-server',\n '@tanstack/start-router-manifest',\n '@tanstack/start-config',\n '@tanstack/server-functions-plugin',\n 'tanstack-start-router-manifest:v',\n 'tanstack-start-server-fn-manifest:v',\n 'nitropack',\n '@tanstack/**',\n ],\n },\n optimizeDeps: {\n exclude: [\n 'tanstack-start-server-fn-manifest:v',\n 'tanstack-start-router-manifest:v',\n 'tanstack-start-server-routes-manifest:v',\n ],\n },\n /* prettier-ignore */\n define: {\n // define is an esbuild function that replaces the any instances of given keys with the given values\n // i.e: __FRAMEWORK_NAME__ can be replaced with JSON.stringify(\"TanStack Start\")\n // This is not the same as injecting environment variables.\n\n ...defineReplaceEnv('TSS_CLIENT_ENTRY', getClientEntryPath(startConfig)), // This is consumed by the router-manifest, where the entry point is imported after the dev refresh runtime is resolved\n ...defineReplaceEnv('TSS_SERVER_FN_BASE', startConfig.serverFns.base),\n ...defineReplaceEnv('TSS_OUTPUT_PUBLIC_DIR', nitroOutputPublicDir),\n ...defineReplaceEnv('TSS_APP_BASE', viteAppBase)\n },\n }\n },\n },\n // N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv\n startCompilerPlugin(opts.framework, {\n client: { envName: VITE_ENVIRONMENT_NAMES.client },\n server: { envName: VITE_ENVIRONMENT_NAMES.server },\n }),\n TanStackServerFnPluginEnv({\n // This is the ID that will be available to look up and import\n // our server function manifest and resolve its module\n manifestVirtualImportId: 'tanstack-start-server-fn-manifest:v',\n manifestOutputFilename:\n '.tanstack-start/build/server/server-functions-manifest.json',\n client: {\n getRuntimeCode: () =>\n `import { createClientRpc } from '@tanstack/${opts.framework}-start/server-functions-client'`,\n replacer: (d) =>\n `createClientRpc('${d.functionId}', '${startConfig.serverFns.base}')`,\n envName: VITE_ENVIRONMENT_NAMES.client,\n },\n server: {\n getRuntimeCode: () =>\n `import { createServerRpc } from '@tanstack/${opts.framework}-start/server-functions-server'`,\n replacer: (d) =>\n `createServerRpc('${d.functionId}', '${startConfig.serverFns.base}', ${d.fn})`,\n envName: VITE_ENVIRONMENT_NAMES.server,\n },\n importer: (fn) => {\n const serverEnv = (globalThis as any).viteDevServer.environments[\n VITE_ENVIRONMENT_NAMES.server\n ]\n if (!serverEnv) {\n throw new Error(`'ssr' vite dev environment not found`)\n }\n return serverEnv.runner.import(fn.extractedFilename)\n },\n }),\n loadEnvPlugin(startConfig),\n startRoutesManifestPlugin(startConfig),\n devServerPlugin(),\n nitroPlugin(startConfig, () => ssrBundle),\n TanStackStartServerRoutesVite({\n ...startConfig.tsr,\n target: opts.framework,\n }),\n ]\n}\n\nfunction defineReplaceEnv<TKey extends string, TValue extends string>(\n key: TKey,\n value: TValue,\n): { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue } {\n return {\n [`process.env.${key}`]: JSON.stringify(value),\n [`import.meta.env.${key}`]: JSON.stringify(value),\n } as { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue }\n}\n"],"names":["nit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AuB,OAAO;AAAA,IAAA,CAClD;AAAA,IACD,0BAA0B;AAAA;AAAA;AAAA,MAGxB,yBAAyB;AAAA,MACzB,wBACE;AAAA,MACF,QAAQ;AAAA,QACN,gBAAgB,MACd,8CAA8C,KAAK,SAAS;AAAA,QAC9D,UAAU,CAAC,MACT,oBAAoB,EAAE,UAAU,OAAO,YAAY,UAAU,IAAI;AAAA,QACnE,SAAS,uBAAuB;AAAA,MAClC;AAAA,MACA,QAAQ;AAAA,QACN,gBAAgB,MACd,8CAA8C,KAAK,SAAS;AAAA,QAC9D,UAAU,CAAC,MACT,oBAAoB,EAAE,UAAU,OAAO,YAAY,UAAU,IAAI,MAAM,EAAE,EAAE;AAAA,QAC7E,SAAS,uBAAuB;AAAA,MAClC;AAAA,MACA,UAAU,CAAC,OAAO;AAChB,cAAM,YAAa,WAAmB,cAAc,aAClD,uBAAuB,MACzB;AACA,YAAI,CAAC,WAAW;AACR,gBAAA,IAAI,MAAM,sCAAsC;AAAA,QAAA;AAExD,eAAO,UAAU,OAAO,OAAO,GAAG,iBAAiB;AAAA,MAAA;AAAA,IACrD,CACD;AAAA,IACD,cAAc,WAAW;AAAA,IACzB,0BAA0B,WAAW;AAAA,IACrC,gBAAgB;AAAA,IAChB,YAAY,aAAa,MAAM,SAAS;AAAA,IACxC,8BAA8B;AAAA,MAC5B,GAAG,YAAY;AAAA,MACf,QAAQ,KAAK;AAAA,IACd,CAAA;AAAA,EACH;AACF;AAEA,SAAS,iBACP,KACA,OACsE;AAC/D,SAAA;AAAA,IACL,CAAC,eAAe,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,IAC5C,CAAC,mBAAmB,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,EAClD;AACF;"}
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["../../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createNitro } from 'nitropack'\nimport { trimPathRight } from '@tanstack/router-core'\nimport { tanstackRouter } from '@tanstack/router-plugin/vite'\nimport { TanStackServerFnPluginEnv } from '@tanstack/server-functions-plugin'\nimport * as vite from 'vite'\nimport { createTanStackConfig } from './schema'\nimport { nitroPlugin } from './nitro-plugin/plugin'\nimport { startRoutesManifestPlugin } from './start-routes-manifest-plugin/plugin'\nimport { startCompilerPlugin } from './start-compiler-plugin'\nimport {\n CLIENT_DIST_DIR,\n SSR_ENTRY_FILE,\n VITE_ENVIRONMENT_NAMES,\n} from './constants'\nimport { TanStackStartServerRoutesVite } from './start-server-routes-plugin/plugin'\nimport { loadEnvPlugin } from './load-env-plugin/plugin'\nimport { devServerPlugin } from './dev-server-plugin/plugin'\nimport { resolveVirtualEntriesPlugin } from './resolve-virtual-entries-plugin/plugin'\nimport type { createTanStackStartOptionsSchema } from './schema'\nimport type { PluginOption, Rollup } from 'vite'\nimport type { z } from 'zod'\nimport type { CompileStartFrameworkOptions } from './compilers'\n\nexport type TanStackStartInputConfig = z.input<\n ReturnType<typeof createTanStackStartOptionsSchema>\n>\n\nconst defaultConfig = createTanStackConfig()\nexport function getTanStackStartOptions(opts?: TanStackStartInputConfig) {\n return defaultConfig.parse(opts)\n}\n\nexport type TanStackStartOutputConfig = ReturnType<\n typeof getTanStackStartOptions\n>\n\ndeclare global {\n // eslint-disable-next-line no-var\n var TSS_APP_BASE: string\n}\n\nexport interface TanStackStartVitePluginCoreOptions {\n framework: CompileStartFrameworkOptions\n getVirtualServerRootHandler: (ctx: {\n routerFilepath: string\n serverEntryFilepath: string\n }) => string\n getVirtualServerEntry: (ctx: { routerFilepath: string }) => string\n getVirtualClientEntry: (ctx: { routerFilepath: string }) => string\n}\n// this needs to live outside of the TanStackStartVitePluginCore since it will be invoked multiple times by vite\nlet ssrBundle: Rollup.OutputBundle\n\nexport function TanStackStartVitePluginCore(\n opts: TanStackStartVitePluginCoreOptions,\n startConfig: TanStackStartOutputConfig,\n): Array<PluginOption> {\n return [\n tanstackRouter({\n verboseFileRoutes: false,\n ...startConfig.tsr,\n target: opts.framework,\n enableRouteGeneration: true,\n autoCodeSplitting: true,\n }),\n resolveVirtualEntriesPlugin(opts, startConfig),\n {\n name: 'tanstack-start-core:config-client',\n async config(viteConfig) {\n const viteAppBase = trimPathRight(viteConfig.base || '/')\n globalThis.TSS_APP_BASE = viteAppBase\n\n const nitroOutputPublicDir = await (async () => {\n // Create a dummy nitro app to get the resolved public output path\n const dummyNitroApp = await createNitro({\n preset: startConfig.target,\n compatibilityDate: '2024-12-01',\n })\n\n const nitroOutputPublicDir = dummyNitroApp.options.output.publicDir\n await dummyNitroApp.close()\n\n return nitroOutputPublicDir\n })()\n\n const getClientEntryPath = (startConfig: TanStackStartOutputConfig) => {\n // when the user specifies a custom client entry path, we need to resolve it\n // relative to the root of the project, keeping in mind that if not specified\n // it will be /~start/default-client-entry which is a virtual path\n // that is resolved by vite to the actual client entry path\n const entry = startConfig.clientEntryPath.startsWith(\n '/~start/default-client-entry',\n )\n ? startConfig.clientEntryPath\n : vite.normalizePath(\n path.join(\n '/@fs',\n path.resolve(startConfig.root, startConfig.clientEntryPath),\n ),\n )\n\n return entry\n }\n\n return {\n base: viteAppBase,\n environments: {\n [VITE_ENVIRONMENT_NAMES.client]: {\n consumer: 'client',\n build: {\n manifest: true,\n rollupOptions: {\n input: {\n main: getClientEntryPath(startConfig),\n },\n output: {\n dir: path.resolve(startConfig.root, CLIENT_DIST_DIR),\n },\n // TODO: this should be removed\n external: ['node:fs', 'node:path', 'node:os', 'node:crypto'],\n },\n },\n },\n [VITE_ENVIRONMENT_NAMES.server]: {\n consumer: 'server',\n build: {\n ssr: true,\n // we don't write to the file system as the below 'capture-output' plugin will\n // capture the output and write it to the virtual file system\n write: false,\n copyPublicDir: false,\n rollupOptions: {\n output: {\n entryFileNames: SSR_ENTRY_FILE,\n },\n plugins: [\n {\n name: 'capture-output',\n generateBundle(_options, bundle) {\n // TODO: can this hook be called more than once?\n ssrBundle = bundle\n },\n },\n ],\n },\n commonjsOptions: {\n include: [/node_modules/],\n },\n },\n },\n },\n resolve: {\n noExternal: [\n '@tanstack/start-client',\n '@tanstack/start-client-core',\n '@tanstack/start-server',\n '@tanstack/start-server-core',\n '@tanstack/start-server-functions-fetcher',\n '@tanstack/start-server-functions-client',\n '@tanstack/start-server-functions-server',\n '@tanstack/start-router-manifest',\n '@tanstack/start-config',\n '@tanstack/server-functions-plugin',\n 'tanstack-start-router-manifest:v',\n 'tanstack-start-server-fn-manifest:v',\n 'nitropack',\n '@tanstack/**start**',\n ],\n },\n optimizeDeps: {\n exclude: [\n 'tanstack-start-server-fn-manifest:v',\n 'tanstack-start-router-manifest:v',\n 'tanstack-start-server-routes-manifest:v',\n ],\n },\n /* prettier-ignore */\n define: {\n // define is an esbuild function that replaces the any instances of given keys with the given values\n // i.e: __FRAMEWORK_NAME__ can be replaced with JSON.stringify(\"TanStack Start\")\n // This is not the same as injecting environment variables.\n\n ...defineReplaceEnv('TSS_CLIENT_ENTRY', getClientEntryPath(startConfig)), // This is consumed by the router-manifest, where the entry point is imported after the dev refresh runtime is resolved\n ...defineReplaceEnv('TSS_SERVER_FN_BASE', startConfig.serverFns.base),\n ...defineReplaceEnv('TSS_OUTPUT_PUBLIC_DIR', nitroOutputPublicDir),\n ...defineReplaceEnv('TSS_APP_BASE', viteAppBase)\n },\n }\n },\n },\n // N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv\n startCompilerPlugin(opts.framework, {\n client: { envName: VITE_ENVIRONMENT_NAMES.client },\n server: { envName: VITE_ENVIRONMENT_NAMES.server },\n }),\n TanStackServerFnPluginEnv({\n // This is the ID that will be available to look up and import\n // our server function manifest and resolve its module\n manifestVirtualImportId: 'tanstack-start-server-fn-manifest:v',\n manifestOutputFilename:\n '.tanstack-start/build/server/server-functions-manifest.json',\n client: {\n getRuntimeCode: () =>\n `import { createClientRpc } from '@tanstack/${opts.framework}-start/server-functions-client'`,\n replacer: (d) =>\n `createClientRpc('${d.functionId}', '${startConfig.serverFns.base}')`,\n envName: VITE_ENVIRONMENT_NAMES.client,\n },\n server: {\n getRuntimeCode: () =>\n `import { createServerRpc } from '@tanstack/${opts.framework}-start/server-functions-server'`,\n replacer: (d) =>\n `createServerRpc('${d.functionId}', '${startConfig.serverFns.base}', ${d.fn})`,\n envName: VITE_ENVIRONMENT_NAMES.server,\n },\n importer: (fn) => {\n const serverEnv = (globalThis as any).viteDevServer.environments[\n VITE_ENVIRONMENT_NAMES.server\n ]\n if (!serverEnv) {\n throw new Error(`'ssr' vite dev environment not found`)\n }\n return serverEnv.runner.import(fn.extractedFilename)\n },\n }),\n loadEnvPlugin(startConfig),\n startRoutesManifestPlugin(startConfig),\n devServerPlugin(),\n nitroPlugin(startConfig, () => ssrBundle),\n TanStackStartServerRoutesVite({\n ...startConfig.tsr,\n target: opts.framework,\n }),\n ]\n}\n\nfunction defineReplaceEnv<TKey extends string, TValue extends string>(\n key: TKey,\n value: TValue,\n): { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue } {\n return {\n [`process.env.${key}`]: JSON.stringify(value),\n [`import.meta.env.${key}`]: JSON.stringify(value),\n } as { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue }\n}\n"],"names":["nitroOutputPublicDir","startConfig"],"mappings":";;;;;;;;;;;;;;;AA4BsB,qBAAqB;AAwB3C,IAAI;AAEY,SAAA,4BACd,MACA,aACqB;AACd,SAAA;AAAA,IACL,eAAe;AAAA,MACb,mBAAmB;AAAA,MACnB,GAAG,YAAY;AAAA,MACf,QAAQ,KAAK;AAAA,MACb,uBAAuB;AAAA,MACvB,mBAAmB;AAAA,IAAA,CACpB;AAAA,IACD,4BAA4B,MAAM,WAAW;AAAA,IAC7C;AAAA,MACE,MAAM;AAAA,MACN,MAAM,OAAO,YAAY;AACvB,cAAM,cAAc,cAAc,WAAW,QAAQ,GAAG;AACxD,mBAAW,eAAe;AAEpB,cAAA,uBAAuB,OAAO,YAAY;AAExC,gBAAA,gBAAgB,MAAM,YAAY;AAAA,YACtC,QAAQ,YAAY;AAAA,Y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M,YAAa,WAAmB,cAAc,aAClD,uBAAuB,MACzB;AACA,YAAI,CAAC,WAAW;AACR,gBAAA,IAAI,MAAM,sCAAsC;AAAA,QAAA;AAExD,eAAO,UAAU,OAAO,OAAO,GAAG,iBAAiB;AAAA,MAAA;AAAA,IACrD,CACD;AAAA,IACD,cAAc,WAAW;AAAA,IACzB,0BAA0B,WAAW;AAAA,IACrC,gBAAgB;AAAA,IAChB,YAAY,aAAa,MAAM,SAAS;AAAA,IACxC,8BAA8B;AAAA,MAC5B,GAAG,YAAY;AAAA,MACf,QAAQ,KAAK;AAAA,IACd,CAAA;AAAA,EACH;AACF;AAEA,SAAS,iBACP,KACA,OACsE;AAC/D,SAAA;AAAA,IACL,CAAC,eAAe,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,IAC5C,CAAC,mBAAmB,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,EAClD;AACF;"}
|
|
@@ -102,7 +102,7 @@ function startRoutesManifestPlugin(opts) {
|
|
|
102
102
|
opts.tsr.routesDirectory
|
|
103
103
|
);
|
|
104
104
|
Object.entries(routeTreeRoutes).forEach(([routeId, v]) => {
|
|
105
|
-
const file = filesByRouteFilePath[path.join(routesDirectoryFromRoot, v.filePath)];
|
|
105
|
+
const file = filesByRouteFilePath[path.posix.join(routesDirectoryFromRoot, v.filePath)];
|
|
106
106
|
if (file) {
|
|
107
107
|
const preloads = (file.imports ?? []).map((d) => {
|
|
108
108
|
const assetPath = joinURL(APP_BASE, viteManifest[d].file);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["../../../src/start-routes-manifest-plugin/plugin.ts"],"sourcesContent":["import { mkdirSync, readFileSync, rmSync, writeFile } from 'node:fs'\nimport path from 'node:path'\nimport { joinURL } from 'ufo'\nimport { rootRouteId } from '@tanstack/router-core'\nimport { resolveViteId } from '../utils'\nimport type {\n PluginOption,\n ResolvedConfig,\n Manifest as ViteManifest,\n ManifestChunk as ViteManifestChunk,\n} from 'vite'\nimport type { Manifest, RouterManagedTag } from '@tanstack/router-core'\nimport type { TanStackStartOutputConfig } from '../plugin'\n\nconst getCSSRecursively = (\n file: ViteManifestChunk,\n filesByRouteFilePath: ViteManifest,\n basePath: string,\n) => {\n const result: Array<RouterManagedTag> = []\n\n // Get all css imports from the file\n for (const cssFile of file.css ?? []) {\n result.push({\n tag: 'link',\n attrs: {\n rel: 'stylesheet',\n href: joinURL(basePath, cssFile),\n type: 'text/css',\n },\n })\n }\n\n // Recursively get CSS from imports\n for (const imp of file.imports ?? []) {\n const importInfo = filesByRouteFilePath[imp]\n if (importInfo) {\n result.push(\n ...getCSSRecursively(importInfo, filesByRouteFilePath, basePath),\n )\n }\n }\n\n return result\n}\n\nexport function startRoutesManifestPlugin(\n opts: TanStackStartOutputConfig,\n): PluginOption {\n let config: ResolvedConfig\n\n const moduleId = 'tanstack-start-router-manifest:v'\n const resolvedModuleId = resolveViteId(moduleId)\n\n return {\n name: 'tsr-routes-manifest',\n enforce: 'pre',\n\n configResolved(resolvedConfig) {\n config = resolvedConfig\n },\n // configEnvironment(env, envConfig) {\n // config = envConfig.\n // },\n resolveId(id) {\n if (id === moduleId) {\n return resolvedModuleId\n }\n return\n },\n load(id) {\n if (id === resolvedModuleId) {\n if (this.environment.config.consumer !== 'server') {\n // this will ultimately fail the build if the plugin is used outside the server environment\n // TODO: do we need special handling for `serve`?\n return `export default {}`\n }\n\n // If we're in development, return a dummy manifest\n if (config.command === 'serve') {\n return `export const tsrStartManifest = () => ({\n routes: {}\n })`\n }\n\n // This is the basepath for the application\n const APP_BASE = globalThis.TSS_APP_BASE\n\n const clientViteManifestPath = path.resolve(\n opts.root,\n '.tanstack-start/build/client-dist/.vite/manifest.json',\n )\n\n let viteManifest: ViteManifest\n try {\n viteManifest = JSON.parse(\n readFileSync(clientViteManifestPath, 'utf-8'),\n )\n } catch (err) {\n console.error(err)\n throw new Error(\n `Could not find the production client vite manifest at '${clientViteManifestPath}'!`,\n )\n }\n\n const routeTreePath = path.resolve(opts.tsr.generatedRouteTree)\n\n let routeTreeContent: string\n try {\n routeTreeContent = readFileSync(routeTreePath, 'utf-8')\n } catch (err) {\n console.error(err)\n throw new Error(\n `Could not find the generated route tree at '${routeTreePath}'!`,\n )\n }\n\n // Extract the routesManifest JSON from the route tree file.\n // It's located between the /* ROUTE_MANIFEST_START and ROUTE_MANIFEST_END */ comment block.\n\n const routerManifest = JSON.parse(\n routeTreeContent.match(\n /\\/\\* ROUTE_MANIFEST_START([\\s\\S]*?)ROUTE_MANIFEST_END \\*\\//,\n )?.[1] || '{ routes: {} }',\n ) as Manifest\n\n // This the manifest pulled from the generated route tree and later used by the Router.\n // i.e what's located in `src/generatedRouteTree.gen.ts`\n const routeTreeRoutes = routerManifest.routes\n\n // This is where hydration will start, from when the SSR'd page reaches the browser.\n // By default, this'd be the virtual entry of `/~start/default-client-entry.tsx`, unless a custom entry is provided.\n let entryFile: ViteManifestChunk | undefined\n\n const filesByRouteFilePath: ViteManifest = Object.fromEntries(\n Object.entries(viteManifest).map(([k, v]) => {\n if (v.isEntry) {\n entryFile = v\n }\n\n const rPath = k.split('?')[0]\n\n return [rPath, v]\n }, {}),\n )\n\n const routesDirectoryFromRoot = path.relative(\n opts.root,\n opts.tsr.routesDirectory,\n )\n\n // Add preloads to the routes from the vite manifest\n Object.entries(routeTreeRoutes).forEach(([routeId, v]) => {\n const file =\n filesByRouteFilePath[\n path.join(routesDirectoryFromRoot, v.filePath as string)\n ]\n\n if (file) {\n // Map the relevant imports to their route paths,\n // so that it can be imported in the browser.\n const preloads = (file.imports ?? []).map((d) => {\n const assetPath = joinURL(APP_BASE, viteManifest[d]!.file)\n return assetPath\n })\n\n // Since this is the most important JS entry for the route,\n // it should be moved to the front of the preloads so that\n // it has the best chance of being loaded first.\n if (file.file) {\n preloads.unshift(path.join(APP_BASE, file.file))\n }\n\n const cssAssetsList = getCSSRecursively(\n file,\n filesByRouteFilePath,\n APP_BASE,\n )\n\n routeTreeRoutes[routeId] = {\n ...v,\n assets: [...(v.assets || []), ...cssAssetsList],\n preloads,\n }\n }\n })\n\n if (entryFile) {\n routeTreeRoutes[rootRouteId]!.preloads = [\n joinURL(APP_BASE, entryFile.file),\n ...(entryFile.imports?.map((d) =>\n joinURL(APP_BASE, viteManifest[d]!.file),\n ) || []),\n ]\n\n // Gather all the CSS files from the entry file in\n // the `css` key and add them to the root route\n const entryCssAssetsList = getCSSRecursively(\n entryFile,\n filesByRouteFilePath,\n APP_BASE,\n )\n\n routeTreeRoutes[rootRouteId]!.assets = [\n ...(routeTreeRoutes[rootRouteId]!.assets || []),\n ...entryCssAssetsList,\n {\n tag: 'script',\n attrs: {\n src: joinURL(APP_BASE, entryFile.file),\n type: 'module',\n },\n },\n ]\n }\n\n const recurseRoute = (\n route: {\n preloads?: Array<string>\n children?: Array<any>\n },\n seenPreloads = {} as Record<string, true>,\n ) => {\n route.preloads = route.preloads?.filter((preload) => {\n if (seenPreloads[preload]) {\n return false\n }\n seenPreloads[preload] = true\n return true\n })\n\n if (route.children) {\n route.children.forEach((child) => {\n const childRoute = routeTreeRoutes[child]!\n recurseRoute(childRoute, { ...seenPreloads })\n })\n }\n }\n\n // @ts-expect-error\n recurseRoute(routeTreeRoutes[rootRouteId])\n\n const routesManifest = {\n routes: routeTreeRoutes,\n }\n\n try {\n const routesManifestOutputDirPath = path.resolve(\n opts.root,\n '.tanstack-start/build/route-assets-manifest',\n )\n rmSync(routesManifestOutputDirPath, {\n recursive: true,\n force: true,\n })\n mkdirSync(routesManifestOutputDirPath, { recursive: true })\n writeFile(\n path.join(routesManifestOutputDirPath, 'manifest.json'),\n JSON.stringify(routesManifest),\n (err) => {\n if (err) {\n console.error(\n 'There was an error writing the routes manifest to disk.\\nYou can ignore this error. It does not affect the runtime of your application.',\n )\n console.error(err)\n }\n },\n )\n } catch (err) {\n console.error(\n 'There was an error writing the routes manifest to disk.\\nYou can ignore this error. It does not affect the runtime of your application.',\n )\n console.error(err)\n }\n\n return `export const tsrStartManifest = () => (${JSON.stringify(routesManifest)})`\n }\n\n return undefined\n },\n }\n}\n"],"names":["_a"],"mappings":";;;;;AAcA,MAAM,oBAAoB,CACxB,MACA,sBACA,aACG;AACH,QAAM,SAAkC,CAAC;AAGzC,aAAW,WAAW,KAAK,OAAO,CAAA,GAAI;AACpC,WAAO,KAAK;AAAA,MACV,KAAK;AAAA,MACL,OAAO;AAAA,QACL,KAAK;AAAA,QACL,MAAM,QAAQ,UAAU,OAAO;AAAA,QAC/B,MAAM;AAAA,MAAA;AAAA,IACR,CACD;AAAA,EAAA;AAIH,aAAW,OAAO,KAAK,WAAW,CAAA,GAAI;AAC9B,UAAA,aAAa,qBAAqB,GAAG;AAC3C,QAAI,YAAY;AACP,aAAA;AAAA,QACL,GAAG,kBAAkB,YAAY,sBAAsB,QAAQ;AAAA,MACjE;AAAA,IAAA;AAAA,EACF;AAGK,SAAA;AACT;AAEO,SAAS,0BACd,MACc;AACV,MAAA;AAEJ,QAAM,WAAW;AACX,QAAA,mBAAmB,cAAc,QAAQ;AAExC,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,eAAe,gBAAgB;AACpB,eAAA;AAAA,IACX;AAAA;AAAA;AAAA;AAAA,IAIA,UAAU,IAAI;AACZ,UAAI,OAAO,UAAU;AACZ,eAAA;AAAA,MAAA;AAET;AAAA,IACF;AAAA,IACA,KAAK,IAAI;;AACP,UAAI,OAAO,kBAAkB;AAC3B,YAAI,KAAK,YAAY,OAAO,aAAa,UAAU;AAG1C,iBAAA;AAAA,QAAA;AAIL,YAAA,OAAO,YAAY,SAAS;AACvB,iBAAA;AAAA;AAAA;AAAA,QAAA;AAMT,cAAM,WAAW,WAAW;AAE5B,cAAM,yBAAyB,KAAK;AAAA,UAClC,KAAK;AAAA,UACL;AAAA,QACF;AAEI,YAAA;AACA,YAAA;AACF,yBAAe,KAAK;AAAA,YAClB,aAAa,wBAAwB,OAAO;AAAA,UAC9C;AAAA,iBACO,KA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A,QACV;AAEI,YAAA;AACF,gBAAM,8BAA8B,KAAK;AAAA,YACvC,KAAK;AAAA,YACL;AAAA,UACF;AACA,iBAAO,6BAA6B;AAAA,YAClC,WAAW;AAAA,YACX,OAAO;AAAA,UAAA,CACR;AACD,oBAAU,6BAA6B,EAAE,WAAW,KAAA,CAAM;AAC1D;AAAA,YACE,KAAK,KAAK,6BAA6B,eAAe;AAAA,YACtD,KAAK,UAAU,cAAc;AAAA,YAC7B,CAAC,QAAQ;AACP,kBAAI,KAAK;AACC,wBAAA;AAAA,kBACN;AAAA,gBACF;AACA,wBAAQ,MAAM,GAAG;AAAA,cAAA;AAAA,YACnB;AAAA,UAEJ;AAAA,iBACO,KAAK;AACJ,kBAAA;AAAA,YACN;AAAA,UACF;AACA,kBAAQ,MAAM,GAAG;AAAA,QAAA;AAGnB,eAAO,0CAA0C,KAAK,UAAU,cAAc,CAAC;AAAA,MAAA;AAG1E,aAAA;AAAA,IAAA;AAAA,EAEX;AACF;"}
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["../../../src/start-routes-manifest-plugin/plugin.ts"],"sourcesContent":["import { mkdirSync, readFileSync, rmSync, writeFile } from 'node:fs'\nimport path from 'node:path'\nimport { joinURL } from 'ufo'\nimport { rootRouteId } from '@tanstack/router-core'\nimport { resolveViteId } from '../utils'\nimport type {\n PluginOption,\n ResolvedConfig,\n Manifest as ViteManifest,\n ManifestChunk as ViteManifestChunk,\n} from 'vite'\nimport type { Manifest, RouterManagedTag } from '@tanstack/router-core'\nimport type { TanStackStartOutputConfig } from '../plugin'\n\nconst getCSSRecursively = (\n file: ViteManifestChunk,\n filesByRouteFilePath: ViteManifest,\n basePath: string,\n) => {\n const result: Array<RouterManagedTag> = []\n\n // Get all css imports from the file\n for (const cssFile of file.css ?? []) {\n result.push({\n tag: 'link',\n attrs: {\n rel: 'stylesheet',\n href: joinURL(basePath, cssFile),\n type: 'text/css',\n },\n })\n }\n\n // Recursively get CSS from imports\n for (const imp of file.imports ?? []) {\n const importInfo = filesByRouteFilePath[imp]\n if (importInfo) {\n result.push(\n ...getCSSRecursively(importInfo, filesByRouteFilePath, basePath),\n )\n }\n }\n\n return result\n}\n\nexport function startRoutesManifestPlugin(\n opts: TanStackStartOutputConfig,\n): PluginOption {\n let config: ResolvedConfig\n\n const moduleId = 'tanstack-start-router-manifest:v'\n const resolvedModuleId = resolveViteId(moduleId)\n\n return {\n name: 'tsr-routes-manifest',\n enforce: 'pre',\n\n configResolved(resolvedConfig) {\n config = resolvedConfig\n },\n // configEnvironment(env, envConfig) {\n // config = envConfig.\n // },\n resolveId(id) {\n if (id === moduleId) {\n return resolvedModuleId\n }\n return\n },\n load(id) {\n if (id === resolvedModuleId) {\n if (this.environment.config.consumer !== 'server') {\n // this will ultimately fail the build if the plugin is used outside the server environment\n // TODO: do we need special handling for `serve`?\n return `export default {}`\n }\n\n // If we're in development, return a dummy manifest\n if (config.command === 'serve') {\n return `export const tsrStartManifest = () => ({\n routes: {}\n })`\n }\n\n // This is the basepath for the application\n const APP_BASE = globalThis.TSS_APP_BASE\n\n const clientViteManifestPath = path.resolve(\n opts.root,\n '.tanstack-start/build/client-dist/.vite/manifest.json',\n )\n\n let viteManifest: ViteManifest\n try {\n viteManifest = JSON.parse(\n readFileSync(clientViteManifestPath, 'utf-8'),\n )\n } catch (err) {\n console.error(err)\n throw new Error(\n `Could not find the production client vite manifest at '${clientViteManifestPath}'!`,\n )\n }\n\n const routeTreePath = path.resolve(opts.tsr.generatedRouteTree)\n\n let routeTreeContent: string\n try {\n routeTreeContent = readFileSync(routeTreePath, 'utf-8')\n } catch (err) {\n console.error(err)\n throw new Error(\n `Could not find the generated route tree at '${routeTreePath}'!`,\n )\n }\n\n // Extract the routesManifest JSON from the route tree file.\n // It's located between the /* ROUTE_MANIFEST_START and ROUTE_MANIFEST_END */ comment block.\n\n const routerManifest = JSON.parse(\n routeTreeContent.match(\n /\\/\\* ROUTE_MANIFEST_START([\\s\\S]*?)ROUTE_MANIFEST_END \\*\\//,\n )?.[1] || '{ routes: {} }',\n ) as Manifest\n\n // This the manifest pulled from the generated route tree and later used by the Router.\n // i.e what's located in `src/generatedRouteTree.gen.ts`\n const routeTreeRoutes = routerManifest.routes\n\n // This is where hydration will start, from when the SSR'd page reaches the browser.\n // By default, this'd be the virtual entry of `/~start/default-client-entry.tsx`, unless a custom entry is provided.\n let entryFile: ViteManifestChunk | undefined\n\n const filesByRouteFilePath: ViteManifest = Object.fromEntries(\n Object.entries(viteManifest).map(([k, v]) => {\n if (v.isEntry) {\n entryFile = v\n }\n\n const rPath = k.split('?')[0]\n\n return [rPath, v]\n }, {}),\n )\n\n const routesDirectoryFromRoot = path.relative(\n opts.root,\n opts.tsr.routesDirectory,\n )\n\n // Add preloads to the routes from the vite manifest\n Object.entries(routeTreeRoutes).forEach(([routeId, v]) => {\n const file =\n filesByRouteFilePath[\n path.posix.join(routesDirectoryFromRoot, v.filePath as string)\n ]\n\n if (file) {\n // Map the relevant imports to their route paths,\n // so that it can be imported in the browser.\n const preloads = (file.imports ?? []).map((d) => {\n const assetPath = joinURL(APP_BASE, viteManifest[d]!.file)\n return assetPath\n })\n\n // Since this is the most important JS entry for the route,\n // it should be moved to the front of the preloads so that\n // it has the best chance of being loaded first.\n if (file.file) {\n preloads.unshift(path.join(APP_BASE, file.file))\n }\n\n const cssAssetsList = getCSSRecursively(\n file,\n filesByRouteFilePath,\n APP_BASE,\n )\n\n routeTreeRoutes[routeId] = {\n ...v,\n assets: [...(v.assets || []), ...cssAssetsList],\n preloads,\n }\n }\n })\n\n if (entryFile) {\n routeTreeRoutes[rootRouteId]!.preloads = [\n joinURL(APP_BASE, entryFile.file),\n ...(entryFile.imports?.map((d) =>\n joinURL(APP_BASE, viteManifest[d]!.file),\n ) || []),\n ]\n\n // Gather all the CSS files from the entry file in\n // the `css` key and add them to the root route\n const entryCssAssetsList = getCSSRecursively(\n entryFile,\n filesByRouteFilePath,\n APP_BASE,\n )\n\n routeTreeRoutes[rootRouteId]!.assets = [\n ...(routeTreeRoutes[rootRouteId]!.assets || []),\n ...entryCssAssetsList,\n {\n tag: 'script',\n attrs: {\n src: joinURL(APP_BASE, entryFile.file),\n type: 'module',\n },\n },\n ]\n }\n\n const recurseRoute = (\n route: {\n preloads?: Array<string>\n children?: Array<any>\n },\n seenPreloads = {} as Record<string, true>,\n ) => {\n route.preloads = route.preloads?.filter((preload) => {\n if (seenPreloads[preload]) {\n return false\n }\n seenPreloads[preload] = true\n return true\n })\n\n if (route.children) {\n route.children.forEach((child) => {\n const childRoute = routeTreeRoutes[child]!\n recurseRoute(childRoute, { ...seenPreloads })\n })\n }\n }\n\n // @ts-expect-error\n recurseRoute(routeTreeRoutes[rootRouteId])\n\n const routesManifest = {\n routes: routeTreeRoutes,\n }\n\n try {\n const routesManifestOutputDirPath = path.resolve(\n opts.root,\n '.tanstack-start/build/route-assets-manifest',\n )\n rmSync(routesManifestOutputDirPath, {\n recursive: true,\n force: true,\n })\n mkdirSync(routesManifestOutputDirPath, { recursive: true })\n writeFile(\n path.join(routesManifestOutputDirPath, 'manifest.json'),\n JSON.stringify(routesManifest),\n (err) => {\n if (err) {\n console.error(\n 'There was an error writing the routes manifest to disk.\\nYou can ignore this error. It does not affect the runtime of your application.',\n )\n console.error(err)\n }\n },\n )\n } catch (err) {\n console.error(\n 'There was an error writing the routes manifest to disk.\\nYou can ignore this error. It does not affect the runtime of your application.',\n )\n console.error(err)\n }\n\n return `export const tsrStartManifest = () => (${JSON.stringify(routesManifest)})`\n }\n\n return undefined\n },\n }\n}\n"],"names":["_a"],"mappings":";;;;;AAcA,MAAM,oBAAoB,CACxB,MACA,sBACA,aACG;AACH,QAAM,SAAkC,CAAC;AAGzC,aAAW,WAAW,KAAK,OAAO,CAAA,GAAI;AACpC,WAAO,KAAK;AAAA,MACV,KAAK;AAAA,MACL,OAAO;AAAA,QACL,KAAK;AAAA,QACL,MAAM,QAAQ,UAAU,OAAO;AAAA,QAC/B,MAAM;AAAA,MAAA;AAAA,IACR,CAC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ACN;AAAA,gBACF;AACA,wBAAQ,MAAM,GAAG;AAAA,cAAA;AAAA,YACnB;AAAA,UAEJ;AAAA,iBACO,KAAK;AACJ,kBAAA;AAAA,YACN;AAAA,UACF;AACA,kBAAQ,MAAM,GAAG;AAAA,QAAA;AAGnB,eAAO,0CAA0C,KAAK,UAAU,cAAc,CAAC;AAAA,MAAA;AAG1E,aAAA;AAAA,IAAA;AAAA,EAEX;AACF;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/start-plugin-core",
|
|
3
|
-
"version": "1.121.0-alpha.
|
|
3
|
+
"version": "1.121.0-alpha.25",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"@tanstack/router-core": "^1.121.0-alpha.22",
|
|
67
67
|
"@tanstack/router-generator": "^1.121.0-alpha.22",
|
|
68
68
|
"@tanstack/router-plugin": "^1.121.0-alpha.22",
|
|
69
|
-
"@tanstack/
|
|
70
|
-
"@tanstack/
|
|
69
|
+
"@tanstack/router-utils": "^1.121.0-alpha.2",
|
|
70
|
+
"@tanstack/server-functions-plugin": "^1.121.0-alpha.8"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"vite": "^6.0.0"
|
package/src/plugin.ts
CHANGED
|
@@ -153,7 +153,7 @@ export function startRoutesManifestPlugin(
|
|
|
153
153
|
Object.entries(routeTreeRoutes).forEach(([routeId, v]) => {
|
|
154
154
|
const file =
|
|
155
155
|
filesByRouteFilePath[
|
|
156
|
-
path.join(routesDirectoryFromRoot, v.filePath as string)
|
|
156
|
+
path.posix.join(routesDirectoryFromRoot, v.filePath as string)
|
|
157
157
|
]
|
|
158
158
|
|
|
159
159
|
if (file) {
|