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

Lerna publish doesn't warn that no token is set #1347

Closed
edmorley opened this issue Mar 23, 2018 · 5 comments
Closed

Lerna publish doesn't warn that no token is set #1347

edmorley opened this issue Mar 23, 2018 · 5 comments

Comments

@edmorley
Copy link

Expected Behavior

If publish is going to fail since no token set, then abort early to prevent the repository being left in a half-published state.

Current Behavior

If no token set, publish proceeds regardless, resulting in:

? Are you sure you want to publish the above changes? Yes
lerna info publish Publishing packages to npm...
lerna ERR! publish Retrying failed publish: @neutrinojs/chunk
lerna ERR! publish Retrying failed publish: @neutrinojs/babel-minify
lerna ERR! publish Retrying failed publish: @neutrinojs/clean
lerna ERR! publish Retrying failed publish: @neutrinojs/banner
lerna ERR! publish Retrying failed publish: @neutrinojs/banner
lerna ERR! publish Retrying failed publish: @neutrinojs/chunk
lerna ERR! publish Retrying failed publish: @neutrinojs/clean
lerna ERR! publish Retrying failed publish: @neutrinojs/babel-minify
lerna ERR! publish Retrying failed publish: @neutrinojs/banner
lerna ERR! publish Retrying failed publish: @neutrinojs/chunk
lerna ERR! publish Retrying failed publish: @neutrinojs/babel-minify
lerna ERR! publish Retrying failed publish: @neutrinojs/clean
lerna ERR! publish Retrying failed publish: @neutrinojs/banner
lerna ERR! publish Retrying failed publish: @neutrinojs/chunk
lerna ERR! publish Retrying failed publish: @neutrinojs/clean
lerna ERR! publish Retrying failed publish: @neutrinojs/babel-minify
lerna ERR! publish Ran out of retries while publishing @neutrinojs/banner Error: Command failed: yarn publish --tag latest --new-version 8.2.0
lerna ERR! publish error An unexpected error occurred: "No token found and can't prompt for login when running with --non-interactive.".
lerna ERR! publish [1/4] Bumping version...
lerna ERR! publish info Current version: 8.2.0
lerna ERR! publish [2/4] Logging in...
lerna ERR! publish info If you think this is a bug, please open a bug report with the information provided in "C:\\Users\\Ed\\src\
lerna ERR! publish eutrino-dev\\packages\\banner\\yarn-error.log".
lerna ERR! publish info Visit https://yarnpkg.com/en/docs/cli/publish for documentation about this command.
lerna ERR! publish
lerna ERR! publish     at Promise.all.then.arr (C:\Users\Ed\src\neutrino-dev\node_modules\lerna\node_modules\execa\index.js:236:11)
lerna ERR! publish     at <anonymous>
lerna ERR! publish     at process._tickCallback (internal/process/next_tick.js:118:7)
lerna ERR! execute callback with error
lerna ERR! Error: Command failed: yarn publish --tag latest --new-version 8.2.0
...

Possible Solution

If npm publishing is enabled (ie the user hasn't passed --skip-npm to lerna publish), then check to see whether a token is set, and if not, abort the publish before doing anything.

Steps to Reproduce (for bugs)

  1. Clear authentication tokens set in .npmrc / .yarnrc
  2. Run lerna publish in a repo that uses lerna
lerna.json

{
  "lerna": "2.4.0",
  "packages": [
    "packages/*"
  ],
  "version": "8.2.0",
  "gitRemote": "upstream",
  "npmClient": "yarn",
  "registry": "https://registry.npmjs.org/",
  "useWorkspaces": true
}

Context

I thought lerna publish would prompt me for a token, avoiding the need to save it to disk. However it doesn't, and left my local state half-published, meaning I'm not sure how to retry the publish without manually unpicking the changes.

Your Environment

Executable Version
lerna --version 2.9.0
npm --version 5.6.0
yarn --version 1.5.1
node --version 9.7.1
OS Version
NAME VERSION
Windows 10 1709
@evocateur
Copy link
Member

It's not lerna's responsibility to set a token, or even be aware of what that token is/where it is located. I agree we should probably run npm whoami (yarn equivalent ???) at the beginning of publish just so the inevitable error can be helpful/informative instead of damaging.

@edmorley
Copy link
Author

edmorley commented Apr 3, 2018

Hi! Yeah I agree it's not lerna's responsibility to handle setting the token; this issue was just about failing early to limit the damage it causes. I can't seem to find a yarn equivalent to npm whoami - perhaps lerna can just use npm whoami regardless of the value of npmClient?

@evocateur
Copy link
Member

I have a hunch yarn has different opinions about how to resolve registry authentication. No actual proof, just bitter experience of several yarn-related lerna bugs due to inconsistent implementation of registry patterns.

@b4lk0n
Copy link

b4lk0n commented May 22, 2018

Faced a similar issue. Publishing anonymously to private registry (proget). When yarn publish works as expected, but lerna publish fails with "No token found and can't prompt for login when running with --non-interactive." error

@lock
Copy link

lock bot commented Dec 27, 2018

This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants