Gathering detailed insights and metrics for resolve
Gathering detailed insights and metrics for resolve
Gathering detailed insights and metrics for resolve
Gathering detailed insights and metrics for resolve
Implements the node.js require.resolve() algorithm
npm install resolve
91.4
Supply Chain
99.6
Quality
76.1
Maintenance
100
Vulnerability
99.6
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
778 Stars
655 Commits
184 Forks
16 Watching
3 Branches
77 Contributors
Updated on 25 Nov 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-7.2%
16,108,796
Compared to previous day
Last week
2%
96,172,102
Compared to previous week
Last month
16.2%
384,353,906
Compared to previous month
Last year
10.5%
3,889,961,514
Compared to previous year
implements the node require.resolve()
algorithm such that you can require.resolve()
on behalf of a file asynchronously and synchronously
asynchronously resolve:
1var resolve = require('resolve/async'); // or, require('resolve') 2resolve('tap', { basedir: __dirname }, function (err, res) { 3 if (err) console.error(err); 4 else console.log(res); 5});
$ node example/async.js
/home/substack/projects/node-resolve/node_modules/tap/lib/main.js
synchronously resolve:
1var resolve = require('resolve/sync'); // or, `require('resolve').sync 2var res = resolve('tap', { basedir: __dirname }); 3console.log(res);
$ node example/sync.js
/home/substack/projects/node-resolve/node_modules/tap/lib/main.js
1var resolve = require('resolve'); 2var async = require('resolve/async'); 3var sync = require('resolve/sync');
For both the synchronous and asynchronous methods, errors may have any of the following err.code
values:
MODULE_NOT_FOUND
: the given path string (id
) could not be resolved to a moduleINVALID_BASEDIR
: the specified opts.basedir
doesn't exist, or is not a directoryINVALID_PACKAGE_MAIN
: a package.json
was encountered with an invalid main
property (eg. not a string)Asynchronously resolve the module path string id
into cb(err, res [, pkg])
, where pkg
(if defined) is the data from package.json
.
options are:
opts.basedir - directory to begin resolving from
opts.package - package.json
data applicable to the module being loaded
opts.extensions - array of file extensions to search in order
opts.includeCoreModules - set to false
to exclude node core modules (e.g. fs
) from the search
opts.readFile - how to read files asynchronously
opts.isFile - function to asynchronously test whether a file exists
opts.isDirectory - function to asynchronously test whether a file exists and is a directory
opts.realpath - function to asynchronously resolve a potential symlink to its real path
opts.readPackage(readFile, pkgfile, cb)
- function to asynchronously read and parse a package.json file
opts.readFile
or fs.readFile
if not specifiedopts.packageFilter(pkg, pkgfile, dir)
- transform the parsed package.json contents before looking at the "main" field
opts.pathFilter(pkg, path, relativePath)
- transform a path within a package
opts.paths - require.paths array to use if nothing is found on the normal node_modules
recursive walk (probably don't use this)
For advanced users, paths
can also be a opts.paths(request, start, opts)
function
node_modules
resolutionopts.packageIterator(request, start, opts)
- return the list of candidate paths where the packages sources may be found (probably don't use this)
node_modules
resolutionopts.moduleDirectory - directory (or directories) in which to recursively look for modules. default: "node_modules"
opts.preserveSymlinks - if true, doesn't resolve basedir
to real path before resolving.
This is the way Node resolves dependencies when executed with the --preserve-symlinks flag.
default opts
values:
1{ 2 paths: [], 3 basedir: __dirname, 4 extensions: ['.js'], 5 includeCoreModules: true, 6 readFile: fs.readFile, 7 isFile: function isFile(file, cb) { 8 fs.stat(file, function (err, stat) { 9 if (!err) { 10 return cb(null, stat.isFile() || stat.isFIFO()); 11 } 12 if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false); 13 return cb(err); 14 }); 15 }, 16 isDirectory: function isDirectory(dir, cb) { 17 fs.stat(dir, function (err, stat) { 18 if (!err) { 19 return cb(null, stat.isDirectory()); 20 } 21 if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false); 22 return cb(err); 23 }); 24 }, 25 realpath: function realpath(file, cb) { 26 var realpath = typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath; 27 realpath(file, function (realPathErr, realPath) { 28 if (realPathErr && realPathErr.code !== 'ENOENT') cb(realPathErr); 29 else cb(null, realPathErr ? file : realPath); 30 }); 31 }, 32 readPackage: function defaultReadPackage(readFile, pkgfile, cb) { 33 readFile(pkgfile, function (readFileErr, body) { 34 if (readFileErr) cb(readFileErr); 35 else { 36 try { 37 var pkg = JSON.parse(body); 38 cb(null, pkg); 39 } catch (jsonErr) { 40 cb(jsonErr); 41 } 42 } 43 }); 44 }, 45 moduleDirectory: 'node_modules', 46 preserveSymlinks: false 47}
Synchronously resolve the module path string id
, returning the result and
throwing an error when id
can't be resolved.
options are:
opts.basedir - directory to begin resolving from
opts.extensions - array of file extensions to search in order
opts.includeCoreModules - set to false
to exclude node core modules (e.g. fs
) from the search
opts.readFileSync - how to read files synchronously
opts.isFile - function to synchronously test whether a file exists
opts.isDirectory - function to synchronously test whether a file exists and is a directory
opts.realpathSync - function to synchronously resolve a potential symlink to its real path
opts.readPackageSync(readFileSync, pkgfile)
- function to synchronously read and parse a package.json file. a thrown SyntaxError will be ignored, all other exceptions will propagate.
opts.readFileSync
or fs.readFileSync
if not specifiedopts.packageFilter(pkg, pkgfile, dir)
- transform the parsed package.json contents before looking at the "main" field
opts.pathFilter(pkg, path, relativePath)
- transform a path within a package
opts.paths - require.paths array to use if nothing is found on the normal node_modules
recursive walk (probably don't use this)
For advanced users, paths
can also be a opts.paths(request, start, opts)
function
node_modules
resolutionopts.packageIterator(request, start, opts)
- return the list of candidate paths where the packages sources may be found (probably don't use this)
node_modules
resolutionopts.moduleDirectory - directory (or directories) in which to recursively look for modules. default: "node_modules"
opts.preserveSymlinks - if true, doesn't resolve basedir
to real path before resolving.
This is the way Node resolves dependencies when executed with the --preserve-symlinks flag.
default opts
values:
1{ 2 paths: [], 3 basedir: __dirname, 4 extensions: ['.js'], 5 includeCoreModules: true, 6 readFileSync: fs.readFileSync, 7 isFile: function isFile(file) { 8 try { 9 var stat = fs.statSync(file); 10 } catch (e) { 11 if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false; 12 throw e; 13 } 14 return stat.isFile() || stat.isFIFO(); 15 }, 16 isDirectory: function isDirectory(dir) { 17 try { 18 var stat = fs.statSync(dir); 19 } catch (e) { 20 if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false; 21 throw e; 22 } 23 return stat.isDirectory(); 24 }, 25 realpathSync: function realpathSync(file) { 26 try { 27 var realpath = typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native : fs.realpathSync; 28 return realpath(file); 29 } catch (realPathErr) { 30 if (realPathErr.code !== 'ENOENT') { 31 throw realPathErr; 32 } 33 } 34 return file; 35 }, 36 readPackageSync: function defaultReadPackageSync(readFileSync, pkgfile) { 37 return JSON.parse(readFileSync(pkgfile)); 38 }, 39 moduleDirectory: 'node_modules', 40 preserveSymlinks: false 41}
With npm do:
1npm install resolve
MIT
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
0 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 1
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More