Skip to content

Commit

Permalink
Improve the logic for finding the calling module
Browse files Browse the repository at this point in the history
The `parent-module` package has better logic for this.
  • Loading branch information
sindresorhus committed Dec 25, 2018
1 parent db00a4e commit 2010f5c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';
const path = require('path');
const resolveFrom = require('resolve-from');
const callerPath = require('caller-path');
const parentModule = require('parent-module');

module.exports = moduleId => {
if (typeof moduleId !== 'string') {
throw new TypeError('Expected a string');
}

const filePath = resolveFrom(path.dirname(callerPath()), moduleId);
const filePath = resolveFrom(path.dirname(parentModule(__filename)), moduleId);

// Delete itself from module parent
if (require.cache[filePath] && require.cache[filePath].parent) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
"bypass"
],
"dependencies": {
"caller-path": "^2.0.0",
"parent-module": "^1.0.0",
"resolve-from": "^3.0.0"
},
"devDependencies": {
"ava": "*",
"ava": "^0.25.0",
"optional-dev-dependency": "^2.0.1",
"xo": "^0.18.2"
},
Expand Down

0 comments on commit 2010f5c

Please sign in to comment.