File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 3
3
import assert from 'assert' ;
4
4
import fs from 'fs/promises' ;
5
5
import path from 'path' ;
6
- import { builtinModules } from 'module' ;
6
+ import module , { builtinModules } from 'module' ;
7
7
import picomatch from 'picomatch' ;
8
8
import { globSync } from 'tinyglobby' ;
9
9
@@ -76,10 +76,17 @@ const win32 = process.platform === 'win32';
76
76
77
77
/**
78
78
* Checks if a module is a core module
79
- * module.isBuiltin is available in Node.js 16.17.0 or later. Once we drop support for older
80
- * versions of Node.js, we can use module.isBuiltin instead of this function .
79
+ * module.isBuiltin is available in Node.js 16.17.0 or later. Use that if available
80
+ * as prefix-only modules (those starting with 'node:') can only be checked that way .
81
81
*/
82
82
function isBuiltin ( moduleName : string ) {
83
+ if (
84
+ Reflect . has ( module , 'isBuiltin' ) &&
85
+ typeof module . isBuiltin === 'function'
86
+ ) {
87
+ return module . isBuiltin ( moduleName ) ;
88
+ }
89
+
83
90
const moduleNameWithoutPrefix = moduleName . startsWith ( 'node:' )
84
91
? moduleName . slice ( 5 )
85
92
: moduleName ;
You can’t perform that action at this time.
0 commit comments