Skip to content

Commit f7d3777

Browse files
author
bweigel
committed
only create new artifact, when module should be moved to root of zip
1 parent 0718914 commit f7d3777

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

lib/inject.js

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

5656
return fse
5757
.readFileAsync(source)
5858
.then(buffer => JSZip.loadAsync(buffer))
5959
.then(sourceZip => sourceZip.filter(() => true))
6060
.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-
61+
let targetName = srcZipObj.name.replace(module + '/', '');
7262
return zipFile(targetZip, targetName, srcZipObj.async('nodebuffer'));
7363
})
7464
.then(() => writeZip(targetZip, target));
@@ -95,19 +85,19 @@ function injectAllRequirements(funcArtifact) {
9585
return func;
9686
})
9787
.map(func => {
98-
if (func.module !== '.') {
88+
if (
89+
this.options.IndividuallyMoveUpModules === true ||
90+
this.options.IndividuallyMoveUpModules === 'true'
91+
) {
9992
const artifact = func.package ? func.package.artifact : funcArtifact;
10093
const newArtifact = path.join(
10194
'.serverless',
10295
`${func.module}-${func.name}.zip`
10396
);
10497
func.package.artifact = newArtifact;
105-
return injectSourceCode(
106-
artifact,
107-
newArtifact,
108-
func.module,
109-
this.options
110-
).then(() => func);
98+
return injectSourceCode(artifact, newArtifact, func.module).then(
99+
() => func
100+
);
111101
} else {
112102
return func;
113103
}
@@ -116,10 +106,10 @@ function injectAllRequirements(funcArtifact) {
116106
return this.options.zip
117107
? func
118108
: injectRequirements(
119-
path.join('.serverless', func.module, 'requirements'),
120-
func.package.artifact,
121-
this.options
122-
);
109+
path.join('.serverless', func.module, 'requirements'),
110+
func.package.artifact,
111+
this.options
112+
);
123113
});
124114
} else if (!this.options.zip) {
125115
return injectRequirements(

0 commit comments

Comments
 (0)