Skip to content

Commit 4b24eb5

Browse files
F3n67uyufeng.freeman
authored and
yufeng.freeman
committed
tools: refactor build-addons.js to ESM
1 parent aa14ff9 commit 4b24eb5

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

.github/label-pr-config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ subSystemLabels:
6767
/^tools\/make-v8/: tools, v8 engine, needs-ci
6868
/^tools\/v8_gypfiles/: tools, v8 engine, needs-ci
6969
/^tools\/(code_cache|snapshot)/: needs-ci
70-
/^tools\/build-addons.js/: needs-ci
70+
/^tools\/build-addons.mjs/: needs-ci
7171
# all other tool changes should be marked as such
7272
/^tools\//: tools
7373
/^\.eslint|\.remark|\.editorconfig/: tools

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,13 @@ ADDONS_BINDING_SOURCES := \
366366
$(filter-out test/addons/??_*/*.h, $(wildcard test/addons/*/*.h))
367367

368368
ADDONS_PREREQS := config.gypi \
369-
deps/npm/node_modules/node-gyp/package.json tools/build-addons.js \
369+
deps/npm/node_modules/node-gyp/package.json tools/build-addons.mjs \
370370
deps/uv/include/*.h deps/v8/include/*.h \
371371
src/node.h src/node_buffer.h src/node_object_wrap.h src/node_version.h
372372

373373
define run_build_addons
374374
env npm_config_loglevel=$(LOGLEVEL) npm_config_nodedir="$$PWD" \
375-
npm_config_python="$(PYTHON)" $(NODE) "$$PWD/tools/build-addons" \
375+
npm_config_python="$(PYTHON)" $(NODE) "$$PWD/tools/build-addons.mjs" \
376376
"$$PWD/deps/npm/node_modules/node-gyp/bin/node-gyp.js" \
377377
$1
378378
touch $2

doc/contributing/collaborator-guide.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ There are some other files that touch the build chain. Changes in the following
232232
files also qualify as affecting the `node` binary:
233233

234234
* `tools/*.py`
235-
* `tools/build-addons.js`
235+
* `tools/build-addons.mjs`
236236
* `*.gyp`
237237
* `*.gypi`
238238
* `configure`

tools/build-addons.js tools/build-addons.mjs

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
'use strict';
1+
// Usage: e.g. node build-addons.mjs <path to node-gyp> <directory>
22

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';
99

1010
const execFile = util.promisify(child_process.execFile);
1111

12-
const parallelization = +process.env.JOBS || require('os').cpus().length;
12+
const parallelization = +process.env.JOBS || os.cpus().length;
1313
const nodeGyp = process.argv[2];
1414

1515
async function runner(directoryQueue) {
@@ -45,14 +45,11 @@ async function runner(directoryQueue) {
4545
return next();
4646
}
4747

48-
async function main(directory) {
48+
const directory = process.argv[3];
4949
const directoryQueue = (await fs.readdir(directory))
5050
.map((subdir) => path.join(directory, subdir));
5151

5252
const runners = [];
5353
for (let i = 0; i < parallelization; ++i)
5454
runners.push(runner(directoryQueue));
55-
return Promise.all(runners);
56-
}
57-
58-
main(process.argv[3]).catch((err) => setImmediate(() => { throw err; }));
55+
await Promise.all(runners);

vcbuild.bat

+3-3
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ if %errorlevel% neq 0 exit /b %errorlevel%
608608
:: building addons
609609
setlocal
610610
set npm_config_nodedir=%~dp0
611-
"%node_exe%" "%~dp0tools\build-addons.js" "%~dp0deps\npm\node_modules\node-gyp\bin\node-gyp.js" "%~dp0test\addons"
611+
"%node_exe%" "%~dp0tools\build-addons.mjs" "%~dp0deps\npm\node_modules\node-gyp\bin\node-gyp.js" "%~dp0test\addons"
612612
if errorlevel 1 exit /b 1
613613
endlocal
614614

@@ -626,7 +626,7 @@ for /d %%F in (test\js-native-api\??_*) do (
626626
:: building js-native-api
627627
setlocal
628628
set npm_config_nodedir=%~dp0
629-
"%node_exe%" "%~dp0tools\build-addons.js" "%~dp0deps\npm\node_modules\node-gyp\bin\node-gyp.js" "%~dp0test\js-native-api"
629+
"%node_exe%" "%~dp0tools\build-addons.mjs" "%~dp0deps\npm\node_modules\node-gyp\bin\node-gyp.js" "%~dp0test\js-native-api"
630630
if errorlevel 1 exit /b 1
631631
endlocal
632632
goto build-node-api-tests
@@ -645,7 +645,7 @@ for /d %%F in (test\node-api\??_*) do (
645645
:: building node-api
646646
setlocal
647647
set npm_config_nodedir=%~dp0
648-
"%node_exe%" "%~dp0tools\build-addons.js" "%~dp0deps\npm\node_modules\node-gyp\bin\node-gyp.js" "%~dp0test\node-api"
648+
"%node_exe%" "%~dp0tools\build-addons.mjs" "%~dp0deps\npm\node_modules\node-gyp\bin\node-gyp.js" "%~dp0test\node-api"
649649
if errorlevel 1 exit /b 1
650650
endlocal
651651
goto run-tests

0 commit comments

Comments
 (0)