Conversation
commit: |
a06e22b to
db777ca
Compare
|
Copied from #1265: Thanks! I tried your PR and for me it worked pretty well and I could already remove a bit of dead code from my project. 👍 A few things I noticed:
Not sure how much I normally would need to use a knip ignore list (if this exists) as I have never used knip outside of this one nuxt project. |
Will add as entry point.
Would need a reproduction to see/fix properly.
If a file is unused, so are its dependencies (since the file isn't even read/analyzed at all).
That's unexpected, every item of
I guess
Thanks for the feedback! Is this repo public? |
I am using layers extensively in the project and many modules are only added to the
Good question. I have installed the module as described here and configured it similar to as described here.
Unfortunately it is a work project that I cannot share. But I will try to work on a repro for the other points later today/this week. |
That'd be great! No rush, and no use for me working in the dark 😅 |
|
I have created a little demo project with layers, modules, aliases etc here: https://github.com/yschroe/knip-nuxt-repro This is the output of running knip from this PR: Unused files (7)
app/components/AppLogo.vue
layers/core/app/assets/css/main.css
layers/core/app/components/LayerComponent.vue
layers/core/app/types/some-augmentation.d.ts
layers/core/modules/my-module/index.ts
layers/core/modules/my-module/runtime/components/Component.vue
layers/core/modules/my-module/runtime/middleware/module-middleware.ts
Unused dependencies (3)
@iconify-json/lucide package.json:15:6
@nuxt/ui package.json:16:6
tailwindcss package.json:18:6
Unlisted dependencies (1)
vitest-environment-nuxt vitest.config.tsI believe pretty much all of those results are false positives. The For some reason in this repro some files are marked as unused while similar ones are okay in my real project. E.g. the module component or css import are correctly detected in my real project. Hope this helps. |
|
Thanks Yannik, this was super helpful! The main takeaway for me here was that layers should have their |
Thanks for the updates, the list is a lot shorter now for me as well. 👍 |
Resolved for layer dirs separately now. |
|
I have created a minimal reproduction of some false positives that I have in some of my projects. https://github.com/OrbisK/knip-nuxt-reprod
Details |
Not sure if this should even fly: Knip can pass it on to TypeScript (and normal semantics will work), but you'd still need to add wildcards like |
23f8020 to
b6afc01
Compare
|
For what it's worth, from my point of view this is good to go. I am using the pkg.pr.new version since a few weeks in my project and didn't notice any issues. At the very least it is a big improvement over the currently released version. Or do you still see blockers on your side? |
|
Yeah I guess we're good. Just trying to gather as much feedback as I can, as fixing issues in a branch is more comfortable to manage. Expect this out today or tomorrow. |
# Conflicts: # packages/knip/src/plugins/nuxt/index.ts
2719122 to
3d4b341
Compare
|
🚀 This pull request is included in v5.86.0. See Release 5.86.0 for release notes. Using Knip in a commercial project? Please consider becoming a sponsor. |
Add support for auto-imports to the Nuxt plugin, by preprocessing and squeezing import statements back into source files during compilation. This way, Knip can connect exports ↔ imports the regular way.
Caveat: requires
nuxt prepareupfront to generate.nuxtdefinition files for imports & components collection and generate the auto imports map.Install this version of Knip using the pkg-pr-new provided link in the first comment below.
Implementation details:
vue/compiler-sfcto parse.vuefiles (fallback if loadingvue/compiler-sfcfails isn't great but it's what we already had so no regression there I think)..nuxt/components.d.tsand some AST traversals to collect and connect identifiers and import specifiers across scripts and templates) for the.vue(components) +.ts(composables) compilers in the same context, to be used during module resolution in TS program creation. Quite a bit of complexity, but isolated, to let core do its job normally.appdir presence and othernuxt.config.tsoptions (such asserverDir)layers/*/nuxt.config.ts) are resolved resulting in additional entry patterns.references, aliased specifiers resolved from root (e.g.css: ["~/main.css"]in rootnuxt.config.ts) might cause trouble, but workaround might cover bases somewhat (so far so good.. 🤞).