Skip to content
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

Closed
zkat opened this issue Oct 9, 2015 · 28 comments
Closed

Expose up-to-date list of builtin modules #3307

zkat opened this issue Oct 9, 2015 · 28 comments
Assignees
Labels
feature request Issues that request new features to be added to Node.js. help wanted Issues that need assistance from volunteers or PRs that need help to proceed.

Comments

@zkat
Copy link
Contributor

zkat commented Oct 9, 2015

npm's normalize-package-data needs a list of built in node modules in order to warn against potential package name conflicts (see fixNameField.

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

@mscdex mscdex added the feature request Issues that request new features to be added to Node.js. label Oct 9, 2015
@Fishrock123
Copy link
Contributor

Fwiw is-builtin-module uses the builtin-modules module, whose source code is as follows:

'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: Object.keys(process.binding('natives')) will stop working in the future.

See:

About the first, process.binding('natives') returns data (the whole damn source code) which cannot be guaranteed not to change. As such we're going to be moving away from it pretty much asap.

@Fishrock123
Copy link
Contributor

I suggest we have an API that exposes a list of core module names only.

@piranna
Copy link
Contributor

piranna commented Oct 10, 2015

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...

@sindresorhus
Copy link

👍 As illustrated, doing this in user-land is brittle.

@ChALkeR
Copy link
Member

ChALkeR commented Oct 20, 2015

See also: #3078 (comment) and ayecue/node-cjs-deps@b3ea440.

We might want to provide a way to expose a list of _prefixed (but not internal) module names.
For example, require('module').builtinModules for the normal list and require('module')._builtinModules for the full list that includes both normal and _prefixed builtin module names.

And yes, names only.

Note: per doc, this should not be put into the module module, it's Frozen. We need a different place I guess.

@ChALkeR
Copy link
Member

ChALkeR commented Oct 20, 2015

cc @Trott

@trevnorris
Copy link
Contributor

Ref: #2180

NM. Different list.

@Fishrock123
Copy link
Contributor

@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.

@sindresorhus
Copy link

Also, should it list internal modules too, or should that be something separate?

Only public modules. If there's a need for a list of internal modules, it should be a separate thing.

@ChALkeR
Copy link
Member

ChALkeR commented Oct 20, 2015

@Fishrock123 Internal or prefixed? Could you give an example, please?

@Fishrock123
Copy link
Contributor

Only public modules. If there's a need for a list of internal modules, it should be a separate thing.

Makes sense, I was thinking along these lines too.

@ChALkeR I meant /internal/. Prefixed modules would appear in the regular one as they are potential module name conflicts.

@hemanth
Copy link
Contributor

hemanth commented Oct 28, 2015

There is all-builtins as well.

@Trott
Copy link
Member

Trott commented Oct 28, 2015

@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 console, constants, module, process, repl, timers and the deprecated modules sys and freelist.

@hemanth
Copy link
Contributor

hemanth commented Oct 29, 2015

@Trott Right, we need to work on process.binding('natives') then.

@ChALkeR
Copy link
Member

ChALkeR commented Oct 29, 2015

@hemanth No, we need to deprecate process.binding('natives') and provide just the list instead.

@hemanth
Copy link
Contributor

hemanth commented Oct 29, 2015

@ChALkeR That's the best thing to happen, but in the current situation.

@vkurchatkin
Copy link
Contributor

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;
   }
}

@piranna
Copy link
Contributor

piranna commented Feb 18, 2016

That's genious :-) Good trick! :-D
El 18/2/2016 15:01, "Vladimir Kurchatkin" notifications@github.com
escribió:

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;
}
}


Reply to this email directly or view it on GitHub
#3307 (comment).

@hemanth
Copy link
Contributor

hemanth commented Feb 20, 2016

@vkurchatkin
Copy link
Contributor

closing, doable using existing APIs

@Fishrock123
Copy link
Contributor

Reopening from #6207 (comment)

@Fishrock123 Fishrock123 reopened this Apr 15, 2016
@ChALkeR
Copy link
Member

ChALkeR commented Aug 26, 2016

@vkurchatkin

closing, doable using existing APIs

That is not accurate. That API does exist, but it's not documented, and is-builtin uses an undocumented _-prefixed property.
See https://github.com/hemanth/node-is-builtin/blob/master/index.js.

Perhaps we should just expose that exact property and document it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. help wanted Issues that need assistance from volunteers or PRs that need help to proceed.
Projects
None yet
Development

No branches or pull requests