Skip to content

Commit 4a936ab

Browse files
committed
feat: add import tracing for rich violation diagnostics
1 parent e54d6a4 commit 4a936ab

File tree

5 files changed

+512
-15
lines changed

5 files changed

+512
-15
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,42 @@ export default {
3939
}
4040
```
4141
42+
### Import Tracing
43+
44+
Enable `trace: true` to get rich violation diagnostics with full import chains and code snippets. When enabled, errors are deferred to `buildEnd` so the complete module graph can be collected first.
45+
46+
```js
47+
ImpoundPlugin.rollup({
48+
cwd: dirname(fileURLToPath(import.meta.url)),
49+
trace: true,
50+
patterns: [
51+
[/\.server$/, 'Server-only import', ['Use a server function instead', 'Move this import to a .server.ts file']]
52+
]
53+
})
54+
```
55+
56+
Example output:
57+
58+
```
59+
Invalid import [importing `secret` from `middle.js`]
60+
61+
Trace:
62+
1. src/routes/index.tsx:2:34 (entry) (import "../features/auth/session")
63+
2. src/features/auth/session.ts
64+
65+
Code:
66+
1 | import { logger } from '../utils/logger'
67+
2 |
68+
> 3 | import { getUsers } from '../db/queries.server'
69+
| ^
70+
4 |
71+
5 | export function loadAuth() {
72+
73+
Suggestions:
74+
- Use a server function instead
75+
- Move this import to a .server.ts file
76+
```
77+
4278
## 💻 Development
4379

4480
- Clone this repository

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"test:types": "tsc --noEmit"
3030
},
3131
"dependencies": {
32+
"es-module-lexer": "^2.0.0",
3233
"exsolve": "^1.0.8",
3334
"mocked-exports": "^0.1.1",
3435
"pathe": "^2.0.3",

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)