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

Does not always work for monorepository. #9

Open
sasaxing opened this issue Mar 15, 2018 · 4 comments
Open

Does not always work for monorepository. #9

sasaxing opened this issue Mar 15, 2018 · 4 comments

Comments

@sasaxing
Copy link

Sometimes if an optional module optModule is installed in one of the sub-packages instead of in projectRoot/node_modules, then it won't be found by optional('optModule').

@BrunnerLivio
Copy link

Any update / alternative on this issue?

@tony-o
Copy link
Owner

tony-o commented Oct 4, 2018

@BrunnerLivio do you have an example I can troubleshoot this with?

@BrunnerLivio
Copy link

BrunnerLivio commented Oct 4, 2018

There you go:
https://github.com/BrunnerLivio/optional-monorepo-bug

When using yarn workspaces, some dependencies might get installed in a
subfolder of a package. In this example it would be the dependency packages/core/node_modules/lodash.

Since optional only uses the NodeJS require resolution, which only checks dependencies
upwards from the root directoy e.g. rootDirectory/../package.json and not downwards rootDirectory/*/package.json
it can not find the lodash package.

├── index.js
├── node_modules
|  └── optional
├── package.json
└── packages
   └── core
      ├── node_modules
      |  └── lodash
      └── package.json

Honestly I do not know how properly fix this bug. One option would be to explicitly support yarn workspaces, therefore parse the package.json of the root directory and search for the workspaces attribute, but I am not quite sure this is the right way to go..

@tony-o
Copy link
Owner

tony-o commented Oct 5, 2018

@BrunnerLivio what mechanism do you use outside of optional that searches downwards into packages/?

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

No branches or pull requests

3 participants