2018-08-31 18:21:41 +00:00
|
|
|
/*
|
|
|
|
** Core logic from https://github.com/sindresorhus/builtin-modules
|
|
|
|
** Many thanks to @sindresorhus
|
|
|
|
*/
|
2018-10-17 21:28:25 +00:00
|
|
|
import Module from 'module'
|
2018-08-31 18:21:41 +00:00
|
|
|
|
|
|
|
const blacklist = [
|
|
|
|
'sys'
|
|
|
|
]
|
|
|
|
|
2018-10-17 21:28:25 +00:00
|
|
|
export const builtins = (Module.builtinModules || Object.keys(process.binding('natives')))
|
2018-08-31 18:21:41 +00:00
|
|
|
.filter(x => !/^_|^(internal|v8|node-inspect)\/|\//.test(x) && !blacklist.includes(x))
|
|
|
|
.sort()
|
|
|
|
|
|
|
|
let builtinsObj = null
|
|
|
|
|
|
|
|
const convertToObj = () => builtins.reduce((obj, builtin) => {
|
|
|
|
obj[builtin] = true
|
|
|
|
return obj
|
|
|
|
}, (builtinsObj = {}))
|
|
|
|
|
|
|
|
export const builtinsMap = () => builtinsObj || convertToObj()
|