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

grunt-jsdeps

v1.0.1

Published

Build a dependency tree from script files using reference tags to declare dependencies

Downloads

7

Readme

grunt-jsdeps

Build a dependency tree from js files with microsoft type dependencies

Getting Started

This plugin requires Grunt ~0.4.5

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-jsdeps --save

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-jsdeps');

The "createJSDeps" task

Overview

In your project's Gruntfile, add a section named jsdeps to the data object passed into grunt.initConfig(). Note there is also an async version of this task called asyncCreateJSDeps

grunt.initConfig({
  createJSDeps: {
    your_target: {
      // Target-specific file lists and/or options go here.
      options: {
        pathPrefix: ".", // from where the directory starts
        sourcePath: "test/fixtures/simple", // dir where your js files are stored - they will be recursively scanned
        format: "json", // can also be xml
        dest: "./tmp/simple.json" // name of destination file or path to it
      }
    },
  },
});

Options

options.pathPrefix

Type: String Default value: .

A string path of what to exclude when writing the path. For example: with pathPrefix = '/test/fixtures/simple/', the path "/test/fixtures/simple/b.js" will be written as "/b.js"

options.sourcePath

Type: String Default value: .

A string path of the root directory to scan to find js files

options.format

Type: String Default value: json

Can be either json or xml. The xml option is not currently supported by the update multitask.

options.dest

Type: String Default value: ./dependency-tree.json

The place the output file is written.

Update Task comments

The update task is updateJSDeps and asyncUpdateJSDeps

The update task doesn't take a sourcePath, rather it takes a list of files that have changed. The files.src is a list of globs of what to include and exclude (to negate a path, prefix it with !) In addition you can speific a filter function. This can, for example, watch the files that changed and edit an enviornment variable. Then the filter function can read the env variable when the task is kicked off and only add the files that changed.

files: {
  expand: true,
  // src: ["test/fixtures/update/simple/**/*.js"]
  src: ["test/fixtures/update/simple/**/*.js", "!test/fixtures/update/simple/a.js"],
  filter: function(path) {
    return path.search("b.js") === -1;
  }
},

Usage Example

Simple case

In this example the following options are used

grunt.initConfig({
  jsdeps: {
    simple: {
      options: {
        pathPrefix: ".",
        sourcePath: "test/fixtures/simple",
        format: "json",
        dest: "./tmp/simple.json"
      }
    }
  }
});

where the following files have these references

test/fixtures/simple/a.js
1:/// <reference path="b.js" />
2:/// <reference path="folder/c.js" />

test/fixtures/simple/folder/c.js
1:/// <reference path="d.js" />

and the destination file looks like this:

[
  {
    "source": "/test/fixtures/simple/a.js",
    "dependencies": [
      "/test/fixtures/simple/b.js",
      "/test/fixtures/simple/folder/c.js"
    ]
  },
  {
    "source": "/test/fixtures/simple/folder/c.js",
    "dependencies": [
      "/test/fixtures/simple/folder/d.js"
    ]
  }
]

Relative path example

In this example the pathPrefix is set to remove the prefix "test/fixtures" from the generated file

grunt.initConfig({
  jsdeps: {
    simple: {
      options: {
        pathPrefix: "test/fixtures",
        sourcePath: "test/fixtures/simple",
        format: "json",
        dest: "./tmp/simple.json"
      }
    }
  }
});

where the following files have these references

test/fixtures/simple/a.js
1:/// <reference path="b.js" />
2:/// <reference path="folder/c.js" />

test/fixtures/simple/folder/c.js
1:/// <reference path="d.js" />

and the destination file looks like this:

[
  {
    "source": "/simple/a.js",
    "dependencies": [
      "/simple/b.js",
      "/simple/folder/c.js"
    ]
  },
  {
    "source": "/simple/folder/c.js",
    "dependencies": [
      "/simple/folder/d.js"
    ]
  }
]

XML case

In this example the following options are used

grunt.initConfig({
  jsdeps: {
    xml: {
      options: {
        pathPrefix: ".",
        sourcePath: "test/fixtures/simple",
        format: "xml",
        dest: "./tmp/simple.xml"
      }
    }
  }
});

where the following files have these references

test/fixtures/simple/a.js
1:/// <reference path="b.js" />
2:/// <reference path="folder/c.js" />

test/fixtures/simple/folder/c.js
1:/// <reference path="d.js" />

and the destination file looks like this:

{
  "/test/fixtures/simple/a.js": [
    "/test/fixtures/simple/b.js",
    "/test/fixtures/simple/folder/c.js"
  ],
  "/test/fixtures/simple/folder/c.js": [
    "/test/fixtures/simple/folder/d.js"
  ]
}