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): add staticDirs object schema #8885

Merged
merged 1 commit into from Mar 8, 2022
Merged

fix(storybook): add staticDirs object schema #8885

merged 1 commit into from Mar 8, 2022

Conversation

leon
Copy link
Contributor

@leon leon commented Feb 7, 2022

Storybook has renamed staticDir to staticDirs.

The have also added a way to specify an object:

module.exports = {
  staticDirs: [{ from: '../my-custom-assets/images', to: '/assets' }],
};

This PR adds the schema for staticDirs, and x-deprecates staticDir.
I don't know if we should do this, because they just fallback if they find staticDir

https://github.com/storybookjs/storybook/blob/92b23c080d03433765cbc7a60553d036a612a501/lib/core-server/src/utils/server-statics.ts#L30

Background

I needed to copy multiple directories and rename them.
the current string[] makes this impossible.

Questions

  • Should we deprecate staticDir?

@nx-cloud
Copy link

nx-cloud bot commented Feb 7, 2022

☁️ Nx Cloud Report

CI ran the following commands for commit 85491cf. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 7 targets

Sent with 💌 from NxCloud.

@vercel
Copy link

vercel bot commented Feb 7, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/nrwl/nx-dev/BtuHZKe3uGpZ1eNgQoEthqUtnQsj
✅ Preview: https://nx-dev-git-fork-leon-fix-storybook-static-dir-objec-1a60a9-nrwl.vercel.app

@leon leon changed the title fix(storybook): add staticDir object schema fix(storybook): add staticDirs object schema Feb 9, 2022
@ChazUK
Copy link

ChazUK commented Feb 28, 2022

Would be nice if this went in as they have added features that would be nice to use in the storybook executor

@mandarini
Copy link
Member

Hi all! @leon sorry for some reason I just saw this. Can you please rebase and push again, and I will approve!

@leon
Copy link
Contributor Author

leon commented Mar 2, 2022

@mandarini done :)

@ChazUK
Copy link

ChazUK commented Mar 2, 2022

@leon I think the staticDirs can also take a plain string instead of the { from: '', to: ''} pattern. https://storybook.js.org/docs/react/configure/images-and-assets#serving-static-files-via-storybook-configuration

@leon
Copy link
Contributor Author

leon commented Mar 2, 2022

@ChazUK Yes, this is accounted for by having the "oneOf" here
https://github.com/leon/nx/blob/fix/storybook-static-dir-object-schema/packages/storybook/src/executors/storybook/schema.json#L166

@ChazUK
Copy link

ChazUK commented Mar 2, 2022

My bad, missed that line, thank you!

@mandarini mandarini enabled auto-merge (squash) March 2, 2022 16:35
@ChazUK
Copy link

ChazUK commented Mar 7, 2022

@mandarini I've noticed the build has not passed, will this effect the auto-merge?

auto-merge was automatically disabled March 8, 2022 06:53

Head branch was pushed to by a user without write access

@leon
Copy link
Contributor Author

leon commented Mar 8, 2022

@mandarini I don't know why my PR didn't want to build.
I tried pushing to the branch to trigger a new build, but now it says the auto merge has been disabled.
so you will have to have a look at it :)

let me know if you want me to do something.

Adds schema for the more advanced storybook staticDirs config defined here.

https://storybook.js.org/docs/react/configure/images-and-assets
@leon
Copy link
Contributor Author

leon commented Mar 8, 2022

Yeey 🥳🙌

@leon leon deleted the fix/storybook-static-dir-object-schema branch March 8, 2022 17:10
@iamrommel
Copy link

iamrommel commented Mar 11, 2022

This thing breaks my storybook. The storybooks even encourage the use of main.js for staticDirs and deprecated the CLI
image

Currently I'm using the main.js for my staticDirs, but it got conflicts with the project.json storybook config
image

my project.json config has not used any staticDir config
image

@mandarini
Copy link
Member

Ooops! Thanks @iamrommel ! @leon do you want to look into this? Or should I?

@leon
Copy link
Contributor Author

leon commented Mar 11, 2022

@mandarini @iamrommel

When I did the PR it was only to fix that you could not pass along multiple strings via the nx storybook plugin.

It's up to you to choose where you want to add the staticDirs setting.

the reason for nx having the option in their config, is so you can have multiple configurations and setup different staticDirs depending on stage, prod environments.

but I generally think it's better to keep it as close to the authors standard as possible, because their documentation is often better kept.

So to your problem.
just choose where you want to add it and remove it from the other place and you will be fine 👍🏻

@iamrommel
Copy link

iamrommel commented Mar 11, 2022 via email

@vrady
Copy link

vrady commented Mar 12, 2022

@leon

The same happens for me.
Property staticDir is always empty array
So storybook checks for deprecated and new properties from config, and deprecated field always return true in this if statement (empty array is not false)

image

When I trying to pass null in project.json for deprecated field, the executor pass default value (empty array)

So its impossible to use not deprecated filed staticDirs, cause deprecated field staticDir always return true in if statement

image

Please fix it or just remove default value from $schema for deprecated field

@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants