Np: Not possible to specify a custom version via the interactive UI

Created on 15 May 2020  ยท  1Comment  ยท  Source: sindresorhus/np

Description

Hi ๐Ÿ‘‹

First off: thanks a ton for your work on this really awesome tool ๐Ÿฆ„ ๐Ÿ’œ.

Problem

I'm currently running into a problem when trying to a problem when trying to specify a custom version _(like v1.0.0.beta)_ via the interactive UI: Selecting Other (specify) does not show the successive prompt to input the version number string. The release process then fails with an error, since the version number is blank.

The explicit error varies for npm and yarn, but the core problem is the same: they are missing the version number to update to. Here two examples of the error messages:

yarn


click here to expand example

โœ– Command failed with exit code 1: yarn version --new-version
error Invalid version supplied.
info Current version: 3.0.0
info Visit https://yarnpkg.com/en/docs/cli/version for documentation about this command.
error Command failed with exit code 1.

npm


click here to expand example

โœ– Command failed with exit code 1: npm version
npm ERR! npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]
npm ERR! (run in package dir)
npm ERR! 'npm -v' or 'npm --version' to print npm version (6.13.7)
npm ERR! 'npm view <pkg> version' to view a package's published version
npm ERR! 'npm ls' to inspect current package/dependency versions
error Command failed with exit code 1.

Cause

The interactive UI skips showing the next input even though the version is not specified yet and instead continues with the next step.

The next step fails due to the version still being blank, which according to this line would normally have been the condition to actually show the prompt for inputting a custom version ๐Ÿค”.

Scenarios

I run into this scenario regardless of using npm or yarn, zsh or bash and regardless of "how" I execute np:

  1. in a release script command defned in my package.json
  2. directly calling yarn np or node_modules/.bin/np
  3. from a shell script

The behavior is the same for versions v6.2.3, v6.0.0 and v5.1.1 _(I did not try other versions as I felt the problem is probably somewhere on my side)_.

Question

Am I using the tool wrong? I need to produce versions with names like e.g. v3.2.0beta and would ideally want to do this via the interactive UI ๐Ÿค”.

Steps to reproduce

Here are the steps for a minimal example to reproduce this problem _(also available as gist)_:

Option 1: Steps as a script:


click here for script ๐Ÿ‘ฉโ€๐Ÿ’ป

#!/bin/sh

set -o errexit
set -o nounset

# Create directory
mkdir example && cd example

# Initialize Git repository
git init && git commit --allow-empty -m "init commit"

# Create bare bones `yarn` project with `np`
yarn init -y && yarn add -D np

# Commit everything (for simplicity)
git add --all && git commit -m "all"

# Run `np` and select `Other (specify)` for the version
yarn np --any-branch --no-tests --no-cleanup --no-release-draft --no-publish

Option 2: Steps as a individual steps:


Click here for steps ๐Ÿ‘จโ€๐Ÿ’ป

  1. Create directory:

    mkdir try && cd try
    
  2. Initialize Git repository:

    git init && git commit --allow-empty -m "init commit"
    
  3. Create bare bones yarn project:

    ```shell
    yarn init -y
    ````

  4. Install np:

    yarn add -D np
    
  5. Commit everything (for simplicity):

    ```shell
    git add --all && git commit -m "all"
    ````

  6. Run np and select Other (specify) for the version:

    yarn np --any-branch --no-tests --no-cleanup --no-release-draft --no-publish
    

The output of the failing command looks approximately like this:


click here for output

? Select semver increment or specify new version Other (specify)

  โœ” Git
  โœ– Bumping version using Yarn
    โ†’ info Visit https://yarnpkg.com/en/docs/cli/version for documentation about this command.
    Pushing tags

โœ– Command failed with exit code 1: yarn version --new-version
error Invalid version supplied.
info Current version: 1.0.0
info Visit https://yarnpkg.com/en/docs/cli/version for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Expected behavior

The behavior I would expect from reading the code in ui.js would be to show a second input to type in the custom version number after selecting Other (specify) in the interactive UI.

Environment

np - 6.2.3
Node.js - 14.2.0
npm - 6.14.4
Git - 2.26.2
OS - macOS 10.15.4

bug

Most helpful comment

Ah, this was a particularly tricky issue.

The issue is reproducible everywhere we run with np but since the inquirer code looked good, it was difficult to understand what was causing the said issue.

Ended up creating demo projects and trying different combinations of inquirer prompts to see what was going on.

Turns out that the issue was caused just above this line because of us using the same name field for multiple prompts. We had version repeating twice, and tag repeating twice in the name field for prompts which unfortunately meant that inquirer skipped over the second of these names.

Fix was simple enough, use different names and finally map everything to the same name which we could then use throughout our whole program.

Should be fixed with #546

>All comments

Ah, this was a particularly tricky issue.

The issue is reproducible everywhere we run with np but since the inquirer code looked good, it was difficult to understand what was causing the said issue.

Ended up creating demo projects and trying different combinations of inquirer prompts to see what was going on.

Turns out that the issue was caused just above this line because of us using the same name field for multiple prompts. We had version repeating twice, and tag repeating twice in the name field for prompts which unfortunately meant that inquirer skipped over the second of these names.

Fix was simple enough, use different names and finally map everything to the same name which we could then use throughout our whole program.

Should be fixed with #546

Was this page helpful?
0 / 5 - 0 ratings

Related issues

natesilva picture natesilva  ยท  5Comments

mikehardy picture mikehardy  ยท  6Comments

fregante picture fregante  ยท  5Comments

ProfessorManhattan picture ProfessorManhattan  ยท  4Comments

janpio picture janpio  ยท  6Comments