function createPerformantResolve() {
  /**
   * @param {string} filepath
   */
  const readPackageWithout = (filepath) => {
    /**
     * @param {(path: string) => StringOrToString} readFileSync - Sync file
     *   reader
     * @param {string} otherFilepath - Path to another `package.json`
     * @returns {Record<string, unknown> | undefined}
     */
    return (readFileSync, otherFilepath) => {
      // avoid loading the package.json we're just trying to resolve
      if (otherFilepath.endsWith(filepath)) {
        return {}
      }
      // original readPackageSync implementation from resolve internals:
      const body = readFileSync(otherFilepath)
      try {
        return JSON.parse(`${body}`)
      } catch (jsonErr) {}
    }
  }

  return {
    sync: (path, { basedir }) =>
      nodeResolve(path, {
        basedir,
        readPackageSync: readPackageWithout(path),
      }),
  }
}
Performant resolve avoids loading package.jsons if their path is what's being
resolved, offering 2x performance improvement compared to using original
resolve

This resolver, using the `resolve` package, is incompatible with subpath
exports.

@returns {Resolver}
@see {@link https://npm.im/resolve}
@see {@link https://nodejs.org/api/packages.html#subpath-exports}