12.1.1 • Published 11 days ago

precinct v12.1.1

Weekly downloads
317,378
License
MIT
Repository
github
Last release
11 days ago

precinct

CI npm version npm downloads

Unleash the detectives

npm install precinct

Uses the appropriate detective to find the dependencies of a file or its AST.

Supports:

  • JavaScript modules: AMD, CommonJS, and ES6
  • TypeScript
  • CSS Preprocessors: Sass, Scss, Stylus, and Less
  • CSS (PostCSS)

Usage

const fs = require('fs');
const precinct = require('precinct');

const content = fs.readFileSync('myFile.js', 'utf8');

// Pass in a file's content or an AST
const deps = precinct(content);

You may pass options (to individual detectives) based on the module type via an optional second object argument detective(content, options), for example:

Example call:

precinct(content, {
  amd: {
    skipLazyLoaded: true
  },
  type: 'amd'
});
  • The supported module type prefixes are: amd, commonjs, css, es6, less, sass, scss, stylus, ts, tsx, vue.

Current options:

  • amd.skipLazyLoaded: tells the AMD detective to omit lazy-loaded dependencies (i.e., inner requires).
  • es6.mixedImports: allows for all dependencies to be fetched from a file that contains both CJS and ES6 imports.
    • Note: This will work for any file format that contains an ES6 import.
  • css.url: tells the CSS detective to include url() references to images, fonts, etc.

Finding non-JavaScript (ex: Sass and Stylus) dependencies:

const fs = require('fs');
const content = fs.readFileSync('styles.scss', 'utf8');

const sassDeps = precinct(content, { type: 'sass' });
const stylusDeps = precinct(content, { type: 'stylus' });

Or, if you just want to pass in a filepath and get the dependencies:

const { paperwork } = require('precinct');

const deps = paperwork('myFile.js');
const deps2 = paperwork('styles.scss');

precinct.paperwork(filename, options)

Supported options:

  • includeCore: (default: true) set to false to exclude core Node.js dependencies from the list of dependencies.
  • fileSystem: (default: undefined) set to an alternative fs implementation that will be used to read the file path.
  • You may also pass detective-specific configuration like you would to precinct(content, options).

CLI

Assumes a global install precinct with npm install -g precinct.

precinct [options] path/to/file

Run precinct --help to see all options.

License

MIT

12.0.0

12 days ago

12.0.1

12 days ago

12.0.2

12 days ago

12.1.0

11 days ago

12.1.1

11 days ago

11.0.5

11 months ago

10.0.0

1 year ago

10.0.1

1 year ago

11.0.4

12 months ago

11.0.2

12 months ago

11.0.3

12 months ago

11.0.0

12 months ago

11.0.1

12 months ago

9.2.1

1 year ago

9.1.0

1 year ago

9.2.0

1 year ago

9.0.1

2 years ago

9.0.0

2 years ago

8.3.0

2 years ago

8.3.1

2 years ago

8.2.0

3 years ago

8.1.0

3 years ago

8.0.0

3 years ago

7.1.0

3 years ago

7.0.0

3 years ago

6.3.1

4 years ago

6.3.0

4 years ago

6.2.0

4 years ago

6.1.2

5 years ago

6.1.1

5 years ago

6.1.0

5 years ago

6.0.0

5 years ago

5.3.1

5 years ago

5.3.0

5 years ago

5.2.1

5 years ago

5.2.0

5 years ago

5.1.0

6 years ago

5.0.1

6 years ago

5.0.0

6 years ago

4.3.0

6 years ago

4.2.0

6 years ago

4.1.0

6 years ago

4.0.0

6 years ago

3.8.0

7 years ago

3.7.0

7 years ago

3.6.0

7 years ago

3.5.2

7 years ago

3.5.1

7 years ago

3.5.0

7 years ago

3.4.0

8 years ago

3.3.0

8 years ago

3.2.0

8 years ago

3.1.2

8 years ago

3.1.1

8 years ago

3.1.0

8 years ago

3.0.0

8 years ago

2.5.1

9 years ago

2.5.0

9 years ago

2.4.3

9 years ago

2.4.2

9 years ago

2.4.1

9 years ago

2.4.0

9 years ago

2.3.2

9 years ago

2.3.1

9 years ago

2.3.0

9 years ago

2.2.0

9 years ago

2.1.1

9 years ago

2.1.0

9 years ago

2.0.0

9 years ago

1.1.0

9 years ago

1.0.0

10 years ago

0.0.0

10 years ago