From 43bab2087123dd105235bee9e4d99a84fa179bd3 Mon Sep 17 00:00:00 2001 From: Superchupu <53496941+SuperchupuDev@users.noreply.github.com> Date: Tue, 25 Jun 2024 17:39:51 +0100 Subject: [PATCH] deps: replace `is-core-module` with node builtin (#224) This PR replaces usage of `is-core-module` with node's built-in `module.builtinModules`, which was added in node 9.3.0, 8.10.0, and 6.13.0. My plan was to use `module.isBuiltin` but that would be a breaking change as it got added in node 16.17.0 and 18.6.0. Maybe once older node versions get dropped :P. This makes `normalize-package-data` use 3 less dependencies, bringing down the total count to 8. The only difference this *could* have is that `builtinModules` do not include `node:` builtins, but it doesn't affect this library as names prefixed by `node:` already throw as they are not valid names. Packages such as `is-core-module`'s dependencies are only there for support with *ancient* node versions (>=0.4) and as such have *many* polyfills, including one that literally emulates hasOwnProperty, and overall end up cluttering the whole javascript ecosystem. Since this package includes an engines field of `^16.14.0 || >=18.0.0`, there's no real reason in using it over a built-in. `is-core-module` in particular does have its own use case (checking the list of built-ins of a certain node version other than the current one), but its use in this library can be replicated by `module.builtinModules` ## References https://nodejs.org/api/module.html#modulebuiltinmodules --------- Co-authored-by: Gar --- lib/fixer.js | 4 ++-- package.json | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/fixer.js b/lib/fixer.js index 9a1ccc9..1c30cad 100644 --- a/lib/fixer.js +++ b/lib/fixer.js @@ -2,7 +2,7 @@ var isValidSemver = require('semver/functions/valid') var cleanSemver = require('semver/functions/clean') var validateLicense = require('validate-npm-package-license') var hostedGitInfo = require('hosted-git-info') -var isBuiltinModule = require('is-core-module') +var moduleBuiltin = require('node:module') var depTypes = ['dependencies', 'devDependencies', 'optionalDependencies'] var extractDescription = require('./extract_description') var url = require('url') @@ -231,7 +231,7 @@ module.exports = { data.name = data.name.trim() } ensureValidName(data.name, strict, options.allowLegacyCase) - if (isBuiltinModule(data.name)) { + if (moduleBuiltin.builtinModules.includes(data.name)) { this.warn('conflictingName', data.name) } }, diff --git a/package.json b/package.json index 7fc803f..93ea2f7 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ }, "dependencies": { "hosted-git-info": "^7.0.0", - "is-core-module": "^2.8.1", "semver": "^7.3.5", "validate-npm-package-license": "^3.0.4" },