-
-
Notifications
You must be signed in to change notification settings - Fork 264
feat: add Docusaurus plugin #1055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! It's a great start, but I do have a remark.
LGTM! Just to be 100% sure, I think this one's finished, right? |
@webpro Good question, I used Pulling on that thread lead to a few other pieces that I'm looking into. Running knip on the repo with the default entry changes currently returns Unused files (2)
sidebars.js
src/components/HomepageFeatures/index.js
Unused devDependencies (1)
@docusaurus/module-type-aliases package.json:26:6
Unlisted dependencies (5)
@docusaurus/Link src/pages/index.js
@docusaurus/useDocusaurusContext src/pages/index.js
@theme/Layout src/pages/index.js
@site/src/components/HomepageFeatures src/pages/index.js
@theme/Heading src/pages/index.js
The sidebars.js is in the config for the '@docusaurus/plugin-content-docs' as the sidebarPath.
As shown in the unlisted dependencies, docusaurus is using certain scopes(
I'll move the PR back to draft and add a checklist to the top description while working through these. Certainly let me know if not delivering on all of those doesn't seem like the deal breaker I currently think it is. |
Thanks a bunch for running this against the docusaurus starter/app. The custom scoped package specifiers seem indeed blocking, otherwise we'd get the false positives you've listed which are kinda annoying to have to add to There's no generic way to handle this in Knip, other than adding those to the global An idea I had was to go down the AST route (a bit like the SST plugin is doing). But realized we'd have to deal with such imports in MDX files well, which gets ugly quickly. So at this point I'm thinking a reasonable way to do this is to (1) figure out the internal/custom/swizzled "dependencies" we need to ignore/skip (which is already cumbersome enough it seems) and then (2) have a way for the plugin to tell Knip/core about this list (which I could add). Maybe (2) could be done in core by adding a new property to existing inputs/functions like But before I start implementing (2) we should be confident we can make (1) happen. So... WDYT? :) |
@webpro I think that would work for the I could be wrong, but it feels like |
Alright, that's great.
Sounds like something that belongs locally in If it isn't we could consider and try supporting that from plugins as well. That might help solve other cases as well:
Maybe something like a new input type so we can do e.g. |
Looks like |
Not sure if that may in turn require the |
83dfdce
to
61d09ab
Compare
Took the liberty to add Tried a few things, but still can't think of anything better than adding the option to return |
That's great! The site scope changes seem to be working solid. I had seen the production entry change in the knip changelogs and figured that was why the tests in this branch started throwing but I hadn't had a chance to dig. That looks much simpler to understand for plugins going forward. I'll take a look at adding back the small ts,jsx,tsx to production entry change now that things are green again. |
Awesome.
Added a purple box about this: https://knip.dev/guides/writing-a-plugin#7-entry-and-production so hopefully at least it will be a bit more clear to the next developer.
Thanks, we will get there! |
ea72d80
to
7787123
Compare
I've added the Rebased this PR on top of that (which in turn was (re)based on an updated The version of knip that features https://pkg.pr.new/knip@fd6ec64 There's currently one caveat to Happy to hear your thoughts about it. Feel free to hack on this further 😇 |
…heme/Layout, @theme/Heading
Does it make a difference to the configuration hint if the e.g.
|
Or maybe the |
At first sight, feels better to keep logic like this within the plugin. In |
@webpro I think this plugin might be ready to see sunlight. Besides the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one nit, but overall this is pretty great. Glad we ended up with something that has improvements to core and feels manageable even though the underlying tool is heavy on virtual modules (a concept that might require a better solution but we can keep exploring).
...(hasClassicTheme ? [toIgnore('(@theme|@theme-init|@theme-original)/*', 'dependencies')] : []), | ||
// Ignore aliases for @docusaurus/core/lib/client/exports/ https://docusaurus.io/docs/docusaurus-core | ||
toIgnore( | ||
'@docusaurus/(BrowserOnly|ComponentCreator|constants|ExecutionEnvironment|Head|Interpolate|isInternalUrl|Link|Noop|renderRoutes|router|Translate|useBaseUrl|useBrokenLinks|useDocusaurusContext|useGlobalData|useIsBrowser|useIsomorphicLayoutEffect|useRouteContext)', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could create an array somewhere inside this resolveConfig
scope to make this a but more readable/maintainable, such as ["BrowserOnly", ...].join('|')
) so that it won't be such a long line.
Or maybe based on an array similar to FIRST_PARTY_MODULES
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit to add it here: 2e48a79
Ran the plugin against two repos: This turned out to require a few adaptions, and support for Hope you don't mind! WDYT, does it still work well on your own project(s)? |
Don't mind at all! Glad it will work in even more uses. It still works just as well with the projects I've tested it on. |
Thank you so much, @cylewaitforit! Great job 🚀 |
🚀 This pull request is included in v5.56.0. See Release 5.56.0 for release notes. Using Knip in a commercial project? Please consider becoming a sponsor. |
This adds a plugin for Docusaurus.
Issue: #1056
Support for
@site
@docusaurus
@theme
@theme-original
@theme-init