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

Publish Support For Yarn Berry/Yarn 2 #714

Open
rjhilgefort opened this issue Dec 15, 2021 · 7 comments
Open

Publish Support For Yarn Berry/Yarn 2 #714

rjhilgefort opened this issue Dec 15, 2021 · 7 comments

Comments

@rjhilgefort
Copy link

rjhilgefort commented Dec 15, 2021

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.

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.

@Andarist
Copy link
Member

The publishing issue is being fixed here: #674 . You can even install the version from this PR (roughly) as it’s available on npm as @changesets/cli@temp

Could you expand on the status issue though? Im not using this command myself and have no access to the computer right now to look through the code but i dont see why using yarn over npm would matter for it. Why reading yarnrc.yml is relevant for this command?

@rjhilgefort
Copy link
Author

The publishing issue is being fixed here: #674 . You can even install the version from this PR (roughly) as it’s available on npm as @changesets/cli@temp

Thanks @Andarist, I'm actually already running your changes but haven't pulled them in since you fixed publish. I'll try it out!

Could you expand on the status issue though? Im not using this command myself and have no access to the computer right now to look through the code but i dont see why using yarn over npm would matter for it. Why reading yarnrc.yml is relevant for this command?

It was related to this line running npm profile instead of yarn npm profile IIRC.

let result = await spawn("npm", ["profile", "get", "--json"], {

@Andarist
Copy link
Member

Thanks @Andarist, I'm actually already running your changes but haven't pulled them in since you fixed publish. I'll try it out!

Hm, what exact version/commit are you running then? 🤔

It was related to this line running npm profile instead of yarn npm profile IIRC.

This shouldn't affect the changeset status though - but I can see how it can affect changeset publish. Gonna look into this.

@rjhilgefort
Copy link
Author

Hm, what exact version/commit are you running then? 🤔

Whatever the state of that tag was about 5 days ago. I'm on Yarn 2 with PnP so I don't get updates as you push them.

This shouldn't affect the changeset status though - but I can see how it can affect changeset publish. Gonna look into this.

Ah, I think that's where I saw the issue now that you mention it!

@Andarist
Copy link
Member

Can you try this version: @changesets/cli@https://pkg.csb.dev/changesets/changesets/commit/98401c27/@changesets/cli/_pkg.tgz? You might need to add this Yarn plugin to make it work though: yarnpkg/berry#3327 (comment)

@ewlsh
Copy link

ewlsh commented 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".

@Andarist
Copy link
Member

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.

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