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

Yarn usage breaking npm plugin #629

Closed
jchamb opened this issue Mar 25, 2020 · 6 comments
Closed

Yarn usage breaking npm plugin #629

jchamb opened this issue Mar 25, 2020 · 6 comments

Comments

@jchamb
Copy link

jchamb commented Mar 25, 2020

Had some issue with our project that uses yarn.
Even though I set

"publishConfig": {
        "registry": "https://registry.npmjs.org/"
      }

Since it matched the default registry it never stuck it in the command so it would never pass the auth check.

It also needs added to add the registry to the publish command for it to work.

I ended up extending the npm plugin to create a npmCustom to use instead. Note: just showing the modified parts, and my publish override has some other mods around removing the private package things...

const NpmPlugin = require('release-it/lib/plugin/npm/npm');

...

class npmCustom extends NpmPlugin {

...

  isAuthenticated() {
    const registry = this.getRegistry();
    const registryArg =  ` --registry ${registry}`;

    return this.exec(`npm whoami ${registryArg}`).then(
      () => true,
      err => {
        this.log.log(err);
        this.debug(err);
        if (/code E40[04]/.test(err)) {
          this.log.warn('Ignoring unsupported `npm whoami` command response.');
          return true;
        }
        return false;
      }
    );
  }

  async publish({ otp = this.options.otp, otpCallback } = {}) {

    const { publishPath = '.', access } = this.options;
    const { name, private: isPrivate, tag = DEFAULT_TAG, isNewPackage } = this.getContext();

    const otpArg = otp ? `--otp ${otp}` : '';
    const dryRunArg = this.global.isDryRun ? '--dry-run' : '';
    const registry = this.getRegistry();
    const registryArg =  `--registry ${registry}`;
    return this.exec(`npm publish ${publishPath} --tag ${tag} ${otpArg} ${dryRunArg} ${registryArg}`, { options })
      .then(() => {
        this.isReleased = true;
      })
      .catch(err => {
        this.debug(err);
        if (/one-time pass/.test(err)) {
          if (otp != null) {
            this.log.warn('The provided OTP is incorrect or has expired.');
          }
          if (otpCallback) {
            return otpCallback(otp => this.publish({ otp, otpCallback }));
          }
        }
        throw err;
      });
  }

...

}

@webpro
Copy link
Collaborator

webpro commented Mar 26, 2020

Yeah, I guess it's best to just always pass the --registry argument.

The private packages will also be fixed by #630. Watch this space :-)

@webpro
Copy link
Collaborator

webpro commented Mar 26, 2020

I added --registry to the whoami and ping commands in v13.3.2. This also includes a fix for the access logic.

@webpro webpro closed this as completed Mar 26, 2020
@webpro
Copy link
Collaborator

webpro commented Mar 26, 2020

Since it matched the default registry it never stuck it in the command so it would never pass the auth check.

Suddenly I got confused. Why didn't it pass the auth check? When either yours or npm/release-it default (without the ending /) is used, they're the same registry. Or did you mean to use the yarn package registry?

@webpro webpro reopened this Mar 26, 2020
@webpro
Copy link
Collaborator

webpro commented Mar 27, 2020

I've simplified the logic a bit in v13.4.0. Let me know if you still have issues.

@webpro webpro closed this as completed Mar 27, 2020
@jchamb
Copy link
Author

jchamb commented Mar 27, 2020

@webpro sorry for not getting back to you sooner. Honestly i'm not sure why it wouldn't pass the auth. I was originally not setting the registry at all and it would just keep saying unauthorized. When I ran the whoami myself, it would show me I was logged in. Forcing the registry seemed to fix it... I have another package hooked up just using npm and it works with zero issues so i'm assuming it was something weird with yarn

also just want to say thanks for this package, it totally rocks!

@webpro
Copy link
Collaborator

webpro commented Mar 28, 2020

Thanks! So, everything works fine for you now?

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

2 participants