@@ -343,6 +343,67 @@ class SafeFileSystem implements SafeFsInterface {
343343 await nodeFs . copyFile ( src , dest ) ;
344344 }
345345
346+
347+ async mkdtemp ( prefix : string ) : Promise < string > {
348+ await this . ensureInitialized ( ) ;
349+
350+ if ( ! this . fallbackMode && this . fsExtra ?. mkdtemp ) {
351+ try {
352+ return await this . fsExtra . mkdtemp ( prefix ) ;
353+ } catch ( error ) {
354+ console . warn ( `fs-extra.mkdtemp failed, using Node.js fallback: ${ ( error as Error ) . message } ` ) ;
355+ }
356+ }
357+
358+ // Node.js built-in fallback
359+ return await nodeFs . mkdtemp ( prefix ) ;
360+ }
361+
362+ async mkdir ( dirPath : string , options ?: any ) : Promise < void > {
363+ await this . ensureInitialized ( ) ;
364+
365+ if ( ! this . fallbackMode && this . fsExtra ?. mkdir ) {
366+ try {
367+ return await this . fsExtra . mkdir ( dirPath , options ) ;
368+ } catch ( error ) {
369+ console . warn ( `fs-extra.mkdir failed, using Node.js fallback: ${ ( error as Error ) . message } ` ) ;
370+ }
371+ }
372+
373+ // Node.js built-in fallback
374+ await nodeFs . mkdir ( dirPath , { recursive : true , ...options } ) ;
375+ }
376+
377+ async chmod ( filePath : string , mode : string | number ) : Promise < void > {
378+ await this . ensureInitialized ( ) ;
379+
380+ if ( ! this . fallbackMode && this . fsExtra ?. chmod ) {
381+ try {
382+ return await this . fsExtra . chmod ( filePath , mode ) ;
383+ } catch ( error ) {
384+ console . warn ( `fs-extra.chmod failed, using Node.js fallback: ${ ( error as Error ) . message } ` ) ;
385+ }
386+ }
387+
388+ // Node.js built-in fallback
389+ await nodeFs . chmod ( filePath , mode ) ;
390+ }
391+
392+ async utimes ( filePath : string , atime : Date | number , mtime : Date | number ) : Promise < void > {
393+ await this . ensureInitialized ( ) ;
394+
395+ if ( ! this . fallbackMode && this . fsExtra ?. utimes ) {
396+ try {
397+ return await this . fsExtra . utimes ( filePath , atime , mtime ) ;
398+ } catch ( error ) {
399+ console . warn ( `fs-extra.utimes failed, using Node.js fallback: ${ ( error as Error ) . message } ` ) ;
400+ }
401+ }
402+
403+ // Node.js built-in fallback
404+ await nodeFs . utimes ( filePath , atime , mtime ) ;
405+ }
406+
346407 /**
347408 * Get diagnostic information about fs-extra availability
348409 */
@@ -383,6 +444,21 @@ export const ensureDir = (dirPath: string) => safeFs.ensureDir(dirPath);
383444export const appendFile = ( filePath : string , data : string ) => safeFs . appendFile ( filePath , data ) ;
384445export const move = ( src : string , dest : string , options ?: any ) => safeFs . move ( src , dest , options ) ;
385446export const copy = ( src : string , dest : string , options ?: any ) => safeFs . copy ( src , dest , options ) ;
447+ // JSON utility functions - always use Node.js built-in JSON methods
448+ export const readJSON = async ( filePath : string ) : Promise < any > => {
449+ const content = await readFile ( filePath , 'utf8' ) ;
450+ return JSON . parse ( content ) ;
451+ } ;
452+ export const readJson = readJSON ; // Alias
453+ export const writeJSON = async ( filePath : string , data : any ) : Promise < void > => {
454+ const jsonStr = JSON . stringify ( data , null , 2 ) ;
455+ await writeFile ( filePath , jsonStr ) ;
456+ } ;
457+ export const writeJson = writeJSON ; // Alias
458+ export const mkdtemp = ( prefix : string ) => safeFs . mkdtemp ( prefix ) ;
459+ export const mkdir = ( dirPath : string , options ?: any ) => safeFs . mkdir ( dirPath , options ) ;
460+ export const chmod = ( filePath : string , mode : string | number ) => safeFs . chmod ( filePath , mode ) ;
461+ export const utimes = ( filePath : string , atime : Date | number , mtime : Date | number ) => safeFs . utimes ( filePath , atime , mtime ) ;
386462
387463// Synchronous version for backwards compatibility (used in server initialization)
388464export const ensureDirSync = ( dirPath : string ) => {
0 commit comments