Skip to content

Commit

Permalink
Update dev doc
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Oct 6, 2024
1 parent e9416ec commit 36b85ba
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
56 changes: 42 additions & 14 deletions .github/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 36b85ba

Please sign in to comment.