Browse Source

Revert to using mock-require but return require instead of wrapping in fn

pull/2/head
Luke Childs 8 years ago
parent
commit
a9f3fd2d8b
  1. 3
      package.json
  2. 5
      src/index.js

3
package.json

@ -30,7 +30,8 @@
}, },
"homepage": "https://github.com/lukechilds/requireable", "homepage": "https://github.com/lukechilds/requireable",
"dependencies": { "dependencies": {
"find-root": "^1.1.0" "find-root": "^1.1.0",
"mock-require": "^2.0.2"
}, },
"devDependencies": { "devDependencies": {
"ava": "^0.19.1", "ava": "^0.19.1",

5
src/index.js

@ -1,15 +1,14 @@
'use strict'; 'use strict';
const Module = require('module');
const findRoot = require('find-root'); const findRoot = require('find-root');
const mock = require('mock-require');
const pkg = { success: false }; const pkg = { success: false };
try { try {
pkg.path = findRoot(process.cwd()); pkg.path = findRoot(process.cwd());
pkg.name = require(pkg.path + '/package.json').name; pkg.name = require(pkg.path + '/package.json').name;
const origRequire = Module.prototype.require; mock(pkg.name, require(pkg.path));
Module.prototype.require = pkgName => pkgName === pkg.name ? origRequire(pkg.path) : origRequire(pkgName);
pkg.success = true; pkg.success = true;
} catch (err) {} } catch (err) {}

Loading…
Cancel
Save