Skip to content
CLDMVPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

@cldmv/configs

@cldmv/configs is the single source of CLDMV's shared tool configurations. Every CLDMV repository runs the same tools with the same house settings; instead of copying those settings into each repository, where the copies drift apart, the canonical versions live here as shared config files that each repository extends.

A repository points its tool at the shared file and keeps only its own overrides locally. When a house setting changes, it changes here once, and every repository picks it up on its next update.

Most of the configs are plain JSON (fix-headers.json, prettier.json) and one is a plain ignore list (prettierignore). Two are small ES modules, because ESLint and Vitest configs are code: eslint.config.mjs exports the flat config as an array and imports the ESLint plugins it needs, and vitest.config.mjs exports a plain settings object with no imports. A third module, eslint-plugin.mjs, is an ESLint plugin with the fleet's own test rules (see Test rules). The package therefore has real dependencies: the six ESLint plugin packages that eslint.config.mjs imports (@eslint/js, @eslint/json, @eslint/markdown, @eslint/css, @cldmv/eslint-plugin-jsonv and globals) are regular dependencies, and eslint, vitest and @cldmv/prettier-plugin-jsonv are optional peers that only matter to repositories using the matching config. It also ships a small command-line tool, cldmv-configs, that adopts the configs in a repository and detects drift (see CLI). It ships the config files, the ESLint plugin and its rules, the CLI, this README, the license and package.json, and nothing else.

npm version npm downloads Last commit npm last update coverage

Contributors Sponsor shinrai


✨ What's New

Latest: v1.6.0 (December 2026)

  • Types packages β€” cldmv-configs types build carves a repository's declarations into a separate <pkg>-types package that TypeScript users install as an optional peer, and leaves re-export stubs in types/stub/. types check proves a consumer resolves and type-checks through both. It type-checks against the files npm pack would publish, under nodenext, bundler and, where they apply, CommonJS, browser and extra conditions (#64).
  • Test lint rule β€” @cldmv/configs/eslint-plugin.mjs ships cldmv/no-regex-in-tomatchobject, which flags a regex inside toMatchObject(...), which Vitest treats as matching anything, so the check never fails. One import (cldmv.configs.recommended) turns it on for test files, replacing the local copies in hoot and quack (#68).
  • View full v1.6.0 Changelog

Recent Releases

  • v1.5.1 (November 2026) β€” dev dependencies moved to the latest CLDMV tools and every header restamped with @cldmv/fix-headers 2.6.1; configs and CLI unchanged (Changelog)
  • v1.5.0 (November 2026) β€” Node-only ESLint base with opt-in withBrowserGlobals() and withVitestGlobals(), the dev floor in devEngines, and @cldmv/eslint-plugin-jsonv 2 (Changelog)
  • v1.4.0 (November 2026) β€” devCondition() in vitest.config.mjs for the <pkg>-dev export condition, plus dependency updates (Changelog)
  • v1.3.0 (October 2026) β€” four new shared configs (prettier.json, prettierignore, eslint.config.mjs, vitest.config.mjs), the cldmv-configs CLI with workspace support, and the ESLint plugins as dependencies (Changelog)

πŸ“š For complete version history, see docs/changelog/ and the GitHub Releases.


πŸš€ Key Features

  • One source of truth β€” each house setting is defined once, here, instead of in a copy per repository.
  • Plain files, almost no code β€” JSON for fix-headers and Prettier, a plain list for the Prettier ignore, and small modules for ESLint (the base, and a plugin with the fleet's test rules) and Vitest. The ESLint plugins the base imports are the package's only dependencies; eslint, vitest and the jsonv Prettier plugin are optional peers.
  • Two ways to consume it β€” by package specifier through package.json exports (@cldmv/configs/fix-headers.json, @cldmv/configs/prettier.json, @cldmv/configs/eslint.config.mjs, ...), or by a raw GitHub URL pinned to a release tag.
  • One command to adopt, one to audit β€” npx cldmv-configs init creates the stubs and scripts, check reports drift for CI, sync refreshes the ignore list.
  • Types packages β€” cldmv-configs types build carves a repository's declarations into a separate <pkg>-types package with re-export stubs, and types check proves a consumer resolves and type-checks through both.
  • Local overrides β€” a repository's own config extends the shared file and overrides only the keys that are genuinely specific to it.
  • Tested β€” the suite checks that every exported file parses, that every exports entry ships, that the settings are ones the tool accepts, and that npm pack publishes exactly the intended files.

πŸ“¦ Installation

Requirements

  • A tool that can extend a shared config. For fix-headers that is v2.0.0 or later: extends arrives in CLDMV/fix-headers#88, and several of the options this config sets (fixCreatedDate, normalizeDateFormat, strictCreatedDate) in CLDMV/fix-headers#67. Older releases cannot resolve extends and ignore those options. Use v2.2.0 or later for the author rules: from 2.2.0, @Last modified by changes only when a file's content was edited (CLDMV/fix-headers#128).
  • For prettier.json, Prettier 3 with a config file that can import JSON (prettier.config.mjs). Repositories that format .jsonv files also install @cldmv/prettier-plugin-jsonv, an optional peer dependency of this package.
  • For eslint.config.mjs, ESLint 10 (eslint/config supplies defineConfig, and the @eslint/js it uses requires ESLint 10) and a flat config file that can import an ES module.
  • For vitest.config.mjs, Vitest 4 or 5 (the peerDependencies range is ^4.0.0 || ^5.0.0; the base uses only options both versions accept) and a Vitest config file that can import an ES module. Coverage with the v8 provider also needs @vitest/coverage-v8 at the Vitest version.
  • A Node.js release that can import JSON with with { type: "json" }.

Install

Install the package as a devDependency next to the tool it configures:

npm install --save-dev @cldmv/configs@latest @cldmv/fix-headers@latest prettier@latest eslint@latest vitest@latest @vitest/coverage-v8@latest

Install only the tools whose config the repository uses. @cldmv/configs itself brings the ESLint plugins that eslint.config.mjs imports; they are its dependencies, so nothing else needs installing for ESLint.

A repository that formats .jsonv files also installs the jsonv plugin, the optional peer dependency that prettier.json loads:

npm install --save-dev @cldmv/prettier-plugin-jsonv@latest

πŸš€ Quick Start

CLI

cldmv-configs is the adoption path. Run it from the root of the repository after installing the package:

npx cldmv-configs init

init creates, only where the file is missing and never overwriting, .configs/fix-headers.json, .configs/prettier.config.mjs, .configs/eslint.config.mjs, .configs/vitest.config.mjs and .prettierignore, then adds the standard npm scripts (format, format:check, lint, lint:fix, fix:headers, test, coverage) to package.json. An existing file or script is reported as kept and never changed. package.json keeps its indentation and key order, but it is re-serialized when scripts are added, so an inline array such as "files": ["a", "b"] is expanded until npm run format collapses it again. Every created, added and kept item is printed. --dry-run prints the same list and writes nothing.

Command What it does Exit codes
cldmv-configs init Creates the missing stubs and .prettierignore, and adds the missing standard scripts 0 ok, 2 usage or I/O error
cldmv-configs check Reports drift without writing: each stub exists and still references the @cldmv/configs base, the .prettierignore managed block matches the shipped one, and @cldmv/configs is installed where a stub imports it (these are problems), and each standard script exists and references its stub (these are warnings). It never judges the repository's own additions 0 ok, 1 problems (or warnings with --strict), 2 usage or I/O error
cldmv-configs sync Rewrites only the managed block of .prettierignore from the shipped file, leaving every byte outside the markers alone. It refuses (exit 1, with a diff) when the file has no markers 0 ok, 1 refused, 2 usage or I/O error
cldmv-configs types build / types check Builds and checks the repository's <pkg>-types declarations package; see Types packages. Never publishes 0 ok, 1 problems, 2 usage or I/O error

Every command takes --help, and --json prints a machine-readable summary instead of plain lines. check is meant for CI and fleet sweeps: it exits 1 on drift and prints one line per item. sync is for the ignore list only; the stubs extend the shared files at run time, so a new release needs no sync for them.

npx cldmv-configs check            # CI: exit 1 on drift
npx cldmv-configs check --strict   # also fail on missing or detached scripts
npx cldmv-configs sync --dry-run   # preview the ignore-list refresh

init takes --scripts prettier to name the Prettier scripts prettier:write and prettier:check instead of format and format:check; check accepts either pair as equivalent. --ignore-file <path> moves the managed ignore block (see Prettier ignore). check also reports, as a problem, a package whose .configs/ stub imports @cldmv/configs while the package does not depend on it, and prints the install command (the CLI never installs anything). In a workspace, --workspaces runs any command in every package; see Monorepos.

The sections below show what init creates and how to set each tool up by hand.

fix-headers

npx cldmv-configs init creates .configs/fix-headers.json and the fix:headers script. To do it by hand, create the repository's own config, .configs/fix-headers.json, extending the shared file:

{
	"extends": "@cldmv/configs/fix-headers.json"
}

Add an npm script that runs fix-headers against it:

{
	"scripts": {
		"fix:headers": "fix-headers --config .configs/fix-headers.json"
	}
}

Preview the first run before writing anything, then apply it:

npx fix-headers --config .configs/fix-headers.json --dry-run --diff --verbose
npm run fix:headers

A first run rewrites many headers across the repository, so land it when no open pull request touches the same files.

Prettier

npx cldmv-configs init creates .configs/prettier.config.mjs, .prettierignore and the format scripts. To do it by hand, create the repository's own config, .configs/prettier.config.mjs, re-exporting the shared file:

import base from "@cldmv/configs/prettier.json" with { type: "json" };

export default base;

Point the npm scripts at it:

{
	"scripts": {
		"format": "prettier --config .configs/prettier.config.mjs --write .",
		"format:check": "prettier --config .configs/prettier.config.mjs --check ."
	}
}

Copy the shared ignore list to .prettierignore as described in Prettier ignore below.

prettier.json loads @cldmv/prettier-plugin-jsonv, so a repository that formats .jsonv files installs that plugin alongside this package. A repository with no .jsonv files does not need the plugin: spread the base and drop plugins and the jsonv override.

import base from "@cldmv/configs/prettier.json" with { type: "json" };

export default {
	...base,
	plugins: [],
	overrides: base.overrides.filter((entry) => entry.files !== "*.jsonv")
};

Preview the first run before writing anything, then apply it. A first run can reformat many files, so land it when no open pull request touches the same files.

npx prettier --config .configs/prettier.config.mjs --check .
npm run format

Prettier ignore

Prettier has no way to extend another ignore file, so the shared list lives in a managed block inside the repository's own .prettierignore. npx cldmv-configs init creates the file with the block; npx cldmv-configs sync refreshes it later. The file looks like this:

# >>> @cldmv/configs prettierignore v1.3.0 β€” managed block, do not edit between the markers; run `npx cldmv-configs sync` to refresh
…the shared ignore lines, each group with a one-line reason…
# <<< @cldmv/configs prettierignore
# Repo-specific ignores go below this line; they survive every sync. Use `!path` to re-include something the managed block ignores.

The rule is simple: everything between the two marker lines belongs to the package and is replaced on every sync; everything outside them belongs to the repository and is never touched. Add the repository's own paths below the closing marker, and use !path there to re-include something the block ignores. The version in the opening marker is the package version at the time of the sync. check compares the block text (not the version) with the shipped block and exits 1 if they differ, so an edit inside the markers is caught. Because .prettierignore is a normal file in the repository, Prettier and editors that format on save read it with no flags.

A .prettierignore that already exists without markers is never rewritten: sync refuses, prints the diff between the file and the shipped block, and exits 1. Add the two marker lines around the shared lines (or rename the file and run init, then move the repository's own lines below the closing marker), then sync again. This repository keeps its .prettierignore the same way, and a test checks that its managed block equals the shipped one.

The managed block can live somewhere other than .prettierignore: --ignore-file .configs/.prettierignore makes init, check and sync use that path, and init then writes the Prettier scripts with --ignore-path .gitignore --ignore-path .configs/.prettierignore. Prettier resolves the patterns relative to the ignore file's folder and still matches dist/ at the repository root.

The alternative, for a repository with no ignore rules of its own that does not need editor support, is to point Prettier at the installed file in the npm scripts. --ignore-path replaces Prettier's defaults, so .gitignore is passed explicitly as well:

{
	"scripts": {
		"format": "prettier --config .configs/prettier.config.mjs --ignore-path .gitignore --ignore-path node_modules/@cldmv/configs/prettierignore --write .",
		"format:check": "prettier --config .configs/prettier.config.mjs --ignore-path .gitignore --ignore-path node_modules/@cldmv/configs/prettierignore --check ."
	}
}

Editors that run Prettier do not see this form, so they ignore nothing from the shared list.

ESLint

npx cldmv-configs init creates .configs/eslint.config.mjs and the lint scripts. To do it by hand, create the repository's own config, .configs/eslint.config.mjs, spreading the shared array and appending the repository's own blocks:

import base from "@cldmv/configs/eslint.config.mjs";

export default [
	...base,
	{
		files: ["src/**/*.mjs"],
		rules: { "no-console": "warn" }
	}
];

Add the npm scripts:

{
	"scripts": {
		"lint": "eslint --config .configs/eslint.config.mjs .",
		"lint:fix": "eslint --config .configs/eslint.config.mjs . --fix"
	}
}

A repository that needs an extra ignore (a generated folder, a bin/ output) adds a block with only ignores: { ignores: ["bin/**"] }. The base lints .configs/ like any other script, so an unused or unspread import in a tool config is reported.

Scripts get the Node globals only. A repository with browser code, or with Vitest globals: true, adds the matching opt-in block; see Browser and Vitest globals.

Vitest

npx cldmv-configs init creates .configs/vitest.config.mjs and the test and coverage scripts. To do it by hand, create the repository's own config, .configs/vitest.config.mjs, merging its settings over the shared base:

import { defineConfig, mergeConfig } from "vitest/config";
import base from "@cldmv/configs/vitest.config.mjs";

export default mergeConfig(
	base,
	defineConfig({
		test: {
			coverage: { include: ["src/**"] }
		}
	})
);

Run Vitest with --config .configs/vitest.config.mjs. mergeConfig concatenates arrays, so a repository's include or coverage.reporter adds to the base entries instead of replacing them.

A package with a <pkg>-dev export condition (the one that points . at src/) adds devCondition() so its tests load src/:

import { defineConfig, mergeConfig } from "vitest/config";
import base, { devCondition } from "@cldmv/configs/vitest.config.mjs";

export default mergeConfig(
	mergeConfig(base, devCondition({ root: new URL("..", import.meta.url) })),
	defineConfig({
		test: {
			coverage: { include: ["src/**"] }
		}
	})
);

πŸ“‹ Configs

File Tool Specifier What it sets
fix-headers.json @cldmv/fix-headers @cldmv/configs/fix-headers.json CLDMV's standard file-header options: author and company identity, copyright range, and the created-date checks
prettier.json prettier @cldmv/configs/prettier.json CLDMV's house formatting: tabs, a 140-column width, preserved quote props and prose wrapping, and the jsonv plugin
prettierignore prettier @cldmv/configs/prettierignore The paths every repository keeps out of Prettier: dependencies, build output, scratch folders, lockfiles, minified files and YAML
eslint.config.mjs eslint @cldmv/configs/eslint.config.mjs CLDMV's flat ESLint config as an array: JavaScript, JSON, jsonv, Markdown and CSS blocks, house no-unused-vars pattern, Node globals
eslint-plugin.mjs eslint @cldmv/configs/eslint-plugin.mjs CLDMV's ESLint plugin: the cldmv/ test rules and a configs.recommended block for test files; see Test rules
vitest.config.mjs vitest @cldmv/configs/vitest.config.mjs CLDMV's base Vitest settings as a plain object: test file pattern, node environment, v8 coverage and its reporters

Each file is exposed through package.json exports, so it resolves by its specifier from any project that installs the package, and is also reachable by URL straight from this repository. The .mjs files are ES modules and eslint.config.mjs imports the ESLint plugins from the package's dependencies, so use them through the installed package; the raw-URL form only suits the plain-data files.


🧾 fix-headers.json

{
	"includeFolders": ["."],
	"useGpgSignerAuthor": true,
	"company": "CLDMV",
	"companyName": "Catalyzed Motivation Inc.",
	"copyrightStartYear": 2013,
	"forceAuthorUpdate": false,
	"forceLastModifiedAuthorUpdate": false,
	"fixCreatedDate": true,
	"normalizeDateFormat": true,
	"strictCreatedDate": true,
	"margin": 1
}
Option Value Effect
includeFolders ["."] Scan the whole project; ignore files (.gitignore and everything else git honours) still exclude what they list
useGpgSignerAuthor true Take the @Author name from the user ID of the OpenPGP key git signs commits with
company "CLDMV" Write @Author as Name <CLDMV>
companyName "Catalyzed Motivation Inc." The copyright holder in @Copyright. fix-headers v2 has no built-in holder and otherwise reads it from the manifest author (CLDMV)
copyrightStartYear 2013 The first year of the @Copyright range, for every file
forceAuthorUpdate false Never rewrite an existing @Author / @Email; they record who created the file. A missing value is still filled in
forceLastModifiedAuthorUpdate false @Last modified by follows real edits: it changes only when a file's content was edited, not when fix-headers only rewrites the header (fix-headers 2.2.0+)
fixCreatedDate true Move an existing @Date back to the oldest of itself, the file's first git commit and its filesystem creation time
normalizeDateFormat true Write every header date in the git %aI form (2026-03-01T17:59:32-08:00)
strictCreatedDate true With --check, fail on an @Date later than the file's first commit or creation time instead of only warning
margin 1 One blank line between the header and the file's next content. The fix-headers default is two, which prettier collapses to one

An existing @Author is never rewritten: it records who created the file, and this config sets forceAuthorUpdate to false explicitly so the decision is visible and wins over anything earlier in an extends chain. A repository can turn it on in its own config for a one-off migration of old author names.

@Last modified by records the last person to edit the file. With fix-headers 2.2.0 or later it changes only when the file's content was edited; a run that only rewrites the header (date format, spacing, a corrected @Date) updates @Last modified time but keeps @Last modified by. This config therefore sets forceLastModifiedAuthorUpdate to false as well. With fix-headers before 2.2.0 that setting keeps the existing @Last modified by on every run, so upgrade fix-headers alongside this config.

The full description of every option is in the fix-headers README.

Using it by URL

Without installing the package, extends can point at the raw file in this repository. fix-headers fetches a URL on every run, with no local cache, so pin the URL to a release tag; the settings then change only when the repository moves to a newer tag:

{
	"extends": "https://raw.githubusercontent.com/CLDMV/configs/v1.1.0/fix-headers.json"
}

Release tags follow the package version (vX.Y.Z); the releases page lists them. A URL on master instead of a tag always follows the latest shipped settings, which is rarely what a repository wants.

Overriding keys

A key set in the repository's own .configs/fix-headers.json overrides the same key from the shared file, and every key it leaves out keeps the shared value. Plain objects merge key by key; arrays and scalars replace. A repository that should only scan its source, tests and root files, for example:

{
	"extends": "@cldmv/configs/fix-headers.json",
	"includeFolders": ["src", "tests", { "path": ".", "recursive": false }],
	"excludeFolders": ["tests/fixtures"]
}

Keep overrides to what is genuinely specific to the repository. A setting every repository would want belongs in the shared file.


🎨 prettier.json

{
	"useTabs": true,
	"tabWidth": 2,
	"printWidth": 140,
	"trailingComma": "none",
	"quoteProps": "preserve",
	"bracketSpacing": true,
	"overrides": [
		{
			"files": "*.xml",
			"options": {
				"printWidth": 300
			}
		},
		{
			"files": "*.md",
			"options": {
				"proseWrap": "preserve"
			}
		},
		{
			"files": "*.jsonv",
			"options": {
				"parser": "jsonv"
			}
		}
	],
	"plugins": ["@cldmv/prettier-plugin-jsonv"]
}
Option Value Effect
useTabs true Indent with tabs
tabWidth 2 A tab counts as two columns when Prettier measures line width
printWidth 140 Wrap lines at 140 columns instead of the default 80, which keeps short call chains and object literals on one line
trailingComma "none" No trailing commas in multi-line literals, calls or parameter lists
quoteProps "preserve" Leave object-key quoting as written, so keys that must be quoted (HTTP headers, JSON-like data) can sit next to unquoted ones
bracketSpacing true Spaces inside object braces: { a: 1 }
overrides for *.xml printWidth: 300 XML is wrapped at 300 columns; its markup does not wrap readably at 140
overrides for *.md proseWrap: "preserve" Markdown paragraphs are never re-flowed: one paragraph per line, so a one-word edit stays a one-line diff
overrides for *.jsonv parser: "jsonv" Parse .jsonv files with the jsonv plugin's parser
plugins ["@cldmv/prettier-plugin-jsonv"] Load the jsonv plugin, which provides that parser. An optional peer dependency of this package

YAML is not configured here. CI workflow files are four-space indented by convention and YAML forbids tabs, so repositories keep *.yml and *.yaml out of Prettier with the shared prettierignore rather than have it reindent every workflow.

The jsonv plugin is optional

Prettier fails to start when a config names a plugin it cannot load, so a repository that extends prettier.json without installing @cldmv/prettier-plugin-jsonv gets an error naming the plugin. The package declares the plugin as an optional peer dependency (peerDependenciesMeta), so npm does not install it for you and does not warn when it is absent. Install it in repositories that format .jsonv files, or drop plugins and the *.jsonv override as shown in Prettier under Quick Start.

Overriding options

The repository's own .configs/prettier.config.mjs is plain JavaScript, so it can spread the shared object and override any key. overrides and plugins are arrays, and a spread replaces them rather than merging, so list every entry you want to keep:

import base from "@cldmv/configs/prettier.json" with { type: "json" };

export default {
	...base,
	printWidth: 120,
	overrides: [...base.overrides, { files: "*.html", options: { printWidth: 200 } }]
};

This repository uses the file the same way: its .configs/prettier.config.mjs re-exports ../prettier.json, so the repository is formatted by the exact file it publishes.


πŸ™ˆ prettierignore

node_modules/
dist/
build/
coverage/
tmp/
trash/
package-lock.json
pnpm-lock.yaml
*.min.*
*.yml
*.yaml

The file in the repository carries a one-line comment above each group; the list above is the patterns only. The shared lines sit between the opening and closing managed-block markers described under Prettier ignore.

Pattern Why it is ignored
node_modules/ Installed dependencies
dist/, build/, coverage/ Build and test output, not hand-authored
tmp/, trash/ Scratch and discarded work
package-lock.json, pnpm-lock.yaml Generated by the package manager
*.min.* Minified or compact generated files of any extension (*.min.js, *.min.css, *.min.json); name compact data files <name>.min.json
*.yml, *.yaml CI workflow files are four-space indented and YAML forbids tabs, so Prettier at tabWidth 2 would reindent every workflow

After the closing marker the file ends with a note that repository-specific ignores go below it, where they survive every sync. See Prettier ignore under Quick Start for the managed-block rule, sync, and the --ignore-path alternative.


🧹 eslint.config.mjs

The module default-exports an array of flat-config blocks built with defineConfig from eslint/config. Spread it into the repository's own array and append blocks after it, as in the ESLint Quick Start.

Block (files) What it sets
Ignores tmp/, trash/, node_modules/, dist/, build/, .git/, .vscode/, coverage/, minified files, package-lock.json and "copy" duplicates of files and folders
**/*.{js,mjs,cjs} @eslint/js recommended, with no-unused-vars ignoring names that match ^(_|___.*)$ (a lone _, or three or more leading underscores) for variables, arguments, caught errors and destructured array items
**/*.js sourceType: "commonjs"; .mjs files stay ES modules
**/*.{js,mjs,cjs} Node globals (globals.node) only
**/*.json, **/*.jsonc, **/*.json5 @eslint/json recommended, parsing each as JSON, JSONC or JSON5
**/*.jsonv @cldmv/eslint-plugin-jsonv recommended, with language: "jsonv/jsonv"
**/*.md @eslint/markdown recommended on GitHub-flavoured Markdown, with markdown/no-missing-label-refs off because GitHub alerts such as [!NOTE] trip it
**/*.css @eslint/css recommended

There is no HTML block: linting HTML is specific to a few repositories, which add a block of their own. The ESLint plugins and globals are dependencies of this package, so a repository does not install them itself.

Browser and Vitest globals

The base declares the Node globals only, so window, document, self and the other browser globals are reported by no-undef in a script, and so are describe, it and expect in a test that doesn't import them. Two named exports add them back where a repository really has them:

Export What it returns
withBrowserGlobals(files?) A block with globals.browser for files (default: every **/*.{js,mjs,cjs} script). Use it for code that runs in a browser.
withVitestGlobals(files?) A block with the Vitest globals, read-only, for files (default: tests/**/*.test.vitest.mjs). Use it only when the repository's Vitest config sets test.globals: true.
import base, { withBrowserGlobals, withVitestGlobals } from "@cldmv/configs/eslint.config.mjs";

export default [...base, withBrowserGlobals(["src/browser/**/*.mjs"]), withVitestGlobals()];

Without withVitestGlobals(), tests import what they use: import { describe, it, expect } from "vitest";.

Test rules (eslint-plugin.mjs)

@cldmv/configs/eslint-plugin.mjs is an ESLint plugin with the fleet's own rules, under the cldmv/ prefix. Its configs.recommended block turns them all on for test files (tests/**/*.{js,mjs,cjs} and **/*.test.vitest.mjs):

import base from "@cldmv/configs/eslint.config.mjs";
import cldmv from "@cldmv/configs/eslint-plugin.mjs";

export default [...base, cldmv.configs.recommended];

For tests elsewhere, replace the block's files: { ...cldmv.configs.recommended, files: ["spec/**/*.mjs"] }.

Rule What it reports
cldmv/no-regex-in-tomatchobject A RegExp in the expected value of toMatchObject. Vitest treats it as matching anything, so toMatchObject({ message: /x/ }) can never fail. Use expect.stringMatching(/x/), which compares correctly.

no-regex-in-tomatchobject walks only the literal passed to toMatchObject (property values, array elements, object and array spreads) and stops at nested calls, so expect.stringMatching, objectContaining and arrayContaining are never flagged. It reports a regex literal, RegExp() and new RegExp() (also through globalThis), a regex in a ternary, a ?? / || / && operand, the last item of a sequence, the right side of an assignment or an await, and a const initialised with one of those. It can't see a regex held in a let, a parameter, an import or an object member, or an expected value that isn't a literal; the rule file lists every blind spot.

A repository that carries its own copy of the rule (.configs/eslint-rules/no-regex-in-tomatchobject.mjs, registered as local/no-regex-in-tomatchobject) deletes the copy and its block, and spreads cldmv.configs.recommended instead.


πŸ§ͺ vitest.config.mjs

The module default-exports a plain object and imports only Node built-ins, so it needs nothing installed and can be merged into any Vitest config with mergeConfig, as in the Vitest Quick Start.

export default {
	test: {
		environment: "node",
		include: ["tests/**/*.test.vitest.{js,mjs,cjs}"],
		coverage: {
			provider: "v8",
			reporter: ["text", "json", "json-summary", "lcov"],
			reportsDirectory: "coverage"
		}
	}
};
Option Value Effect
test.environment "node" Run tests in Node.js
test.include ["tests/**/*.test.vitest.{js,mjs,cjs}"] Test files live under tests/ and are named *.test.vitest.<ext>, the fleet-wide naming
test.coverage.provider "v8" Measure coverage with V8's built-in collector (needs @vitest/coverage-v8)
test.coverage.reporter ["text", "json", "json-summary", "lcov"] Console table, the raw and summary JSON that CI's coverage badge and PR comment read (coverage/coverage-summary.json), and lcov for editors and uploaders
test.coverage.reportsDirectory "coverage" Write reports to coverage/, which .gitignore and the Prettier ignore already exclude

Vitest 4 and 5 are both supported (peerDependencies.vitest is ^4.0.0 || ^5.0.0); the base was checked under 4.1 and 5.0.

A monorepo that already has a shared Vitest helper of its own (a workspace package, for example) should merge the base for the coverage provider and reporters and keep its own test.include. The base's tests/**/*.test.vitest.{js,mjs,cjs} glob would pull every test tier into one run, which is wrong when the repository splits tiers by directory (unit tests against docker-backed integration tests, say). mergeConfig concatenates include, so to keep only your own globs set them on the base copy instead of merging over it:

import { defineConfig, mergeConfig } from "vitest/config";
import base from "@cldmv/configs/vitest.config.mjs";

const test = { ...base.test };
delete test.include;

export default mergeConfig({ ...base, test }, defineConfig({ test: { include: ["tests/unit/**/*.unit.test.vitest.mjs"] } }));

Coverage include and exclude globs, thresholds, root, timeouts and reporters are repository-specific and stay in the repository's own config. mergeConfig concatenates arrays, so a repository that lists its own coverage.reporter entries adds to these four.

devCondition()

A CLDMV library's exports has a <pkg>-dev condition that points . at src/ instead of dist/. Tests run against src/ through it, which takes the condition in three places. devCondition() returns all three, ready to merge:

devCondition({ root: new URL("..", import.meta.url) });
// {
// 	resolve: { conditions: ["wisp-dev", "module", "browser", "development|production"] },
// 	ssr: { resolve: { conditions: ["wisp-dev", "module", "node", "development|production"] } },
// 	test: { execArgv: ["--conditions=wisp-dev"] }
// }
Setting Why
resolve.conditions Vite's resolver picks src/ for imports in test files. Setting it replaces Vite's defaults, so they follow the condition (exported as VITE_CLIENT_CONDITIONS)
ssr.resolve.conditions The same for Vite's server-side resolver, which Vitest uses for Node tests (VITE_SERVER_CONDITIONS)
test.execArgv Vitest's worker processes start with --conditions=<name>, so Node's own resolver (a require(), or anything Vite doesn't load) picks src/ too

test.nodeOptions is not a Vitest option; a config that sets it passes nothing to the workers. Use test.execArgv, or devCondition().

The argument is the condition name (devCondition("wisp-dev")), or { name, root }. With no name, it is read from <root>/package.json (root defaults to the current directory, and may be a path or a file URL): the one condition ending in -dev on the . export, otherwise the unscoped package name plus -dev. Several -dev conditions, or no condition and no name, throw instead of guessing.


🧩 Types packages

A fleet package can ship its TypeScript declarations as a separate package, <root name>-types (for example @cldmv/uuid-types), an optional peer that only TypeScript users install. The runtime package keeps one small stub per published types target under types/stub/, and each stub re-exports the same subpath from the types package. cldmv-configs types builds and checks that pair. It never publishes and never touches the network: publishing stays in CI (publish.yml extra_packages).

npx cldmv-configs types build   # stubs into types/stub/, the carved package into dist-packages/<pkg>-types/
npx cldmv-configs types check   # resolution checks, then the tsc consumer check

Run types build after the repository's own types:build (tsc) has written the declarations. The usual wiring is "build:subpackages": "cldmv-configs types build" and "test:types": "cldmv-configs types check", both in build:ci. Both commands take --root <dir> (default: the current directory) and --json.

What it reads.

  • The root package.json: every types target in exports and imports, at any condition depth (types, browser.types, types.node, ...), and the top-level types field. The <pkg>-dev condition (any condition ending in -dev) is skipped, because it points into the repository rather than the published tree.
  • packaging/<pkg>-types/package.json, which is required. name must be <root name>-types; description and keywords are optional; "private": true is refused.
  • .configs/types-package.json, optional:
Key Default Effect
source The folder holding the real declarations: found from the <pkg>-dev types targets, otherwise the first of types/src, types/core, types that has every stubbed file Where the declarations are copied from
includeMaps false Copy the .d.*ts.map files too. Without it the maps stay out and sourceMappingURL comments are stripped
exclude [] Globs, relative to source, left out of the carve. Excluding a file the root publishes is a problem
tsc { "enabled": true } { "enabled": false, "reason": "..." } skips the tsc consumer check; the reason is required and printed on every types check

types build never writes the root package.json. Its published types conditions must already point at ./types/stub/... (the <pkg>-dev condition keeps pointing at the real declarations); when one does not, the build fails and prints the stub path to use. Otherwise it empties and rewrites both output folders:

  • types/stub/: one stub per published target, at the target's path. A stub is export * from "<pkg>-types/<subpath>";, plus export { default } from ... when the real declaration has a default export (export default, as default, or a re-exported export { default } from). A conditional variant such as browser.types gets its own stub with the same re-export; the consumer's conditions pick the variant inside the types package.
  • dist-packages/<pkg>-types/: the declarations from source, a LICENSE copied from the root (a root without one is a problem), the README.md from packaging/<pkg>-types/README.md or a short generated one, and a package.json built in three layers. Inherited from the root: license, author, contributors, funding, repository (with directory set to packaging/<pkg>-types), bugs, homepage, publishConfig, type and engines. Authored in the packaging manifest: name, description (default TypeScript declarations for <root name>) and keywords. Computed: version (the root's), exports mirroring every root export that has a types target with the same subpaths and condition nesting and the paths rewritten, imports for the #... entries the declarations use (their files are copied too; an entry pointing straight at a declaration file counts without a types key), files, and the root package as an optional peer, ^<major>.0.0 (^0.<minor>.0 before 1.0.0). Every package the declarations import by name (Node built-ins aside) becomes a required peer with the range the root declares for it in dependencies, peerDependencies or optionalDependencies, so a strict pnpm install can resolve it from the types package; a package the root doesn't depend on is a problem. A published target that points outside the repository (absolute, or climbing out with ..) is a problem too.

Then it runs the repository's own fix-headers over the carved package, from the repository root: node_modules/.bin/fix-headers --config .configs/fix-headers.json --input dist-packages/<pkg>-types. When fix-headers or that config is missing it warns and skips; --no-headers skips it on purpose.

types check writes nothing in the repository. It checks that every published types target points at an existing stub, that every stub re-exports a subpath the carved package.json exports and that subpath's files exist, that the carved version matches the root's, and that every #... import and relative import in the carved declarations resolves inside the carved package. Then, by default, it type-checks a generated consumer.mts that imports every typed subpath (and its default export, when there is one) with the repository's own typescript, against the root package and the carved package installed side by side in a temporary project in the system temp folder (os.tmpdir(), a fresh cldmv-types-check-* folder per run). That is a deliberate exception to keeping scratch in the repository's tmp/: module resolution walks up through every parent node_modules, so a project under the repository would find packages in the repository's own node_modules and hide a dependency the types package doesn't declare. The folder is removed on every exit path, success, failure, or SIGINT/SIGTERM/SIGHUP. The root package goes in as the files npm pack would publish (scripts are not run), so a stub left out of files fails the check, and the carved package's peers are linked in from the repository's node_modules. It runs once with nodenext resolution and once with bundler resolution, both with @types/node when it's installed. A package that declares a browser condition runs the bundler check with that condition and without @types/node instead, since its browser declarations promise to work without Node's globals. When the package exports a require entry or ships .d.cts files, the nodenext run also type-checks a consumer.cts, and every other condition on a types leaf (say deno) gets a nodenext run of its own with that condition set. A repository without typescript in its node_modules fails with the install command. To skip the tsc step, set tsc.enabled: false with a reason in the config, or pass --no-tsc --reason "<text>"; a missing reason is an error.


🏒 Monorepos

The same three commands serve a single package and a workspace. With no flag they act on the current directory only. In a workspace root they print a hint and still run on the root alone; add --workspaces to cover every package.

npx cldmv-configs init --workspaces                  # every workspace package
npx cldmv-configs check --workspaces --root          # every package and the root
npx cldmv-configs sync --workspaces --dry-run        # preview the ignore-list refresh everywhere

Finding the packages. The globs come from pnpm-workspace.yaml (packages:) or, without that file, from package.json workspaces (an array, or { "packages": [...] }). The matcher supports *, ** (any depth, including none), trailing /** and ! exclusions, never enters node_modules, and keeps only directories that have a package.json. The workspace root is added with --root. Each package gets its own .configs/ stubs, ignore file and scripts, and the commands run in each directory in turn.

Output. One line per package, with the details of anything that is not ok or kept indented below it, then a summary line. Exit codes aggregate: any problem in any package makes the exit code 1. --json nests the results per package (packages[].path, .ok, .problems, .warnings, .results).

pnpm needs the dependency in every package. The stubs import @cldmv/configs. npm hoists it from the workspace root, but pnpm's strict layout does not, so under pnpm (a pnpm-lock.yaml or pnpm-workspace.yaml is present) each package must list it itself. check reports a missing one as a problem and prints the command; init prints it as a hint. Neither runs an install. To add it everywhere at once:

pnpm add -D @cldmv/configs@latest -r

or for one package, pnpm add -D @cldmv/configs@latest --filter @acme/api. On npm, check accepts the dependency in the package or in the workspace root.

Other options.

Option Effect
--ignore-file <path> Keep the managed ignore block somewhere other than .prettierignore, such as .configs/.prettierignore. init creates it there and writes the Prettier scripts with --ignore-path .gitignore --ignore-path <path> (--ignore-path replaces Prettier's defaults, so .gitignore is passed too); check and sync read it there
--scripts <name> init only: fleet (default) adds format and format:check, prettier adds prettier:write and prettier:check. A pair is never added when either of its names already exists, and check treats the two pairs as equivalent
--root With --workspaces, also run in the workspace root

Worked example. A pnpm workspace with two packages, packages/api (which already has a test script) and packages/web:

acme/
β”œβ”€β”€ pnpm-workspace.yaml     packages: ["packages/*"]
β”œβ”€β”€ pnpm-lock.yaml
β”œβ”€β”€ package.json
└── packages/
    β”œβ”€β”€ api/package.json    "scripts": { "test": "vitest run" }
    └── web/package.json
$ npx cldmv-configs init --workspaces --scripts prettier
packages/api: created 5 file(s), added 6 script(s), kept 1
  created  .configs/fix-headers.json: created
  …
  added    prettier:write: prettier --config .configs/prettier.config.mjs --write .
  …
  hint     @cldmv/configs: not installed yet; install it (init never installs): pnpm add -D @cldmv/configs@latest --filter @acme/api
packages/web: created 5 file(s), added 7 script(s), kept 0
  …
2 package(s): 2 ok, 0 with problems (0 problem(s), 0 warning(s))
2 package(s) lack @cldmv/configs; to add it to every package at once: pnpm add -D @cldmv/configs@latest -r

$ npx cldmv-configs check --workspaces
packages/api: FAIL (1 problem(s), 1 warning(s))
  problem  @cldmv/configs: imported by a .configs/ stub but not in this package's dependencies (pnpm does not hoist it into packages); install it: pnpm add -D @cldmv/configs@latest --filter @acme/api
  warning  test: does not reference .configs/vitest.config.mjs
packages/web: FAIL (1 problem(s), 0 warning(s))
  problem  @cldmv/configs: imported by a .configs/ stub but not in this package's dependencies (pnpm does not hoist it into packages); install it: pnpm add -D @cldmv/configs@latest --filter @acme/web
2 package(s): 0 ok, 2 with problems (2 problem(s), 1 warning(s))
[exit 1]

$ pnpm add -D @cldmv/configs@latest -r
$ npx cldmv-configs check --workspaces
packages/api: ok (0 problem(s), 1 warning(s))
  warning  test: does not reference .configs/vitest.config.mjs
packages/web: ok (0 problem(s), 0 warning(s))
2 package(s): 2 ok, 0 with problems (0 problem(s), 1 warning(s))
[exit 0]

api keeps its own test script, so check warns that it does not reference the shared Vitest stub; the warning does not fail the check unless --strict is passed. A repository with its own shared Vitest helper, as in the Vitest section, keeps its test.include and merges only the base's coverage settings.


βž• Adding a config

  1. Add the file at the package root, named after the tool it configures (<tool>.json, or the filename the tool expects for an ESLint or Vitest module). Keep any imports it needs to a minimum, and add those packages to dependencies; add the tool itself as an optional peer.
  2. List it in package.json files and expose it in exports under its own filename ("./<tool>.json": "./<tool>.json").
  3. Add it to dist_paths in .github/workflows/bundle-size.yml.
  4. Add a row to the Configs table and a section describing its keys.
  5. Add tests under tests/ that check the keys against what the tool accepts.
  6. If consumers need a stub file or npm script for it, add them to the STUBS and SCRIPTS lists in bin/cldmv-configs.mjs, so init creates them and check verifies them.

The suite already checks that every exported JSON file parses, that every exports entry ships, and that npm pack publishes exactly the intended files. That last check lists those files explicitly, so a new config also goes into its expected list.


πŸ”’ Versioning

Consumers pick up a changed default the next time they update, so a change to a shared value is a change in behavior for every repository that extends it.

  • Minor: adding a config, or a key that only makes a tool stricter where it was silent.
  • Major: changing or removing an existing value in a way that alters what the tool writes.
  • Patch: documentation, tests and tooling with no change to any shipped file's settings.

πŸ›  Development

npm install
npm test            # the vitest suite, via @cldmv/vitest-runner
npm run coverage    # the suite with coverage
npm run lint        # eslint
npm run format      # prettier --write
npm run build:ci    # lint + format:check, as CI runs it

The repository follows the CLDMV v4 release flow: work branches off next and merges there, and next ships to master through a release PR that publishes to npm.


🀝 Contributing

Issues and pull requests are welcome. Branch from next with a conventional prefix (feat/, fix/, docs/, …); pushing the branch opens its pull request into next automatically.

Contributors Sponsor shinrai


πŸ”— Links


πŸ“„ License

GitHub license npm license

Apache-2.0 Β© Shinrai / CLDMV

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages