@@ -72,18 +72,22 @@ const filesystem = async (fetch) => ({
7272
7373if  ( shareDirectory  !==  undefined )  { 
7474    const  tarEntries  =  [ ] ; 
75-     for  ( const  dirent  of  await  readdir ( shareDirectory ,  {  withFileTypes : true ,  recursive : true  } ) )  { 
76-         const  name  =  `${ dirent . parentPath }  /${ dirent . name }  ` . replace ( `${ shareDirectory }  /` ,  '' ) ; 
77-         if  ( dirent . isDirectory ( ) )  { 
78-             tarEntries . push ( { name : name } ) ; 
79-         }  else  if  ( dirent . isFile ( ) )  { 
80-             tarEntries . push ( { name,  data : await  readFile ( `${ dirent . parentPath }  /${ dirent . name }  ` ) } ) ; 
75+     async  function  archivePath ( pathName )  { 
76+         const  pathStat  =  await  stat ( pathName ) ; 
77+         const  tarName  =  pathName . replace ( `${ shareDirectory }  /` ,  '' ) ; 
78+         if  ( pathStat . isDirectory ( ) )  { 
79+             if  ( pathName  !==  shareDirectory ) 
80+                 tarEntries . push ( { name : tarName } ) ; 
81+             for  ( const  name  of  await  readdir ( pathName ) ) 
82+                 await  archivePath ( `${ pathName }  /${ name }  ` ) ; 
83+         }  else  if  ( pathStat . isFile ( ) )  { 
84+             tarEntries . push ( { name : tarName ,  data : await  readFile ( pathName ) } ) ; 
8185        }  else  { 
82-             console . error ( `Unsupported type of '${ dirent . name }  '!` ) ; 
86+             console . error ( `Unsupported type of '${ pathName }  '!` ) ; 
8387            process . exit ( 2 ) ; 
8488        } 
8589    } 
86- 
90+      await   archivePath ( shareDirectory ) ; 
8791    const  tarData  =  createTar ( tarEntries ) ; 
8892    const  tarFilePath  =  resourceFilePath . replace ( / \. j s $ / ,  '.tar' ) ; 
8993    await  writeFile ( tarFilePath ,  tarData ) ; 
0 commit comments