Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,12 @@ async function run(): Promise<void> {
onZip: (sourceDir: string, zipPath: string) => {
logInfo(`Created zip file from '${sourceDir}' at '${zipPath}'`);
},
onZipEntry: (entry: EntryData) => {
onZipAddEntry: (entry: EntryData) => {
logDebug(formatEntry(entry));
},
onZipIgnoreEntry: (entry: EntryData) => {
logDebug(`Ignoring ${entry.name}`);
},
onNew: () => {
logInfo('Creating new Cloud Function deployment');
},
Expand Down
19 changes: 16 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ export type OnZipEntryFunction = (entry: Archiver.EntryData) => void;
* ZipOptions is used as input to the zip function.
*/
export type ZipOptions = {
onZipEntry?: OnZipEntryFunction;
/**
* onZipAddEntry is called when an entry is added to the archive.
*/
onZipAddEntry?: OnZipEntryFunction;

/**
* onZipIgnoreEntry is called when an entry is ignored due to an ignore
* specification.
*/
onZipIgnoreEntry?: OnZipEntryFunction;
};

/**
Expand Down Expand Up @@ -60,7 +69,11 @@ export async function zipDir(
const ignores = await parseGcloudIgnore(ignoreFile);
const ignorer = ignore().add(ignores);
const ignoreFn = (entry: Archiver.EntryData): false | Archiver.EntryData => {
return ignorer.ignores(entry.name) ? false : entry;
if (ignorer.ignores(entry.name)) {
if (opts?.onZipIgnoreEntry) opts.onZipIgnoreEntry(entry);
return false;
}
return entry;
};

return new Promise((resolve, reject) => {
Expand All @@ -70,7 +83,7 @@ export async function zipDir(
// For some reason, TypeScript complains if this guard is outside the
// closure. It would be more performant just not create this listener, but
// alas...
if (opts?.onZipEntry) opts.onZipEntry(entry);
if (opts?.onZipAddEntry) opts.onZipAddEntry(entry);
});
archive.on('warning', (err) => reject(err));
archive.on('error', (err) => reject(err));
Expand Down