MCPcopy Create free account
hub / github.com/vercel/vercel / processMessage

Function processMessage

packages/cli/src/util/dev/builder-worker.cjs:37–108  ·  view source on GitHub ↗
(message)

Source from the content-addressed store, hash-verified

35}
36
37async function processMessage(message) {
38 const { requirePath, buildOptions } = message;
39 const builder = require(requirePath);
40
41 // Convert the `files` to back into `FileFsRef` instances
42 for (const name of Object.keys(buildOptions.files)) {
43 const ref = Object.assign(
44 Object.create(FileFsRef.prototype),
45 buildOptions.files[name]
46 );
47 buildOptions.files[name] = ref;
48 }
49
50 let result = await builder.build(buildOptions);
51
52 // `@vercel/next` sets this, but it causes "Converting circular
53 // structure to JSON" errors, so delete the property...
54 delete result.childProcesses;
55
56 // Unwrap BuildResultVX (builder.version === -1) to the actual V2 or V3 result.
57 // effectiveVersion reflects the actual result version for downstream checks.
58 let effectiveVersion = builder.version;
59 if (builder.version === -1) {
60 effectiveVersion = result.resultVersion;
61 result = result.result;
62 }
63
64 // Helper to handle zipBuffer - writes to temp file if too large for IPC
65 async function processLambdaOutput(output) {
66 const zipBuffer = await output.createZip();
67 // Delete files after creating zip to avoid OOM when serializing via IPC.
68 // The zipBuffer contains all file data, so files is no longer needed.
69 delete output.files;
70
71 // For large zip buffers, write to a temp file instead of sending via IPC.
72 // JSON serialization of large Buffers causes OOM because each byte becomes
73 // a separate array element (e.g., {"type":"Buffer","data":[1,2,3,...]}).
74 if (zipBuffer.length > ZIP_BUFFER_FILE_THRESHOLD) {
75 const tempDir = os.tmpdir();
76 const randomId = crypto.randomBytes(8).toString('hex');
77 const zipFilePath = path.join(
78 tempDir,
79 `vercel-dev-lambda-${randomId}.zip`
80 );
81 fs.writeFileSync(zipFilePath, zipBuffer);
82 output.zipBufferPath = zipFilePath;
83 } else {
84 output.zipBuffer = zipBuffer;
85 }
86 }
87
88 // Container Lambdas carry an OCI image reference in `handler`, not a code
89 // bundle, so there is nothing to zip. They are built and run locally by the
90 // builder's `startDevServer`; calling `createZip()` on them would throw since
91 // the output is a plain image-reference object.
92 const isZippableLambda = output =>
93 output.type === 'Lambda' && output.runtime !== 'container';
94

Callers 1

onMessageFunction · 0.85

Calls 7

isZippableLambdaFunction · 0.85
processLambdaOutputFunction · 0.85
buildMethod · 0.65
keysMethod · 0.45
createMethod · 0.45
valuesMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected