Skip to content

Fix corrupted zip archive in case of same module #181

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ function injectAllRequirements() {
.map(func => {
if (func.module !== '.') {
const artifact = func.package.artifact;
const newArtifact = path.join('.serverless', `${func.module}.zip`);
const newArtifact = path.join(
'.serverless',
`${func.module}-${func.name}.zip`
);
func.package.artifact = newArtifact;
return moveModuleUp(artifact, newArtifact, func.module).then(
() => func
Expand Down
46 changes: 26 additions & 20 deletions lib/pip.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,29 +201,35 @@ function installAllRequirements() {
fse.ensureDirSync(path.join(this.servicePath, '.serverless'));
if (this.serverless.service.package.individually) {
let doneModules = [];
values(this.serverless.service.functions).forEach(f => {
if (!get(f, 'module')) {
set(f, ['module'], '.');
}
if (!doneModules.includes(f.module)) {
installRequirements(
path.join(f.module, this.options.fileName),
path.join('.serverless', f.module),
this.serverless,
this.servicePath,
this.options
);
if (f.vendor) {
// copy vendor libraries to requirements folder
copyVendors(
f.vendor,
values(this.serverless.service.functions)
.filter(func =>
(func.runtime || this.serverless.service.provider.runtime).match(
/^python.*/
)
)
.map(f => {
if (!get(f, 'module')) {
set(f, ['module'], '.');
}
if (!doneModules.includes(f.module)) {
installRequirements(
path.join(f.module, this.options.fileName),
path.join('.serverless', f.module),
this.serverless
this.serverless,
this.servicePath,
this.options
);
if (f.vendor) {
// copy vendor libraries to requirements folder
copyVendors(
f.vendor,
path.join('.serverless', f.module),
this.serverless
);
}
doneModules.push(f.module);
}
doneModules.push(f.module);
}
});
});
} else {
installRequirements(
this.options.fileName,
Expand Down
4 changes: 2 additions & 2 deletions test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ teardown() {
cd tests/individually
npm i $(npm pack ../..)
sls package
unzip .serverless/module1.zip -d puck
unzip .serverless/module2.zip -d puck2
unzip .serverless/module1-sls-py-req-test-indiv.zip -d puck
unzip .serverless/module2-sls-py-req-test-indiv.zip -d puck2
ls puck/handler1.py
ls puck2/handler2.py
ls puck/pyaml
Expand Down