* 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)
| 59 | * @return {Promise} the JSZip object written out. |
| 60 | */ |
| 61 | async 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. |
no test coverage detected
searching dependent graphs…