-
-
Notifications
You must be signed in to change notification settings - Fork 177
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
Add ladle plugin #728
Add ladle plugin #728
Conversation
✅ Deploy Preview for knip canceled.
|
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 @justb3a! A Ladle plugin is a great addition to Knip.
My main point of feedback is that the fixtures are a bit minimal. Ideally there would be more configuration with stories and components to verify the right files are indeed used as entry files (and they'll probably use dependencies that are then no longer unused).
|
||
const resolveEntryPaths: ResolveEntryPaths<LadleConfig> = async localConfig => { | ||
const localStories = typeof localConfig.stories === 'string' ? [localConfig.stories] : localConfig.stories; | ||
const localViteConfig = localConfig.viteConfig ? [localConfig.viteConfig] : []; |
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.
The Vite config should be handled by the Vite plugin, so I think we can just ignore it here? Btw it would need be a config
file, not an entry
file.
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.
For ladle it might be necessary to have a dedicated / different viteConfig file. So in my case I have ~/.vite.config.ts
and for ladle ~/.ladle/vite.config.ts
. Only if you don't use the default one, this parameter is set and then should be respected. Otherwise, I get it listed as "unused file".
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.
OK in that case I think it's interesting to look into using the resolveConfig
function of the Vitest plugin (which is basically the same as the Vite plugin).
Simplified inside resolveConfig
: const viteDeps = resolveConfig(await load(localConfig.viteConfig))
Does that make sense?
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.
Changed 👍 I wasn't aware that it is allowed to use other plugins.
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.
… I cannot get rid of the message that the file is unused, stuck here.
Unused files (1)
.ladle/vite.config.ts
I also tried things like
const resolveConfig: ResolveConfig<LadleConfig> = async (localConfig, options) =>
resolveVitestConfig(localConfig.viteConfig ? await load(join(process.cwd(), localConfig.viteConfig)) : [], options);
Maybe someone with more insights can help here? 😇
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.
Perhaps confusingly, loading the file does not "use" it (because it's not part of the dependency graph). For this you could add it as an entry file (contrary to what I said earlier, sorry, but that was for another reason).
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.
I re-added it additionally as an entry file 👍
Run & review this pull request in StackBlitz Codeflow. commit: knip
|
@webpro thanks for the feedback. I added some commits on top and extended the fixtures. If you want to have something else regarding fixtures/tests pls give me some hints, I checked some other plugins and couldn't find something helpful. I did not add |
Most plugins should have fixtures for the config and entry files they're referencing in the implementation.
Great, that would be too much indeed. Sometimes a basic |
1e7bb4b
to
67c4e87
Compare
}; | ||
|
||
const resolveConfig: ResolveConfig<LadleConfig> = async (localConfig, options) => | ||
localConfig.viteConfig ? resolveVitestConfig(await load(localConfig.viteConfig), options) : []; |
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.
Please expand it a bit and use something like join(options.configFileDir, localConfig.viteConfig)
so that it is resolved relative the Ladle config file dir.
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.
Oh never mind, now I read https://ladle.dev/docs/config/#viteconfig and see that the path should be absolute anyway (wasn't clear from the fixture).
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.
Not sure, just the example uses an absolute path, I could not find something in the documentation stating that is has to be absolute.
I think it would be great to support both, so I now check if the path is already absolute and if not, I join it with options.cwd
. (I did not check before what's inside options, so helpful 🤣 ).
At least on my machine with our config it now works like a charm :)
@webpro do you have any idea why the test is failing in CI?
locally it's working
|
Yeah, crazy. I'll take a look tonight. |
The issue seems to be with Bun 1.1.19, 1.1.20 handles it fine. |
But bun 1.1.20 has another issue, so I'm afraid we'll have to wait for a fix. Still no idea what eventually causes the issue in this PR 🤷♂️ |
This is great, thanks! 👍 |
Ladle is a lightweight Storybook alternative. Its configuration is stored in
.ladle/config.mjs
, along with some other files. It uses Vite, a custom Vite config is sometimes necessary in a customizable location viaviteConfig
.Related issue: #268