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

Fix Storybook build args #4455

Conversation

josemasar
Copy link
Contributor

@josemasar josemasar commented Feb 13, 2022

Fixes: #4448

Background:

When running yarn redwood storybook --build, it threw an error because the argument --open was set to true as default. --build and --open cannot be called at the same time.

Proposed solution:

The proposed solution is to turn the default behaviour of the argument --open to false.

In addition, I´m deleting another line which was running the arg --ci (skip interactive prompts, don't open browser) when calling --build and generating the same issue. --ci is not a permitted option when building storybook.

See: Storybook Docs

Tags:

@thedavidprice
@callingmedic911

Copy link
Contributor

@thedavidprice thedavidprice left a comment

Choose a reason for hiding this comment

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

cc @virtuoushub (looping you in in case you have time to help me think through the logic we need here to handle all cases of running storybook.)

@josemasar Thank you for starting the work on this! Greatful for the help.

What we're running into here is a history of adding features (and conditions) to this CLI Command that has now overly complicated the logic used to build the command and options that are run. So I'd like to consider re-architecting the way we "build" the command that's run (starting at L80 with execa(yarn ${build ? ...`).

There are three things we can do with the Redwood Storybook command, each with applicable options

  1. Start Storybook server
    (see all options via yarn start-storybook --help)

    • run start-storybook
    • open in browser (default true)
    • set port (default 7910)
    • directory options are hard-coded
  2. Build Storybook static site/assets
    (see all options via yarn build-storybook --help)

    • build-directory option (default web/public/storybook)
    • manager-cache option (default true)
    • directory for config is hard-coded
  3. Smoke-test: Check Storybook in CI
    CI mode plus Smoke-test (skip prompts, don't open browser, exit after successful start)

    • runs the start-storybook command; exits gracefully if started successful, throws otherwise
    • passes --smoke-test and --ci options

So instead of trying to build logic to handle all of these at once, what if we try to build logic based on each case — separating them out? The goal is to rework the complexity we currently have because it's all done at once starting on L80, which makes it really hard to understand what options are required (along with defaults) for the type of run a dev is trying to achieve.

  • yarn rw sb: case 1. above
  • with --build: case 2. above
  • with --smoke-test: case 3. above

Questions? Feedback?

Lastly, ideally we'd add a simple test for this command, which would parse given input and make sure the output is what's expected. That could be a follow-on PR if/as needed — I don't want to slow this down by doubling the scope (twice 😆).

@josemasar
Copy link
Contributor Author

@thedavidprice, when I read the issue, I thought the idea was to declutter the defaults options, so that the commands start and build will not be stepping into each other.

What you explained it makes a lot of sense because it will align better to the Storybook API and an user with previous experience using Storybook will feel familiar with our CLI. Furthermore, any potential change from Storybook, it will be easier to update.

I start working on this!

@thedavidprice
Copy link
Contributor

@josemasar Completely understood. Frankly, I didn't even think about this until I saw what you tried to do, which helped me understand that we have a higher-level problem here — the mashup of conditionals.

Why don't you try to archtect for one case and push that change for us to discuss? Up to you if you want to handle it all at once. I'm just happy to iterate step by step if it feels more efficient for you.

@thedavidprice thedavidprice marked this pull request as draft February 14, 2022 21:59
@thedavidprice thedavidprice self-assigned this Feb 14, 2022
@jtoar jtoar added bug/confirmed We have confirmed this is a bug v1/priority labels Feb 15, 2022
@josemasar
Copy link
Contributor Author

@thedavidprice , I separated the logic in the last commit. I tested in gitpod and launching 'yarn rw sb' and 'yarn rw sb --build' are giving the expected results. On 'yarn rw sb --smoke-test I couldn´t appreciate if there is a difference from 'yarn rw sb' because gitpod is not launching storybook properly. I guess at some point I´ll need to configure WSL for Windows to be more eficient when contributing to Redwood.

Besides, I´ll need to change the managerCache option to e.g. noManagerCache because the user has no ability to shift this parameter to false and storybook is caching always except if the option --no-manager-cached is called. So it´s better to align with the original API.

Copy link
Contributor

@thedavidprice thedavidprice left a comment

Choose a reason for hiding this comment

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

@josemasar this is looking good! Still a few things left to do but really close — see my inline comments.

I tested in gitpod and launching 'yarn rw sb' and 'yarn rw sb --build' are giving the expected results. On 'yarn rw sb --smoke-test I couldn´t appreciate if there is a difference from 'yarn rw sb' because gitpod is not launching storybook properly. I guess at some point I´ll need to configure WSL for Windows to be more eficient when contributing to Redwood.

^^ Hmm, this is strange and maybe something is getting out of sync with GitPod. Just a reminder, if you're using the GitPod container linked from the PR, it only does a one-time "link" with the packages code from the branch. You'll need to run yarn rwfw project:sync yourself.

I can (and will) test myself as well. And I can tell 95% from the code whether things are looking good, which they are so far.

Besides, I´ll need to change the managerCache option to e.g. noManagerCache because the user has no ability to shift this parameter to false and storybook is caching always except if the option --no-manager-cached is called. So it´s better to align with the original API.

Yeah, this one is kinda backwards logic. We do want to use the original behavior, which requires using the && to either add the --no-manager-cache option or not.

Make sense?

@josemasar
Copy link
Contributor Author

@thedavidprice, thanks for the guidance. I made all the changes that you suggested in the inline comments. I had to add an eslint-disable as we are not using open with the new conditionals logic.

@thedavidprice thedavidprice marked this pull request as ready for review February 16, 2022 22:41
Copy link
Contributor

@thedavidprice thedavidprice left a comment

Choose a reason for hiding this comment

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

So close! Check out my comment regarding the open var. We'll be able to get this merged this week for sure.

Thanks again.

packages/cli/src/commands/storybook.js Show resolved Hide resolved
@josemasar
Copy link
Contributor Author

@thedavidprice, I included the open argument and deleted the eslint disable comment.

This PR has been a great way to introduce me into the redwood codebase. The first days I read most of the files for building the CLI commands to get ideas to resolve this issue and adhere to your coding style. That´s been a good learning!

I´d like to continue contributing, so if during your triage sessions, you think an item would be good for me, just text me!

@josemasar
Copy link
Contributor Author

Running yarn rw sb:

yarn rw sb

Running yarn rw sb --build

yarn rw sb --build

Running yarn rw sb --smoke-test

yarn rw sb --smoke-test

@virtuoushub
Copy link
Collaborator

...

Running yarn rw sb --smoke-test

yarn rw sb --smoke-test

Does the smoke test catch "bad" stories? e.g.

+ import StoryRouter from 'storybook-react-router'
import BlogPost from './BlogPost'

export const generated = () => {
  return <BlogPost />
}

- export default { title: 'Components/BlogPost' }
+ export default { title: 'Components/BlogPost', decorators: [StoryRouter()] }

Source: #3515 (comment)

@thedavidprice
Copy link
Contributor

@virtuoushub re: bad stories --> confirmed ✅

@thedavidprice
Copy link
Contributor

Excellent work here @josemasar 🚀

I´d like to continue contributing, so if during your triage sessions, you think an item would be good for me, just text me!

I have one if you're up for it! Basically taking over this one #4445

I'll follow up on Discord

@thedavidprice thedavidprice reopened this Feb 18, 2022
@thedavidprice thedavidprice merged commit d9284aa into redwoodjs:main Feb 18, 2022
@jtoar jtoar added this to the next-release milestone Feb 18, 2022
@thedavidprice thedavidprice modified the milestones: next-release, v0.46.0 Feb 18, 2022
dac09 added a commit to dac09/redwood that referenced this pull request Feb 21, 2022
…test

* 'main' of github.com:redwoodjs/redwood: (23 commits)
  Netlify client getToken fix when GoTrue client refreshes JWT (redwoodjs#4539)
  Update dependency @supabase/supabase-js to v1.30.4 (redwoodjs#4536)
  Envelop: Don't use useImmediateIntrospection as it causes auth bug (redwoodjs#4538)
  Update dependency react-hook-form to v7.27.1 (redwoodjs#4521)
  try increasing timeout for flaky test (redwoodjs#4526)
  Update dependency stacktracey to v2.1.8 (redwoodjs#4519)
  Update dependency msw to v0.38.1 (redwoodjs#4525)
  Update dependency eslint-config-prettier to v8.4.0 (redwoodjs#4522)
  Provide a Revised Runtime Error Page (redwoodjs#4167)
  update yarn.lock
  v0.46.0
  Update dependency esbuild to v0.14.23 (redwoodjs#4518)
  Fix Storybook build args (redwoodjs#4455)
  Update dependency react-helmet-async to v1.2.3 (redwoodjs#4502)
  Bump url-parse in /__fixtures__/example-todo-main-with-errors (redwoodjs#4511)
  Bump url-parse from 1.5.1 to 1.5.7 in /__fixtures__/example-todo-main (redwoodjs#4512)
  Update dependency fastify to v3.27.2 (redwoodjs#4516)
  Uncomment role checks (redwoodjs#4476)
  Update dependency zx to v5.1.0 (redwoodjs#4505)
  Update dependency firebase to v9.6.7 (redwoodjs#4514)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/confirmed We have confirmed this is a bug release:fix This PR is a fix topic/cli
Projects
No open projects
Status: Archived
Development

Successfully merging this pull request may close these issues.

Storybook build fails due to default open arg
5 participants