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

yarb

v0.8.0

Published

Yet another require() bundler

Downloads

77

Readme

yarb

Build Status

yarb performs mostly the same task as browserify, and shares a lot of the same internals (browser-pack, node-detective, insert-module-globals).

yarb is much less flexible than browserify, but better at defining dependencies between bundles. In browserify, sharing files between bundles tends to require a lot of manual expose and external settings on each file. A yarbundle’s external function only accepts other bundles as input, and the bundling process knows exactly which files are common to both.

While yarb shares API similarities with browserify and is even compatible with browserify transforms, it currently does not handle the full array of core modules (only events, fs, module, net, path, stream, util), and lacks most of the settings and behaviors that browserify has.

Notes

Internally, yarb stores files as vinyl objects, and even accepts these as input wherever a path is accepted. This allows passing in existing buffers/streams by just wrapping them in vinyl objects beforehand.

The catch is that all vinyls must have a path property that is both unique to the bundle and absolute (though it doesn't have to exist on disk). Paths are how modules reference each other, after all.

The expose method could theoretically support exposing a vinyl buffer/stream as an arbitrary ID, since those always take precedence over paths. That’d be a rare case, since the vast majority of things will be sourced from disk. Giving a fake but unique path where one doesn't exist will otherwise suffice.

API

var bundle = yarb([files[, options]])

Returns a new bundle with files as entry points, i.e. modules executed when the bundle is loaded. files can be a single file or an array of files consisting of paths or vinyl objects.

Current options are:

Option | Purpose --------- | ------------- debug | Enables source maps. basedir | Sets the starting point for resolving relative paths.

bundle.add(files)

Adds additional entry files to bundle. See above for accepted inputs for files.

Returns bundle.

bundle.require(files)

Adds non-entry files to be included in bundle. Only necessary if you want to include files that aren’t referenced by any entry files, or are referenced dynamically (e.g. require('foo' + bar));

Returns bundle.

bundle.external(externalBundle)

Looks to externalBundle when resolving required paths/IDs, excluding all modules that exist in it from bundle. Obviously, externalBundle must be loaded on the page before anything that references it in bundle executes. Note that externalBundle’s externals will also be recursively checked, allowing a chain of dependencies to form.

Returns bundle.

bundle.expose(file, id)

Calls bundle.require on file and aliases it as id for the current bundle and external bundles. require(id) will always takes precedence over normal path-resolution and always resolve to file.

Returns bundle.

bundle.transform(transform[, options])

Adds browserify-compatible transform to execute on all file contents before being parsed for require calls.

By default, transforms are not run on any code contained within a node_modules/ directory relative to any of the bundle’s entry files. yarb supports a global flag in options which serves the same purpose as the one in browserify and forces the transform to run on all code.

Returns bundle.

bundle.bundle([callback])

Bundles everything together for the browser.

Returns a readable stream that can be piped to disk or elsewhere. If a node-style callback is given, it’ll execute on completion with the arguments (error, buffer).

bundle.has(path)

Returns true if the bundle includes the file located at path in its output, otherwise false. Will only give accurate results after bundle() is called.

License

MIT