@tanstack/router-cli 0.0.1-beta.56 → 0.0.1-beta.63
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/build/cjs/generator.js +8 -8
- package/build/cjs/generator.js.map +1 -1
- package/build/cjs/transformCode.js +22 -23
- package/build/cjs/transformCode.js.map +1 -1
- package/build/esm/index.js +30 -31
- package/build/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/generator.ts +9 -9
- package/src/transformCode.ts +25 -25
package/src/transformCode.ts
CHANGED
|
@@ -12,8 +12,6 @@ import {
|
|
|
12
12
|
import path from 'path'
|
|
13
13
|
|
|
14
14
|
export const isolatedProperties = [
|
|
15
|
-
'loader',
|
|
16
|
-
'action',
|
|
17
15
|
'component',
|
|
18
16
|
'errorComponent',
|
|
19
17
|
'pendingComponent',
|
|
@@ -53,7 +51,6 @@ export async function ensureBoilerplate(node: RouteNode, code: string) {
|
|
|
53
51
|
Program: {
|
|
54
52
|
enter(programPath) {
|
|
55
53
|
// Remove all properties except for our isolated one
|
|
56
|
-
|
|
57
54
|
if (node.isRoot) {
|
|
58
55
|
let foundImport = false
|
|
59
56
|
|
|
@@ -61,7 +58,7 @@ export async function ensureBoilerplate(node: RouteNode, code: string) {
|
|
|
61
58
|
ImportSpecifier(importPath) {
|
|
62
59
|
if (
|
|
63
60
|
t.isIdentifier(importPath.node.imported) &&
|
|
64
|
-
importPath.node.imported.name === '
|
|
61
|
+
importPath.node.imported.name === 'Route'
|
|
65
62
|
) {
|
|
66
63
|
foundImport = true
|
|
67
64
|
}
|
|
@@ -71,7 +68,7 @@ export async function ensureBoilerplate(node: RouteNode, code: string) {
|
|
|
71
68
|
if (!foundImport) {
|
|
72
69
|
programPath.node.body.unshift(
|
|
73
70
|
babel.template.statement(
|
|
74
|
-
`import {
|
|
71
|
+
`import { Route } from '@tanstack/react-router'`,
|
|
75
72
|
)(),
|
|
76
73
|
)
|
|
77
74
|
}
|
|
@@ -81,7 +78,7 @@ export async function ensureBoilerplate(node: RouteNode, code: string) {
|
|
|
81
78
|
ImportSpecifier(importPath) {
|
|
82
79
|
if (
|
|
83
80
|
t.isIdentifier(importPath.node.imported) &&
|
|
84
|
-
importPath.node.imported.name === '
|
|
81
|
+
importPath.node.imported.name === 'route'
|
|
85
82
|
) {
|
|
86
83
|
foundImport = true
|
|
87
84
|
if (t.isImportDeclaration(importPath.parentPath.node)) {
|
|
@@ -99,7 +96,10 @@ export async function ensureBoilerplate(node: RouteNode, code: string) {
|
|
|
99
96
|
if (!foundImport) {
|
|
100
97
|
programPath.node.body.unshift(
|
|
101
98
|
babel.template.statement(
|
|
102
|
-
`import {
|
|
99
|
+
`import { route } from '${relativeImportPath.replace(
|
|
100
|
+
/\\/gi,
|
|
101
|
+
'/',
|
|
102
|
+
)}'`,
|
|
103
103
|
)(),
|
|
104
104
|
)
|
|
105
105
|
}
|
|
@@ -111,7 +111,7 @@ export async function ensureBoilerplate(node: RouteNode, code: string) {
|
|
|
111
111
|
],
|
|
112
112
|
})
|
|
113
113
|
|
|
114
|
-
const separator =
|
|
114
|
+
const separator = 'new Route('
|
|
115
115
|
|
|
116
116
|
if (!originalFile?.code) {
|
|
117
117
|
return `${file?.code}\n\n${separator}{\n\n})`
|
|
@@ -157,7 +157,7 @@ export async function isolateOptionToExport(
|
|
|
157
157
|
programPath.traverse({
|
|
158
158
|
Identifier(path) {
|
|
159
159
|
if (
|
|
160
|
-
path.node.name === '
|
|
160
|
+
path.node.name === 'Route' &&
|
|
161
161
|
t.isCallExpression(path.parentPath.node)
|
|
162
162
|
) {
|
|
163
163
|
const options = getCreateRouteConfigOptions(path)
|
|
@@ -177,9 +177,9 @@ export async function isolateOptionToExport(
|
|
|
177
177
|
if (program?.isProgram()) {
|
|
178
178
|
program.node.body.push(
|
|
179
179
|
babel.template.statement(
|
|
180
|
-
`export const ${opts.isolate} = $
|
|
180
|
+
`export const ${opts.isolate} = $VAR`,
|
|
181
181
|
)({
|
|
182
|
-
$
|
|
182
|
+
$VAR: property.value,
|
|
183
183
|
}),
|
|
184
184
|
)
|
|
185
185
|
}
|
|
@@ -221,9 +221,9 @@ export async function isolateOptionToExport(
|
|
|
221
221
|
if (program?.isProgram()) {
|
|
222
222
|
program.node.body.push(
|
|
223
223
|
babel.template.statement(
|
|
224
|
-
`export const ${opts.isolate} = $
|
|
224
|
+
`export const ${opts.isolate} = $VAR`,
|
|
225
225
|
)({
|
|
226
|
-
$
|
|
226
|
+
$VAR: property.value,
|
|
227
227
|
}),
|
|
228
228
|
)
|
|
229
229
|
}
|
|
@@ -322,7 +322,7 @@ export async function generateRouteConfig(
|
|
|
322
322
|
ImportSpecifier(path) {
|
|
323
323
|
if (t.isIdentifier(path.node.imported)) {
|
|
324
324
|
if (!node.isRoot) {
|
|
325
|
-
if (path.node.imported.name === '
|
|
325
|
+
if (path.node.imported.name === 'route') {
|
|
326
326
|
path.parentPath.remove()
|
|
327
327
|
|
|
328
328
|
const program = path.findParent((d) => d.isProgram())
|
|
@@ -330,7 +330,7 @@ export async function generateRouteConfig(
|
|
|
330
330
|
if (program?.isProgram()) {
|
|
331
331
|
program.node.body.unshift(
|
|
332
332
|
babel.template.statement(
|
|
333
|
-
`import {
|
|
333
|
+
`import { route as parentRoute } from '$IMPORT'`,
|
|
334
334
|
)({
|
|
335
335
|
$IMPORT: relativeParentRoutePath,
|
|
336
336
|
}),
|
|
@@ -344,7 +344,7 @@ export async function generateRouteConfig(
|
|
|
344
344
|
let options
|
|
345
345
|
|
|
346
346
|
if (node.isRoot) {
|
|
347
|
-
if (iPath.node.name === '
|
|
347
|
+
if (iPath.node.name === 'Route') {
|
|
348
348
|
if (t.isCallExpression(iPath.parentPath.node)) {
|
|
349
349
|
if (
|
|
350
350
|
t.isExpressionStatement(
|
|
@@ -354,7 +354,7 @@ export async function generateRouteConfig(
|
|
|
354
354
|
iPath.parentPath.parentPath?.replaceWith(
|
|
355
355
|
t.variableDeclaration('const', [
|
|
356
356
|
t.variableDeclarator(
|
|
357
|
-
t.identifier('
|
|
357
|
+
t.identifier('route'),
|
|
358
358
|
iPath.parentPath.node,
|
|
359
359
|
),
|
|
360
360
|
]) as any,
|
|
@@ -366,8 +366,8 @@ export async function generateRouteConfig(
|
|
|
366
366
|
if (iPath.node.name === 'generate') {
|
|
367
367
|
if (t.isMemberExpression(iPath.parentPath.node)) {
|
|
368
368
|
if (t.isIdentifier(iPath.parentPath.node.object)) {
|
|
369
|
-
iPath.node.name = '
|
|
370
|
-
iPath.parentPath.node.object.name = '
|
|
369
|
+
iPath.node.name = 'Route'
|
|
370
|
+
iPath.parentPath.node.object.name = 'parentRoute'
|
|
371
371
|
|
|
372
372
|
options = getRouteConfigGenerateOptions(iPath)
|
|
373
373
|
}
|
|
@@ -484,7 +484,7 @@ export async function generateRouteConfig(
|
|
|
484
484
|
|
|
485
485
|
if (node.isRoot) {
|
|
486
486
|
program.node.body[index] = babel.template.statement(
|
|
487
|
-
`const
|
|
487
|
+
`const route = new Route(
|
|
488
488
|
$OPTIONS
|
|
489
489
|
)`,
|
|
490
490
|
)({
|
|
@@ -492,7 +492,7 @@ export async function generateRouteConfig(
|
|
|
492
492
|
})
|
|
493
493
|
} else {
|
|
494
494
|
program.node.body[index] = babel.template.statement(
|
|
495
|
-
`const
|
|
495
|
+
`const route = new Route(
|
|
496
496
|
$OPTIONS
|
|
497
497
|
)`,
|
|
498
498
|
)({
|
|
@@ -510,17 +510,17 @@ export async function generateRouteConfig(
|
|
|
510
510
|
)(),
|
|
511
511
|
)
|
|
512
512
|
|
|
513
|
-
// Add the
|
|
513
|
+
// Add the route exports
|
|
514
514
|
programPath.node.body.push(
|
|
515
515
|
babel.template.statement(
|
|
516
516
|
clientOnly
|
|
517
|
-
? `export {
|
|
518
|
-
: `export {
|
|
517
|
+
? `export { route, route as ${node.variable}Route }`
|
|
518
|
+
: `export { route }`,
|
|
519
519
|
)(),
|
|
520
520
|
)
|
|
521
521
|
|
|
522
522
|
cleanUnusedCode(programPath, state, [
|
|
523
|
-
'
|
|
523
|
+
'route',
|
|
524
524
|
`${node.variable}Route`,
|
|
525
525
|
])
|
|
526
526
|
},
|