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

Adding a new package in a dependency breaks yalc #144

Closed
rahul22048 opened this issue Nov 28, 2020 · 28 comments
Closed

Adding a new package in a dependency breaks yalc #144

rahul22048 opened this issue Nov 28, 2020 · 28 comments

Comments

@rahul22048
Copy link

Let's say package A is added as a dependency in package B, and A is referred in B through yalc . Now when i add some package in A and make the corresponding changes in package A, and do yalc push to update the changes in package B. Code changes are reflected correctly in B, but it breaks at run time saying the package i added in A is not available. Is it a known issue?

@rahul22048 rahul22048 reopened this Dec 2, 2020
@rahul22048
Copy link
Author

@aleclarson :- Could you have a look at this issue. We have taken dependency on yalc, and it is serving most of our use cases except this bug. We tried different ways at our end, but are not able to get a way around this bug.

@rahul22048
Copy link
Author

@aleclarson @whitecolor :- Could you have a look at this issue. We have taken dependency on yalc, and it is serving most of our use cases except this bug. We tried different ways at our end, but are not able to get a way around this bug.

@wclr
Copy link
Owner

wclr commented Dec 3, 2020

Yalc is very simple, (while push) it just copies new package content into your location. So what issues this can cause in your case? I'm not sure what is the exact problem is. You didn't provide the details of an error or something.

@rahul22048
Copy link
Author

@whitecolor :- let's take the above example, where package A is added as a yalc dependency in B. Now i add some package, let's say C in A, and did some code changes, and did yalc push to make the changes reflect in package B. Now when i go inside .yalc folder inside package B, i see the code changes getting reflected there. Now when i start the server in B, at run time i get error message :- Cannot find module 'C'. Essentially the code changes did reflect, but the package i added in A, somehow didn't reflect inside B.

@rahul22048
Copy link
Author

Is there some command that we need to run before running yalc push, in case we do npm install 'Some package' in dependency (package A in above case).

@wclr
Copy link
Owner

wclr commented Dec 5, 2020

Now i add some package, let's say C in A, and did some code changes

If you add a dependency to package you need to run install command in your project, yalc doesn't doen't this, there is a flag called --yarn || --npm currenlty to run while add/push.

@grebenyuksv-preply
Copy link

grebenyuksv-preply commented Dec 6, 2020

I suspect the problem lies on the Yarn/NPM side, which seem to be caching file:.-like dependencies forever. I'm not sure if it's a good design, but there seem to have been long discussions about that: yarnpkg/yarn#2165.

Calling yarn/npm i doesn't seem to update the lock files for me. However, adding this to my lib's package.json file seems to do the trick:

    "scripts": {
        "postupdate": "ls | grep yarn.lock && yarn upgrade lib || :; ls | grep package-lock.json && npm uninstall lib && yalc add lib && npm i || :"
    },

@whitecolor, do you mind sharing with us, what's the logic behind simply calling yarn/npm i when being passed --yarn/--npm? Wouldn't yarn upgrade [lib]/npm update [lib] support this use case on top of doing what it already does?

@wclr
Copy link
Owner

wclr commented Dec 7, 2020

@grebenyuksv-preply
Probably I had this issue with yarn cache before, seems yalc even had a workaround for this, but it was a hack and was removed. Try to add package with link: protocol for your case (use yalc add --link ...)

@rahul22048
Copy link
Author

@whitecolor @grebenyuksv-preply :- Thanks for the response. Let me try both of the approaches , and i will get back to you.

@grebenyuksv-preply
Copy link

grebenyuksv-preply commented Dec 7, 2020

@whitecolor do you mean postupdate was the hack which was removed? At least it looks so.

How would yalc add --link update my lock files everywhere? I did try, it didn't do the trick, but I didn't really expect that to work. Here's what I'm trying to achieve (I believe it's exactly what @rahul22048 means):

  • My yalc'ed package is lib, which is consumed by host-npm and host-yarn
  • When I call yalc push in lib, I want the lock files in the hosts to get updated because I might have changed lib's dependencies

@grebenyuksv-preply
Copy link

grebenyuksv-preply commented Dec 7, 2020

Thanks for the response. Let me try both of the approaches , and i will get back to you.

@rahul22048 I've just discovered that there's no more postupdate in the latest version, mind that. My approach works with 1.0.0-pre.35.

@rahul22048
Copy link
Author

@whitecolor do you mean postupdate was the hack which was removed? At least it looks so.

How would yalc add --link update my lock files everywhere? I did try, it didn't do the trick, but I didn't really expect that to work. Here's what I'm trying to achieve (I believe it's exactly what @rahul22048 means):

  • My yalc'ed package is lib, which is consumed by host-npm and host-yarn
  • When I call yalc push in lib, I want the lock files in the hosts to get updated because I might have changed lib's dependencies

Yes , i am trying to do exactly the same thing

@rahul22048
Copy link
Author

Thanks for the response. Let me try both of the approaches , and i will get back to you.

@rahul22048 I've just discovered that there's no more postupdate in the latest version, mind that. My approach works with 1.0.0-pre.35.

@grebenyuksv-preply :- I will try to install version '1.0.0-pre.35' and run the 'postupdate' command. On a side note if it works, would it make sense to include this in the current version? Because i feel this is going to be a very common scenario

@grebenyuksv-preply
Copy link

@rahul22048 makes sense to me but I'm not a maintainer :)

@whitecolor would returning postupdate make sense to you? Or maybe you have any better suggestion for us?

@rahul22048
Copy link
Author

rahul22048 commented Dec 7, 2020

@grebenyuksv-preply :- In your post update statement ls | grep package-lock.json && npm update lib
i have a following question:-
i guess it would update package-lock file of current package (package A in our example)? If yes this was happening before as well. The problem was after doing yalc push inside package A, package-lock file of package B was not reflecting the added package

And somehow reverting to version 1.0.0-pre.35 of yalc, is not working. It is somehow not able to publish the changes to yalc store.

I found the following workaround:-

First of all i reverted to latest version of yalc. After doing yalc push inside package A, i went to package B (in which A was yalc referred) and deleted the package-lock file altogether, and then did npm install . (earlier i was just doing npm install), and then checked package-lock file of B. Now the added dependency was getting reflected.

@whitecolor :- I am not sure, is this an issue at yalc end or npm, from customer perspective ideal solution would be that package-lock file is also updated to reflect the added dependency.

@wclr
Copy link
Owner

wclr commented Dec 7, 2020

do you mean postupdate was the hack which was removed

No I don't know what is postupdate. I was related to cleaning up yarn cache. It was long time ago.

I am not sure, is this an issue at yalc end or npm,

I don't get the issue. Yalc just copies the new content (including package.json with new deps). Then you should run install command in to get new deps installed. Doesn't this flow work?

@rahul22048
Copy link
Author

@whitecolor :- This flow doesn't work in cases when i add a package (let's say C inside A in above example), and then do yalc push (inside Package A above). Then the changes are not reflected correctly. Code changes are there, but the added dependency C inside A in not there in package-lock file in B. Did u get the complete picture of the issue now?

@wclr
Copy link
Owner

wclr commented Dec 7, 2020

Yes I think I have met the same issue.

but the added dependency C inside A in not there in package-lock file in B

So your C dep is not updated (on yarn install) in the root node_modules? What PM do you use?

@grebenyuksv-preply
Copy link

grebenyuksv-preply commented Dec 8, 2020

Neither yarn nor npm i update the lock files properly, here I put together a small repo illustrating this: https://github.com/grebenyuksv-preply/yalc-postupdate-example

Note, I understand this sounds a bit out of Yalc's scope, so I'm not suggesting to make it work. I do wonder, however:

  • Aren't Yalc's --yarn/--npm flags designed to do this?
  • Does it sound feasible for you to return postupdate to Yalc?

I'm basically trying to leverage Yalc while building a CI/CD pipeline for this all.

@wclr
Copy link
Owner

wclr commented Dec 8, 2020

@grebenyuksv-preply
You need to add "postyalc": "yarn upgrade lib" in "scripts" of host-yarn/package.json it will execute it on yalc push, you can be also more specific for handling particular package updates "postyalc.lib": "yarn upgrade lib"

@grebenyuksv-preply
Copy link

grebenyuksv-preply commented Dec 10, 2020

@grebenyuksv-preply
You need to add "postyalc": "yarn upgrade lib" in "scripts" of host-yarn/package.json it will execute it on yalc push, you maybe also specific for handling particular package operations "postyalc.lib": "yarn upgrade lib"

That should be able to replace postupdate's functionality, thank you very much for pointing that out! My bad, I didn't re-read the docs after discovering postupdate is no longer there.

@wclr
Copy link
Owner

wclr commented Dec 10, 2020

Yeah, postupdate in docs was misleading, removed it and added new. Also added --update flag, used with push will execute yarn/npm upgrade in target dir.

@grebenyuksv-preply
Copy link

I won't use --update since it doesn't seem to be updating the hosts' lock files, but postyalc does seem to work for my needs. Thanks for that!

Let's see if @rahul22048 needs anything else.

@wclr
Copy link
Owner

wclr commented Dec 11, 2020

--update will execute yarn upgrade package-name so it should modify lock file, I believe.

@grebenyuksv-preply
Copy link

grebenyuksv-preply commented Dec 14, 2020

I also had to clean up host-npm/.yalc/lib/node_modules after modifying the dependency tree, so it didn't appear that easy to me

@wclr
Copy link
Owner

wclr commented Dec 14, 2020

I also had to clean up host-npm/.yalc/lib/node_modules

Why?

@grebenyuksv-preply
Copy link

Hmm I can't reproduce the issue with NPM I was having, looks like --update just works!

@wclr
Copy link
Owner

wclr commented Jan 19, 2021

I think I will close it, reopen if needed.

@wclr wclr closed this as completed Jan 19, 2021
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