diff --git a/.github/DEVELOPMENT.md b/.github/DEVELOPMENT.md index 01d8768cd..74a607d2f 100644 --- a/.github/DEVELOPMENT.md +++ b/.github/DEVELOPMENT.md @@ -36,35 +36,47 @@ There's a separate guide for [writing a plugin][5]. ## Watcher ```shell -cd packages/knip bun watch ``` Changes in the source code are now automatically picked up, and `knip` is available globally to run from any directory. +## Debugging + +### IDE + +- Open the Knip source repository +- Set a breakpoint in Knip source code +- In the built-in terminal, cd to your project +- Enable e.g. "auto-attach" to Node.js process or "only attach with flag" +- Run: + +```shell +tsx --inspect path/to/knip/packages/knip/src/cli.ts +``` + ## Fixtures & Tests Pull requests should include one or more tests. See the `tests` and `fixtures` directories to find relevant files that you may want to borrow or copy from. -Let's assume you created `fixtures/feature` and `test/feature.test.ts`. Here's 4 -ways to run it: +Assuming you've created `fixtures/feature` and `test/feature.test.ts`, from the +`packages/knip` location, here's 4 ways to run it: -### Run the test +### 1. Run the test ```shell bun test ./test/feature.test.ts ``` -### Run Knip in the directory +### 2. Run Knip in the directory ```shell -cd fixtures/feature -knip +knip --directory fixtures/feature ``` -### Attach debugger to Node.js +### 3. Attach debugger to Node.js Attach to Node.js process launched in terminal in IDE, and then: @@ -73,21 +85,37 @@ cd fixtures/feature tsx --inspect ../../src/cli.ts ``` -### Attach debugger to Bun +### 4. VS Code: Attach to Bun -Set a breakpoint and start Knip with Bun while waiting for the debugger to be -attached: +- Install the + [VS Code Bun extension](https://marketplace.visualstudio.com/items?itemName=oven.bun-vscode) + if you haven't already +- Set a breakpoint and start Knip with Bun while waiting for the debugger to be + attached: ```shell cd fixtures/feature bun --inspect-wait=127.0.0.1:6499/knip run ../../src/cli.ts ``` -Attach the debugger using the "Attach to Bun" launch configuration. +Then run the "Attach to Bun" launch configuration. + +### 5. VS Code: Attach debugger to Bun from a test + +- Install the + [VS Code Bun extension](https://marketplace.visualstudio.com/items?itemName=oven.bun-vscode) + if you haven't already +- Set a breakpoint and run the "Debug Bun test" launch configuration while in + any test file. -### Attach debugger to Bun from a test +### Attach debugger to tests -Run the "Debug Bun test" launch configuration from any test file. +In case you're wondering if/why some code is ever hit, it's possible to attach +the debugger to each test. Set a breakpoint and run all tests (warning: slow): + +```shell +tsx --inspect --test --import ./transform-test.js test/**/*.test.ts +``` ## QA diff --git a/package.json b/package.json index 4e82f7b02..692afe2cf 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "scripts": { "watch": "bun run --cwd packages/knip watch", "docs": "bun run --cwd packages/docs dev", + "test": "bun run --cwd packages/knip test", "format": "biome format .", "lint": "biome lint .", "ci": "biome ci . && installed-check --no-include-workspace-root --ignore-dev"