5.0.1 • Published 7 years ago

pulling-deps v5.0.1

Weekly downloads
65
License
MIT
Repository
github
Last release
7 years ago

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

5.0.1

7 years ago

5.0.0

7 years ago

4.1.0

7 years ago

4.0.0

7 years ago

3.0.0

7 years ago

2.0.4

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.0

9 years ago

0.2.0

9 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago