Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/babel-plugins/strip-node-prefix.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { types as t } from '@babel/core';

export default function () {
return {
name: 'strip-node-prefix',
visitor: {
// e.g. `import fs from 'node:fs'`
ImportDeclaration({ node }) {
if (node.source.value.startsWith('node:')) {
node.source.value = node.source.value.slice(5);
}
},

// e.g. `await import('node:fs')`
// Note: only here for reference, it's mangled with EMSCRIPTEN$AWAIT$IMPORT below.
ImportExpression({ node }) {
if (t.isStringLiteral(node.source) && node.source.value.startsWith('node:')) {
node.source.value = node.source.value.slice(5);
}
},

// e.g. `require('node:fs')` or EMSCRIPTEN$AWAIT$IMPORT('node:fs')
CallExpression({ node }) {
if (
(t.isIdentifier(node.callee, { name: 'require' }) ||
// Special placeholder for `await import`
// FIXME: Remove after PR https://github.com/emscripten-core/emscripten/pull/23730 is landed.
t.isIdentifier(node.callee, { name: 'EMSCRIPTEN$AWAIT$IMPORT' })) &&
t.isStringLiteral(node.arguments[0]) &&
node.arguments[0].value.startsWith('node:')
) {
node.arguments[0].value = node.arguments[0].value.slice(5);
}
},
},
};
}
2 changes: 1 addition & 1 deletion src/lib/libatomic.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ addToLibrary({

emscripten_num_logical_cores: () =>
#if ENVIRONMENT_MAY_BE_NODE
ENVIRONMENT_IS_NODE ? require('os').cpus().length :
ENVIRONMENT_IS_NODE ? require('node:os').cpus().length :
#endif
navigator['hardwareConcurrency'],
});
2 changes: 1 addition & 1 deletion src/lib/libcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ addToLibrary({
var cmdstr = UTF8ToString(command);
if (!cmdstr.length) return 0; // this is what glibc seems to do (shell works test?)

var cp = require('child_process');
var cp = require('node:child_process');
var ret = cp.spawnSync(cmdstr, [], {shell:true, stdio:'inherit'});

var _W_EXITCODE = (ret, sig) => ((ret) << 8 | (sig));
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libembind_gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ var LibraryEmbind = {
const printer = new TsPrinter(moduleDefinitions);
#endif
const output = printer.print();
var fs = require('fs');
var fs = require('node:fs');
fs.writeFileSync(process.argv[2], output + '\n');
},

Expand Down
2 changes: 1 addition & 1 deletion src/lib/libnodepath.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// operations. Hence, using `nodePath` should be safe here.

addToLibrary({
$nodePath: "require('path')",
$nodePath: "require('node:path')",
$PATH__deps: ['$nodePath'],
$PATH: `{
isAbs: nodePath.isAbsolute,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libwasi.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ var WasiLibrary = {
#if ENVIRONMENT_MAY_BE_NODE && MIN_NODE_VERSION < 190000
// This block is not needed on v19+ since crypto.getRandomValues is builtin
if (ENVIRONMENT_IS_NODE) {
var nodeCrypto = require('crypto');
var nodeCrypto = require('node:crypto');
return (view) => nodeCrypto.randomFillSync(view);
}
#endif // ENVIRONMENT_MAY_BE_NODE
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libwasm_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ if (ENVIRONMENT_IS_WASM_WORKER

emscripten_navigator_hardware_concurrency: () => {
#if ENVIRONMENT_MAY_BE_NODE
if (ENVIRONMENT_IS_NODE) return require('os').cpus().length;
if (ENVIRONMENT_IS_NODE) return require('node:os').cpus().length;
#endif
return navigator['hardwareConcurrency'];
},
Expand Down
8 changes: 4 additions & 4 deletions src/parseTools.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,19 +1115,19 @@ function nodePthreadDetection() {
// Under node we detect that we are running in a pthread by checking the
// workerData property.
if (EXPORT_ES6) {
return "(await import('worker_threads')).workerData === 'em-pthread'";
return "(await import('node:worker_threads')).workerData === 'em-pthread'";
} else {
return "require('worker_threads').workerData === 'em-pthread'";
return "require('node:worker_threads').workerData === 'em-pthread'";
}
}

function nodeWWDetection() {
// Under node we detect that we are running in a wasm worker by checking the
// workerData property.
if (EXPORT_ES6) {
return "(await import('worker_threads')).workerData === 'em-ww'";
return "(await import('node:worker_threads')).workerData === 'em-ww'";
} else {
return "require('worker_threads').workerData === 'em-ww'";
return "require('node:worker_threads').workerData === 'em-ww'";
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/postamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ if (ENVIRONMENT_IS_NODE
#endif
)
{
const url = await import('url');
const url = await import('node:url');
const isMainModule = url.pathToFileURL(process.argv[1]).href === import.meta.url;
if (isMainModule) await init();
}
Expand Down
2 changes: 1 addition & 1 deletion src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ function instantiateSync(file, info) {
var binary = getBinarySync(file);
#if NODE_CODE_CACHING
if (ENVIRONMENT_IS_NODE) {
var v8 = require('v8');
var v8 = require('node:v8');
// Include the V8 version in the cache name, so that we don't try to
// load cached code from another version, which fails silently (it seems
// to load ok, but we do actually recompile the binary every time).
Expand Down
2 changes: 1 addition & 1 deletion src/pthread_esm_startup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ console.log("Running pthread_esm_startup");
if ({{{ nodeDetectionCode() }}}) {
// Create as web-worker-like an environment as we can.
globalThis.self = globalThis;
var worker_threads = await import('worker_threads');
var worker_threads = await import('node:worker_threads');
globalThis.Worker = worker_threads.Worker;
var parentPort = worker_threads['parentPort'];
// Deno and Bun already have `postMessage` defined on the global scope and
Expand Down
4 changes: 2 additions & 2 deletions src/runtime_debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ function dbg(...args) {
// See https://github.com/emscripten-core/emscripten/issues/14804
if (ENVIRONMENT_IS_NODE) {
// TODO(sbc): Unify with err/out implementation in shell.sh.
var fs = require('fs');
var utils = require('util');
var fs = require('node:fs');
var utils = require('node:util');
function stringify(a) {
switch (typeof a) {
case 'object': return utils.inspect(a);
Expand Down
10 changes: 5 additions & 5 deletions src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ if (ENVIRONMENT_IS_NODE) {
#if EXPORT_ES6
// When building an ES module `require` is not normally available.
// We need to use `createRequire()` to construct the require()` function.
const { createRequire } = await import('module');
const { createRequire } = await import('node:module');
/** @suppress{duplicate} */
var require = createRequire(import.meta.url);
#endif

#if PTHREADS || WASM_WORKERS
var worker_threads = require('worker_threads');
var worker_threads = require('node:worker_threads');
global.Worker = worker_threads.Worker;
ENVIRONMENT_IS_WORKER = !worker_threads.isMainThread;
#if PTHREADS
Expand Down Expand Up @@ -200,11 +200,11 @@ if (ENVIRONMENT_IS_NODE) {

// These modules will usually be used on Node.js. Load them eagerly to avoid
// the complexity of lazy-loading.
var fs = require('fs');
var fs = require('node:fs');

#if EXPORT_ES6
if (_scriptName.startsWith('file:')) {
scriptDirectory = require('path').dirname(require('url').fileURLToPath(_scriptName)) + '/';
scriptDirectory = require('node:path').dirname(require('node:url').fileURLToPath(_scriptName)) + '/';
}
#else
scriptDirectory = __dirname + '/';
Expand Down Expand Up @@ -376,7 +376,7 @@ if (!ENVIRONMENT_IS_AUDIO_WORKLET)
var defaultPrint = console.log.bind(console);
var defaultPrintErr = console.error.bind(console);
if (ENVIRONMENT_IS_NODE) {
var utils = require('util');
var utils = require('node:util');
var stringify = (a) => typeof a == 'object' ? utils.inspect(a) : a;
defaultPrint = (...args) => fs.writeSync(1, args.map(stringify).join(' ') + '\n');
defaultPrintErr = (...args) => fs.writeSync(2, args.map(stringify).join(' ') + '\n');
Expand Down
6 changes: 3 additions & 3 deletions src/shell_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var ENVIRONMENT_IS_WEB = !ENVIRONMENT_IS_NODE;

#if ENVIRONMENT_MAY_BE_NODE && (PTHREADS || WASM_WORKERS)
if (ENVIRONMENT_IS_NODE) {
var worker_threads = require('worker_threads');
var worker_threads = require('node:worker_threads');
global.Worker = worker_threads.Worker;
}
#endif
Expand Down Expand Up @@ -99,7 +99,7 @@ if (ENVIRONMENT_IS_NODE && ENVIRONMENT_IS_SHELL) {
var defaultPrint = console.log.bind(console);
var defaultPrintErr = console.error.bind(console);
if (ENVIRONMENT_IS_NODE) {
var fs = require('fs');
var fs = require('node:fs');
defaultPrint = (...args) => fs.writeSync(1, args.join(' ') + '\n');
defaultPrintErr = (...args) => fs.writeSync(2, args.join(' ') + '\n');
}
Expand Down Expand Up @@ -181,7 +181,7 @@ if (!ENVIRONMENT_IS_PTHREAD) {
// Wasm or Wasm2JS loading:

if (ENVIRONMENT_IS_NODE) {
var fs = require('fs');
var fs = require('node:fs');
#if WASM == 2
if (globalThis.WebAssembly) Module['wasm'] = fs.readFileSync(__dirname + '/{{{ TARGET_BASENAME }}}.wasm');
else eval(fs.readFileSync(__dirname + '/{{{ TARGET_BASENAME }}}.wasm.js')+'');
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_ctors1.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19654,
"a.out.js.gz": 8145,
"a.out.js": 19664,
"a.out.js.gz": 8146,
"a.out.nodebug.wasm": 129455,
"a.out.nodebug.wasm.gz": 49210,
"total": 149109,
"total_gz": 57355,
"total": 149119,
"total_gz": 57356,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_ctors2.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19631,
"a.out.js.gz": 8132,
"a.out.js": 19641,
"a.out.js.gz": 8133,
"a.out.nodebug.wasm": 128882,
"a.out.nodebug.wasm.gz": 48854,
"total": 148513,
"total_gz": 56986,
"total": 148523,
"total_gz": 56987,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_except.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 23315,
"a.out.js.gz": 9125,
"a.out.js": 23325,
"a.out.js.gz": 9127,
"a.out.nodebug.wasm": 171263,
"a.out.nodebug.wasm.gz": 57315,
"total": 194578,
"total_gz": 66440,
"total": 194588,
"total_gz": 66442,
"sent": [
"__cxa_begin_catch",
"__cxa_end_catch",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_except_wasm.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19470,
"a.out.js.gz": 8070,
"a.out.js": 19475,
"a.out.js.gz": 8072,
"a.out.nodebug.wasm": 144623,
"a.out.nodebug.wasm.gz": 54880,
"total": 164093,
"total_gz": 62950,
"total": 164098,
"total_gz": 62952,
"sent": [
"_abort_js",
"_tzset_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_except_wasm_legacy.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19539,
"a.out.js.gz": 8089,
"a.out.js": 19549,
"a.out.js.gz": 8091,
"a.out.nodebug.wasm": 142212,
"a.out.nodebug.wasm.gz": 54344,
"total": 161751,
"total_gz": 62433,
"total": 161761,
"total_gz": 62435,
"sent": [
"_abort_js",
"_tzset_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_lto.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 18993,
"a.out.js.gz": 7823,
"a.out.js": 19003,
"a.out.js.gz": 7825,
"a.out.nodebug.wasm": 106448,
"a.out.nodebug.wasm.gz": 42638,
"total": 125441,
"total_gz": 50461,
"total": 125451,
"total_gz": 50463,
"sent": [
"a (emscripten_resize_heap)",
"b (_setitimer_js)",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_mangle.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 23365,
"a.out.js.gz": 9145,
"a.out.js": 23375,
"a.out.js.gz": 9147,
"a.out.nodebug.wasm": 235290,
"a.out.nodebug.wasm.gz": 78917,
"total": 258655,
"total_gz": 88062,
"total": 258665,
"total_gz": 88064,
"sent": [
"__cxa_begin_catch",
"__cxa_end_catch",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_noexcept.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19654,
"a.out.js.gz": 8145,
"a.out.js": 19664,
"a.out.js.gz": 8146,
"a.out.nodebug.wasm": 131872,
"a.out.nodebug.wasm.gz": 50209,
"total": 151526,
"total_gz": 58354,
"total": 151536,
"total_gz": 58355,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_wasmfs.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 7043,
"a.out.js.gz": 3322,
"a.out.js": 7053,
"a.out.js.gz": 3325,
"a.out.nodebug.wasm": 170045,
"a.out.nodebug.wasm.gz": 62927,
"total": 177088,
"total_gz": 66249,
"total": 177098,
"total_gz": 66252,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
4 changes: 2 additions & 2 deletions test/codesize/test_codesize_file_preload.expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ var readAsync, readBinary;
if (ENVIRONMENT_IS_NODE) {
// These modules will usually be used on Node.js. Load them eagerly to avoid
// the complexity of lazy-loading.
var fs = require("fs");
var fs = require("node:fs");
scriptDirectory = __dirname + "/";
// include: node_shell_read.js
readBinary = filename => {
Expand Down Expand Up @@ -603,7 +603,7 @@ var PATH = {
var initRandomFill = () => {
// This block is not needed on v19+ since crypto.getRandomValues is builtin
if (ENVIRONMENT_IS_NODE) {
var nodeCrypto = require("crypto");
var nodeCrypto = require("node:crypto");
return view => nodeCrypto.randomFillSync(view);
}
return view => crypto.getRandomValues(view);
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_file_preload.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 22561,
"a.out.js.gz": 9336,
"a.out.js": 22571,
"a.out.js.gz": 9339,
"a.out.nodebug.wasm": 1681,
"a.out.nodebug.wasm.gz": 960,
"total": 24242,
"total_gz": 10296,
"total": 24252,
"total_gz": 10299,
"sent": [
"a (fd_write)"
],
Expand Down
Loading