File tree Expand file tree Collapse file tree 4 files changed +21
-11
lines changed
Expand file tree Collapse file tree 4 files changed +21
-11
lines changed Original file line number Diff line number Diff line change @@ -631,21 +631,25 @@ const fixZip = async (data, options = {}) => {
631631 }
632632 } ) ;
633633
634- /** @type {Array<[string, import("@turbowarp/jszip").JSZipObject]> } */
635- const zipFiles = [ ] ;
636- zip . forEach ( ( relativePath , file ) => {
637- zipFiles . push ( [ relativePath , file ] ) ;
638- } ) ;
639-
640634 // Remove any unreadable files from the zip. This can notably happen if the compressed data in the zip was
641635 // corrupted, which would make the uncompressed data size field not match. Scratch/JSZip will refuse to
642636 // keep loading the project if that happens. If we remove the asset, at least there's a chance it can now
643637 // be downloaded from the asset server instead.
644- for ( const [ relativePath , file ] of zipFiles ) {
645- try {
646- await file . async ( 'uint8array' ) ;
647- } catch ( error ) {
648- log ( `zip had unreadable file ${ relativePath } : ${ error } ` ) ;
638+ for ( const [ relativePath , file ] of Object . entries ( zip . files ) ) {
639+ if ( file . dir ) {
640+ continue ;
641+ }
642+
643+ if ( / (?: p r o j e c t | s p r i t e ) \. j s o n / . test ( relativePath ) || / [ 0 - 9 a - f ] { 32 } \. / . test ( relativePath ) ) {
644+ try {
645+ // If the file is corrupt, this will throw.
646+ await file . async ( 'uint8array' ) ;
647+ } catch ( error ) {
648+ log ( `zip had unreadable file ${ relativePath } : ${ error } ` ) ;
649+ zip . remove ( relativePath ) ;
650+ }
651+ } else {
652+ log ( `zip had extraneous file ${ relativePath } ` ) ;
649653 zip . remove ( relativePath ) ;
650654 }
651655 }
Original file line number Diff line number Diff line change 1+ zip had extraneous file README.md
2+ zip had extraneous file package.json
3+ zip had extraneous file a folder in the zip/package-lock.json
4+ zip had extraneous file a folder in the zip/webpack.config.js
5+ checking target 0
6+ checking target 1
You can’t perform that action at this time.
0 commit comments