mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 04:22:07 +00:00
49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
/**
|
|
* This file gets copied out of the `pkg` snapshot filesystem into the `vc dev`
|
|
* builder cache directory, so it's very important that it does not rely on any
|
|
* modules from npm that would not be available in that directory (so basically,
|
|
* only Vercel Runtimes and `@vercel/build-utils`.
|
|
*/
|
|
const { FileFsRef } = require('@vercel/build-utils');
|
|
|
|
process.on('unhandledRejection', err => {
|
|
console.error('Exiting builder due to build error:');
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|
|
|
|
process.on('message', onMessage);
|
|
|
|
function onMessage(message) {
|
|
processMessage(message).catch(err => {
|
|
Object.defineProperty(err, 'message', { enumerable: true });
|
|
Object.defineProperty(err, 'stack', { enumerable: true });
|
|
process.removeListener('message', onMessage);
|
|
process.send({ type: 'buildResult', error: err }, () => process.exit(1));
|
|
});
|
|
}
|
|
|
|
async function processMessage(message) {
|
|
const { requirePath, buildOptions } = message;
|
|
const builder = require(requirePath);
|
|
|
|
// Convert the `files` to back into `FileFsRef` instances
|
|
for (const name of Object.keys(buildOptions.files)) {
|
|
const ref = Object.assign(
|
|
Object.create(FileFsRef.prototype),
|
|
buildOptions.files[name]
|
|
);
|
|
buildOptions.files[name] = ref;
|
|
}
|
|
|
|
const result = await builder.build(buildOptions);
|
|
|
|
// `@vercel/next` sets this, but it causes "Converting circular
|
|
// structure to JSON" errors, so delete the property...
|
|
delete result.childProcesses;
|
|
|
|
process.send({ type: 'buildResult', result });
|
|
}
|
|
|
|
process.send({ type: 'ready' });
|