GithubHelp home page GithubHelp logo

npm-utils's Introduction

node security project npm utilities

Methods:

getPackageJson = function (module, callback)

Return the full package document for the given module.

getShrinkwrapDependencies = function (shrinkwrapJson, callback)

Get a depTree for the module from a full npm-shrinkwrap.json. shrinkwrapJson should be an object from a parsed npm-shrinkwrap.json file (or look like one): required keys: name, version, dependencies.

var fs = require('fs');

getShrinkwrapDependencies(JSON.parse(fs.readFileSync('./npm-shrinkwrap.json')), function (err, depTree) {
    console.log(depTree);
});

depTree format

The returned depTree representing the full dependency tree object is in a format that's easier to traverse than a full tree. Each module in the full heirarchy has a key in the object of module@version. It's value is an object with parents, children and source.

Note that the root module has a key too.

e.g.:

//depTree for some-module version 1.1.0
{
    //root module
    "[email protected]": {
        parents: [],
        children: ["[email protected]", "[email protected]", "[email protected]"],
    },

    //root's dependencies
    "[email protected]": {
        parents: ["[email protected]"],
        children: ["[email protected]"],
        source: "npm"
    },
    "[email protected]": {
        parents: ["[email protected]"],
        children: ["[email protected]", "[email protected]"],
        source: "npm"
    },
    "[email protected]": {
        parents: ["[email protected]"],
        children: [],
        source: "unknown" //not on npm, maybe it's private/local?
    }

    //deeper dependencies
    "[email protected]": {
        parents: ["[email protected]", "[email protected]", "[email protected]"], //modules can be required multiple places in the tree
        children: [],
        source: "npm"
    },
    "[email protected]": {
        parents: ["[email protected]"], //modules can be required multiple places in the tree
        children: ["[email protected]"],
        source: "npm"
    }
}

npm-utils's People

Contributors

nlf avatar latentflip avatar henrikjoreteg avatar wraithgar avatar sam-breed-ck avatar tomsteele avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.