From 70b9aa50eb85ee9496ce32f7e30b509c860c633b Mon Sep 17 00:00:00 2001 From: Nikolay Dolzhenkov Date: Fri, 9 Apr 2021 00:01:01 +0300 Subject: [PATCH] zip only filtered files --- lib/packageModules.js | 18 ++++++++++++------ lib/wpwatch.js | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/packageModules.js b/lib/packageModules.js index 3cc4f4d73..858a34e08 100644 --- a/lib/packageModules.js +++ b/lib/packageModules.js @@ -27,15 +27,19 @@ function setArtifactPath(funcName, func, artifactPath) { function zip(directory, name) { // Check that files exist to be zipped - let files = glob.sync('**', { + const globFiles = glob.sync('**', { cwd: directory, dot: true, silent: true, - follow: true + follow: true, + nodir: true }); - if (this.configuration.excludeRegex) { - files = _.filter(files, f => f.match(this.configuration.excludeRegex) === null); + const files = this.configuration.excludeRegex + ? _.filter(globFiles, f => f.match(this.configuration.excludeRegex) === null) + : globFiles; + if (files.length < globFiles.length && this.options.verbose) { + this.serverless.cli.log(`Excluded ${globFiles.length - files.length} file(s) based on excludeRegex`); } if (_.isEmpty(files)) { @@ -49,7 +53,7 @@ function zip(directory, name) { this.serverless.utils.writeFileDir(artifactFilePath); const cwd = directory; - const source = '*'; + const source = files; const destination = path.relative(cwd, artifactFilePath); const zipArgs = { source, @@ -118,7 +122,9 @@ module.exports = { () => this.options.verbose && this.serverless.cli.log( - `Zip ${_.isEmpty(entryFunction) ? 'service' : 'function'} (using ${hasNativeZip() ? 'native' : 'node'} method): ${modulePath} [${_.now() - startZip} ms]` + `Zip ${_.isEmpty(entryFunction) ? 'service' : 'function'} (using ${ + hasNativeZip() ? 'native' : 'node' + } method): ${modulePath} [${_.now() - startZip} ms]` ) ); }); diff --git a/lib/wpwatch.js b/lib/wpwatch.js index 2a9b5b19c..36c34caff 100644 --- a/lib/wpwatch.js +++ b/lib/wpwatch.js @@ -83,7 +83,7 @@ module.exports = { } process.env.SLS_DEBUG && - this.serverless.cli.log(`Webpack watch invoke: HASH NEW=${stats.hash} CUR=${lastHash}`); + this.serverless.cli.log(`Webpack watch invoke: HASH NEW=${stats && stats.hash} CUR=${lastHash}`); // If the file hash did not change there were no effective code changes detected // (comment changes do not change the compile hash and do not account for a rebuild!)