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
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+56 −3
Diff settings

Always

Just for now

@@ -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,
}; };
@@ -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')
),
]));
});
});
}); });
@@ -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, {
ProTip! Use n and p to navigate between commits in a pull request.