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

Core: Deprecate default postcss config, recommend addon-postcss #13669

Merged
merged 4 commits into from
Jan 22, 2021

Conversation

phated
Copy link
Contributor

@phated phated commented Jan 18, 2021

Issue: #12668

What I did

I deprecated the implicit addition of the postcss-loader to the preview webpack config inside @storybook/core and skip adding it completely if users depend on the new @storybook/addon-postcss package.

This new addon is much more flexible in configuring each loader and is versioned independently of Storybook, so it can track PostCSS updates in the future.

I also deprecated the default plugins that Storybook adds for users and added a migration guide to set up a postcss config file if consumers want those packages.

Additionally, I updated the html-kitchen-sink example to show how an end-user can swap out the PostCSS version to v8, even before the plugin is upgraded (handy for v9, v10, etc!).

How to test

  • Is this testable with Jest or Chromatic screenshots? ❌
  • Does this need a new example in the kitchen sink apps? I updated the html-kitchen-sink example, which shows it can be added and configured correctly.
  • Does this need an update to the documentation? Added the migration docs! Happy to add any more that are deemed necessary.

If your answer is yes to any of these, please make sure to include it in your PR.

@phated
Copy link
Contributor Author

phated commented Jan 19, 2021

@shilman This isn't quite ready to be promoted from a draft, but it'd be great if you can review to decide if this is a good direction to go. Happy to chat about it some time this week.

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.

Looking great 💯

My only concern (and it's a small one) is the peer dependency -- is there any way of providing a "sensible default"?

addons/postcss/src/index.ts Outdated Show resolved Hide resolved
app/angular/package.json Outdated Show resolved Hide resolved
@phated
Copy link
Contributor Author

phated commented Jan 19, 2021

@shilman What is your goal in avoiding the peerDep? If we don't have users install the version of postcss they want to use, we are going to run into the same issue that currently exists with @storybook/core—specifically, this addon isn't independently versioned, so you can't increase the PostCSS version when they bump a major and break plugins like autoprefixer.

@merceyz
Copy link
Contributor

merceyz commented Jan 21, 2021

Could the PnP tests be updated to cover this please? Should make sure the dependencies are handled correctly

@phated
Copy link
Contributor Author

phated commented Jan 21, 2021

Could the PnP tests be updated to cover this please? Should make sure the dependencies are handled correctly

I have no idea what this is and I have no experience with PnP.

FWIW, we decided that addon-postcss is going to embed it's dependencies directly and not rely on any peerDep stuff. Not sure if that matters at all.

@phated phated changed the title WIP: Move implicit Postcss magic to an addon Move implicit Postcss magic to an addon Jan 22, 2021
@phated phated marked this pull request as ready for review January 22, 2021 01:38
@phated
Copy link
Contributor Author

phated commented Jan 22, 2021

Updated the PR comment body! I think this is in a solid place now and needs review.

@shilman @merceyz If someone can guide me in the PnP tests, I'm happy to make those changes, too. I just don't know anything about them.

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.

Aside from a couple typos, looking great!

MIGRATION.md Outdated Show resolved Hide resolved
MIGRATION.md Outdated Show resolved Hide resolved
@shilman shilman changed the title Move implicit Postcss magic to an addon Core: Deprecate default postcss config, recommend addon-postcss Jan 22, 2021
@shilman
Copy link
Member

shilman commented Jan 22, 2021

@merceyz @gaetanmaisse I'm merging this and releasing to move the project along. We can update with the PnP stuff once we have a little more clarity there.

@shilman shilman added the run e2e extended test suite Run the e2e extended test suite in CircleCI workflows label Jan 22, 2021
@shilman shilman merged commit 4aba6ad into storybookjs:next Jan 22, 2021
@merceyz
Copy link
Contributor

merceyz commented Jan 22, 2021

I have no idea what this is and I have no experience with PnP.

https://yarnpkg.com/features/pnp - TL;DR; You can't access anything you haven't declared

@shilman @merceyz If someone can guide me in the PnP tests, I'm happy to make those changes, too. I just don't know anything about them.

Would basically just update the list of e2e tests to run through PnP here

command: yarn test:e2e-framework --use-yarn-2-pnp sfcVue cra
e2e tests are defined here https://github.com/storybookjs/storybook/blob/431d209ec7d3c1002cffcf3eef5be250584d905e/scripts/run-e2e-config.ts so pick one that uses the new postcss stuff and add it to the list above

@phated
Copy link
Contributor Author

phated commented Jan 22, 2021

Ah cool! So that means the html-kitchen-sink example will run in both PnP and non-PnP mode? I'll give it a shot. Is there a way for me to run/debug it locally?

@phated phated deleted the phated/addon-postcss branch January 22, 2021 19:26
@merceyz
Copy link
Contributor

merceyz commented Jan 22, 2021

So that means the html-kitchen-sink example will run in both PnP and non-PnP mode?

As it is setup now, no, the CI config I linked to only tests sfcVue and cra

I'll give it a shot. Is there a way for me to run/debug it locally?

yarn test:e2e-framework --use-yarn-2-pnp <e2e test here>

@phated
Copy link
Contributor Author

phated commented Jan 22, 2021

Hmm, is it not necessary to have cypress and a local registry set up?

@phated
Copy link
Contributor Author

phated commented Jan 22, 2021

Alright, I've researched this more and it seems that the yarn PnP e2e tests use the scaffolds that the CLI provides and none of those are going to include addon-postcss, since it's an external addon that people opt into. I don't think it makes sense to e2e test this.

@gaetanmaisse
Copy link
Member

It would make sense to have a test with multiples addons but we are not there yet, we talked about using the SB CLI to add them during the E2E process. Feels free to ping me on discord!

@vdh
Copy link
Contributor

vdh commented Jan 25, 2021

Is the goal of this is to allow upgrading to postcss^8? Because if so, there's still going to be issues with the css-loader^3.0.0 / css-loader^3.6.0 dependencies pinning to postcss^7.0.32.

@phated
Copy link
Contributor Author

phated commented Jan 25, 2021

@vdh if you take a look at the example, it proves that this works. Those loaders don't pull in autoprefixer or any plugins (config loading isn't part of postcss itself, only the loader). Additionally, PostCSS can support plugins using older versions if they are written in a specific fashion (see postcss-rebecca-purple in the example).

@kaelig
Copy link
Contributor

kaelig commented Feb 11, 2021

I'm confused about the message introduced in this PR:

info => Using implicit CSS loaders
(node:94445) DeprecationWarning: Relying on the implicit PostCSS loader is deprecated and will be removed in Storybook 7.0.
If you need PostCSS, include '@storybook/addon-postcss' in your '.storybook/main.js' file.

See https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-implicit-postcss-loader for details.

If I'm not relying on PostCSS, how do I disable the message?

@phated
Copy link
Contributor Author

phated commented Feb 11, 2021

@kaelig you don't disable the warning. It will go away when storybook 7 is released.

@shilman
Copy link
Member

shilman commented Feb 11, 2021

@phated shouldn't we detect if the user has @storybook/addon-postcss in their main.js and skip the warning if they do?

@phated
Copy link
Contributor Author

phated commented Feb 11, 2021

@shilman that's only for people that actually want to use postcss, users that don't want to use it are just shown the warning to know the implicit addition of postcss will be removed in 7.0

@kaelig
Copy link
Contributor

kaelig commented Feb 17, 2021

users that don't want to use it are just shown the warning to know the implicit addition of postcss will be removed in 7.0

This is definitely useful to know for people configuring Storybook. In contrast, I'm on a team where I configure Storybook for hundreds of devs (who are on the side of "using" storybook), and I'd like to prevent them from seeing this message in case they think there's something wrong with our config.

I'd love the ability to hide this message, or perhaps you can provide a workaround with a webpack plugin that would filter out that particular message?

@phated
Copy link
Contributor Author

phated commented Feb 17, 2021

@shilman
Copy link
Member

shilman commented Feb 17, 2021

@kaelig @phated looks to me like installing the addon-postcss should already disable the warning, no?

https://github.com/storybookjs/storybook/blob/next/lib/core/src/server/preview/base-webpack.config.ts#L67-L72

@kaelig
Copy link
Contributor

kaelig commented Feb 17, 2021

Yes, however I'm not sure we'll want to install it. I'll try both approaches and see!

@shilman shilman mentioned this pull request Feb 17, 2021
Robbert added a commit to nl-design-system/utrecht that referenced this pull request May 3, 2021
We didn't use the addon, so this change prevents logging the deprecation warning.

storybookjs/storybook#13669
Yolijn pushed a commit to nl-design-system/utrecht that referenced this pull request May 3, 2021
We didn't use the addon, so this change prevents logging the deprecation warning.

storybookjs/storybook#13669
@prateekj16
Copy link

storybook with postcss8 works with npm but not with yarn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core feature request run e2e extended test suite Run the e2e extended test suite in CircleCI workflows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants