File tree Expand file tree Collapse file tree 2 files changed +23
-20
lines changed
php-wasm/universal/src/lib
playground/blueprints/src/lib Expand file tree Collapse file tree 2 files changed +23
-20
lines changed Original file line number Diff line number Diff line change @@ -45,16 +45,18 @@ export async function writeFiles(
45
45
await php . rmdir ( root , { recursive : true } ) ;
46
46
}
47
47
}
48
- for ( const [ relativePath , content ] of Object . entries ( newFiles ) ) {
48
+ newFiles = await newFiles ;
49
+ for ( const relativePath of Object . keys ( newFiles ) ) {
50
+ const content = await newFiles [ relativePath ] ;
51
+
49
52
const filePath = joinPaths ( root , relativePath ) ;
50
53
if ( ! ( await php . fileExists ( dirname ( filePath ) ) ) ) {
51
54
await php . mkdir ( dirname ( filePath ) ) ;
52
55
}
53
56
if ( content instanceof Uint8Array || typeof content === 'string' ) {
54
57
await php . writeFile ( filePath , content ) ;
55
58
} else {
56
- const fileTreeContent = content as MaybePromise < FileTree > ;
57
- await writeFiles ( php , filePath , fileTreeContent ) ;
59
+ await writeFiles ( php , filePath , content ) ;
58
60
}
59
61
}
60
62
}
Original file line number Diff line number Diff line change @@ -353,33 +353,34 @@ export class BlueprintAssetDirectoryResource extends VFSDirectoryResource {
353
353
async function createLazyVFSFileTree (
354
354
path : string ,
355
355
playground : UniversalPHP
356
- ) : Promise < FileTree > {
357
- const keys = await playground . listFiles ( path ) ;
358
- const keySet = new Set ( keys ) ;
356
+ ) : Promise < FileTreeAsync > {
357
+ const lazyFileTree : FileTreeAsync = { } ;
358
+
359
+ if ( ! ( await playground . isDir ( path ) ) ) {
360
+ throw new Error ( `Path "${ path } " is not a directory` ) ;
361
+ }
362
+
363
+ for ( const fileName of await playground . listFiles ( path ) ) {
364
+ Object . defineProperty ( lazyFileTree , fileName , {
365
+ configurable : false ,
366
+ enumerable : true ,
367
+ async get ( ) {
368
+ const fullPath = joinPaths ( path , fileName ) ;
359
369
360
- return new Proxy < FileTree > (
361
- { } ,
362
- {
363
- ownKeys ( ) {
364
- return keys ;
365
- } ,
366
- async get ( target , prop : string ) {
367
- if ( ! keySet . has ( prop ) ) {
368
- return undefined ;
369
- }
370
- const fullPath = joinPaths ( path , prop ) ;
371
370
if ( ! ( await playground . fileExists ( fullPath ) ) ) {
372
371
return undefined ;
373
372
}
374
373
375
374
if ( await playground . isDir ( fullPath ) ) {
376
375
return createLazyVFSFileTree ( fullPath , playground ) ;
377
376
} else {
378
- return playground . readFileAsBuffer ( joinPaths ( path , prop ) ) ;
377
+ return playground . readFileAsBuffer ( fullPath ) ;
379
378
}
380
379
} ,
381
- }
382
- ) ;
380
+ } ) ;
381
+ }
382
+
383
+ return lazyFileTree ;
383
384
}
384
385
385
386
/**
You can’t perform that action at this time.
0 commit comments