@tanstack/router-plugin 1.121.7 → 1.121.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/core/code-splitter/compilers.cjs +17 -18
- package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/compilers.d.cts +0 -1
- package/dist/cjs/core/config.d.cts +4 -4
- package/dist/cjs/core/route-autoimport-plugin.cjs +1 -1
- package/dist/cjs/core/route-autoimport-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-code-splitter-plugin.cjs +7 -6
- package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-generator-plugin.cjs +3 -2
- package/dist/cjs/core/router-generator-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-hmr-plugin.cjs +1 -1
- package/dist/cjs/core/router-hmr-plugin.cjs.map +1 -1
- package/dist/esm/core/code-splitter/compilers.d.ts +0 -1
- package/dist/esm/core/code-splitter/compilers.js +17 -18
- package/dist/esm/core/code-splitter/compilers.js.map +1 -1
- package/dist/esm/core/config.d.ts +4 -4
- package/dist/esm/core/route-autoimport-plugin.js +1 -1
- package/dist/esm/core/route-autoimport-plugin.js.map +1 -1
- package/dist/esm/core/router-code-splitter-plugin.js +7 -6
- package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
- package/dist/esm/core/router-generator-plugin.js +3 -2
- package/dist/esm/core/router-generator-plugin.js.map +1 -1
- package/dist/esm/core/router-hmr-plugin.js +1 -1
- package/dist/esm/core/router-hmr-plugin.js.map +1 -1
- package/package.json +4 -4
- package/src/core/code-splitter/compilers.ts +25 -24
- package/src/core/route-autoimport-plugin.ts +1 -1
- package/src/core/router-code-splitter-plugin.ts +11 -9
- package/src/core/router-generator-plugin.ts +4 -2
- package/src/core/router-hmr-plugin.ts +1 -1
- package/src/global.d.ts +3 -1
|
@@ -706,12 +706,9 @@ export function compileCodeSplitVirtualRoute(
|
|
|
706
706
|
*/
|
|
707
707
|
export function detectCodeSplitGroupingsFromRoute(opts: ParseAstOptions): {
|
|
708
708
|
groupings: CodeSplitGroupings | undefined
|
|
709
|
-
routeId: string
|
|
710
709
|
} {
|
|
711
710
|
const ast = parseAst(opts)
|
|
712
711
|
|
|
713
|
-
let routeId = ''
|
|
714
|
-
|
|
715
712
|
let codeSplitGroupings: CodeSplitGroupings | undefined = undefined
|
|
716
713
|
|
|
717
714
|
babel.traverse(ast, {
|
|
@@ -732,26 +729,11 @@ export function detectCodeSplitGroupingsFromRoute(opts: ParseAstOptions): {
|
|
|
732
729
|
return
|
|
733
730
|
}
|
|
734
731
|
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
if (t.isIdentifier(callee.callee)) {
|
|
741
|
-
const firstArg = callee.arguments[0]
|
|
742
|
-
if (t.isStringLiteral(firstArg)) {
|
|
743
|
-
routeId = firstArg.value
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
// Extracting the codeSplitGroupings
|
|
749
|
-
const options = resolveIdentifier(
|
|
750
|
-
path,
|
|
751
|
-
path.parentPath.node.arguments[0],
|
|
752
|
-
)
|
|
753
|
-
if (t.isObjectExpression(options)) {
|
|
754
|
-
options.properties.forEach((prop) => {
|
|
732
|
+
function babelHandleSplittingGroups(
|
|
733
|
+
routeOptions: t.Node | undefined,
|
|
734
|
+
) {
|
|
735
|
+
if (t.isObjectExpression(routeOptions)) {
|
|
736
|
+
routeOptions.properties.forEach((prop) => {
|
|
755
737
|
if (t.isObjectProperty(prop)) {
|
|
756
738
|
if (t.isIdentifier(prop.key)) {
|
|
757
739
|
if (prop.key.name === 'codeSplitGroupings') {
|
|
@@ -786,13 +768,32 @@ export function detectCodeSplitGroupingsFromRoute(opts: ParseAstOptions): {
|
|
|
786
768
|
})
|
|
787
769
|
}
|
|
788
770
|
}
|
|
771
|
+
|
|
772
|
+
// Extracting the codeSplitGroupings
|
|
773
|
+
if (t.isCallExpression(path.parentPath.node)) {
|
|
774
|
+
// createFileRoute('/')({ ... })
|
|
775
|
+
const options = resolveIdentifier(
|
|
776
|
+
path,
|
|
777
|
+
path.parentPath.node.arguments[0],
|
|
778
|
+
)
|
|
779
|
+
|
|
780
|
+
babelHandleSplittingGroups(options)
|
|
781
|
+
} else if (t.isVariableDeclarator(path.parentPath.node)) {
|
|
782
|
+
// createFileRoute({ ... })
|
|
783
|
+
const caller = resolveIdentifier(path, path.parentPath.node.init)
|
|
784
|
+
|
|
785
|
+
if (t.isCallExpression(caller)) {
|
|
786
|
+
const options = resolveIdentifier(path, caller.arguments[0])
|
|
787
|
+
babelHandleSplittingGroups(options)
|
|
788
|
+
}
|
|
789
|
+
}
|
|
789
790
|
},
|
|
790
791
|
})
|
|
791
792
|
},
|
|
792
793
|
},
|
|
793
794
|
})
|
|
794
795
|
|
|
795
|
-
return { groupings: codeSplitGroupings
|
|
796
|
+
return { groupings: codeSplitGroupings }
|
|
796
797
|
}
|
|
797
798
|
|
|
798
799
|
function getImportSpecifierAndPathFromLocalName(
|
|
@@ -24,7 +24,7 @@ export const unpluginRouteAutoImportFactory: UnpluginFactory<
|
|
|
24
24
|
code: /createFileRoute\(|createLazyFileRoute\(/,
|
|
25
25
|
},
|
|
26
26
|
handler(code, id) {
|
|
27
|
-
if (!globalThis.
|
|
27
|
+
if (!globalThis.TSR_ROUTES_BY_ID_MAP?.has(id)) {
|
|
28
28
|
return null
|
|
29
29
|
}
|
|
30
30
|
let routeType: 'createFileRoute' | 'createLazyFileRoute'
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
import { decodeIdentifier } from './code-splitter/path-ids'
|
|
20
20
|
import { debug } from './utils'
|
|
21
21
|
import type { CodeSplitGroupings, SplitRouteIdentNodes } from './constants'
|
|
22
|
-
|
|
22
|
+
import type { GetRoutesByFileMapResultValue } from '@tanstack/router-generator'
|
|
23
23
|
import type { Config } from './config'
|
|
24
24
|
import type {
|
|
25
25
|
UnpluginContextMeta,
|
|
@@ -44,8 +44,11 @@ const bannedBeforeExternalPlugins: Array<BannedBeforeExternalPlugin> = [
|
|
|
44
44
|
]
|
|
45
45
|
|
|
46
46
|
class FoundPluginInBeforeCode extends Error {
|
|
47
|
-
constructor(
|
|
48
|
-
|
|
47
|
+
constructor(
|
|
48
|
+
externalPlugin: BannedBeforeExternalPlugin,
|
|
49
|
+
pluginFramework: string,
|
|
50
|
+
) {
|
|
51
|
+
super(`We detected that the '${externalPlugin.pkg}' was passed before '@tanstack/router-plugin/${pluginFramework}'. Please make sure that '@tanstack/router-plugin' is passed before '${externalPlugin.pkg}' and try again:
|
|
49
52
|
e.g.
|
|
50
53
|
plugins: [
|
|
51
54
|
tanstackRouter(), // Place this before ${externalPlugin.usage}
|
|
@@ -78,6 +81,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
78
81
|
const handleCompilingReferenceFile = (
|
|
79
82
|
code: string,
|
|
80
83
|
id: string,
|
|
84
|
+
generatorNodeInfo: GetRoutesByFileMapResultValue,
|
|
81
85
|
): UnpluginTransformResult => {
|
|
82
86
|
if (debug) console.info('Compiling Route: ', id)
|
|
83
87
|
|
|
@@ -98,7 +102,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
98
102
|
const userShouldSplitFn = getShouldSplitFn()
|
|
99
103
|
|
|
100
104
|
const pluginSplitBehavior = userShouldSplitFn?.({
|
|
101
|
-
routeId:
|
|
105
|
+
routeId: generatorNodeInfo.routePath,
|
|
102
106
|
}) as CodeSplitGroupings | undefined
|
|
103
107
|
|
|
104
108
|
if (pluginSplitBehavior) {
|
|
@@ -180,10 +184,8 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
180
184
|
code: 'createFileRoute(',
|
|
181
185
|
},
|
|
182
186
|
handler(code, id) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
code.includes('createFileRoute(')
|
|
186
|
-
) {
|
|
187
|
+
const generatorFileInfo = globalThis.TSR_ROUTES_BY_ID_MAP?.get(id)
|
|
188
|
+
if (generatorFileInfo && code.includes('createFileRoute(')) {
|
|
187
189
|
for (const externalPlugin of bannedBeforeExternalPlugins) {
|
|
188
190
|
if (!externalPlugin.frameworks.includes(framework)) {
|
|
189
191
|
continue
|
|
@@ -194,7 +196,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
194
196
|
}
|
|
195
197
|
}
|
|
196
198
|
|
|
197
|
-
return handleCompilingReferenceFile(code, id)
|
|
199
|
+
return handleCompilingReferenceFile(code, id, generatorFileInfo)
|
|
198
200
|
}
|
|
199
201
|
|
|
200
202
|
return null
|
|
@@ -51,7 +51,7 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
|
|
|
51
51
|
|
|
52
52
|
try {
|
|
53
53
|
await generator.run(generatorEvent)
|
|
54
|
-
globalThis.
|
|
54
|
+
globalThis.TSR_ROUTES_BY_ID_MAP = generator.getRoutesByFileMap()
|
|
55
55
|
} catch (e) {
|
|
56
56
|
console.error(e)
|
|
57
57
|
}
|
|
@@ -74,7 +74,9 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
|
|
|
74
74
|
initConfigAndGenerator()
|
|
75
75
|
},
|
|
76
76
|
async buildStart() {
|
|
77
|
-
|
|
77
|
+
// to support vite 5, we need to optionally chain the access to the environment
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
79
|
+
if (this.environment?.config?.consumer === 'server') {
|
|
78
80
|
// When building in environment mode, we only need to generate routes
|
|
79
81
|
// for the client environment
|
|
80
82
|
return
|
package/src/global.d.ts
CHANGED