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-bundle-deps

v0.0.1

Published

walk the dependency graph of a browser bundle entry file and return it as a json stream. Supports both AMD and CommonJS (node-style) modules.

Downloads

2

Readme

browser-bundle-deps

walk the dependency graph of a browser bundle entry file and return it as a json stream. Supports both AMD and CommonJS (node-style) modules.

example

var bdeps = require('browser-module-deps');
var JSONStream = require('JSONStream');

var stringify = JSONStream.stringify();
stringify.pipe(process.stdout);

var file = __dirname + '/files/main.js';
mdeps(file).pipe(stringify);

output:

$ node example/deps.js
[
{"id":"/data/dev/browser-bundle-deps/test/files/main.js","source":"define([\"./baz\"], function(foo) {\n    console.log('main: ' + foo(5));\n});\n","format":"amd","deps":{"./baz":"/data/dev/browser-bundle-deps/test/files/baz.js"},"entry":true}
,
{"id":"/data/dev/browser-bundle-deps/test/files/baz.js","source":"define([\"./bar\"], function(bar) {\n    require([\"./foo\"], function() {\n        return function (n) {\n            return bar(n) * foo(n);\n        };\n    });\n});\n","format":"amd","deps":{"./foo":"/data/dev/browser-bundle-deps/test/files/foo.js","./bar":"/data/dev/browser-bundle-deps/test/files/bar.js"}}
,
{"id":"/data/dev/browser-bundle-deps/test/files/bar.js","source":"module.exports = function (n) {\n    return n * 100;\n};\n","format":"commonJS","deps":{}}
,
{"id":"/data/dev/browser-bundle-deps/test/files/foo.js","source":"var bar = require('./bar');\n\nmodule.exports = function (n) {\n    return n * 111 + bar(n);\n};\n","format":"commonJS","deps":{"./bar":"/data/dev/browser-bundle-deps/test/files/bar.js"}}
]

usage

usage: browser-bundle-deps [files]

  generate json output from each entry file

methods

var bdeps = require('browser-bundle-deps')

bdeps(files, opts={})

Return a readable stream of javascript objects from an array of filenames files.

Optionally pass in some opts:

  • opts.transform - a string or array of string transforms (see below)

  • opts.transformKey - an array path of strings showing where to look in the package.json for source transformations. If falsy, don't look at the package.json at all.

  • opts.resolve - custom resolve function using the opts.resolve(id, parent, cb) signature that browser-resolve has

  • opts.filter - a function (id) to skip resolution of some module id strings. If defined, opts.filter(id) should return truthy for all the ids to include and falsey for all the ids to skip.

  • opts.packageFilter - transform the parsed package.json contents before using the values. opts.packageFilter(pkg) should return the new pkg object to use.

transforms

browser-bundle-deps can be configured to run source transformations on files before parsing them for require() calls. These transforms are useful if you want to compile a language like coffeescript on the fly or if you want to load static assets into your bundle by parsing the AST for fs.readFileSync() calls.

If the transform is a function, it should take the file name as an argument and return a through stream that will be written file contents and should output the new transformed file contents.

If the transform is a string, it is treated as a module name that will resolve to a module that is expected to follow this format:

var through = require('through');
module.exports = function (file) { return through() };

You don't necessarily need to use the through module to create a readable/writable filter stream for transforming file contents, but this is an easy way to do it.

When you call bdeps() with an opts.transform, the transformations you specify will not be run for any files in node_modules/. This is because modules you include should be self-contained and not need to worry about guarding themselves against transformations that may happen upstream.

Modules can apply their own transformations by setting a transformation pipeline in their package.json at the opts.transformKey path. These transformations only apply to the files directly in the module itself, not to the module's dependants nor to its dependencies.

install

With npm, to get the module do:

npm install browser-bundle-deps

and to get the browser-bundle-deps command do:

npm install -g browser-bundle-deps

license

MIT