From b798dc3d2fdf6095810c3440e9350089b3cfa445 Mon Sep 17 00:00:00 2001 From: Sheraff Date: Mon, 9 Nov 2026 13:47:44 +0100 Subject: [PATCH] fix(router-generator): create the temporary directory again when it was deleted under a session Co-Authored-By: Claude Opus 5.5 --- .../router-generator/src/publish/atomic.ts | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/packages/router-generator/src/publish/atomic.ts b/packages/router-generator/src/publish/atomic.ts index 73b9d5fdca..8b889e25df 100644 --- a/packages/router-generator/src/publish/atomic.ts +++ b/packages/router-generator/src/publish/atomic.ts @@ -95,12 +95,7 @@ export class AtomicPublisher { this.tmpDirReady ??= fsp.mkdir(this.tmpDir, { recursive: true }) await this.tmpDirReady try { - await this.writeVia( - path.join(this.tmpDir, `${this.session}-${this.writes++}`), - file, - content, - expected, - ) + await this.writeViaTmpDir(file, content, expected) } catch (error) { if (!isErrorCode(error, 'EXDEV')) { throw error @@ -110,6 +105,30 @@ export class AtomicPublisher { } } + /** + * Through a temporary file in `tmpDir`. The directory can be deleted under + * a running session (`git stash -u` or `git clean -fd` where `.tanstack/` is + * not ignored, `rm -rf .tanstack`): on ENOENT, the directory is created + * again and the write tried once more. + */ + private async writeViaTmpDir( + file: string, + content: string, + expected: string | null | undefined, + ) { + const temporary = () => + path.join(this.tmpDir, `${this.session}-${this.writes++}`) + try { + await this.writeVia(temporary(), file, content, expected) + } catch (error) { + if (!isErrorCode(error, 'ENOENT')) { + throw error + } + await fsp.mkdir(this.tmpDir, { recursive: true }) + await this.writeVia(temporary(), file, content, expected) + } + } + private besideName(file: string) { return path.join( path.dirname(file),