Gathering detailed insights and metrics for browser-resolve
Gathering detailed insights and metrics for browser-resolve
Gathering detailed insights and metrics for browser-resolve
Gathering detailed insights and metrics for browser-resolve
resolve function which support the browser field in package.json
npm install browser-resolve
91
Supply Chain
99.5
Quality
83.5
Maintenance
100
Vulnerability
99.6
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
102 Stars
172 Commits
70 Forks
8 Watching
1 Branches
58 Contributors
Updated on 27 Aug 2024
JavaScript (99.96%)
CoffeeScript (0.04%)
Cumulative downloads
Total Downloads
Last day
-8.7%
1,064,897
Compared to previous day
Last week
3.8%
6,930,895
Compared to previous week
Last month
56.3%
24,318,813
Compared to previous month
Last year
-17%
202,327,973
Compared to previous year
node.js resolve algorithm with browser field support.
Resolve a module path and call cb(err, path [, pkg])
Options:
basedir
- directory to begin resolving frombrowser
- the 'browser' property to use from package.json (defaults to 'browser')filename
- the calling filename where the require()
call originated (in the source)modules
- object with module id/name -> path mappings to consult before doing manual resolution (use to provide core modules)packageFilter
- transform the parsed package.json
contents before looking at the main
fieldpaths
- require.paths
array to use if nothing is found on the normal node_modules
recursive walkAdditionally, options supported by node-resolve can be used.
Same as the async resolve, just uses sync methods.
Additionally, options supported by node-resolve can be used.
you can resolve files like require.resolve()
:
1var bresolve = require('browser-resolve'); 2bresolve('../', { filename: __filename }, function(err, path) { 3 console.log(path); 4});
$ node example/resolve.js
/home/substack/projects/browser-resolve/index.js
By default, core modules (http, dgram, etc) will return their same name as the path. If you want to have specific paths returned, specify a modules
property in the options object.
1var shims = { 2 http: '/your/path/to/http.js' 3}; 4 5var bresolve = require('browser-resolve'); 6bresolve('http', { modules: shims }, function(err, path) { 7 console.log(path); 8});
$ node example/builtin.js
/home/substack/projects/browser-resolve/builtin/http.js
browser-specific versions of modules
1{ 2 "name": "custom", 3 "version": "0.0.0", 4 "browser": { 5 "./main.js": "custom.js" 6 } 7}
1var bresolve = require('browser-resolve'); 2var parent = { filename: __dirname + '/custom/file.js' }; 3bresolve('./main.js', parent, function(err, path) { 4 console.log(path); 5});
$ node example/custom.js
/home/substack/projects/browser-resolve/example/custom/custom.js
You can use different package.json properties for the resolution, if you want to allow packages to target different environments for example:
1{ 2 "browser": { "./main.js": "custom.js" }, 3 "chromeapp": { "./main.js": "custom-chromeapp.js" } 4}
1var bresolve = require('browser-resolve'); 2var parent = { filename: __dirname + '/custom/file.js', browser: 'chromeapp' }; 3bresolve('./main.js', parent, function(err, path) { 4 console.log(path); 5});
$ node example/custom.js
/home/substack/projects/browser-resolve/example/custom/custom-chromeapp.js
You can skip over dependencies by setting a
browser field
value to false
:
1{ 2 "name": "skip", 3 "version": "0.0.0", 4 "browser": { 5 "tar": false 6 } 7}
This is handy if you have code like:
1var tar = require('tar'); 2 3exports.add = function (a, b) { 4 return a + b; 5}; 6 7exports.parse = function () { 8 return tar.Parse(); 9};
so that require('tar')
will just return {}
in the browser because you don't
intend to support the .parse()
export in a browser environment.
1var bresolve = require('browser-resolve'); 2var parent = { filename: __dirname + '/skip/main.js' }; 3bresolve('tar', parent, function(err, path) { 4 console.log(path); 5});
$ node example/skip.js
/home/substack/projects/browser-resolve/empty.js
MIT
Prior to v1.x this library provided shims for node core modules. These have since been removed. If you want to have alternative core modules provided, use the modules
option when calling bresolve()
.
This was done to allow package managers to choose which shims they want to use without browser-resolve being the central point of update.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
Found 5/21 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
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