detective-postcss

Detective to find dependents of CSS (PostCSS dialect)

MIT 24 个版本
安装
npm install detective-postcss
yarn add detective-postcss
pnpm add detective-postcss
bun add detective-postcss
README

node-detective-postcss

build npm version npm downloads

Find the dependencies of a CSS file (PostCSS dialect)

Supports @import and @value ... from. Absolute and protocol-relative URLs are automatically filtered out.

The AST is generated using postcss and postcss-values-parser.

Installation

npm install detective-postcss

postcss must be installed separately as a peer dependency:

npm install postcss

Usage

// ESM
import { readFileSync } from 'node:fs';
import detective from 'detective-postcss';
// CommonJS
const { readFileSync } = require('node:fs');
const detective = require('detective-postcss');

const content = readFileSync('styles.css', 'utf8');

// Returns an array of imported file paths (e.g. ['foo.css', 'bar.css'])
const dependencies = detective(content);

// Also include url() references (images, fonts, etc.) found in declarations
const allDependencies = detective(content, { url: true });

API

detective(src, options?)

Parameter Type Required Description
src string Yes CSS source code to analyse
options.url boolean No When true, also extracts url() references from declarations (e.g. background, src, cursor). Defaults to false.

Returns string[] - the list of local dependency paths found in the source.

Throws detective.MalformedCssError if src cannot be parsed.

What is detected

Syntax Example Detected by default
@import "file.css" @import "theme.css" yes
@import url(file.css) @import url(print.css) yes
@value x from "file.css" @value primary from 'colors.css' yes
url() in declarations background: url(bg.png) only with { url: true }

Absolute URLs (https://...) and protocol-relative URLs (//...) are always ignored.

This is the CSS (PostCSS dialect) counterpart to:

Releasing

  1. Ensure CI is green on main.
  2. Preview what would be included in the package without publishing: npm pack --dry-run.
  3. Bump the version following semver (this also creates the vX.Y.Z tag): npm version <patch|minor|major>.
  4. Push the commit and tag: git push --follow-tags.
  5. Create (or draft) a GitHub release from that vX.Y.Z tag, then Publish it.
  6. Publishing the release triggers npm-publish (release.published), which runs npm ci and npm publish --provenance.

License

MIT

版本列表
9.0.1 2026-07-01
9.0.0 2026-05-19
8.0.4 2026-05-19
8.0.3 2026-04-23
8.0.0 2026-04-23
7.0.1 2025-02-01
7.0.0 2024-04-08
6.1.3 2023-04-26
6.1.2 2023-04-18
6.1.1 2023-03-18
6.1.0 2022-05-21
6.0.1 2022-03-18
5.1.3 2022-12-04
5.1.1 2022-03-18
5.1.0 2022-03-14
5.0.0 2021-04-29
4.0.0 2020-11-29
3.0.1 2019-03-06
3.0.0 2018-09-04
2.1.2 2018-05-15
2.1.1 2018-05-14
2.1.0 2018-05-14
2.0.0 2018-04-12
1.0.0 2018-04-12