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

is-core-module #72

Open
AbhiPrasad opened this issue Jul 1, 2024 · 2 comments
Open

is-core-module #72

AbhiPrasad opened this issue Jul 1, 2024 · 2 comments

Comments

@AbhiPrasad
Copy link
Contributor

AbhiPrasad commented Jul 1, 2024

https://www.npmjs.com/package/is-core-module

ref: #58 (comment)

You can do something like so:

import module from 'node:module';

function isCoreModule(moduleName): boolean {
  if (moduleName.startsWith('node:') {
    return true;
  }

  // requires v18.6.0, v16.17.0
  if (module.isBuiltin(moduleName)) {
    return true;
  }

  // if using Node.js older than 16.17
  // use: module.builtinModules.includes(moduleName)

  return false;
}

We should prob add https://www.npmjs.com/package/is-builtin-module and https://github.com/sindresorhus/builtin-modules to the list as well (although those packages do make it pretty clear in the README to use the Node.js API if possible).

@43081j
Copy link
Contributor

43081j commented Jul 1, 2024

we already have is-builtin-module here:
https://github.com/es-tooling/module-replacements/blob/main/docs/modules/is-builtin-module.md?plain=1

if this provides the same functionality, we should probably just add an entry to the preferred manifest pointing at the same doc

@AbhiPrasad
Copy link
Contributor Author

I can't believe I missed is-builtin-module 😭

Let me make a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants