Skip to content

Commit

Permalink
fix: use createRequire() for require.resolve() (#986)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Feb 8, 2022
1 parent f229016 commit a941003
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/runtimes/node/bundlers/zisi/resolve.ts
@@ -1,10 +1,13 @@
import { createRequire } from 'module'
import { version as nodeVersion } from 'process'

import findUp from 'find-up'
import pathExists from 'path-exists'
import resolveLib from 'resolve'
import semver from 'semver'

const requireLib = createRequire(__filename)

const BACKSLASH_REGEXP = /\\/g

// Find the path to a module's `package.json`
Expand Down Expand Up @@ -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`)
Expand Down

1 comment on commit a941003

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱ Benchmark results

largeDepsEsbuild: 9.7s

largeDepsNft: 45.9s

largeDepsZisi: 1m 17.4s

Please sign in to comment.