@tanstack/router-cli 0.0.1-beta.58 → 0.0.1-beta.69
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 +24 -25
- package/build/cjs/transformCode.js.map +1 -1
- package/build/esm/index.js +32 -33
- package/build/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/generator.ts +9 -9
- package/src/transformCode.ts +24 -27
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,7 @@ 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(
|
|
103
100
|
/\\/gi,
|
|
104
101
|
'/',
|
|
105
102
|
)}'`,
|
|
@@ -114,7 +111,7 @@ export async function ensureBoilerplate(node: RouteNode, code: string) {
|
|
|
114
111
|
],
|
|
115
112
|
})
|
|
116
113
|
|
|
117
|
-
const separator =
|
|
114
|
+
const separator = 'new Route('
|
|
118
115
|
|
|
119
116
|
if (!originalFile?.code) {
|
|
120
117
|
return `${file?.code}\n\n${separator}{\n\n})`
|
|
@@ -160,10 +157,10 @@ export async function isolateOptionToExport(
|
|
|
160
157
|
programPath.traverse({
|
|
161
158
|
Identifier(path) {
|
|
162
159
|
if (
|
|
163
|
-
path.node.name === '
|
|
160
|
+
path.node.name === 'Route' &&
|
|
164
161
|
t.isCallExpression(path.parentPath.node)
|
|
165
162
|
) {
|
|
166
|
-
const options =
|
|
163
|
+
const options = getRouteOptions(path)
|
|
167
164
|
|
|
168
165
|
if (options) {
|
|
169
166
|
const property = options.properties.find((property) => {
|
|
@@ -180,9 +177,9 @@ export async function isolateOptionToExport(
|
|
|
180
177
|
if (program?.isProgram()) {
|
|
181
178
|
program.node.body.push(
|
|
182
179
|
babel.template.statement(
|
|
183
|
-
`export const ${opts.isolate} = $
|
|
180
|
+
`export const ${opts.isolate} = $VAR`,
|
|
184
181
|
)({
|
|
185
|
-
$
|
|
182
|
+
$VAR: property.value,
|
|
186
183
|
}),
|
|
187
184
|
)
|
|
188
185
|
}
|
|
@@ -224,9 +221,9 @@ export async function isolateOptionToExport(
|
|
|
224
221
|
if (program?.isProgram()) {
|
|
225
222
|
program.node.body.push(
|
|
226
223
|
babel.template.statement(
|
|
227
|
-
`export const ${opts.isolate} = $
|
|
224
|
+
`export const ${opts.isolate} = $VAR`,
|
|
228
225
|
)({
|
|
229
|
-
$
|
|
226
|
+
$VAR: property.value,
|
|
230
227
|
}),
|
|
231
228
|
)
|
|
232
229
|
}
|
|
@@ -325,7 +322,7 @@ export async function generateRouteConfig(
|
|
|
325
322
|
ImportSpecifier(path) {
|
|
326
323
|
if (t.isIdentifier(path.node.imported)) {
|
|
327
324
|
if (!node.isRoot) {
|
|
328
|
-
if (path.node.imported.name ===
|
|
325
|
+
if (path.node.imported.name === 'route') {
|
|
329
326
|
path.parentPath.remove()
|
|
330
327
|
|
|
331
328
|
const program = path.findParent((d) => d.isProgram())
|
|
@@ -333,7 +330,7 @@ export async function generateRouteConfig(
|
|
|
333
330
|
if (program?.isProgram()) {
|
|
334
331
|
program.node.body.unshift(
|
|
335
332
|
babel.template.statement(
|
|
336
|
-
`import {
|
|
333
|
+
`import { route as parentRoute } from '$IMPORT'`,
|
|
337
334
|
)({
|
|
338
335
|
$IMPORT: relativeParentRoutePath,
|
|
339
336
|
}),
|
|
@@ -347,7 +344,7 @@ export async function generateRouteConfig(
|
|
|
347
344
|
let options
|
|
348
345
|
|
|
349
346
|
if (node.isRoot) {
|
|
350
|
-
if (iPath.node.name === '
|
|
347
|
+
if (iPath.node.name === 'Route') {
|
|
351
348
|
if (t.isCallExpression(iPath.parentPath.node)) {
|
|
352
349
|
if (
|
|
353
350
|
t.isExpressionStatement(
|
|
@@ -357,7 +354,7 @@ export async function generateRouteConfig(
|
|
|
357
354
|
iPath.parentPath.parentPath?.replaceWith(
|
|
358
355
|
t.variableDeclaration('const', [
|
|
359
356
|
t.variableDeclarator(
|
|
360
|
-
t.identifier(
|
|
357
|
+
t.identifier('route'),
|
|
361
358
|
iPath.parentPath.node,
|
|
362
359
|
),
|
|
363
360
|
]) as any,
|
|
@@ -369,8 +366,8 @@ export async function generateRouteConfig(
|
|
|
369
366
|
if (iPath.node.name === 'generate') {
|
|
370
367
|
if (t.isMemberExpression(iPath.parentPath.node)) {
|
|
371
368
|
if (t.isIdentifier(iPath.parentPath.node.object)) {
|
|
372
|
-
iPath.node.name = '
|
|
373
|
-
iPath.parentPath.node.object.name = '
|
|
369
|
+
iPath.node.name = 'Route'
|
|
370
|
+
iPath.parentPath.node.object.name = 'parentRoute'
|
|
374
371
|
|
|
375
372
|
options = getRouteConfigGenerateOptions(iPath)
|
|
376
373
|
}
|
|
@@ -487,7 +484,7 @@ export async function generateRouteConfig(
|
|
|
487
484
|
|
|
488
485
|
if (node.isRoot) {
|
|
489
486
|
program.node.body[index] = babel.template.statement(
|
|
490
|
-
`const
|
|
487
|
+
`const route = new Route(
|
|
491
488
|
$OPTIONS
|
|
492
489
|
)`,
|
|
493
490
|
)({
|
|
@@ -495,7 +492,7 @@ export async function generateRouteConfig(
|
|
|
495
492
|
})
|
|
496
493
|
} else {
|
|
497
494
|
program.node.body[index] = babel.template.statement(
|
|
498
|
-
`const
|
|
495
|
+
`const route = new Route(
|
|
499
496
|
$OPTIONS
|
|
500
497
|
)`,
|
|
501
498
|
)({
|
|
@@ -513,17 +510,17 @@ export async function generateRouteConfig(
|
|
|
513
510
|
)(),
|
|
514
511
|
)
|
|
515
512
|
|
|
516
|
-
// Add the
|
|
513
|
+
// Add the route exports
|
|
517
514
|
programPath.node.body.push(
|
|
518
515
|
babel.template.statement(
|
|
519
516
|
clientOnly
|
|
520
|
-
? `export {
|
|
521
|
-
: `export {
|
|
517
|
+
? `export { route, route as ${node.variable}Route }`
|
|
518
|
+
: `export { route }`,
|
|
522
519
|
)(),
|
|
523
520
|
)
|
|
524
521
|
|
|
525
522
|
cleanUnusedCode(programPath, state, [
|
|
526
|
-
|
|
523
|
+
'route',
|
|
527
524
|
`${node.variable}Route`,
|
|
528
525
|
])
|
|
529
526
|
},
|
|
@@ -617,7 +614,7 @@ function getRouteConfigGenerateOptions(path: any): t.ObjectExpression | void {
|
|
|
617
614
|
}
|
|
618
615
|
}
|
|
619
616
|
|
|
620
|
-
function
|
|
617
|
+
function getRouteOptions(path: any): t.ObjectExpression | void {
|
|
621
618
|
const tryOptions = (node: any): t.ObjectExpression | void => {
|
|
622
619
|
if (t.isIdentifier(node)) {
|
|
623
620
|
const initNode = path.scope.getBinding(node.name)?.path.node
|