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

vinyl-commonjs-dependencies

v0.7.9

Published

A vinyl adaptor for for commonjs dependency trees. Get all files that a script depends on.

Downloads

3

Readme

Vinyl CommonJs Dependencies

A vinyl adaptor for for commonJs dependency trees. Push dependant files that into a vinyl object stream.

The main use-case being gulp build processes that parse node modules for reuse in the browser.

Install

npm install --save-dev vinyl-commonjs-dependencies

Or

yarn add --dev vinyl-commonjs-dependencies

Example use


const gulp = require('gulp');
const vcjd = require('vinyl-commonjs-dependencies');
const commonjsBrowserWrap = require('gulp-commonjs-browser-wrap');
const concat = require('gulp-concat');

vcd.gulp = gulp // So same version is being used and so we can access gulp.dest via vcjd class.

gulp.task('build', ()=>vcjd.src(['./index.js'])
	.pipe(commonjsBrowserWrap())
    .pipe(concat('browser.js'))
    .pipe(commonjsBrowserWrap({
    	type:'moduleWrap',
    	main:['./index.js']
    }))
    .pipe(vcjd.dest(settings.dest))
);

In the example above we have a basic build task in gulp. Code is sourced from ./index.js and it dependencies. Files are concatenated together and then commonjs-browser-wrap is used to create a browser wrapped version with no loader dependencies.

vcjd.src(globs [,options])

Wraps gulp.src() to parse supplied paths for main files. These input files are then parsed for their dependencies, which are then added to the stream.

In most cases, one input file would be supplied but is possible to supply as many as you want.

| Parameter | Type | Description | | --- | --- | --- | | globs | string| Array.<string> | Glob or array of globs to read. Globs use node-glob syntax except that negation is fully supported. | | options | Object | Options to pass to node-glob through glob-stream. Vcjd supports all options supported by node-glob / glob-stream (except ignore) and gulp. |

Other options

As well as supporting all the standard gulp.src() options; Vcjd also supports the following:

|property | type | description | | --- | --- | --- | | gulp | Gulp | Used to pass a gulp instance into Vcjd. This is useful if you need to pass a specific version into the adaptor to use for src() | | mapper | Object | A module lookup object. You may want to override module names or locations. This a direct mapping object, so keys are module-ids (or paths) and values are their overridden path / id. If value of mapper property is set to null then given module will be skipped and not pulled into the stream. If the value is set to true it will override any internalOnly settong for given module. | | lookup | Map | This is a map, which maps full-paths to vinyl files. Used internally to cache loaded files and avoid reloading. It could be used to pre-cache some files | | resolver | Object | Options object to be passed to async-resolve. If not supplied then defaults are used, which are normally what is needed. | internalOnly | boolean | If set then will only pull in local files rather than loading all requires (including modules from node_modules). |

Example using mapper:

const gulp = require('gulp');
const vcjd = require('vinyl-commonjs-dependencies');

gulp.task('build', ()=>vcjd.src(['./index.js'], {
   mapper: {
   	'text-encoding': './lib/textEncoding'
   }})
   // Do something here ...
   .pipe(vcjd.dest(settings.dest))
);

Here we are telling Vcjd that we want to override the text-encoding module with our own local version. Perhaps we just want to use the native one in the browser so our local module exports this.

vcjd.gulp

This is just simple way to pass gulp to the module. It allows for vcjd.dest() to wrap the gulp version.

vcjs.dest(path [, options])

This is the just a wrapped version of gulp.dest() and does nothing special.