# precinct

> Unleash the detectives

Latest version **13.0.1** (published 2026-07-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install precinct
pnpm add precinct
yarn add precinct
bun add precinct
```

Provides the command `precinct`.

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 13.0.1 |
| Published | 2026-07-15 |
| First published | 2014-07-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20.19.0 \|\| >=22.12.0 |
| Dependencies | 15 |
| Unpacked size | 15.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 234 |
| Author | Joel Kemp |
| Maintainers | pahen, mrjoelkemp, xhmikosr |
| Keywords | modules, amd, commonjs, es6, sass, less, vue, detective, dependencies |

## Links

- npm: https://www.npmjs.com/package/precinct
- Repository: https://github.com/dependents/node-precinct
- Issues: https://github.com/dependents/node-precinct/issues
- npm.io page: https://npm.io/package/precinct

## Dependencies (15)

- [postcss](https://npm.io/package/postcss.md) ^8.5.19
- [commander](https://npm.io/package/commander.md) ^14.0.3
- [typescript](https://npm.io/package/typescript.md) ^6.0.3
- [detective-amd](https://npm.io/package/detective-amd.md) ^7.0.0
- [detective-cjs](https://npm.io/package/detective-cjs.md) ^7.0.0
- [detective-es6](https://npm.io/package/detective-es6.md) ^6.0.0
- [detective-sass](https://npm.io/package/detective-sass.md) ^7.0.1
- [detective-scss](https://npm.io/package/detective-scss.md) ^6.0.1
- [detective-vue2](https://npm.io/package/detective-vue2.md) ^3.0.1
- [detective-stylus](https://npm.io/package/detective-stylus.md) ^6.0.0
- [node-source-walk](https://npm.io/package/node-source-walk.md) ^8.0.0
- [detective-postcss](https://npm.io/package/detective-postcss.md) ^9.0.1
- [module-definition](https://npm.io/package/module-definition.md) ^7.0.0
- [detective-typescript](https://npm.io/package/detective-typescript.md) ^15.0.1
- [@dependents/detective-less](https://npm.io/package/@dependents/detective-less.md) ^6.0.1

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 13.0.1 (latest) — 2026-07-15
- 13.0.0 — 2026-05-19
- 12.3.2 — 2026-05-06
- 12.3.1 — 2026-04-19
- 12.3.0 — 2026-04-15
- 12.2.1 — 2026-04-13
- 12.2.0 — 2025-02-06
- 12.1.3 — 2025-02-01
- 12.1.2 — 2024-07-26
- 12.1.1 — 2024-04-15
- 12.1.0 — 2024-04-15
- 12.0.2 — 2024-04-14
- 12.0.1 — 2024-04-14
- 12.0.0 — 2024-04-14
- 11.0.5 — 2023-05-25
- … 66 more at https://npm.io/package/precinct/versions

## README

# precinct

[![CI](https://img.shields.io/github/actions/workflow/status/dependents/node-precinct/ci.yml?branch=main&label=CI&logo=github)](https://github.com/dependents/node-precinct/actions/workflows/ci.yml?query=branch%3Amain)
[![npm version](https://img.shields.io/npm/v/precinct?logo=npm&logoColor=fff)](https://www.npmjs.com/package/precinct)
[![npm downloads](https://img.shields.io/npm/dm/precinct)](https://www.npmjs.com/package/precinct)

> Unleash the detectives

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

Supports:

- JavaScript modules: AMD, CommonJS, ES6
- TypeScript
- CSS preprocessors: Sass, Scss, Less, Stylus
- CSS (PostCSS)
- Vue

## Install

```sh
npm install precinct
```

## Quick start

```js
// ESM
import fs from 'node:fs';
import precinct from 'precinct';
// CommonJS
const fs = require('node:fs');
const { default: precinct } = require('precinct');

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

// From source content or an AST
const deps = precinct(content);

// Or directly from a file path
const deps2 = precinct.paperwork('styles.scss');
```

## API

### `precinct(content, options?)`

Returns an array of dependency strings discovered in `content`. `content` may be a source string or an already-parsed AST.

| Option | Type | Default | Notes |
|---|---|---|---|
| `type` | `string` | inferred from source | Forces a specific detective. See [Supported types](#supported-types). |
| `walker` | `object` | - | Passed through to the underlying [node-source-walk](https://github.com/dependents/node-source-walk) instance - e.g. `{ allowImportExportEverywhere: true }`, or `{ parser: myCustomParser }` to swap in a parser with a `.parse(src, opts)` method. |
| `amd.skipLazyLoaded` | `boolean` | `false` | Omit lazy-loaded (inner-`require`) dependencies in AMD files. |
| `es6.mixedImports` | `boolean` | `false` | Return both ES6 and CommonJS imports from a file that mixes the two. Works for any format that contains an ES6 import. |
| `css.url` | `boolean` | `false` | Include `url()` references (images, fonts, etc.) in CSS output. |
| `[type]` | `object` | - | Any other key matching a module type is forwarded to that detective as its options bag. |

Side channel: `precinct.ast` holds the last AST produced (or `null` when parsing failed).

#### Example

```js
precinct(content, {
  type: 'amd',
  amd: {
    skipLazyLoaded: true
  }
});

precinct(content, {
  walker: {
    allowImportExportEverywhere: true
  }
});

// Non-JS content
precinct(scssSource, { type: 'scss' });
precinct(stylusSource, { type: 'stylus' });
```

### `precinct.paperwork(filename, options?)`

Reads the file at `filename` and returns an array of its dependencies. The module type is inferred from the file extension (see below). Accepts every option `precinct()` does, plus the two below.

| Option | Type | Default | Notes |
|---|---|---|---|
| `includeCore` | `boolean` | `true` | Set to `false` to strip Node.js core modules (`fs`, `path`, `node:fs`, ...) from the result. |
| `fileSystem` | `{ readFileSync(path, encoding): string }` | `node:fs` | An alternative `fs` implementation used to read `filename`. Only `readFileSync(path, 'utf8')` is required. |
| `walker`, `amd`, `es6`, `css`, `[type]` | - | - | Same as `precinct()` - all detective options are forwarded. |

#### Example

```js
// ESM
import { paperwork } from 'precinct';
// CommonJS
const { paperwork } = require('precinct');

const deps = paperwork('myFile.js');
const deps2 = paperwork('styles.scss');
const deps3 = paperwork('app.ts', { includeCore: false });
```

## Supported types

Accepted values for the `type` option:

| Value | Detective |
|---|---|
| `amd` | [detective-amd](https://github.com/dependents/node-detective-amd) |
| `cjs`, `commonjs` | [detective-cjs](https://github.com/dependents/node-detective-cjs) |
| `css` | [detective-postcss](https://github.com/dependents/node-detective-postcss) |
| `es6`, `esm`, `mjs` | [detective-es6](https://github.com/dependents/node-detective-es6) |
| `less` | [@dependents/detective-less](https://github.com/dependents/node-detective-less) |
| `sass` | [detective-sass](https://github.com/dependents/node-detective-sass) |
| `scss` | [detective-scss](https://github.com/dependents/node-detective-scss) |
| `stylus` | [detective-stylus](https://github.com/dependents/node-detective-stylus) |
| `ts` | [detective-typescript](https://github.com/dependents/detective-typescript) |
| `tsx` | [detective-typescript](https://github.com/dependents/detective-typescript) (tsx variant) |
| `vue` | [detective-vue2](https://github.com/dependents/detective-vue2) |

`paperwork()` infers the type from the filename extension; `.styl` maps to `stylus` and `.cjs` maps to `commonjs`. Any other extension becomes the type with the leading dot stripped. `.js` and `.jsx` are sniffed at the source level rather than by extension.

## CLI

```sh
npm install -g precinct
precinct [options] <filename>
```

| Flag | Description |
|---|---|
| `-t, --type <type>` | Force a module type (see [Supported types](#supported-types)). |
| `--es6-mixed-imports` | Collect both ES6 and CommonJS imports in the same file. |
| `-V, --version` | Print version. |
| `-h, --help` | Print help. |

## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/precinct · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
