Skip to content

Commit 36b85ba

Browse files
committed
Update dev doc
1 parent e9416ec commit 36b85ba

2 files changed

Lines changed: 43 additions & 14 deletions

File tree

.github/DEVELOPMENT.md

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,47 @@ There's a separate guide for [writing a plugin][5].
3636
## Watcher
3737

3838
```shell
39-
cd packages/knip
4039
bun watch
4140
```
4241

4342
Changes in the source code are now automatically picked up, and `knip` is
4443
available globally to run from any directory.
4544

45+
## Debugging
46+
47+
### IDE
48+
49+
- Open the Knip source repository
50+
- Set a breakpoint in Knip source code
51+
- In the built-in terminal, cd to your project
52+
- Enable e.g. "auto-attach" to Node.js process or "only attach with flag"
53+
- Run:
54+
55+
```shell
56+
tsx --inspect path/to/knip/packages/knip/src/cli.ts
57+
```
58+
4659
## Fixtures & Tests
4760

4861
Pull requests should include one or more tests. See the `tests` and `fixtures`
4962
directories to find relevant files that you may want to borrow or copy from.
5063

51-
Let's assume you created `fixtures/feature` and `test/feature.test.ts`. Here's 4
52-
ways to run it:
64+
Assuming you've created `fixtures/feature` and `test/feature.test.ts`, from the
65+
`packages/knip` location, here's 4 ways to run it:
5366

54-
### Run the test
67+
### 1. Run the test
5568

5669
```shell
5770
bun test ./test/feature.test.ts
5871
```
5972

60-
### Run Knip in the directory
73+
### 2. Run Knip in the directory
6174

6275
```shell
63-
cd fixtures/feature
64-
knip
76+
knip --directory fixtures/feature
6577
```
6678

67-
### Attach debugger to Node.js
79+
### 3. Attach debugger to Node.js
6880

6981
Attach to Node.js process launched in terminal in IDE, and then:
7082

@@ -73,21 +85,37 @@ cd fixtures/feature
7385
tsx --inspect ../../src/cli.ts
7486
```
7587

76-
### Attach debugger to Bun
88+
### 4. VS Code: Attach to Bun
7789

78-
Set a breakpoint and start Knip with Bun while waiting for the debugger to be
79-
attached:
90+
- Install the
91+
[VS Code Bun extension](https://marketplace.visualstudio.com/items?itemName=oven.bun-vscode)
92+
if you haven't already
93+
- Set a breakpoint and start Knip with Bun while waiting for the debugger to be
94+
attached:
8095

8196
```shell
8297
cd fixtures/feature
8398
bun --inspect-wait=127.0.0.1:6499/knip run ../../src/cli.ts
8499
```
85100

86-
Attach the debugger using the "Attach to Bun" launch configuration.
101+
Then run the "Attach to Bun" launch configuration.
102+
103+
### 5. VS Code: Attach debugger to Bun from a test
104+
105+
- Install the
106+
[VS Code Bun extension](https://marketplace.visualstudio.com/items?itemName=oven.bun-vscode)
107+
if you haven't already
108+
- Set a breakpoint and run the "Debug Bun test" launch configuration while in
109+
any test file.
87110

88-
### Attach debugger to Bun from a test
111+
### Attach debugger to tests
89112

90-
Run the "Debug Bun test" launch configuration from any test file.
113+
In case you're wondering if/why some code is ever hit, it's possible to attach
114+
the debugger to each test. Set a breakpoint and run all tests (warning: slow):
115+
116+
```shell
117+
tsx --inspect --test --import ./transform-test.js test/**/*.test.ts
118+
```
91119

92120
## QA
93121

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"scripts": {
2020
"watch": "bun run --cwd packages/knip watch",
2121
"docs": "bun run --cwd packages/docs dev",
22+
"test": "bun run --cwd packages/knip test",
2223
"format": "biome format .",
2324
"lint": "biome lint .",
2425
"ci": "biome ci . && installed-check --no-include-workspace-root --ignore-dev"

0 commit comments

Comments
 (0)