@tanstack/router-plugin 1.167.30 → 1.167.32
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/context.cjs +3 -0
- package/dist/cjs/context.d.cts +2 -0
- package/dist/cjs/core/router-code-splitter-plugin.cjs +7 -2
- package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-code-splitter-plugin.d.cts +2 -0
- package/dist/cjs/core/router-composed-plugin.cjs +7 -6
- package/dist/cjs/core/router-composed-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-generator-plugin.cjs +7 -2
- package/dist/cjs/core/router-generator-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-generator-plugin.d.cts +2 -0
- package/dist/cjs/core/router-hmr-plugin.cjs +9 -6
- package/dist/cjs/core/router-hmr-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-hmr-plugin.d.cts +2 -0
- package/dist/cjs/core/router-plugin-context.cjs +8 -0
- package/dist/cjs/core/router-plugin-context.cjs.map +1 -0
- package/dist/cjs/core/router-plugin-context.d.cts +5 -0
- package/dist/cjs/esbuild.cjs +10 -2
- package/dist/cjs/esbuild.cjs.map +1 -1
- package/dist/cjs/esbuild.d.cts +5 -95
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.d.cts +2 -0
- package/dist/cjs/rspack.cjs +10 -2
- package/dist/cjs/rspack.cjs.map +1 -1
- package/dist/cjs/rspack.d.cts +5 -49
- package/dist/cjs/vite.cjs +11 -2
- package/dist/cjs/vite.cjs.map +1 -1
- package/dist/cjs/vite.d.cts +6 -96
- package/dist/cjs/webpack.cjs +10 -2
- package/dist/cjs/webpack.cjs.map +1 -1
- package/dist/cjs/webpack.d.cts +4 -49
- package/dist/esm/context.d.ts +2 -0
- package/dist/esm/context.js +2 -0
- package/dist/esm/core/router-code-splitter-plugin.d.ts +2 -0
- package/dist/esm/core/router-code-splitter-plugin.js +7 -3
- package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
- package/dist/esm/core/router-composed-plugin.js +10 -9
- package/dist/esm/core/router-composed-plugin.js.map +1 -1
- package/dist/esm/core/router-generator-plugin.d.ts +2 -0
- package/dist/esm/core/router-generator-plugin.js +7 -3
- package/dist/esm/core/router-generator-plugin.js.map +1 -1
- package/dist/esm/core/router-hmr-plugin.d.ts +2 -0
- package/dist/esm/core/router-hmr-plugin.js +9 -6
- package/dist/esm/core/router-hmr-plugin.js.map +1 -1
- package/dist/esm/core/router-plugin-context.d.ts +5 -0
- package/dist/esm/core/router-plugin-context.js +8 -0
- package/dist/esm/core/router-plugin-context.js.map +1 -0
- package/dist/esm/esbuild.d.ts +5 -95
- package/dist/esm/esbuild.js +12 -4
- package/dist/esm/esbuild.js.map +1 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -1
- package/dist/esm/rspack.d.ts +5 -49
- package/dist/esm/rspack.js +12 -4
- package/dist/esm/rspack.js.map +1 -1
- package/dist/esm/vite.d.ts +6 -96
- package/dist/esm/vite.js +14 -6
- package/dist/esm/vite.js.map +1 -1
- package/dist/esm/webpack.d.ts +4 -49
- package/dist/esm/webpack.js +12 -4
- package/dist/esm/webpack.js.map +1 -1
- package/package.json +14 -4
- package/src/context.ts +2 -0
- package/src/core/router-code-splitter-plugin.ts +13 -4
- package/src/core/router-composed-plugin.ts +16 -11
- package/src/core/router-generator-plugin.ts +13 -4
- package/src/core/router-hmr-plugin.ts +21 -6
- package/src/core/router-plugin-context.ts +11 -0
- package/src/esbuild.ts +27 -9
- package/src/index.ts +2 -0
- package/src/rspack.ts +30 -12
- package/src/vite.ts +29 -9
- package/src/webpack.ts +27 -12
- package/src/global.d.ts +0 -7
|
@@ -5,6 +5,7 @@ const require_utils = require("./utils.cjs");
|
|
|
5
5
|
const require_path_ids = require("./code-splitter/path-ids.cjs");
|
|
6
6
|
const require_compilers = require("./code-splitter/compilers.cjs");
|
|
7
7
|
const require_framework_plugins = require("./code-splitter/plugins/framework-plugins.cjs");
|
|
8
|
+
const require_router_plugin_context = require("./router-plugin-context.cjs");
|
|
8
9
|
let node_url = require("node:url");
|
|
9
10
|
let _tanstack_router_utils = require("@tanstack/router-utils");
|
|
10
11
|
//#region src/core/router-code-splitter-plugin.ts
|
|
@@ -41,7 +42,7 @@ var TRANSFORMATION_PLUGINS_BY_FRAMEWORK = {
|
|
|
41
42
|
usage: "solid()"
|
|
42
43
|
}]
|
|
43
44
|
};
|
|
44
|
-
|
|
45
|
+
function createRouterCodeSplitterPlugin(options = {}, routerPluginContext) {
|
|
45
46
|
let ROOT = process.cwd();
|
|
46
47
|
let userConfig;
|
|
47
48
|
function initUserConfig() {
|
|
@@ -149,7 +150,7 @@ var unpluginRouterCodeSplitterFactory = (options = {}, { framework: _framework }
|
|
|
149
150
|
},
|
|
150
151
|
handler(code, id) {
|
|
151
152
|
const normalizedId = require_utils.normalizePath(id);
|
|
152
|
-
const generatorFileInfo =
|
|
153
|
+
const generatorFileInfo = routerPluginContext.routesByFile.get(normalizedId);
|
|
153
154
|
if (generatorFileInfo && includedCode.some((included) => code.includes(included))) return handleCompilingReferenceFile(code, normalizedId, generatorFileInfo);
|
|
154
155
|
return null;
|
|
155
156
|
}
|
|
@@ -229,8 +230,12 @@ var unpluginRouterCodeSplitterFactory = (options = {}, { framework: _framework }
|
|
|
229
230
|
} }
|
|
230
231
|
}
|
|
231
232
|
];
|
|
233
|
+
}
|
|
234
|
+
var unpluginRouterCodeSplitterFactory = (options = {}) => {
|
|
235
|
+
return createRouterCodeSplitterPlugin(options, require_router_plugin_context.createRouterPluginContext());
|
|
232
236
|
};
|
|
233
237
|
//#endregion
|
|
238
|
+
exports.createRouterCodeSplitterPlugin = createRouterCodeSplitterPlugin;
|
|
234
239
|
exports.unpluginRouterCodeSplitterFactory = unpluginRouterCodeSplitterFactory;
|
|
235
240
|
|
|
236
241
|
//# sourceMappingURL=router-code-splitter-plugin.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-code-splitter-plugin.cjs","names":[],"sources":["../../../src/core/router-code-splitter-plugin.ts"],"sourcesContent":["/**\n * It is important to familiarize yourself with how the code-splitting works in this plugin.\n * https://github.com/TanStack/router/pull/3355\n */\n\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { logDiff } from '@tanstack/router-utils'\nimport { getConfig, splitGroupingsSchema } from './config'\nimport {\n compileCodeSplitReferenceRoute,\n compileCodeSplitSharedRoute,\n compileCodeSplitVirtualRoute,\n computeSharedBindings,\n detectCodeSplitGroupingsFromRoute,\n} from './code-splitter/compilers'\nimport { getReferenceRouteCompilerPlugins } from './code-splitter/plugins/framework-plugins'\nimport {\n defaultCodeSplitGroupings,\n splitRouteIdentNodes,\n tsrShared,\n tsrSplit,\n} from './constants'\nimport { decodeIdentifier } from './code-splitter/path-ids'\nimport { debug, normalizePath } from './utils'\nimport type { CodeSplitGroupings, SplitRouteIdentNodes } from './constants'\nimport type { GetRoutesByFileMapResultValue } from '@tanstack/router-generator'\nimport type { Config } from './config'\nimport type {\n UnpluginFactory,\n TransformResult as UnpluginTransformResult,\n} from 'unplugin'\n\nconst CODE_SPLITTER_PLUGIN_NAME =\n 'tanstack-router:code-splitter:compile-reference-file'\n\ntype TransformationPluginInfo = {\n pluginNames: Array<string>\n pkg: string\n usage: string\n}\n\n/**\n * JSX transformation plugins grouped by framework.\n * These plugins must come AFTER the TanStack Router plugin in the Vite config.\n */\nconst TRANSFORMATION_PLUGINS_BY_FRAMEWORK: Record<\n string,\n Array<TransformationPluginInfo>\n> = {\n react: [\n {\n // Babel-based React plugin\n pluginNames: ['vite:react-babel', 'vite:react-refresh'],\n pkg: '@vitejs/plugin-react',\n usage: 'react()',\n },\n {\n // SWC-based React plugin\n pluginNames: ['vite:react-swc', 'vite:react-swc:resolve-runtime'],\n pkg: '@vitejs/plugin-react-swc',\n usage: 'reactSwc()',\n },\n {\n // OXC-based React plugin (deprecated but should still be handled)\n pluginNames: ['vite:react-oxc:config', 'vite:react-oxc:refresh-runtime'],\n pkg: '@vitejs/plugin-react-oxc',\n usage: 'reactOxc()',\n },\n ],\n solid: [\n {\n pluginNames: ['solid'],\n pkg: 'vite-plugin-solid',\n usage: 'solid()',\n },\n ],\n}\n\nexport const unpluginRouterCodeSplitterFactory: UnpluginFactory<\n Partial<Config | (() => Config)> | undefined\n> = (options = {}, { framework: _framework }) => {\n let ROOT: string = process.cwd()\n let userConfig: Config\n\n function initUserConfig() {\n if (typeof options === 'function') {\n userConfig = options()\n } else {\n userConfig = getConfig(options, ROOT)\n }\n }\n const isProduction = process.env.NODE_ENV === 'production'\n // Map from normalized route file path → set of shared binding names.\n // Populated by the reference compiler, consumed by virtual and shared compilers.\n const sharedBindingsMap = new Map<string, Set<string>>()\n\n const getGlobalCodeSplitGroupings = () => {\n return (\n userConfig.codeSplittingOptions?.defaultBehavior ||\n defaultCodeSplitGroupings\n )\n }\n const getShouldSplitFn = () => {\n return userConfig.codeSplittingOptions?.splitBehavior\n }\n\n const handleCompilingReferenceFile = (\n code: string,\n id: string,\n generatorNodeInfo: GetRoutesByFileMapResultValue,\n ): UnpluginTransformResult => {\n if (debug) console.info('Compiling Route: ', id)\n\n const fromCode = detectCodeSplitGroupingsFromRoute({\n code,\n })\n\n if (fromCode.groupings !== undefined) {\n const res = splitGroupingsSchema.safeParse(fromCode.groupings)\n if (!res.success) {\n const message = res.error.errors.map((e) => e.message).join('. ')\n throw new Error(\n `The groupings for the route \"${id}\" are invalid.\\n${message}`,\n )\n }\n }\n\n const userShouldSplitFn = getShouldSplitFn()\n\n const pluginSplitBehavior = userShouldSplitFn?.({\n routeId: generatorNodeInfo.routeId,\n }) as CodeSplitGroupings | undefined\n\n if (pluginSplitBehavior) {\n const res = splitGroupingsSchema.safeParse(pluginSplitBehavior)\n if (!res.success) {\n const message = res.error.errors.map((e) => e.message).join('. ')\n throw new Error(\n `The groupings returned when using \\`splitBehavior\\` for the route \"${id}\" are invalid.\\n${message}`,\n )\n }\n }\n\n const splitGroupings: CodeSplitGroupings =\n fromCode.groupings ?? pluginSplitBehavior ?? getGlobalCodeSplitGroupings()\n\n // Compute shared bindings before compiling the reference route\n const sharedBindings = computeSharedBindings({\n code,\n codeSplitGroupings: splitGroupings,\n })\n if (sharedBindings.size > 0) {\n sharedBindingsMap.set(id, sharedBindings)\n } else {\n sharedBindingsMap.delete(id)\n }\n\n const addHmr =\n (userConfig.codeSplittingOptions?.addHmr ?? true) && !isProduction\n const hmrStyle = userConfig.plugin?.hmr?.style ?? 'vite'\n\n const compiledReferenceRoute = compileCodeSplitReferenceRoute({\n code,\n codeSplitGroupings: splitGroupings,\n targetFramework: userConfig.target,\n filename: id,\n id,\n deleteNodes: userConfig.codeSplittingOptions?.deleteNodes\n ? new Set(userConfig.codeSplittingOptions.deleteNodes)\n : undefined,\n addHmr,\n hmrStyle,\n hmrRouteId: generatorNodeInfo.routeId,\n sharedBindings: sharedBindings.size > 0 ? sharedBindings : undefined,\n compilerPlugins: getReferenceRouteCompilerPlugins({\n targetFramework: userConfig.target,\n addHmr,\n hmrStyle,\n }),\n })\n\n if (compiledReferenceRoute === null) {\n if (debug) {\n console.info(\n `No changes made to route \"${id}\", skipping code-splitting.`,\n )\n }\n return null\n }\n if (debug) {\n logDiff(code, compiledReferenceRoute.code)\n console.log('Output:\\n', compiledReferenceRoute.code + '\\n\\n')\n }\n\n return compiledReferenceRoute\n }\n\n const handleCompilingVirtualFile = (\n code: string,\n id: string,\n ): UnpluginTransformResult => {\n if (debug) console.info('Splitting Route: ', id)\n\n const [_, ...pathnameParts] = id.split('?')\n\n const searchParams = new URLSearchParams(pathnameParts.join('?'))\n const splitValue = searchParams.get(tsrSplit)\n\n if (!splitValue) {\n throw new Error(\n `The split value for the virtual route \"${id}\" was not found.`,\n )\n }\n\n const rawGrouping = decodeIdentifier(splitValue)\n const grouping = [...new Set(rawGrouping)].filter((p) =>\n splitRouteIdentNodes.includes(p as any),\n ) as Array<SplitRouteIdentNodes>\n\n const baseId = id.split('?')[0]!\n const resolvedSharedBindings = sharedBindingsMap.get(baseId)\n\n const result = compileCodeSplitVirtualRoute({\n code,\n filename: id,\n splitTargets: grouping,\n sharedBindings: resolvedSharedBindings,\n })\n\n if (debug) {\n logDiff(code, result.code)\n console.log('Output:\\n', result.code + '\\n\\n')\n }\n\n return result\n }\n\n const includedCode = [\n 'createFileRoute(',\n 'createRootRoute(',\n 'createRootRouteWithContext(',\n ]\n return [\n {\n name: 'tanstack-router:code-splitter:compile-reference-file',\n enforce: 'pre',\n\n transform: {\n filter: {\n id: {\n exclude: [tsrSplit, tsrShared],\n // this is necessary for webpack / rspack to avoid matching .html files\n include: /\\.(m|c)?(j|t)sx?$/,\n },\n code: {\n include: includedCode,\n },\n },\n handler(code, id) {\n const normalizedId = normalizePath(id)\n const generatorFileInfo =\n globalThis.TSR_ROUTES_BY_ID_MAP?.get(normalizedId)\n if (\n generatorFileInfo &&\n includedCode.some((included) => code.includes(included))\n ) {\n return handleCompilingReferenceFile(\n code,\n normalizedId,\n generatorFileInfo,\n )\n }\n\n return null\n },\n },\n\n vite: {\n configResolved(config) {\n ROOT = config.root\n initUserConfig()\n\n // Validate plugin order - router must come before JSX transformation plugins\n const routerPluginIndex = config.plugins.findIndex(\n (p) => p.name === CODE_SPLITTER_PLUGIN_NAME,\n )\n\n if (routerPluginIndex === -1) return\n\n const frameworkPlugins =\n TRANSFORMATION_PLUGINS_BY_FRAMEWORK[userConfig.target]\n if (!frameworkPlugins) return\n\n for (const transformPlugin of frameworkPlugins) {\n const transformPluginIndex = config.plugins.findIndex((p) =>\n transformPlugin.pluginNames.includes(p.name),\n )\n\n if (\n transformPluginIndex !== -1 &&\n transformPluginIndex < routerPluginIndex\n ) {\n throw new Error(\n `Plugin order error: '${transformPlugin.pkg}' is placed before '@tanstack/router-plugin'.\\n\\n` +\n `The TanStack Router plugin must come BEFORE JSX transformation plugins.\\n\\n` +\n `Please update your Vite config:\\n\\n` +\n ` plugins: [\\n` +\n ` tanstackRouter(),\\n` +\n ` ${transformPlugin.usage},\\n` +\n ` ]\\n`,\n )\n }\n }\n },\n applyToEnvironment(environment) {\n if (userConfig.plugin?.vite?.environmentName) {\n return userConfig.plugin.vite.environmentName === environment.name\n }\n return true\n },\n },\n\n rspack() {\n ROOT = process.cwd()\n initUserConfig()\n },\n\n webpack() {\n ROOT = process.cwd()\n initUserConfig()\n },\n },\n {\n name: 'tanstack-router:code-splitter:compile-virtual-file',\n enforce: 'pre',\n\n transform: {\n filter: {\n id: /tsr-split/,\n },\n handler(code, id) {\n const url = pathToFileURL(id)\n url.searchParams.delete('v')\n const normalizedId = normalizePath(fileURLToPath(url))\n return handleCompilingVirtualFile(code, normalizedId)\n },\n },\n\n vite: {\n applyToEnvironment(environment) {\n if (userConfig.plugin?.vite?.environmentName) {\n return userConfig.plugin.vite.environmentName === environment.name\n }\n return true\n },\n },\n },\n {\n name: 'tanstack-router:code-splitter:compile-shared-file',\n enforce: 'pre',\n\n transform: {\n filter: {\n id: /tsr-shared/,\n },\n handler(code, id) {\n const url = pathToFileURL(id)\n url.searchParams.delete('v')\n const normalizedId = normalizePath(fileURLToPath(url))\n const [baseId] = normalizedId.split('?')\n\n if (!baseId) return null\n\n const sharedBindings = sharedBindingsMap.get(baseId)\n if (!sharedBindings || sharedBindings.size === 0) return null\n\n if (debug) console.info('Compiling Shared Module: ', id)\n\n const result = compileCodeSplitSharedRoute({\n code,\n sharedBindings,\n filename: normalizedId,\n })\n\n if (debug) {\n logDiff(code, result.code)\n console.log('Output:\\n', result.code + '\\n\\n')\n }\n\n return result\n },\n },\n\n vite: {\n applyToEnvironment(environment) {\n if (userConfig.plugin?.vite?.environmentName) {\n return userConfig.plugin.vite.environmentName === environment.name\n }\n return true\n },\n },\n },\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;AAgCA,IAAM,4BACJ;;;;;AAYF,IAAM,sCAGF;CACF,OAAO;EACL;GAEE,aAAa,CAAC,oBAAoB,qBAAqB;GACvD,KAAK;GACL,OAAO;GACR;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AQ,MAAM,OAAO,KAAK;AAC1B,cAAQ,IAAI,aAAa,OAAO,OAAO,OAAO;;AAGhD,YAAO;;IAEV;GAED,MAAM,EACJ,mBAAmB,aAAa;AAC9B,QAAI,WAAW,QAAQ,MAAM,gBAC3B,QAAO,WAAW,OAAO,KAAK,oBAAoB,YAAY;AAEhE,WAAO;MAEV;GACF;EACF"}
|
|
1
|
+
{"version":3,"file":"router-code-splitter-plugin.cjs","names":[],"sources":["../../../src/core/router-code-splitter-plugin.ts"],"sourcesContent":["/**\n * It is important to familiarize yourself with how the code-splitting works in this plugin.\n * https://github.com/TanStack/router/pull/3355\n */\n\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { logDiff } from '@tanstack/router-utils'\nimport { getConfig, splitGroupingsSchema } from './config'\nimport {\n compileCodeSplitReferenceRoute,\n compileCodeSplitSharedRoute,\n compileCodeSplitVirtualRoute,\n computeSharedBindings,\n detectCodeSplitGroupingsFromRoute,\n} from './code-splitter/compilers'\nimport { getReferenceRouteCompilerPlugins } from './code-splitter/plugins/framework-plugins'\nimport {\n defaultCodeSplitGroupings,\n splitRouteIdentNodes,\n tsrShared,\n tsrSplit,\n} from './constants'\nimport { decodeIdentifier } from './code-splitter/path-ids'\nimport { debug, normalizePath } from './utils'\nimport { createRouterPluginContext } from './router-plugin-context'\nimport type { CodeSplitGroupings, SplitRouteIdentNodes } from './constants'\nimport type { GetRoutesByFileMapResultValue } from '@tanstack/router-generator'\nimport type { Config } from './config'\nimport type { RouterPluginContext } from './router-plugin-context'\nimport type {\n UnpluginFactory,\n TransformResult as UnpluginTransformResult,\n} from 'unplugin'\n\nconst CODE_SPLITTER_PLUGIN_NAME =\n 'tanstack-router:code-splitter:compile-reference-file'\n\ntype TransformationPluginInfo = {\n pluginNames: Array<string>\n pkg: string\n usage: string\n}\n\n/**\n * JSX transformation plugins grouped by framework.\n * These plugins must come AFTER the TanStack Router plugin in the Vite config.\n */\nconst TRANSFORMATION_PLUGINS_BY_FRAMEWORK: Record<\n string,\n Array<TransformationPluginInfo>\n> = {\n react: [\n {\n // Babel-based React plugin\n pluginNames: ['vite:react-babel', 'vite:react-refresh'],\n pkg: '@vitejs/plugin-react',\n usage: 'react()',\n },\n {\n // SWC-based React plugin\n pluginNames: ['vite:react-swc', 'vite:react-swc:resolve-runtime'],\n pkg: '@vitejs/plugin-react-swc',\n usage: 'reactSwc()',\n },\n {\n // OXC-based React plugin (deprecated but should still be handled)\n pluginNames: ['vite:react-oxc:config', 'vite:react-oxc:refresh-runtime'],\n pkg: '@vitejs/plugin-react-oxc',\n usage: 'reactOxc()',\n },\n ],\n solid: [\n {\n pluginNames: ['solid'],\n pkg: 'vite-plugin-solid',\n usage: 'solid()',\n },\n ],\n}\n\nexport function createRouterCodeSplitterPlugin(\n options: Partial<Config | (() => Config)> | undefined = {},\n routerPluginContext: RouterPluginContext,\n): ReturnType<UnpluginFactory<Partial<Config | (() => Config)> | undefined>> {\n let ROOT: string = process.cwd()\n let userConfig: Config\n\n function initUserConfig() {\n if (typeof options === 'function') {\n userConfig = options()\n } else {\n userConfig = getConfig(options, ROOT)\n }\n }\n const isProduction = process.env.NODE_ENV === 'production'\n // Map from normalized route file path → set of shared binding names.\n // Populated by the reference compiler, consumed by virtual and shared compilers.\n const sharedBindingsMap = new Map<string, Set<string>>()\n\n const getGlobalCodeSplitGroupings = () => {\n return (\n userConfig.codeSplittingOptions?.defaultBehavior ||\n defaultCodeSplitGroupings\n )\n }\n const getShouldSplitFn = () => {\n return userConfig.codeSplittingOptions?.splitBehavior\n }\n\n const handleCompilingReferenceFile = (\n code: string,\n id: string,\n generatorNodeInfo: GetRoutesByFileMapResultValue,\n ): UnpluginTransformResult => {\n if (debug) console.info('Compiling Route: ', id)\n\n const fromCode = detectCodeSplitGroupingsFromRoute({\n code,\n })\n\n if (fromCode.groupings !== undefined) {\n const res = splitGroupingsSchema.safeParse(fromCode.groupings)\n if (!res.success) {\n const message = res.error.errors.map((e) => e.message).join('. ')\n throw new Error(\n `The groupings for the route \"${id}\" are invalid.\\n${message}`,\n )\n }\n }\n\n const userShouldSplitFn = getShouldSplitFn()\n\n const pluginSplitBehavior = userShouldSplitFn?.({\n routeId: generatorNodeInfo.routeId,\n }) as CodeSplitGroupings | undefined\n\n if (pluginSplitBehavior) {\n const res = splitGroupingsSchema.safeParse(pluginSplitBehavior)\n if (!res.success) {\n const message = res.error.errors.map((e) => e.message).join('. ')\n throw new Error(\n `The groupings returned when using \\`splitBehavior\\` for the route \"${id}\" are invalid.\\n${message}`,\n )\n }\n }\n\n const splitGroupings: CodeSplitGroupings =\n fromCode.groupings ?? pluginSplitBehavior ?? getGlobalCodeSplitGroupings()\n\n // Compute shared bindings before compiling the reference route\n const sharedBindings = computeSharedBindings({\n code,\n codeSplitGroupings: splitGroupings,\n })\n if (sharedBindings.size > 0) {\n sharedBindingsMap.set(id, sharedBindings)\n } else {\n sharedBindingsMap.delete(id)\n }\n\n const addHmr =\n (userConfig.codeSplittingOptions?.addHmr ?? true) && !isProduction\n const hmrStyle = userConfig.plugin?.hmr?.style ?? 'vite'\n\n const compiledReferenceRoute = compileCodeSplitReferenceRoute({\n code,\n codeSplitGroupings: splitGroupings,\n targetFramework: userConfig.target,\n filename: id,\n id,\n deleteNodes: userConfig.codeSplittingOptions?.deleteNodes\n ? new Set(userConfig.codeSplittingOptions.deleteNodes)\n : undefined,\n addHmr,\n hmrStyle,\n hmrRouteId: generatorNodeInfo.routeId,\n sharedBindings: sharedBindings.size > 0 ? sharedBindings : undefined,\n compilerPlugins: getReferenceRouteCompilerPlugins({\n targetFramework: userConfig.target,\n addHmr,\n hmrStyle,\n }),\n })\n\n if (compiledReferenceRoute === null) {\n if (debug) {\n console.info(\n `No changes made to route \"${id}\", skipping code-splitting.`,\n )\n }\n return null\n }\n if (debug) {\n logDiff(code, compiledReferenceRoute.code)\n console.log('Output:\\n', compiledReferenceRoute.code + '\\n\\n')\n }\n\n return compiledReferenceRoute\n }\n\n const handleCompilingVirtualFile = (\n code: string,\n id: string,\n ): UnpluginTransformResult => {\n if (debug) console.info('Splitting Route: ', id)\n\n const [_, ...pathnameParts] = id.split('?')\n\n const searchParams = new URLSearchParams(pathnameParts.join('?'))\n const splitValue = searchParams.get(tsrSplit)\n\n if (!splitValue) {\n throw new Error(\n `The split value for the virtual route \"${id}\" was not found.`,\n )\n }\n\n const rawGrouping = decodeIdentifier(splitValue)\n const grouping = [...new Set(rawGrouping)].filter((p) =>\n splitRouteIdentNodes.includes(p as any),\n ) as Array<SplitRouteIdentNodes>\n\n const baseId = id.split('?')[0]!\n const resolvedSharedBindings = sharedBindingsMap.get(baseId)\n\n const result = compileCodeSplitVirtualRoute({\n code,\n filename: id,\n splitTargets: grouping,\n sharedBindings: resolvedSharedBindings,\n })\n\n if (debug) {\n logDiff(code, result.code)\n console.log('Output:\\n', result.code + '\\n\\n')\n }\n\n return result\n }\n\n const includedCode = [\n 'createFileRoute(',\n 'createRootRoute(',\n 'createRootRouteWithContext(',\n ]\n return [\n {\n name: 'tanstack-router:code-splitter:compile-reference-file',\n enforce: 'pre',\n\n transform: {\n filter: {\n id: {\n exclude: [tsrSplit, tsrShared],\n // this is necessary for webpack / rspack to avoid matching .html files\n include: /\\.(m|c)?(j|t)sx?$/,\n },\n code: {\n include: includedCode,\n },\n },\n handler(code, id) {\n const normalizedId = normalizePath(id)\n const generatorFileInfo =\n routerPluginContext.routesByFile.get(normalizedId)\n if (\n generatorFileInfo &&\n includedCode.some((included) => code.includes(included))\n ) {\n return handleCompilingReferenceFile(\n code,\n normalizedId,\n generatorFileInfo,\n )\n }\n\n return null\n },\n },\n\n vite: {\n configResolved(config) {\n ROOT = config.root\n initUserConfig()\n\n // Validate plugin order - router must come before JSX transformation plugins\n const routerPluginIndex = config.plugins.findIndex(\n (p) => p.name === CODE_SPLITTER_PLUGIN_NAME,\n )\n\n if (routerPluginIndex === -1) return\n\n const frameworkPlugins =\n TRANSFORMATION_PLUGINS_BY_FRAMEWORK[userConfig.target]\n if (!frameworkPlugins) return\n\n for (const transformPlugin of frameworkPlugins) {\n const transformPluginIndex = config.plugins.findIndex((p) =>\n transformPlugin.pluginNames.includes(p.name),\n )\n\n if (\n transformPluginIndex !== -1 &&\n transformPluginIndex < routerPluginIndex\n ) {\n throw new Error(\n `Plugin order error: '${transformPlugin.pkg}' is placed before '@tanstack/router-plugin'.\\n\\n` +\n `The TanStack Router plugin must come BEFORE JSX transformation plugins.\\n\\n` +\n `Please update your Vite config:\\n\\n` +\n ` plugins: [\\n` +\n ` tanstackRouter(),\\n` +\n ` ${transformPlugin.usage},\\n` +\n ` ]\\n`,\n )\n }\n }\n },\n applyToEnvironment(environment) {\n if (userConfig.plugin?.vite?.environmentName) {\n return userConfig.plugin.vite.environmentName === environment.name\n }\n return true\n },\n },\n\n rspack() {\n ROOT = process.cwd()\n initUserConfig()\n },\n\n webpack() {\n ROOT = process.cwd()\n initUserConfig()\n },\n },\n {\n name: 'tanstack-router:code-splitter:compile-virtual-file',\n enforce: 'pre',\n\n transform: {\n filter: {\n id: /tsr-split/,\n },\n handler(code, id) {\n const url = pathToFileURL(id)\n url.searchParams.delete('v')\n const normalizedId = normalizePath(fileURLToPath(url))\n return handleCompilingVirtualFile(code, normalizedId)\n },\n },\n\n vite: {\n applyToEnvironment(environment) {\n if (userConfig.plugin?.vite?.environmentName) {\n return userConfig.plugin.vite.environmentName === environment.name\n }\n return true\n },\n },\n },\n {\n name: 'tanstack-router:code-splitter:compile-shared-file',\n enforce: 'pre',\n\n transform: {\n filter: {\n id: /tsr-shared/,\n },\n handler(code, id) {\n const url = pathToFileURL(id)\n url.searchParams.delete('v')\n const normalizedId = normalizePath(fileURLToPath(url))\n const [baseId] = normalizedId.split('?')\n\n if (!baseId) return null\n\n const sharedBindings = sharedBindingsMap.get(baseId)\n if (!sharedBindings || sharedBindings.size === 0) return null\n\n if (debug) console.info('Compiling Shared Module: ', id)\n\n const result = compileCodeSplitSharedRoute({\n code,\n sharedBindings,\n filename: normalizedId,\n })\n\n if (debug) {\n logDiff(code, result.code)\n console.log('Output:\\n', result.code + '\\n\\n')\n }\n\n return result\n },\n },\n\n vite: {\n applyToEnvironment(environment) {\n if (userConfig.plugin?.vite?.environmentName) {\n return userConfig.plugin.vite.environmentName === environment.name\n }\n return true\n },\n },\n },\n ]\n}\n\nexport const unpluginRouterCodeSplitterFactory: UnpluginFactory<\n Partial<Config | (() => Config)> | undefined\n> = (options = {}) => {\n return createRouterCodeSplitterPlugin(options, createRouterPluginContext())\n}\n"],"mappings":";;;;;;;;;;;;;;;AAkCA,IAAM,4BACJ;;;;;AAYF,IAAM,sCAGF;CACF,OAAO;EACL;GAEE,aAAa,CAAC,oBAAoB,qBAAqB;GACvD,KAAK;GACL,OAAO;GACR;EACD;GAEE,aAAa,CAAC,kBAAkB,iCAAiC;GACjE,KAAK;GACL,OAAO;GACR;EACD;GAEE,aAAa,CAAC,yBAAyB,iCAAiC;GACxE,KAAK;GACL,OAAO;GACR;EACF;CACD,OAAO,CACL;EACE,aAAa,CAAC,QAAQ;EACtB,KAAK;EACL,OAAO;EACR,CACF;CACF;AAED,SAAgB,+BACd,UAAwD,EAAE,EAC1D,qBAC2E;CAC3E,IAAI,OAAe,QAAQ,KAAK;CAChC,IAAI;CAEJ,SAAS,iBAAiB;AACxB,MAAI,OAAO,YAAY,WACrB,cAAa,SAAS;MAEtB,cAAa,eAAA,UAAU,SAAS,KAAK;;CAGzC,MAAM,eAAA,QAAA,IAAA,aAAwC;CAG9C,MAAM,oCAAoB,IAAI,KAA0B;CAExD,MAAM,oCAAoC;AACxC,SACE,WAAW,sBAAsB,mBACjC,kBAAA;;CAGJ,MAAM,yBAAyB;AAC7B,SAAO,WAAW,sBAAsB;;CAG1C,MAAM,gCACJ,MACA,IACA,sBAC4B;AAC5B,MAAI,cAAA,MAAO,SAAQ,KAAK,qBAAqB,GAAG;EAEhD,MAAM,WAAW,kBAAA,kCAAkC,EACjD,MACD,CAAC;AAEF,MAAI,SAAS,cAAc,KAAA,GAAW;GACpC,MAAM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B,GAAG;AAC7B,SAAI,aAAa,OAAO,IAAI;KAC5B,MAAM,eAAe,cAAA,eAAA,GAAA,SAAA,eAA4B,IAAI,CAAC;KACtD,MAAM,CAAC,UAAU,aAAa,MAAM,IAAI;AAExC,SAAI,CAAC,OAAQ,QAAO;KAEpB,MAAM,iBAAiB,kBAAkB,IAAI,OAAO;AACpD,SAAI,CAAC,kBAAkB,eAAe,SAAS,EAAG,QAAO;AAEzD,SAAI,cAAA,MAAO,SAAQ,KAAK,6BAA6B,GAAG;KAExD,MAAM,SAAS,kBAAA,4BAA4B;MACzC;MACA;MACA,UAAU;MACX,CAAC;AAEF,SAAI,cAAA,OAAO;AACT,OAAA,GAAA,uBAAA,SAAQ,MAAM,OAAO,KAAK;AAC1B,cAAQ,IAAI,aAAa,OAAO,OAAO,OAAO;;AAGhD,YAAO;;IAEV;GAED,MAAM,EACJ,mBAAmB,aAAa;AAC9B,QAAI,WAAW,QAAQ,MAAM,gBAC3B,QAAO,WAAW,OAAO,KAAK,oBAAoB,YAAY;AAEhE,WAAO;MAEV;GACF;EACF;;AAGH,IAAa,qCAER,UAAU,EAAE,KAAK;AACpB,QAAO,+BAA+B,SAAS,8BAAA,2BAA2B,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { Config } from './config.cjs';
|
|
2
|
+
import { RouterPluginContext } from './router-plugin-context.cjs';
|
|
2
3
|
import { UnpluginFactory } from 'unplugin';
|
|
4
|
+
export declare function createRouterCodeSplitterPlugin(options: Partial<Config | (() => Config)> | undefined, routerPluginContext: RouterPluginContext): ReturnType<UnpluginFactory<Partial<Config | (() => Config)> | undefined>>;
|
|
3
5
|
export declare const unpluginRouterCodeSplitterFactory: UnpluginFactory<Partial<Config | (() => Config)> | undefined>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_router_plugin_context = require("./router-plugin-context.cjs");
|
|
2
3
|
const require_router_code_splitter_plugin = require("./router-code-splitter-plugin.cjs");
|
|
3
4
|
const require_router_generator_plugin = require("./router-generator-plugin.cjs");
|
|
4
5
|
const require_router_hmr_plugin = require("./router-hmr-plugin.cjs");
|
|
@@ -14,16 +15,16 @@ function applyWebpackInlineCssDefaultDefinePlugin(compiler) {
|
|
|
14
15
|
function applyRspackInlineCssDefaultDefinePlugin(compiler) {
|
|
15
16
|
new compiler.webpack.DefinePlugin(INLINE_CSS_DEFAULT_DEFINES).apply(compiler);
|
|
16
17
|
}
|
|
17
|
-
var unpluginRouterComposedFactory = (options = {},
|
|
18
|
+
var unpluginRouterComposedFactory = (options = {}, _meta) => {
|
|
18
19
|
const ROOT = process.cwd();
|
|
19
20
|
const userConfig = (0, _tanstack_router_generator.getConfig)(typeof options === "function" ? options() : options, ROOT);
|
|
20
|
-
const
|
|
21
|
-
|
|
21
|
+
const routerPluginContext = require_router_plugin_context.createRouterPluginContext();
|
|
22
|
+
const getPlugin = (plugin) => {
|
|
22
23
|
if (!Array.isArray(plugin)) return [plugin];
|
|
23
24
|
return plugin;
|
|
24
25
|
};
|
|
25
|
-
const routerGenerator = getPlugin(require_router_generator_plugin.
|
|
26
|
-
const routerCodeSplitter = getPlugin(require_router_code_splitter_plugin.
|
|
26
|
+
const routerGenerator = getPlugin(require_router_generator_plugin.createRouterGeneratorPlugin(options, routerPluginContext));
|
|
27
|
+
const routerCodeSplitter = getPlugin(require_router_code_splitter_plugin.createRouterCodeSplitterPlugin(options, routerPluginContext));
|
|
27
28
|
const result = [{
|
|
28
29
|
name: "tanstack:router-inline-css-defaults",
|
|
29
30
|
vite: { config() {
|
|
@@ -44,7 +45,7 @@ var unpluginRouterComposedFactory = (options = {}, meta) => {
|
|
|
44
45
|
}, ...routerGenerator];
|
|
45
46
|
if (userConfig.autoCodeSplitting) result.push(...routerCodeSplitter);
|
|
46
47
|
if (!(process.env.NODE_ENV === "production") && !userConfig.autoCodeSplitting) {
|
|
47
|
-
const routerHmr = getPlugin(require_router_hmr_plugin.
|
|
48
|
+
const routerHmr = getPlugin(require_router_hmr_plugin.createRouterHmrPlugin(options, routerPluginContext));
|
|
48
49
|
result.push(...routerHmr);
|
|
49
50
|
}
|
|
50
51
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-composed-plugin.cjs","names":[],"sources":["../../../src/core/router-composed-plugin.ts"],"sourcesContent":["import { getConfig } from '@tanstack/router-generator'\nimport {
|
|
1
|
+
{"version":3,"file":"router-composed-plugin.cjs","names":[],"sources":["../../../src/core/router-composed-plugin.ts"],"sourcesContent":["import { getConfig } from '@tanstack/router-generator'\nimport { createRouterGeneratorPlugin } from './router-generator-plugin'\nimport { createRouterCodeSplitterPlugin } from './router-code-splitter-plugin'\nimport { createRouterHmrPlugin } from './router-hmr-plugin'\nimport { createRouterPluginContext } from './router-plugin-context'\nimport type { Config } from './config'\nimport type {\n RspackCompiler,\n UnpluginFactory,\n UnpluginOptions,\n WebpackCompiler,\n} from 'unplugin'\n\nconst INLINE_CSS_DEFAULT_DEFINES = {\n 'process.env.TSS_INLINE_CSS_ENABLED': JSON.stringify('false'),\n 'import.meta.env.TSS_INLINE_CSS_ENABLED': JSON.stringify('false'),\n}\n\ntype EsbuildOptionsWithDefine = Parameters<\n NonNullable<NonNullable<UnpluginOptions['esbuild']>['config']>\n>[0]\n\nfunction applyWebpackInlineCssDefaultDefinePlugin(compiler: WebpackCompiler) {\n new compiler.webpack.DefinePlugin(INLINE_CSS_DEFAULT_DEFINES).apply(compiler)\n}\n\nfunction applyRspackInlineCssDefaultDefinePlugin(compiler: RspackCompiler) {\n new compiler.webpack.DefinePlugin(INLINE_CSS_DEFAULT_DEFINES).apply(compiler)\n}\n\nexport const unpluginRouterComposedFactory: UnpluginFactory<\n Partial<Config | (() => Config)> | undefined\n> = (options = {}, _meta) => {\n const ROOT: string = process.cwd()\n const userConfig = getConfig(\n (typeof options === 'function' ? options() : options) as Partial<Config>,\n ROOT,\n )\n const routerPluginContext = createRouterPluginContext()\n\n const getPlugin = (plugin: ReturnType<UnpluginFactory<any>>) => {\n if (!Array.isArray(plugin)) {\n return [plugin]\n }\n return plugin\n }\n\n const routerGenerator = getPlugin(\n createRouterGeneratorPlugin(options, routerPluginContext),\n )\n const routerCodeSplitter = getPlugin(\n createRouterCodeSplitterPlugin(options, routerPluginContext),\n )\n\n const result = [\n {\n name: 'tanstack:router-inline-css-defaults',\n vite: {\n config() {\n return {\n define: {\n ...INLINE_CSS_DEFAULT_DEFINES,\n },\n }\n },\n },\n webpack(compiler: WebpackCompiler) {\n applyWebpackInlineCssDefaultDefinePlugin(compiler)\n },\n rspack(compiler: RspackCompiler) {\n applyRspackInlineCssDefaultDefinePlugin(compiler)\n },\n esbuild: {\n config(options: EsbuildOptionsWithDefine) {\n options.define = {\n ...INLINE_CSS_DEFAULT_DEFINES,\n ...options.define,\n }\n },\n },\n },\n ...routerGenerator,\n ]\n if (userConfig.autoCodeSplitting) {\n result.push(...routerCodeSplitter)\n }\n\n const isProduction = process.env.NODE_ENV === 'production'\n\n if (!isProduction && !userConfig.autoCodeSplitting) {\n const routerHmr = getPlugin(\n createRouterHmrPlugin(options, routerPluginContext),\n )\n result.push(...routerHmr)\n }\n return result\n}\n"],"mappings":";;;;;;;AAaA,IAAM,6BAA6B;CACjC,sCAAsC,KAAK,UAAU,QAAQ;CAC7D,0CAA0C,KAAK,UAAU,QAAQ;CAClE;AAMD,SAAS,yCAAyC,UAA2B;AAC3E,KAAI,SAAS,QAAQ,aAAa,2BAA2B,CAAC,MAAM,SAAS;;AAG/E,SAAS,wCAAwC,UAA0B;AACzE,KAAI,SAAS,QAAQ,aAAa,2BAA2B,CAAC,MAAM,SAAS;;AAG/E,IAAa,iCAER,UAAU,EAAE,EAAE,UAAU;CAC3B,MAAM,OAAe,QAAQ,KAAK;CAClC,MAAM,cAAA,GAAA,2BAAA,WACH,OAAO,YAAY,aAAa,SAAS,GAAG,SAC7C,KACD;CACD,MAAM,sBAAsB,8BAAA,2BAA2B;CAEvD,MAAM,aAAa,WAA6C;AAC9D,MAAI,CAAC,MAAM,QAAQ,OAAO,CACxB,QAAO,CAAC,OAAO;AAEjB,SAAO;;CAGT,MAAM,kBAAkB,UACtB,gCAAA,4BAA4B,SAAS,oBAAoB,CAC1D;CACD,MAAM,qBAAqB,UACzB,oCAAA,+BAA+B,SAAS,oBAAoB,CAC7D;CAED,MAAM,SAAS,CACb;EACE,MAAM;EACN,MAAM,EACJ,SAAS;AACP,UAAO,EACL,QAAQ,EACN,GAAG,4BACJ,EACF;KAEJ;EACD,QAAQ,UAA2B;AACjC,4CAAyC,SAAS;;EAEpD,OAAO,UAA0B;AAC/B,2CAAwC,SAAS;;EAEnD,SAAS,EACP,OAAO,SAAmC;AACxC,WAAQ,SAAS;IACf,GAAG;IACH,GAAG,QAAQ;IACZ;KAEJ;EACF,EACD,GAAG,gBACJ;AACD,KAAI,WAAW,kBACb,QAAO,KAAK,GAAG,mBAAmB;AAKpC,KAAI,EAAA,QAAA,IAAA,aAF0C,iBAEzB,CAAC,WAAW,mBAAmB;EAClD,MAAM,YAAY,UAChB,0BAAA,sBAAsB,SAAS,oBAAoB,CACpD;AACD,SAAO,KAAK,GAAG,UAAU;;AAE3B,QAAO"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
const require_config = require("./config.cjs");
|
|
3
|
+
const require_router_plugin_context = require("./router-plugin-context.cjs");
|
|
3
4
|
let _tanstack_router_generator = require("@tanstack/router-generator");
|
|
4
5
|
let node_path = require("node:path");
|
|
5
6
|
//#region src/core/router-generator-plugin.ts
|
|
6
7
|
var PLUGIN_NAME = "unplugin:router-generator";
|
|
7
|
-
|
|
8
|
+
function createRouterGeneratorPlugin(options = {}, routerPluginContext) {
|
|
8
9
|
let ROOT = process.cwd();
|
|
9
10
|
let userConfig;
|
|
10
11
|
let generator;
|
|
@@ -37,7 +38,7 @@ var unpluginRouterGeneratorFactory = (options = {}) => {
|
|
|
37
38
|
}
|
|
38
39
|
try {
|
|
39
40
|
await generator.run(generatorEvent);
|
|
40
|
-
|
|
41
|
+
routerPluginContext.routesByFile = generator.getRoutesByFileMap();
|
|
41
42
|
} catch (e) {
|
|
42
43
|
console.error(e);
|
|
43
44
|
}
|
|
@@ -96,8 +97,12 @@ var unpluginRouterGeneratorFactory = (options = {}) => {
|
|
|
96
97
|
initConfigAndGenerator();
|
|
97
98
|
} }
|
|
98
99
|
};
|
|
100
|
+
}
|
|
101
|
+
var unpluginRouterGeneratorFactory = (options = {}) => {
|
|
102
|
+
return createRouterGeneratorPlugin(options, require_router_plugin_context.createRouterPluginContext());
|
|
99
103
|
};
|
|
100
104
|
//#endregion
|
|
105
|
+
exports.createRouterGeneratorPlugin = createRouterGeneratorPlugin;
|
|
101
106
|
exports.unpluginRouterGeneratorFactory = unpluginRouterGeneratorFactory;
|
|
102
107
|
|
|
103
108
|
//# sourceMappingURL=router-generator-plugin.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-generator-plugin.cjs","names":[],"sources":["../../../src/core/router-generator-plugin.ts"],"sourcesContent":["import { isAbsolute, join, normalize } from 'node:path'\nimport { Generator, resolveConfigPath } from '@tanstack/router-generator'\nimport { getConfig } from './config'\n\nimport type { GeneratorEvent } from '@tanstack/router-generator'\nimport type { FSWatcher } from 'chokidar'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { Config } from './config'\n\nconst PLUGIN_NAME = 'unplugin:router-generator'\n\nexport
|
|
1
|
+
{"version":3,"file":"router-generator-plugin.cjs","names":[],"sources":["../../../src/core/router-generator-plugin.ts"],"sourcesContent":["import { isAbsolute, join, normalize } from 'node:path'\nimport { Generator, resolveConfigPath } from '@tanstack/router-generator'\nimport { getConfig } from './config'\nimport { createRouterPluginContext } from './router-plugin-context'\n\nimport type { GeneratorEvent } from '@tanstack/router-generator'\nimport type { FSWatcher } from 'chokidar'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { Config } from './config'\nimport type { RouterPluginContext } from './router-plugin-context'\n\nconst PLUGIN_NAME = 'unplugin:router-generator'\n\nexport function createRouterGeneratorPlugin(\n options: Partial<Config | (() => Config)> | undefined = {},\n routerPluginContext: RouterPluginContext,\n): ReturnType<UnpluginFactory<Partial<Config | (() => Config)> | undefined>> {\n let ROOT: string = process.cwd()\n let userConfig: Config\n let generator: Generator\n\n const routeGenerationDisabled = () =>\n userConfig.enableRouteGeneration === false\n const getRoutesDirectoryPath = () => {\n return isAbsolute(userConfig.routesDirectory)\n ? userConfig.routesDirectory\n : join(ROOT, userConfig.routesDirectory)\n }\n\n const initConfigAndGenerator = (opts?: { root?: string }) => {\n if (opts?.root) {\n ROOT = opts.root\n }\n if (typeof options === 'function') {\n userConfig = options()\n } else {\n userConfig = getConfig(options, ROOT)\n }\n generator = new Generator({\n config: userConfig,\n root: ROOT,\n })\n }\n\n const generate = async (opts?: {\n file: string\n event: 'create' | 'update' | 'delete'\n }) => {\n if (routeGenerationDisabled()) {\n return\n }\n let generatorEvent: GeneratorEvent | undefined = undefined\n if (opts) {\n const filePath = normalize(opts.file)\n if (filePath === resolveConfigPath({ configDirectory: ROOT })) {\n initConfigAndGenerator()\n return\n }\n generatorEvent = { path: filePath, type: opts.event }\n }\n\n try {\n await generator.run(generatorEvent)\n routerPluginContext.routesByFile = generator.getRoutesByFileMap()\n } catch (e) {\n console.error(e)\n }\n }\n\n return {\n name: 'tanstack:router-generator',\n enforce: 'pre',\n async watchChange(id, { event }) {\n await generate({\n file: id,\n event,\n })\n },\n vite: {\n async configResolved(config) {\n initConfigAndGenerator({ root: config.root })\n await generate()\n },\n },\n rspack(compiler) {\n initConfigAndGenerator()\n\n let handle: FSWatcher | null = null\n\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, () => generate())\n\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (handle) {\n return\n }\n\n // rspack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n handle = chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', (file) => generate({ file, event: 'create' }))\n\n await generate()\n })\n\n compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {\n if (handle) {\n await handle.close()\n }\n })\n },\n webpack(compiler) {\n initConfigAndGenerator()\n\n let handle: FSWatcher | null = null\n\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, () => generate())\n\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (handle) {\n return\n }\n\n // webpack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n handle = chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', (file) => generate({ file, event: 'create' }))\n\n await generate()\n })\n\n compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {\n if (handle) {\n await handle.close()\n }\n })\n\n compiler.hooks.done.tap(PLUGIN_NAME, () => {\n console.info('✅ ' + PLUGIN_NAME + ': route-tree generation done')\n })\n },\n esbuild: {\n config() {\n initConfigAndGenerator()\n },\n },\n }\n}\n\nexport const unpluginRouterGeneratorFactory: UnpluginFactory<\n Partial<Config | (() => Config)> | undefined\n> = (options = {}) => {\n return createRouterGeneratorPlugin(options, createRouterPluginContext())\n}\n"],"mappings":";;;;;;AAWA,IAAM,cAAc;AAEpB,SAAgB,4BACd,UAAwD,EAAE,EAC1D,qBAC2E;CAC3E,IAAI,OAAe,QAAQ,KAAK;CAChC,IAAI;CACJ,IAAI;CAEJ,MAAM,gCACJ,WAAW,0BAA0B;CACvC,MAAM,+BAA+B;AACnC,UAAA,GAAA,UAAA,YAAkB,WAAW,gBAAgB,GACzC,WAAW,mBAAA,GAAA,UAAA,MACN,MAAM,WAAW,gBAAgB;;CAG5C,MAAM,0BAA0B,SAA6B;AAC3D,MAAI,MAAM,KACR,QAAO,KAAK;AAEd,MAAI,OAAO,YAAY,WACrB,cAAa,SAAS;MAEtB,cAAa,eAAA,UAA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,MAAM,UAAU,WAAW,mBAAmB,UAAU,CAAC;AAElE,YAAS,MAAM,SAAS,WAAW,aAAa,YAAY;AAC1D,QAAI,OACF;IAIF,MAAM,sBAAsB,wBAAwB;AAEpD,cADiB,MAAM,OAAO,aAE3B,MAAM,qBAAqB,EAAE,eAAe,MAAM,CAAC,CACnD,GAAG,QAAQ,SAAS,SAAS;KAAE;KAAM,OAAO;KAAU,CAAC,CAAC;AAE3D,UAAM,UAAU;KAChB;AAEF,YAAS,MAAM,WAAW,IAAI,aAAa,YAAY;AACrD,QAAI,OACF,OAAM,OAAO,OAAO;KAEtB;AAEF,YAAS,MAAM,KAAK,IAAI,mBAAmB;AACzC,YAAQ,KAAK,OAAO,cAAc,+BAA+B;KACjE;;EAEJ,SAAS,EACP,SAAS;AACP,2BAAwB;KAE3B;EACF;;AAGH,IAAa,kCAER,UAAU,EAAE,KAAK;AACpB,QAAO,4BAA4B,SAAS,8BAAA,2BAA2B,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { UnpluginFactory } from 'unplugin';
|
|
2
2
|
import { Config } from './config.cjs';
|
|
3
|
+
import { RouterPluginContext } from './router-plugin-context.cjs';
|
|
4
|
+
export declare function createRouterGeneratorPlugin(options: Partial<Config | (() => Config)> | undefined, routerPluginContext: RouterPluginContext): ReturnType<UnpluginFactory<Partial<Config | (() => Config)> | undefined>>;
|
|
3
5
|
export declare const unpluginRouterGeneratorFactory: UnpluginFactory<Partial<Config | (() => Config)> | undefined>;
|
|
@@ -16,9 +16,12 @@ var includeCode = [
|
|
|
16
16
|
"createRootRoute(",
|
|
17
17
|
"createRootRouteWithContext("
|
|
18
18
|
];
|
|
19
|
-
|
|
19
|
+
function createRouterHmrPlugin(options = {}, routerPluginContext) {
|
|
20
20
|
let ROOT = process.cwd();
|
|
21
|
-
|
|
21
|
+
const resolveUserConfig = () => {
|
|
22
|
+
return require_config.getConfig(typeof options === "function" ? options() : options, ROOT);
|
|
23
|
+
};
|
|
24
|
+
let userConfig = resolveUserConfig();
|
|
22
25
|
return {
|
|
23
26
|
name: "tanstack-router:hmr",
|
|
24
27
|
enforce: "pre",
|
|
@@ -29,7 +32,7 @@ var unpluginRouterHmrFactory = (options = {}) => {
|
|
|
29
32
|
},
|
|
30
33
|
handler(code, id) {
|
|
31
34
|
const normalizedId = require_utils.normalizePath(id);
|
|
32
|
-
const routeEntry =
|
|
35
|
+
const routeEntry = routerPluginContext.routesByFile.get(normalizedId);
|
|
33
36
|
if (!routeEntry) return null;
|
|
34
37
|
if (require_utils.debug) console.info("Adding HMR handling to route ", normalizedId);
|
|
35
38
|
const hmrStyle = userConfig.plugin?.hmr?.style ?? "vite";
|
|
@@ -79,7 +82,7 @@ var unpluginRouterHmrFactory = (options = {}) => {
|
|
|
79
82
|
vite: {
|
|
80
83
|
configResolved(config) {
|
|
81
84
|
ROOT = config.root;
|
|
82
|
-
userConfig =
|
|
85
|
+
userConfig = resolveUserConfig();
|
|
83
86
|
},
|
|
84
87
|
applyToEnvironment(environment) {
|
|
85
88
|
if (userConfig.plugin?.vite?.environmentName) return userConfig.plugin.vite.environmentName === environment.name;
|
|
@@ -87,8 +90,8 @@ var unpluginRouterHmrFactory = (options = {}) => {
|
|
|
87
90
|
}
|
|
88
91
|
}
|
|
89
92
|
};
|
|
90
|
-
}
|
|
93
|
+
}
|
|
91
94
|
//#endregion
|
|
92
|
-
exports.
|
|
95
|
+
exports.createRouterHmrPlugin = createRouterHmrPlugin;
|
|
93
96
|
|
|
94
97
|
//# sourceMappingURL=router-hmr-plugin.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-hmr-plugin.cjs","names":[],"sources":["../../../src/core/router-hmr-plugin.ts"],"sourcesContent":["import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'\nimport { compileCodeSplitReferenceRoute } from './code-splitter/compilers'\nimport { getReferenceRouteCompilerPlugins } from './code-splitter/plugins/framework-plugins'\nimport { createRouteHmrStatement } from './hmr'\nimport { debug, normalizePath } from './utils'\nimport { getConfig } from './config'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { Config } from './config'\n\n/**\n * This plugin adds HMR support for file routes.\n * It is only added to the composed plugin in dev when autoCodeSplitting is disabled, since the code splitting plugin\n * handles HMR for code-split routes itself.\n */\n\nconst includeCode = [\n 'createFileRoute(',\n 'createRootRoute(',\n 'createRootRouteWithContext(',\n]\nexport
|
|
1
|
+
{"version":3,"file":"router-hmr-plugin.cjs","names":[],"sources":["../../../src/core/router-hmr-plugin.ts"],"sourcesContent":["import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'\nimport { compileCodeSplitReferenceRoute } from './code-splitter/compilers'\nimport { getReferenceRouteCompilerPlugins } from './code-splitter/plugins/framework-plugins'\nimport { createRouteHmrStatement } from './hmr'\nimport { debug, normalizePath } from './utils'\nimport { getConfig } from './config'\nimport { createRouterPluginContext } from './router-plugin-context'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { Config } from './config'\nimport type { RouterPluginContext } from './router-plugin-context'\n\n/**\n * This plugin adds HMR support for file routes.\n * It is only added to the composed plugin in dev when autoCodeSplitting is disabled, since the code splitting plugin\n * handles HMR for code-split routes itself.\n */\n\nconst includeCode = [\n 'createFileRoute(',\n 'createRootRoute(',\n 'createRootRouteWithContext(',\n]\n\nexport function createRouterHmrPlugin(\n options: Partial<Config | (() => Config)> | undefined = {},\n routerPluginContext: RouterPluginContext,\n): ReturnType<UnpluginFactory<Partial<Config> | undefined>> {\n let ROOT: string = process.cwd()\n\n const resolveUserConfig = () => {\n return getConfig(typeof options === 'function' ? options() : options, ROOT)\n }\n\n let userConfig = resolveUserConfig()\n\n return {\n name: 'tanstack-router:hmr',\n enforce: 'pre',\n transform: {\n filter: {\n // this is necessary for webpack / rspack to avoid matching .html files\n id: /\\.(m|c)?(j|t)sx?$/,\n code: {\n include: includeCode,\n },\n },\n handler(code, id) {\n const normalizedId = normalizePath(id)\n const routeEntry = routerPluginContext.routesByFile.get(normalizedId)\n if (!routeEntry) {\n return null\n }\n\n if (debug) console.info('Adding HMR handling to route ', normalizedId)\n\n const hmrStyle = userConfig.plugin?.hmr?.style ?? 'vite'\n\n if (userConfig.target === 'react') {\n const compilerPlugins = getReferenceRouteCompilerPlugins({\n targetFramework: 'react',\n addHmr: true,\n hmrStyle,\n })\n const compiled = compileCodeSplitReferenceRoute({\n code,\n filename: normalizedId,\n id: normalizedId,\n addHmr: true,\n hmrStyle,\n hmrRouteId: routeEntry.routeId,\n codeSplitGroupings: [],\n targetFramework: 'react',\n compilerPlugins,\n })\n\n if (compiled) {\n if (debug) {\n logDiff(code, compiled.code)\n console.log('Output:\\n', compiled.code + '\\n\\n')\n }\n\n return compiled\n }\n }\n\n const ast = parseAst({ code })\n ast.program.body.push(\n ...createRouteHmrStatement([], {\n hmrStyle,\n targetFramework: userConfig.target,\n routeId: routeEntry.routeId,\n }),\n )\n const result = generateFromAst(ast, {\n sourceMaps: true,\n filename: normalizedId,\n sourceFileName: normalizedId,\n })\n if (debug) {\n logDiff(code, result.code)\n console.log('Output:\\n', result.code + '\\n\\n')\n }\n return result\n },\n },\n vite: {\n configResolved(config) {\n ROOT = config.root\n userConfig = resolveUserConfig()\n },\n applyToEnvironment(environment) {\n if (userConfig.plugin?.vite?.environmentName) {\n return userConfig.plugin.vite.environmentName === environment.name\n }\n return true\n },\n },\n }\n}\n\nexport const unpluginRouterHmrFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}) => {\n return createRouterHmrPlugin(options, createRouterPluginContext())\n}\n"],"mappings":";;;;;;;;;;;;;AAiBA,IAAM,cAAc;CAClB;CACA;CACA;CACD;AAED,SAAgB,sBACd,UAAwD,EAAE,EAC1D,qBAC0D;CAC1D,IAAI,OAAe,QAAQ,KAAK;CAEhC,MAAM,0BAA0B;AAC9B,SAAO,eAAA,UAAU,OAAO,YAAY,aAAa,SAAS,GAAG,SAAS,KAAK;;CAG7E,IAAI,aAAa,mBAAmB;AAEpC,QAAO;EACL,MAAM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,QAAI,WAAW,QAAQ,MAAM,gBAC3B,QAAO,WAAW,OAAO,KAAK,oBAAoB,YAAY;AAEhE,WAAO;;GAEV;EACF"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { UnpluginFactory } from 'unplugin';
|
|
2
2
|
import { Config } from './config.cjs';
|
|
3
|
+
import { RouterPluginContext } from './router-plugin-context.cjs';
|
|
4
|
+
export declare function createRouterHmrPlugin(options: Partial<Config | (() => Config)> | undefined, routerPluginContext: RouterPluginContext): ReturnType<UnpluginFactory<Partial<Config> | undefined>>;
|
|
3
5
|
export declare const unpluginRouterHmrFactory: UnpluginFactory<Partial<Config> | undefined>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/core/router-plugin-context.ts
|
|
2
|
+
function createRouterPluginContext() {
|
|
3
|
+
return { routesByFile: /* @__PURE__ */ new Map() };
|
|
4
|
+
}
|
|
5
|
+
//#endregion
|
|
6
|
+
exports.createRouterPluginContext = createRouterPluginContext;
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=router-plugin-context.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-plugin-context.cjs","names":[],"sources":["../../../src/core/router-plugin-context.ts"],"sourcesContent":["import type { GetRoutesByFileMapResult } from '@tanstack/router-generator'\n\nexport type RouterPluginContext = {\n routesByFile: GetRoutesByFileMapResult\n}\n\nexport function createRouterPluginContext(): RouterPluginContext {\n return {\n routesByFile: new Map(),\n }\n}\n"],"mappings":";AAMA,SAAgB,4BAAiD;AAC/D,QAAO,EACL,8BAAc,IAAI,KAAK,EACxB"}
|
package/dist/cjs/esbuild.cjs
CHANGED
|
@@ -4,11 +4,13 @@ Object.defineProperties(exports, {
|
|
|
4
4
|
});
|
|
5
5
|
require("./_virtual/_rolldown/runtime.cjs");
|
|
6
6
|
const require_config = require("./core/config.cjs");
|
|
7
|
+
const require_router_plugin_context = require("./core/router-plugin-context.cjs");
|
|
7
8
|
const require_router_code_splitter_plugin = require("./core/router-code-splitter-plugin.cjs");
|
|
8
9
|
const require_router_generator_plugin = require("./core/router-generator-plugin.cjs");
|
|
9
10
|
const require_router_composed_plugin = require("./core/router-composed-plugin.cjs");
|
|
10
11
|
let unplugin = require("unplugin");
|
|
11
12
|
//#region src/esbuild.ts
|
|
13
|
+
var defaultRouterPluginContext = require_router_plugin_context.createRouterPluginContext();
|
|
12
14
|
/**
|
|
13
15
|
* @example
|
|
14
16
|
* ```ts
|
|
@@ -18,7 +20,10 @@ let unplugin = require("unplugin");
|
|
|
18
20
|
* }
|
|
19
21
|
* ```
|
|
20
22
|
*/
|
|
21
|
-
var TanStackRouterGeneratorEsbuild = (
|
|
23
|
+
var TanStackRouterGeneratorEsbuild = (options, routerPluginContext) => {
|
|
24
|
+
const pluginContext = routerPluginContext ?? defaultRouterPluginContext;
|
|
25
|
+
return (0, unplugin.createEsbuildPlugin)((pluginOptions) => require_router_generator_plugin.createRouterGeneratorPlugin(pluginOptions, pluginContext))(options);
|
|
26
|
+
};
|
|
22
27
|
/**
|
|
23
28
|
* @example
|
|
24
29
|
* ```ts
|
|
@@ -28,7 +33,10 @@ var TanStackRouterGeneratorEsbuild = (0, unplugin.createEsbuildPlugin)(require_r
|
|
|
28
33
|
* }
|
|
29
34
|
* ```
|
|
30
35
|
*/
|
|
31
|
-
var TanStackRouterCodeSplitterEsbuild = (
|
|
36
|
+
var TanStackRouterCodeSplitterEsbuild = (options, routerPluginContext) => {
|
|
37
|
+
const pluginContext = routerPluginContext ?? defaultRouterPluginContext;
|
|
38
|
+
return (0, unplugin.createEsbuildPlugin)((pluginOptions) => require_router_code_splitter_plugin.createRouterCodeSplitterPlugin(pluginOptions, pluginContext))(options);
|
|
39
|
+
};
|
|
32
40
|
/**
|
|
33
41
|
* @example
|
|
34
42
|
* ```ts
|
package/dist/cjs/esbuild.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esbuild.cjs","names":[],"sources":["../../src/esbuild.ts"],"sourcesContent":["import { createEsbuildPlugin } from 'unplugin'\n\nimport { configSchema } from './core/config'\nimport {
|
|
1
|
+
{"version":3,"file":"esbuild.cjs","names":[],"sources":["../../src/esbuild.ts"],"sourcesContent":["import { createEsbuildPlugin } from 'unplugin'\n\nimport { configSchema } from './core/config'\nimport { createRouterCodeSplitterPlugin } from './core/router-code-splitter-plugin'\nimport { createRouterGeneratorPlugin } from './core/router-generator-plugin'\nimport { unpluginRouterComposedFactory } from './core/router-composed-plugin'\nimport { createRouterPluginContext } from './core/router-plugin-context'\n\nimport type { CodeSplittingOptions, Config } from './core/config'\nimport type { RouterPluginContext } from './core/router-plugin-context'\n\ntype RouterPluginOptions = Partial<Config | (() => Config)> | undefined\n\nconst defaultRouterPluginContext = createRouterPluginContext()\n\n/**\n * @example\n * ```ts\n * export default {\n * plugins: [TanStackRouterGeneratorEsbuild()],\n * // ...\n * }\n * ```\n */\nconst TanStackRouterGeneratorEsbuild = (\n options?: RouterPluginOptions,\n routerPluginContext?: RouterPluginContext,\n) => {\n const pluginContext = routerPluginContext ?? defaultRouterPluginContext\n return createEsbuildPlugin((pluginOptions: RouterPluginOptions) =>\n createRouterGeneratorPlugin(pluginOptions, pluginContext),\n )(options)\n}\n\n/**\n * @example\n * ```ts\n * export default {\n * plugins: [TanStackRouterCodeSplitterEsbuild()],\n * // ...\n * }\n * ```\n */\nconst TanStackRouterCodeSplitterEsbuild = (\n options?: RouterPluginOptions,\n routerPluginContext?: RouterPluginContext,\n) => {\n const pluginContext = routerPluginContext ?? defaultRouterPluginContext\n return createEsbuildPlugin((pluginOptions: RouterPluginOptions) =>\n createRouterCodeSplitterPlugin(pluginOptions, pluginContext),\n )(options)\n}\n\n/**\n * @example\n * ```ts\n * export default {\n * plugins: [tanstackRouter()],\n * // ...\n * }\n * ```\n */\nconst TanStackRouterEsbuild = createEsbuildPlugin(unpluginRouterComposedFactory)\nconst tanstackRouter = TanStackRouterEsbuild\nexport default TanStackRouterEsbuild\n\nexport {\n configSchema,\n TanStackRouterGeneratorEsbuild,\n TanStackRouterCodeSplitterEsbuild,\n TanStackRouterEsbuild,\n tanstackRouter,\n}\n\nexport type { Config, CodeSplittingOptions, RouterPluginContext }\n"],"mappings":";;;;;;;;;;;;AAaA,IAAM,6BAA6B,8BAAA,2BAA2B;;;;;;;;;;AAW9D,IAAM,kCACJ,SACA,wBACG;CACH,MAAM,gBAAgB,uBAAuB;AAC7C,SAAA,GAAA,SAAA,sBAA4B,kBAC1B,gCAAA,4BAA4B,eAAe,cAAc,CAC1D,CAAC,QAAQ;;;;;;;;;;;AAYZ,IAAM,qCACJ,SACA,wBACG;CACH,MAAM,gBAAgB,uBAAuB;AAC7C,SAAA,GAAA,SAAA,sBAA4B,kBAC1B,oCAAA,+BAA+B,eAAe,cAAc,CAC7D,CAAC,QAAQ;;;;;;;;;;;AAYZ,IAAM,yBAAA,GAAA,SAAA,qBAA4C,+BAAA,8BAA8B;AAChF,IAAM,iBAAiB"}
|
package/dist/cjs/esbuild.d.cts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { configSchema, CodeSplittingOptions, Config } from './core/config.cjs';
|
|
2
|
+
import { RouterPluginContext } from './core/router-plugin-context.cjs';
|
|
3
|
+
type RouterPluginOptions = Partial<Config | (() => Config)> | undefined;
|
|
2
4
|
/**
|
|
3
5
|
* @example
|
|
4
6
|
* ```ts
|
|
@@ -8,53 +10,7 @@ import { configSchema, CodeSplittingOptions, Config } from './core/config.cjs';
|
|
|
8
10
|
* }
|
|
9
11
|
* ```
|
|
10
12
|
*/
|
|
11
|
-
declare const TanStackRouterGeneratorEsbuild: (options?:
|
|
12
|
-
target: "react" | "solid" | "vue";
|
|
13
|
-
routeFileIgnorePrefix: string;
|
|
14
|
-
routesDirectory: string;
|
|
15
|
-
quoteStyle: "single" | "double";
|
|
16
|
-
semicolons: boolean;
|
|
17
|
-
disableLogging: boolean;
|
|
18
|
-
routeTreeFileHeader: string[];
|
|
19
|
-
indexToken: string | RegExp | {
|
|
20
|
-
regex: string;
|
|
21
|
-
flags?: string | undefined;
|
|
22
|
-
};
|
|
23
|
-
routeToken: string | RegExp | {
|
|
24
|
-
regex: string;
|
|
25
|
-
flags?: string | undefined;
|
|
26
|
-
};
|
|
27
|
-
generatedRouteTree: string;
|
|
28
|
-
disableTypes: boolean;
|
|
29
|
-
addExtensions: string | boolean;
|
|
30
|
-
enableRouteTreeFormatting: boolean;
|
|
31
|
-
tmpDir: string;
|
|
32
|
-
importRoutesUsingAbsolutePaths: boolean;
|
|
33
|
-
enableRouteGeneration?: boolean | undefined;
|
|
34
|
-
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
35
|
-
plugin?: {
|
|
36
|
-
vite?: {
|
|
37
|
-
environmentName?: string | undefined;
|
|
38
|
-
} | undefined;
|
|
39
|
-
hmr?: {
|
|
40
|
-
style?: "vite" | "webpack" | undefined;
|
|
41
|
-
} | undefined;
|
|
42
|
-
} | undefined;
|
|
43
|
-
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
44
|
-
routeFilePrefix?: string | undefined;
|
|
45
|
-
routeFileIgnorePattern?: string | undefined;
|
|
46
|
-
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
47
|
-
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
48
|
-
autoCodeSplitting?: boolean | undefined;
|
|
49
|
-
customScaffolding?: {
|
|
50
|
-
routeTemplate?: string | undefined;
|
|
51
|
-
lazyRouteTemplate?: string | undefined;
|
|
52
|
-
} | undefined;
|
|
53
|
-
experimental?: {
|
|
54
|
-
enableCodeSplitting?: boolean | undefined;
|
|
55
|
-
} | undefined;
|
|
56
|
-
plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
|
|
57
|
-
} | (() => Config)> | undefined) => import('unplugin').EsbuildPlugin;
|
|
13
|
+
declare const TanStackRouterGeneratorEsbuild: (options?: RouterPluginOptions, routerPluginContext?: RouterPluginContext) => import('unplugin').EsbuildPlugin;
|
|
58
14
|
/**
|
|
59
15
|
* @example
|
|
60
16
|
* ```ts
|
|
@@ -64,53 +20,7 @@ declare const TanStackRouterGeneratorEsbuild: (options?: Partial<{
|
|
|
64
20
|
* }
|
|
65
21
|
* ```
|
|
66
22
|
*/
|
|
67
|
-
declare const TanStackRouterCodeSplitterEsbuild: (options?:
|
|
68
|
-
target: "react" | "solid" | "vue";
|
|
69
|
-
routeFileIgnorePrefix: string;
|
|
70
|
-
routesDirectory: string;
|
|
71
|
-
quoteStyle: "single" | "double";
|
|
72
|
-
semicolons: boolean;
|
|
73
|
-
disableLogging: boolean;
|
|
74
|
-
routeTreeFileHeader: string[];
|
|
75
|
-
indexToken: string | RegExp | {
|
|
76
|
-
regex: string;
|
|
77
|
-
flags?: string | undefined;
|
|
78
|
-
};
|
|
79
|
-
routeToken: string | RegExp | {
|
|
80
|
-
regex: string;
|
|
81
|
-
flags?: string | undefined;
|
|
82
|
-
};
|
|
83
|
-
generatedRouteTree: string;
|
|
84
|
-
disableTypes: boolean;
|
|
85
|
-
addExtensions: string | boolean;
|
|
86
|
-
enableRouteTreeFormatting: boolean;
|
|
87
|
-
tmpDir: string;
|
|
88
|
-
importRoutesUsingAbsolutePaths: boolean;
|
|
89
|
-
enableRouteGeneration?: boolean | undefined;
|
|
90
|
-
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
91
|
-
plugin?: {
|
|
92
|
-
vite?: {
|
|
93
|
-
environmentName?: string | undefined;
|
|
94
|
-
} | undefined;
|
|
95
|
-
hmr?: {
|
|
96
|
-
style?: "vite" | "webpack" | undefined;
|
|
97
|
-
} | undefined;
|
|
98
|
-
} | undefined;
|
|
99
|
-
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
100
|
-
routeFilePrefix?: string | undefined;
|
|
101
|
-
routeFileIgnorePattern?: string | undefined;
|
|
102
|
-
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
103
|
-
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
104
|
-
autoCodeSplitting?: boolean | undefined;
|
|
105
|
-
customScaffolding?: {
|
|
106
|
-
routeTemplate?: string | undefined;
|
|
107
|
-
lazyRouteTemplate?: string | undefined;
|
|
108
|
-
} | undefined;
|
|
109
|
-
experimental?: {
|
|
110
|
-
enableCodeSplitting?: boolean | undefined;
|
|
111
|
-
} | undefined;
|
|
112
|
-
plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
|
|
113
|
-
} | (() => Config)> | undefined) => import('unplugin').EsbuildPlugin;
|
|
23
|
+
declare const TanStackRouterCodeSplitterEsbuild: (options?: RouterPluginOptions, routerPluginContext?: RouterPluginContext) => import('unplugin').EsbuildPlugin;
|
|
114
24
|
/**
|
|
115
25
|
* @example
|
|
116
26
|
* ```ts
|
|
@@ -216,4 +126,4 @@ declare const tanstackRouter: (options?: Partial<{
|
|
|
216
126
|
} | (() => Config)> | undefined) => import('unplugin').EsbuildPlugin;
|
|
217
127
|
export default TanStackRouterEsbuild;
|
|
218
128
|
export { configSchema, TanStackRouterGeneratorEsbuild, TanStackRouterCodeSplitterEsbuild, TanStackRouterEsbuild, tanstackRouter, };
|
|
219
|
-
export type { Config, CodeSplittingOptions };
|
|
129
|
+
export type { Config, CodeSplittingOptions, RouterPluginContext };
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_config = require("./core/config.cjs");
|
|
3
3
|
const require_constants = require("./core/constants.cjs");
|
|
4
|
+
const require_router_plugin_context = require("./core/router-plugin-context.cjs");
|
|
4
5
|
const require_router_code_splitter_plugin = require("./core/router-code-splitter-plugin.cjs");
|
|
5
6
|
const require_router_generator_plugin = require("./core/router-generator-plugin.cjs");
|
|
6
7
|
exports.configSchema = require_config.configSchema;
|
|
8
|
+
exports.createRouterPluginContext = require_router_plugin_context.createRouterPluginContext;
|
|
7
9
|
exports.defaultCodeSplitGroupings = require_constants.defaultCodeSplitGroupings;
|
|
8
10
|
exports.getConfig = require_config.getConfig;
|
|
9
11
|
exports.splitRouteIdentNodes = require_constants.splitRouteIdentNodes;
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { configSchema, getConfig } from './core/config.cjs';
|
|
2
2
|
export { unpluginRouterCodeSplitterFactory } from './core/router-code-splitter-plugin.cjs';
|
|
3
3
|
export { unpluginRouterGeneratorFactory } from './core/router-generator-plugin.cjs';
|
|
4
|
+
export { createRouterPluginContext } from './core/router-plugin-context.cjs';
|
|
4
5
|
export type { Config, ConfigInput, ConfigOutput, CodeSplittingOptions, DeletableNodes, HmrOptions, } from './core/config.cjs';
|
|
6
|
+
export type { RouterPluginContext } from './core/router-plugin-context.cjs';
|
|
5
7
|
export { tsrSplit, splitRouteIdentNodes, defaultCodeSplitGroupings, } from './core/constants.cjs';
|
package/dist/cjs/rspack.cjs
CHANGED
|
@@ -4,11 +4,13 @@ Object.defineProperties(exports, {
|
|
|
4
4
|
});
|
|
5
5
|
require("./_virtual/_rolldown/runtime.cjs");
|
|
6
6
|
const require_config = require("./core/config.cjs");
|
|
7
|
+
const require_router_plugin_context = require("./core/router-plugin-context.cjs");
|
|
7
8
|
const require_router_code_splitter_plugin = require("./core/router-code-splitter-plugin.cjs");
|
|
8
9
|
const require_router_generator_plugin = require("./core/router-generator-plugin.cjs");
|
|
9
10
|
const require_router_composed_plugin = require("./core/router-composed-plugin.cjs");
|
|
10
11
|
let unplugin = require("unplugin");
|
|
11
12
|
//#region src/rspack.ts
|
|
13
|
+
var defaultRouterPluginContext = require_router_plugin_context.createRouterPluginContext();
|
|
12
14
|
/**
|
|
13
15
|
* Rspack uses webpack-compatible `module.hot` / `import.meta.webpackHot` HMR.
|
|
14
16
|
* Force `plugin.hmr.style = 'webpack'` so the router HMR adapter emits
|
|
@@ -42,7 +44,10 @@ function withWebpackHmrStyle(options) {
|
|
|
42
44
|
* })
|
|
43
45
|
* ```
|
|
44
46
|
*/
|
|
45
|
-
var TanStackRouterGeneratorRspack =
|
|
47
|
+
var TanStackRouterGeneratorRspack = (options, routerPluginContext) => {
|
|
48
|
+
const pluginContext = routerPluginContext ?? defaultRouterPluginContext;
|
|
49
|
+
return (0, unplugin.createRspackPlugin)((pluginOptions) => require_router_generator_plugin.createRouterGeneratorPlugin(pluginOptions, pluginContext))(options);
|
|
50
|
+
};
|
|
46
51
|
/**
|
|
47
52
|
* @example
|
|
48
53
|
* ```ts
|
|
@@ -56,7 +61,10 @@ var TanStackRouterGeneratorRspack = /* @__PURE__ */ (0, unplugin.createRspackPlu
|
|
|
56
61
|
* })
|
|
57
62
|
* ```
|
|
58
63
|
*/
|
|
59
|
-
var TanStackRouterCodeSplitterRspack =
|
|
64
|
+
var TanStackRouterCodeSplitterRspack = (options, routerPluginContext) => {
|
|
65
|
+
const pluginContext = routerPluginContext ?? defaultRouterPluginContext;
|
|
66
|
+
return (0, unplugin.createRspackPlugin)((pluginOptions) => require_router_code_splitter_plugin.createRouterCodeSplitterPlugin(withWebpackHmrStyle(pluginOptions), pluginContext))(options);
|
|
67
|
+
};
|
|
60
68
|
/**
|
|
61
69
|
* @example
|
|
62
70
|
* ```ts
|