Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
browser-resolve-noio
Advanced tools
This is an experimental fork of browser-resolve, that accepts hooks for
readFile
andisFile
, preventing the module from accessing the disk directly.
node.js resolve algorithm with browser field support.
Resolve a module path and call cb(err, path)
Options:
Same as the async resolve, just uses sync methods.
you can resolve files like require.resolve()
:
var resolve = require('browser-resolve');
resolve('../', { filename: __filename }, function(err, path) {
console.log(path);
});
$ node example/resolve.js
/home/substack/projects/node-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.
var shims = {
http: '/your/path/to/http.js'
};
var resolve = require('browser-resolve');
resolve('fs', { modules: shims }, function(err, path) {
console.log(path);
});
$ node example/builtin.js
/home/substack/projects/node-browser-resolve/builtin/fs.js
browser-specific versions of modules
{
"name": "custom",
"version": "0.0.0",
"browser": {
"./main.js": "custom.js"
}
}
var resolve = require('browser-resolve');
var parent = { filename: __dirname + '/custom/file.js' };
resolve('./main.js', parent, function(err, path) {
console.log(path);
});
$ node example/custom.js
/home/substack/projects/node-browser-resolve/example/custom/custom.js
You can skip over dependencies by setting a
browser field
value to false
:
{
"name": "skip",
"version": "0.0.0",
"browser": {
"tar": false
}
}
This is handy if you have code like:
var tar = require('tar');
exports.add = function (a, b) {
return a + b;
};
exports.parse = function () {
return tar.Parse();
};
so that require('tar')
will just return {}
in the browser because you don't
intend to support the .parse()
export in a browser environment.
var resolve = require('browser-resolve');
var parent = { filename: __dirname + '/skip/main.js' };
resolve('tar', parent, function(err, path) {
console.log(path);
});
$ node example/skip.js
/home/substack/projects/node-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 resolve.
This was done to allow package managers to choose which shims they want to use without browser-resolve being the central point of update.
FAQs
resolve which handles browser field support in package.json
The npm package browser-resolve-noio receives a total of 1 weekly downloads. As such, browser-resolve-noio popularity was classified as not popular.
We found that browser-resolve-noio demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.