rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

[RRFC] `workspace-tag-version-prefix` config

Open ljharb opened this issue 2 years ago • 9 comments

Motivation ("The Why")

See https://github.com/npm/cli/issues/4017#issuecomment-1101481619 - npm version should be able to work inside workspaces.

Example

See the OP in https://github.com/npm/cli/issues/4017.

I think adding an npm config of workspace-tag-version-prefix, which defaults to [$workspaceName] - which would result in a tag of [foo] v1.2.3, for example - should address the need.

ljharb avatar Apr 18 '22 17:04 ljharb

Would npm version patch --ws result in multiple commits or a single commit with multiple tags?

ben-page avatar Apr 25 '22 17:04 ben-page

I'd expect a single commit with multiple tags.

ljharb avatar Apr 27 '22 18:04 ljharb

in case we use a template system, it should probably also contain a value for version

e.g: [$workspaceName] v$workspaceVersion in your original example @ljharb

ruyadorno avatar Apr 27 '22 18:04 ruyadorno

this is a prefix so it's assumed version is the end so [$workspaceName] v

wraithgar avatar Apr 27 '22 18:04 wraithgar

good point @wraithgar I believe you're right, in case it's a prefix, it should just end at the v

ruyadorno avatar Apr 27 '22 18:04 ruyadorno

npm version patch --ws result in multiple commits or a single commit with multiple tags?

Multiple commits

wraithgar avatar Apr 27 '22 18:04 wraithgar

I'd expect a single commit with multiple tags.

I would like to see that as a default behavior which can be overwritten with a specific flag (like git-single-tag or something along the line).

Possible usecase:

In case of our company project we have a monorepo which deploys an API and releases a npm package (for connecting to this api and several more) at the same time, because they will be no cases where only one of both should be updated - we bundle it in one pipeline with tests and everything related triggered by tags. Having multiple pipelines (because multiple tags will be generated) would result in longer pipelines due to dependecy testing.

Kagu-chan avatar May 03 '22 12:05 Kagu-chan

in case additional prior art is useful, semantic-release-monorepo uses a pattern of <package-name>-<version> by default, but enables adjusting the format.

example: @scope/package-name-v9.25.0

travi avatar May 03 '22 16:05 travi

I would like to suggest the tried-and-true package-spec format (i.e., $workspaceName@ in the context of this issue) for the following reasons (non-exhaustive):

  • The format is already used in parts of npm.

  • There are monorepos already using the format (e.g., EthereumJS, Gatsby, React Router).

  • The tag is much easier to parse for workspace name & semantic version than with $workspaceName- or [$workspaceName] v.

    Example using Posix parameter expansion:

    $ tag="@example/[email protected]+exp.sha.5114f85"
    $ echo "Workspace name is '${tag%@*}'" 
    Workspace name is '@example/package'
    $ echo "Workspace version is '${tag##*@}'"
    Workspace version is '1.0.0-beta+exp.sha.5114f85'
    

Also, this may be out of scope (slightly within scope, since $workspaceName suggests a formatting system), but I would also suggest:

  • Using an OS-agnostic approach to the variables used in the format string, such as {workspaceName}.
  • Using env variables already provided, such as npm_old_version and npm_new_version (workspace name will need to be newly provided).
  • Opting out of prefixes and into a new config convention for greater flexibility. workspace-tag-version-prefix would be workspace-tag-version-format, and tag-version-prefix would be tag-version-format.
    • For backwards-compatibility, defaults could either be unset (preferring tag-version-prefix) or set to something like {npm_tag_version_prefix}{npm_new_version}, where npm_tag_version_prefix may be some new environment set.

None of my suggestions have to be taken in the final form, but I thought I would just brain dump my ideas here to see if anything sticks 😊

jameschensmith avatar Dec 17 '22 16:12 jameschensmith