Skip to content
This repository was archived by the owner on May 22, 2024. It is now read-only.

Commit a941003

Browse files
authoredFeb 8, 2022
fix: use createRequire() for require.resolve() (#986)
1 parent f229016 commit a941003

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed
 

‎src/runtimes/node/bundlers/zisi/resolve.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import { createRequire } from 'module'
12
import { version as nodeVersion } from 'process'
23

34
import findUp from 'find-up'
45
import pathExists from 'path-exists'
56
import resolveLib from 'resolve'
67
import semver from 'semver'
78

9+
const requireLib = createRequire(__filename)
10+
811
const BACKSLASH_REGEXP = /\\/g
912

1013
// Find the path to a module's `package.json`
@@ -74,7 +77,7 @@ const resolvePathPreserveSymlinks = async function (path: string, baseDirs: stri
7477
}
7578

7679
const resolvePathFollowSymlinks = function (path: string, baseDirs: string[]) {
77-
return require.resolve(path, { paths: baseDirs })
80+
return requireLib.resolve(path, { paths: baseDirs })
7881
}
7982

8083
// `require.resolve()` on a module's specific file (like `package.json`)

1 commit comments

Comments
 (1)

github-actions[bot] commented on Feb 8, 2022

@github-actions[bot]
Contributor

⏱ Benchmark results

largeDepsEsbuild: 9.7s

largeDepsNft: 45.9s

largeDepsZisi: 1m 17.4s

This repository has been archived.