MCPcopy
hub / github.com/serverless/serverless / addVendorHelper

Function addVendorHelper

packages/serverless/lib/plugins/python/lib/zip.js:29–112  ·  view source on GitHub ↗

* Add the vendor helper to the current service tree. * @return {Promise}

()

Source from the content-addressed store, hash-verified

27 * @return {Promise}
28 */
29async function addVendorHelper() {
30 if (this.options.zip) {
31 // Step 1: Get all Python functions and set default module
32 const pythonFuncs = this.targetFuncs
33 .filter((func) => {
34 const runtime = func.runtime || this.serverless.service.provider.runtime
35 return runtime && runtime.match(/^python.*/)
36 })
37 .map((func) => {
38 // Default module to '.' if not specified
39 if (!func.module) {
40 func.module = '.'
41 }
42 return func
43 })
44
45 // Step 2: Separate functions by packaging mode
46 // Check BOTH function-level AND service-level package.individually
47 const individuallyPackagedFuncs = []
48 const sharedPackagedFuncs = []
49
50 for (const func of pythonFuncs) {
51 // A function is individually packaged if EITHER:
52 // 1. It has package.individually: true at function level, OR
53 // 2. The service has package.individually: true at service level
54 const isFunctionIndividual = func.package?.individually === true
55 const isServiceIndividual =
56 this.serverless.service.package?.individually === true
57
58 if (isFunctionIndividual || isServiceIndividual) {
59 // Initialize package properties if needed
60 if (!func.package) func.package = {}
61 if (!func.package.patterns) func.package.patterns = []
62 func.package.patterns.push('unzip_requirements.py')
63 individuallyPackagedFuncs.push(func)
64 } else {
65 sharedPackagedFuncs.push(func)
66 }
67 }
68
69 // Step 3: Add helper for individually packaged functions
70 // Process each unique module once (functions can share modules)
71 if (individuallyPackagedFuncs.length > 0) {
72 const uniqueFunctions = uniqBy(
73 individuallyPackagedFuncs,
74 (func) => func.module,
75 )
76 for (const func of uniqueFunctions) {
77 if (this.log) {
78 this.log.info(`Adding Python requirements helper to ${func.module}`)
79 } else {
80 this.serverless.cli.log(
81 `Adding Python requirements helper to ${func.module}...`,
82 )
83 }
84 await fse.copy(
85 getUnzipRequirementsPath(),
86 path.join(this.servicePath, func.module, 'unzip_requirements.py'),

Callers

nothing calls this directly

Calls 3

getUnzipRequirementsPathFunction · 0.85
infoMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…