-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose up-to-date list of builtin modules #3307
Comments
Fwiw 'use strict';
var blacklist = [
'freelist',
'sys'
];
module.exports = Object.keys(process.binding('natives')).filter(function (el) {
return !/^_|^internal/.test(el) && blacklist.indexOf(el) === -1;
}).sort(); Specifically, this bit: See:
About the first, |
I suggest we have an API that exposes a list of core module names only. |
On NodeOS we were thinking about moving out all build-in modules to reduce the size of the binary and it's memory foot print, I think this could be really useful... |
👍 As illustrated, doing this in user-land is brittle. |
See also: #3078 (comment) and ayecue/node-cjs-deps@b3ea440. We might want to provide a way to expose a list of And yes, names only. Note: per doc, this should not be put into the |
cc @Trott |
NM. Different list. |
@trevnorris that's not quite the same though, is it? Also, should it list internal modules too, or should that be something separate? I've noticed some things, such as debuggers, apparently rely on knowing what internal modules there are, which is weird. I'd prefer someone to give a solid reason why first. |
Only public modules. If there's a need for a list of internal modules, it should be a separate thing. |
@Fishrock123 Internal or prefixed? Could you give an example, please? |
Makes sense, I was thinking along these lines too. @ChALkeR I meant |
There is all-builtins as well. |
@hemanth That looks like it lists all the modules that are automatically loaded by the REPL, but not all the built-ins available in Node. It misses |
@Trott Right, we need to work on |
@hemanth No, we need to deprecate |
@ChALkeR That's the best thing to happen, but in the current situation. |
Here is a simple way to check if module is built-in using only public APIs: function isBuiltin(module) {
try {
const resolved = require.resolve(module);
return !resolved.includes(require('path').sep);
} catch(e) {
return false;
}
} |
That's genious :-) Good trick! :-D
|
closing, doable using existing APIs |
Reopening from #6207 (comment) |
That is not accurate. That API does exist, but it's not documented, and Perhaps we should just expose that exact property and document it? |
npm's
normalize-package-data
needs a list of built in node modules in order to warn against potential package name conflicts (seefixNameField
.We used to have the list hardcoded, and then @sindresorhus was kind enough to author an external package that would maintain such a list,
is-builtin-module
.It seems that this list is best maintained by node itself, since there's always a risk of things going out of sync or being just plain wrong. Would it be possible to expose this directly through some built-in value in node?
Ref: https://github.com/nodejs/node/pull/3299/files#r41686776
cc @Fishrock123
The text was updated successfully, but these errors were encountered: