@tanstack/router-plugin 1.167.18 → 1.167.19
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/config.d.cts +0 -4
- package/dist/cjs/core/route-hmr-statement.cjs.map +1 -1
- package/dist/cjs/core/route-hmr-statement.d.cts +2 -1
- package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-composed-plugin.cjs +0 -3
- package/dist/cjs/core/router-composed-plugin.cjs.map +1 -1
- package/dist/cjs/esbuild.d.cts +0 -4
- package/dist/cjs/rspack.d.cts +0 -1
- package/dist/cjs/vite.cjs +0 -3
- package/dist/cjs/vite.cjs.map +1 -1
- package/dist/cjs/vite.d.cts +1 -53
- package/dist/cjs/webpack.d.cts +0 -1
- package/dist/esm/core/config.d.ts +0 -4
- package/dist/esm/core/route-hmr-statement.d.ts +2 -1
- package/dist/esm/core/route-hmr-statement.js.map +1 -1
- package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
- package/dist/esm/core/router-composed-plugin.js +0 -3
- package/dist/esm/core/router-composed-plugin.js.map +1 -1
- package/dist/esm/esbuild.d.ts +0 -4
- package/dist/esm/rspack.d.ts +0 -1
- package/dist/esm/vite.d.ts +1 -53
- package/dist/esm/vite.js +1 -3
- package/dist/esm/vite.js.map +1 -1
- package/dist/esm/webpack.d.ts +0 -1
- package/package.json +4 -4
- package/skills/router-plugin/SKILL.md +10 -13
- package/src/core/route-hmr-statement.ts +2 -1
- package/src/core/router-code-splitter-plugin.ts +0 -1
- package/src/core/router-composed-plugin.ts +0 -5
- package/src/vite.ts +0 -6
- package/dist/cjs/core/route-autoimport-plugin.cjs +0 -83
- package/dist/cjs/core/route-autoimport-plugin.cjs.map +0 -1
- package/dist/cjs/core/route-autoimport-plugin.d.cts +0 -6
- package/dist/esm/core/route-autoimport-plugin.d.ts +0 -6
- package/dist/esm/core/route-autoimport-plugin.js +0 -80
- package/dist/esm/core/route-autoimport-plugin.js.map +0 -1
- package/src/core/route-autoimport-plugin.ts +0 -120
package/dist/esm/esbuild.d.ts
CHANGED
|
@@ -44,7 +44,6 @@ declare const TanStackRouterGeneratorEsbuild: (options?: Partial<{
|
|
|
44
44
|
routeFilePrefix?: string | undefined;
|
|
45
45
|
routeFileIgnorePattern?: string | undefined;
|
|
46
46
|
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
47
|
-
verboseFileRoutes?: boolean | undefined;
|
|
48
47
|
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
49
48
|
autoCodeSplitting?: boolean | undefined;
|
|
50
49
|
customScaffolding?: {
|
|
@@ -101,7 +100,6 @@ declare const TanStackRouterCodeSplitterEsbuild: (options?: Partial<{
|
|
|
101
100
|
routeFilePrefix?: string | undefined;
|
|
102
101
|
routeFileIgnorePattern?: string | undefined;
|
|
103
102
|
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
104
|
-
verboseFileRoutes?: boolean | undefined;
|
|
105
103
|
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
106
104
|
autoCodeSplitting?: boolean | undefined;
|
|
107
105
|
customScaffolding?: {
|
|
@@ -158,7 +156,6 @@ declare const TanStackRouterEsbuild: (options?: Partial<{
|
|
|
158
156
|
routeFilePrefix?: string | undefined;
|
|
159
157
|
routeFileIgnorePattern?: string | undefined;
|
|
160
158
|
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
161
|
-
verboseFileRoutes?: boolean | undefined;
|
|
162
159
|
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
163
160
|
autoCodeSplitting?: boolean | undefined;
|
|
164
161
|
customScaffolding?: {
|
|
@@ -206,7 +203,6 @@ declare const tanstackRouter: (options?: Partial<{
|
|
|
206
203
|
routeFilePrefix?: string | undefined;
|
|
207
204
|
routeFileIgnorePattern?: string | undefined;
|
|
208
205
|
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
209
|
-
verboseFileRoutes?: boolean | undefined;
|
|
210
206
|
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
211
207
|
autoCodeSplitting?: boolean | undefined;
|
|
212
208
|
customScaffolding?: {
|
package/dist/esm/rspack.d.ts
CHANGED
|
@@ -48,7 +48,6 @@ declare const TanStackRouterGeneratorRspack: (options?: Partial<{
|
|
|
48
48
|
routeFilePrefix?: string | undefined;
|
|
49
49
|
routeFileIgnorePattern?: string | undefined;
|
|
50
50
|
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
51
|
-
verboseFileRoutes?: boolean | undefined;
|
|
52
51
|
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
53
52
|
autoCodeSplitting?: boolean | undefined;
|
|
54
53
|
customScaffolding?: {
|
package/dist/esm/vite.d.ts
CHANGED
|
@@ -1,52 +1,4 @@
|
|
|
1
1
|
import { configSchema, CodeSplittingOptions, Config, getConfig } from './core/config.js';
|
|
2
|
-
declare const tanstackRouterAutoImport: (options?: Partial<{
|
|
3
|
-
target: "react" | "solid" | "vue";
|
|
4
|
-
routeFileIgnorePrefix: string;
|
|
5
|
-
routesDirectory: string;
|
|
6
|
-
quoteStyle: "single" | "double";
|
|
7
|
-
semicolons: boolean;
|
|
8
|
-
disableLogging: boolean;
|
|
9
|
-
routeTreeFileHeader: string[];
|
|
10
|
-
indexToken: string | RegExp | {
|
|
11
|
-
regex: string;
|
|
12
|
-
flags?: string | undefined;
|
|
13
|
-
};
|
|
14
|
-
routeToken: string | RegExp | {
|
|
15
|
-
regex: string;
|
|
16
|
-
flags?: string | undefined;
|
|
17
|
-
};
|
|
18
|
-
generatedRouteTree: string;
|
|
19
|
-
disableTypes: boolean;
|
|
20
|
-
addExtensions: string | boolean;
|
|
21
|
-
enableRouteTreeFormatting: boolean;
|
|
22
|
-
tmpDir: string;
|
|
23
|
-
importRoutesUsingAbsolutePaths: boolean;
|
|
24
|
-
enableRouteGeneration?: boolean | undefined;
|
|
25
|
-
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
26
|
-
plugin?: {
|
|
27
|
-
hmr?: {
|
|
28
|
-
hotExpression?: string | undefined;
|
|
29
|
-
} | undefined;
|
|
30
|
-
vite?: {
|
|
31
|
-
environmentName?: string | undefined;
|
|
32
|
-
} | undefined;
|
|
33
|
-
} | undefined;
|
|
34
|
-
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
35
|
-
routeFilePrefix?: string | undefined;
|
|
36
|
-
routeFileIgnorePattern?: string | undefined;
|
|
37
|
-
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
38
|
-
verboseFileRoutes?: boolean | undefined;
|
|
39
|
-
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
40
|
-
autoCodeSplitting?: boolean | undefined;
|
|
41
|
-
customScaffolding?: {
|
|
42
|
-
routeTemplate?: string | undefined;
|
|
43
|
-
lazyRouteTemplate?: string | undefined;
|
|
44
|
-
} | undefined;
|
|
45
|
-
experimental?: {
|
|
46
|
-
enableCodeSplitting?: boolean | undefined;
|
|
47
|
-
} | undefined;
|
|
48
|
-
plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
|
|
49
|
-
} | (() => Config)> | undefined) => import('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
50
2
|
/**
|
|
51
3
|
* @example
|
|
52
4
|
* ```ts
|
|
@@ -92,7 +44,6 @@ declare const tanstackRouterGenerator: (options?: Partial<{
|
|
|
92
44
|
routeFilePrefix?: string | undefined;
|
|
93
45
|
routeFileIgnorePattern?: string | undefined;
|
|
94
46
|
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
95
|
-
verboseFileRoutes?: boolean | undefined;
|
|
96
47
|
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
97
48
|
autoCodeSplitting?: boolean | undefined;
|
|
98
49
|
customScaffolding?: {
|
|
@@ -149,7 +100,6 @@ declare const tanStackRouterCodeSplitter: (options?: Partial<{
|
|
|
149
100
|
routeFilePrefix?: string | undefined;
|
|
150
101
|
routeFileIgnorePattern?: string | undefined;
|
|
151
102
|
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
152
|
-
verboseFileRoutes?: boolean | undefined;
|
|
153
103
|
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
154
104
|
autoCodeSplitting?: boolean | undefined;
|
|
155
105
|
customScaffolding?: {
|
|
@@ -206,7 +156,6 @@ declare const tanstackRouter: (options?: Partial<{
|
|
|
206
156
|
routeFilePrefix?: string | undefined;
|
|
207
157
|
routeFileIgnorePattern?: string | undefined;
|
|
208
158
|
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
209
|
-
verboseFileRoutes?: boolean | undefined;
|
|
210
159
|
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
211
160
|
autoCodeSplitting?: boolean | undefined;
|
|
212
161
|
customScaffolding?: {
|
|
@@ -257,7 +206,6 @@ declare const TanStackRouterVite: (options?: Partial<{
|
|
|
257
206
|
routeFilePrefix?: string | undefined;
|
|
258
207
|
routeFileIgnorePattern?: string | undefined;
|
|
259
208
|
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
260
|
-
verboseFileRoutes?: boolean | undefined;
|
|
261
209
|
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
262
210
|
autoCodeSplitting?: boolean | undefined;
|
|
263
211
|
customScaffolding?: {
|
|
@@ -270,5 +218,5 @@ declare const TanStackRouterVite: (options?: Partial<{
|
|
|
270
218
|
plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
|
|
271
219
|
}> | undefined) => import('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
272
220
|
export default tanstackRouter;
|
|
273
|
-
export { configSchema, getConfig,
|
|
221
|
+
export { configSchema, getConfig, tanStackRouterCodeSplitter, tanstackRouterGenerator, TanStackRouterVite, tanstackRouter, };
|
|
274
222
|
export type { Config, CodeSplittingOptions };
|
package/dist/esm/vite.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { configSchema } from "./core/config.js";
|
|
2
2
|
import { unpluginRouterCodeSplitterFactory } from "./core/router-code-splitter-plugin.js";
|
|
3
3
|
import { unpluginRouterGeneratorFactory } from "./core/router-generator-plugin.js";
|
|
4
|
-
import { unpluginRouteAutoImportFactory } from "./core/route-autoimport-plugin.js";
|
|
5
4
|
import { unpluginRouterComposedFactory } from "./core/router-composed-plugin.js";
|
|
6
5
|
import { createVitePlugin } from "unplugin";
|
|
7
6
|
//#region src/vite.ts
|
|
8
|
-
var tanstackRouterAutoImport = createVitePlugin(unpluginRouteAutoImportFactory);
|
|
9
7
|
/**
|
|
10
8
|
* @example
|
|
11
9
|
* ```ts
|
|
@@ -41,6 +39,6 @@ var tanstackRouter = createVitePlugin(unpluginRouterComposedFactory);
|
|
|
41
39
|
*/
|
|
42
40
|
var TanStackRouterVite = tanstackRouter;
|
|
43
41
|
//#endregion
|
|
44
|
-
export { TanStackRouterVite, configSchema, tanstackRouter as default, tanstackRouter, tanStackRouterCodeSplitter,
|
|
42
|
+
export { TanStackRouterVite, configSchema, tanstackRouter as default, tanstackRouter, tanStackRouterCodeSplitter, tanstackRouterGenerator };
|
|
45
43
|
|
|
46
44
|
//# sourceMappingURL=vite.js.map
|
package/dist/esm/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","names":[],"sources":["../../src/vite.ts"],"sourcesContent":["import { createVitePlugin } from 'unplugin'\n\nimport { configSchema } from './core/config'\nimport { unpluginRouterCodeSplitterFactory } from './core/router-code-splitter-plugin'\nimport { unpluginRouterGeneratorFactory } from './core/router-generator-plugin'\nimport { unpluginRouterComposedFactory } from './core/router-composed-plugin'\nimport
|
|
1
|
+
{"version":3,"file":"vite.js","names":[],"sources":["../../src/vite.ts"],"sourcesContent":["import { createVitePlugin } from 'unplugin'\n\nimport { configSchema } from './core/config'\nimport { unpluginRouterCodeSplitterFactory } from './core/router-code-splitter-plugin'\nimport { unpluginRouterGeneratorFactory } from './core/router-generator-plugin'\nimport { unpluginRouterComposedFactory } from './core/router-composed-plugin'\nimport type { CodeSplittingOptions, Config, getConfig } from './core/config'\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [tanstackRouterGenerator()],\n * // ...\n * })\n * ```\n */\nconst tanstackRouterGenerator = createVitePlugin(unpluginRouterGeneratorFactory)\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [tanStackRouterCodeSplitter()],\n * // ...\n * })\n * ```\n */\nconst tanStackRouterCodeSplitter = createVitePlugin(\n unpluginRouterCodeSplitterFactory,\n)\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [tanstackRouter()],\n * // ...\n * })\n * ```\n */\nconst tanstackRouter = createVitePlugin(unpluginRouterComposedFactory)\n\n/**\n * @deprecated Use `tanstackRouter` instead.\n */\nconst TanStackRouterVite = tanstackRouter\n\nexport default tanstackRouter\nexport {\n configSchema,\n getConfig,\n tanStackRouterCodeSplitter,\n tanstackRouterGenerator,\n TanStackRouterVite,\n tanstackRouter,\n}\n\nexport type { Config, CodeSplittingOptions }\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,IAAM,0BAA0B,iBAAiB,+BAA+B;;;;;;;;;;AAWhF,IAAM,6BAA6B,iBACjC,kCACD;;;;;;;;;;AAWD,IAAM,iBAAiB,iBAAiB,8BAA8B;;;;AAKtE,IAAM,qBAAqB"}
|
package/dist/esm/webpack.d.ts
CHANGED
|
@@ -44,7 +44,6 @@ declare const TanStackRouterGeneratorWebpack: (options?: Partial<{
|
|
|
44
44
|
routeFilePrefix?: string | undefined;
|
|
45
45
|
routeFileIgnorePattern?: string | undefined;
|
|
46
46
|
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
47
|
-
verboseFileRoutes?: boolean | undefined;
|
|
48
47
|
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
49
48
|
autoCodeSplitting?: boolean | undefined;
|
|
50
49
|
customScaffolding?: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/router-plugin",
|
|
3
|
-
"version": "1.167.
|
|
3
|
+
"version": "1.167.19",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -99,9 +99,9 @@
|
|
|
99
99
|
"chokidar": "^3.6.0",
|
|
100
100
|
"unplugin": "^2.1.2",
|
|
101
101
|
"zod": "^3.24.2",
|
|
102
|
-
"@tanstack/router-generator": "1.166.29",
|
|
103
|
-
"@tanstack/router-utils": "1.161.6",
|
|
104
102
|
"@tanstack/router-core": "1.168.14",
|
|
103
|
+
"@tanstack/router-generator": "1.166.30",
|
|
104
|
+
"@tanstack/router-utils": "1.161.6",
|
|
105
105
|
"@tanstack/virtual-file-routes": "1.161.7"
|
|
106
106
|
},
|
|
107
107
|
"devDependencies": {
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"vite": ">=5.0.0 || >=6.0.0 || >=7.0.0 || >=8.0.0",
|
|
117
117
|
"vite-plugin-solid": "^2.11.10",
|
|
118
118
|
"webpack": ">=5.92.0",
|
|
119
|
-
"@tanstack/react-router": "^1.168.
|
|
119
|
+
"@tanstack/react-router": "^1.168.19"
|
|
120
120
|
},
|
|
121
121
|
"peerDependenciesMeta": {
|
|
122
122
|
"@rsbuild/core": {
|
|
@@ -142,15 +142,14 @@ tanstackRouter({
|
|
|
142
142
|
|
|
143
143
|
### Output Options
|
|
144
144
|
|
|
145
|
-
| Option | Type | Default
|
|
146
|
-
| --------------------------- | ---------------------- |
|
|
147
|
-
| `quoteStyle` | `'single' \| 'double'` | `'single'`
|
|
148
|
-
| `semicolons` | `boolean` | `false`
|
|
149
|
-
| `disableTypes` | `boolean` | `false`
|
|
150
|
-
| `disableLogging` | `boolean` | `false`
|
|
151
|
-
| `addExtensions` | `boolean \| string` | `false`
|
|
152
|
-
| `enableRouteTreeFormatting` | `boolean` | `true`
|
|
153
|
-
| `verboseFileRoutes` | `boolean` | `undefined` | When `false`, auto-imports `createFileRoute` |
|
|
145
|
+
| Option | Type | Default | Description |
|
|
146
|
+
| --------------------------- | ---------------------- | ---------- | -------------------------------- |
|
|
147
|
+
| `quoteStyle` | `'single' \| 'double'` | `'single'` | Quote style in generated code |
|
|
148
|
+
| `semicolons` | `boolean` | `false` | Use semicolons in generated code |
|
|
149
|
+
| `disableTypes` | `boolean` | `false` | Disable TypeScript types |
|
|
150
|
+
| `disableLogging` | `boolean` | `false` | Suppress plugin logs |
|
|
151
|
+
| `addExtensions` | `boolean \| string` | `false` | Add file extensions to imports |
|
|
152
|
+
| `enableRouteTreeFormatting` | `boolean` | `true` | Format generated route tree |
|
|
154
153
|
|
|
155
154
|
### Virtual Route Config
|
|
156
155
|
|
|
@@ -165,12 +164,11 @@ tanstackRouter({
|
|
|
165
164
|
|
|
166
165
|
## How It Works
|
|
167
166
|
|
|
168
|
-
The composed plugin assembles up to
|
|
167
|
+
The composed plugin assembles up to 3 sub-plugins:
|
|
169
168
|
|
|
170
169
|
1. **Route Generator** (always) — Watches route files and generates `routeTree.gen.ts`
|
|
171
170
|
2. **Code Splitter** (when `autoCodeSplitting: true`) — Splits route files into lazy-loaded chunks using virtual modules
|
|
172
|
-
3. **
|
|
173
|
-
4. **HMR** (dev mode, when code splitter is off) — Hot-reloads route changes without full refresh
|
|
171
|
+
3. **HMR** (dev mode, when code splitter is off) — Hot-reloads route changes without full refresh
|
|
174
172
|
|
|
175
173
|
## Individual Plugin Exports
|
|
176
174
|
|
|
@@ -181,7 +179,6 @@ import {
|
|
|
181
179
|
tanstackRouter, // Composed (default)
|
|
182
180
|
tanstackRouterGenerator, // Generator only
|
|
183
181
|
tanStackRouterCodeSplitter, // Code splitter only
|
|
184
|
-
tanstackRouterAutoImport, // Auto-import only
|
|
185
182
|
} from '@tanstack/router-plugin/vite'
|
|
186
183
|
```
|
|
187
184
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as template from '@babel/template'
|
|
2
2
|
import { createHmrHotExpressionAst } from './hmr-hot-expression'
|
|
3
|
+
import type * as t from '@babel/types'
|
|
3
4
|
import type {
|
|
4
5
|
AnyRoute,
|
|
5
6
|
AnyRouteMatch,
|
|
@@ -159,7 +160,7 @@ const handleRouteUpdateStr = handleRouteUpdate.toString()
|
|
|
159
160
|
export function createRouteHmrStatement(
|
|
160
161
|
stableRouteOptionKeys: Array<string>,
|
|
161
162
|
opts?: { hotExpression?: string },
|
|
162
|
-
) {
|
|
163
|
+
): t.Statement {
|
|
163
164
|
return template.statement(
|
|
164
165
|
`
|
|
165
166
|
if (%%hotExpression%%) {
|
|
@@ -2,7 +2,6 @@ import { getConfig } from '@tanstack/router-generator'
|
|
|
2
2
|
import { unpluginRouterGeneratorFactory } from './router-generator-plugin'
|
|
3
3
|
import { unpluginRouterCodeSplitterFactory } from './router-code-splitter-plugin'
|
|
4
4
|
import { unpluginRouterHmrFactory } from './router-hmr-plugin'
|
|
5
|
-
import { unpluginRouteAutoImportFactory } from './route-autoimport-plugin'
|
|
6
5
|
import type { Config } from './config'
|
|
7
6
|
import type { UnpluginFactory } from 'unplugin'
|
|
8
7
|
|
|
@@ -22,15 +21,11 @@ export const unpluginRouterComposedFactory: UnpluginFactory<
|
|
|
22
21
|
|
|
23
22
|
const routerGenerator = getPlugin(unpluginRouterGeneratorFactory)
|
|
24
23
|
const routerCodeSplitter = getPlugin(unpluginRouterCodeSplitterFactory)
|
|
25
|
-
const routeAutoImport = getPlugin(unpluginRouteAutoImportFactory)
|
|
26
24
|
|
|
27
25
|
const result = [...routerGenerator]
|
|
28
26
|
if (userConfig.autoCodeSplitting) {
|
|
29
27
|
result.push(...routerCodeSplitter)
|
|
30
28
|
}
|
|
31
|
-
if (userConfig.verboseFileRoutes === false) {
|
|
32
|
-
result.push(...routeAutoImport)
|
|
33
|
-
}
|
|
34
29
|
|
|
35
30
|
const isProduction = process.env.NODE_ENV === 'production'
|
|
36
31
|
|
package/src/vite.ts
CHANGED
|
@@ -4,13 +4,8 @@ import { configSchema } from './core/config'
|
|
|
4
4
|
import { unpluginRouterCodeSplitterFactory } from './core/router-code-splitter-plugin'
|
|
5
5
|
import { unpluginRouterGeneratorFactory } from './core/router-generator-plugin'
|
|
6
6
|
import { unpluginRouterComposedFactory } from './core/router-composed-plugin'
|
|
7
|
-
import { unpluginRouteAutoImportFactory } from './core/route-autoimport-plugin'
|
|
8
7
|
import type { CodeSplittingOptions, Config, getConfig } from './core/config'
|
|
9
8
|
|
|
10
|
-
const tanstackRouterAutoImport = createVitePlugin(
|
|
11
|
-
unpluginRouteAutoImportFactory,
|
|
12
|
-
)
|
|
13
|
-
|
|
14
9
|
/**
|
|
15
10
|
* @example
|
|
16
11
|
* ```ts
|
|
@@ -55,7 +50,6 @@ export default tanstackRouter
|
|
|
55
50
|
export {
|
|
56
51
|
configSchema,
|
|
57
52
|
getConfig,
|
|
58
|
-
tanstackRouterAutoImport,
|
|
59
53
|
tanStackRouterCodeSplitter,
|
|
60
54
|
tanstackRouterGenerator,
|
|
61
55
|
TanStackRouterVite,
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const require_config = require("./config.cjs");
|
|
3
|
-
const require_utils = require("./utils.cjs");
|
|
4
|
-
let _tanstack_router_utils = require("@tanstack/router-utils");
|
|
5
|
-
let _babel_template = require("@babel/template");
|
|
6
|
-
_babel_template = require_runtime.__toESM(_babel_template);
|
|
7
|
-
let _babel_core = require("@babel/core");
|
|
8
|
-
_babel_core = require_runtime.__toESM(_babel_core);
|
|
9
|
-
//#region src/core/route-autoimport-plugin.ts
|
|
10
|
-
/**
|
|
11
|
-
* This plugin adds imports for createFileRoute and createLazyFileRoute to the file route.
|
|
12
|
-
*/
|
|
13
|
-
var unpluginRouteAutoImportFactory = (options = {}) => {
|
|
14
|
-
let ROOT = process.cwd();
|
|
15
|
-
let userConfig;
|
|
16
|
-
function initUserConfig() {
|
|
17
|
-
if (typeof options === "function") userConfig = options();
|
|
18
|
-
else userConfig = require_config.getConfig(options, ROOT);
|
|
19
|
-
}
|
|
20
|
-
return {
|
|
21
|
-
name: "tanstack-router:autoimport",
|
|
22
|
-
enforce: "pre",
|
|
23
|
-
transform: {
|
|
24
|
-
filter: {
|
|
25
|
-
id: /\.(m|c)?(j|t)sx?$/,
|
|
26
|
-
code: /createFileRoute\(|createLazyFileRoute\(/
|
|
27
|
-
},
|
|
28
|
-
handler(code, id) {
|
|
29
|
-
const normalizedId = require_utils.normalizePath(id);
|
|
30
|
-
if (!globalThis.TSR_ROUTES_BY_ID_MAP?.has(normalizedId)) return null;
|
|
31
|
-
let routeType;
|
|
32
|
-
if (code.includes("createFileRoute(")) routeType = "createFileRoute";
|
|
33
|
-
else if (code.includes("createLazyFileRoute(")) routeType = "createLazyFileRoute";
|
|
34
|
-
else return null;
|
|
35
|
-
const routerImportPath = `@tanstack/${userConfig.target}-router`;
|
|
36
|
-
const ast = (0, _tanstack_router_utils.parseAst)({ code });
|
|
37
|
-
let isCreateRouteFunctionImported = false;
|
|
38
|
-
_babel_core.traverse(ast, { Program: { enter(programPath) {
|
|
39
|
-
programPath.traverse({ ImportDeclaration(path) {
|
|
40
|
-
if (path.node.specifiers.map((specifier) => specifier.local.name).includes(routeType) && path.node.source.value === routerImportPath) isCreateRouteFunctionImported = true;
|
|
41
|
-
} });
|
|
42
|
-
} } });
|
|
43
|
-
if (!isCreateRouteFunctionImported) {
|
|
44
|
-
if (require_utils.debug) console.info("Adding autoimports to route ", normalizedId);
|
|
45
|
-
const autoImportStatement = _babel_template.statement(`import { ${routeType} } from '${routerImportPath}'`)();
|
|
46
|
-
ast.program.body.unshift(autoImportStatement);
|
|
47
|
-
const result = (0, _tanstack_router_utils.generateFromAst)(ast, {
|
|
48
|
-
sourceMaps: true,
|
|
49
|
-
filename: normalizedId,
|
|
50
|
-
sourceFileName: normalizedId
|
|
51
|
-
});
|
|
52
|
-
if (require_utils.debug) {
|
|
53
|
-
(0, _tanstack_router_utils.logDiff)(code, result.code);
|
|
54
|
-
console.log("Output:\n", result.code + "\n\n");
|
|
55
|
-
}
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
vite: {
|
|
62
|
-
configResolved(config) {
|
|
63
|
-
ROOT = config.root;
|
|
64
|
-
initUserConfig();
|
|
65
|
-
},
|
|
66
|
-
applyToEnvironment() {
|
|
67
|
-
return userConfig.verboseFileRoutes === false;
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
rspack() {
|
|
71
|
-
ROOT = process.cwd();
|
|
72
|
-
initUserConfig();
|
|
73
|
-
},
|
|
74
|
-
webpack() {
|
|
75
|
-
ROOT = process.cwd();
|
|
76
|
-
initUserConfig();
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
//#endregion
|
|
81
|
-
exports.unpluginRouteAutoImportFactory = unpluginRouteAutoImportFactory;
|
|
82
|
-
|
|
83
|
-
//# sourceMappingURL=route-autoimport-plugin.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"route-autoimport-plugin.cjs","names":[],"sources":["../../../src/core/route-autoimport-plugin.ts"],"sourcesContent":["import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'\nimport * as babel from '@babel/core'\nimport * as template from '@babel/template'\nimport { getConfig } from './config'\nimport { debug, normalizePath } from './utils'\nimport type { Config } from './config'\nimport type { UnpluginFactory } from 'unplugin'\n\n/**\n * This plugin adds imports for createFileRoute and createLazyFileRoute to the file route.\n */\nexport const unpluginRouteAutoImportFactory: UnpluginFactory<\n Partial<Config | (() => Config)> | undefined\n> = (options = {}) => {\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 return {\n name: 'tanstack-router:autoimport',\n enforce: 'pre',\n\n transform: {\n filter: {\n // this is necessary for webpack / rspack to avoid matching .html files\n id: /\\.(m|c)?(j|t)sx?$/,\n code: /createFileRoute\\(|createLazyFileRoute\\(/,\n },\n handler(code, id) {\n const normalizedId = normalizePath(id)\n if (!globalThis.TSR_ROUTES_BY_ID_MAP?.has(normalizedId)) {\n return null\n }\n let routeType: 'createFileRoute' | 'createLazyFileRoute'\n if (code.includes('createFileRoute(')) {\n routeType = 'createFileRoute'\n } else if (code.includes('createLazyFileRoute(')) {\n routeType = 'createLazyFileRoute'\n } else {\n return null\n }\n\n const routerImportPath = `@tanstack/${userConfig.target}-router`\n\n const ast = parseAst({ code })\n\n let isCreateRouteFunctionImported = false as boolean\n\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n programPath.traverse({\n ImportDeclaration(path) {\n const importedSpecifiers = path.node.specifiers.map(\n (specifier) => specifier.local.name,\n )\n if (\n importedSpecifiers.includes(routeType) &&\n path.node.source.value === routerImportPath\n ) {\n isCreateRouteFunctionImported = true\n }\n },\n })\n },\n },\n })\n\n if (!isCreateRouteFunctionImported) {\n if (debug) console.info('Adding autoimports to route ', normalizedId)\n\n const autoImportStatement = template.statement(\n `import { ${routeType} } from '${routerImportPath}'`,\n )()\n ast.program.body.unshift(autoImportStatement)\n\n const result = generateFromAst(ast, {\n sourceMaps: true,\n filename: normalizedId,\n sourceFileName: normalizedId,\n })\n if (debug) {\n logDiff(code, result.code)\n console.log('Output:\\n', result.code + '\\n\\n')\n }\n return result\n }\n\n return null\n },\n },\n\n vite: {\n configResolved(config) {\n ROOT = config.root\n initUserConfig()\n },\n // this check may only happen after config is resolved, so we use applyToEnvironment (apply is too early)\n applyToEnvironment() {\n return userConfig.verboseFileRoutes === false\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"],"mappings":";;;;;;;;;;;;AAWA,IAAa,kCAER,UAAU,EAAE,KAAK;CACpB,IAAI,OAAe,QAAQ,KAAK;CAChC,IAAI;CAEJ,SAAS,iBAAiB;AACxB,MAAI,OAAO,YAAY,WACrB,cAAa,SAAS;MAEtB,cAAa,eAAA,UAAU,SAAS,KAAK;;AAGzC,QAAO;EACL,MAAM;EACN,SAAS;EAET,WAAW;GACT,QAAQ;IAEN,IAAI;IACJ,MAAM;IACP;GACD,QAAQ,MAAM,IAAI;IAChB,MAAM,eAAe,cAAA,cAAc,GAAG;AACtC,QAAI,CAAC,WAAW,sBAAsB,IAAI,aAAa,CACrD,QAAO;IAET,IAAI;AACJ,QAAI,KAAK,SAAS,mBAAmB,CACnC,aAAY;aACH,KAAK,SAAS,uBAAuB,CAC9C,aAAY;QAEZ,QAAO;IAGT,MAAM,mBAAmB,aAAa,WAAW,OAAO;IAExD,MAAM,OAAA,GAAA,uBAAA,UAAe,EAAE,MAAM,CAAC;IAE9B,IAAI,gCAAgC;AAEpC,gBAAM,SAAS,KAAK,EAClB,SAAS,EACP,MAAM,aAAa;AACjB,iBAAY,SAAS,EACnB,kBAAkB,MAAM;AAItB,UAH2B,KAAK,KAAK,WAAW,KAC7C,cAAc,UAAU,MAAM,KAChC,CAEoB,SAAS,UAAU,IACtC,KAAK,KAAK,OAAO,UAAU,iBAE3B,iCAAgC;QAGrC,CAAC;OAEL,EACF,CAAC;AAEF,QAAI,CAAC,+BAA+B;AAClC,SAAI,cAAA,MAAO,SAAQ,KAAK,gCAAgC,aAAa;KAErE,MAAM,sBAAsB,gBAAS,UACnC,YAAY,UAAU,WAAW,iBAAiB,GACnD,EAAE;AACH,SAAI,QAAQ,KAAK,QAAQ,oBAAoB;KAE7C,MAAM,UAAA,GAAA,uBAAA,iBAAyB,KAAK;MAClC,YAAY;MACZ,UAAU;MACV,gBAAgB;MACjB,CAAC;AACF,SAAI,cAAA,OAAO;AACT,OAAA,GAAA,uBAAA,SAAQ,MAAM,OAAO,KAAK;AAC1B,cAAQ,IAAI,aAAa,OAAO,OAAO,OAAO;;AAEhD,YAAO;;AAGT,WAAO;;GAEV;EAED,MAAM;GACJ,eAAe,QAAQ;AACrB,WAAO,OAAO;AACd,oBAAgB;;GAGlB,qBAAqB;AACnB,WAAO,WAAW,sBAAsB;;GAE3C;EAED,SAAS;AACP,UAAO,QAAQ,KAAK;AACpB,mBAAgB;;EAGlB,UAAU;AACR,UAAO,QAAQ,KAAK;AACpB,mBAAgB;;EAEnB"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Config } from './config.cjs';
|
|
2
|
-
import { UnpluginFactory } from 'unplugin';
|
|
3
|
-
/**
|
|
4
|
-
* This plugin adds imports for createFileRoute and createLazyFileRoute to the file route.
|
|
5
|
-
*/
|
|
6
|
-
export declare const unpluginRouteAutoImportFactory: UnpluginFactory<Partial<Config | (() => Config)> | undefined>;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Config } from './config.js';
|
|
2
|
-
import { UnpluginFactory } from 'unplugin';
|
|
3
|
-
/**
|
|
4
|
-
* This plugin adds imports for createFileRoute and createLazyFileRoute to the file route.
|
|
5
|
-
*/
|
|
6
|
-
export declare const unpluginRouteAutoImportFactory: UnpluginFactory<Partial<Config | (() => Config)> | undefined>;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { getConfig } from "./config.js";
|
|
2
|
-
import { debug, normalizePath } from "./utils.js";
|
|
3
|
-
import { generateFromAst, logDiff, parseAst } from "@tanstack/router-utils";
|
|
4
|
-
import * as template from "@babel/template";
|
|
5
|
-
import * as babel from "@babel/core";
|
|
6
|
-
//#region src/core/route-autoimport-plugin.ts
|
|
7
|
-
/**
|
|
8
|
-
* This plugin adds imports for createFileRoute and createLazyFileRoute to the file route.
|
|
9
|
-
*/
|
|
10
|
-
var unpluginRouteAutoImportFactory = (options = {}) => {
|
|
11
|
-
let ROOT = process.cwd();
|
|
12
|
-
let userConfig;
|
|
13
|
-
function initUserConfig() {
|
|
14
|
-
if (typeof options === "function") userConfig = options();
|
|
15
|
-
else userConfig = getConfig(options, ROOT);
|
|
16
|
-
}
|
|
17
|
-
return {
|
|
18
|
-
name: "tanstack-router:autoimport",
|
|
19
|
-
enforce: "pre",
|
|
20
|
-
transform: {
|
|
21
|
-
filter: {
|
|
22
|
-
id: /\.(m|c)?(j|t)sx?$/,
|
|
23
|
-
code: /createFileRoute\(|createLazyFileRoute\(/
|
|
24
|
-
},
|
|
25
|
-
handler(code, id) {
|
|
26
|
-
const normalizedId = normalizePath(id);
|
|
27
|
-
if (!globalThis.TSR_ROUTES_BY_ID_MAP?.has(normalizedId)) return null;
|
|
28
|
-
let routeType;
|
|
29
|
-
if (code.includes("createFileRoute(")) routeType = "createFileRoute";
|
|
30
|
-
else if (code.includes("createLazyFileRoute(")) routeType = "createLazyFileRoute";
|
|
31
|
-
else return null;
|
|
32
|
-
const routerImportPath = `@tanstack/${userConfig.target}-router`;
|
|
33
|
-
const ast = parseAst({ code });
|
|
34
|
-
let isCreateRouteFunctionImported = false;
|
|
35
|
-
babel.traverse(ast, { Program: { enter(programPath) {
|
|
36
|
-
programPath.traverse({ ImportDeclaration(path) {
|
|
37
|
-
if (path.node.specifiers.map((specifier) => specifier.local.name).includes(routeType) && path.node.source.value === routerImportPath) isCreateRouteFunctionImported = true;
|
|
38
|
-
} });
|
|
39
|
-
} } });
|
|
40
|
-
if (!isCreateRouteFunctionImported) {
|
|
41
|
-
if (debug) console.info("Adding autoimports to route ", normalizedId);
|
|
42
|
-
const autoImportStatement = template.statement(`import { ${routeType} } from '${routerImportPath}'`)();
|
|
43
|
-
ast.program.body.unshift(autoImportStatement);
|
|
44
|
-
const result = generateFromAst(ast, {
|
|
45
|
-
sourceMaps: true,
|
|
46
|
-
filename: normalizedId,
|
|
47
|
-
sourceFileName: normalizedId
|
|
48
|
-
});
|
|
49
|
-
if (debug) {
|
|
50
|
-
logDiff(code, result.code);
|
|
51
|
-
console.log("Output:\n", result.code + "\n\n");
|
|
52
|
-
}
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
vite: {
|
|
59
|
-
configResolved(config) {
|
|
60
|
-
ROOT = config.root;
|
|
61
|
-
initUserConfig();
|
|
62
|
-
},
|
|
63
|
-
applyToEnvironment() {
|
|
64
|
-
return userConfig.verboseFileRoutes === false;
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
rspack() {
|
|
68
|
-
ROOT = process.cwd();
|
|
69
|
-
initUserConfig();
|
|
70
|
-
},
|
|
71
|
-
webpack() {
|
|
72
|
-
ROOT = process.cwd();
|
|
73
|
-
initUserConfig();
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
//#endregion
|
|
78
|
-
export { unpluginRouteAutoImportFactory };
|
|
79
|
-
|
|
80
|
-
//# sourceMappingURL=route-autoimport-plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"route-autoimport-plugin.js","names":[],"sources":["../../../src/core/route-autoimport-plugin.ts"],"sourcesContent":["import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'\nimport * as babel from '@babel/core'\nimport * as template from '@babel/template'\nimport { getConfig } from './config'\nimport { debug, normalizePath } from './utils'\nimport type { Config } from './config'\nimport type { UnpluginFactory } from 'unplugin'\n\n/**\n * This plugin adds imports for createFileRoute and createLazyFileRoute to the file route.\n */\nexport const unpluginRouteAutoImportFactory: UnpluginFactory<\n Partial<Config | (() => Config)> | undefined\n> = (options = {}) => {\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 return {\n name: 'tanstack-router:autoimport',\n enforce: 'pre',\n\n transform: {\n filter: {\n // this is necessary for webpack / rspack to avoid matching .html files\n id: /\\.(m|c)?(j|t)sx?$/,\n code: /createFileRoute\\(|createLazyFileRoute\\(/,\n },\n handler(code, id) {\n const normalizedId = normalizePath(id)\n if (!globalThis.TSR_ROUTES_BY_ID_MAP?.has(normalizedId)) {\n return null\n }\n let routeType: 'createFileRoute' | 'createLazyFileRoute'\n if (code.includes('createFileRoute(')) {\n routeType = 'createFileRoute'\n } else if (code.includes('createLazyFileRoute(')) {\n routeType = 'createLazyFileRoute'\n } else {\n return null\n }\n\n const routerImportPath = `@tanstack/${userConfig.target}-router`\n\n const ast = parseAst({ code })\n\n let isCreateRouteFunctionImported = false as boolean\n\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n programPath.traverse({\n ImportDeclaration(path) {\n const importedSpecifiers = path.node.specifiers.map(\n (specifier) => specifier.local.name,\n )\n if (\n importedSpecifiers.includes(routeType) &&\n path.node.source.value === routerImportPath\n ) {\n isCreateRouteFunctionImported = true\n }\n },\n })\n },\n },\n })\n\n if (!isCreateRouteFunctionImported) {\n if (debug) console.info('Adding autoimports to route ', normalizedId)\n\n const autoImportStatement = template.statement(\n `import { ${routeType} } from '${routerImportPath}'`,\n )()\n ast.program.body.unshift(autoImportStatement)\n\n const result = generateFromAst(ast, {\n sourceMaps: true,\n filename: normalizedId,\n sourceFileName: normalizedId,\n })\n if (debug) {\n logDiff(code, result.code)\n console.log('Output:\\n', result.code + '\\n\\n')\n }\n return result\n }\n\n return null\n },\n },\n\n vite: {\n configResolved(config) {\n ROOT = config.root\n initUserConfig()\n },\n // this check may only happen after config is resolved, so we use applyToEnvironment (apply is too early)\n applyToEnvironment() {\n return userConfig.verboseFileRoutes === false\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"],"mappings":";;;;;;;;;AAWA,IAAa,kCAER,UAAU,EAAE,KAAK;CACpB,IAAI,OAAe,QAAQ,KAAK;CAChC,IAAI;CAEJ,SAAS,iBAAiB;AACxB,MAAI,OAAO,YAAY,WACrB,cAAa,SAAS;MAEtB,cAAa,UAAU,SAAS,KAAK;;AAGzC,QAAO;EACL,MAAM;EACN,SAAS;EAET,WAAW;GACT,QAAQ;IAEN,IAAI;IACJ,MAAM;IACP;GACD,QAAQ,MAAM,IAAI;IAChB,MAAM,eAAe,cAAc,GAAG;AACtC,QAAI,CAAC,WAAW,sBAAsB,IAAI,aAAa,CACrD,QAAO;IAET,IAAI;AACJ,QAAI,KAAK,SAAS,mBAAmB,CACnC,aAAY;aACH,KAAK,SAAS,uBAAuB,CAC9C,aAAY;QAEZ,QAAO;IAGT,MAAM,mBAAmB,aAAa,WAAW,OAAO;IAExD,MAAM,MAAM,SAAS,EAAE,MAAM,CAAC;IAE9B,IAAI,gCAAgC;AAEpC,UAAM,SAAS,KAAK,EAClB,SAAS,EACP,MAAM,aAAa;AACjB,iBAAY,SAAS,EACnB,kBAAkB,MAAM;AAItB,UAH2B,KAAK,KAAK,WAAW,KAC7C,cAAc,UAAU,MAAM,KAChC,CAEoB,SAAS,UAAU,IACtC,KAAK,KAAK,OAAO,UAAU,iBAE3B,iCAAgC;QAGrC,CAAC;OAEL,EACF,CAAC;AAEF,QAAI,CAAC,+BAA+B;AAClC,SAAI,MAAO,SAAQ,KAAK,gCAAgC,aAAa;KAErE,MAAM,sBAAsB,SAAS,UACnC,YAAY,UAAU,WAAW,iBAAiB,GACnD,EAAE;AACH,SAAI,QAAQ,KAAK,QAAQ,oBAAoB;KAE7C,MAAM,SAAS,gBAAgB,KAAK;MAClC,YAAY;MACZ,UAAU;MACV,gBAAgB;MACjB,CAAC;AACF,SAAI,OAAO;AACT,cAAQ,MAAM,OAAO,KAAK;AAC1B,cAAQ,IAAI,aAAa,OAAO,OAAO,OAAO;;AAEhD,YAAO;;AAGT,WAAO;;GAEV;EAED,MAAM;GACJ,eAAe,QAAQ;AACrB,WAAO,OAAO;AACd,oBAAgB;;GAGlB,qBAAqB;AACnB,WAAO,WAAW,sBAAsB;;GAE3C;EAED,SAAS;AACP,UAAO,QAAQ,KAAK;AACpB,mBAAgB;;EAGlB,UAAU;AACR,UAAO,QAAQ,KAAK;AACpB,mBAAgB;;EAEnB"}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'
|
|
2
|
-
import * as babel from '@babel/core'
|
|
3
|
-
import * as template from '@babel/template'
|
|
4
|
-
import { getConfig } from './config'
|
|
5
|
-
import { debug, normalizePath } from './utils'
|
|
6
|
-
import type { Config } from './config'
|
|
7
|
-
import type { UnpluginFactory } from 'unplugin'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* This plugin adds imports for createFileRoute and createLazyFileRoute to the file route.
|
|
11
|
-
*/
|
|
12
|
-
export const unpluginRouteAutoImportFactory: UnpluginFactory<
|
|
13
|
-
Partial<Config | (() => Config)> | undefined
|
|
14
|
-
> = (options = {}) => {
|
|
15
|
-
let ROOT: string = process.cwd()
|
|
16
|
-
let userConfig: Config
|
|
17
|
-
|
|
18
|
-
function initUserConfig() {
|
|
19
|
-
if (typeof options === 'function') {
|
|
20
|
-
userConfig = options()
|
|
21
|
-
} else {
|
|
22
|
-
userConfig = getConfig(options, ROOT)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
name: 'tanstack-router:autoimport',
|
|
27
|
-
enforce: 'pre',
|
|
28
|
-
|
|
29
|
-
transform: {
|
|
30
|
-
filter: {
|
|
31
|
-
// this is necessary for webpack / rspack to avoid matching .html files
|
|
32
|
-
id: /\.(m|c)?(j|t)sx?$/,
|
|
33
|
-
code: /createFileRoute\(|createLazyFileRoute\(/,
|
|
34
|
-
},
|
|
35
|
-
handler(code, id) {
|
|
36
|
-
const normalizedId = normalizePath(id)
|
|
37
|
-
if (!globalThis.TSR_ROUTES_BY_ID_MAP?.has(normalizedId)) {
|
|
38
|
-
return null
|
|
39
|
-
}
|
|
40
|
-
let routeType: 'createFileRoute' | 'createLazyFileRoute'
|
|
41
|
-
if (code.includes('createFileRoute(')) {
|
|
42
|
-
routeType = 'createFileRoute'
|
|
43
|
-
} else if (code.includes('createLazyFileRoute(')) {
|
|
44
|
-
routeType = 'createLazyFileRoute'
|
|
45
|
-
} else {
|
|
46
|
-
return null
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const routerImportPath = `@tanstack/${userConfig.target}-router`
|
|
50
|
-
|
|
51
|
-
const ast = parseAst({ code })
|
|
52
|
-
|
|
53
|
-
let isCreateRouteFunctionImported = false as boolean
|
|
54
|
-
|
|
55
|
-
babel.traverse(ast, {
|
|
56
|
-
Program: {
|
|
57
|
-
enter(programPath) {
|
|
58
|
-
programPath.traverse({
|
|
59
|
-
ImportDeclaration(path) {
|
|
60
|
-
const importedSpecifiers = path.node.specifiers.map(
|
|
61
|
-
(specifier) => specifier.local.name,
|
|
62
|
-
)
|
|
63
|
-
if (
|
|
64
|
-
importedSpecifiers.includes(routeType) &&
|
|
65
|
-
path.node.source.value === routerImportPath
|
|
66
|
-
) {
|
|
67
|
-
isCreateRouteFunctionImported = true
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
})
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
if (!isCreateRouteFunctionImported) {
|
|
76
|
-
if (debug) console.info('Adding autoimports to route ', normalizedId)
|
|
77
|
-
|
|
78
|
-
const autoImportStatement = template.statement(
|
|
79
|
-
`import { ${routeType} } from '${routerImportPath}'`,
|
|
80
|
-
)()
|
|
81
|
-
ast.program.body.unshift(autoImportStatement)
|
|
82
|
-
|
|
83
|
-
const result = generateFromAst(ast, {
|
|
84
|
-
sourceMaps: true,
|
|
85
|
-
filename: normalizedId,
|
|
86
|
-
sourceFileName: normalizedId,
|
|
87
|
-
})
|
|
88
|
-
if (debug) {
|
|
89
|
-
logDiff(code, result.code)
|
|
90
|
-
console.log('Output:\n', result.code + '\n\n')
|
|
91
|
-
}
|
|
92
|
-
return result
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return null
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
vite: {
|
|
100
|
-
configResolved(config) {
|
|
101
|
-
ROOT = config.root
|
|
102
|
-
initUserConfig()
|
|
103
|
-
},
|
|
104
|
-
// this check may only happen after config is resolved, so we use applyToEnvironment (apply is too early)
|
|
105
|
-
applyToEnvironment() {
|
|
106
|
-
return userConfig.verboseFileRoutes === false
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
rspack() {
|
|
111
|
-
ROOT = process.cwd()
|
|
112
|
-
initUserConfig()
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
webpack() {
|
|
116
|
-
ROOT = process.cwd()
|
|
117
|
-
initUserConfig()
|
|
118
|
-
},
|
|
119
|
-
}
|
|
120
|
-
}
|