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

Storybook: upgrade to v6, Styled-Components: upgrade to v5 (includes brave-ui) #8120

Merged
merged 9 commits into from
Mar 11, 2021

Conversation

petemill
Copy link
Member

@petemill petemill commented Mar 4, 2021

Fix brave/brave-browser#14305 (npm audit issues), as well as brings some much-needed storybook bug fixes.

Here's a find/replace regex I used for the styled-components typescript format: https://regex101.com/r/5X75t3/1/

core-js added as a dependency due to storybookjs/storybook#11255

Requires:

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

  • npm run storybook and verify each item is showing and with correct styles.
  • Build browser and run as many WebUI as possible. Check styles and theming.

@petemill petemill self-assigned this Mar 4, 2021
@petemill petemill force-pushed the storybook-v6-2 branch 2 times, most recently from 59b55e2 to 72b1c95 Compare March 9, 2021 22:26
@petemill petemill changed the title Storybook: upgrade to v6 Storybook: upgrade to v6, Styled-Components: upgrade to v5 Mar 9, 2021
@petemill petemill changed the title Storybook: upgrade to v6, Styled-Components: upgrade to v5 Storybook: upgrade to v6, Styled-Components: upgrade to v5 (includes brave-ui) Mar 9, 2021
.storybook/preview.js Outdated Show resolved Hide resolved
@@ -314,6 +311,7 @@
"array-move": "^2.2.1",
"bignumber.js": "^7.2.1",
"bluebird": "^3.5.1",
"core-js": "^3.9.1",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where does the core-js dep come from?

Copy link
Member Author

Choose a reason for hiding this comment

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

To fix storybookjs/storybook#11255. Apologies for not explicitly mentioning. Maybe I should have added a comment, but not sure how npm handles that.

import Button, { Props as ButtonProps } from 'brave-ui/components/buttonsIndicators/button'

export const SideBySideButtons = styled<{}, 'div'>('div')`
export const SideBySideButtons = styled('div')<{}>`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the empty props object needed, or can it just be styled('div') (or even styled.div)?

Copy link
Member Author

Choose a reason for hiding this comment

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

It can, yes, and it will still get correctly-typed theme props. But we can do it in a follow-up. This was the result of a find/replace just switching the order and removing the duplication.

@@ -3,10 +3,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

import styled from 'brave-ui/theme'
import styled from 'styled-components'
Copy link
Collaborator

Choose a reason for hiding this comment

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

This dependency flattening is great - thanks!

@@ -0,0 +1,37 @@
// Copyright (c) 2020 The Brave Authors. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

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

2021?

Copy link
Member

Choose a reason for hiding this comment

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

Eternally March 2020 😛

Copy link
Member Author

Choose a reason for hiding this comment

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

In my defense, I did write this code in 2020 when I started this branch!

@@ -0,0 +1,9 @@
{
"extends": "../../../tsconfig",
"include": [
Copy link
Collaborator

Choose a reason for hiding this comment

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

Curious: what does the addition of this file do?

Copy link
Member Author

@petemill petemill Mar 10, 2021

Choose a reason for hiding this comment

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

It was the only way I could see to get correct intellisense in Visual Studio Code working for certain types (I think theme properties, but I'm having trouble remembering now). Perhaps the project was otherwise too big unless localized to the specific dir the current file open is in. So, a different tsconfig per WebUI "project" seems appropriate anyway.


type Theme = IBraveTheme & IWelcomeTheme

export default styled as unknown as Styled.ThemedStyledInterface<Theme>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the as unknown as ... intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, it allows the type to be cast, otherwise you cannot directly cast styled to include the theme. But we know that it does include the specific Welcome theme, so it's ok.

This is the suggested way to have multiple themes in a project. Otherwise it will just assume our re-defined DefaultTheme.

@@ -97,10 +97,10 @@ export default class GrantCaptcha extends React.PureComponent<Props, {}> {
return (
<StyledWrapper
id={id}
innerRef={this.refWrapper}
ref={this.refWrapper}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yay!

@@ -0,0 +1,4 @@
Name: core-js
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is this file for?

Copy link
Member Author

Choose a reason for hiding this comment

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

all of our deps in package.json must define the license file, which I believe gets automatically included in chrome://credits. Otherwise the build fails.

@diracdeltas
Copy link
Member

npm run tslint shows a few errors on this branch. dep updates lgtm though.

@petemill petemill force-pushed the storybook-v6-2 branch 2 times, most recently from 8cc477f to b56c8e7 Compare March 10, 2021 04:54
Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

Left some comments - but looks great! 😄 This is a whole lot of work, thanks for taking it on!

@petemill petemill force-pushed the storybook-v6-2 branch 2 times, most recently from 21c0b2d to 8c0357b Compare March 10, 2021 09:58
@petemill
Copy link
Member Author

Restarted Windows build, it had typescript errors even though all other platforms did not 🤷

@petemill
Copy link
Member Author

Windows CI still giving off errors that were previously fixed within the brave-ui PR that this pulls in via package.json, checking...

@petemill petemill added CI/skip-android Do not run CI builds for Android CI/skip-ios Do not run CI builds for iOS CI/skip-linux CI/skip-macos-x64 Do not run CI builds for macOS x64 labels Mar 11, 2021
@petemill
Copy link
Member Author

skipping all other platforms for CI apart from Windows whilst I attempt to fix it

@petemill
Copy link
Member Author

CI now passed on all platforms 🍾

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

npm audit failing due to immer
4 participants