@prunr/prunr 0.4.0 → 0.5.0

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.
Files changed (2) hide show
  1. package/README.md +141 -81
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -6,38 +6,44 @@
6
6
  </p>
7
7
 
8
8
  <p align="center">
9
- Detector de código morto para Node.js, com CommonJS como cidadão de primeira classe.
9
+ Dead code finder for Node.js, with CommonJS as a first-class citizen.
10
10
  </p>
11
11
 
12
12
  <p align="center">
13
13
  <a href="https://www.npmjs.com/package/@prunr/prunr"><img src="https://img.shields.io/npm/v/@prunr/prunr" alt="npm"></a>
14
- <a href="LICENSE"><img src="https://img.shields.io/npm/l/@prunr/prunr" alt="licença MIT"></a>
14
+ <a href="LICENSE"><img src="https://img.shields.io/npm/l/@prunr/prunr" alt="MIT license"></a>
15
+ </p>
16
+
17
+ <p align="center">
18
+ <a href="https://github.com/ViniciusDev26/prunr/blob/main/README.md"><img src="https://img.shields.io/badge/lang-English-blue" alt="Read in English"></a>
19
+ <a href="https://github.com/ViniciusDev26/prunr/blob/main/README.pt-BR.md"><img src="https://img.shields.io/badge/lang-Portugu%C3%AAs%20(BR)-green" alt="Leia em português"></a>
15
20
  </p>
16
21
 
17
22
  ---
18
23
 
19
- O prunr monta um grafo de módulos a partir dos pontos de entrada do projeto e encontra o que
20
- nada usa: arquivos, exports, imports e dependências. No mesmo grafo, ele aponta dependências não
21
- declaradas, imports circulares e `require` que não dá para seguir.
24
+ prunr builds a module graph from your project's entry points and finds what nothing uses: files,
25
+ exports, imports and dependencies. From the same graph, it points out undeclared dependencies,
26
+ circular imports and `require` calls it cannot follow.
22
27
 
23
- É um binário em Rust, um arquivo de configuração e um comando, no lugar da combinação de
24
- depcheck + madge + scripts próprios.
28
+ It is one Rust binary, one config file and one command, in place of depcheck + madge + custom
29
+ scripts.
25
30
 
26
- - **CommonJS de verdade:** `module.exports`, `exports.x`, desestruturação de `require`, métodos
27
- estáticos e `require` com caminho montado (`` require(`./handlers/${nome}`) ``).
28
- - **ESM e TypeScript no mesmo grafo**, com `paths` do `tsconfig.json` e interop CJS/ESM como no
29
- Node.
30
- - **Entende o seu stack** sem configuração: Jest, Vitest, Playwright, Vite, React, Next.js,
31
- NestJS, Drizzle Kit, PostCSS e monorepos (npm, yarn, pnpm, bun, lerna, rush, nx, turbo).
32
- - **Conserta sozinho:** `prunr fix` apaga o que está morto e limpa o `package.json`.
33
- - **Feito para CI:** anotações no diff do PR, só os achados novos com `--since`, e um baseline
34
- para adotar em código legado.
31
+ - **Real CommonJS:** `module.exports`, `exports.x`, destructured `require`, static methods and
32
+ `require` with a built path (`` require(`./handlers/${name}`) ``).
33
+ - **ESM and TypeScript in the same graph**, with `tsconfig.json` `paths` and CJS/ESM interop the
34
+ way Node does it.
35
+ - **Knows your stack** with no setup: Jest, Vitest, Mocha, `node --test`, tap, AVA, Playwright,
36
+ Vite, React, Next.js, NestJS, Drizzle Kit, PostCSS and monorepos (npm, yarn, pnpm, bun, lerna,
37
+ rush, nx, turbo).
38
+ - **Fixes it for you:** `prunr fix` deletes what is dead and cleans up `package.json`.
39
+ - **Built for CI:** annotations on the PR diff, only new findings with `--since`, and a baseline
40
+ for adopting it on legacy code.
35
41
 
36
- ## Início rápido
42
+ ## Quick start
37
43
 
38
44
  ```sh
39
- npm i -D @prunr/prunr # ou pnpm add -D / yarn add -D / bun add -d
40
- npx prunr init # cria um prunr.json a partir do package.json
45
+ npm i -D @prunr/prunr # or pnpm add -D / yarn add -D / bun add -d
46
+ npx prunr init # creates a prunr.json from package.json
41
47
  npx prunr check
42
48
  ```
43
49
 
@@ -55,16 +61,16 @@ unresolved-require src/index.js: require(process.env.PLUGIN) (warning)
55
61
  errors: 7, warnings: 1
56
62
  ```
57
63
 
58
- (É a saída do projeto em [`tests/fixtures/example/`](tests/fixtures/example/).)
64
+ (That is the output for the project in [`tests/fixtures/example/`](tests/fixtures/example/).)
59
65
 
60
- O pacote baixa só o binário da sua plataforma (Linux x64/arm64, macOS x64/arm64, Windows x64),
61
- sem script de instalação. Os binários também estão em cada
62
- [release](https://github.com/ViniciusDev26/prunr/releases), com `.sha256`.
66
+ The package downloads only the binary for your platform (Linux x64/arm64, macOS x64/arm64,
67
+ Windows x64), with no install script. The binaries are also attached to every
68
+ [release](https://github.com/ViniciusDev26/prunr/releases), each with a `.sha256`.
63
69
 
64
- ## Configuração
70
+ ## Configuration
65
71
 
66
- O `prunr.json` diz por onde o programa começa. Tudo o que essas entradas alcançam está vivo; o
67
- que só os testes alcançam está morto em produção.
72
+ `prunr.json` says where the program starts. Everything those entries reach is alive; what only
73
+ the tests reach is dead in production.
68
74
 
69
75
  ```json
70
76
  {
@@ -76,42 +82,43 @@ que só os testes alcançam está morto em produção.
76
82
  }
77
83
  ```
78
84
 
79
- Os arquivos que os `scripts` do `package.json` rodam (`node src/server.js`, `tsx watch
80
- src/index.ts`) já são entradas, e com Jest, Vitest, Vite, Next.js ou NestJS boa parte do resto o
81
- prunr acha sozinho. Todas as opções estão
82
- em [Configuração](docs/guide/configuration.md).
85
+ The files the `scripts` of `package.json` run (`node src/server.js`, `tsx watch src/index.ts`)
86
+ are entries already, and with Jest, Vitest, Vite, Next.js or NestJS prunr finds most of the rest
87
+ on its own. Every option is in [Configuration](docs/guide/configuration.md).
83
88
 
84
- ## Comandos
89
+ ## Commands
85
90
 
86
- | Comando | O que faz |
91
+ | Command | What it does |
87
92
  |---|---|
88
- | `prunr check` | Lista os achados. `--json` para máquinas, `--github` para anotações no PR, `--since <ref>` para só o que é novo. |
89
- | `prunr fix` | Remove o código morto e as dependências sem uso. `--dry-run` mostra sem mudar nada. |
90
- | `prunr init` | Cria um `prunr.json` a partir do `package.json`. |
91
- | `prunr baseline` | Grava os achados atuais, para adotar o prunr sem consertar tudo de uma vez. |
92
- | `prunr schema` | Imprime o JSON Schema do `prunr.json`. |
93
+ | `prunr check` | Lists the findings. `--json` for machines, `--github` for PR annotations, `--sarif` for code scanning, `--codeclimate` for GitLab Code Quality, `--markdown` for a PR comment, `--since <ref>` for only what is new, `--production` for only what ships. |
94
+ | `prunr fix` | Removes dead code and unused dependencies. `--dry-run` shows the changes without making them. |
95
+ | `prunr why <target>` | Explains a file (the chain of imports from an entry), a `file:export` (who uses it) or a package (the files, scripts and tools that need it). |
96
+ | `prunr init` | Creates a `prunr.json` from `package.json`. |
97
+ | `prunr baseline` | Records the current findings, to adopt prunr without fixing everything at once. |
98
+ | `prunr schema` | Prints the JSON Schema of `prunr.json`. |
93
99
 
94
- O `check` sai com `0` sem achados (ou só com avisos), `1` com achados e `2` quando não consegue
95
- rodar.
100
+ `check` exits with `0` when there are no findings (or only warnings), `1` when there are
101
+ findings, and `2` when it cannot run.
96
102
 
97
- ## O que ele encontra
103
+ ## What it finds
98
104
 
99
- | Achado | Quando |
105
+ | Finding | When |
100
106
  |---|---|
101
- | `unused-file` | Nenhuma entrada de produção alcança o arquivo. |
102
- | `unused-export` | Nenhum código de produção usa o export. |
103
- | `unused-import` | Um `require` ou `import` traz um nome que o arquivo nunca usa. |
104
- | `unused-dependency` | Nada importa o pacote e nenhum script o roda. |
105
- | `misplaced-dependency` | O pacote está em `dependencies`, mas só os testes o usam. |
106
- | `missing-dependency` | O código importa um pacote que o `package.json` não declara. |
107
- | `circular-import` | Há um ciclo de imports. |
108
- | `unused-ignore` | Um comentário `prunr-ignore` que não ignora mais nada. |
109
- | `unresolved-require` | Aviso: um `require` que não dá para seguir. |
110
-
111
- Quando o único uso vem dos testes, o achado diz `(only tests use it)`. Os detalhes de cada um
112
- estão em [Achados](docs/guide/checks.md).
113
-
114
- ## No CI
107
+ | `unused-file` | No production entry reaches the file. |
108
+ | `unused-export` | No production code uses the export. |
109
+ | `unused-import` | A `require` or `import` brings in a name the file never uses. |
110
+ | `unused-dependency` | Nothing imports the package and no script runs it. |
111
+ | `misplaced-dependency` | The package is in `dependencies`, but only the tests use it. |
112
+ | `missing-dependency` | The code imports a package `package.json` does not declare. |
113
+ | `circular-import` | There is an import cycle. |
114
+ | `unused-ignore` | A `prunr-ignore` comment that no longer ignores anything. |
115
+ | `unresolved-require` | Warning: a `require` prunr cannot follow. |
116
+ | `unparsed-file` | Warning: a file the graph reaches does not parse, so what it uses is unknown. |
117
+
118
+ When the only use comes from the tests, the finding says `(only tests use it)`. The details of
119
+ each are in [Findings](docs/guide/checks.md).
120
+
121
+ ## In CI
115
122
 
116
123
  ```yaml
117
124
  - uses: actions/checkout@v4
@@ -121,42 +128,95 @@ estão em [Achados](docs/guide/checks.md).
121
128
  - run: npx prunr check --github --since origin/${{ github.base_ref }}
122
129
  ```
123
130
 
124
- Cada achado novo vira uma anotação na linha certa do diff. Para um código legado, comece com
125
- `prunr baseline`: o que já existe não falha, e o que surgir depois falha. Veja
126
- [CI e código legado](docs/guide/ci.md).
131
+ Each new finding becomes an annotation on the right line of the diff. For legacy code, start
132
+ with `prunr baseline`: what is already there does not fail, and anything that shows up later
133
+ does. See [CI and legacy code](docs/guide/ci.md).
134
+
135
+ ## Guide
127
136
 
128
- ## Guia
137
+ The guide is in Portuguese for now.
129
138
 
130
- - [Configuração](docs/guide/configuration.md): o `prunr.json` e os `scripts` do `package.json`.
131
- - [Achados](docs/guide/checks.md): o que cada um significa, ESM e TypeScript, `require` dinâmico.
132
- - [`prunr fix`](docs/guide/fix.md): o que ele remove e o que deixa para você.
139
+ - [Configuration](docs/guide/configuration.md): `prunr.json` and the `scripts` of `package.json`.
140
+ - [Findings](docs/guide/checks.md): what each one means, ESM and TypeScript, dynamic `require`.
141
+ - [`prunr fix`](docs/guide/fix.md): what it removes and what it leaves to you.
133
142
  - [Frameworks](docs/guide/frameworks.md): Jest, Vitest, Playwright, Vite, React, Next.js,
134
- NestJS, Drizzle Kit e PostCSS.
135
- - [Monorepos](docs/guide/monorepos.md): como os pacotes são encontrados e checados.
136
- - [Ignorar no código](docs/guide/ignore.md): exports públicos de propósito.
137
- - [CI e código legado](docs/guide/ci.md): anotações, `--since` e baseline.
143
+ NestJS, Drizzle Kit and PostCSS.
144
+ - [Monorepos](docs/guide/monorepos.md): how packages are found and checked.
145
+ - [Ignoring in code](docs/guide/ignore.md): exports that are public on purpose.
146
+ - [CI and legacy code](docs/guide/ci.md): annotations, `--since` and the baseline.
147
+
148
+ ## What it leaves out
149
+
150
+ - **Unused variables and private members inside a file** are a linter's job. Turn on
151
+ `noUnusedVariables` and `noUnusedPrivateClassMembers` in [Biome](https://biomejs.dev/):
152
+ together with prunr's `unused-import`, they cover what `tsc`'s `noUnusedLocals` catches.
153
+ - **Formatting, style and types:** use Biome and `tsc --noEmit`.
154
+ - **Dependencies named only in another tool's config** (ESLint plugins, Babel presets) show up
155
+ as `unused-dependency`. List them in `dependencies.ignore`.
156
+
157
+ What comes next is in the [roadmap](docs/roadmap/).
158
+
159
+ ## Why prunr, and not Knip or other tools
160
+
161
+ [Knip](https://knip.dev) is the reference for ESM and TypeScript, and tools like `ts-prune` and
162
+ `unimported` were archived pointing to it. prunr exists for the case Knip treats as secondary:
163
+ **Node.js code in CommonJS**, alone or mixed with ESM.
164
+
165
+ **CommonJS as it is actually written.** Knip asks code to follow a convention so it can
166
+ understand the exports: according to its
167
+ [CommonJS guide](https://knip.dev/guides/working-with-commonjs), only `module.exports.x =` and an
168
+ object with shorthand keys only (`{ a, b }`) are named exports; any other object in
169
+ `module.exports` becomes a single default export, and importing the whole module makes every
170
+ named export show up as unused. prunr reads the code you already have, without asking you to
171
+ change it:
172
+
173
+ ```js
174
+ // invoices.js
175
+ module.exports = {
176
+ total,
177
+ cancel: () => {},
178
+ format(value) { return value; },
179
+ };
180
+
181
+ // index.js
182
+ const invoices = require("./invoices");
183
+ invoices.format(invoices.total());
184
+ const handler = require(`./handlers/${name}`);
185
+ ```
186
+
187
+ prunr reports only `cancel`: it reads each key of the object, follows the use through
188
+ `invoices.x`, and the `require` built at runtime keeps the files in `handlers/` alive. When in
189
+ doubt (the module passed along, a computed key), it treats everything as used: it is better to
190
+ let a dead export through than to tell you to delete a live one.
138
191
 
139
- ## O que fica de fora
192
+ This is not a hypothetical case. prunr was born in a production Node.js project, all in
193
+ CommonJS, that adopted Knip, fixed its entry points, deleted what it pointed out, and ended up
194
+ removing it because of too many false positives. In the same project, prunr pointed out 26 real
195
+ problems (dead files and exports, unused dependencies and a queue shutdown that was never
196
+ called), all of them fixed, and it now runs in CI with no pending findings.
140
197
 
141
- - **Variáveis e membros privados sem uso dentro de um arquivo** são trabalho de linter. Ligue
142
- `noUnusedVariables` e `noUnusedPrivateClassMembers` no [Biome](https://biomejs.dev/): junto com
143
- o `unused-import` do prunr, elas cobrem o que o `noUnusedLocals` do `tsc` pega.
144
- - **Formatação, estilo e tipos:** use Biome e `tsc --noEmit`.
145
- - **Dependências citadas só na configuração de outra ferramenta** (plugins do ESLint, presets do
146
- Babel) aparecem como `unused-dependency`. Liste-as em `dependencies.ignore`.
198
+ **One tool in place of several.** Unused files, exports, imports and dependencies, undeclared
199
+ or misplaced dependencies and circular imports all come out of the same graph, in one command.
200
+ That is the work usually split across `depcheck`, `madge`, `unimported` and custom scripts.
147
201
 
148
- O que vem depois está no [roadmap](docs/roadmap/).
202
+ **Fast, and it runs nothing.** It is a native binary, written in Rust, that reads and resolves
203
+ files in parallel; the npm package only downloads the binary for your platform, with no install
204
+ script. On a monorepo of 13,000 files, the check takes 0.6 s. Tool configs (Jest, Vitest,
205
+ Playwright, Vite...) are read as text, never executed.
149
206
 
150
- ## Por que não o Knip
207
+ **Built to adopt on existing code.** A baseline so you do not have to fix everything at once,
208
+ `--since` and diff annotations to block only what is new in the PR, and a `prunr fix` that
209
+ deletes dead code and cleans up `package.json`.
151
210
 
152
- O Knip é ótimo para ESM e TypeScript, mas não lida bem com CommonJS, e suportá-lo não está nos
153
- planos dele. O prunr começou pelo caminho oposto: Node puro em CommonJS primeiro, e ESM,
154
- TypeScript e frameworks depois, no mesmo grafo.
211
+ **When Knip is the better choice.** On a project that is only ESM and TypeScript, Knip has many
212
+ more plugins (prunr knows Jest, Vitest, Playwright, Vite, React, Next.js, NestJS, Drizzle Kit
213
+ and PostCSS) and more mileage. prunr pays off when there is CommonJS in the mix, or when speed
214
+ and a single tool matter more.
155
215
 
156
- ## Contribuindo
216
+ ## Contributing
157
217
 
158
- O prunr é feito com TDD e 100% de cobertura de testes. Veja [CONTRIBUTING.md](CONTRIBUTING.md).
218
+ prunr is built with TDD and 100% test coverage. See [CONTRIBUTING.md](CONTRIBUTING.md).
159
219
 
160
- ## Licença
220
+ ## License
161
221
 
162
222
  [MIT](LICENSE)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prunr/prunr",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Dead code detector for Node.js, with CommonJS as a first-class citizen",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -26,10 +26,10 @@
26
26
  "node": ">=18"
27
27
  },
28
28
  "optionalDependencies": {
29
- "@prunr/darwin-arm64": "0.4.0",
30
- "@prunr/darwin-x64": "0.4.0",
31
- "@prunr/linux-arm64": "0.4.0",
32
- "@prunr/linux-x64": "0.4.0",
33
- "@prunr/win32-x64": "0.4.0"
29
+ "@prunr/darwin-arm64": "0.5.0",
30
+ "@prunr/darwin-x64": "0.5.0",
31
+ "@prunr/linux-arm64": "0.5.0",
32
+ "@prunr/linux-x64": "0.5.0",
33
+ "@prunr/win32-x64": "0.5.0"
34
34
  }
35
35
  }