Skip to content

Commit

Permalink
Improve global require detection for path resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
niksy committed Nov 20, 2024
1 parent 26208c0 commit 4032e50
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ import pkgDir from 'pkg-dir';
* @param {string} path
*/
const resolvePath = (path) => {

Check warning on line 7 in index.js

View workflow job for this annotation

GitHub Actions / Test (10)

'path' is already declared in the upper scope on line 41 column 7

Check warning on line 7 in index.js

View workflow job for this annotation

GitHub Actions / Test (12)

'path' is already declared in the upper scope on line 41 column 7

Check warning on line 7 in index.js

View workflow job for this annotation

GitHub Actions / Test (16)

'path' is already declared in the upper scope on line 41 column 7
let _require = null;
let resolvedPath;
try {
_require = require;
resolvedPath = require.resolve(path);
} catch {
// Handled
resolvedPath = (
globalThis.require ?? createRequire(import.meta.url)
).resolve(path);
}
const resolvedPath = (
_require ??
globalThis.require ??
createRequire(import.meta.url)
).resolve(path);
if (!path.includes('./')) {
const directory = pkgDir.sync(resolvedPath) ?? '';
return directory;
Expand Down

0 comments on commit 4032e50

Please sign in to comment.