yalc icon indicating copy to clipboard operation
yalc copied to clipboard

Question about using yalc with monorepo/workspaces and many apps

Open lipedeitos opened this issue 5 years ago • 11 comments

Hi!

I have a monorepo with about 40 components, and I'm using yarn workspaces to deal with dependencies, my folder structure and yarn are like this:

// folder structure
packages/comp1
packages/comp1/packages.json
packages/comp2
packages/comp2/packages.json
packages/comp3
packages/comp3/packages.json

// packages.json
"workspaces":  [
    "packages/*"
],

Then I have a test application, in another directory. So to get everything working, I would link the componentes one by one running yarn link inside their folder. In the application, run yarn install and after that I used to link all the packages comp1, comp2, comp3 to the application using yarn link comp1. Finally when I'v run the application I could change the components and test them perfectly.

But with that process, I only had the package linked and not is dependencies, so if I go to comp1, and update one of they'r dependencies, the link will not find the new dependency.

After a little search I'v came across yalc, and tried to use it but without success. With this structure I have, how should I use yalc?

lipedeitos avatar Dec 18 '19 19:12 lipedeitos

Was just coming here to report/ask a similar question. Similar monorepo, but for me I have a single package shared by my sub module workspaces and main workspace.

eg: main /package/module1 /package/module2 /package/module3

all have a dependency of "core" module

From the workspace side everything is hoisted properly and I only see a single core module in node_modules. However if try to yalc link it. it never symlinks to the .yalc/core folder

Using yarn link, it creates the proper symlink but since its react it breaks rendering.

As a work around I manually symlinked the package myself. ln -s ../.yalc/core ./core

jchamb avatar Dec 18 '19 21:12 jchamb

I not getting why yarn link is used at all in yarn workspaces monorepo. Yarn ws supposed to handle all the linkings into root node_modules automatically.

So I'm just not getting your scenario -)

Yalc'ed packages may play well with yarn ws monorepos when you declare them as workspace they will be linked automatically as everything else in monorepo, that is all.

wclr avatar Dec 20 '19 10:12 wclr

"I not getting why yarn link is used at all in yarn workspaces monorepo. Yarn ws supposed to handle all the linkings into root node_modules automatically."

So actually my scenario was working perfectly, until I have to update a third lib from a package, comp1 example, supose it has the react@15 installed on it's package.json. Then I'v use yarn upgrade do move to react@16... the componente itself and the root node_modules on packages are up to date (using WS).

The problem is the application that is consuming those packages via YARN LINK are not getting this updates because the application still get the OLD package dependencies but the NEW packages files linked.

The scenario os more clear now? If don't ask me and I try to explain even more with examples.

lipedeitos avatar Dec 20 '19 17:12 lipedeitos

The scenario os more clear now? If don't ask me and I try to explain even more with examples.

What is yalc here for?

The problem is the application that is consuming those packages via YARN LINK are not getting this updates because the application still get the OLD package dependencies

You should update package dependencies in linked app.

wclr avatar Dec 22 '19 09:12 wclr

What is yalc here for?

As I said, I'm linking some components while in development, so I don't need to publish it everytime. Until now, yarn link was working 100%, but I came across the scenario that my component need to upgrade one of its dependencies, and the link doesn't work anymor, because yarn only link to components files and not is dependencies. Then I'v discovered ylc...

You should update package dependencies in linked app.

The linked app have his package.json with all deps and dev deps in it, if I run some yarn upgrade or yarn upgrade-interactive it'll respect the package.json and override the linked packages don't?

lipedeitos avatar Dec 26 '19 14:12 lipedeitos

@whitecolor like @lipedeitos said, I'm only using this for development purposes for a react library, that I is built with rollup before linking. In production yarn/yalc link are not used.

What you said is correct about the workspace packages, everything is being lifted up to the top level of the node_modules as you would expect with workspaces. What I was trying to point out (not very well) is that I expected yarn link and yalc link to work similarly after initial install, and create a symlink.

for example purposes if I do:

yarn link core creates symlink node_modules/core --> [LOCAL_PATH]/core yalc link core creates .yalc/core folder, DOES NOT create symlink node_modules/core --> ../.yalc/core

my work around for the above is to manually symlink my core folder to the .yalc folder. mv node_modules/core node_modules/core.bck && cd node_modules && ln -s ../.yalc/core ./core

Maybe yalc is behaving correctly, I was just basing all this off of what it does when not using workspaces. If this is case, please let me know and i'll look for an alternative solution.

after @lipedeitos second explanation it sounds like we are actually having different issues, sorry I hijacked the thread, seemed like we were having the same issue originally.

jchamb avatar Dec 27 '19 19:12 jchamb

yalc link core creates .yalc/core folder, DOES NOT create symlink node_modules/core --> ../.yalc/core

yalc link should create symlink in node_modules pointing to package sources copied into .yalc folder.

wclr avatar Dec 28 '19 21:12 wclr

@whitecolor do you have any suggestions on how I can debug or test why it is not creating the symlink like it should?

I've tried everything under Use with Yarn workspaces! to no avail.

jchamb avatar Jan 02 '20 17:01 jchamb

Tried using Yalc in a Yarn Workspaces project, and my app won't work. The package I'm trying to patch through is subdependency.

Any plans on fixing this?

lolmaus avatar May 26 '21 08:05 lolmaus

Tried using Yalc in a Yarn Workspaces project, and my app won't work. The package I'm trying to patch through is subdependency.

You'll have to explain your setup in detail to explain what does not work. Also you may consider creating a sample repo wich will expose the problem.

wclr avatar May 26 '21 08:05 wclr

I'm sorry, my problem seems not to be with Yalc itself.

Using a yalced package triggered an update in yarn.lock. The issue persisted even after removing all things yalcy. Only reverting yarn.lock made the app work again. 😒

lolmaus avatar May 26 '21 09:05 lolmaus