@@ -36,35 +36,47 @@ There's a separate guide for [writing a plugin][5].
3636## Watcher
3737
3838``` shell
39- cd packages/knip
4039bun watch
4140```
4241
4342Changes in the source code are now automatically picked up, and ` knip ` is
4443available 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
4861Pull requests should include one or more tests. See the ` tests ` and ` fixtures `
4962directories 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
5770bun 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
6981Attach to Node.js process launched in terminal in IDE, and then:
7082
@@ -73,21 +85,37 @@ cd fixtures/feature
7385tsx --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
8297cd fixtures/feature
8398bun --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
0 commit comments