@tanstack/router-plugin 1.168.5 → 1.168.7
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 +32 -233
- package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/compilers.d.cts +2 -57
- package/dist/cjs/core/code-splitter/plugins.d.cts +1 -0
- package/dist/cjs/core/config.cjs +1 -1
- package/dist/cjs/core/config.cjs.map +1 -1
- package/dist/cjs/core/config.d.cts +44 -163
- package/dist/cjs/core/hmr/handle-route-update.cjs +17 -18
- package/dist/cjs/core/hmr/handle-route-update.cjs.map +1 -1
- package/dist/cjs/core/router-code-splitter-plugin.cjs +5 -6
- package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
- package/dist/cjs/esbuild.d.cts +26 -26
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.d.cts +2 -0
- package/dist/cjs/vite.d.cts +26 -26
- package/dist/esm/core/code-splitter/compilers.d.ts +2 -57
- package/dist/esm/core/code-splitter/compilers.js +15 -216
- package/dist/esm/core/code-splitter/compilers.js.map +1 -1
- package/dist/esm/core/code-splitter/plugins.d.ts +1 -0
- package/dist/esm/core/config.d.ts +44 -163
- package/dist/esm/core/config.js +1 -1
- package/dist/esm/core/config.js.map +1 -1
- package/dist/esm/core/hmr/handle-route-update.js +17 -18
- package/dist/esm/core/hmr/handle-route-update.js.map +1 -1
- package/dist/esm/core/router-code-splitter-plugin.js +5 -6
- package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
- package/dist/esm/esbuild.d.ts +26 -26
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -1
- package/dist/esm/vite.d.ts +26 -26
- package/package.json +7 -7
- package/src/core/code-splitter/compilers.ts +51 -411
- package/src/core/code-splitter/plugins.ts +3 -0
- package/src/core/config.ts +12 -1
- package/src/core/hmr/handle-route-update.ts +30 -35
- package/src/core/router-code-splitter-plugin.ts +11 -9
- package/src/index.ts +5 -0
- package/dist/cjs/core/code-splitter/path-ids.cjs +0 -32
- package/dist/cjs/core/code-splitter/path-ids.cjs.map +0 -1
- package/dist/cjs/core/code-splitter/path-ids.d.cts +0 -2
- package/dist/esm/core/code-splitter/path-ids.d.ts +0 -2
- package/dist/esm/core/code-splitter/path-ids.js +0 -31
- package/dist/esm/core/code-splitter/path-ids.js.map +0 -1
- package/src/core/code-splitter/path-ids.ts +0 -39
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { CreateFileRoute, RegisteredRouter, RouteIds } from '@tanstack/router-core';
|
|
3
3
|
import { CodeSplitGroupings } from './constants.cjs';
|
|
4
|
-
export declare const splitGroupingsSchema: z.
|
|
4
|
+
export declare const splitGroupingsSchema: z.ZodArray<z.ZodArray<z.ZodUnion<readonly [z.ZodLiteral<"loader">, z.ZodLiteral<"component">, z.ZodLiteral<"pendingComponent">, z.ZodLiteral<"errorComponent">, z.ZodLiteral<"notFoundComponent">]>>>;
|
|
5
5
|
export type CodeSplittingOptions = {
|
|
6
6
|
/**
|
|
7
7
|
* Use this function to programmatically control the code splitting behavior
|
|
@@ -42,99 +42,73 @@ export type HmrOptions = {
|
|
|
42
42
|
type FileRouteKeys = keyof (Parameters<CreateFileRoute<any, any, any, any, any>>[0] & {});
|
|
43
43
|
export type DeletableNodes = FileRouteKeys | (string & {});
|
|
44
44
|
export declare const configSchema: z.ZodObject<{
|
|
45
|
-
target: z.ZodDefault<z.ZodOptional<z.ZodEnum<
|
|
46
|
-
|
|
45
|
+
target: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
46
|
+
vue: "vue";
|
|
47
|
+
react: "react";
|
|
48
|
+
solid: "solid";
|
|
49
|
+
}>>>;
|
|
50
|
+
virtualRouteConfig: z.ZodOptional<z.ZodUnion<[z.ZodType<import('@tanstack/virtual-file-routes').VirtualRootRoute, unknown, z.core.$ZodTypeInternals<import('@tanstack/virtual-file-routes').VirtualRootRoute, unknown>>, z.ZodString]>>;
|
|
47
51
|
routeFilePrefix: z.ZodOptional<z.ZodString>;
|
|
48
52
|
routeFileIgnorePrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
49
53
|
routeFileIgnorePattern: z.ZodOptional<z.ZodString>;
|
|
50
54
|
routesDirectory: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
51
|
-
quoteStyle: z.ZodDefault<z.ZodOptional<z.ZodEnum<
|
|
55
|
+
quoteStyle: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
56
|
+
single: "single";
|
|
57
|
+
double: "double";
|
|
58
|
+
}>>>;
|
|
52
59
|
semicolons: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
53
60
|
disableLogging: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
54
|
-
routeTreeFileHeader: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString
|
|
55
|
-
indexToken: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodString, z.
|
|
61
|
+
routeTreeFileHeader: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
62
|
+
indexToken: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<RegExp, RegExp>, z.ZodObject<{
|
|
56
63
|
regex: z.ZodString;
|
|
57
64
|
flags: z.ZodOptional<z.ZodString>;
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
flags?: string | undefined;
|
|
61
|
-
}, {
|
|
62
|
-
regex: string;
|
|
63
|
-
flags?: string | undefined;
|
|
64
|
-
}>]>>>;
|
|
65
|
-
routeToken: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>, z.ZodObject<{
|
|
65
|
+
}, z.core.$strip>]>>>;
|
|
66
|
+
routeToken: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<RegExp, RegExp>, z.ZodObject<{
|
|
66
67
|
regex: z.ZodString;
|
|
67
68
|
flags: z.ZodOptional<z.ZodString>;
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
}, z.core.$strip>]>>>;
|
|
70
|
+
pathParamsAllowedCharacters: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
71
|
+
":": ":";
|
|
72
|
+
$: "$";
|
|
73
|
+
";": ";";
|
|
74
|
+
"@": "@";
|
|
75
|
+
"&": "&";
|
|
76
|
+
"=": "=";
|
|
77
|
+
"+": "+";
|
|
78
|
+
",": ",";
|
|
79
|
+
}>>>;
|
|
77
80
|
generatedRouteTree: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
78
81
|
disableTypes: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
79
|
-
addExtensions: z.
|
|
82
|
+
addExtensions: z.ZodPipe<z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>>, z.ZodTransform<string | boolean, string | boolean>>;
|
|
80
83
|
enableRouteTreeFormatting: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
81
|
-
routeTreeFileFooter: z.ZodOptional<z.ZodUnion<[z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString
|
|
84
|
+
routeTreeFileFooter: z.ZodOptional<z.ZodUnion<readonly [z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString>>>, z.ZodCustom<() => Array<string>, () => Array<string>>]>>;
|
|
82
85
|
autoCodeSplitting: z.ZodOptional<z.ZodBoolean>;
|
|
83
86
|
customScaffolding: z.ZodOptional<z.ZodObject<{
|
|
84
87
|
routeTemplate: z.ZodOptional<z.ZodString>;
|
|
85
88
|
lazyRouteTemplate: z.ZodOptional<z.ZodString>;
|
|
86
|
-
},
|
|
87
|
-
routeTemplate?: string | undefined;
|
|
88
|
-
lazyRouteTemplate?: string | undefined;
|
|
89
|
-
}, {
|
|
90
|
-
routeTemplate?: string | undefined;
|
|
91
|
-
lazyRouteTemplate?: string | undefined;
|
|
92
|
-
}>>;
|
|
89
|
+
}, z.core.$strip>>;
|
|
93
90
|
experimental: z.ZodOptional<z.ZodObject<{
|
|
94
91
|
enableCodeSplitting: z.ZodOptional<z.ZodBoolean>;
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
}, {
|
|
98
|
-
enableCodeSplitting?: boolean | undefined;
|
|
99
|
-
}>>;
|
|
100
|
-
plugins: z.ZodOptional<z.ZodArray<z.ZodType<import('@tanstack/router-generator').GeneratorPlugin, z.ZodTypeDef, import('@tanstack/router-generator').GeneratorPlugin>, "many">>;
|
|
92
|
+
}, z.core.$strip>>;
|
|
93
|
+
plugins: z.ZodOptional<z.ZodArray<z.ZodCustom<import('@tanstack/router-generator').GeneratorPlugin, import('@tanstack/router-generator').GeneratorPlugin>>>;
|
|
101
94
|
tmpDir: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
102
95
|
importRoutesUsingAbsolutePaths: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
103
|
-
} & {
|
|
104
96
|
enableRouteGeneration: z.ZodOptional<z.ZodBoolean>;
|
|
105
|
-
codeSplittingOptions: z.ZodOptional<z.
|
|
97
|
+
codeSplittingOptions: z.ZodOptional<z.ZodCustom<CodeSplittingOptions, CodeSplittingOptions>>;
|
|
106
98
|
plugin: z.ZodOptional<z.ZodObject<{
|
|
107
99
|
hmr: z.ZodOptional<z.ZodObject<{
|
|
108
|
-
style: z.ZodOptional<z.ZodEnum<
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}>>;
|
|
100
|
+
style: z.ZodOptional<z.ZodEnum<{
|
|
101
|
+
vite: "vite";
|
|
102
|
+
webpack: "webpack";
|
|
103
|
+
}>>;
|
|
104
|
+
}, z.core.$strip>>;
|
|
114
105
|
vite: z.ZodOptional<z.ZodObject<{
|
|
115
106
|
environmentName: z.ZodOptional<z.ZodString>;
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}, "strip", z.ZodTypeAny, {
|
|
122
|
-
vite?: {
|
|
123
|
-
environmentName?: string | undefined;
|
|
124
|
-
} | undefined;
|
|
125
|
-
hmr?: {
|
|
126
|
-
style?: "vite" | "webpack" | undefined;
|
|
127
|
-
} | undefined;
|
|
128
|
-
}, {
|
|
129
|
-
vite?: {
|
|
130
|
-
environmentName?: string | undefined;
|
|
131
|
-
} | undefined;
|
|
132
|
-
hmr?: {
|
|
133
|
-
style?: "vite" | "webpack" | undefined;
|
|
134
|
-
} | undefined;
|
|
135
|
-
}>>;
|
|
136
|
-
}, "strip", z.ZodTypeAny, {
|
|
137
|
-
target: "react" | "solid" | "vue";
|
|
107
|
+
}, z.core.$strip>>;
|
|
108
|
+
}, z.core.$strip>>;
|
|
109
|
+
}, z.core.$strip>;
|
|
110
|
+
export declare const getConfig: (inlineConfig: Partial<Config>, root: string) => {
|
|
111
|
+
target: "vue" | "react" | "solid";
|
|
138
112
|
routeFileIgnorePrefix: string;
|
|
139
113
|
routesDirectory: string;
|
|
140
114
|
quoteStyle: "single" | "double";
|
|
@@ -155,21 +129,11 @@ export declare const configSchema: z.ZodObject<{
|
|
|
155
129
|
enableRouteTreeFormatting: boolean;
|
|
156
130
|
tmpDir: string;
|
|
157
131
|
importRoutesUsingAbsolutePaths: boolean;
|
|
158
|
-
enableRouteGeneration?: boolean | undefined;
|
|
159
|
-
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
160
|
-
plugin?: {
|
|
161
|
-
vite?: {
|
|
162
|
-
environmentName?: string | undefined;
|
|
163
|
-
} | undefined;
|
|
164
|
-
hmr?: {
|
|
165
|
-
style?: "vite" | "webpack" | undefined;
|
|
166
|
-
} | undefined;
|
|
167
|
-
} | undefined;
|
|
168
132
|
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
169
133
|
routeFilePrefix?: string | undefined;
|
|
170
134
|
routeFileIgnorePattern?: string | undefined;
|
|
171
|
-
pathParamsAllowedCharacters?: ("
|
|
172
|
-
routeTreeFileFooter?: string[] | ((
|
|
135
|
+
pathParamsAllowedCharacters?: (":" | "$" | ";" | "@" | "&" | "=" | "+" | ",")[] | undefined;
|
|
136
|
+
routeTreeFileFooter?: string[] | (() => Array<string>) | undefined;
|
|
173
137
|
autoCodeSplitting?: boolean | undefined;
|
|
174
138
|
customScaffolding?: {
|
|
175
139
|
routeTemplate?: string | undefined;
|
|
@@ -179,99 +143,16 @@ export declare const configSchema: z.ZodObject<{
|
|
|
179
143
|
enableCodeSplitting?: boolean | undefined;
|
|
180
144
|
} | undefined;
|
|
181
145
|
plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
|
|
182
|
-
}, {
|
|
183
146
|
enableRouteGeneration?: boolean | undefined;
|
|
184
147
|
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
185
148
|
plugin?: {
|
|
186
|
-
vite?: {
|
|
187
|
-
environmentName?: string | undefined;
|
|
188
|
-
} | undefined;
|
|
189
149
|
hmr?: {
|
|
190
150
|
style?: "vite" | "webpack" | undefined;
|
|
191
151
|
} | undefined;
|
|
192
|
-
} | undefined;
|
|
193
|
-
target?: "react" | "solid" | "vue" | undefined;
|
|
194
|
-
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
195
|
-
routeFilePrefix?: string | undefined;
|
|
196
|
-
routeFileIgnorePrefix?: string | undefined;
|
|
197
|
-
routeFileIgnorePattern?: string | undefined;
|
|
198
|
-
routesDirectory?: string | undefined;
|
|
199
|
-
quoteStyle?: "single" | "double" | undefined;
|
|
200
|
-
semicolons?: boolean | undefined;
|
|
201
|
-
disableLogging?: boolean | undefined;
|
|
202
|
-
routeTreeFileHeader?: string[] | undefined;
|
|
203
|
-
indexToken?: string | RegExp | {
|
|
204
|
-
regex: string;
|
|
205
|
-
flags?: string | undefined;
|
|
206
|
-
} | undefined;
|
|
207
|
-
routeToken?: string | RegExp | {
|
|
208
|
-
regex: string;
|
|
209
|
-
flags?: string | undefined;
|
|
210
|
-
} | undefined;
|
|
211
|
-
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
212
|
-
generatedRouteTree?: string | undefined;
|
|
213
|
-
disableTypes?: boolean | undefined;
|
|
214
|
-
addExtensions?: string | boolean | undefined;
|
|
215
|
-
enableRouteTreeFormatting?: boolean | undefined;
|
|
216
|
-
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
217
|
-
autoCodeSplitting?: boolean | undefined;
|
|
218
|
-
customScaffolding?: {
|
|
219
|
-
routeTemplate?: string | undefined;
|
|
220
|
-
lazyRouteTemplate?: string | undefined;
|
|
221
|
-
} | undefined;
|
|
222
|
-
experimental?: {
|
|
223
|
-
enableCodeSplitting?: boolean | undefined;
|
|
224
|
-
} | undefined;
|
|
225
|
-
plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
|
|
226
|
-
tmpDir?: string | undefined;
|
|
227
|
-
importRoutesUsingAbsolutePaths?: boolean | undefined;
|
|
228
|
-
}>;
|
|
229
|
-
export declare const getConfig: (inlineConfig: Partial<Config>, root: string) => {
|
|
230
|
-
target: "react" | "solid" | "vue";
|
|
231
|
-
routeFileIgnorePrefix: string;
|
|
232
|
-
routesDirectory: string;
|
|
233
|
-
quoteStyle: "single" | "double";
|
|
234
|
-
semicolons: boolean;
|
|
235
|
-
disableLogging: boolean;
|
|
236
|
-
routeTreeFileHeader: string[];
|
|
237
|
-
indexToken: string | RegExp | {
|
|
238
|
-
regex: string;
|
|
239
|
-
flags?: string | undefined;
|
|
240
|
-
};
|
|
241
|
-
routeToken: string | RegExp | {
|
|
242
|
-
regex: string;
|
|
243
|
-
flags?: string | undefined;
|
|
244
|
-
};
|
|
245
|
-
generatedRouteTree: string;
|
|
246
|
-
disableTypes: boolean;
|
|
247
|
-
addExtensions: string | boolean;
|
|
248
|
-
enableRouteTreeFormatting: boolean;
|
|
249
|
-
tmpDir: string;
|
|
250
|
-
importRoutesUsingAbsolutePaths: boolean;
|
|
251
|
-
enableRouteGeneration?: boolean | undefined;
|
|
252
|
-
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
253
|
-
plugin?: {
|
|
254
152
|
vite?: {
|
|
255
153
|
environmentName?: string | undefined;
|
|
256
154
|
} | undefined;
|
|
257
|
-
hmr?: {
|
|
258
|
-
style?: "vite" | "webpack" | undefined;
|
|
259
|
-
} | undefined;
|
|
260
155
|
} | undefined;
|
|
261
|
-
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
262
|
-
routeFilePrefix?: string | undefined;
|
|
263
|
-
routeFileIgnorePattern?: string | undefined;
|
|
264
|
-
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
265
|
-
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
266
|
-
autoCodeSplitting?: boolean | undefined;
|
|
267
|
-
customScaffolding?: {
|
|
268
|
-
routeTemplate?: string | undefined;
|
|
269
|
-
lazyRouteTemplate?: string | undefined;
|
|
270
|
-
} | undefined;
|
|
271
|
-
experimental?: {
|
|
272
|
-
enableCodeSplitting?: boolean | undefined;
|
|
273
|
-
} | undefined;
|
|
274
|
-
plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
|
|
275
156
|
};
|
|
276
157
|
export type Config = z.infer<typeof configSchema>;
|
|
277
158
|
export type ConfigInput = z.input<typeof configSchema>;
|
|
@@ -3,9 +3,18 @@ function handleRouteUpdate(routeId, newRoute) {
|
|
|
3
3
|
const router = window.__TSR_ROUTER__;
|
|
4
4
|
const oldRoute = router.routesById[routeId];
|
|
5
5
|
if (!oldRoute) return;
|
|
6
|
+
const generatedRouteOptionKeys = new Set([
|
|
7
|
+
"id",
|
|
8
|
+
"path",
|
|
9
|
+
"getParentRoute"
|
|
10
|
+
]);
|
|
11
|
+
const generatedRouteOptions = {};
|
|
12
|
+
generatedRouteOptionKeys.forEach((key) => {
|
|
13
|
+
if (key in oldRoute.options) generatedRouteOptions[key] = oldRoute.options[key];
|
|
14
|
+
});
|
|
6
15
|
const removedKeys = /* @__PURE__ */ new Set();
|
|
7
16
|
Object.keys(oldRoute.options).forEach((key) => {
|
|
8
|
-
if (!(key in newRoute.options)) {
|
|
17
|
+
if (!generatedRouteOptionKeys.has(key) && !(key in newRoute.options)) {
|
|
9
18
|
removedKeys.add(key);
|
|
10
19
|
delete oldRoute.options[key];
|
|
11
20
|
}
|
|
@@ -15,17 +24,16 @@ function handleRouteUpdate(routeId, newRoute) {
|
|
|
15
24
|
if (preserveComponentIdentity) componentKeys.forEach((key) => {
|
|
16
25
|
if (key in oldRoute.options && key in newRoute.options) newRoute.options[key] = oldRoute.options[key];
|
|
17
26
|
});
|
|
18
|
-
|
|
19
|
-
|
|
27
|
+
const nextOptions = {
|
|
28
|
+
...newRoute.options,
|
|
29
|
+
...generatedRouteOptions
|
|
30
|
+
};
|
|
31
|
+
oldRoute.options = nextOptions;
|
|
32
|
+
oldRoute.update(nextOptions);
|
|
20
33
|
oldRoute._componentsPromise = void 0;
|
|
21
34
|
oldRoute._lazyPromise = void 0;
|
|
22
|
-
router.
|
|
23
|
-
router.routesByPath[oldRoute.fullPath] = oldRoute;
|
|
24
|
-
router.processedTree.matchCache.clear();
|
|
25
|
-
router.processedTree.flatCache?.clear();
|
|
26
|
-
router.processedTree.singleCache.clear();
|
|
35
|
+
router.setRoutes(router.buildRouteTree());
|
|
27
36
|
router.resolvePathCache.clear();
|
|
28
|
-
walkReplaceSegmentTree(oldRoute, router.processedTree.segmentTree);
|
|
29
37
|
const filter = (m) => m.routeId === oldRoute.id;
|
|
30
38
|
const activeMatch = router.stores.matches.get().find(filter);
|
|
31
39
|
const pendingMatch = router.stores.pendingMatches.get().find(filter);
|
|
@@ -57,15 +65,6 @@ function handleRouteUpdate(routeId, newRoute) {
|
|
|
57
65
|
sync: true
|
|
58
66
|
});
|
|
59
67
|
}
|
|
60
|
-
function walkReplaceSegmentTree(route, node) {
|
|
61
|
-
if (node.route?.id === route.id) node.route = route;
|
|
62
|
-
if (node.index) walkReplaceSegmentTree(route, node.index);
|
|
63
|
-
node.static?.forEach((child) => walkReplaceSegmentTree(route, child));
|
|
64
|
-
node.staticInsensitive?.forEach((child) => walkReplaceSegmentTree(route, child));
|
|
65
|
-
node.dynamic?.forEach((child) => walkReplaceSegmentTree(route, child));
|
|
66
|
-
node.optional?.forEach((child) => walkReplaceSegmentTree(route, child));
|
|
67
|
-
node.wildcard?.forEach((child) => walkReplaceSegmentTree(route, child));
|
|
68
|
-
}
|
|
69
68
|
function getStoreMatch(matchId) {
|
|
70
69
|
return router.stores.pendingMatchStores.get(matchId)?.get() || router.stores.matchStores.get(matchId)?.get() || router.stores.cachedMatchStores.get(matchId)?.get();
|
|
71
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle-route-update.cjs","names":[],"sources":["../../../../src/core/hmr/handle-route-update.ts"],"sourcesContent":["import type {\n AnyRoute,\n AnyRouteMatch,\n AnyRouter,\n RouterWritableStore,\n} from '@tanstack/router-core'\n\ntype AnyRouteWithPrivateProps = AnyRoute & {\n options: Record<string, unknown>\n _componentsPromise?: Promise<void>\n _lazyPromise?: Promise<void>\n update: (options: Record<string, unknown>) => unknown\n _path: string\n _id: string\n _fullPath: string\n _to: string\n}\n\ntype AnyRouterWithPrivateMaps = AnyRouter & {\n routesById: Record<string, AnyRoute>\n routesByPath: Record<string, AnyRoute>\n stores: AnyRouter['stores'] & {\n cachedMatchStores: Map<\n string,\n Pick<RouterWritableStore<AnyRouteMatch>, 'get' | 'set'>\n >\n pendingMatchStores: Map<\n string,\n Pick<RouterWritableStore<AnyRouteMatch>, 'get' | 'set'>\n >\n matchStores: Map<\n string,\n Pick<RouterWritableStore<AnyRouteMatch>, 'get' | 'set'>\n >\n }\n}\n\ntype AnyRouteMatchWithPrivateProps = AnyRouteMatch & {\n __beforeLoadContext?: unknown\n __routeContext?: Record<string, unknown>\n context?: Record<string, unknown>\n}\n\nfunction handleRouteUpdate(\n routeId: string,\n newRoute: AnyRouteWithPrivateProps,\n) {\n const router = window.__TSR_ROUTER__ as AnyRouterWithPrivateMaps\n const oldRoute = router.routesById[routeId] as\n | AnyRouteWithPrivateProps\n | undefined\n\n if (!oldRoute) {\n return\n }\n\n // Keys whose identity must remain stable to prevent React from\n // unmounting/remounting the component tree. React Fast Refresh already\n // handles hot-updating the function bodies of these components — our job\n // is only to update non-component route options (loader, head, etc.).\n // For code-split (splittable) routes, the lazyRouteComponent wrapper is\n // already cached in the bundler hot data so its identity is stable.\n // For unsplittable routes (e.g. root routes), the component is a plain\n // function reference that gets recreated on every module re-execution,\n // so we must explicitly preserve the old reference.\n const removedKeys = new Set<string>()\n Object.keys(oldRoute.options).forEach((key) => {\n if (!(key in newRoute.options)) {\n removedKeys.add(key)\n delete oldRoute.options[key]\n }\n })\n\n const oldHasShellComponent = 'shellComponent' in oldRoute.options\n const newHasShellComponent = 'shellComponent' in newRoute.options\n const preserveComponentIdentity =\n oldHasShellComponent === newHasShellComponent\n\n // Preserve component identity so React doesn't remount.\n // React Fast Refresh patches the function bodies in-place.\n const componentKeys = '__TSR_COMPONENT_TYPES__' as unknown as Array<string>\n if (preserveComponentIdentity) {\n componentKeys.forEach((key) => {\n if (key in oldRoute.options && key in newRoute.options) {\n newRoute.options[key] = oldRoute.options[key]\n }\n })\n }\n\n oldRoute.options = newRoute.options\n oldRoute.update(newRoute.options)\n oldRoute._componentsPromise = undefined\n oldRoute._lazyPromise = undefined\n\n router.routesById[oldRoute.id] = oldRoute\n router.routesByPath[oldRoute.fullPath] = oldRoute\n\n router.processedTree.matchCache.clear()\n router.processedTree.flatCache?.clear()\n router.processedTree.singleCache.clear()\n router.resolvePathCache.clear()\n walkReplaceSegmentTree(oldRoute, router.processedTree.segmentTree)\n\n const filter = (m: AnyRouteMatch) => m.routeId === oldRoute.id\n const activeMatch = router.stores.matches.get().find(filter)\n const pendingMatch = router.stores.pendingMatches.get().find(filter)\n const cachedMatches = router.stores.cachedMatches.get().filter(filter)\n\n if (activeMatch || pendingMatch || cachedMatches.length > 0) {\n // Clear stale match data for removed route options BEFORE invalidating.\n // Without this, router.invalidate() -> matchRoutes() reuses the existing\n // match from the store (via ...existingMatch spread) and the stale\n // loaderData / __beforeLoadContext survives the reload cycle.\n //\n // We must update the store directly (not via router.updateMatch) because\n // updateMatch wraps in startTransition which may defer the state update,\n // and we need the clear to be visible before invalidate reads the store.\n if (removedKeys.has('loader') || removedKeys.has('beforeLoad')) {\n const matchIds = [\n activeMatch?.id,\n pendingMatch?.id,\n ...cachedMatches.map((match) => match.id),\n ].filter(Boolean) as Array<string>\n router.batch(() => {\n for (const matchId of matchIds) {\n const store =\n router.stores.pendingMatchStores.get(matchId) ||\n router.stores.matchStores.get(matchId) ||\n router.stores.cachedMatchStores.get(matchId)\n if (store) {\n store.set((prev) => {\n const next: AnyRouteMatchWithPrivateProps = { ...prev }\n\n if (removedKeys.has('loader')) {\n next.loaderData = undefined\n }\n if (removedKeys.has('beforeLoad')) {\n next.__beforeLoadContext = undefined\n next.context = rebuildMatchContextWithoutBeforeLoad(next)\n }\n\n return next\n })\n }\n }\n })\n }\n\n router.invalidate({ filter, sync: true })\n }\n\n function walkReplaceSegmentTree(\n route: AnyRouteWithPrivateProps,\n node: AnyRouter['processedTree']['segmentTree'],\n ) {\n if (node.route?.id === route.id) node.route = route\n if (node.index) walkReplaceSegmentTree(route, node.index)\n node.static?.forEach((child) => walkReplaceSegmentTree(route, child))\n node.staticInsensitive?.forEach((child) =>\n walkReplaceSegmentTree(route, child),\n )\n node.dynamic?.forEach((child) => walkReplaceSegmentTree(route, child))\n node.optional?.forEach((child) => walkReplaceSegmentTree(route, child))\n node.wildcard?.forEach((child) => walkReplaceSegmentTree(route, child))\n }\n\n function getStoreMatch(matchId: string) {\n return (\n router.stores.pendingMatchStores.get(matchId)?.get() ||\n router.stores.matchStores.get(matchId)?.get() ||\n router.stores.cachedMatchStores.get(matchId)?.get()\n )\n }\n\n function getMatchList(matchId: string) {\n const pendingMatches = router.stores.pendingMatches.get()\n if (pendingMatches.some((match) => match.id === matchId)) {\n return pendingMatches\n }\n\n const activeMatches = router.stores.matches.get()\n if (activeMatches.some((match) => match.id === matchId)) {\n return activeMatches\n }\n\n const cachedMatches = router.stores.cachedMatches.get()\n if (cachedMatches.some((match) => match.id === matchId)) {\n return cachedMatches\n }\n\n return []\n }\n\n function getParentMatch(match: AnyRouteMatch) {\n const matchList = getMatchList(match.id)\n const matchIndex = matchList.findIndex((item) => item.id === match.id)\n\n if (matchIndex <= 0) {\n return undefined\n }\n\n const parentMatch = matchList[matchIndex - 1]!\n return getStoreMatch(parentMatch.id) || parentMatch\n }\n\n function rebuildMatchContextWithoutBeforeLoad(\n match: AnyRouteMatchWithPrivateProps,\n ) {\n const parentMatch = getParentMatch(match)\n const getParentContext = (\n router as unknown as {\n getParentContext?: (\n parentMatch?: AnyRouteMatch,\n ) => Record<string, unknown> | undefined\n }\n ).getParentContext\n const parentContext = getParentContext\n ? getParentContext.call(router, parentMatch)\n : (parentMatch?.context ?? router.options.context)\n\n return {\n ...(parentContext ?? {}),\n ...(match.__routeContext ?? {}),\n }\n }\n}\n\nconst handleRouteUpdateStr = handleRouteUpdate.toString()\n\nexport function getHandleRouteUpdateCode(stableRouteOptionKeys: Array<string>) {\n return handleRouteUpdateStr.replace(\n /['\"]__TSR_COMPONENT_TYPES__['\"]/,\n JSON.stringify(stableRouteOptionKeys),\n )\n}\n"],"mappings":";AA2CA,SAAS,kBACP,SACA,UACA;CACA,MAAM,SAAS,OAAO;CACtB,MAAM,WAAW,OAAO,WAAW;AAInC,KAAI,CAA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U,MAAM,OAAO,QAAQ,CACrD,QAAO;EAGT,MAAM,gBAAgB,OAAO,OAAO,cAAc,KAAK;AACvD,MAAI,cAAc,MAAM,UAAU,MAAM,OAAO,QAAQ,CACrD,QAAO;AAGT,SAAO,EAAE;;CAGX,SAAS,eAAe,OAAsB;EAC5C,MAAM,YAAY,aAAa,MAAM,GAAG;EACxC,MAAM,aAAa,UAAU,WAAW,SAAS,KAAK,OAAO,MAAM,GAAG;AAEtE,MAAI,cAAc,EAChB;EAGF,MAAM,cAAc,UAAU,aAAa;AAC3C,SAAO,cAAc,YAAY,GAAG,IAAI;;CAG1C,SAAS,qCACP,OACA;EACA,MAAM,cAAc,eAAe,MAAM;EACzC,MAAM,mBACJ,OAKA;AAKF,SAAO;GACL,IALoB,mBAClB,iBAAiB,KAAK,QAAQ,YAAY,GACzC,aAAa,WAAW,OAAO,QAAQ,YAGrB,EAAE;GACvB,GAAI,MAAM,kBAAkB,EAAE;GAC/B;;;AAIL,IAAM,uBAAuB,kBAAkB,UAAU;AAEzD,SAAgB,yBAAyB,uBAAsC;AAC7E,QAAO,qBAAqB,QAC1B,mCACA,KAAK,UAAU,sBAAsB,CACtC"}
|
|
1
|
+
{"version":3,"file":"handle-route-update.cjs","names":[],"sources":["../../../../src/core/hmr/handle-route-update.ts"],"sourcesContent":["import type {\n AnyRoute,\n AnyRouteMatch,\n AnyRouter,\n RouterWritableStore,\n} from '@tanstack/router-core'\n\ntype AnyRouteWithPrivateProps = AnyRoute & {\n options: Record<string, unknown>\n _componentsPromise?: Promise<void>\n _lazyPromise?: Promise<void>\n update: (options: Record<string, unknown>) => unknown\n _path: string\n _id: string\n _fullPath: string\n _to: string\n}\n\ntype AnyRouterWithPrivateMaps = AnyRouter & {\n routesById: Record<string, AnyRoute>\n buildRouteTree: () => Parameters<AnyRouter['setRoutes']>[0]\n setRoutes: AnyRouter['setRoutes']\n stores: AnyRouter['stores'] & {\n cachedMatchStores: Map<\n string,\n Pick<RouterWritableStore<AnyRouteMatch>, 'get' | 'set'>\n >\n pendingMatchStores: Map<\n string,\n Pick<RouterWritableStore<AnyRouteMatch>, 'get' | 'set'>\n >\n matchStores: Map<\n string,\n Pick<RouterWritableStore<AnyRouteMatch>, 'get' | 'set'>\n >\n }\n}\n\ntype AnyRouteMatchWithPrivateProps = AnyRouteMatch & {\n __beforeLoadContext?: unknown\n __routeContext?: Record<string, unknown>\n context?: Record<string, unknown>\n}\n\nfunction handleRouteUpdate(\n routeId: string,\n newRoute: AnyRouteWithPrivateProps,\n) {\n const router = window.__TSR_ROUTER__ as AnyRouterWithPrivateMaps\n const oldRoute = router.routesById[routeId] as\n | AnyRouteWithPrivateProps\n | undefined\n\n if (!oldRoute) {\n return\n }\n\n // Generated route-tree options are not present on the freshly imported route\n // module, but they must stay on the live route before rebuilding indexes.\n const generatedRouteOptionKeys = new Set(['id', 'path', 'getParentRoute'])\n const generatedRouteOptions: Record<string, unknown> = {}\n generatedRouteOptionKeys.forEach((key) => {\n if (key in oldRoute.options) {\n generatedRouteOptions[key] = oldRoute.options[key]\n }\n })\n\n const removedKeys = new Set<string>()\n Object.keys(oldRoute.options).forEach((key) => {\n if (!generatedRouteOptionKeys.has(key) && !(key in newRoute.options)) {\n removedKeys.add(key)\n delete oldRoute.options[key]\n }\n })\n\n const oldHasShellComponent = 'shellComponent' in oldRoute.options\n const newHasShellComponent = 'shellComponent' in newRoute.options\n const preserveComponentIdentity =\n oldHasShellComponent === newHasShellComponent\n\n // Keys whose identity must remain stable to prevent React from\n // unmounting/remounting the component tree. React Fast Refresh already\n // handles hot-updating the function bodies of these components — our job\n // is only to update non-component route options (loader, head, etc.).\n // For code-split (splittable) routes, the lazyRouteComponent wrapper is\n // already cached in the bundler hot data so its identity is stable.\n // For unsplittable routes (e.g. root routes), the component is a plain\n // function reference that gets recreated on every module re-execution,\n // so we must explicitly preserve the old reference.\n // Preserve component identity so React doesn't remount.\n // React Fast Refresh patches the function bodies in-place.\n const componentKeys = '__TSR_COMPONENT_TYPES__' as unknown as Array<string>\n if (preserveComponentIdentity) {\n componentKeys.forEach((key) => {\n if (key in oldRoute.options && key in newRoute.options) {\n newRoute.options[key] = oldRoute.options[key]\n }\n })\n }\n\n const nextOptions = {\n ...newRoute.options,\n ...generatedRouteOptions,\n }\n\n oldRoute.options = nextOptions\n oldRoute.update(nextOptions)\n oldRoute._componentsPromise = undefined\n oldRoute._lazyPromise = undefined\n\n router.setRoutes(router.buildRouteTree())\n router.resolvePathCache.clear()\n\n const filter = (m: AnyRouteMatch) => m.routeId === oldRoute.id\n const activeMatch = router.stores.matches.get().find(filter)\n const pendingMatch = router.stores.pendingMatches.get().find(filter)\n const cachedMatches = router.stores.cachedMatches.get().filter(filter)\n\n if (activeMatch || pendingMatch || cachedMatches.length > 0) {\n // Clear stale match data for removed route options BEFORE invalidating.\n // Without this, router.invalidate() -> matchRoutes() reuses the existing\n // match from the store (via ...existingMatch spread) and the stale\n // loaderData / __beforeLoadContext survives the reload cycle.\n //\n // We must update the store directly (not via router.updateMatch) because\n // updateMatch wraps in startTransition which may defer the state update,\n // and we need the clear to be visible before invalidate reads the store.\n if (removedKeys.has('loader') || removedKeys.has('beforeLoad')) {\n const matchIds = [\n activeMatch?.id,\n pendingMatch?.id,\n ...cachedMatches.map((match) => match.id),\n ].filter(Boolean) as Array<string>\n router.batch(() => {\n for (const matchId of matchIds) {\n const store =\n router.stores.pendingMatchStores.get(matchId) ||\n router.stores.matchStores.get(matchId) ||\n router.stores.cachedMatchStores.get(matchId)\n if (store) {\n store.set((prev) => {\n const next: AnyRouteMatchWithPrivateProps = { ...prev }\n\n if (removedKeys.has('loader')) {\n next.loaderData = undefined\n }\n if (removedKeys.has('beforeLoad')) {\n next.__beforeLoadContext = undefined\n next.context = rebuildMatchContextWithoutBeforeLoad(next)\n }\n\n return next\n })\n }\n }\n })\n }\n\n router.invalidate({ filter, sync: true })\n }\n\n function getStoreMatch(matchId: string) {\n return (\n router.stores.pendingMatchStores.get(matchId)?.get() ||\n router.stores.matchStores.get(matchId)?.get() ||\n router.stores.cachedMatchStores.get(matchId)?.get()\n )\n }\n\n function getMatchList(matchId: string) {\n const pendingMatches = router.stores.pendingMatches.get()\n if (pendingMatches.some((match) => match.id === matchId)) {\n return pendingMatches\n }\n\n const activeMatches = router.stores.matches.get()\n if (activeMatches.some((match) => match.id === matchId)) {\n return activeMatches\n }\n\n const cachedMatches = router.stores.cachedMatches.get()\n if (cachedMatches.some((match) => match.id === matchId)) {\n return cachedMatches\n }\n\n return []\n }\n\n function getParentMatch(match: AnyRouteMatch) {\n const matchList = getMatchList(match.id)\n const matchIndex = matchList.findIndex((item) => item.id === match.id)\n\n if (matchIndex <= 0) {\n return undefined\n }\n\n const parentMatch = matchList[matchIndex - 1]!\n return getStoreMatch(parentMatch.id) || parentMatch\n }\n\n function rebuildMatchContextWithoutBeforeLoad(\n match: AnyRouteMatchWithPrivateProps,\n ) {\n const parentMatch = getParentMatch(match)\n const getParentContext = (\n router as unknown as {\n getParentContext?: (\n parentMatch?: AnyRouteMatch,\n ) => Record<string, unknown> | undefined\n }\n ).getParentContext\n const parentContext = getParentContext\n ? getParentContext.call(router, parentMatch)\n : (parentMatch?.context ?? router.options.context)\n\n return {\n ...(parentContext ?? {}),\n ...(match.__routeContext ?? {}),\n }\n }\n}\n\nconst handleRouteUpdateStr = handleRouteUpdate.toString()\n\nexport function getHandleRouteUpdateCode(stableRouteOptionKeys: Array<string>) {\n return handleRouteUpdateStr.replace(\n /['\"]__TSR_COMPONENT_TYPES__['\"]/,\n JSON.stringify(stableRouteOptionKeys),\n )\n}\n"],"mappings":";AA4CA,SAAS,kBACP,SACA,UACA;CACA,MAAM,SAAS,OAAO;CACtB,MAAM,WAAW,OAAO,WAAW;AAInC,KAAI,CAAC,SACH;CAKF,MAAM,2BAA2B,IAAI,IAAI;EAAC;EAAM;EAAQ;EAAiB,CAAC;CAC1E,MAAM,wBAAiD,EAAE;AACzD,0BAAyB,SAAS,QAAQ;AACxC,MAAI,OAAO,SAAS,QA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ALoB,mBAClB,iBAAiB,KAAK,QAAQ,YAAY,GACzC,aAAa,WAAW,OAAO,QAAQ,YAGrB,EAAE;GACvB,GAAI,MAAM,kBAAkB,EAAE;GAC/B;;;AAIL,IAAM,uBAAuB,kBAAkB,UAAU;AAEzD,SAAgB,yBAAyB,uBAAsC;AAC7E,QAAO,qBAAqB,QAC1B,mCACA,KAAK,UAAU,sBAAsB,CACtC"}
|
|
@@ -2,7 +2,6 @@ require("../_virtual/_rolldown/runtime.cjs");
|
|
|
2
2
|
const require_config = require("./config.cjs");
|
|
3
3
|
const require_constants = require("./constants.cjs");
|
|
4
4
|
const require_utils = require("./utils.cjs");
|
|
5
|
-
const require_path_ids = require("./code-splitter/path-ids.cjs");
|
|
6
5
|
const require_compilers = require("./code-splitter/compilers.cjs");
|
|
7
6
|
const require_framework_plugins = require("./code-splitter/plugins/framework-plugins.cjs");
|
|
8
7
|
const require_router_plugin_context = require("./router-plugin-context.cjs");
|
|
@@ -66,7 +65,7 @@ function createRouterCodeSplitterPlugin(options = {}, routerPluginContext) {
|
|
|
66
65
|
if (fromCode.groupings !== void 0) {
|
|
67
66
|
const res = require_config.splitGroupingsSchema.safeParse(fromCode.groupings);
|
|
68
67
|
if (!res.success) {
|
|
69
|
-
const message = res.error.
|
|
68
|
+
const message = res.error.issues.map((e) => e.message).join(". ");
|
|
70
69
|
throw new Error(`The groupings for the route "${id}" are invalid.\n${message}`);
|
|
71
70
|
}
|
|
72
71
|
}
|
|
@@ -74,7 +73,7 @@ function createRouterCodeSplitterPlugin(options = {}, routerPluginContext) {
|
|
|
74
73
|
if (pluginSplitBehavior) {
|
|
75
74
|
const res = require_config.splitGroupingsSchema.safeParse(pluginSplitBehavior);
|
|
76
75
|
if (!res.success) {
|
|
77
|
-
const message = res.error.
|
|
76
|
+
const message = res.error.issues.map((e) => e.message).join(". ");
|
|
78
77
|
throw new Error(`The groupings returned when using \`splitBehavior\` for the route "${id}" are invalid.\n${message}`);
|
|
79
78
|
}
|
|
80
79
|
}
|
|
@@ -99,11 +98,11 @@ function createRouterCodeSplitterPlugin(options = {}, routerPluginContext) {
|
|
|
99
98
|
hmrStyle,
|
|
100
99
|
hmrRouteId: generatorNodeInfo.routeId,
|
|
101
100
|
sharedBindings: sharedBindings.size > 0 ? sharedBindings : void 0,
|
|
102
|
-
compilerPlugins: require_framework_plugins.getReferenceRouteCompilerPlugins({
|
|
101
|
+
compilerPlugins: [...require_framework_plugins.getReferenceRouteCompilerPlugins({
|
|
103
102
|
targetFramework: userConfig.target,
|
|
104
103
|
addHmr,
|
|
105
104
|
hmrStyle
|
|
106
|
-
})
|
|
105
|
+
}) ?? [], ...userConfig.codeSplittingOptions?.compilerPlugins ?? []]
|
|
107
106
|
});
|
|
108
107
|
if (compiledReferenceRoute === null) {
|
|
109
108
|
if (require_utils.debug) console.info(`No changes made to route "${id}", skipping code-splitting.`);
|
|
@@ -120,7 +119,7 @@ function createRouterCodeSplitterPlugin(options = {}, routerPluginContext) {
|
|
|
120
119
|
const [_, ...pathnameParts] = id.split("?");
|
|
121
120
|
const splitValue = new URLSearchParams(pathnameParts.join("?")).get(require_constants.tsrSplit);
|
|
122
121
|
if (!splitValue) throw new Error(`The split value for the virtual route "${id}" was not found.`);
|
|
123
|
-
const rawGrouping =
|
|
122
|
+
const rawGrouping = (0, _tanstack_router_utils.decodeIdentifier)(splitValue);
|
|
124
123
|
const grouping = [...new Set(rawGrouping)].filter((p) => require_constants.splitRouteIdentNodes.includes(p));
|
|
125
124
|
const baseId = id.split("?")[0];
|
|
126
125
|
const result = require_compilers.compileCodeSplitVirtualRoute({
|
|
@@ -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, routeFactoryCallCodeFilter } 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 filename: id,\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 filename: id,\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 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: routeFactoryCallCodeFilter,\n },\n },\n handler(code, id) {\n const normalizedId = normalizePath(id)\n const generatorFileInfo =\n routerPluginContext.routesByFile.get(normalizedId)\n if (generatorFileInfo) {\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,O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AC9B,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
|
+
{"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 { decodeIdentifier, 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 { debug, normalizePath, routeFactoryCallCodeFilter } 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 filename: id,\n })\n\n if (fromCode.groupings !== undefined) {\n const res = splitGroupingsSchema.safeParse(fromCode.groupings)\n if (!res.success) {\n const message = res.error.issues.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.issues.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 filename: id,\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: [\n ...(getReferenceRouteCompilerPlugins({\n targetFramework: userConfig.target,\n addHmr,\n hmrStyle,\n }) ?? []),\n ...(userConfig.codeSplittingOptions?.compilerPlugins ?? []),\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 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: routeFactoryCallCodeFilter,\n },\n },\n handler(code, id) {\n const normalizedId = normalizePath(id)\n const generatorFileInfo =\n routerPluginContext.routesByFile.get(normalizedId)\n if (generatorFileInfo) {\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":";;;;;;;;;;;;;;AAiCA,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;GACjD;GACA,UAAU;GACX,CAAC;AAEF,MAAI,SAAS,cAAc,KAAA,GAAW;GACpC,MAAM,MAAM,eAAA,qBAAqB,UAAU,SAAS,UAAU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AAO,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"}
|
package/dist/cjs/esbuild.d.cts
CHANGED
|
@@ -31,7 +31,7 @@ declare const TanStackRouterCodeSplitterEsbuild: (options?: RouterPluginOptions,
|
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
declare const TanStackRouterEsbuild: (options?: Partial<{
|
|
34
|
-
target: "
|
|
34
|
+
target: "vue" | "react" | "solid";
|
|
35
35
|
routeFileIgnorePrefix: string;
|
|
36
36
|
routesDirectory: string;
|
|
37
37
|
quoteStyle: "single" | "double";
|
|
@@ -52,21 +52,11 @@ declare const TanStackRouterEsbuild: (options?: Partial<{
|
|
|
52
52
|
enableRouteTreeFormatting: boolean;
|
|
53
53
|
tmpDir: string;
|
|
54
54
|
importRoutesUsingAbsolutePaths: boolean;
|
|
55
|
-
enableRouteGeneration?: boolean | undefined;
|
|
56
|
-
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
57
|
-
plugin?: {
|
|
58
|
-
vite?: {
|
|
59
|
-
environmentName?: string | undefined;
|
|
60
|
-
} | undefined;
|
|
61
|
-
hmr?: {
|
|
62
|
-
style?: "vite" | "webpack" | undefined;
|
|
63
|
-
} | undefined;
|
|
64
|
-
} | undefined;
|
|
65
55
|
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
66
56
|
routeFilePrefix?: string | undefined;
|
|
67
57
|
routeFileIgnorePattern?: string | undefined;
|
|
68
|
-
pathParamsAllowedCharacters?: ("
|
|
69
|
-
routeTreeFileFooter?: string[] | ((
|
|
58
|
+
pathParamsAllowedCharacters?: (":" | "$" | ";" | "@" | "&" | "=" | "+" | ",")[] | undefined;
|
|
59
|
+
routeTreeFileFooter?: string[] | (() => Array<string>) | undefined;
|
|
70
60
|
autoCodeSplitting?: boolean | undefined;
|
|
71
61
|
customScaffolding?: {
|
|
72
62
|
routeTemplate?: string | undefined;
|
|
@@ -76,9 +66,19 @@ declare const TanStackRouterEsbuild: (options?: Partial<{
|
|
|
76
66
|
enableCodeSplitting?: boolean | undefined;
|
|
77
67
|
} | undefined;
|
|
78
68
|
plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
|
|
69
|
+
enableRouteGeneration?: boolean | undefined;
|
|
70
|
+
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
71
|
+
plugin?: {
|
|
72
|
+
hmr?: {
|
|
73
|
+
style?: "vite" | "webpack" | undefined;
|
|
74
|
+
} | undefined;
|
|
75
|
+
vite?: {
|
|
76
|
+
environmentName?: string | undefined;
|
|
77
|
+
} | undefined;
|
|
78
|
+
} | undefined;
|
|
79
79
|
} | (() => Config)> | undefined) => import('unplugin').EsbuildPlugin;
|
|
80
80
|
declare const tanstackRouter: (options?: Partial<{
|
|
81
|
-
target: "
|
|
81
|
+
target: "vue" | "react" | "solid";
|
|
82
82
|
routeFileIgnorePrefix: string;
|
|
83
83
|
routesDirectory: string;
|
|
84
84
|
quoteStyle: "single" | "double";
|
|
@@ -99,21 +99,11 @@ declare const tanstackRouter: (options?: Partial<{
|
|
|
99
99
|
enableRouteTreeFormatting: boolean;
|
|
100
100
|
tmpDir: string;
|
|
101
101
|
importRoutesUsingAbsolutePaths: boolean;
|
|
102
|
-
enableRouteGeneration?: boolean | undefined;
|
|
103
|
-
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
104
|
-
plugin?: {
|
|
105
|
-
vite?: {
|
|
106
|
-
environmentName?: string | undefined;
|
|
107
|
-
} | undefined;
|
|
108
|
-
hmr?: {
|
|
109
|
-
style?: "vite" | "webpack" | undefined;
|
|
110
|
-
} | undefined;
|
|
111
|
-
} | undefined;
|
|
112
102
|
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
113
103
|
routeFilePrefix?: string | undefined;
|
|
114
104
|
routeFileIgnorePattern?: string | undefined;
|
|
115
|
-
pathParamsAllowedCharacters?: ("
|
|
116
|
-
routeTreeFileFooter?: string[] | ((
|
|
105
|
+
pathParamsAllowedCharacters?: (":" | "$" | ";" | "@" | "&" | "=" | "+" | ",")[] | undefined;
|
|
106
|
+
routeTreeFileFooter?: string[] | (() => Array<string>) | undefined;
|
|
117
107
|
autoCodeSplitting?: boolean | undefined;
|
|
118
108
|
customScaffolding?: {
|
|
119
109
|
routeTemplate?: string | undefined;
|
|
@@ -123,6 +113,16 @@ declare const tanstackRouter: (options?: Partial<{
|
|
|
123
113
|
enableCodeSplitting?: boolean | undefined;
|
|
124
114
|
} | undefined;
|
|
125
115
|
plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
|
|
116
|
+
enableRouteGeneration?: boolean | undefined;
|
|
117
|
+
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
118
|
+
plugin?: {
|
|
119
|
+
hmr?: {
|
|
120
|
+
style?: "vite" | "webpack" | undefined;
|
|
121
|
+
} | undefined;
|
|
122
|
+
vite?: {
|
|
123
|
+
environmentName?: string | undefined;
|
|
124
|
+
} | undefined;
|
|
125
|
+
} | undefined;
|
|
126
126
|
} | (() => Config)> | undefined) => import('unplugin').EsbuildPlugin;
|
|
127
127
|
export default TanStackRouterEsbuild;
|
|
128
128
|
export { configSchema, TanStackRouterGeneratorEsbuild, TanStackRouterCodeSplitterEsbuild, TanStackRouterEsbuild, tanstackRouter, };
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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_utils = require("./core/utils.cjs");
|
|
4
5
|
const require_router_plugin_context = require("./core/router-plugin-context.cjs");
|
|
5
6
|
const require_router_code_splitter_plugin = require("./core/router-code-splitter-plugin.cjs");
|
|
6
7
|
const require_router_generator_plugin = require("./core/router-generator-plugin.cjs");
|
|
@@ -8,6 +9,7 @@ exports.configSchema = require_config.configSchema;
|
|
|
8
9
|
exports.createRouterPluginContext = require_router_plugin_context.createRouterPluginContext;
|
|
9
10
|
exports.defaultCodeSplitGroupings = require_constants.defaultCodeSplitGroupings;
|
|
10
11
|
exports.getConfig = require_config.getConfig;
|
|
12
|
+
exports.getObjectPropertyKeyName = require_utils.getObjectPropertyKeyName;
|
|
11
13
|
exports.splitRouteIdentNodes = require_constants.splitRouteIdentNodes;
|
|
12
14
|
exports.tsrSplit = require_constants.tsrSplit;
|
|
13
15
|
exports.unpluginRouterCodeSplitterFactory = require_router_code_splitter_plugin.unpluginRouterCodeSplitterFactory;
|