@tanstack/router-generator 1.121.0-alpha.26 → 1.121.0-alpha.27
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/config.cjs +4 -2
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/generator.cjs +4 -2
- package/dist/cjs/generator.cjs.map +1 -1
- package/dist/cjs/transform/transform.cjs +7 -12
- package/dist/cjs/transform/transform.cjs.map +1 -1
- package/dist/cjs/transform/transform.d.cts +1 -1
- package/dist/cjs/transform/types.d.cts +1 -1
- package/dist/cjs/transform/utils.cjs.map +1 -1
- package/dist/cjs/transform/utils.d.cts +1 -1
- package/dist/esm/config.js +4 -2
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/generator.js +4 -2
- package/dist/esm/generator.js.map +1 -1
- package/dist/esm/transform/transform.d.ts +1 -1
- package/dist/esm/transform/transform.js +7 -12
- package/dist/esm/transform/transform.js.map +1 -1
- package/dist/esm/transform/types.d.ts +1 -1
- package/dist/esm/transform/utils.d.ts +1 -1
- package/dist/esm/transform/utils.js.map +1 -1
- package/package.json +4 -4
- package/src/config.ts +5 -3
- package/src/generator.ts +4 -2
- package/src/transform/transform.ts +9 -18
- package/src/transform/types.ts +1 -1
- package/src/transform/utils.ts +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { types } from 'recast';
|
|
2
|
-
export declare function ensureStringArgument(callExpression: types.namedTypes.CallExpression, value: string, preferredQuote?: "'" | '"'
|
|
2
|
+
export declare function ensureStringArgument(callExpression: types.namedTypes.CallExpression, value: string, preferredQuote?: "'" | '"'): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/transform/utils.ts"],"sourcesContent":["import { types } from 'recast'\n\nconst b = types.builders\n\nexport function ensureStringArgument(\n callExpression: types.namedTypes.CallExpression,\n value: string,\n preferredQuote?: \"'\" | '\"'
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/transform/utils.ts"],"sourcesContent":["import { types } from 'recast'\n\nconst b = types.builders\n\nexport function ensureStringArgument(\n callExpression: types.namedTypes.CallExpression,\n value: string,\n preferredQuote?: \"'\" | '\"',\n) {\n const argument = callExpression.arguments[0]\n if (!argument) {\n let stringLiteral: types.namedTypes.StringLiteral\n if (!preferredQuote) {\n stringLiteral = b.stringLiteral.from({ value })\n } else {\n stringLiteral = b.stringLiteral.from({\n value,\n extra: {\n rawValue: value,\n raw: `${preferredQuote}${value}${preferredQuote}`,\n },\n })\n }\n callExpression.arguments.push(stringLiteral)\n return true\n } else if (argument.type === 'StringLiteral') {\n if (argument.value !== value) {\n argument.value = value\n return true\n }\n } else if (argument.type === 'TemplateLiteral') {\n if (\n argument.quasis.length === 1 &&\n argument.quasis[0] &&\n argument.quasis[0].value.raw !== value\n ) {\n argument.quasis[0].value.raw = value\n return true\n }\n }\n return false\n}\n"],"names":[],"mappings":";AAEA,MAAM,IAAI,MAAM;AAEA,SAAA,qBACd,gBACA,OACA,gBACA;AACM,QAAA,WAAW,eAAe,UAAU,CAAC;AAC3C,MAAI,CAAC,UAAU;AACT,QAAA;AACJ,QAAI,CAAC,gBAAgB;AACnB,sBAAgB,EAAE,cAAc,KAAK,EAAE,OAAO;AAAA,IAAA,OACzC;AACW,sBAAA,EAAE,cAAc,KAAK;AAAA,QACnC;AAAA,QACA,OAAO;AAAA,UACL,UAAU;AAAA,UACV,KAAK,GAAG,cAAc,GAAG,KAAK,GAAG,cAAc;AAAA,QAAA;AAAA,MACjD,CACD;AAAA,IAAA;AAEY,mBAAA,UAAU,KAAK,aAAa;AACpC,WAAA;AAAA,EAAA,WACE,SAAS,SAAS,iBAAiB;AACxC,QAAA,SAAS,UAAU,OAAO;AAC5B,eAAS,QAAQ;AACV,aAAA;AAAA,IAAA;AAAA,EACT,WACS,SAAS,SAAS,mBAAmB;AAC9C,QACE,SAAS,OAAO,WAAW,KAC3B,SAAS,OAAO,CAAC,KACjB,SAAS,OAAO,CAAC,EAAE,MAAM,QAAQ,OACjC;AACA,eAAS,OAAO,CAAC,EAAE,MAAM,MAAM;AACxB,aAAA;AAAA,IAAA;AAAA,EACT;AAEK,SAAA;AACT;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/router-generator",
|
|
3
|
-
"version": "1.121.0-alpha.
|
|
3
|
+
"version": "1.121.0-alpha.27",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,12 +54,12 @@
|
|
|
54
54
|
"source-map": "^0.7.4",
|
|
55
55
|
"tsx": "^4.19.2",
|
|
56
56
|
"zod": "^3.24.2",
|
|
57
|
-
"@tanstack/router-core": "^1.121.0-alpha.22",
|
|
58
57
|
"@tanstack/router-utils": "^1.121.0-alpha.26",
|
|
59
|
-
"@tanstack/virtual-file-routes": "^1.121.0-alpha.1"
|
|
58
|
+
"@tanstack/virtual-file-routes": "^1.121.0-alpha.1",
|
|
59
|
+
"@tanstack/router-core": "^1.121.0-alpha.27"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@tanstack/react-router": "^1.121.0-alpha.
|
|
62
|
+
"@tanstack/react-router": "^1.121.0-alpha.27"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {}
|
|
65
65
|
}
|
package/src/config.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import { tmpdir } from 'node:os'
|
|
3
2
|
import { existsSync, mkdirSync, readFileSync } from 'node:fs'
|
|
4
3
|
import { z } from 'zod'
|
|
5
4
|
import { virtualRootRouteSchema } from './filesystem/virtual/config'
|
|
@@ -121,7 +120,10 @@ export function getConfig(
|
|
|
121
120
|
}
|
|
122
121
|
}
|
|
123
122
|
|
|
124
|
-
const resolveTmpDir = (dir: string) => {
|
|
123
|
+
const resolveTmpDir = (dir: string | Array<string>) => {
|
|
124
|
+
if (Array.isArray(dir)) {
|
|
125
|
+
dir = path.join(...dir)
|
|
126
|
+
}
|
|
125
127
|
if (!path.isAbsolute(dir)) {
|
|
126
128
|
dir = path.resolve(process.cwd(), dir)
|
|
127
129
|
}
|
|
@@ -134,7 +136,7 @@ export function getConfig(
|
|
|
134
136
|
} else if (process.env.TSR_TMP_DIR) {
|
|
135
137
|
config.tmpDir = resolveTmpDir(process.env.TSR_TMP_DIR)
|
|
136
138
|
} else {
|
|
137
|
-
config.tmpDir =
|
|
139
|
+
config.tmpDir = resolveTmpDir(['.tanstack', 'tmp'])
|
|
138
140
|
}
|
|
139
141
|
|
|
140
142
|
validateConfig(config)
|
package/src/generator.ts
CHANGED
|
@@ -178,7 +178,7 @@ export class Generator {
|
|
|
178
178
|
this.root = opts.root
|
|
179
179
|
this.fs = opts.fs || DefaultFileSystem
|
|
180
180
|
this.tmpDir = this.fs.mkdtempSync(
|
|
181
|
-
path.join(this.config.tmpDir, '
|
|
181
|
+
path.join(this.config.tmpDir, 'router-generator-'),
|
|
182
182
|
)
|
|
183
183
|
this.generatedRouteTreePath = path.resolve(this.config.generatedRouteTree)
|
|
184
184
|
this.targetTemplate = getTargetTemplate(this.config)
|
|
@@ -1050,7 +1050,9 @@ ${acc.routeTree.map((child) => `${child.variableName}${exportName}: typeof ${get
|
|
|
1050
1050
|
const result = await this.isRouteFileCacheFresh(node)
|
|
1051
1051
|
|
|
1052
1052
|
if (result.status === 'fresh') {
|
|
1053
|
-
|
|
1053
|
+
node.exports = result.cacheEntry.exports
|
|
1054
|
+
this.routeNodeShadowCache.set(node.fullPath, result.cacheEntry)
|
|
1055
|
+
return result.exportsChanged
|
|
1054
1056
|
}
|
|
1055
1057
|
const rootNodeFile = await this.fs.readFile(node.fullPath)
|
|
1056
1058
|
if (rootNodeFile === 'file-not-existing') {
|
|
@@ -290,7 +290,7 @@ async function fixTransformedOutputText({
|
|
|
290
290
|
originalCode: string
|
|
291
291
|
transformedCode: string
|
|
292
292
|
sourceMap: RawSourceMap
|
|
293
|
-
preferredQuote: '"' | "'"
|
|
293
|
+
preferredQuote: '"' | "'"
|
|
294
294
|
}) {
|
|
295
295
|
const originalLines = originalCode.split('\n')
|
|
296
296
|
const transformedLines = transformedCode.split('\n')
|
|
@@ -302,11 +302,10 @@ async function fixTransformedOutputText({
|
|
|
302
302
|
const fixedLines = transformedLines.map((line, i) => {
|
|
303
303
|
const transformedLineNum = i + 1
|
|
304
304
|
|
|
305
|
-
let
|
|
306
|
-
let origLineText = null
|
|
305
|
+
let origLineText: string | undefined = undefined
|
|
307
306
|
|
|
308
307
|
for (let col = 0; col < line.length; col++) {
|
|
309
|
-
mapped = consumer.originalPositionFor({
|
|
308
|
+
const mapped = consumer.originalPositionFor({
|
|
310
309
|
line: transformedLineNum,
|
|
311
310
|
column: col,
|
|
312
311
|
})
|
|
@@ -316,7 +315,7 @@ async function fixTransformedOutputText({
|
|
|
316
315
|
}
|
|
317
316
|
}
|
|
318
317
|
|
|
319
|
-
if (origLineText
|
|
318
|
+
if (origLineText !== undefined) {
|
|
320
319
|
if (origLineText === line) {
|
|
321
320
|
return origLineText
|
|
322
321
|
}
|
|
@@ -409,10 +408,9 @@ function detectSemicolonUsage(code: string) {
|
|
|
409
408
|
return withSemis > total / 2
|
|
410
409
|
}
|
|
411
410
|
|
|
412
|
-
export function detectPreferredQuoteStyle(ast: types.ASTNode): "'" | '"'
|
|
411
|
+
export function detectPreferredQuoteStyle(ast: types.ASTNode): "'" | '"' {
|
|
413
412
|
let single = 0
|
|
414
413
|
let double = 0
|
|
415
|
-
let backtick = 0
|
|
416
414
|
|
|
417
415
|
visit(ast, {
|
|
418
416
|
visitStringLiteral(path) {
|
|
@@ -423,17 +421,10 @@ export function detectPreferredQuoteStyle(ast: types.ASTNode): "'" | '"' | '`' {
|
|
|
423
421
|
}
|
|
424
422
|
return false
|
|
425
423
|
},
|
|
426
|
-
visitTemplateLiteral(path) {
|
|
427
|
-
if (path.parent.type !== 'JSXAttribute') {
|
|
428
|
-
backtick++
|
|
429
|
-
}
|
|
430
|
-
return false
|
|
431
|
-
},
|
|
432
424
|
})
|
|
433
425
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
: '`'
|
|
426
|
+
if (single >= double) {
|
|
427
|
+
return "'"
|
|
428
|
+
}
|
|
429
|
+
return '"'
|
|
439
430
|
}
|
package/src/transform/types.ts
CHANGED
package/src/transform/utils.ts
CHANGED
|
@@ -5,7 +5,7 @@ const b = types.builders
|
|
|
5
5
|
export function ensureStringArgument(
|
|
6
6
|
callExpression: types.namedTypes.CallExpression,
|
|
7
7
|
value: string,
|
|
8
|
-
preferredQuote?: "'" | '"'
|
|
8
|
+
preferredQuote?: "'" | '"',
|
|
9
9
|
) {
|
|
10
10
|
const argument = callExpression.arguments[0]
|
|
11
11
|
if (!argument) {
|