UNPKG

895 BJavaScriptView Raw
1require('v8-compile-cache');
2const Pipeline = require('./Pipeline');
3
4let pipeline;
5
6exports.init = function(options, callback) {
7 pipeline = new Pipeline(options || {});
8 Object.assign(process.env, options.env || {});
9 process.env.HMR_PORT = options.hmrPort;
10 process.env.HMR_HOSTNAME = options.hmrHostname;
11 callback();
12};
13
14exports.run = async function(path, pkg, options, isWarmUp, callback) {
15 try {
16 options.isWarmUp = isWarmUp;
17 var result = await pipeline.process(path, pkg, options);
18
19 callback(null, result);
20 } catch (err) {
21 let returned = err;
22 returned.fileName = path;
23 callback(returned);
24 }
25};
26
27process.on('unhandledRejection', function(err) {
28 // ERR_IPC_CHANNEL_CLOSED happens when the worker is killed before it finishes processing
29 if (err.code !== 'ERR_IPC_CHANNEL_CLOSED') {
30 console.error('Unhandled promise rejection:', err.stack);
31 }
32});