Skip to content

Commit 3614ac8

Browse files
fix: generator fixes (#4362)
1 parent 41af409 commit 3614ac8

File tree

16 files changed

+52
-69
lines changed

16 files changed

+52
-69
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@ jobs:
2626
name: Test & Publish
2727
if: github.repository_owner == 'TanStack'
2828
runs-on: ubuntu-latest
29-
env:
30-
TSR_TMP_DIR: ./tmp
3129
steps:
3230
- name: Checkout
3331
uses: actions/[email protected]
3432
with:
3533
fetch-depth: 0
3634
- name: Start Nx Agents
37-
run: npx nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yaml" --with-env-vars="TSR_TMP_DIR"
35+
run: npx nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yaml"
3836
- name: Setup Tools
3937
uses: tanstack/config/.github/setup@main
4038
- name: Run Tests

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
with:
2727
fetch-depth: 0
2828
- name: Start Nx Agents
29-
run: npx nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yaml" --with-env-vars="TSR_TMP_DIR"
29+
run: npx nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yaml"
3030
- name: Setup Tools
3131
uses: tanstack/config/.github/setup@main
3232
- name: Get base and head commits for `nx affected`

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ vite.config.ts.timestamp_*
7474
# Handling VSCode settings
7575
/.vscode/
7676
!/examples/react/**/.vscode/settings.json
77-
**/.tanstack-start/build
7877

7978
**/llms
79+
80+
**/.tanstack

docs/router/api/file-based-routing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,4 @@ Atomic file writes (route files and the generated route tree file) are implement
200200
This config option allows to configure the path of the temp directory that will be used for creating those temporary files.
201201
If it is a relative path, it will be resolved to the current working directory.
202202
If this value is not set, `process.env.TSR_TMP_DIR` will be used.
203-
If `process.env.TSR_TMP_DIR` is not set, it will default to `os.tmpdir()`.
203+
If `process.env.TSR_TMP_DIR` is not set, it will default to `.tanstack/tmp` relative to the current working directory.

e2e/react-start/website/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ yarn.lock
1717
/blob-report/
1818
/playwright/.cache/
1919

20-
.tanstack-start/build
20+
.tanstack

examples/react/start-basic/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ yarn.lock
1717
/playwright-report/
1818
/blob-report/
1919
/playwright/.cache/
20-
.tanstack-start/build
20+
.tanstack

examples/react/start-tailwind-v4/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ yarn.lock
1717
/playwright-report/
1818
/blob-report/
1919
/playwright/.cache/
20-
.tanstack-start/build
20+
.tanstack

packages/router-generator/src/config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import path from 'node:path'
2-
import { tmpdir } from 'node:os'
32
import { existsSync, mkdirSync, readFileSync } from 'node:fs'
43
import { z } from 'zod'
54
import { virtualRootRouteSchema } from './filesystem/virtual/config'
@@ -121,7 +120,10 @@ export function getConfig(
121120
}
122121
}
123122

124-
const resolveTmpDir = (dir: string) => {
123+
const resolveTmpDir = (dir: string | Array<string>) => {
124+
if (Array.isArray(dir)) {
125+
dir = path.join(...dir)
126+
}
125127
if (!path.isAbsolute(dir)) {
126128
dir = path.resolve(process.cwd(), dir)
127129
}
@@ -134,7 +136,7 @@ export function getConfig(
134136
} else if (process.env.TSR_TMP_DIR) {
135137
config.tmpDir = resolveTmpDir(process.env.TSR_TMP_DIR)
136138
} else {
137-
config.tmpDir = tmpdir()
139+
config.tmpDir = resolveTmpDir(['.tanstack', 'tmp'])
138140
}
139141

140142
validateConfig(config)

packages/router-generator/src/generator.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export class Generator {
178178
this.root = opts.root
179179
this.fs = opts.fs || DefaultFileSystem
180180
this.tmpDir = this.fs.mkdtempSync(
181-
path.join(this.config.tmpDir, 'tanstack-router-'),
181+
path.join(this.config.tmpDir, 'router-generator-'),
182182
)
183183
this.generatedRouteTreePath = path.resolve(this.config.generatedRouteTree)
184184
this.targetTemplate = getTargetTemplate(this.config)
@@ -1050,7 +1050,9 @@ ${acc.routeTree.map((child) => `${child.variableName}${exportName}: typeof ${get
10501050
const result = await this.isRouteFileCacheFresh(node)
10511051

10521052
if (result.status === 'fresh') {
1053-
return false
1053+
node.exports = result.cacheEntry.exports
1054+
this.routeNodeShadowCache.set(node.fullPath, result.cacheEntry)
1055+
return result.exportsChanged
10541056
}
10551057
const rootNodeFile = await this.fs.readFile(node.fullPath)
10561058
if (rootNodeFile === 'file-not-existing') {

packages/router-generator/src/transform/transform.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ async function fixTransformedOutputText({
290290
originalCode: string
291291
transformedCode: string
292292
sourceMap: RawSourceMap
293-
preferredQuote: '"' | "'" | '`'
293+
preferredQuote: '"' | "'"
294294
}) {
295295
const originalLines = originalCode.split('\n')
296296
const transformedLines = transformedCode.split('\n')
@@ -302,11 +302,10 @@ async function fixTransformedOutputText({
302302
const fixedLines = transformedLines.map((line, i) => {
303303
const transformedLineNum = i + 1
304304

305-
let mapped = null
306-
let origLineText = null
305+
let origLineText: string | undefined = undefined
307306

308307
for (let col = 0; col < line.length; col++) {
309-
mapped = consumer.originalPositionFor({
308+
const mapped = consumer.originalPositionFor({
310309
line: transformedLineNum,
311310
column: col,
312311
})
@@ -316,7 +315,7 @@ async function fixTransformedOutputText({
316315
}
317316
}
318317

319-
if (origLineText != null) {
318+
if (origLineText !== undefined) {
320319
if (origLineText === line) {
321320
return origLineText
322321
}
@@ -409,10 +408,9 @@ function detectSemicolonUsage(code: string) {
409408
return withSemis > total / 2
410409
}
411410

412-
export function detectPreferredQuoteStyle(ast: types.ASTNode): "'" | '"' | '`' {
411+
export function detectPreferredQuoteStyle(ast: types.ASTNode): "'" | '"' {
413412
let single = 0
414413
let double = 0
415-
let backtick = 0
416414

417415
visit(ast, {
418416
visitStringLiteral(path) {
@@ -423,17 +421,10 @@ export function detectPreferredQuoteStyle(ast: types.ASTNode): "'" | '"' | '`' {
423421
}
424422
return false
425423
},
426-
visitTemplateLiteral(path) {
427-
if (path.parent.type !== 'JSXAttribute') {
428-
backtick++
429-
}
430-
return false
431-
},
432424
})
433425

434-
return single >= double && single >= backtick
435-
? "'"
436-
: double >= single && double >= backtick
437-
? '"'
438-
: '`'
426+
if (single >= double) {
427+
return "'"
428+
}
429+
return '"'
439430
}

0 commit comments

Comments
 (0)