From 9a6df262d6c8e6c58f91bb8f59ad6bde5a7183cb Mon Sep 17 00:00:00 2001 From: Christian Musa Date: Tue, 25 Aug 2020 10:22:01 -0300 Subject: [PATCH 1/2] Fix packaging with files that contain dots as part of the name This ports a fix introduced in serverless-components: https://github.com/serverless-components/aws-lambda/pull/26 but given some changes in the test, it probably needs to be flagged as a breaking change. Fixes https://github.com/serverless/serverless/issues/8125 --- lib/plugins/package/lib/packageService.js | 2 +- lib/plugins/package/lib/packageService.test.js | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/plugins/package/lib/packageService.js b/lib/plugins/package/lib/packageService.js index 0f26a6fcb82..f5514c70f09 100644 --- a/lib/plugins/package/lib/packageService.js +++ b/lib/plugins/package/lib/packageService.js @@ -247,7 +247,7 @@ module.exports = { // NOTE: please keep this order of concatenating the include params // rather than doing it the other way round! // see https://github.com/serverless/serverless/pull/5825 for more information - return globby(['**'].concat(params.include), { + return globby(['**/*'].concat(params.include), { cwd: path.join(this.serverless.config.servicePath, prefix || ''), dot: true, silent: true, diff --git a/lib/plugins/package/lib/packageService.test.js b/lib/plugins/package/lib/packageService.test.js index d731cc6c009..4eae1a58aa8 100644 --- a/lib/plugins/package/lib/packageService.test.js +++ b/lib/plugins/package/lib/packageService.test.js @@ -612,17 +612,19 @@ describe('#packageService()', () => { // independent file paths const handlerFile = 'src/function/handler.js'; const utilsFile = 'src/utils/utils.js'; + const dotsFile = 'src/dots/[...file].js'; let servicePath; beforeEach(() => { servicePath = createTmpDir(); fse.ensureFileSync(path.join(servicePath, handlerFile)); fse.ensureFileSync(path.join(servicePath, utilsFile)); + fse.ensureFileSync(path.join(servicePath, dotsFile)); }); it('should exclude all and include function/handler.js', () => { const params = { - exclude: ['**'], + exclude: ['**/*'], include: [handlerFile], }; serverless.config.servicePath = servicePath; @@ -642,7 +644,7 @@ describe('#packageService()', () => { return expect( packagePlugin.resolveFilePathsFromPatterns(params) ).to.be.fulfilled.then(actual => - expect(actual.sort()).to.deep.equal([handlerFile, utilsFile].sort()) + expect(actual.sort()).to.deep.equal([dotsFile, handlerFile, utilsFile].sort()) ); }); @@ -651,7 +653,7 @@ describe('#packageService()', () => { exclude: [], include: [`!${utilsFile}`], }; - const expected = [handlerFile]; + const expected = [dotsFile, handlerFile]; serverless.config.servicePath = servicePath; return expect( From 42de6ccdb266a759f4d20b50d6b6ea802a500052 Mon Sep 17 00:00:00 2001 From: Christian Musa Date: Tue, 25 Aug 2020 17:59:36 -0300 Subject: [PATCH 2/2] Update globby to v11 and replace nanomatch with micromatch --- lib/plugins/package/lib/packageService.js | 8 ++++---- lib/plugins/package/lib/packageService.test.js | 4 ++-- package.json | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/plugins/package/lib/packageService.js b/lib/plugins/package/lib/packageService.js index f5514c70f09..eadc2c03c01 100644 --- a/lib/plugins/package/lib/packageService.js +++ b/lib/plugins/package/lib/packageService.js @@ -4,7 +4,7 @@ const BbPromise = require('bluebird'); const path = require('path'); const globby = require('globby'); const _ = require('lodash'); -const nanomatch = require('nanomatch'); +const micromatch = require('micromatch'); const serverlessConfigFileUtils = require('../../../../lib/utils/getServerlessConfigFile'); module.exports = { @@ -247,7 +247,7 @@ module.exports = { // NOTE: please keep this order of concatenating the include params // rather than doing it the other way round! // see https://github.com/serverless/serverless/pull/5825 for more information - return globby(['**/*'].concat(params.include), { + return globby(['**'].concat(params.include), { cwd: path.join(this.serverless.config.servicePath, prefix || ''), dot: true, silent: true, @@ -257,14 +257,14 @@ module.exports = { }).then(allFilePaths => { const filePathStates = allFilePaths.reduce((p, c) => Object.assign(p, { [c]: true }), {}); patterns - // nanomatch only does / style path delimiters, so convert them if on windows + // micromatch only does / style path delimiters, so convert them if on windows .map(p => { return process.platform === 'win32' ? p.replace(/\\/g, '/') : p; }) .forEach(p => { const exclude = p.startsWith('!'); const pattern = exclude ? p.slice(1) : p; - nanomatch(allFilePaths, [pattern], { dot: true }).forEach(key => { + micromatch(allFilePaths, [pattern], { dot: true }).forEach(key => { filePathStates[key] = !exclude; }); }); diff --git a/lib/plugins/package/lib/packageService.test.js b/lib/plugins/package/lib/packageService.test.js index 4eae1a58aa8..ad5991ede0e 100644 --- a/lib/plugins/package/lib/packageService.test.js +++ b/lib/plugins/package/lib/packageService.test.js @@ -624,7 +624,7 @@ describe('#packageService()', () => { it('should exclude all and include function/handler.js', () => { const params = { - exclude: ['**/*'], + exclude: ['**'], include: [handlerFile], }; serverless.config.servicePath = servicePath; @@ -644,7 +644,7 @@ describe('#packageService()', () => { return expect( packagePlugin.resolveFilePathsFromPatterns(params) ).to.be.fulfilled.then(actual => - expect(actual.sort()).to.deep.equal([dotsFile, handlerFile, utilsFile].sort()) + expect(actual.sort()).to.deep.equal([handlerFile, utilsFile].sort()) ); }); diff --git a/package.json b/package.json index 5597c6c0eb4..5f91e797042 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "filesize": "^3.6.1", "fs-extra": "^8.1.0", "get-stdin": "^6.0.0", - "globby": "^9.2.0", + "globby": "^11.0.1", "graceful-fs": "^4.2.4", "https-proxy-agent": "^5.0.0", "is-docker": "^1.1.0", @@ -57,8 +57,8 @@ "jwt-decode": "^2.2.0", "lodash": "^4.17.20", "memoizee": "^0.4.14", + "micromatch": "^4.0.2", "mkdirp": "^0.5.4", - "nanomatch": "^1.2.13", "ncjsm": "^4.1.0", "node-fetch": "^2.6.0", "object-hash": "^2.0.3",