Skip to content
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

ConfigFile: Fix export { X } parsing #29344

Merged
merged 10 commits into from
Oct 20, 2024

Conversation

vctqs1
Copy link
Contributor

@vctqs1 vctqs1 commented Oct 12, 2024

Closes #28751 (comment)

What I did

Just add an extra step to check decl exists before assign to another variable or accessing inside it

Here is the failure message in case having export { X } with X is `import X from 'another file'. Please notice the line 258, and the message error in the terminal

test

In _findVarDeclarator (code), the function currently only handles finding its own declaration within the same file. We lack a step to locate import declarations, which leads to multiple cases where the import can be a file, a native package (Eg 'fs', 'path'), or a package name (node_module's package. Eg: 'react'). Therefore, I believe the best course of action is to add a step to prevent the function from breaking and causing incorrect errors in various situations, as discussed here: GitHub Discussion.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/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 PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 78.7 MB 78.7 MB -234 B 2.05 0%
initSize 147 MB 147 MB -722 B 1.91 0%
diffSize 68.3 MB 68.3 MB -488 B 1.64 0%
buildSize 6.79 MB 6.79 MB -34 B 0.47 0%
buildSbAddonsSize 1.5 MB 1.5 MB 0 B -0.9 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 1.83 MB 1.83 MB -34 B 0.61 0%
buildSbPreviewSize 270 kB 270 kB 0 B -0.9 0%
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 3.8 MB 3.8 MB -34 B 0.51 0%
buildPreviewSize 2.99 MB 2.99 MB 0 B -0.9 0%
testBuildSize 0 B 0 B 0 B - -
testBuildSbAddonsSize 0 B 0 B 0 B - -
testBuildSbCommonSize 0 B 0 B 0 B - -
testBuildSbManagerSize 0 B 0 B 0 B - -
testBuildSbPreviewSize 0 B 0 B 0 B - -
testBuildStaticSize 0 B 0 B 0 B - -
testBuildPrebuildSize 0 B 0 B 0 B - -
testBuildPreviewSize 0 B 0 B 0 B - -
name before after diff z %
createTime 5.9s 22.2s 16.2s 1.85 🔺73.2%
generateTime 20.6s 18.4s -2s -157ms -0.69 -11.7%
initTime 13.7s 11.6s -2s -50ms -0.69 -17.5%
buildTime 8.3s 8s -216ms -0.64 -2.7%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 5.6s 6.4s 781ms 0.03 12.1%
devManagerResponsive 3.7s 4.2s 580ms 0.16 13.5%
devManagerHeaderVisible 488ms 603ms 115ms 0.03 19.1%
devManagerIndexVisible 521ms 649ms 128ms 0.13 19.7%
devStoryVisibleUncached 897ms 710ms -187ms -1.3 🔰-26.3%
devStoryVisible 522ms 643ms 121ms 0.06 18.8%
devAutodocsVisible 455ms 556ms 101ms 0.3 18.2%
devMDXVisible 431ms 521ms 90ms -0.05 17.3%
buildManagerHeaderVisible 447ms 520ms 73ms -0.33 14%
buildManagerIndexVisible 451ms 554ms 103ms -0.18 18.6%
buildStoryVisible 518ms 555ms 37ms -0.55 6.7%
buildAutodocsVisible 441ms 485ms 44ms -0.3 9.1%
buildMDXVisible 448ms 453ms 5ms -0.57 1.1%

Greptile Summary

This pull request adds a safety check in the ConfigFile class to handle imported variables correctly and includes a new test case to verify the behavior. Here are the key changes:

  • Added a null check for 'decl' before assigning to config._exports in code/core/src/csf-tools/ConfigFile.ts
  • Introduced a new test case in code/core/src/csf-tools/ConfigFile.test.ts for handling imported and re-exported variables

These changes improve the robustness of the ConfigFile class when dealing with imports and ensure proper test coverage for the new functionality.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

4 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@shilman shilman self-assigned this Oct 14, 2024
@shilman shilman changed the title fix: add step to check decl before assign to config._exports ConfigFile: Fix export { X } parsing Oct 15, 2024
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @vctqs1 !!! Looks great 💯

@shilman shilman added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Oct 15, 2024
Copy link

nx-cloud bot commented Oct 15, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 993d250. 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 1 target

Sent with 💌 from NxCloud.

@vctqs1
Copy link
Contributor Author

vctqs1 commented Oct 16, 2024

Thanks @vctqs1 !!! Looks great 💯

@shilman thanks for helping me fix the lint issue

I see that there are still two jobs failing. Please let me know if there’s anything I need to update to fix them. Thanks!

@shilman
Copy link
Member

shilman commented Oct 16, 2024

@vctqs1 the failures are unrelated to this PR, and I'd guess are also happening on the base branch.

I'll work with the core team to figure out what's going on and get this merged. Thanks so much for your contribution!!

@shilman shilman merged commit 3b4318f into storybookjs:next Oct 20, 2024
50 of 52 checks passed
@vctqs1
Copy link
Contributor Author

vctqs1 commented Oct 20, 2024

@shilman Thank you

@kasperpeulen kasperpeulen added the patch:done Patch/release PRs already cherry-picked to main/release branch label Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ci:normal csf patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants