@@ -200,7 +200,7 @@ function editFileJson(filepath: string, edit: (s: string) => string) {
200200export async function setupInlineFixture ( options : {
201201 src : string
202202 dest : string
203- files ?: Record < string , string >
203+ files ?: Record < string , string | { cp : string } >
204204} ) {
205205 fs . rmSync ( options . dest , { recursive : true , force : true } )
206206 fs . mkdirSync ( options . dest , { recursive : true } )
@@ -214,20 +214,17 @@ export async function setupInlineFixture(options: {
214214 // write additional files
215215 if ( options . files ) {
216216 for ( let [ filename , contents ] of Object . entries ( options . files ) ) {
217- // custom fs command
218- if ( contents . startsWith ( 'fs:cp:' ) ) {
219- const src = contents . slice ( 'fs:cp:' . length )
220- const srcPath = path . resolve ( options . src , src )
221- if ( ! fs . existsSync ( srcPath ) ) {
222- throw new Error ( `Source file does not exist: ${ srcPath } ` )
223- }
224- fs . cpSync ( srcPath , path . join ( options . dest , filename ) , {
225- recursive : true ,
226- } )
217+ // custom command
218+ if ( typeof contents === 'object' && 'cp' in contents ) {
219+ const srcFile = path . join ( options . dest , contents . cp )
220+ const destFile = path . join ( options . dest , filename )
221+ fs . mkdirSync ( path . dirname ( srcFile ) , { recursive : true } )
222+ fs . mkdirSync ( path . dirname ( destFile ) , { recursive : true } )
223+ fs . cpSync ( srcFile , destFile , { recursive : true } )
227224 continue
228225 }
229- // write new file
230- let filepath = path . join ( options . dest , filename )
226+ // write a file
227+ const filepath = path . join ( options . dest , filename )
231228 fs . mkdirSync ( path . dirname ( filepath ) , { recursive : true } )
232229 // strip indent
233230 contents = contents . replace ( / ^ \n * / , '' ) . replace ( / \s * $ / , '\n' )
0 commit comments