From 0d90db66a99a088ed66c438a90ba963fc766fa0d Mon Sep 17 00:00:00 2001 From: ehmicky Date: Fri, 28 Jan 2022 19:57:23 +0100 Subject: [PATCH] chore: use `createRequire()` for `require.resolve()` --- src/runtimes/node/bundlers/zisi/resolve.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/runtimes/node/bundlers/zisi/resolve.ts b/src/runtimes/node/bundlers/zisi/resolve.ts index 81c3a0073..dc398dcab 100644 --- a/src/runtimes/node/bundlers/zisi/resolve.ts +++ b/src/runtimes/node/bundlers/zisi/resolve.ts @@ -1,3 +1,4 @@ +import { createRequire } from 'module' import { version as nodeVersion } from 'process' import findUp from 'find-up' @@ -5,6 +6,8 @@ import pathExists from 'path-exists' import resolveLib from 'resolve' import { lt as ltVersion } from 'semver' +const requireLib = createRequire(__filename) + const BACKSLASH_REGEXP = /\\/g // Find the path to a module's `package.json` @@ -74,7 +77,7 @@ const resolvePathPreserveSymlinks = async function (path: string, baseDirs: stri } const resolvePathFollowSymlinks = function (path: string, baseDirs: string[]) { - return require.resolve(path, { paths: baseDirs }) + return requireLib.resolve(path, { paths: baseDirs }) } // `require.resolve()` on a module's specific file (like `package.json`)