@tanstack/router-plugin 1.120.4-alpha.4 → 1.120.4
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 +21 -39
- package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/compilers.d.cts +0 -3
- package/dist/cjs/core/code-splitter/framework-options.cjs +8 -4
- package/dist/cjs/core/code-splitter/framework-options.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/framework-options.d.cts +2 -0
- package/dist/cjs/core/config.d.cts +40 -31
- package/dist/cjs/core/router-code-splitter-plugin.cjs +20 -11
- package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-composed-plugin.cjs +5 -19
- package/dist/cjs/core/router-composed-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-generator-plugin.cjs +2 -8
- package/dist/cjs/core/router-generator-plugin.cjs.map +1 -1
- package/dist/cjs/esbuild.d.cts +27 -21
- package/dist/cjs/rspack.d.cts +27 -21
- package/dist/cjs/vite.cjs +0 -2
- package/dist/cjs/vite.cjs.map +1 -1
- package/dist/cjs/vite.d.cts +26 -52
- package/dist/cjs/webpack.d.cts +27 -21
- package/dist/esm/core/code-splitter/compilers.d.ts +0 -3
- package/dist/esm/core/code-splitter/compilers.js +21 -39
- package/dist/esm/core/code-splitter/compilers.js.map +1 -1
- package/dist/esm/core/code-splitter/framework-options.d.ts +2 -0
- package/dist/esm/core/code-splitter/framework-options.js +8 -4
- package/dist/esm/core/code-splitter/framework-options.js.map +1 -1
- package/dist/esm/core/config.d.ts +40 -31
- package/dist/esm/core/router-code-splitter-plugin.js +14 -5
- package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
- package/dist/esm/core/router-composed-plugin.js +5 -19
- package/dist/esm/core/router-composed-plugin.js.map +1 -1
- package/dist/esm/core/router-generator-plugin.js +2 -8
- package/dist/esm/core/router-generator-plugin.js.map +1 -1
- package/dist/esm/esbuild.d.ts +27 -21
- package/dist/esm/rspack.d.ts +27 -21
- package/dist/esm/vite.d.ts +26 -52
- package/dist/esm/vite.js +1 -3
- package/dist/esm/vite.js.map +1 -1
- package/dist/esm/webpack.d.ts +27 -21
- package/package.json +6 -6
- package/src/core/code-splitter/compilers.ts +27 -54
- package/src/core/code-splitter/framework-options.ts +6 -0
- package/src/core/router-code-splitter-plugin.ts +23 -3
- package/src/core/router-composed-plugin.ts +10 -20
- package/src/core/router-generator-plugin.ts +1 -12
- package/src/vite.ts +0 -3
- package/dist/cjs/core/route-autoimport-plugin.cjs +0 -98
- package/dist/cjs/core/route-autoimport-plugin.cjs.map +0 -1
- package/dist/cjs/core/route-autoimport-plugin.d.cts +0 -6
- package/dist/cjs/core/route-hmr-statement.cjs +0 -33
- package/dist/cjs/core/route-hmr-statement.cjs.map +0 -1
- package/dist/cjs/core/route-hmr-statement.d.cts +0 -1
- package/dist/cjs/core/router-hmr-plugin.cjs +0 -51
- package/dist/cjs/core/router-hmr-plugin.cjs.map +0 -1
- package/dist/cjs/core/router-hmr-plugin.d.cts +0 -8
- package/dist/cjs/core/utils.cjs +0 -12
- package/dist/cjs/core/utils.cjs.map +0 -1
- package/dist/cjs/core/utils.d.cts +0 -2
- package/dist/esm/core/route-autoimport-plugin.d.ts +0 -6
- package/dist/esm/core/route-autoimport-plugin.js +0 -81
- package/dist/esm/core/route-autoimport-plugin.js.map +0 -1
- package/dist/esm/core/route-hmr-statement.d.ts +0 -1
- package/dist/esm/core/route-hmr-statement.js +0 -16
- package/dist/esm/core/route-hmr-statement.js.map +0 -1
- package/dist/esm/core/router-hmr-plugin.d.ts +0 -8
- package/dist/esm/core/router-hmr-plugin.js +0 -51
- package/dist/esm/core/router-hmr-plugin.js.map +0 -1
- package/dist/esm/core/utils.d.ts +0 -2
- package/dist/esm/core/utils.js +0 -12
- package/dist/esm/core/utils.js.map +0 -1
- package/src/core/route-autoimport-plugin.ts +0 -102
- package/src/core/route-hmr-statement.ts +0 -13
- package/src/core/router-hmr-plugin.ts +0 -65
- package/src/core/utils.ts +0 -18
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'
|
|
2
|
-
import babel from '@babel/core'
|
|
3
|
-
import * as template from '@babel/template'
|
|
4
|
-
import { getConfig } from './config'
|
|
5
|
-
import { debug, fileIsInRoutesDirectory } 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> | undefined
|
|
14
|
-
> = (options = {}) => {
|
|
15
|
-
let ROOT: string = process.cwd()
|
|
16
|
-
let userConfig = options as Config
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
name: 'router-autoimport-plugin',
|
|
20
|
-
enforce: 'pre',
|
|
21
|
-
|
|
22
|
-
transform(code, id) {
|
|
23
|
-
let routeType: 'createFileRoute' | 'createLazyFileRoute'
|
|
24
|
-
if (code.includes('export const Route = createFileRoute(')) {
|
|
25
|
-
routeType = 'createFileRoute'
|
|
26
|
-
} else if (code.includes('export const Route = createLazyFileRoute(')) {
|
|
27
|
-
routeType = 'createLazyFileRoute'
|
|
28
|
-
} else {
|
|
29
|
-
return null
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const routerImportPath = `@tanstack/${userConfig.target}-router`
|
|
33
|
-
|
|
34
|
-
const ast = parseAst({ code })
|
|
35
|
-
|
|
36
|
-
let isCreateRouteFunctionImported = false as boolean
|
|
37
|
-
|
|
38
|
-
babel.traverse(ast, {
|
|
39
|
-
Program: {
|
|
40
|
-
enter(programPath) {
|
|
41
|
-
programPath.traverse({
|
|
42
|
-
ImportDeclaration(path) {
|
|
43
|
-
const importedSpecifiers = path.node.specifiers.map(
|
|
44
|
-
(specifier) => specifier.local.name,
|
|
45
|
-
)
|
|
46
|
-
if (
|
|
47
|
-
importedSpecifiers.includes(routeType) &&
|
|
48
|
-
path.node.source.value === routerImportPath
|
|
49
|
-
) {
|
|
50
|
-
isCreateRouteFunctionImported = true
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
})
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
if (!isCreateRouteFunctionImported) {
|
|
59
|
-
if (debug) console.info('Adding autoimports to route ', id)
|
|
60
|
-
|
|
61
|
-
const autoImportStatement = template.statement(
|
|
62
|
-
`import { ${routeType} } from '${routerImportPath}'`,
|
|
63
|
-
)()
|
|
64
|
-
ast.program.body.unshift(autoImportStatement)
|
|
65
|
-
|
|
66
|
-
const result = generateFromAst(ast, {
|
|
67
|
-
sourceMaps: true,
|
|
68
|
-
filename: id,
|
|
69
|
-
sourceFileName: id,
|
|
70
|
-
})
|
|
71
|
-
if (debug) {
|
|
72
|
-
logDiff(code, result.code)
|
|
73
|
-
console.log('Output:\n', result.code + '\n\n')
|
|
74
|
-
}
|
|
75
|
-
return result
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return null
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
transformInclude(id) {
|
|
82
|
-
return fileIsInRoutesDirectory(id, userConfig.routesDirectory)
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
vite: {
|
|
86
|
-
configResolved(config) {
|
|
87
|
-
ROOT = config.root
|
|
88
|
-
userConfig = getConfig(options, ROOT)
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
rspack() {
|
|
93
|
-
ROOT = process.cwd()
|
|
94
|
-
userConfig = getConfig(options, ROOT)
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
webpack() {
|
|
98
|
-
ROOT = process.cwd()
|
|
99
|
-
userConfig = getConfig(options, ROOT)
|
|
100
|
-
},
|
|
101
|
-
}
|
|
102
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as template from '@babel/template'
|
|
2
|
-
|
|
3
|
-
export const routeHmrStatement = template.statement(
|
|
4
|
-
`
|
|
5
|
-
if (import.meta.hot) {
|
|
6
|
-
import.meta.hot.accept((newModule) => {
|
|
7
|
-
if (newModule.Route && typeof newModule.Route.clone === 'function') {
|
|
8
|
-
newModule.Route.clone(Route)
|
|
9
|
-
}
|
|
10
|
-
})
|
|
11
|
-
}
|
|
12
|
-
`,
|
|
13
|
-
)()
|
|
@@ -1,65 +0,0 @@
|
|
|
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
|
-
}
|
package/src/core/utils.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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
|
-
}
|