Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle layers paths with trailing slash and leading ./ or just . #5656

Merged
merged 2 commits into from
Jan 29, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/plugins/package/lib/packageService.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ module.exports = {
const zipFileName = `${layerName}.zip`; const zipFileName = `${layerName}.zip`;


return this.resolveFilePathsLayer(layerName) return this.resolveFilePathsLayer(layerName)
.then(filePaths => filePaths.map(f => path.resolve(path.join(layerObject.path, f))))
.then(filePaths => .then(filePaths =>
this.zipFiles(filePaths, zipFileName, layerObject.path).then(artifactPath => { this.zipFiles(filePaths, zipFileName, path.resolve(layerObject.path)).then(artifactPath => {
layerObject.package = { layerObject.package = {
artifact: artifactPath, artifact: artifactPath,
}; };
Expand Down
53 changes: 53 additions & 0 deletions lib/plugins/package/lib/packageService.test.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -418,4 +418,57 @@ describe('#packageService()', () => {
])); ]));
}); });
}); });
describe('#packageLayer()', () => {
const exclude = ['test-exclude'];
const include = ['test-include'];
const files = [];
const artifactFilePath = '/some/fake/path/test-artifact.zip';
let getExcludesStub;
let getIncludesStub;
let resolveFilePathsFromPatternsStub;
let zipFilesStub;

beforeEach(() => {
getExcludesStub = sinon
.stub(packagePlugin, 'getExcludes').returns(exclude);
getIncludesStub = sinon
.stub(packagePlugin, 'getIncludes').returns(include);
resolveFilePathsFromPatternsStub = sinon
.stub(packagePlugin, 'resolveFilePathsFromPatterns').returns(files);
zipFilesStub = sinon
.stub(packagePlugin, 'zipFiles').resolves(artifactFilePath);
});

afterEach(() => {
packagePlugin.getExcludes.restore();
packagePlugin.getIncludes.restore();
packagePlugin.resolveFilePathsFromPatterns.restore();
packagePlugin.zipFiles.restore();
});

it('should call zipService with settings', () => {
const servicePath = 'test';
const layerName = 'test-layer';

const zipFileName = 'test-layer.zip';

serverless.config.servicePath = servicePath;
serverless.service.layers = {};
serverless.service.layers[layerName] = { path: './foobar' };

return expect(packagePlugin.packageLayer(layerName)).to.eventually.equal(artifactFilePath)
.then(() => BbPromise.all([
expect(getExcludesStub).to.be.calledOnce,
expect(getIncludesStub).to.be.calledOnce,
expect(resolveFilePathsFromPatternsStub).to.be.calledOnce,

expect(zipFilesStub).to.be.calledOnce,
expect(zipFilesStub).to.have.been.calledWithExactly(
files,
zipFileName,
path.resolve('./foobar')
),
]));
});
});
}); });
3 changes: 1 addition & 2 deletions lib/plugins/package/lib/zipService.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ module.exports = {
output.on('open', () => { output.on('open', () => {
zip.pipe(output); zip.pipe(output);


const filePaths = files.map(file => (prefix ? path.join(prefix, file) : file)); BbPromise.all(files.map(this.getFileContentAndStat.bind(this))).then((contents) => {
BbPromise.all(filePaths.map(this.getFileContentAndStat.bind(this))).then((contents) => {
_.forEach(_.sortBy(contents, ['filePath']), (file) => { _.forEach(_.sortBy(contents, ['filePath']), (file) => {
const name = file.filePath.slice(prefix ? `${prefix}${path.sep}`.length : 0); const name = file.filePath.slice(prefix ? `${prefix}${path.sep}`.length : 0);
zip.append(file.data, { zip.append(file.data, {
Expand Down