dt-clean 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [v1.0.1](https://github.com/ljharb/dt-clean/compare/v1.0.0...v1.0.1) - 2026-06-19
9
+
10
+ ### Commits
11
+
12
+ - [Fix] exit nonzero when changes are needed [`7c19b07`](https://github.com/ljharb/dt-clean/commit/7c19b07735c33d4a757f822355fd7a02760f7aed)
13
+ - [readme] use proper indefinite article [`a63be72`](https://github.com/ljharb/dt-clean/commit/a63be726dd3655a1e9bbecc7d8726b8637700888)
14
+ - [Deps] update `semver` [`a93456c`](https://github.com/ljharb/dt-clean/commit/a93456cda93fbde6d1c23b5b76418a60c11b14ea)
15
+ - [Dev Deps] downgrade `@types/node` [`7aa7c07`](https://github.com/ljharb/dt-clean/commit/7aa7c072d0003816e40591b7aa56cdcbe217fa92)
16
+
8
17
  ## v1.0.0 - 2026-06-19
9
18
 
10
19
  ### Commits
package/README.md CHANGED
@@ -12,8 +12,8 @@ Ensures the only DefinitelyTyped (`@types/*`) packages you have installed are th
12
12
  `dt-clean` inspects your `package.json` and, for each dependency, decides what should happen to its DefinitelyTyped types package:
13
13
 
14
14
  - **add**: the runtime package ships no types of its own, but a matching `@types/*` package exists on the registry.
15
- - **move**: an `@types/*` package is in `dependencies`, but belongs in `devDependencies`.
16
- - **remove**: an `@types/*` package is installed but no longer needed: the runtime package now bundles its own types, or it no longer corresponds to any dependency.
15
+ - **move**: a `@types/*` package is in `dependencies`, but belongs in `devDependencies`.
16
+ - **remove**: a `@types/*` package is installed but no longer needed: the runtime package now bundles its own types, or it no longer corresponds to any dependency.
17
17
  - **keep**: the `@types/*` package is present and still needed. `@types/node` is always kept.
18
18
 
19
19
  ## Usage
@@ -49,6 +49,21 @@ With `--update` (`-u`), `dt-clean` edits `package.json` in place - adding, movin
49
49
  - `-u`, `--update`: apply the changes to `package.json` (default: report only).
50
50
  - `--help`: show usage.
51
51
 
52
+ ### Exit codes
53
+
54
+ In the default report-only mode, the exit code is a bitmask of the kinds of pending changes, so a clean project exits `0` and you can fail CI (or a `git` pre-commit hook) on drift:
55
+
56
+ | Value | Meaning |
57
+ | ----- | ---------------------------------------- |
58
+ | `1` | there are `@types/*` packages to remove |
59
+ | `2` | there are `@types/*` packages to add |
60
+ | `4` | there are `@types/*` packages to move |
61
+
62
+ The bits combine, so a project that needs both an add and a remove exits `3`, and one that needs all three exits `7`.
63
+
64
+ With `--update`, `dt-clean` applies the changes, leaving the project clean, so a successful run always exits `0`;
65
+ a nonzero exit then means the update itself failed.
66
+
52
67
  [package-url]: https://npmjs.org/package/dt-clean
53
68
  [npm-version-svg]: https://versionbadg.es/ljharb/dt-clean.svg
54
69
  [npm-badge-png]: https://nodei.co/npm/dt-clean.png?downloads=true&stars=true
package/bin.mjs CHANGED
@@ -7,6 +7,7 @@ import pargs from 'pargs';
7
7
  import getDelTa from '#/getDelTa';
8
8
  import applyChanges from '#/applyChanges';
9
9
  import formatReport from '#/report';
10
+ import exitCode from '#/exitCode';
10
11
 
11
12
  const {
12
13
  values: { json, update },
@@ -64,6 +65,8 @@ if (json) {
64
65
  }
65
66
 
66
67
  if (update) {
68
+ // `--update` applies the changes, leaving the project clean, so a successful run exits zero;
69
+ // only an error (e.g. a failed write, which throws) yields a nonzero exit.
67
70
  const changed = await applyChanges(cwd, {
68
71
  toAdd,
69
72
  toMove,
@@ -72,6 +75,15 @@ if (update) {
72
75
  console.error(changed
73
76
  ? '\nUpdated `package.json`; run `npm install` (or your package manager’s equivalent) to sync.'
74
77
  : '\nNo changes needed.');
75
- } else if (toAdd.size + toMove.size + toRemove.length > 0) {
76
- console.error('\nRe-run with `--update` (`-u`) to apply these changes to `package.json`.');
78
+ } else {
79
+ // report-only: the exit code is a bitmask of the pending change kinds, so a clean project exits zero.
80
+ const code = exitCode({
81
+ toAdd,
82
+ toMove,
83
+ toRemove,
84
+ });
85
+ process.exitCode = code;
86
+ if (code > 0) {
87
+ console.error('\nRe-run with `--update` (`-u`) to apply these changes to `package.json`.');
88
+ }
77
89
  }
package/exitCode.mjs ADDED
@@ -0,0 +1,31 @@
1
+ /** @import { DTDelta } from './getDelTa.d.ts' */
2
+
3
+ export const TO_REMOVE = 1;
4
+ export const TO_ADD = 2;
5
+ export const TO_MOVE = 4;
6
+
7
+ /** @typedef {1 | 2 | 4 | 3 | 6 | 7} PossibleExitCode */
8
+
9
+ /**
10
+ * In report-only mode the exit code is a bitmask of the pending change kinds, so a clean
11
+ * delta is `0` and any combination of kinds combines (e.g. add + remove is `3`).
12
+ *
13
+ * @type {(delta: Pick<DTDelta, 'toAdd' | 'toMove' | 'toRemove'>) => PossibleExitCode}
14
+ */
15
+ export default function exitCode({
16
+ toAdd,
17
+ toMove,
18
+ toRemove,
19
+ }) {
20
+ let code = 0;
21
+ if (toRemove.length > 0) {
22
+ code |= TO_REMOVE;
23
+ }
24
+ if (toAdd.size > 0) {
25
+ code |= TO_ADD;
26
+ }
27
+ if (toMove.size > 0) {
28
+ code |= TO_MOVE;
29
+ }
30
+ return /** @type {PossibleExitCode} */ (code);
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-clean",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Ensures the only DefinitelyTyped (`@types`) packages you have installed are the ones you need",
5
5
  "bin": "./bin.mjs",
6
6
  "exports": {
@@ -40,13 +40,13 @@
40
40
  "es-errors": "^1.3.0",
41
41
  "hastypes": "^4.0.4",
42
42
  "pargs": "^1.4.2",
43
- "semver": "^7.8.4"
43
+ "semver": "^7.8.5"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@arethetypeswrong/cli": "^0.18.3",
47
47
  "@ljharb/eslint-config": "^22.2.3",
48
48
  "@ljharb/tsconfig": "^0.3.2",
49
- "@types/node": "^25.9.3",
49
+ "@types/node": "^24.13.2",
50
50
  "@types/semver": "^7.7.1",
51
51
  "auto-changelog": "^2.6.0",
52
52
  "c8": "^11.0.0",