@tanstack/router-plugin 1.120.3 → 1.120.4-alpha.1
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 +39 -21
- package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/compilers.d.cts +3 -0
- package/dist/cjs/core/code-splitter/framework-options.cjs +4 -8
- package/dist/cjs/core/code-splitter/framework-options.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/framework-options.d.cts +0 -2
- package/dist/cjs/core/config.d.cts +31 -40
- package/dist/cjs/core/route-autoimport-plugin.cjs +98 -0
- package/dist/cjs/core/route-autoimport-plugin.cjs.map +1 -0
- package/dist/cjs/core/route-autoimport-plugin.d.cts +6 -0
- package/dist/cjs/core/route-hmr-statement.cjs +33 -0
- package/dist/cjs/core/route-hmr-statement.cjs.map +1 -0
- package/dist/cjs/core/route-hmr-statement.d.cts +1 -0
- package/dist/cjs/core/router-code-splitter-plugin.cjs +11 -20
- package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-composed-plugin.cjs +19 -5
- package/dist/cjs/core/router-composed-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-generator-plugin.cjs +8 -2
- package/dist/cjs/core/router-generator-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-hmr-plugin.cjs +51 -0
- package/dist/cjs/core/router-hmr-plugin.cjs.map +1 -0
- package/dist/cjs/core/router-hmr-plugin.d.cts +8 -0
- package/dist/cjs/core/utils.cjs +12 -0
- package/dist/cjs/core/utils.cjs.map +1 -0
- package/dist/cjs/core/utils.d.cts +2 -0
- package/dist/cjs/esbuild.d.cts +21 -27
- package/dist/cjs/rspack.d.cts +21 -27
- package/dist/cjs/vite.cjs +2 -0
- package/dist/cjs/vite.cjs.map +1 -1
- package/dist/cjs/vite.d.cts +52 -26
- package/dist/cjs/webpack.d.cts +21 -27
- package/dist/esm/core/code-splitter/compilers.d.ts +3 -0
- package/dist/esm/core/code-splitter/compilers.js +39 -21
- package/dist/esm/core/code-splitter/compilers.js.map +1 -1
- package/dist/esm/core/code-splitter/framework-options.d.ts +0 -2
- package/dist/esm/core/code-splitter/framework-options.js +4 -8
- package/dist/esm/core/code-splitter/framework-options.js.map +1 -1
- package/dist/esm/core/config.d.ts +31 -40
- package/dist/esm/core/route-autoimport-plugin.d.ts +6 -0
- package/dist/esm/core/route-autoimport-plugin.js +81 -0
- package/dist/esm/core/route-autoimport-plugin.js.map +1 -0
- package/dist/esm/core/route-hmr-statement.d.ts +1 -0
- package/dist/esm/core/route-hmr-statement.js +16 -0
- package/dist/esm/core/route-hmr-statement.js.map +1 -0
- package/dist/esm/core/router-code-splitter-plugin.js +5 -14
- package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
- package/dist/esm/core/router-composed-plugin.js +19 -5
- package/dist/esm/core/router-composed-plugin.js.map +1 -1
- package/dist/esm/core/router-generator-plugin.js +8 -2
- package/dist/esm/core/router-generator-plugin.js.map +1 -1
- package/dist/esm/core/router-hmr-plugin.d.ts +8 -0
- package/dist/esm/core/router-hmr-plugin.js +51 -0
- package/dist/esm/core/router-hmr-plugin.js.map +1 -0
- package/dist/esm/core/utils.d.ts +2 -0
- package/dist/esm/core/utils.js +12 -0
- package/dist/esm/core/utils.js.map +1 -0
- package/dist/esm/esbuild.d.ts +21 -27
- package/dist/esm/rspack.d.ts +21 -27
- package/dist/esm/vite.d.ts +52 -26
- package/dist/esm/vite.js +3 -1
- package/dist/esm/vite.js.map +1 -1
- package/dist/esm/webpack.d.ts +21 -27
- package/package.json +6 -6
- package/src/core/code-splitter/compilers.ts +54 -27
- package/src/core/code-splitter/framework-options.ts +0 -6
- package/src/core/route-autoimport-plugin.ts +102 -0
- package/src/core/route-hmr-statement.ts +13 -0
- package/src/core/router-code-splitter-plugin.ts +3 -23
- package/src/core/router-composed-plugin.ts +20 -10
- package/src/core/router-generator-plugin.ts +12 -1
- package/src/core/router-hmr-plugin.ts +65 -0
- package/src/core/utils.ts +18 -0
- package/src/vite.ts +3 -0
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* https://github.com/TanStack/router/pull/3355
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { isAbsolute, join, normalize } from 'node:path'
|
|
7
6
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
8
7
|
import { logDiff } from '@tanstack/router-utils'
|
|
9
8
|
import { getConfig, splitGroupingsSchema } from './config'
|
|
@@ -18,6 +17,7 @@ import {
|
|
|
18
17
|
tsrSplit,
|
|
19
18
|
} from './constants'
|
|
20
19
|
import { decodeIdentifier } from './code-splitter/path-ids'
|
|
20
|
+
import { debug, fileIsInRoutesDirectory } from './utils'
|
|
21
21
|
import type { CodeSplitGroupings, SplitRouteIdentNodes } from './constants'
|
|
22
22
|
|
|
23
23
|
import type { Config } from './config'
|
|
@@ -27,27 +27,10 @@ import type {
|
|
|
27
27
|
TransformResult as UnpluginTransformResult,
|
|
28
28
|
} from 'unplugin'
|
|
29
29
|
|
|
30
|
-
const debug =
|
|
31
|
-
process.env.TSR_VITE_DEBUG &&
|
|
32
|
-
['true', 'router-plugin'].includes(process.env.TSR_VITE_DEBUG)
|
|
33
|
-
|
|
34
30
|
function capitalizeFirst(str: string): string {
|
|
35
31
|
return str.charAt(0).toUpperCase() + str.slice(1)
|
|
36
32
|
}
|
|
37
33
|
|
|
38
|
-
function fileIsInRoutesDirectory(
|
|
39
|
-
filePath: string,
|
|
40
|
-
routesDirectory: string,
|
|
41
|
-
): boolean {
|
|
42
|
-
const routesDirectoryPath = isAbsolute(routesDirectory)
|
|
43
|
-
? routesDirectory
|
|
44
|
-
: join(process.cwd(), routesDirectory)
|
|
45
|
-
|
|
46
|
-
const path = normalize(filePath)
|
|
47
|
-
|
|
48
|
-
return path.startsWith(routesDirectoryPath)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
34
|
type BannedBeforeExternalPlugin = {
|
|
52
35
|
identifier: string
|
|
53
36
|
pkg: string
|
|
@@ -104,8 +87,6 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
104
87
|
|
|
105
88
|
const fromCode = detectCodeSplitGroupingsFromRoute({
|
|
106
89
|
code,
|
|
107
|
-
root: ROOT,
|
|
108
|
-
filename: id,
|
|
109
90
|
})
|
|
110
91
|
|
|
111
92
|
if (fromCode.groupings) {
|
|
@@ -139,11 +120,11 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
139
120
|
|
|
140
121
|
const compiledReferenceRoute = compileCodeSplitReferenceRoute({
|
|
141
122
|
code,
|
|
142
|
-
root: ROOT,
|
|
143
|
-
filename: id,
|
|
144
123
|
runtimeEnv: isProduction ? 'prod' : 'dev',
|
|
145
124
|
codeSplitGroupings: splitGroupings,
|
|
146
125
|
targetFramework: userConfig.target,
|
|
126
|
+
filename: id,
|
|
127
|
+
id,
|
|
147
128
|
})
|
|
148
129
|
|
|
149
130
|
if (debug) {
|
|
@@ -178,7 +159,6 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
178
159
|
|
|
179
160
|
const result = compileCodeSplitVirtualRoute({
|
|
180
161
|
code,
|
|
181
|
-
root: ROOT,
|
|
182
162
|
filename: id,
|
|
183
163
|
splitTargets: grouping,
|
|
184
164
|
})
|
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
import { unpluginRouterGeneratorFactory } from './router-generator-plugin'
|
|
2
2
|
import { unpluginRouterCodeSplitterFactory } from './router-code-splitter-plugin'
|
|
3
|
-
|
|
3
|
+
import { unpluginRouterHmrFactory } from './router-hmr-plugin'
|
|
4
|
+
import { unpluginRouteAutoimportFactory } from './route-autoimport-plugin'
|
|
4
5
|
import type { Config } from './config'
|
|
5
6
|
import type { UnpluginFactory } from 'unplugin'
|
|
6
7
|
|
|
7
8
|
export const unpluginRouterComposedFactory: UnpluginFactory<
|
|
8
9
|
Partial<Config> | undefined
|
|
9
10
|
> = (options = {}, meta) => {
|
|
10
|
-
const
|
|
11
|
+
const getPlugin = (pluginFactory: UnpluginFactory<Partial<Config>>) => {
|
|
12
|
+
const plugin = pluginFactory(options, meta)
|
|
13
|
+
if (!Array.isArray(plugin)) {
|
|
14
|
+
return [plugin]
|
|
15
|
+
}
|
|
16
|
+
return plugin
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const routerGenerator = getPlugin(unpluginRouterGeneratorFactory)
|
|
20
|
+
const routerCodeSplitter = getPlugin(unpluginRouterCodeSplitterFactory)
|
|
21
|
+
const routeAutoImport = getPlugin(unpluginRouteAutoimportFactory)
|
|
11
22
|
|
|
12
|
-
const
|
|
13
|
-
? routerGenerator
|
|
14
|
-
: [routerGenerator]
|
|
23
|
+
const result = [...routerGenerator, ...routerCodeSplitter, ...routeAutoImport]
|
|
15
24
|
|
|
16
|
-
const
|
|
17
|
-
const routerCodeSplitterOptions = Array.isArray(routerCodeSplitter)
|
|
18
|
-
? routerCodeSplitter
|
|
19
|
-
: [routerCodeSplitter]
|
|
25
|
+
const isProduction = process.env.NODE_ENV === 'production'
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
if (!isProduction && !options.autoCodeSplitting) {
|
|
28
|
+
const routerHmr = getPlugin(unpluginRouterHmrFactory)
|
|
29
|
+
result.push(...routerHmr)
|
|
30
|
+
}
|
|
31
|
+
return result
|
|
22
32
|
}
|
|
@@ -82,12 +82,23 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
|
|
|
82
82
|
})
|
|
83
83
|
},
|
|
84
84
|
vite: {
|
|
85
|
-
|
|
85
|
+
configResolved(config) {
|
|
86
86
|
ROOT = config.root
|
|
87
87
|
userConfig = getConfig(options, ROOT)
|
|
88
88
|
|
|
89
|
+
// if (config.command === 'serve') {
|
|
90
|
+
// await run(generate)
|
|
91
|
+
// }
|
|
92
|
+
},
|
|
93
|
+
async buildStart() {
|
|
94
|
+
if (this.environment.name === 'server') {
|
|
95
|
+
// When building in environment mode, we only need to generate routes
|
|
96
|
+
// for the client environment
|
|
97
|
+
return
|
|
98
|
+
}
|
|
89
99
|
await run(generate)
|
|
90
100
|
},
|
|
101
|
+
sharedDuringBuild: true,
|
|
91
102
|
},
|
|
92
103
|
rspack(compiler) {
|
|
93
104
|
userConfig = getConfig(options, ROOT)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'
|
|
2
|
+
import { getConfig } from './config'
|
|
3
|
+
import { routeHmrStatement } from './route-hmr-statement'
|
|
4
|
+
import { debug, fileIsInRoutesDirectory } from './utils'
|
|
5
|
+
import type { Config } from './config'
|
|
6
|
+
import type { UnpluginFactory } from 'unplugin'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This plugin adds HMR support for file routes.
|
|
10
|
+
* It is only added to the composed plugin in dev when autoCodeSplitting is disabled, since the code splitting plugin
|
|
11
|
+
* handles HMR for code-split routes itself.
|
|
12
|
+
*/
|
|
13
|
+
export const unpluginRouterHmrFactory: UnpluginFactory<
|
|
14
|
+
Partial<Config> | undefined
|
|
15
|
+
> = (options = {}) => {
|
|
16
|
+
let ROOT: string = process.cwd()
|
|
17
|
+
let userConfig = options as Config
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
name: 'router-hmr-plugin',
|
|
21
|
+
enforce: 'pre',
|
|
22
|
+
|
|
23
|
+
transform(code, id) {
|
|
24
|
+
if (!code.includes('export const Route = createFileRoute(')) {
|
|
25
|
+
return null
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (debug) console.info('Adding HMR handling to route ', id)
|
|
29
|
+
|
|
30
|
+
const ast = parseAst({ code })
|
|
31
|
+
ast.program.body.push(routeHmrStatement)
|
|
32
|
+
const result = generateFromAst(ast, {
|
|
33
|
+
sourceMaps: true,
|
|
34
|
+
filename: id,
|
|
35
|
+
sourceFileName: id,
|
|
36
|
+
})
|
|
37
|
+
if (debug) {
|
|
38
|
+
logDiff(code, result.code)
|
|
39
|
+
console.log('Output:\n', result.code + '\n\n')
|
|
40
|
+
}
|
|
41
|
+
return result
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
transformInclude(id) {
|
|
45
|
+
return fileIsInRoutesDirectory(id, userConfig.routesDirectory)
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
vite: {
|
|
49
|
+
configResolved(config) {
|
|
50
|
+
ROOT = config.root
|
|
51
|
+
userConfig = getConfig(options, ROOT)
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
rspack() {
|
|
56
|
+
ROOT = process.cwd()
|
|
57
|
+
userConfig = getConfig(options, ROOT)
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
webpack() {
|
|
61
|
+
ROOT = process.cwd()
|
|
62
|
+
userConfig = getConfig(options, ROOT)
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isAbsolute, join, normalize } from 'node:path'
|
|
2
|
+
|
|
3
|
+
export const debug =
|
|
4
|
+
process.env.TSR_VITE_DEBUG &&
|
|
5
|
+
['true', 'router-plugin'].includes(process.env.TSR_VITE_DEBUG)
|
|
6
|
+
|
|
7
|
+
export function fileIsInRoutesDirectory(
|
|
8
|
+
filePath: string,
|
|
9
|
+
routesDirectory: string,
|
|
10
|
+
): boolean {
|
|
11
|
+
const routesDirectoryPath = isAbsolute(routesDirectory)
|
|
12
|
+
? routesDirectory
|
|
13
|
+
: join(process.cwd(), routesDirectory)
|
|
14
|
+
|
|
15
|
+
const path = normalize(filePath)
|
|
16
|
+
|
|
17
|
+
return path.startsWith(routesDirectoryPath)
|
|
18
|
+
}
|
package/src/vite.ts
CHANGED
|
@@ -43,6 +43,7 @@ const TanStackRouterCodeSplitterVite = createVitePlugin(
|
|
|
43
43
|
* ```
|
|
44
44
|
*/
|
|
45
45
|
const TanStackRouterVite = createVitePlugin(unpluginRouterComposedFactory)
|
|
46
|
+
const tanstackRouter = TanStackRouterVite
|
|
46
47
|
|
|
47
48
|
export default TanStackRouterVite
|
|
48
49
|
export {
|
|
@@ -50,5 +51,7 @@ export {
|
|
|
50
51
|
TanStackRouterGeneratorVite,
|
|
51
52
|
TanStackRouterCodeSplitterVite,
|
|
52
53
|
TanStackRouterVite,
|
|
54
|
+
tanstackRouter,
|
|
53
55
|
}
|
|
56
|
+
|
|
54
57
|
export type { Config }
|