question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Publish Support For `Yarn Berry`/`Yarn 2`

See original GitHub issue

Affected Packages

@changesets/cli

Problem

I recently setup yarn berry and changesets in my repo. First I noticed that status wasn’t working because it wasn’t running yarn in front of npm commands so it wasn’t looking for my yarnrc.yml. I worked around that but then was seeing a similar issue with publish. Digging in, I can see that it’s a similar problem in that publish isn’t running yarn npm publish like yarn berry wants.

https://github.com/changesets/changesets/blob/94f609773a91ef70c631e0ee243a79114f382f6b/packages/cli/src/commands/publish/npm-utils.ts#L171

Proposed solution

Probably need to make something a little more flexible instead of just publishTool.name, or have the name for yarn berry be yarn npm instead of just yarn.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Andaristcommented, May 20, 2022

Thanks for this comment and the done testing related to this ❤️ I’d like to merge this stuff into the main branch - it’s already hanging there for quite a bit of time. Honestly… I’m a little bit scared of that PR as it’s so delicate and so hard to test out all of the package managers with different combinations of private/public packages etc

This is very helpful.

0reactions
ewlshcommented, May 20, 2022

@Andarist We’re using 2.22.0-temp.0 (mostly) successfully to publish our packages, we ran into a snag using yarn v3 with private packages though.

The current npm info command only works if .npmrc exists and is configured (which it no longer is). We used yarn patch (like patch-package) to patch @changesets/cli to use yarn npm info {package} --json instead. This seems to be working great - the comment on caching issues probably no longer applies to yarn npm info (vs. the legacy yarn info)

diff --git a/dist/cli.cjs.dev.js b/dist/cli.cjs.dev.js
index 8d826de63e1289666b7a47c4f2260348febcf523..b8d1ec1c3e228840dd8bff85ae901e750cca1f5f 100644
--- a/dist/cli.cjs.dev.js
+++ b/dist/cli.cjs.dev.js
@@ -665,7 +665,7 @@ function getPackageInfo(packageJson) {
     // as they will always give a 404, which will tell `publish` to always try to publish.
     // See: https://github.com/yarnpkg/yarn/issues/2935#issuecomment-355292633
 
-    let result = await spawn__default['default']("npm", ["info", packageJson.name, "--registry", getCorrectRegistry(packageJson), "--json"]); // Github package registry returns empty string when calling npm info
+    let result = await spawn__default['default']("yarn", ["npm", "info", packageJson.name, "--json"]); // Github package registry returns empty string when calling npm info
     // for a non-existent package instead of a E404
 
     if (result.stdout.toString() === "") {
diff --git a/dist/cli.cjs.prod.js b/dist/cli.cjs.prod.js
index ab0ea013e7e93781c3026ec2674937376e4d87ae..0d5de9375abca0a3b0fb5ed3b07e03b30d49fbd9 100644
--- a/dist/cli.cjs.prod.js
+++ b/dist/cli.cjs.prod.js
@@ -388,7 +388,7 @@ async function getTokenIsRequired() {
 function getPackageInfo(packageJson) {
   return npmRequestLimit((async () => {
     logger.info("npm info " + packageJson.name);
-    let result = await spawn__default.default("npm", [ "info", packageJson.name, "--registry", getCorrectRegistry(packageJson), "--json" ]);
+    let result = await spawn__default.default("yarn", ["npm", "info", packageJson.name, "--json"]);
     return "" === result.stdout.toString() ? {
       error: {
         code: "E404"
diff --git a/dist/cli.esm.js b/dist/cli.esm.js
index d03dfdfde80ebf068fe1a80504fe88dc24bdb0be..8620fb73d2554eeb78f53b505485ef3e235a4c9d 100644
--- a/dist/cli.esm.js
+++ b/dist/cli.esm.js
@@ -643,7 +643,7 @@ function getPackageInfo(packageJson) {
     // as they will always give a 404, which will tell `publish` to always try to publish.
     // See: https://github.com/yarnpkg/yarn/issues/2935#issuecomment-355292633
 
-    let result = await spawn$1("npm", ["info", packageJson.name, "--registry", getCorrectRegistry(packageJson), "--json"]); // Github package registry returns empty string when calling npm info
+    let result = await spawn$1("yarn", ["npm", "info", packageJson.name, "--json"]); // Github package registry returns empty string when calling npm info
     // for a non-existent package instead of a E404
 
     if (result.stdout.toString() === "") {

This obviously doesn’t work for npm users so it’d likely need a conditional “if yarn v2+, use yarn npm info”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

yarn publish
Publishes a package to the npm registry. Once a package is published, you can never modify that specific version, so take care before...
Read more >
JavaScript package managers compared: npm, Yarn, or ...
Its successor, Yarn v2 or Berry, is now the active development branch. ... With the help of Corepack, you don't have to install...
Read more >
yarn
For defining a registry you must use the .yarnrc.yml located in the root of your project or global configuration. When you publish a...
Read more >
Migrating to Yarn 2
This article is intended to help current Heroku users migrate from Yarn 1 to Yarn 2. Apps being migrated should already be using...
Read more >
Configure and use Yarn with CodeArtifact
After you create a repository, you can use the Yarn client to manage npm ... and uses information from your npm configuration file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found