New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

pulling-deps

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pulling-deps

Pull CJS require, AMD define, and ES2015 import JavaScript dependencies

latest
Source
npmnpm
Version
5.0.1
Version published
Weekly downloads
55
161.9%
Maintainers
1
Weekly downloads
 
Created
Source

pulling-deps

Greenkeeper badge Build Status

Pull CJS require, AMD define, as well as ESM dynamic and static imports.

pulling-deps accomplishes this by building and traversing an AST leveraging acorn.

usage

install

npm

npm install pulling-deps

cli

To run the cli command directly in your console, you will need to install pulling-deps globally. Alternatively, you can create npm scripts in your package json, or use npx. Running npm scripts or npx are the preferred methods for using the CLI.

pull-deps which will extract the dependencies in the files you specify

$ pull-deps src/*.js
$ echo "import('./src/index.js')" | pull-deps

pull-vendor which will extract only node module dependencies

$ pull-vendor src/*.js
$ echo "import('./src/index.js')" | pull-vendor

pull-tree which will generate a flat map of all the dependencies

$ pull-tree src/*.js
$ echo "import('./src/index.js')" | pull-tree

api

pullDeps.fromSource

is a method that takes in a JavaScript string source as the first parameter, and an optional object as the second paramter. The second parameter is an object that is pass straight to acorn.

const pullDeps = require('pullig-deps');

// This gets us an object that has a property `dependencies`, which is an array
// of all the dependencies found.
const result = pullDeps.fromSource(`
  import a from "esmdep";
  const b = require("cjsdep");
  import("dynamicESM");
`);

// Print to console the dependencies, which will have `esmdep`, `cjsdep`, and `dynamicESM`.
console.log(result.dependencies);

pullDeps.fromAST

is a method that takes in as its only parameter an AST as created by acorn.

const acorn = require('acorn-dynamic-import/lib/inject').default(require('acorn'));
const pullDeps = require('pulling-deps');

// Walk the AST to get all the dependencies out
const result = pullDeps.fromAST(acorn(`
  import a from "esmdep";
  const b = require("cjsdep");
  import("dynamicESM");
`));

// Print to console the dependencies, which will have `esmdep`, `cjsdep`, and `dynamicESM`.
console.log(result.dependencies);

build

grunt build

test

grunt test

License

MIT

Keywords

amd

FAQs

Package last updated on 21 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts