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

@everymundo/cleanrequire

Package Overview
Dependencies
Maintainers
23
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.1 to 1.2.0

17

index.js

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

const os = require('os');
const prependSlash = (str) => {
if (os.platform() === 'win32') return str;
return `/${str}`;
};
const cleanrequire = (libpath) => {

@@ -16,7 +24,8 @@ if (!/^\./.test(libpath)) return removeCacheAndLoad(libpath);

secndI = (stack + '\n').indexOf('\n', firstI + 1),
firstMatch = stack.substring(firstI, secndI).match(/\s+\(?(\/([^:]+):\d+)/),
line = stack.substring(firstI, secndI),
firstMatch = line.match(/\s+\(?((?:\/|\w:)([^:]+):\d+)/),
// baseDir = firstMatch ? path.dirname(firstMatch[2]) : process.cwd();
baseDir = firstMatchOrCWD(firstMatch);
const libFile = '/' + path.join(baseDir, libpath).replace(/^\//, '');
const libFile = prependSlash(path.join(baseDir, libpath).replace(/^\//, ''));

@@ -34,3 +43,5 @@ return removeCacheAndLoad(libFile);

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

5

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

@@ -27,4 +27,5 @@ "main": "index.js",

"istanbul": "^0.4.5",
"mocha": "^5.0.1"
"mocha": "^5.2.0",
"sinon": "^6.2.0"
}
}

@@ -8,2 +8,3 @@ 'use strict';

{ expect } = require('chai'),
sinon = require('sinon'),
cleanrequire = require('../');

@@ -22,2 +23,36 @@

describe('prependSlash', () => {
context('NOT running on windows', () => {
it('shoud return a string prepended by a slash', () => {
const { prependSlash } = cleanrequire;
const input = 'C:\\path\\another-path';
const expected = `/${input}`;
const res = prependSlash(input);
expect(res).to.equal(expected);
});
});
context('running on windows', () => {
const os = require('os');
beforeEach(() => {
sinon.stub(os, 'platform').callsFake(() => 'win32');
});
afterEach(() => {
os.platform.restore();
});
it('shoud return the exact same string without prepending the slash', () => {
const { prependSlash } = cleanrequire;
const input = 'C:\\path\\another-path';
const res = prependSlash(input);
expect(res).to.equal(input);
});
});
});
describe('require', () => {

@@ -24,0 +59,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