@tanstack/router-plugin 1.166.10 → 1.166.11
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/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/cjs/core/code-splitter/compilers.cjs +866 -1324
- package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/framework-options.cjs +39 -41
- package/dist/cjs/core/code-splitter/framework-options.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/path-ids.cjs +26 -31
- package/dist/cjs/core/code-splitter/path-ids.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/plugins/framework-plugins.cjs +11 -14
- package/dist/cjs/core/code-splitter/plugins/framework-plugins.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/plugins/react-refresh-route-components.cjs +31 -65
- package/dist/cjs/core/code-splitter/plugins/react-refresh-route-components.cjs.map +1 -1
- package/dist/cjs/core/config.cjs +36 -46
- package/dist/cjs/core/config.cjs.map +1 -1
- package/dist/cjs/core/constants.cjs +16 -15
- package/dist/cjs/core/constants.cjs.map +1 -1
- package/dist/cjs/core/route-autoimport-plugin.cjs +81 -115
- package/dist/cjs/core/route-autoimport-plugin.cjs.map +1 -1
- package/dist/cjs/core/route-hmr-statement.cjs +34 -56
- package/dist/cjs/core/route-hmr-statement.cjs.map +1 -1
- package/dist/cjs/core/router-code-splitter-plugin.cjs +236 -306
- package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-composed-plugin.cjs +28 -34
- package/dist/cjs/core/router-composed-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-generator-plugin.cjs +101 -133
- package/dist/cjs/core/router-generator-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-hmr-plugin.cjs +81 -81
- package/dist/cjs/core/router-hmr-plugin.cjs.map +1 -1
- package/dist/cjs/core/utils.cjs +23 -30
- package/dist/cjs/core/utils.cjs.map +1 -1
- package/dist/cjs/esbuild.cjs +47 -18
- package/dist/cjs/esbuild.cjs.map +1 -1
- package/dist/cjs/index.cjs +11 -13
- package/dist/cjs/rspack.cjs +58 -19
- package/dist/cjs/rspack.cjs.map +1 -1
- package/dist/cjs/vite.cjs +52 -20
- package/dist/cjs/vite.cjs.map +1 -1
- package/dist/cjs/webpack.cjs +46 -19
- package/dist/cjs/webpack.cjs.map +1 -1
- package/dist/esm/core/code-splitter/compilers.js +859 -1307
- package/dist/esm/core/code-splitter/compilers.js.map +1 -1
- package/dist/esm/core/code-splitter/framework-options.js +40 -42
- package/dist/esm/core/code-splitter/framework-options.js.map +1 -1
- package/dist/esm/core/code-splitter/path-ids.js +27 -33
- package/dist/esm/core/code-splitter/path-ids.js.map +1 -1
- package/dist/esm/core/code-splitter/plugins/framework-plugins.js +11 -14
- package/dist/esm/core/code-splitter/plugins/framework-plugins.js.map +1 -1
- package/dist/esm/core/code-splitter/plugins/react-refresh-route-components.js +29 -48
- package/dist/esm/core/code-splitter/plugins/react-refresh-route-components.js.map +1 -1
- package/dist/esm/core/config.js +35 -48
- package/dist/esm/core/config.js.map +1 -1
- package/dist/esm/core/constants.js +17 -19
- package/dist/esm/core/constants.js.map +1 -1
- package/dist/esm/core/route-autoimport-plugin.js +78 -98
- package/dist/esm/core/route-autoimport-plugin.js.map +1 -1
- package/dist/esm/core/route-hmr-statement.js +32 -39
- package/dist/esm/core/route-hmr-statement.js.map +1 -1
- package/dist/esm/core/router-code-splitter-plugin.js +234 -305
- package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
- package/dist/esm/core/router-composed-plugin.js +25 -32
- package/dist/esm/core/router-composed-plugin.js.map +1 -1
- package/dist/esm/core/router-generator-plugin.js +100 -111
- package/dist/esm/core/router-generator-plugin.js.map +1 -1
- package/dist/esm/core/router-hmr-plugin.js +79 -80
- package/dist/esm/core/router-hmr-plugin.js.map +1 -1
- package/dist/esm/core/utils.js +21 -15
- package/dist/esm/core/utils.js.map +1 -1
- package/dist/esm/esbuild.js +37 -18
- package/dist/esm/esbuild.js.map +1 -1
- package/dist/esm/index.js +2 -11
- package/dist/esm/rspack.js +49 -20
- package/dist/esm/rspack.js.map +1 -1
- package/dist/esm/vite.js +42 -21
- package/dist/esm/vite.js.map +1 -1
- package/dist/esm/webpack.js +37 -20
- package/dist/esm/webpack.js.map +1 -1
- package/package.json +6 -6
- package/src/core/code-splitter/compilers.ts +1 -1
- package/src/core/route-autoimport-plugin.ts +1 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/esm/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-code-splitter-plugin.cjs","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 PLUGIN_NAME = 'unplugin:router-code-splitter'\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) {\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.routePath,\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\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 sharedBindings: sharedBindings.size > 0 ? sharedBindings : undefined,\n compilerPlugins: getReferenceRouteCompilerPlugins({\n targetFramework: userConfig.target,\n addHmr,\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(compiler) {\n ROOT = process.cwd()\n initUserConfig()\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.done.tap(PLUGIN_NAME, () => {\n console.info('✅ ' + PLUGIN_NAME + ': code-splitting done!')\n })\n }\n },\n\n webpack(compiler) {\n ROOT = process.cwd()\n initUserConfig()\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.done.tap(PLUGIN_NAME, () => {\n console.info('✅ ' + PLUGIN_NAME + ': code-splitting done!')\n })\n }\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"],"names":["getConfig","defaultCodeSplitGroupings","debug","detectCodeSplitGroupingsFromRoute","splitGroupingsSchema","computeSharedBindings","compileCodeSplitReferenceRoute","getReferenceRouteCompilerPlugins","logDiff","tsrSplit","decodeIdentifier","splitRouteIdentNodes","compileCodeSplitVirtualRoute","tsrShared","normalizePath","config","frameworkPlugins","pathToFileURL","fileURLToPath","compileCodeSplitSharedRoute"],"mappings":";;;;;;;;;;AAgCA,MAAM,cAAc;AACpB,MAAM,4BACJ;AAYF,MAAM,sCAGF;AAAA,EACF,OAAO;AAAA,IACL;AAAA;AAAA,MAEE,aAAa,CAAC,oBAAoB,oBAAoB;AAAA,MACtD,KAAK;AAAA,MACL,OAAO;AAAA,IAAA;AAAA,IAET;AAAA;AAAA,MAEE,aAAa,CAAC,kBAAkB,gCAAgC;AAAA,MAChE,KAAK;AAAA,MACL,OAAO;AAAA,IAAA;AAAA,IAET;AAAA;AAAA,MAEE,aAAa,CAAC,yBAAyB,gCAAgC;AAAA,MACvE,KAAK;AAAA,MACL,OAAO;AAAA,IAAA;AAAA,EACT;AAAA,EAEF,OAAO;AAAA,IACL;AAAA,MACE,aAAa,CAAC,OAAO;AAAA,MACrB,KAAK;AAAA,MACL,OAAO;AAAA,IAAA;AAAA,EACT;AAEJ;AAEO,MAAM,oCAET,CAAC,UAAU,CAAA,GAAI,EAAE,WAAW,iBAAiB;AAC/C,MAA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MAAM;AAAA,QACJ,mBAAmB,aAAa;AAC9B,cAAI,WAAW,QAAQ,MAAM,iBAAiB;AAC5C,mBAAO,WAAW,OAAO,KAAK,oBAAoB,YAAY;AAAA,UAChE;AACA,iBAAO;AAAA,QACT;AAAA,MAAA;AAAA,IACF;AAAA,EACF;AAEJ;;"}
|
|
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 PLUGIN_NAME = 'unplugin:router-code-splitter'\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) {\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.routePath,\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\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 sharedBindings: sharedBindings.size > 0 ? sharedBindings : undefined,\n compilerPlugins: getReferenceRouteCompilerPlugins({\n targetFramework: userConfig.target,\n addHmr,\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(compiler) {\n ROOT = process.cwd()\n initUserConfig()\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.done.tap(PLUGIN_NAME, () => {\n console.info('✅ ' + PLUGIN_NAME + ': code-splitting done!')\n })\n }\n },\n\n webpack(compiler) {\n ROOT = process.cwd()\n initUserConfig()\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.done.tap(PLUGIN_NAME, () => {\n console.info('✅ ' + PLUGIN_NAME + ': code-splitting done!')\n })\n }\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,cAAc;AACpB,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,IAAa,qCAER,UAAU,EAAE,EAAE,EAAE,WAAW,iBAAiB;CAC/C,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,WAAW;GACtB,MAAM,MAAM,eAAA,qBAAqB,UAAU,SAAS,UAAU;AAC9D,OAAI,CAAC,IAAI,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M;GACN,SAAS;GAET,WAAW;IACT,QAAQ,EACN,IAAI,cACL;IACD,QAAQ,MAAM,IAAI;KAChB,MAAM,OAAA,GAAA,SAAA,eAAoB,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"}
|
|
@@ -1,36 +1,30 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
result.push(...routeAutoImport);
|
|
27
|
-
}
|
|
28
|
-
const isProduction = process.env.NODE_ENV === "production";
|
|
29
|
-
if (!isProduction && !userConfig.autoCodeSplitting) {
|
|
30
|
-
const routerHmr = getPlugin(routerHmrPlugin.unpluginRouterHmrFactory);
|
|
31
|
-
result.push(...routerHmr);
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
1
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_router_code_splitter_plugin = require("./router-code-splitter-plugin.cjs");
|
|
3
|
+
const require_router_generator_plugin = require("./router-generator-plugin.cjs");
|
|
4
|
+
const require_router_hmr_plugin = require("./router-hmr-plugin.cjs");
|
|
5
|
+
const require_route_autoimport_plugin = require("./route-autoimport-plugin.cjs");
|
|
6
|
+
let _tanstack_router_generator = require("@tanstack/router-generator");
|
|
7
|
+
//#region src/core/router-composed-plugin.ts
|
|
8
|
+
var unpluginRouterComposedFactory = (options = {}, meta) => {
|
|
9
|
+
const userConfig = (0, _tanstack_router_generator.getConfig)(options, process.cwd());
|
|
10
|
+
const getPlugin = (pluginFactory) => {
|
|
11
|
+
const plugin = pluginFactory(options, meta);
|
|
12
|
+
if (!Array.isArray(plugin)) return [plugin];
|
|
13
|
+
return plugin;
|
|
14
|
+
};
|
|
15
|
+
const routerGenerator = getPlugin(require_router_generator_plugin.unpluginRouterGeneratorFactory);
|
|
16
|
+
const routerCodeSplitter = getPlugin(require_router_code_splitter_plugin.unpluginRouterCodeSplitterFactory);
|
|
17
|
+
const routeAutoImport = getPlugin(require_route_autoimport_plugin.unpluginRouteAutoImportFactory);
|
|
18
|
+
const result = [...routerGenerator];
|
|
19
|
+
if (userConfig.autoCodeSplitting) result.push(...routerCodeSplitter);
|
|
20
|
+
if (userConfig.verboseFileRoutes === false) result.push(...routeAutoImport);
|
|
21
|
+
if (!(process.env.NODE_ENV === "production") && !userConfig.autoCodeSplitting) {
|
|
22
|
+
const routerHmr = getPlugin(require_router_hmr_plugin.unpluginRouterHmrFactory);
|
|
23
|
+
result.push(...routerHmr);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
34
26
|
};
|
|
27
|
+
//#endregion
|
|
35
28
|
exports.unpluginRouterComposedFactory = unpluginRouterComposedFactory;
|
|
36
|
-
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=router-composed-plugin.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-composed-plugin.cjs","sources":["../../../src/core/router-composed-plugin.ts"],"sourcesContent":["import { getConfig } from '@tanstack/router-generator'\nimport { unpluginRouterGeneratorFactory } from './router-generator-plugin'\nimport { unpluginRouterCodeSplitterFactory } from './router-code-splitter-plugin'\nimport { unpluginRouterHmrFactory } from './router-hmr-plugin'\nimport { unpluginRouteAutoImportFactory } from './route-autoimport-plugin'\nimport type { Config } from './config'\nimport type { UnpluginFactory } from 'unplugin'\n\nexport const unpluginRouterComposedFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}, meta) => {\n const ROOT: string = process.cwd()\n const userConfig = getConfig(options, ROOT)\n\n const getPlugin = (pluginFactory: UnpluginFactory<Partial<Config>>) => {\n const plugin = pluginFactory(options, meta)\n if (!Array.isArray(plugin)) {\n return [plugin]\n }\n return plugin\n }\n\n const routerGenerator = getPlugin(unpluginRouterGeneratorFactory)\n const routerCodeSplitter = getPlugin(unpluginRouterCodeSplitterFactory)\n const routeAutoImport = getPlugin(unpluginRouteAutoImportFactory)\n\n const result = [...routerGenerator]\n if (userConfig.autoCodeSplitting) {\n result.push(...routerCodeSplitter)\n }\n if (userConfig.verboseFileRoutes === false) {\n result.push(...routeAutoImport)\n }\n\n const isProduction = process.env.NODE_ENV === 'production'\n\n if (!isProduction && !userConfig.autoCodeSplitting) {\n const routerHmr = getPlugin(unpluginRouterHmrFactory)\n result.push(...routerHmr)\n }\n return result\n}\n"],"
|
|
1
|
+
{"version":3,"file":"router-composed-plugin.cjs","names":[],"sources":["../../../src/core/router-composed-plugin.ts"],"sourcesContent":["import { getConfig } from '@tanstack/router-generator'\nimport { unpluginRouterGeneratorFactory } from './router-generator-plugin'\nimport { unpluginRouterCodeSplitterFactory } from './router-code-splitter-plugin'\nimport { unpluginRouterHmrFactory } from './router-hmr-plugin'\nimport { unpluginRouteAutoImportFactory } from './route-autoimport-plugin'\nimport type { Config } from './config'\nimport type { UnpluginFactory } from 'unplugin'\n\nexport const unpluginRouterComposedFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}, meta) => {\n const ROOT: string = process.cwd()\n const userConfig = getConfig(options, ROOT)\n\n const getPlugin = (pluginFactory: UnpluginFactory<Partial<Config>>) => {\n const plugin = pluginFactory(options, meta)\n if (!Array.isArray(plugin)) {\n return [plugin]\n }\n return plugin\n }\n\n const routerGenerator = getPlugin(unpluginRouterGeneratorFactory)\n const routerCodeSplitter = getPlugin(unpluginRouterCodeSplitterFactory)\n const routeAutoImport = getPlugin(unpluginRouteAutoImportFactory)\n\n const result = [...routerGenerator]\n if (userConfig.autoCodeSplitting) {\n result.push(...routerCodeSplitter)\n }\n if (userConfig.verboseFileRoutes === false) {\n result.push(...routeAutoImport)\n }\n\n const isProduction = process.env.NODE_ENV === 'production'\n\n if (!isProduction && !userConfig.autoCodeSplitting) {\n const routerHmr = getPlugin(unpluginRouterHmrFactory)\n result.push(...routerHmr)\n }\n return result\n}\n"],"mappings":";;;;;;;AAQA,IAAa,iCAER,UAAU,EAAE,EAAE,SAAS;CAE1B,MAAM,cAAA,GAAA,2BAAA,WAAuB,SADR,QAAQ,KAAK,CACS;CAE3C,MAAM,aAAa,kBAAoD;EACrE,MAAM,SAAS,cAAc,SAAS,KAAK;AAC3C,MAAI,CAAC,MAAM,QAAQ,OAAO,CACxB,QAAO,CAAC,OAAO;AAEjB,SAAO;;CAGT,MAAM,kBAAkB,UAAU,gCAAA,+BAA+B;CACjE,MAAM,qBAAqB,UAAU,oCAAA,kCAAkC;CACvE,MAAM,kBAAkB,UAAU,gCAAA,+BAA+B;CAEjE,MAAM,SAAS,CAAC,GAAG,gBAAgB;AACnC,KAAI,WAAW,kBACb,QAAO,KAAK,GAAG,mBAAmB;AAEpC,KAAI,WAAW,sBAAs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
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {
|
|
100
|
-
if (handle) {
|
|
101
|
-
await handle.close();
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
},
|
|
105
|
-
webpack(compiler) {
|
|
106
|
-
initConfigAndGenerator();
|
|
107
|
-
let handle = null;
|
|
108
|
-
compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, () => generate());
|
|
109
|
-
compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
|
|
110
|
-
if (handle) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
const routesDirectoryPath = getRoutesDirectoryPath();
|
|
114
|
-
const chokidar = await import("chokidar");
|
|
115
|
-
handle = chokidar.watch(routesDirectoryPath, { ignoreInitial: true }).on("add", (file) => generate({ file, event: "create" }));
|
|
116
|
-
await generate();
|
|
117
|
-
});
|
|
118
|
-
compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {
|
|
119
|
-
if (handle) {
|
|
120
|
-
await handle.close();
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
compiler.hooks.done.tap(PLUGIN_NAME, () => {
|
|
124
|
-
console.info("✅ " + PLUGIN_NAME + ": route-tree generation done");
|
|
125
|
-
});
|
|
126
|
-
},
|
|
127
|
-
esbuild: {
|
|
128
|
-
config() {
|
|
129
|
-
initConfigAndGenerator();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
};
|
|
1
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_config = require("./config.cjs");
|
|
3
|
+
let _tanstack_router_generator = require("@tanstack/router-generator");
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
//#region src/core/router-generator-plugin.ts
|
|
6
|
+
var PLUGIN_NAME = "unplugin:router-generator";
|
|
7
|
+
var unpluginRouterGeneratorFactory = (options = {}) => {
|
|
8
|
+
let ROOT = process.cwd();
|
|
9
|
+
let userConfig;
|
|
10
|
+
let generator;
|
|
11
|
+
const routeGenerationDisabled = () => userConfig.enableRouteGeneration === false;
|
|
12
|
+
const getRoutesDirectoryPath = () => {
|
|
13
|
+
return (0, node_path.isAbsolute)(userConfig.routesDirectory) ? userConfig.routesDirectory : (0, node_path.join)(ROOT, userConfig.routesDirectory);
|
|
14
|
+
};
|
|
15
|
+
const initConfigAndGenerator = (opts) => {
|
|
16
|
+
if (opts?.root) ROOT = opts.root;
|
|
17
|
+
if (typeof options === "function") userConfig = options();
|
|
18
|
+
else userConfig = require_config.getConfig(options, ROOT);
|
|
19
|
+
generator = new _tanstack_router_generator.Generator({
|
|
20
|
+
config: userConfig,
|
|
21
|
+
root: ROOT
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
const generate = async (opts) => {
|
|
25
|
+
if (routeGenerationDisabled()) return;
|
|
26
|
+
let generatorEvent = void 0;
|
|
27
|
+
if (opts) {
|
|
28
|
+
const filePath = (0, node_path.normalize)(opts.file);
|
|
29
|
+
if (filePath === (0, _tanstack_router_generator.resolveConfigPath)({ configDirectory: ROOT })) {
|
|
30
|
+
initConfigAndGenerator();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
generatorEvent = {
|
|
34
|
+
path: filePath,
|
|
35
|
+
type: opts.event
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
await generator.run(generatorEvent);
|
|
40
|
+
globalThis.TSR_ROUTES_BY_ID_MAP = generator.getRoutesByFileMap();
|
|
41
|
+
} catch (e) {
|
|
42
|
+
console.error(e);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
name: "tanstack:router-generator",
|
|
47
|
+
enforce: "pre",
|
|
48
|
+
async watchChange(id, { event }) {
|
|
49
|
+
await generate({
|
|
50
|
+
file: id,
|
|
51
|
+
event
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
vite: { async configResolved(config) {
|
|
55
|
+
initConfigAndGenerator({ root: config.root });
|
|
56
|
+
await generate();
|
|
57
|
+
} },
|
|
58
|
+
rspack(compiler) {
|
|
59
|
+
initConfigAndGenerator();
|
|
60
|
+
let handle = null;
|
|
61
|
+
compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, () => generate());
|
|
62
|
+
compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
|
|
63
|
+
if (handle) return;
|
|
64
|
+
const routesDirectoryPath = getRoutesDirectoryPath();
|
|
65
|
+
handle = (await import("chokidar")).watch(routesDirectoryPath, { ignoreInitial: true }).on("add", (file) => generate({
|
|
66
|
+
file,
|
|
67
|
+
event: "create"
|
|
68
|
+
}));
|
|
69
|
+
await generate();
|
|
70
|
+
});
|
|
71
|
+
compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {
|
|
72
|
+
if (handle) await handle.close();
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
webpack(compiler) {
|
|
76
|
+
initConfigAndGenerator();
|
|
77
|
+
let handle = null;
|
|
78
|
+
compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, () => generate());
|
|
79
|
+
compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
|
|
80
|
+
if (handle) return;
|
|
81
|
+
const routesDirectoryPath = getRoutesDirectoryPath();
|
|
82
|
+
handle = (await import("chokidar")).watch(routesDirectoryPath, { ignoreInitial: true }).on("add", (file) => generate({
|
|
83
|
+
file,
|
|
84
|
+
event: "create"
|
|
85
|
+
}));
|
|
86
|
+
await generate();
|
|
87
|
+
});
|
|
88
|
+
compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {
|
|
89
|
+
if (handle) await handle.close();
|
|
90
|
+
});
|
|
91
|
+
compiler.hooks.done.tap(PLUGIN_NAME, () => {
|
|
92
|
+
console.info("✅ " + PLUGIN_NAME + ": route-tree generation done");
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
esbuild: { config() {
|
|
96
|
+
initConfigAndGenerator();
|
|
97
|
+
} }
|
|
98
|
+
};
|
|
133
99
|
};
|
|
100
|
+
//#endregion
|
|
134
101
|
exports.unpluginRouterGeneratorFactory = unpluginRouterGeneratorFactory;
|
|
135
|
-
|
|
102
|
+
|
|
103
|
+
//# sourceMappingURL=router-generator-plugin.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-generator-plugin.cjs","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 const unpluginRouterGeneratorFactory: UnpluginFactory<\n Partial<Config | (() => Config)> | undefined\n> = (options = {}) => {\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 globalThis.TSR_ROUTES_BY_ID_MAP = 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"],"
|
|
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 const unpluginRouterGeneratorFactory: UnpluginFactory<\n Partial<Config | (() => Config)> | undefined\n> = (options = {}) => {\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 globalThis.TSR_ROUTES_BY_ID_MAP = 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"],"mappings":";;;;;AASA,IAAM,cAAc;AAEpB,IAAa,kCAER,UAAU,EAAE,KAAK;CACpB,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,MAA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O,OAAO;KAEtB;;EAEJ,QAAQ,UAAU;AAChB,2BAAwB;GAExB,IAAI,SAA2B;AAE/B,YAAS,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"}
|
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_config = require("./config.cjs");
|
|
3
|
+
const require_route_hmr_statement = require("./route-hmr-statement.cjs");
|
|
4
|
+
const require_compilers = require("./code-splitter/compilers.cjs");
|
|
5
|
+
const require_utils = require("./utils.cjs");
|
|
6
|
+
const require_framework_plugins = require("./code-splitter/plugins/framework-plugins.cjs");
|
|
7
|
+
let _tanstack_router_utils = require("@tanstack/router-utils");
|
|
8
|
+
//#region src/core/router-hmr-plugin.ts
|
|
9
|
+
/**
|
|
10
|
+
* This plugin adds HMR support for file routes.
|
|
11
|
+
* It is only added to the composed plugin in dev when autoCodeSplitting is disabled, since the code splitting plugin
|
|
12
|
+
* handles HMR for code-split routes itself.
|
|
13
|
+
*/
|
|
14
|
+
var includeCode = [
|
|
15
|
+
"createFileRoute(",
|
|
16
|
+
"createRootRoute(",
|
|
17
|
+
"createRootRouteWithContext("
|
|
13
18
|
];
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (userConfig.plugin?.vite?.environmentName) {
|
|
76
|
-
return userConfig.plugin.vite.environmentName === environment.name;
|
|
77
|
-
}
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
};
|
|
19
|
+
var unpluginRouterHmrFactory = (options = {}) => {
|
|
20
|
+
let ROOT = process.cwd();
|
|
21
|
+
let userConfig = options;
|
|
22
|
+
return {
|
|
23
|
+
name: "tanstack-router:hmr",
|
|
24
|
+
enforce: "pre",
|
|
25
|
+
transform: {
|
|
26
|
+
filter: {
|
|
27
|
+
id: /\.(m|c)?(j|t)sx?$/,
|
|
28
|
+
code: { include: includeCode }
|
|
29
|
+
},
|
|
30
|
+
handler(code, id) {
|
|
31
|
+
const normalizedId = require_utils.normalizePath(id);
|
|
32
|
+
if (!globalThis.TSR_ROUTES_BY_ID_MAP?.has(normalizedId)) return null;
|
|
33
|
+
if (require_utils.debug) console.info("Adding HMR handling to route ", normalizedId);
|
|
34
|
+
if (userConfig.target === "react") {
|
|
35
|
+
const compiled = require_compilers.compileCodeSplitReferenceRoute({
|
|
36
|
+
code,
|
|
37
|
+
filename: normalizedId,
|
|
38
|
+
id: normalizedId,
|
|
39
|
+
addHmr: true,
|
|
40
|
+
codeSplitGroupings: [],
|
|
41
|
+
targetFramework: "react",
|
|
42
|
+
compilerPlugins: require_framework_plugins.getReferenceRouteCompilerPlugins({
|
|
43
|
+
targetFramework: "react",
|
|
44
|
+
addHmr: true
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
if (compiled) {
|
|
48
|
+
if (require_utils.debug) {
|
|
49
|
+
(0, _tanstack_router_utils.logDiff)(code, compiled.code);
|
|
50
|
+
console.log("Output:\n", compiled.code + "\n\n");
|
|
51
|
+
}
|
|
52
|
+
return compiled;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const ast = (0, _tanstack_router_utils.parseAst)({ code });
|
|
56
|
+
ast.program.body.push(require_route_hmr_statement.routeHmrStatement);
|
|
57
|
+
const result = (0, _tanstack_router_utils.generateFromAst)(ast, {
|
|
58
|
+
sourceMaps: true,
|
|
59
|
+
filename: normalizedId,
|
|
60
|
+
sourceFileName: normalizedId
|
|
61
|
+
});
|
|
62
|
+
if (require_utils.debug) {
|
|
63
|
+
(0, _tanstack_router_utils.logDiff)(code, result.code);
|
|
64
|
+
console.log("Output:\n", result.code + "\n\n");
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
vite: {
|
|
70
|
+
configResolved(config) {
|
|
71
|
+
ROOT = config.root;
|
|
72
|
+
userConfig = require_config.getConfig(options, ROOT);
|
|
73
|
+
},
|
|
74
|
+
applyToEnvironment(environment) {
|
|
75
|
+
if (userConfig.plugin?.vite?.environmentName) return userConfig.plugin.vite.environmentName === environment.name;
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
82
80
|
};
|
|
81
|
+
//#endregion
|
|
83
82
|
exports.unpluginRouterHmrFactory = unpluginRouterHmrFactory;
|
|
84
|
-
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=router-hmr-plugin.cjs.map
|