|
3 | 3 | const SERIALIZE_ERROR = require('./serialize-error') |
4 | 4 |
|
5 | 5 | module.exports = snippet => ` |
6 | | - const args = JSON.parse(process.argv[2]) |
| 6 | + ;(async () => { |
| 7 | + const args = JSON.parse(process.argv[2]) |
7 | 8 |
|
8 | | - /* https://github.com/Kikobeats/null-prototype-object */ |
9 | | - const logging = new (/* @__PURE__ */ (() => { let e = function(){}; return e.prototype = Object.create(null), Object.freeze(e.prototype), e })()); |
| 9 | + /* https://github.com/Kikobeats/null-prototype-object */ |
| 10 | + const logging = new (/* @__PURE__ */ (() => { let e = function(){}; return e.prototype = Object.create(null), Object.freeze(e.prototype), e })()); |
10 | 11 |
|
11 | | - for (const method of ['log', 'info', 'debug', 'warn', 'error']) { |
12 | | - console[method] = function (...args) { |
13 | | - logging[method] === undefined ? logging[method] = [args] : logging[method].push(args) |
| 12 | + for (const method of ['log', 'info', 'debug', 'warn', 'error']) { |
| 13 | + console[method] = function (...args) { |
| 14 | + logging[method] === undefined ? logging[method] = [args] : logging[method].push(args) |
| 15 | + } |
14 | 16 | } |
15 | | - } |
16 | 17 |
|
17 | | - ;(async (send) => { |
18 | | - process.stdout.write = function () {} |
19 | | - let value |
20 | | - let isFulfilled |
| 18 | + ;await (async (send) => { |
| 19 | + process.stdout.write = function () {} |
| 20 | + let value |
| 21 | + let isFulfilled |
21 | 22 |
|
22 | | - try { |
23 | | - value = await (${snippet.toString()})(...args) |
24 | | - isFulfilled = true |
25 | | - } catch (error) { |
26 | | - value = ${SERIALIZE_ERROR}(error) |
27 | | - isFulfilled = false |
28 | | - } finally { |
29 | | - send(JSON.stringify({ |
30 | | - isFulfilled, |
31 | | - logging, |
32 | | - value, |
33 | | - profiling: { memory: process.memoryUsage().rss } |
34 | | - })) |
35 | | - } |
36 | | - })(process.stdout.write.bind(process.stdout))` |
| 23 | + try { |
| 24 | + value = await (${snippet.toString()})(...args) |
| 25 | + isFulfilled = true |
| 26 | + } catch (error) { |
| 27 | + value = ${SERIALIZE_ERROR}(error) |
| 28 | + isFulfilled = false |
| 29 | + } finally { |
| 30 | + send(JSON.stringify({ |
| 31 | + isFulfilled, |
| 32 | + logging, |
| 33 | + value, |
| 34 | + profiling: { memory: process.memoryUsage().rss } |
| 35 | + })) |
| 36 | + } |
| 37 | + })(process.stdout.write.bind(process.stdout)) |
| 38 | + })()` |
0 commit comments