Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.
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
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class ServerlessPythonRequirements {
useDownloadCache: true,
cacheLocation: false,
staticCacheMaxVersions: 0,
IndividuallyMoveUpModules: true,
pipCmdExtraArgs: [],
noDeploy: [],
vendor: ''
Expand Down
37 changes: 22 additions & 15 deletions lib/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,17 @@ function injectRequirements(requirementsPath, packagePath, options) {
* @param {string} module module to keep
* @return {Promise} the JSZip object written out.
*/
function moveModuleUp(source, target, module) {
function injectSourceCode(source, target, module) {
const targetZip = new JSZip();

return fse
.readFileAsync(source)
.then(buffer => JSZip.loadAsync(buffer))
.then(sourceZip => sourceZip.filter(file => file.startsWith(module + '/')))
.map(srcZipObj =>
zipFile(
targetZip,
srcZipObj.name.replace(module + '/', ''),
srcZipObj.async('nodebuffer')
)
)
.then(sourceZip => sourceZip.filter(() => true))
.map(srcZipObj => {
let targetName = srcZipObj.name.replace(module + '/', '');
return zipFile(targetZip, targetName, srcZipObj.async('nodebuffer'));
})
.then(() => writeZip(targetZip, target));
}

Expand Down Expand Up @@ -99,14 +96,24 @@ function injectAllRequirements(funcArtifact) {
return func;
})
.map(func => {
if (func.module !== '.') {
if (
this.options.IndividuallyMoveUpModules === true ||
this.options.IndividuallyMoveUpModules === 'true'
) {
const artifact = func.package ? func.package.artifact : funcArtifact;
const newArtifact = path.join(
'.serverless',
`${func.module}-${func.name}.zip`
);

let newArtifact;
if (func.module === '.') {
newArtifact = path.join('.serverless', `root-${func.name}.zip`);
} else {
newArtifact = path.join(
'.serverless',
`${func.module}-${func.name}.zip`
);
}

func.package.artifact = newArtifact;
return moveModuleUp(artifact, newArtifact, func.module).then(
return injectSourceCode(artifact, newArtifact, func.module).then(
() => func
);
} else {
Expand Down
Loading