npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

browser-resolve-noio

v1.4.1

Published

resolve which handles browser field support in package.json

Downloads

6

Readme

browser-resolve-noio Build Status

This is an experimental fork of browser-resolve, that accepts hooks for readFile and isFile, preventing the module from accessing the disk directly.

node.js resolve algorithm with browser field support.

api

resolve(pkg, opts={}, cb)

Resolve a module path and call cb(err, path)

Options:

  • filename - the calling filename where the require call originated (in the source)
  • paths - require.paths array to use if nothing is found on the normal node_modules recursive walk
  • packageFilter - transform the parsed package.json contents before looking at the "main" field
  • modules - object with module id/name -> path mappings to consult before doing manual resolution (use to provide core modules)

resolve.sync(pkg, opts={})

Same as the async resolve, just uses sync methods.

basic usage

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

core modules

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 field

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

skip

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

license

MIT

upgrade notes

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.