Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1293,5 +1293,10 @@ Module.syncBuiltinESMExports = function syncBuiltinESMExports() {
}
};

Module.isBuiltIn = function isBuiltIn(moduleName) {
moduleName = String(moduleName).replace('node:', '');
return Module.builtinModules.includes(moduleName);
};

// Backwards compatibility
Module.Module = Module;
13 changes: 13 additions & 0 deletions test/parallel/test-module-isBuiltIn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';
require('../common');
const assert = require('assert');
const { isBuiltIn } = require('module');

// Includes modules in lib/ (even deprecated ones)
assert(isBuiltIn('http'));
assert(isBuiltIn('sys'));

// Does not include internal modules
assert(!isBuiltIn('internal'));
assert(!isBuiltIn(''));
assert(!isBuiltIn(undefined));