Skip to Content

Custom rules

Teach purgeit about your own build output, caches and directories to avoid.

Rules are data, not code: a config can always be validated, printed with purgeit rules, and shared. Put them in purgeit.config.ts (or .json, .mjs, …, or the purgeit key of package.json). purgeit uses the nearest config, searching from the current directory upward, then a user-level config.* in ~/.config/purgeit/; the nearest one wins outright. purgeit init writes a starter. See the full configuration reference.

purgeit.config.ts
import { defineConfig } from 'purgeit';

export default defineConfig({
  /* … */
});

Recipes

A cache that is always safe to delete

safe: ['.my-tool-cache'],

A generic name, but only next to proof

Use a gated rule when the name alone is too generic. out is only generated output when a project.toml sits beside it:

gated: [{ name: 'out', when: { file: 'project.toml' } }],

when accepts one condition or a list of which any one suffices:

{ file: 'package.json' }                              // a sibling file
{ glob: '*.csproj' }                                  // a sibling matching a glob
{ grep: { file: 'Makefile', pattern: '^build:' } }    // a sibling whose contents match
{ inside: 'pyvenv.cfg' }                              // a file inside the directory itself

inside is how a bare name like venv is proved: the built-in rule only matches a venv that contains a pyvenv.cfg.

Any directory carrying a tag file

markers: [{ name: 'MYTOOL.TAG', file: '.mytool-cache', signature: 'mytool-cache-v1' }],

Keep things out

ignore: ['vault', 'secrets'],   // never entered, anywhere
exclude: ['legacy/**'],         // skipped, relative to each scanned root

Switch off a built-in rule

disable: ['coverage'],          // unknown names are an error, so typos are caught

Named groups for --only

groups: { web: ['node_modules', '.next', 'dist'] },
// purgeit clean --only web

Defaults for flags

minAge: '14d', minSize: '50MB', depth: 6,
dormantAfter: '14d',   // when a project counts as dormant (default 30d)

Flags always override config.

JSON config with editor completion

{ "$schema": "./node_modules/purgeit/schema.json", "safe": [".my-tool-cache"] }

Things worth knowing

  • A rule with the same name as a built-in replaces it.
  • A name can't be both safe and gated in one config — that is rejected.
  • Version-control directories are never entered, whatever the config says.
  • Matching a name is never enough on its own: protection checks still apply to every match.

On this page