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

Add node_module symlink support #1530

Merged
merged 9 commits into from
Aug 12, 2017
Merged

Conversation

mlabrum
Copy link
Contributor

@mlabrum mlabrum commented Jul 27, 2017

Issue:
If you have a symlink'd node_module then react-native adds that as a project root, as storybook is manually setting the project roots, storybook will need to detect the symlink and add it as a root

I've ran into this issue because we have a monorepo with symlink'd dependencies....

What I did

Edited the storybook start command to call the react-native symlink detection script and add those to the project root

How to test

  • Move a node module to another location
  • Create a symlink to that node_module
  • Ensure that React Native has picked that module up

Thanks!

Specifying project roots on the command line seem to override read natives detection of symlink'd node_modules.
@ndelangen ndelangen requested review from orta, tmeasday, Gongreg and a team July 27, 2017 22:22
@tmeasday
Copy link
Member

Could this solve some of the problems we've been having too? #1301

@tmeasday tmeasday self-assigned this Jul 28, 2017
@mlabrum
Copy link
Contributor Author

mlabrum commented Jul 28, 2017

It could, we're pretty much doing the same thing

packages/app
  - node_modules
      - common -> symlink to ../../common via npm5 file:

packages/common

packages/web
  - node_modules
      - common -> symlink to ../../common via npm5 file:

If you're using windows you'll need to do the following:

If you're using linux/mac the symlink should just work once the packager has the new root.

I've tested this PR and it does solve my problem. (at least on RN 0.45.1)

@codecov
Copy link

codecov bot commented Jul 28, 2017

Codecov Report

Merging #1530 into master will decrease coverage by 0.14%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1530      +/-   ##
==========================================
- Coverage   21.41%   21.27%   -0.15%     
==========================================
  Files         244      244              
  Lines        5402     5392      -10     
  Branches      663      656       -7     
==========================================
- Hits         1157     1147      -10     
+ Misses       3761     3760       -1     
- Partials      484      485       +1
Impacted Files Coverage Δ
app/react-native/src/bin/storybook-start.js 0% <0%> (ø) ⬆️
lib/ui/src/modules/api/actions/api.js 49.42% <0%> (-1.06%) ⬇️
lib/ui/src/modules/ui/libs/hierarchy.js 45.45% <0%> (ø) ⬆️
.../src/manager/containers/CommentsPanel/dataStore.js 34.78% <0%> (ø) ⬆️
lib/ui/src/modules/shortcuts/actions/shortcuts.js 6.25% <0%> (ø) ⬆️
addons/info/src/components/Props.js 37.2% <0%> (ø) ⬆️
lib/ui/src/modules/ui/containers/layout.js 12.5% <0%> (ø) ⬆️
addons/notes/src/react.js 0% <0%> (ø) ⬆️
lib/ui/src/modules/ui/libs/filters.js 53.33% <0%> (ø) ⬆️
app/react-native/src/bin/storybook-build.js 0% <0%> (ø) ⬆️
... and 12 more

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 b4968af...f1f73a6. Read the comment docs.

@ndelangen
Copy link
Member

@mlabrum Thank you so much for this!

Another stepping stone to getting storybook development in a amazing state!

If you could have a look at the linting or add a eslint-ignore-next-line or something we can get this merged I think.

@ndelangen ndelangen added the maintenance User-facing maintenance tasks label Jul 28, 2017
@mlabrum
Copy link
Contributor Author

mlabrum commented Jul 28, 2017 via email

@atticoos
Copy link
Member

atticoos commented Jul 31, 2017

This is quite clever, thanks for contributing this! I think many of us run into this problem.

I, in particular, use Haul to gain the benefit of webpack. But having this support-built in is a nice frictionless experience.

Can you think of any scenarios where this might cause problems, as the packager would normally skip symlinks? Wondering if it should be a configuration option that users can opt in or out of.

@mlabrum
Copy link
Contributor Author

mlabrum commented Aug 1, 2017

@ajwhite this solution pretty much mocks what react native does when it loads its config
https://github.com/facebook/react-native/blob/113e046444e090e38f89574620210ba86b711fed/local-cli/util/Config.js#L153
but it seems by storybook providing its own project root and directories this is ignored within react native.... so storybook has to add these directories.

I'm not sure how Haul would handle these extra project roots....but react natives packager will be fine

@ndelangen
Copy link
Member

@ajwhite Do you think you could test this for Haul and review & merge?

@tmeasday
Copy link
Member

tmeasday commented Aug 2, 2017

I just took a look at this and it works great!

With this change we can remove the RN apps from our list of "non-lerna-ed" things. Perhaps in a follow up PR.

@ndelangen
Copy link
Member

ndelangen commented Aug 2, 2017

With this change we can remove the RN apps from our list of "non-lerna-ed" things. Perhaps in a follow up PR.

HOLY SMOKES, I'd say that calls for some 🎊 🎈 🎉 💯

@shilman you nightmare is over!

@tmeasday
Copy link
Member

tmeasday commented Aug 2, 2017

Don't get the 🍾 out just yet, bootstrapping was creaking a bit when I tried to test it, but I confirmed that the basic problem (#1301) that caused us to do that was solved by this patch.

@Gongreg
Copy link
Member

Gongreg commented Aug 7, 2017

I just have a question:
Is it safe to depend on react-native/local-cli/util/findSymlinksPaths? This is a quite deep import.

Copy link
Member

@danielduan danielduan left a comment

Choose a reason for hiding this comment

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

Looks good!


const projectRoots = (configDir === projectDir ? [configDir] : [configDir, projectDir]).concat(symlinks);
Copy link
Member

@danielduan danielduan Aug 8, 2017

Choose a reason for hiding this comment

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

I think it'd be a good option somewhere to be able to specify a different project root through storybook-start for those who have components and assets that need to be included from outside of the storybook root project.

It's definitely out of scope of this PR though so don't feel obligated to add this by any means. If it's a feature we want, I think a separate issue is an appropriate place to start.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, it would be nice to have, but probably belongs in a different PR

@mlabrum
Copy link
Contributor Author

mlabrum commented Aug 9, 2017

@Gongreg It's as safe as it could be, I've wrapped it in a try/catch...the only option around this would be to copy their code into the repo.

it's probably the same level of risk as depending on node_modules/react-native/local-cli/cli.js

@ndelangen
Copy link
Member

@tmeasday Are you ready to approve this?

@tmeasday
Copy link
Member

Yes!

@ndelangen ndelangen merged commit 8fcdbe7 into storybookjs:master Aug 12, 2017
@ndelangen
Copy link
Member

Thank you @mlabrum for this PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance User-facing maintenance tasks react-native
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants