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.0.0 to 1.1.0

12

index.js

@@ -5,2 +5,4 @@ 'use strict';

const cleanrequire = (libpath) => {
if (!/^[./]/.test(libpath)) return removeCacheAndLoad(libpath);
const

@@ -14,6 +16,12 @@ err = new Error(''),

delete require.cache[require.resolve(libFile)];
return require(libFile);
return removeCacheAndLoad(libFile);
};
const removeCacheAndLoad = (libFile) => {
const resolved = require.resolve(libFile);
if (resolved in require.cache) delete require.cache[resolved];
return require(resolved);
};
module.exports = cleanrequire;

4

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

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

"istanbul": "^0.4.5",
"mocha": "^5.0.0"
"mocha": "^5.0.1"
}
}

@@ -11,4 +11,4 @@ 'use strict';

describe('require', () => {
it('require should cache and return cached version on a second call', (done) => {
const datetimeA = require('./resources/datetime');
it('require should cache and return cached version on the second call', (done) => {
const datetimeA = cleanrequire('./resources/datetime');
setTimeout(() => {

@@ -23,10 +23,25 @@ const datetimeB = require('./resources/datetime');

describe('cleanrequire', () => {
it('cleanrequire should return a NON CACHED version on a second call', (done) => {
const datetimeA = require('./resources/datetime');
setTimeout(() => {
const datetimeB = cleanrequire('./resources/datetime');
expect(datetimeA).to.not.equal(datetimeB);
done();
}, 10);
context('When loading a relative file', () => {
it('cleanrequire should return a NON CACHED version on the second call', (done) => {
const datetimeA = require('./resources/datetime');
setTimeout(() => {
const datetimeB = cleanrequire('./resources/datetime');
expect(datetimeA).to.not.equal(datetimeB);
done();
}, 10);
});
});
context('When loading a library from node_modules', () => {
it('cleanrequire should return a NON CACHED version on the second call', (done) => {
const chaiA = require('istanbul');
setTimeout(() => {
const chaiB = cleanrequire('istanbul');
expect(chaiA).to.deep.equal(chaiB);
expect(chaiA).to.not.equal(chaiB);
done();
}, 10);
});
});
});
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