{"id":7501,"date":"2018-11-05T10:07:35","date_gmt":"2018-11-05T15:07:35","guid":{"rendered":"http:\/\/www.ericfeminella.com\/blog\/?p=7501"},"modified":"2024-02-23T13:50:31","modified_gmt":"2024-02-23T18:50:31","slug":"synchronizing-package-json-with-yarn-lock","status":"publish","type":"post","link":"https:\/\/www.ericfeminella.com\/blog\/2018\/11\/05\/synchronizing-package-json-with-yarn-lock\/","title":{"rendered":"Synchronizing package.json with yarn.lock"},"content":{"rendered":"<p><img decoding=\"async\" src=\"\/img\/articles\/syncronizing-yarn-lock.png\"\/><br \/>\nAfter having used <a href=\"https:\/\/yarnpkg.com\/en\/\" rel=\"noopener noreferrer\" target=\"_blank\">Yarn<\/a> almost exclusively for the past couple of years, there has been one nagging\u00a0issue which seemed to continually crop up. Specifically, the inability to have a project&#8217;s package.json dependency versions kept in sync with the actual versions in yarn.lock. And so, while running <code>yarn upgrade<\/code> results in all packages being updated to the latest versions (as specified via the given <a href=\"https:\/\/semver.org\/\" rel=\"noopener noreferrer\" target=\"_blank\">semver ranges<\/a>), the versions defined in package.json are not updated to reflect that which they have been upgraded to.  <\/p>\n<p>This can prove problematic as, one can not easily discern a project&#8217;s dependency versions by simply viewing their respective values in package.json.<\/p>\n<p>In particular, as part of process, after each production release I have scripts which are executed to automate the process of updating all project dependencies to their respective latest Minor and Patch\u00a0revisions prior to opening master for new development. While the scripts manage the updates and committals internally, each project&#8217;s package.json would remain unmodified, making it challenging to determine which packages have been upgraded, and which have not. Having to automate or manually inspect the yarn.lock files is less than ideal, and quite cumbersome to say the least.<\/p>\n<p>Fortunately, like most things in the Javascript world, there is a package for this; <a href=\"https:\/\/www.npmjs.com\/package\/syncyarnlock\" rel=\"noopener noreferrer\" target=\"_blank\">syncyarnlock<\/a>, which provides exactly what one would need to ensure that the dependency versions defined in package.json are kept in sync with the project&#8217;s yarn.lock.<\/p>\n<p>Simply install <a href=\"https:\/\/www.npmjs.com\/package\/syncyarnlock\" rel=\"noopener noreferrer\" target=\"_blank\">syncyarnlock<\/a>, and execute with the <a href=\"https:\/\/github.com\/vasilevich\/sync-yarnlock-into-packagejson#usage\" rel=\"noopener noreferrer\" target=\"_blank\">options<\/a> applicable to your needs. <\/p>\n<p>For example, to sync a project&#8217;s package.json with the project&#8217;s yarn.lock, and have the ranges remain intact while updating the versions to reflect what will actually be installed, simply run: <code>syncyarnlock -s -k<\/code>. <\/p>\n<p>This will result in the dependency ranges being preserved, while also updating their versions to reflect the versions that will actually be installed.<\/p>\n<p>And with that, we have proper syncing. A definite time-saver!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After having used Yarn almost exclusively for the past couple of years, there has been one nagging\u00a0issue which seemed to continually crop up. Specifically, the inability to have a project&#8217;s package.json dependency versions kept in sync with the actual versions in yarn.lock. And so, while running yarn upgrade results in all packages being updated to the latest versions (as specified&#8230; <a class=\"read-more\" href=\"https:\/\/www.ericfeminella.com\/blog\/2018\/11\/05\/synchronizing-package-json-with-yarn-lock\/\">Continue Reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":8199,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[44,78,201,35],"tags":[308,292,303,309,305,302,304],"class_list":["post-7501","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code-review","category-javascript-2","category-quick-tips","category-software-engineering","tag-dependencies","tag-npm","tag-package-json","tag-packages","tag-syncyarnlock","tag-yarn","tag-yarn-lock"],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.ericfeminella.com\/blog\/wp-content\/uploads\/2020\/01\/syncronizing-yarn-lock.png?fit=718%2C320&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/posts\/7501","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/comments?post=7501"}],"version-history":[{"count":0,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/posts\/7501\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/media\/8199"}],"wp:attachment":[{"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/media?parent=7501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/categories?post=7501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/tags?post=7501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}