@everymundo/cleanrequire
Advanced tools
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; |
{ | ||
"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) => { |
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
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
6132
71