From cbb5456c7d79f1ec0e54a373d03f2c1e00d0e900 Mon Sep 17 00:00:00 2001 From: Roni Frantchi Date: Mon, 3 May 2021 10:41:02 +0300 Subject: [PATCH 1/4] fix: non-nodejs runtime are being packaged --- lib/packageModules.js | 4 +--- tests/packageModules.test.js | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/packageModules.js b/lib/packageModules.js index 0aec043e6..866fb57eb 100644 --- a/lib/packageModules.js +++ b/lib/packageModules.js @@ -133,9 +133,7 @@ module.exports = { copyExistingArtifacts() { this.serverless.cli.log('Copying existing artifacts...'); - // When invoked as a part of `deploy function`, - // only function passed with `-f` flag should be processed. - const functionNames = this.options.function ? [this.options.function] : this.serverless.service.getAllFunctions(); + const functionNames = _.map(this.entryFunctions, 'funcName'); // Copy artifacts to package location if (isIndividialPackaging.call(this)) { diff --git a/tests/packageModules.test.js b/tests/packageModules.test.js index c7904a49d..c84e07a1f 100644 --- a/tests/packageModules.test.js +++ b/tests/packageModules.test.js @@ -682,6 +682,8 @@ describe('packageModules', () => { it('copies only the artifact for function specified in options', () => { _.set(module, 'options.function', 'func1'); + // when set to options.function is set, validate.js will only have that function as an entry point + _.set(module, 'entryFunctions', _.pickBy(entryFunctions, [ 'funcName', 'func1' ])); const expectedFunc1Destination = path.join('.serverless', 'func1.zip'); return expect(module.copyExistingArtifacts()).to.be.fulfilled.then(() => From 6d60fc6af05cad0fd8c0619b2b9cf29c03d9d5d3 Mon Sep 17 00:00:00 2001 From: Roni Frantchi Date: Mon, 3 May 2021 11:49:20 +0300 Subject: [PATCH 2/4] edit comment --- tests/packageModules.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/packageModules.test.js b/tests/packageModules.test.js index c84e07a1f..6d8b4ee36 100644 --- a/tests/packageModules.test.js +++ b/tests/packageModules.test.js @@ -682,7 +682,7 @@ describe('packageModules', () => { it('copies only the artifact for function specified in options', () => { _.set(module, 'options.function', 'func1'); - // when set to options.function is set, validate.js will only have that function as an entry point + // when options.function is set, validate.js will only have that function as an entry point - mocking that behavior: _.set(module, 'entryFunctions', _.pickBy(entryFunctions, [ 'funcName', 'func1' ])); const expectedFunc1Destination = path.join('.serverless', 'func1.zip'); From af1475a4a92e075236571e41813a101e3b79c2c4 Mon Sep 17 00:00:00 2001 From: Roni Frantchi Date: Tue, 4 May 2021 10:06:52 +0300 Subject: [PATCH 3/4] fix - entryFunctions is not available --- lib/packageModules.js | 9 ++++++++- tests/packageModules.test.js | 20 ++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/packageModules.js b/lib/packageModules.js index 866fb57eb..8a0c44797 100644 --- a/lib/packageModules.js +++ b/lib/packageModules.js @@ -133,7 +133,14 @@ module.exports = { copyExistingArtifacts() { this.serverless.cli.log('Copying existing artifacts...'); - const functionNames = _.map(this.entryFunctions, 'funcName'); + const functionNames = _.filter( + this.options.function ? [this.options.function] : this.serverless.service.getAllFunctions(), + funcName => { + const func = this.serverless.service.getFunction(funcName); + const runtime = func.runtime || this.serverless.service.provider.runtime || 'nodejs'; + return runtime.match(/node/); + } + ); // Copy artifacts to package location if (isIndividialPackaging.call(this)) { diff --git a/tests/packageModules.test.js b/tests/packageModules.test.js index c84e07a1f..cca71fba4 100644 --- a/tests/packageModules.test.js +++ b/tests/packageModules.test.js @@ -477,16 +477,21 @@ describe('packageModules', () => { }); describe('copyExistingArtifacts()', () => { - const allFunctions = [ 'func1', 'func2' ]; + const allFunctions = [ 'func1', 'func2', 'funcPython' ]; const func1 = { handler: 'src/handler1', events: [] }; const func2 = { handler: 'src/handler2', - events: [] + events: [], + runtime: 'node' + }; + const funcPython = { + handler: 'src/handlerPython', + events: [], + runtime: 'python' }; - const entryFunctions = [ { handlerFile: 'src/handler1.js', @@ -497,6 +502,11 @@ describe('packageModules', () => { handlerFile: 'src/handler2.js', funcName: 'func2', func: func2 + }, + { + handlerFile: 'src/handlerPython.js', + funcName: 'funcPython', + func: funcPython } ]; @@ -515,6 +525,7 @@ describe('packageModules', () => { getAllFunctionsStub.returns(allFunctions); getFunctionStub.withArgs('func1').returns(func1); getFunctionStub.withArgs('func2').returns(func2); + getFunctionStub.withArgs('funcPython').returns(funcPython); }); it('copies the artifact', () => { @@ -660,9 +671,10 @@ describe('packageModules', () => { getAllFunctionsStub.returns(allFunctions); getFunctionStub.withArgs('func1').returns(func1); getFunctionStub.withArgs('func2').returns(func2); + getFunctionStub.withArgs('funcPython').returns(funcPython); }); - it('copies each artifact', () => { + it('copies each node artifact', () => { const expectedFunc1Destination = path.join('.serverless', 'func1.zip'); const expectedFunc2Destination = path.join('.serverless', 'func2.zip'); From 2bee3458ea2c7407160326e399dc2b93c0aeca34 Mon Sep 17 00:00:00 2001 From: Roni Frantchi Date: Tue, 4 May 2021 10:20:49 +0300 Subject: [PATCH 4/4] filter only on individually --- lib/packageModules.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/packageModules.js b/lib/packageModules.js index 8a0c44797..64ed0541b 100644 --- a/lib/packageModules.js +++ b/lib/packageModules.js @@ -133,18 +133,18 @@ module.exports = { copyExistingArtifacts() { this.serverless.cli.log('Copying existing artifacts...'); - const functionNames = _.filter( - this.options.function ? [this.options.function] : this.serverless.service.getAllFunctions(), - funcName => { - const func = this.serverless.service.getFunction(funcName); - const runtime = func.runtime || this.serverless.service.provider.runtime || 'nodejs'; - return runtime.match(/node/); - } - ); + // When invoked as a part of `deploy function`, + // only function passed with `-f` flag should be processed. + const functionNames = this.options.function ? [this.options.function] : this.serverless.service.getAllFunctions(); // Copy artifacts to package location if (isIndividialPackaging.call(this)) { - _.forEach(functionNames, funcName => copyArtifactByName.call(this, funcName)); + const nodeFunctionNames = _.filter(functionNames, funcName => { + const func = this.serverless.service.getFunction(funcName); + const runtime = func.runtime || this.serverless.service.provider.runtime || 'nodejs'; + return runtime.match(/node/); + }); + _.forEach(nodeFunctionNames, funcName => copyArtifactByName.call(this, funcName)); } else { // Copy service packaged artifact const serviceName = this.serverless.service.getServiceObject().name;