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

Use postcss.config.js when present #4411

Closed
wants to merge 13 commits into from

Conversation

kylemh
Copy link
Member

@kylemh kylemh commented Oct 13, 2018

Issue: #2455

What I did

  • Add find-up to dependencies to search for the nearest postcss.config.js
  • Use the nearest postcss.config.js to determine postcss-loader options if present, maintain previous defaults if not.

How to test

  • Use local storybook core against a test repository using a postcss config with an option not present in the default set (such as postcss-import).

Is this testable with Jest or Chromatic screenshots? Only if a custom serializer renders all styles.
Does this need a new example in the kitchen sink apps?

No.

Does this need an update to the documentation?
Yes. Describe that custom postcss.config.js should be handled just like custom babel configurations. Just wanted to ensure this is the correct direction before I add any changes.

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

For maintainers only: Please tag your pull request with at least one of the following:
["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]

@kylemh kylemh changed the title [Feature] - Use postcss.config.js when present Use postcss.config.js when present Oct 13, 2018
@codecov
Copy link

codecov bot commented Oct 14, 2018

Codecov Report

Merging #4411 into master will decrease coverage by 0.05%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4411      +/-   ##
==========================================
- Coverage   35.57%   35.52%   -0.06%     
==========================================
  Files         557      558       +1     
  Lines        6732     6742      +10     
  Branches      884      885       +1     
==========================================
  Hits         2395     2395              
- Misses       3877     3886       +9     
- Partials      460      461       +1
Impacted Files Coverage Δ
lib/core/src/server/config/style.config.js 0% <0%> (ø)
...b/core/src/server/config/webpack.config.default.js 0% <0%> (ø) ⬆️
lib/core/src/server/core-preset-webpack-custom.js 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d16f1d6...dfa78c3. Read the comment docs.

@ndelangen ndelangen added maintenance User-facing maintenance tasks core labels Oct 14, 2018
},
options: postcssConfig
? {
postcssConfig,
Copy link
Member

Choose a reason for hiding this comment

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

should it be { ...postcssConfig } ?

I think will be better something like this:

postcssConfig || {
   // flexbug blah blah
}

Copy link
Member Author

@kylemh kylemh Oct 14, 2018

Choose a reason for hiding this comment

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

I think the config would work without a spread operator, but adding it doesn't hurt anything, so I will 👍

I'm totally fine with that! I do my best to not subscribe to lint beliefs and simply adhere to the linting of the code base. I have seen @ndelangen express a favor towards ternaries when discussing short-circuits, so I did it that way; perhaps a lint rule is in order to prevent further confusion?

Copy link
Member

Choose a reason for hiding this comment

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

I was more about to simplify the readability. Maybe even worth to extract it to a func

Copy link
Member Author

@kylemh kylemh Oct 15, 2018

Choose a reason for hiding this comment

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

simplify the readability

is subjective.

I think ternaries read fine, but most importantly this discussion shouldn't even happen. We should just have a lint rule to prevent bike-shedding. I want to do whatever the team wants to do here.

Doesn't look like ESLint has a rule to prevent this discussion aside from preventing ternaries at all. It'd be cool to see a prefer-short-circuit lint rule which favors && or || instead of ternaries where one option is null or undefined

Anywho... I'll go ahead and make both of those changes.

Copy link
Member

@igor-dv igor-dv left a comment

Choose a reason for hiding this comment

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

We should have an example for this I think

}
: {
plugins: () => [
require('postcss-flexbugs-fixes'), // eslint-disable-line global-require
Copy link
Member

Choose a reason for hiding this comment

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

I understand that something won't work if this plugin will be missing?

Copy link
Member Author

Choose a reason for hiding this comment

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

The plugins are currently available, correct? I didn't remove dependencies for that reason.

Copy link
Member

Choose a reason for hiding this comment

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

I mean, should we somehow merge it to the user's config?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I wouldn't do that. Either we give them a set of defaults, or they have full control. I'm not a fan of doing obscure things like providing a pair of plugins the user may or may not want if they have their own postcss config.

@kylemh
Copy link
Member Author

kylemh commented Oct 14, 2018

Agreed on needing an example. I'll add one and update docs as long as this is going in the right direction.

@kylemh
Copy link
Member Author

kylemh commented Oct 17, 2018

Gonna wait on #4405 before I move forward.

The only work left to be done will be to integrate with those changes + provide an example + update docs 👍

I'm prepared to make the moves at any moment in my work day.

@chadfawcett chadfawcett mentioned this pull request Oct 17, 2018
@ndelangen ndelangen added this to the v4.0.0 milestone Oct 17, 2018
@storybook-safe-bot
Copy link
Contributor

Fails
🚫

PR is marked with "feature request" label.

Generated by 🚫 dangerJS


export default function getStyleConfig(baseConfig) {
// null if file is not found
const customPostcssConfig = findUp.sync('postcss.config.js', {
Copy link
Member

Choose a reason for hiding this comment

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

Will be very nice if you could asyncify this... Need to add some additional awaits in the call chain though. Not critical one, bit since we already support async/await that be great =)

@kylemh kylemh requested a review from usulpro as a code owner October 25, 2018 10:44
@kylemh
Copy link
Member Author

kylemh commented Oct 25, 2018

Suggested spot for documentation:
A section after https://storybook.js.org/configurations/custom-babel-config/ called "other common custom configurations" to leave room for how postcss.config.js gets consumed and - eventually - how .browserlistrc gets consumed

Norbert spoke with me about creating an example folder for this, so I will 👍

Temporarily committed example to make it easier for people to try out themselves.

In testing it locally, I run yarn build-storybook against CRA storybook example with a postcss.config.js (even though CRA doesnt support postcss.config) at the project root and with the rebecca purple import. I would expect the chunk to have that color value changed to an rgb() calc that results in #663399, but the name rebeccapurple remains... You should also be able to simply open the browser with yarn storybook and check out dev tools to be on the lookout for the same value change.


export default async function getStyleConfig(baseConfig) {
// null if file is not found
const customPostcssConfig = await findUp.sync('postcss.config.js', {
Copy link
Member

Choose a reason for hiding this comment

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

it should be just findUp(...) without the sync

Copy link
Member Author

Choose a reason for hiding this comment

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

🤦‍♂️ fixed

Wurielle added a commit to Wurielle/pristine that referenced this pull request Oct 26, 2018
@ndelangen ndelangen modified the milestones: v4.0.0, next Oct 29, 2018
@Hypnosphi Hypnosphi changed the base branch from master to next November 5, 2018 17:04
@kylemh
Copy link
Member Author

kylemh commented Nov 6, 2018

@ndelangen thoughts on deleting this branch PR and starting from the new API changes?

@kylemh
Copy link
Member Author

kylemh commented Nov 19, 2018

Gonna take another stab at this in a different PR since direction has changed a bit

@kylemh kylemh closed this Nov 19, 2018
@kylemh kylemh deleted the feature/use-custom-postcss-config branch November 19, 2018 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core feature request maintenance User-facing maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants