Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@everymundo/cleanrequire

Package Overview
Dependencies
Maintainers
17
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@everymundo/cleanrequire - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

12

index.js
'use strict';
const path = require('path');
const firstMatchOrCWD = (firstMatch) =>
Array.isArray(firstMatch) ? path.dirname(firstMatch[2]) : process.cwd();
const cleanrequire = (libpath) => {
if (!/^[./]/.test(libpath)) return removeCacheAndLoad(libpath);
if (!/^\./.test(libpath)) return removeCacheAndLoad(libpath);

@@ -13,4 +16,7 @@ const

firstMatch = stack.substring(firstI, secndI).match(/\s+\(?(\/([^:]+):\d+)/),
libFile = '/' + path.join(path.dirname(firstMatch[2]), libpath);
// baseDir = firstMatch ? path.dirname(firstMatch[2]) : process.cwd();
baseDir = firstMatchOrCWD(firstMatch);
const libFile = '/' + path.join(baseDir, libpath).replace(/^\//, '');
return removeCacheAndLoad(libFile);

@@ -26,2 +32,4 @@ };

cleanrequire.firstMatchOrCWD = firstMatchOrCWD;
module.exports = cleanrequire;

2

package.json
{
"name": "@everymundo/cleanrequire",
"version": "1.1.0",
"version": "1.1.1",
"description": "Cleans nodejs require.cache for a given module and requires it again. Very useful for testing purposes.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -10,2 +10,13 @@ 'use strict';

describe('firstMatchOrCWD', () => {
it('shoud return Current Working Directory when input is not an Array', () => {
const { firstMatchOrCWD } = cleanrequire;
const res = firstMatchOrCWD(null);
const expected = process.cwd();
expect(res).to.equal(expected);
});
});
describe('require', () => {

@@ -12,0 +23,0 @@ it('require should cache and return cached version on the second call', (done) => {

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