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

Babel: Ensure story files not transpiled earlier than ES2017 #28469

Merged
merged 10 commits into from
Jul 8, 2024

Conversation

kasperpeulen
Copy link
Contributor

@kasperpeulen kasperpeulen commented Jul 5, 2024

What I did

Make sure that stories files get not transpiled by babel further than the browser we support.

The purpose of this is to preserve the play: async ({ mount }) => { destructure code, which we dynamically test at runtime. It's important that we be able to do this at runtime (instead of during compilation) because it will allow us to support Playwright-style fixtures in the future -- an option that we want to keep open.

We believe it is a safe, nonbreaking change, because we are scoping the restriction to story files only and not to the user's components. Plus we already apply the same browser targets to the manager & preview-api code, so it is consistent with existing constraints!

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>

@kasperpeulen kasperpeulen added maintenance User-facing maintenance tasks ci:normal labels Jul 5, 2024
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.

PR Summary

  • Updated code/core/src/core-server/presets/common-preset.ts to prevent story files from being transpiled beyond supported browsers.
  • Added Babel configuration override in code/core/src/core-server/presets/common-preset.ts to target specific browser versions.
  • Re-applied default Storybook Babel override in code/frameworks/nextjs/src/preset.ts to ensure compatibility with supported browsers.
  • Included specific browser targets for Chrome, Safari, and Firefox in code/frameworks/nextjs/src/preset.ts.

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

nx-cloud bot commented Jul 5, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 5b884b6. 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.

@kasperpeulen kasperpeulen changed the base branch from next to kasper/improve-error-message July 5, 2024 21:43
@kasperpeulen kasperpeulen changed the title Babel: Make sure that stories files get not transpiled by babel further than the browser we support Babel: Make sure that stories files get not transpiled by babel further than the browsers we support Jul 5, 2024
@kasperpeulen kasperpeulen added ci:daily Run the CI jobs that normally run in the daily job. and removed ci:normal labels Jul 5, 2024
@shilman shilman changed the title Babel: Make sure that stories files get not transpiled by babel further than the browsers we support Babel: Ensure story files not transpiled earlier than ES2017 Jul 6, 2024
@shilman shilman changed the title Babel: Ensure story files not transpiled earlier than ES2017 Babel: Ensure story files get transpiled no earlier than ES2017 Jul 6, 2024
@shilman shilman changed the title Babel: Ensure story files get transpiled no earlier than ES2017 Babel: Ensure story files not transpiled earlier than ES2017 Jul 6, 2024
@@ -108,6 +108,29 @@ export const babel: PresetProperty<'babel'> = async (baseConfig: TransformOption
presets,
babelrc: false,
configFile: false,
overrides: [
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn’t we load babelDefault instead from the presets and apply it?

Copy link
Contributor Author

@kasperpeulen kasperpeulen Jul 6, 2024

Choose a reason for hiding this comment

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

I'm not sure what you mean with this, do you mean to somehow reuse the babel preset override loaded in:
code/core/src/core-server/presets/common-preset.ts?

So in theory options.overrides should actually contain that preset/override, but it gets ignored as the include regex doesn't match the filename in line 62.

That is why I need to copy the override again.
I think we should solve it in:
#28467

But won't be easy I imagine.

// https://storybook.js.org/docs/writing-tests/interaction-testing#run-code-before-each-test
overrides: [
{
include: /(story|stories)\.[cm]?[jt]sx?$/,
Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to be really exact you probably want to:

  1. Add a dot at the beginning, to not match the-cool-stories.js
  2. Don't match on story, Storybook doesn't support that even if a user's glob pattern would match it. (Unless something changes recently in the default CSF Indexer that I'm unaware of)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point!

Regarding 2, do you know @shilman ?

Copy link
Member

Choose a reason for hiding this comment

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

Looks like we do support both suffixes in our indexer and the "." bug exists there too:

https://github.com/storybookjs/storybook/blob/next/code/core/src/core-server/presets/common-preset.ts#L191-L194

Base automatically changed from kasper/improve-error-message to next July 7, 2024 13:43
Co-authored-by: Valentin Palkovic <valentin@chromatic.com>
@valentinpalkovic valentinpalkovic merged commit dd1f7f0 into next Jul 8, 2024
103 of 104 checks passed
@valentinpalkovic valentinpalkovic deleted the kasper/babel-fixes branch July 8, 2024 09:07
@github-actions github-actions bot mentioned this pull request Jul 8, 2024
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:daily Run the CI jobs that normally run in the daily job. maintenance User-facing maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants