Socket
Socket
Sign inDemoInstall

require-in-the-middle

Package Overview
Dependencies
Maintainers
3
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

require-in-the-middle - npm Package Compare versions

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc