Skip to content

Commit 29f383b

Browse files
author
bweigel
committed
initial implementation of base behavior of individual packaging
1 parent 411ced4 commit 29f383b

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class ServerlessPythonRequirements {
4646
useDownloadCache: false,
4747
cacheLocation: false,
4848
staticCacheMaxVersions: 0,
49+
IndividuallyMoveUpModules: true,
4950
pipCmdExtraArgs: [],
5051
noDeploy: [
5152
'boto3',

lib/inject.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,27 @@ function injectRequirements(requirementsPath, packagePath, options) {
5050
* @param {string} module module to keep
5151
* @return {Promise} the JSZip object written out.
5252
*/
53-
function moveModuleUp(source, target, module) {
53+
function moveModuleUp(source, target, module, options) {
5454
const targetZip = new JSZip();
5555

5656
return fse
5757
.readFileAsync(source)
5858
.then(buffer => JSZip.loadAsync(buffer))
5959
.then(sourceZip => sourceZip.filter(file => file.startsWith(module + '/')))
60-
.map(srcZipObj =>
61-
zipFile(
62-
targetZip,
63-
srcZipObj.name.replace(module + '/', ''),
64-
srcZipObj.async('nodebuffer')
65-
)
66-
)
60+
.map(srcZipObj => {
61+
let targetName;
62+
63+
if (
64+
options.IndividuallyMoveUpModules === true ||
65+
options.IndividuallyMoveUpModules == 'true'
66+
) {
67+
targetName = srcZipObj.name.replace(module + '/', '');
68+
} else {
69+
targetName = srcZipObj.name;
70+
}
71+
72+
return zipFile(targetZip, targetName, srcZipObj.async('nodebuffer'));
73+
})
6774
.then(() => writeZip(targetZip, target));
6875
}
6976

@@ -95,9 +102,12 @@ function injectAllRequirements(funcArtifact) {
95102
`${func.module}-${func.name}.zip`
96103
);
97104
func.package.artifact = newArtifact;
98-
return moveModuleUp(artifact, newArtifact, func.module).then(
99-
() => func
100-
);
105+
return moveModuleUp(
106+
artifact,
107+
newArtifact,
108+
func.module,
109+
this.options
110+
).then(() => func);
101111
} else {
102112
return func;
103113
}
@@ -106,10 +116,10 @@ function injectAllRequirements(funcArtifact) {
106116
return this.options.zip
107117
? func
108118
: injectRequirements(
109-
path.join('.serverless', func.module, 'requirements'),
110-
func.package.artifact,
111-
this.options
112-
);
119+
path.join('.serverless', func.module, 'requirements'),
120+
func.package.artifact,
121+
this.options
122+
);
113123
});
114124
} else if (!this.options.zip) {
115125
return injectRequirements(

0 commit comments

Comments
 (0)