Skip to content

Commit

Permalink
Merge pull request serverless#5297 from fruffin/fix-4188
Browse files Browse the repository at this point in the history
Fixed serverless#4188 - Package generating incorrect package artifact path in serverless-state.json
  • Loading branch information
pmuens authored Mar 14, 2019
2 parents 5d73e81 + 2a846ca commit fe86fde
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/plugins/aws/package/lib/saveServiceState.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ module.exports = {
const selfReferences = findReferences(strippedService, this.serverless.service);
_.forEach(selfReferences, refPath => _.set(strippedService, refPath, '${self:}'));

_.forEach(strippedService.functions, func => {
const packageRef = func.package;
if (!_.isEmpty(packageRef)) {
packageRef.artifact = path.join(
this.packagePath,
packageRef.artifact.substr(packageRef.artifact.lastIndexOf('\\') + 1)
);
}
});

const state = {
service: strippedService,
package: {
Expand Down
53 changes: 53 additions & 0 deletions lib/plugins/aws/package/lib/saveServiceState.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,57 @@ describe('#saveServiceState()', () => {
.to.equal(true);
});
});

it('should resolve package artifact paths on function levels', () => {
const filePath = path.join(
awsPackage.serverless.config.servicePath,
'.serverless',
'service-state.json'
);

const distPath = path.join('..', 'dist');
const firstFuncArtifactPath = path.join('..', 'artifacts', 'first.zip');

awsPackage.packagePath = distPath;
serverless.service.package.path = distPath;
serverless.service.functions = {
first: {
package: {
artifact: firstFuncArtifactPath,
},
},
second: {
package: {},
},
};

return awsPackage.saveServiceState().then(() => {
const expectedStateFileContent = {
service: {
provider: {
compiledCloudFormationTemplate: 'compiled content',
},
functions: {
first: {
package: {
artifact: firstFuncArtifactPath,
},
},
second: {
package: {},
},
},
},
package: {
individually: false,
artifactDirectoryName: 'artifact-directory',
artifact: 'service.zip',
},
};

expect(getServiceStateFileNameStub.calledOnce).to.equal(true);
expect(writeFileSyncStub.calledWithExactly(filePath, expectedStateFileContent, true))
.to.equal(true);
});
});
});

0 comments on commit fe86fde

Please sign in to comment.