require-in-the-middle
Advanced tools
Comparing version 5.1.0 to 5.2.0
43
index.js
@@ -11,12 +11,19 @@ 'use strict' | ||
const builtins = Module.builtinModules | ||
/** | ||
* Is the given module a "core" module? | ||
* https://nodejs.org/api/modules.html#core-modules | ||
* | ||
* @type {(moduleName: string) => boolean} | ||
*/ | ||
let isCore | ||
if (Module.isBuiltin) { // as of node v18.6.0 | ||
isCore = Module.isBuiltin | ||
} else { | ||
isCore = moduleName => { | ||
// Prefer `resolve.core` lookup to `resolve.isCore(moduleName)` because the | ||
// latter is doing version range matches for every call. | ||
return !!resolve.core[moduleName] | ||
} | ||
} | ||
const isCore = builtins | ||
? (filename) => builtins.includes(filename) | ||
// Fallback in case `builtins` isn't available in the current Node.js | ||
// version. This isn't as acurate, as some core modules contain slashes, but | ||
// all modern versions of Node.js supports `buildins`, so it shouldn't affect | ||
// many people. | ||
: (filename) => filename.includes(path.sep) === false | ||
// 'foo/bar.js' or 'foo/bar/index.js' => 'foo/bar' | ||
@@ -62,4 +69,18 @@ const normalize = /([/\\]index)?(\.js)?$/ | ||
const filename = Module._resolveFilename(id, this) | ||
const core = isCore(filename) | ||
const core = isCore(id) | ||
let filename // the string used for caching | ||
if (core) { | ||
filename = id | ||
// If this is a builtin module that can be identified both as 'foo' and | ||
// 'node:foo', then prefer 'foo' as the caching key. | ||
if (id.startsWith('node:')) { | ||
const idWithoutPrefix = id.slice(5) | ||
if (isCore(idWithoutPrefix)) { | ||
filename = idWithoutPrefix | ||
} | ||
} | ||
} else { | ||
filename = Module._resolveFilename(id, this) | ||
} | ||
let moduleName, basedir | ||
@@ -66,0 +87,0 @@ |
{ | ||
"name": "require-in-the-middle", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "Module to hook into the Node.js require function", | ||
@@ -9,3 +9,3 @@ "main": "index.js", | ||
"module-details-from-path": "^1.0.3", | ||
"resolve": "^1.12.0" | ||
"resolve": "^1.22.1" | ||
}, | ||
@@ -46,2 +46,3 @@ "devDependencies": { | ||
], | ||
"files": [], | ||
"author": "Thomas Watson Steen <w@tson.dk> (https://twitter.com/wa7son)", | ||
@@ -53,6 +54,5 @@ "license": "MIT", | ||
"homepage": "https://github.com/elastic/require-in-the-middle#readme", | ||
"coordinates": [ | ||
56.009779, | ||
11.962099 | ||
] | ||
"engines": { | ||
"node": ">=6" | ||
} | ||
} |
@@ -7,5 +7,5 @@ # require-in-the-middle | ||
[![npm](https://img.shields.io/npm/v/require-in-the-middle.svg)](https://www.npmjs.com/package/require-in-the-middle) | ||
[![Build status](https://travis-ci.org/elastic/require-in-the-middle.svg?branch=master)](https://travis-ci.org/elastic/require-in-the-middle) | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard) | ||
[![Test status](https://github.com/elastic/require-in-the-middle/workflows/Test/badge.svg)](https://github.com/elastic/require-in-the-middle/actions) | ||
## Installation | ||
@@ -12,0 +12,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12144
168
1
Updatedresolve@^1.22.1