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

Moving repositories without recreating yarn.lock? #4817

Closed
imsnif opened this issue Nov 1, 2017 · 14 comments · Fixed by #4860
Closed

Moving repositories without recreating yarn.lock? #4817

imsnif opened this issue Nov 1, 2017 · 14 comments · Fixed by #4860

Comments

@imsnif
Copy link
Member

imsnif commented Nov 1, 2017

Do you want to request a feature or report a bug?

Bug (I think!)

What is the current behavior?
We're trying to move to a new internal npm repository (specifically, moving from Sinopia to Nexus). We've been using yarn extensively for all of our packages. So when moving, we have to do a search/replace of the repository-url in the yarn.lock file.
While not ideal, this is not a problem.

The problem is with the sha checksum of each package. The checksum includes (from the generated package.json file of each package in node_modules) the repository url. Meaning it is by definition different and yarn fails with:
error <package_in_new_repository>.tgz: Bad hash. Expected "<old_checksum>" but got "<new_checksum>"

Looking through the documentation and the issues I could not find any mention of a solution for this. Am I missing something? Is there a better solution than updating all the checksums in addition to the repository urls in yarn.lock?

If the current behavior is a bug, please provide the steps to reproduce.

  1. install a private package through one private repository (Sinopia/Verdaccio/Nexus/etc.) and save it to package.json and yarn.lock
  2. delete node_modules and yarn cache, change the repository url in yarn.lock to a different private repository
  3. try to install the package again

What is the expected behavior?
If indeed I did not miss an existing option to do so, I think a yarn --update-checksum flag would be nice. I'd be willing to work out a PR.

@csvan
Copy link

csvan commented Nov 2, 2017

There is an ongoing RFC that may resolve your issue: yarnpkg/rfcs#84 (comment)

@bestander
Copy link
Member

I don't see tarball fetcher using URL when checking hash

const expectHash = this.hash;
.
Only tarball contents should matter.

Are you sure that when you switch to another private repository the tarball content does not change?

@bestander
Copy link
Member

On the other hand I like the idea --update-checksum, a few times when dealing with local packages I needed to update the hash of a dependency in yarn.lock file.
Would you mind sending a short RFC/PR for this change?
It will totally be useful.

@imsnif
Copy link
Member Author

imsnif commented Nov 2, 2017

Hey @bestander - so this is apparently a bit of an edge case:
The checksums can potentially differ because of this field in package.json:
https://docs.npmjs.com/all#resolved
eg:

// package.json
// ...
"_resolved": "https://old-repo:1337/package-name/-/package-name-1.1.1.tgz",
// ...

In such cases the checksum can be affected (I think this happens mainly in setups such as Sinopia/Verdaccio where some packages are private and some are public, but I'll admit that I have not checked the use-case here thoroughly yet!)

I'd love to do a PR for --update-checksum. I'm not familiar with the process though, do I need to write an RFC first or can I jump straight in?

@bestander
Copy link
Member

RFC is a chance to get comments from other contributors, sometimes people notice edge cases or the opposite - suggest a more generic solution that solves other problems.

This change is quite small, non breaking and quite focused though, I think a good PR with a decent description and unit tests would be enough.

@bestander
Copy link
Member

Back you your problem, afaik _resolved field is not necessary, is it possible to strip it before you publish?

@imsnif
Copy link
Member Author

imsnif commented Nov 2, 2017

It is possible, but it would complicate the repository migration. I thought an --update-checksum flag would solve this and benefit others in similar situations as well. (Currently I'm scripting the checksum update).

I'll start working on the PR and hopefully have something soon. Thanks!

@imsnif
Copy link
Member Author

imsnif commented Nov 2, 2017

Come to think of it, if we strip it the checksum would still be changed.

@bestander
Copy link
Member

Yeah, it would require a 4 step change:

  1. strip checksum
  2. republish to old repo
  3. update yarn.lock
  4. switch registry

Whatever works best for you :)

@imsnif
Copy link
Member Author

imsnif commented Nov 5, 2017

Hey @bestander - I created a PR for this: #4860
It's my first one to this repo, so I hope I didn't make any faux pas :)

@imsnif
Copy link
Member Author

imsnif commented Nov 6, 2017

If I may make an additional related suggestion (sorry, it just came to mind): right now, if there is no hash string at all in a package in yarn.lock (rather than a corrupted one) I think yarn leaves things as they are (i.e. with no hash string). Perhaps if --update-checksums is on, it could update it with the new checksum? I'd be happy to make another PR to that effect (I'm thinking it's out of scope for this one?)

@bestander
Copy link
Member

bestander commented Nov 6, 2017 via email

@imsnif
Copy link
Member Author

imsnif commented Nov 6, 2017

I'll wait for the current one to be merged though in order to decrease the amount of chaos. :)

@BYK BYK closed this as completed in #4860 Nov 7, 2017
BYK pushed a commit that referenced this issue Nov 7, 2017
**Summary**

Fixes #4817.
When the `--update-checksums` flag is set, yarn would know to ignore a checksum mismatch between `yarn.lock` and the repository, and instead update the yarn.lock file with the proper checksum(s).

**Test plan**

Added new tests.

To manually check this:
1. Change one or more of the package checksums in `yarn.lock`
2. Delete node_modules (optionally also run `yarn cache clean`)
3. Run `yarn` => checksum mismatch error will be received.
4. Run `yarn --update-checksums` => will install successfully and fix the damaged checksums in `yarn.lock`
calvinhuang pushed a commit to calvinhuang/yarn that referenced this issue Nov 9, 2017
**Summary**

Fixes yarnpkg#4817.
When the `--update-checksums` flag is set, yarn would know to ignore a checksum mismatch between `yarn.lock` and the repository, and instead update the yarn.lock file with the proper checksum(s).

**Test plan**

Added new tests.

To manually check this:
1. Change one or more of the package checksums in `yarn.lock`
2. Delete node_modules (optionally also run `yarn cache clean`)
3. Run `yarn` => checksum mismatch error will be received.
4. Run `yarn --update-checksums` => will install successfully and fix the damaged checksums in `yarn.lock`
@kopax-polyconseil
Copy link

I don't see tarball fetcher using URL when checking hash

const expectHash = this.hash;

.
Only tarball contents should matter.
Are you sure that when you switch to another private repository the tarball content does not change?

The checksum of the yarn lock change, that's already a problem, another problem is the git repo not being up to date after change. A workaround would be to be able to specifiy the lock file, and create a 2nd one with the first one. But that's also not possible.

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

Successfully merging a pull request may close this issue.

4 participants