11import type { PtySession } from './lib/pty.ts'
2- import { readFileSync , rmSync , symlinkSync , writeFileSync } from 'node:fs'
2+ import { lstatSync , readFileSync , renameSync , rmSync , symlinkSync , writeFileSync } from 'node:fs'
33import { dirname , join } from 'node:path'
44import process from 'node:process'
55import { fileURLToPath } from 'node:url'
@@ -140,9 +140,22 @@ export const captures: Capture[] = [
140140
141141 // `installNuxtModule` runs the *project's* `@nuxt/cli` in-process, which
142142 // the fixture installed from the registry; the capture should show the
143- // build under test, so the project copy is pointed at it.
143+ // build under test, so the project copy is pointed at it for the
144+ // recording and put back afterwards. A symlink found here is residue of
145+ // an interrupted run, with nothing behind it to preserve.
144146 const projectCli = join ( cwd , 'node_modules/@nuxt/cli' )
145- rmSync ( projectCli , { recursive : true , force : true } )
147+ const savedCli = `${ projectCli } .original`
148+ if ( lstatSync ( savedCli , { throwIfNoEntry : false } ) ) {
149+ rmSync ( projectCli , { recursive : true , force : true } )
150+ renameSync ( savedCli , projectCli )
151+ }
152+ const installed = lstatSync ( projectCli , { throwIfNoEntry : false } )
153+ if ( installed ?. isSymbolicLink ( ) ) {
154+ rmSync ( projectCli , { force : true } )
155+ }
156+ else if ( installed ) {
157+ renameSync ( projectCli , savedCli )
158+ }
146159 symlinkSync ( dirname ( dirname ( bin ) ) , projectCli , 'dir' )
147160
148161 try {
@@ -168,6 +181,10 @@ export const captures: Capture[] = [
168181 writeFileSync ( file , text )
169182 }
170183 rmSync ( join ( cwd , 'node_modules/@nuxt/scripts' ) , { recursive : true , force : true } )
184+ rmSync ( projectCli , { force : true } )
185+ if ( lstatSync ( savedCli , { throwIfNoEntry : false } ) ) {
186+ renameSync ( savedCli , projectCli )
187+ }
171188 }
172189 } ,
173190 } ,
0 commit comments