MCPcopy
hub / github.com/serverless/serverless / moveModuleUp

Function moveModuleUp

packages/serverless/lib/plugins/python/lib/inject.js:61–81  ·  view source on GitHub ↗

* Remove all modules but the selected module from a package. * @param {string} source path to original package * @param {string} target path to result package * @param {string} module module to keep * @return {Promise} the JSZip object written out.

(source, target, module)

Source from the content-addressed store, hash-verified

59 * @return {Promise} the JSZip object written out.
60 */
61async function moveModuleUp(source, target, module) {
62 const targetZip = new JSZip()
63 const buffer = await fse.readFile(source)
64 const sourceZip = await JSZip.loadAsync(buffer)
65 const entries = sourceZip.filter(
66 (file) =>
67 file.startsWith(module + '/') ||
68 file.startsWith('serverless_sdk/') ||
69 file.match(/^s_.*\.py/) !== null,
70 )
71 for (const srcZipObj of entries) {
72 await zipFile(
73 targetZip,
74 srcZipObj.name.startsWith(module + '/')
75 ? srcZipObj.name.replace(module + '/', '')
76 : srcZipObj.name,
77 srcZipObj.async('nodebuffer'),
78 )
79 }
80 await writeZip(targetZip, target)
81}
82
83/**
84 * Inject requirements into packaged application.

Callers 1

injectAllRequirementsFunction · 0.85

Calls 3

zipFileFunction · 0.90
writeZipFunction · 0.90
readFileMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…