|
1 | | -'use strict'; |
| 1 | +// Usage: e.g. node build-addons.mjs <path to node-gyp> <directory> |
2 | 2 |
|
3 | | -// Usage: e.g. node build-addons.js <path to node-gyp> <directory> |
4 | | - |
5 | | -const child_process = require('child_process'); |
6 | | -const path = require('path'); |
7 | | -const fs = require('fs').promises; |
8 | | -const util = require('util'); |
| 3 | +import child_process from 'node:child_process'; |
| 4 | +import path from 'node:path'; |
| 5 | +import fs from 'node:fs/promises'; |
| 6 | +import util from 'node:util'; |
| 7 | +import process from 'node:process'; |
| 8 | +import os from 'node:os'; |
9 | 9 |
|
10 | 10 | const execFile = util.promisify(child_process.execFile); |
11 | 11 |
|
12 | | -const parallelization = +process.env.JOBS || require('os').cpus().length; |
| 12 | +const parallelization = +process.env.JOBS || os.cpus().length; |
13 | 13 | const nodeGyp = process.argv[2]; |
14 | 14 |
|
15 | 15 | async function runner(directoryQueue) { |
@@ -45,14 +45,15 @@ async function runner(directoryQueue) { |
45 | 45 | return next(); |
46 | 46 | } |
47 | 47 |
|
48 | | -async function main(directory) { |
| 48 | +const directory = process.argv[3]; |
| 49 | +try { |
49 | 50 | const directoryQueue = (await fs.readdir(directory)) |
50 | 51 | .map((subdir) => path.join(directory, subdir)); |
51 | 52 |
|
52 | 53 | const runners = []; |
53 | 54 | for (let i = 0; i < parallelization; ++i) |
54 | 55 | runners.push(runner(directoryQueue)); |
55 | | - return Promise.all(runners); |
| 56 | + await Promise.all(runners); |
| 57 | +} catch (err) { |
| 58 | + setImmediate(() => { throw err; }); |
56 | 59 | } |
57 | | - |
58 | | -main(process.argv[3]).catch((err) => setImmediate(() => { throw err; })); |
|
0 commit comments