-
-
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
CSF-Tools: Fix export specifier bug #27418
CSF-Tools: Fix export specifier bug #27418
Conversation
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.
Makes sense. Please add a test case! 🙏
☁️ Nx Cloud ReportCI is running/has finished running commands for commit dcf4a25. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 2 targetsSent with 💌 from NxCloud. |
ab9c663
to
bb0466f
Compare
@shilman Done! |
bb0466f
to
dcf4a25
Compare
…-export-analysis CSF-Tools: Fix export specifier bug (cherry picked from commit 3ad2f5f)
I'm still facing what I think might be a related bug in our project when using transforming (1) iframe.htmlTypeError: Cannot read properties of null (reading 'init')
at ./node_modules/@storybook/csf-tools/dist/index.js:17:3419
at Array.forEach (<anonymous>)
at enter (./node_modules/@storybook/csf-tools/dist/index.js:17:3176)
at NodePath._call (./node_modules/@babel/traverse/lib/path/context.js:46:20)
at NodePath.call (./node_modules/@babel/traverse/lib/path/context.js:36:17)
at NodePath.visit (./node_modules/@babel/traverse/lib/path/context.js:82:31)
at TraversalContext.visitQueue (./node_modules/@babel/traverse/lib/context.js:89:16)
at TraversalContext.visitMultiple (./node_modules/@babel/traverse/lib/context.js:61:17)
at TraversalContext.visit (./node_modules/@babel/traverse/lib/context.js:110:19)
at traverseNode (./node_modules/@babel/traverse/lib/traverse-node.js:22:17) |
Hi @daneah Could be related! Could you please send me the compiled code of |
@valentinpalkovic Thanks a bunch for taking a look! I've got it up on a pastebin here as I didn't feel pasting it directly here would be particularly helpful. Let me know if I can send it some other way, or do anything else to help out. |
It seems to be related! Could you please replace the |
Awesome, that's sort of what I was thinking of doing once I got a little more time to read what was going on in this module. Here's the code in question, output from that log: import { setCustomElementsManifest } from '@storybook/web-components';
import customElementsManifest from '../../packages/pharos/custom-elements.json';
import '../styleConfig';
import '../initComponents';
setCustomElementsManifest(customElementsManifest);
export { preview } from '../preview'; If I understand correctly, the issue is with the Babel parsing of this code here directly, and the change you made here improved things around exports, so maybe it's the re-export of |
The issue is that csf-tools doesn't follow imports or re-exports. Therefore, this preview has to define the preview object statically. I understand that this leads to some duplication in your case, but unfortunately, it's impossible to have a global preview.js and then import and re-export it in other preview.js files. That's a limitation of how csf-tools parses preview files. Correct @shilman? If you don't want to duplicate code, I would advise writing a small script that gets executed on, for example, a "pre-commit" hook, which copies over the contents of the generic preview.js and takes template framework-specific preview.js files and generates them as soon as the generic preview.js changes. |
Thanks for the details—FWIW this worked up until the EDIT: I confirm that making the EDIT: It seems I can also do the following rather than the reexport: import { preview as basePreview } from '../preview';
export const preview = basePreview; |
@daneah I think you've found a bug. What's happening: Storybook loads
|
Thanks for looking into this and the quick turnaround @shilman. I understand that your change in the PR ends up being to fix the break in backward compatibility, but that we're still doing something that isn't expressly supported and should continue toward the static definitions that @valentinpalkovic suggested. Am I thinking about that right? Just want to make sure our team proceeds in the best long-term way possible 😄 |
I would recommend having a statically analyzable preview.js file, because in some particular scenarios (as for tags) we don't evaluate but rather parse it. That's definitely more future proof than your current solution :) |
Closes N/A
What I did
CSF-Tools was not able to analyze aliased named exports properly. An export like the following lead to an Error:
The fix now makes sure that the local name of the ExportSpecifier is used to find the proper declaration
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.ts
Make sure this PR contains one of the labels below:
Available labels
bug
: Internal changes that fixes incorrect behavior.maintenance
: User-facing maintenance tasks.dependencies
: Upgrading (sometimes downgrading) dependencies.build
: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup
: Minor cleanup style change. Will not show up in release changelog.documentation
: Documentation only changes. Will not show up in release changelog.feature request
: Introducing a new feature.BREAKING CHANGE
: Changes that break compatibility in some way with current major version.other
: Changes that don't fit in the above categories.🦋 Canary release
This pull request has been released as version
0.0.0-pr-27418-sha-ab9c6633
. Try it out in a new sandbox by runningnpx [email protected] sandbox
or in an existing project withnpx [email protected] upgrade
.More information
0.0.0-pr-27418-sha-ab9c6633
valentin/fix-aliased-named-export-analysis
ab9c6633
1717012276
)To request a new release of this pull request, mention the
@storybookjs/core
team.core team members can create a new canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=27418