Skip to content

Commit 6e43f4b

Browse files
authored
ui: Migrate build.js commonjs -> ESM and rename to build.mjs (#5848)
Migrate build.js commonjs -> ESM and rename to build.mjs - Migrate build.js to use ESM imports rather than commonjs `require`. - Rename to .mjs in order to get node.js to run it as an ESM module. - s/build.js/build.mjs/g everywhere to update the state.
1 parent 9fe7f44 commit 6e43f4b

9 files changed

Lines changed: 23 additions & 21 deletions

File tree

ui/.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ src/test/diff_viewer
66
out
77
config
88
build.js
9+
build.mjs
910
eslint.config.js
1011
**/*.grammar.js
1112
**/*.grammar.terms.js

ui/BUILD.gn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ action("ui_build") {
4545
outputs = [ "$target_out_dir/never_written_always_execute_rule.stamp" ]
4646
inputs = [
4747
"../tools/node",
48-
"build.js",
48+
"build.mjs",
4949
]
5050
args = [
5151
nodejs_bin,
52-
rebase_path("build.js", root_build_dir),
52+
rebase_path("build.mjs", root_build_dir),
5353
"--out",
5454
".",
5555
]

ui/build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515

1616
UI_DIR="$(cd -P ${BASH_SOURCE[0]%/*}; pwd)"
1717

18-
$UI_DIR/node $UI_DIR/build.js "$@"
18+
$UI_DIR/node $UI_DIR/build.mjs "$@"

ui/build.js renamed to ui/build.mjs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
'use strict';
16-
17-
1815
// This script takes care of:
1916
// - The build process for the whole UI and the chrome extension.
2017
// - The HTTP dev-server with live-reload capabilities.
@@ -65,14 +62,18 @@
6562
// +----------------------+ | +----------+ +--------------------+|
6663
// +------------------------------------------------+
6764

68-
const argparse = require('argparse');
69-
const childProcess = require('child_process');
70-
const crypto = require('crypto');
71-
const fs = require('fs');
72-
const http = require('http');
73-
const path = require('path');
74-
const zlib = require('zlib');
65+
import argparse from 'argparse';
66+
import childProcess from 'node:child_process';
67+
import crypto from 'node:crypto';
68+
import fs from 'node:fs';
69+
import http from 'node:http';
70+
import path from 'node:path';
71+
import zlib from 'node:zlib';
72+
import {fileURLToPath} from 'node:url';
73+
7574
const pjoin = path.join;
75+
const __filename = fileURLToPath(import.meta.url);
76+
const __dirname = path.dirname(__filename);
7677

7778
const ROOT_DIR = path.dirname(__dirname); // The repo root.
7879
const VERSION_SCRIPT = pjoin(ROOT_DIR, 'tools/write_version_header.py');
@@ -1213,7 +1214,7 @@ function prepareBuildLock() {
12131214
running = false;
12141215
}
12151216
if (running) {
1216-
console.error(`Error: a build.js instance is already running (${cfg.lockFile} PID=${oldPid}).`);
1217+
console.error(`Error: a build.mjs instance is already running (${cfg.lockFile} PID=${oldPid}).`);
12171218
console.error('Hint: use --no-build (-n) to skip the build and avoid the lock.');
12181219
process.exit(1);
12191220
} else {

ui/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@
8282
"typescript": "5.5.2"
8383
},
8484
"scripts": {
85-
"build": "node build.js",
86-
"test": "node build.js --run-unittests",
85+
"build": "node build.mjs",
86+
"test": "node build.mjs --run-unittests",
8787
"lint": "npx eslint . --ext .js,.ts"
8888
}
8989
}

ui/run-all-tests

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515

1616
UI_DIR="$(cd -P ${BASH_SOURCE[0]%/*}; pwd)"
1717

18-
$UI_DIR/node $UI_DIR/build.js --only-wasm-memory64 "$@" # Build just once.
19-
$UI_DIR/node $UI_DIR/build.js --no-build --run-unittests "$@"
18+
$UI_DIR/node $UI_DIR/build.mjs --only-wasm-memory64 "$@" # Build just once.
19+
$UI_DIR/node $UI_DIR/build.mjs --no-build --run-unittests "$@"
2020
$UI_DIR/run-integrationtests --no-build "$@"

ui/run-dev-server

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
# limitations under the License.
1515

1616
UI_DIR="$(cd -P ${BASH_SOURCE[0]%/*}; pwd)"
17-
$UI_DIR/node $UI_DIR/build.js --only-wasm-memory64 --serve --watch "$@"
17+
$UI_DIR/node $UI_DIR/build.mjs --only-wasm-memory64 --serve --watch "$@"

ui/run-unittests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
# limitations under the License.
1515

1616
UI_DIR="$(cd -P ${BASH_SOURCE[0]%/*}; pwd)"
17-
$UI_DIR/node $UI_DIR/build.js --only-wasm-memory64 --run-unittests "$@"
17+
$UI_DIR/node $UI_DIR/build.mjs --only-wasm-memory64 --run-unittests "$@"

ui/src/engine/wasm_bridge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {assertExists, assertTrue} from '../base/assert';
2020
import TraceProcessor64 from '../gen/trace_processor_memory64';
2121

2222
// The 32-bit variant may or may not be part of the build, depending on whether
23-
// the user passes --only-wasm-memory64 to ui/build.js. When we are building
23+
// the user passes --only-wasm-memory64 to ui/build.mjs. When we are building
2424
// also the 32-bit (e.g., in production builds) the import below will be
2525
// redirected by rollup to '../gen/trace_processor' (The 32-bit module).
2626
import TraceProcessor32 from './trace_processor_32_stub';

0 commit comments

Comments
 (0)