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
2 changes: 1 addition & 1 deletion src/lib/libatomic.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,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 @@ -352,7 +352,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
4 changes: 2 additions & 2 deletions src/lib/libsockfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ addToLibrary({
var WebSocketConstructor;
#if ENVIRONMENT_MAY_BE_NODE
if (ENVIRONMENT_IS_NODE) {
WebSocketConstructor = /** @type{(typeof WebSocket)} */(require('ws'));
WebSocketConstructor = /** @type{(typeof WebSocket)} */(require('node:ws'));
} else
#endif // ENVIRONMENT_MAY_BE_NODE
{
Expand Down Expand Up @@ -503,7 +503,7 @@ addToLibrary({
if (sock.server) {
throw new FS.ErrnoError({{{ cDefs.EINVAL }}}); // already listening
}
var WebSocketServer = require('ws').Server;
var WebSocketServer = require('node:ws').Server;
var host = sock.saddr;
#if SOCKET_DEBUG
dbg(`websocket: listen: ${host}:${sock.sport}`);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libwasi.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,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
2 changes: 1 addition & 1 deletion src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,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/proxyClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#if ENVIRONMENT_MAY_BE_NODE
var ENVIRONMENT_IS_NODE = typeof process == 'object' && typeof process.versions == 'object' && typeof process.versions.node == 'string' && process.type != 'renderer';
if (ENVIRONMENT_IS_NODE) {
var NodeWorker = require('worker_threads').Worker;
var NodeWorker = require('node:worker_threads').Worker;
global.Worker = function(url, options) {
// Special handling for `data:` URL argument, to match the behaviour
// of the Web API.
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ if (ENVIRONMENT_IS_NODE) {
// depends on it for accurate timing.
// Use `global` rather than `globalThis` here since older versions of node
// don't have `globalThis`.
global.performance ??= require('perf_hooks').performance;
global.performance ??= require('node:perf_hooks').performance;
}
#endif
8 changes: 4 additions & 4 deletions src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,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 @@ -196,8 +196,8 @@ 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 nodePath = require('path');
var fs = require('node:fs');
var nodePath = require('node:path');

#if EXPORT_ES6
// EXPORT_ES6 + ENVIRONMENT_IS_NODE always requires use of import.meta.url,
Expand Down
4 changes: 2 additions & 2 deletions src/shell_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,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 @@ -167,7 +167,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 (typeof WebAssembly != 'undefined') Module['wasm'] = fs.readFileSync(__dirname + '/{{{ TARGET_BASENAME }}}.wasm');
else eval(fs.readFileSync(__dirname + '/{{{ TARGET_BASENAME }}}.wasm.js')+'');
Expand Down
6 changes: 3 additions & 3 deletions src/wasm_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var ENVIRONMENT_IS_NODE = typeof process == 'object' && typeof process.versions
if (ENVIRONMENT_IS_NODE) {
// Create as web-worker-like an environment as we can.

var nodeWorkerThreads = require('worker_threads');
var nodeWorkerThreads = require('node:worker_threads');

var parentPort = nodeWorkerThreads.parentPort;

Expand All @@ -28,8 +28,8 @@ if (ENVIRONMENT_IS_NODE) {
return f;
}

var fs = require('fs');
var vm = require('vm');
var fs = require('node:fs');
var vm = require('node:vm');

Object.assign(global, {
self: global,
Expand Down
4 changes: 2 additions & 2 deletions tools/file_packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ def generate_js(data_target, data_files, metadata):
if options.support_node:
node_support_code = '''
if (isNode) {
require('fs').readFile(packageName, (err, contents) => {
require('node:fs').readFile(packageName, (err, contents) => {
if (err) {
errback(err);
} else {
Expand Down Expand Up @@ -1108,7 +1108,7 @@ def generate_js(data_target, data_files, metadata):
if options.support_node:
node_support_code = '''
if (isNode) {
require('fs').readFile(metadataUrl, 'utf8', (err, contents) => {
require('node:fs').readFile(metadataUrl, 'utf8', (err, contents) => {
if (err) {
return Promise.reject(err);
} else {
Expand Down
4 changes: 2 additions & 2 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -2361,9 +2361,9 @@ def node_pthread_detection():
# Under node we detect that we are running in a pthread by checking the
# workerData property.
if settings.EXPORT_ES6:
return "(await import('worker_threads')).workerData === 'em-pthread';\n"
return "(await import('node:worker_threads')).workerData === 'em-pthread';\n"
else:
return "require('worker_threads').workerData === 'em-pthread'\n"
return "require('node:worker_threads').workerData === 'em-pthread'\n"


def modularize():
Expand Down