{"name":"resolve","version":"1.22.11","keywords":["resolve","require","node","module"],"author":{"url":"http://substack.net","name":"James Halliday","email":"mail@substack.net"},"license":"MIT","_id":"resolve@1.22.11","maintainers":[{"name":"ljharb","email":"ljharb@gmail.com"}],"homepage":"https://github.com/browserify/resolve#readme","bugs":{"url":"https://github.com/browserify/resolve/issues"},"bin":{"resolve":"bin/resolve"},"dist":{"shasum":"aad857ce1ffb8bfa9b0b1ac29f1156383f68c262","tarball":"http://registry-npm.ywwl.com/resolve/download/resolve-1.22.11.tgz","fileCount":99,"integrity":"sha512-RfqAvLnMl313r7c9oclB1HhUEAezcpLjz95wFH4LVuhk9JF/r22qmVP9AMmOU4vMX7Q8pN8jwNg/CSpdFnMjTQ==","signatures":[{"sig":"MEQCIGVfGpVt7hsMypJow0f/xJVuQ+ctzfrOuGvQUJfUFM+fAiBu1GsO1V21Zz+llWu6dd9Xxnx5oOmDL88cja3WavNvNQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":154172,"size":30870,"noattachment":false,"key":"/resolve/-/resolve-1.22.11.tgz"},"main":"index.js","engines":{"node":">= 0.4"},"funding":{"url":"https://github.com/sponsors/ljharb"},"gitHead":"f24742ccc61eb20fadd50c3481321dfcdf95d77a","scripts":{"lint":"eslint --ext=js,mjs --no-eslintrc -c .eslintrc . 'bin/**'","test":"npm run --silent tests-only","prelint":"eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git')","prepack":"npmignore --auto --commentLines=autogenerated && cp node_modules/is-core-module/core.json ./lib/ ||:","pretest":"npm run lint","posttest":"npm run test:multirepo && npx npm@'>= 10.2' audit --production","prepublish":"not-in-publish || npm run prepublishOnly","tests-only":"tape test/*.js","pretests-only":"cd ./test/resolver/nested_symlinks && node mylib/sync && node mylib/async","prepublishOnly":"safe-publish-latest","test:multirepo":"cd ./test/resolver/multirepo && npm install && npm test"},"_npmUser":{"name":"ljharb","email":"ljharb@gmail.com"},"repository":{"url":"git+ssh://git@github.com/browserify/resolve.git","type":"git"},"_npmVersion":"11.6.2","description":"resolve like require.resolve() on behalf of files asynchronously and synchronously","directories":{},"_nodeVersion":"25.0.0","dependencies":{"path-parse":"^1.0.7","is-core-module":"^2.16.1","supports-preserve-symlinks-flag":"^1.0.0"},"publishConfig":{"ignore":[".github/workflows","appveyor.yml","test/resolver/malformed_package_json","test/list-exports"]},"_hasShrinkwrap":false,"devDependencies":{"mv":"^2.1.1","tap":"0.4.13","tmp":"^0.0.31","tape":"^5.9.0","eclint":"^2.8.1","eslint":"=8.8.0","mkdirp":"^0.5.5","rimraf":"^2.7.1","semver":"^6.3.1","copy-dir":"^1.3.0","npmignore":"^0.3.1","in-publish":"^2.0.1","object-keys":"^1.1.1","array.prototype.map":"^1.0.8","safe-publish-latest":"^2.0.0","@ljharb/eslint-config":"^21.2.0"},"_npmOperationalInternal":{"tmp":"tmp/resolve_1.22.11_1760993081536_0.23209454086533832","host":"s3://npm-registry-packages-npm-production"},"readme":"# resolve <sup>[![Version Badge][2]][1]</sup>\n\nimplements the [node `require.resolve()` algorithm](https://nodejs.org/api/modules.html#modules_all_together) such that you can `require.resolve()` on behalf of a file asynchronously and synchronously\n\n[![github actions][actions-image]][actions-url]\n[![coverage][codecov-image]][codecov-url]\n[![License][license-image]][license-url]\n[![Downloads][downloads-image]][downloads-url]\n[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/10759/badge)](https://bestpractices.coreinfrastructure.org/projects/10759)\n\n[![npm badge][11]][1]\n\n# example\n\nasynchronously resolve:\n\n```js\nvar resolve = require('resolve/async'); // or, require('resolve')\nresolve('tap', { basedir: __dirname }, function (err, res) {\n    if (err) console.error(err);\n    else console.log(res);\n});\n```\n\n```\n$ node example/async.js\n/home/substack/projects/node-resolve/node_modules/tap/lib/main.js\n```\n\nsynchronously resolve:\n\n```js\nvar resolve = require('resolve/sync'); // or, `require('resolve').sync\nvar res = resolve('tap', { basedir: __dirname });\nconsole.log(res);\n```\n\n```\n$ node example/sync.js\n/home/substack/projects/node-resolve/node_modules/tap/lib/main.js\n```\n\n# methods\n\n```js\nvar resolve = require('resolve');\nvar async = require('resolve/async');\nvar sync = require('resolve/sync');\n```\n\nFor both the synchronous and asynchronous methods, errors may have any of the following `err.code` values:\n\n- `MODULE_NOT_FOUND`: the given path string (`id`) could not be resolved to a module\n- `INVALID_BASEDIR`: the specified `opts.basedir` doesn't exist, or is not a directory\n- `INVALID_PACKAGE_MAIN`: a `package.json` was encountered with an invalid `main` property (eg. not a string)\n\n## resolve(id, opts={}, cb)\n\nAsynchronously resolve the module path string `id` into `cb(err, res [, pkg])`, where `pkg` (if defined) is the data from `package.json`.\n\noptions are:\n\n* opts.basedir - directory to begin resolving from\n\n* opts.package - `package.json` data applicable to the module being loaded\n\n* opts.extensions - array of file extensions to search in order\n\n* opts.includeCoreModules - set to `false` to exclude node core modules (e.g. `fs`) from the search\n\n* opts.readFile - how to read files asynchronously\n\n* opts.isFile - function to asynchronously test whether a file exists\n\n* opts.isDirectory - function to asynchronously test whether a file exists and is a directory\n\n* opts.realpath - function to asynchronously resolve a potential symlink to its real path\n\n* `opts.readPackage(readFile, pkgfile, cb)` - function to asynchronously read and parse a package.json file\n  * readFile - the passed `opts.readFile` or `fs.readFile` if not specified\n  * pkgfile - path to package.json\n  * cb - callback\n\n* `opts.packageFilter(pkg, pkgfile, dir)` - transform the parsed package.json contents before looking at the \"main\" field\n  * pkg - package data\n  * pkgfile - path to package.json\n  * dir - directory that contains package.json\n\n* `opts.pathFilter(pkg, path, relativePath)` - transform a path within a package\n  * pkg - package data\n  * path - the path being resolved\n  * relativePath - the path relative from the package.json location\n  * returns - a relative path that will be joined from the package.json location\n\n* opts.paths - require.paths array to use if nothing is found on the normal `node_modules` recursive walk (probably don't use this)\n\n  For advanced users, `paths` can also be a `opts.paths(request, start, opts)` function\n    * request - the import specifier being resolved\n    * start - lookup path\n    * getNodeModulesDirs - a thunk (no-argument function) that returns the paths using standard `node_modules` resolution\n    * opts - the resolution options\n\n* `opts.packageIterator(request, start, opts)` - return the list of candidate paths where the packages sources may be found (probably don't use this)\n    * request - the import specifier being resolved\n    * start - lookup path\n    * getPackageCandidates - a thunk (no-argument function) that returns the paths using standard `node_modules` resolution\n    * opts - the resolution options\n\n* opts.moduleDirectory - directory (or directories) in which to recursively look for modules. default: `\"node_modules\"`\n\n* opts.preserveSymlinks - if true, doesn't resolve `basedir` to real path before resolving.\nThis is the way Node resolves dependencies when executed with the [--preserve-symlinks](https://nodejs.org/api/all.html#cli_preserve_symlinks) flag.\n**Note:** this property is currently `true` by default but it will be changed to\n`false` in the next major version because *Node's resolution algorithm does not preserve symlinks by default*.\n\ndefault `opts` values:\n\n```js\n{\n    paths: [],\n    basedir: __dirname,\n    extensions: ['.js'],\n    includeCoreModules: true,\n    readFile: fs.readFile,\n    isFile: function isFile(file, cb) {\n        fs.stat(file, function (err, stat) {\n            if (!err) {\n                return cb(null, stat.isFile() || stat.isFIFO());\n            }\n            if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);\n            return cb(err);\n        });\n    },\n    isDirectory: function isDirectory(dir, cb) {\n        fs.stat(dir, function (err, stat) {\n            if (!err) {\n                return cb(null, stat.isDirectory());\n            }\n            if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);\n            return cb(err);\n        });\n    },\n    realpath: function realpath(file, cb) {\n        var realpath = typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath;\n        realpath(file, function (realPathErr, realPath) {\n            if (realPathErr && realPathErr.code !== 'ENOENT') cb(realPathErr);\n            else cb(null, realPathErr ? file : realPath);\n        });\n    },\n    readPackage: function defaultReadPackage(readFile, pkgfile, cb) {\n        readFile(pkgfile, function (readFileErr, body) {\n            if (readFileErr) cb(readFileErr);\n            else {\n                try {\n                    var pkg = JSON.parse(body);\n                    cb(null, pkg);\n                } catch (jsonErr) {\n                    cb(null);\n                }\n            }\n        });\n    },\n    moduleDirectory: 'node_modules',\n    preserveSymlinks: true\n}\n```\n\n## resolve.sync(id, opts)\n\nSynchronously resolve the module path string `id`, returning the result and\nthrowing an error when `id` can't be resolved.\n\noptions are:\n\n* opts.basedir - directory to begin resolving from\n\n* opts.extensions - array of file extensions to search in order\n\n* opts.includeCoreModules - set to `false` to exclude node core modules (e.g. `fs`) from the search\n\n* opts.readFileSync - how to read files synchronously\n\n* opts.isFile - function to synchronously test whether a file exists\n\n* opts.isDirectory - function to synchronously test whether a file exists and is a directory\n\n* opts.realpathSync - function to synchronously resolve a potential symlink to its real path\n\n* `opts.readPackageSync(readFileSync, pkgfile)` - function to synchronously read and parse a package.json file\n  * readFileSync - the passed `opts.readFileSync` or `fs.readFileSync` if not specified\n  * pkgfile - path to package.json\n\n* `opts.packageFilter(pkg, dir)` - transform the parsed package.json contents before looking at the \"main\" field\n  * pkg - package data\n  * dir - directory that contains package.json (Note: the second argument will change to \"pkgfile\" in v2)\n\n* `opts.pathFilter(pkg, path, relativePath)` - transform a path within a package\n  * pkg - package data\n  * path - the path being resolved\n  * relativePath - the path relative from the package.json location\n  * returns - a relative path that will be joined from the package.json location\n\n* opts.paths - require.paths array to use if nothing is found on the normal `node_modules` recursive walk (probably don't use this)\n\n  For advanced users, `paths` can also be a `opts.paths(request, start, opts)` function\n    * request - the import specifier being resolved\n    * start - lookup path\n    * getNodeModulesDirs - a thunk (no-argument function) that returns the paths using standard `node_modules` resolution\n    * opts - the resolution options\n\n* `opts.packageIterator(request, start, opts)` - return the list of candidate paths where the packages sources may be found (probably don't use this)\n    * request - the import specifier being resolved\n    * start - lookup path\n    * getPackageCandidates - a thunk (no-argument function) that returns the paths using standard `node_modules` resolution\n    * opts - the resolution options\n\n* opts.moduleDirectory - directory (or directories) in which to recursively look for modules. default: `\"node_modules\"`\n\n* opts.preserveSymlinks - if true, doesn't resolve `basedir` to real path before resolving.\nThis is the way Node resolves dependencies when executed with the [--preserve-symlinks](https://nodejs.org/api/all.html#cli_preserve_symlinks) flag.\n**Note:** this property is currently `true` by default but it will be changed to\n`false` in the next major version because *Node's resolution algorithm does not preserve symlinks by default*.\n\ndefault `opts` values:\n\n```js\n{\n    paths: [],\n    basedir: __dirname,\n    extensions: ['.js'],\n    includeCoreModules: true,\n    readFileSync: fs.readFileSync,\n    isFile: function isFile(file) {\n        try {\n            var stat = fs.statSync(file);\n        } catch (e) {\n            if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;\n            throw e;\n        }\n        return stat.isFile() || stat.isFIFO();\n    },\n    isDirectory: function isDirectory(dir) {\n        try {\n            var stat = fs.statSync(dir);\n        } catch (e) {\n            if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;\n            throw e;\n        }\n        return stat.isDirectory();\n    },\n    realpathSync: function realpathSync(file) {\n        try {\n            var realpath = typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native : fs.realpathSync;\n            return realpath(file);\n        } catch (realPathErr) {\n            if (realPathErr.code !== 'ENOENT') {\n                throw realPathErr;\n            }\n        }\n        return file;\n    },\n    readPackageSync: function defaultReadPackageSync(readFileSync, pkgfile) {\n        var body = readFileSync(pkgfile);\n        try {\n            var pkg = JSON.parse(body);\n            return pkg;\n        } catch (jsonErr) {}\n    },\n    moduleDirectory: 'node_modules',\n    preserveSymlinks: true\n}\n```\n\n# install\n\nWith [npm](https://npmjs.org) do:\n\n```sh\nnpm install resolve\n```\n\n# license\n\nMIT\n\n[1]: https://npmjs.org/package/resolve\n[2]: https://versionbadg.es/browserify/resolve.svg\n[5]: https://david-dm.org/browserify/resolve.svg\n[6]: https://david-dm.org/browserify/resolve\n[7]: https://david-dm.org/browserify/resolve/dev-status.svg\n[8]: https://david-dm.org/browserify/resolve#info=devDependencies\n[11]: https://nodei.co/npm/resolve.png?downloads=true&stars=true\n[license-image]: https://img.shields.io/npm/l/resolve.svg\n[license-url]: LICENSE\n[downloads-image]: https://img.shields.io/npm/dm/resolve.svg\n[downloads-url]: https://npm-stat.com/charts.html?package=resolve\n[codecov-image]: https://codecov.io/gh/browserify/resolve/branch/main/graphs/badge.svg\n[codecov-url]: https://app.codecov.io/gh/browserify/resolve/\n[actions-image]: https://img.shields.io/github/check-runs/browserify/resolve/main\n[actions-url]: https://github.com/browserify/resolve/actions\n","publish_time":1760993081703,"_cnpm_publish_time":1760993081703,"dist-tags":{"latest":"1.22.14","next":"2.0.0-next.7"}}