-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Vite: Re-export essentials sub-addon preview annotations for pnpm #19689
Conversation
# Conflicts: # code/addons/outline/package.json
Turns out it's kind of a bit PITA
@Dschungelabenteuer and I found a few bugs in SSv6 that this now takes care of, and we've confirmed that his project (using pnpm and SSv7) is working correctly without any workarounds with these changes. \o/ |
|
||
import * as clientApi from "@storybook/client-api"; | ||
import { logger } from '@storybook/client-logger'; | ||
import { clientApi } from '${frameworkName}'; |
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.
SSv6 with the vite-builder and pnpm has been broken for a while. I figured I might as well fix it in this PR, but I can move it to a different one if preferred. I'd like to make a separate PR soon to create a vite-core
that each of the frameworks re-export from, to avoid all the duplication in the frameworks above. I'll do that soon.
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.
WFM!
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.
Some nitpicking, but one important detail to cover.
|
||
import * as clientApi from "@storybook/client-api"; | ||
import { logger } from '@storybook/client-logger'; | ||
import { clientApi } from '${frameworkName}'; |
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.
WFM!
I can confirm this works perfectly against my pnpm monorepo. This is looking pretty good, especially since my environment has some abstraction around Vite+Storybook configuration, which is shared across different Storybook instances and consumed as a local package. Basically, my setup could easily have raised some edge-case issues, but it did not at all! Well done @IanVS! This lets me get rid of ~7 "explicit" installs from my There are still some workarounds needed for MDX (which relies on react dependencies), Please let me know if the latest changes require additional testing on my side! |
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.
This LGTM but is all a bit clever/subtle. I hope that we can come up with something simpler in 8.0!!
I think the main change here is that if an addon wants to include other addons without forcing the user to also install those, it should re-export from them and point to its re-exports, rather than just specify the names of the sub-addons. We'll need to decide if that's a good change to force community addons to make, or if there's another approach like all addons being imported into a preview.js or something. This is "backwards compatible" for now in the sense that webpack will continue working as before (I think that's the "clever" bit you're referring to?), but the vite builder will be broken with pnp(m) for any community addons that have sub-addons. So yeah, I hope we can refine this as we go. |
@IanVS I am referring to the whole absolute path / bare thing. And the amount of work that an addon has to do to include other addons. I hope we can streamline this with the That said, you've done an incredible job getting this working for 7.0 given the limitations of our current presets setup. Did not intend to piss on your work -- this is really great. |
That should just really be a matter of specifying something like:
I got a little fancy with export maps here, but there are other ways to accomplish that as well (but this worked the best with our tooling). |
Hey it looks like something in here caused this issue for me:
Any idea what caused it? I can confirm the bug shows up at |
@matsko could you open a new issue with all the details, and ideally a reproduction, and ping me on it? My guess is that you might have an old version of |
Issue: #19176
Closes #19530
What I did
In order to support pnpm from the vite builder, I added re-exports of the sub-addons which have preview annotations, and adjusted the preset handling to leave bare imports alone instead of turning them into absolute paths. This allows pnpm to correctly find the files and avoids users from having to "shamefully hoist" or add the sub-addons to their package.json.
I added
typesVersions
to the addons, so that we canexport * from "@storybook/addon-actions/preview"
, for instance. The .d.ts file isn't at the root of the package, it's in/dist
, so using typesVersions lets us point to the right spot. This is one of the approaches shown in https://github.com/andrewbranch/example-subpath-exports-ts-compat, and has the best overall compatibility.One problem I hit is that tsup generates empty .d.ts files for
manager
, so I filed egoist/tsup#762 and needed to ignore errors when re-exporting from them.How to test
We don't have any good tests for pnpm, unfortunately, so this is a bit manual.
lib/builder-vite
,lib/core-common
, andaddons/essentials
pnpm create vite@latest --template=react
)pnpx sb@next init --builder=vite
)dist
oflib/builder-vite
intonode_modules/.pnpm/@[email protected]_<hash>/node_modules/@storybook/builder-vite
dist
oflib/core-common
intonode_modules/.pnpm/@[email protected]_<hash>/node_modules/@storybook/core-common
dist
andpackage.json
ofaddons/essentials
intonode_modules/@storybook/addon-essentials/
pnpm run storybook
), and it should start successfully.