Skip to content

Commit d088ead

Browse files
committed
Prefix node built-in module imports with node:.
This makes the imports diistinguishable from the corresponding `npm` packages, which can help with: - Development ergonomics: - Marking all `node:*` packages as external in a bundler. - Tracking the dependency graph - Supply chain security (avoiding risks from name squatting). The `node:` protocol prefix is supported in LTS versions all the way back to `node` 12: https://nodejs.org/api/esm.html#node-imports
1 parent 2e02d0e commit d088ead

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

emcc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3704,7 +3704,7 @@ def node_es6_imports():
37043704

37053705
# Use static import declaration if we only target Node.js
37063706
return '''
3707-
import { createRequire } from 'module';
3707+
import { createRequire } from 'node:module';
37083708
const require = createRequire(import.meta.url);
37093709
'''
37103710

src/shell.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,14 @@ if (ENVIRONMENT_IS_NODE) {
194194
// builds, `-sENVIRONMENT=node` emits a static import declaration instead.
195195
// TODO: Swap all `require()`'s with `import()`'s?
196196
#if EXPORT_ES6 && ENVIRONMENT_MAY_BE_WEB
197-
const { createRequire } = await import('module');
197+
const { createRequire } = await import('node:module');
198198
/** @suppress{duplicate} */
199199
var require = createRequire(import.meta.url);
200200
#endif
201201
// These modules will usually be used on Node.js. Load them eagerly to avoid
202202
// the complexity of lazy-loading.
203-
var fs = require('fs');
204-
var nodePath = require('path');
203+
var fs = require('node:fs');
204+
var nodePath = require('node:path');
205205

206206
if (ENVIRONMENT_IS_WORKER) {
207207
scriptDirectory = nodePath.dirname(scriptDirectory) + '/';
@@ -210,7 +210,7 @@ if (ENVIRONMENT_IS_NODE) {
210210
// EXPORT_ES6 + ENVIRONMENT_IS_NODE always requires use of import.meta.url,
211211
// since there's no way getting the current absolute path of the module when
212212
// support for that is not available.
213-
scriptDirectory = require('url').fileURLToPath(new URL('./', import.meta.url)); // includes trailing slash
213+
scriptDirectory = require('node:url').fileURLToPath(new URL('./', import.meta.url)); // includes trailing slash
214214
#else
215215
scriptDirectory = __dirname + '/';
216216
#endif
@@ -264,7 +264,7 @@ if (ENVIRONMENT_IS_NODE) {
264264
#if USE_PTHREADS
265265
let nodeWorkerThreads;
266266
try {
267-
nodeWorkerThreads = require('worker_threads');
267+
nodeWorkerThreads = require('node:worker_threads');
268268
} catch (e) {
269269
console.error('The "worker_threads" module is not supported in this node.js build - perhaps a newer version is needed?');
270270
throw e;
@@ -426,7 +426,7 @@ if (ENVIRONMENT_IS_NODE) {
426426
// Polyfill the performance object, which emscripten pthreads support
427427
// depends on for good timing.
428428
if (typeof performance == 'undefined') {
429-
global.performance = require('perf_hooks').performance;
429+
global.performance = require('node:perf_hooks').performance;
430430
}
431431
}
432432

0 commit comments

Comments
 (0)