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

Yarn 2: Fix compatibility with .storybook/preview.js file #10342

Merged
merged 3 commits into from
Apr 15, 2020

Conversation

gaetanmaisse
Copy link
Member

Issue: #10094

What I did

Patch clientApi and clientLogger strings to avoid issues when they contain $ symbol.

$ has a special behavior when used in the replacement string of the replace function, see here for more details.

As clientApi and clientLogger can contain $ symbol we need to double every $ to not have trouble when replacing them in the virtual module template 🤷‍♂ .

Also, use ES imports in the virtual module template as it is now transpiled like all other JS files.

How to test

Test locally as we do not have automated tests with yarn 2... for now! I agree it's painful...

@gaetanmaisse gaetanmaisse added maintenance User-facing maintenance tasks yarn / npm Yarn / npm acting weird labels Apr 7, 2020
@gaetanmaisse gaetanmaisse changed the title Yarn 2: Fix usage of .storybook/preview.js file Yarn 2: Fix compatibility with .storybook/preview.js file Apr 7, 2020
@gaetanmaisse gaetanmaisse marked this pull request as ready for review April 7, 2020 16:01
@gaetanmaisse
Copy link
Member Author

@ndelangen @tmeasday 👋 It's my again 😁, we faced a new :wow: 🙃 issue after using js template file and replace function introduced in #10281. I really need to think about a way to have automated tests for Yarn 2 (and also fix the CLI Yarn 2 CI).

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.

Looks great but would be good to clean it up a little!

lib/core/src/server/preview/iframe-webpack.config.js Outdated Show resolved Hide resolved
* @param bindings {Object} key-value object use to fill the template, `{{key}}` will be replaced by `escaped(value)`
* @returns {String} Filled template
*/
const interpolate = (template, bindings) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

a third template exists in the manager lib\core\src\server\manager\virtualModuleRef.template.js as it's in the manager, I don't know if it's impacted by yarn 2 ? Also, not sure if there's any common place to put this helper to use at both places ? (if relevant)

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't make a bigger refactoring because I have in mind that a TS migration + refactoring of @storybook/core is currently in progress in #9870. I'm not sure about the current state of this PR or even if it will be merged as it (for now there are a lot of conflicts). @ndelangen @shilman @kroeder do you know if it's going to land in 6.0?

@tooppaaa there are also template things in lib/core/src/server/utils/template.js, it's for related to HTML file but it will be great to find a way to have only one "template mechanism". However, I think this is a refactoring that can be done outside this PR that fixes incompatibility between preview.js file and Yarn 2. @shilman are you ok too to merge this as it and work on another template related PR ?

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with this landing in 6.0.0, what conflicts are you worries about?

Copy link
Member Author

Choose a reason for hiding this comment

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

Any big change in @storybook/core will create conflicts in #9870 that why I would prefer to merge this one and do some refactoring after TS migration will be done.

Copy link
Member

Choose a reason for hiding this comment

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

@gaetanmaisse hopefully the learnings from #9870 will be applicable to the refactor.

I'd agree merging this first rather then wait for #9870

@gaetanmaisse
Copy link
Member Author

gaetanmaisse commented Apr 12, 2020

@shilman is it ok for you? --> I just saw that you added some chromatics tests to check if SB is working on IE11, and it's currently failing on next should I wait to get the IE11 CI to be green?

Also, I will wait for #10396 to be merged and rebase this one. With both, the CLI tests / CLI Fixtures with Yarn 2 CI check should be 🟢 again 💪 🤞

…y contain `$` symbol

`$` has a special behavior when using it in the replacement string of the `replace` function, see:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter

As clientApi and clientLogger  can contain `$` symbol we need to double every `$` to not have trouble when replacing them in the virtual module template
We can use latest JS in it as it is now transpiled like all other JS files
@ndelangen
Copy link
Member

chromatic work on next now @gaetanmaisse

@gaetanmaisse
Copy link
Member Author

@ndelangen I rebased this branch so chromatic tests are working here too. @shilman are you ok to merge now?

@gaetanmaisse gaetanmaisse merged commit de750e1 into next Apr 15, 2020
@gaetanmaisse gaetanmaisse deleted the fix-virtual-module-with-yarn2 branch April 15, 2020 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance User-facing maintenance tasks yarn / npm Yarn / npm acting weird
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants