@@ -31,7 +31,16 @@ export type OnZipEntryFunction = (entry: Archiver.EntryData) => void;
31
31
* ZipOptions is used as input to the zip function.
32
32
*/
33
33
export type ZipOptions = {
34
- onZipEntry ?: OnZipEntryFunction ;
34
+ /**
35
+ * onZipAddEntry is called when an entry is added to the archive.
36
+ */
37
+ onZipAddEntry ?: OnZipEntryFunction ;
38
+
39
+ /**
40
+ * onZipIgnoreEntry is called when an entry is ignored due to an ignore
41
+ * specification.
42
+ */
43
+ onZipIgnoreEntry ?: OnZipEntryFunction ;
35
44
} ;
36
45
37
46
/**
@@ -60,7 +69,11 @@ export async function zipDir(
60
69
const ignores = await parseGcloudIgnore ( ignoreFile ) ;
61
70
const ignorer = ignore ( ) . add ( ignores ) ;
62
71
const ignoreFn = ( entry : Archiver . EntryData ) : false | Archiver . EntryData => {
63
- return ignorer . ignores ( entry . name ) ? false : entry ;
72
+ if ( ignorer . ignores ( entry . name ) ) {
73
+ if ( opts ?. onZipIgnoreEntry ) opts . onZipIgnoreEntry ( entry ) ;
74
+ return false ;
75
+ }
76
+ return entry ;
64
77
} ;
65
78
66
79
return new Promise ( ( resolve , reject ) => {
@@ -70,7 +83,7 @@ export async function zipDir(
70
83
// For some reason, TypeScript complains if this guard is outside the
71
84
// closure. It would be more performant just not create this listener, but
72
85
// alas...
73
- if ( opts ?. onZipEntry ) opts . onZipEntry ( entry ) ;
86
+ if ( opts ?. onZipAddEntry ) opts . onZipAddEntry ( entry ) ;
74
87
} ) ;
75
88
archive . on ( 'warning' , ( err ) => reject ( err ) ) ;
76
89
archive . on ( 'error' , ( err ) => reject ( err ) ) ;
0 commit comments