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

gulp-resolve-dependencies

v4.1.0

Published

Resolve dependency directives in assets (e.g. "@requires" or "//= require" in JavaScript)

Downloads

1,770

Readme

gulp-resolve-dependencies

Resolve dependency directives in assets, e.g. @depend (Juicer) or //= require (Sprockets)). Inspired by grunt-concat-in-order. Useful in combination with gulp-concat.

Usage

First, install gulp-resolve-dependencies as a development dependency:

npm install --save-dev gulp-resolve-dependencies

Then, add it to your gulpfile.js (probably together with gulp-concat):

var resolveDependencies = require('gulp-resolve-dependencies');
var concat = require('gulp-concat');

gulp.task('js', function(){
  gulp.src(['app/assets/js/main.js'])
    .pipe(resolveDependencies({
      pattern: /\* @requires [\s-]*(.*\.js)/g
    }))
        .on('error', function(err) {
            console.log(err.message);
        })
    .pipe(concat())
    .pipe(gulp.dest('dest/assets/js/'));
});

And use the directives in your JS files (dependencies can be nested, they are handled recursively):

/**
 * @requires libs/jquery/jquery.js
 * @requires ../modules/slideshow/slideshow.js
 */

(function(window, document, $, undefined) {
    'use strict';

    $(document).on('ready', function() {
        $('.slideshow').slideshow();
    });

})(window, document, jQuery);

Warning: This might not be very efficient (especially in case of nested dependencies). Some kind of caching mechanism could come in handy.

Circular dependencies are either silently ignored or emit an error. See options.ignoreCircularDependencies below.

gulp.src will not necessarily return files in a deterministic way. If this turns out to be an issue, using a plugin like gulp-sort or gulp-order right after gulp.src might be an option for you. Thanks to @fabiospampinato for pointing this out.

API

resolveDependencies(options)

options.pattern

Type: RegExp

The matching pattern (defaults to /\* @requires [\s-]*(.*?\.js)/g).

options.resolvePath

Type: Function

Resolver for matched paths. Default:

function(match, targetFile) {
    return path.join(path.dirname(targetFile.path), match);
}

Parameters:

  • match {String} Matched file path (in the example above this would be libs/jquery/jquery.js and ../modules/slideshow/slideshow.js, respectively)
  • targetFile {Vinyl file object} Currently parsed file (where the matches were found)

The path package is available in this context.

Returning a falsy value will ignore the resolved path:

function(match, targetFile) {
    // Ignore `/lib.js`
    if (match.match(/\/lib\.js$/)) {
        return null;
    }

    return path.join(path.dirname(targetFile.path), match);
}

options.log

Type: Boolean

Whether to log the resolved dependencies (defaults to false).

options.ignoreCircularDependencies

Type: Boolean

Whether to just continue instead of emitting an error if circular dependencies are detected (defaults to false).

options.include

Type: Array

Only dependencies matching this array of absolute paths will be included (defaults to []).

options.exclude

Type: Array

Dependencies matching this array of absolute paths will be excluded (defaults to []).

Contributors