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

Release/v7.10.0 #3087

Merged
merged 10 commits into from Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
33 changes: 33 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,36 @@
## v7.10.0 (2021-04-15)

### FEATURES

* [`f9b639eb6`](https://github.com/npm/cli/commit/f9b639eb6c504ded6cdd59e83e26a392bfe81e5d)
[#3052](https://github.com/npm/cli/issues/3052)
feat(bugs): fall back to email if provided
([@Yash-Singh1](https://github.com/Yash-Singh1))
* [`8c9e24778`](https://github.com/npm/cli/commit/8c9e24778db867cb3148bc247c7e321639aa9f58)
[#3055](https://github.com/npm/cli/issues/3055)
feat(version): add workspace support
([@wraithgar](https://github.com/wraithgar))

### DEPENDENCIES

* [`f1e6743a6`](https://github.com/npm/cli/commit/f1e6743a6e8e32ddad6d1964eb05d17e6c50a456)
`libnpmversion@1.2.0`
* feat(retrieve-tag): retrieve unannotated git tags
* fix(retrieve-tag): use semver to look for semver
* [`3b476a24c`](https://github.com/npm/cli/commit/3b476a24cf0b2823fdf92505b84bddde4fcc8b14)
`@npmcl/git@2.0.8`
* fix(git): do not use shell when calling git
* [`dfcd0c1e2`](https://github.com/npm/cli/commit/dfcd0c1e2331c1f4b6573466b50505772eddaf22)
[#3069](https://github.com/npm/cli/issues/3069)
`tap@15.0.2`

### DOCUMENTATION

* [`90b61eda9`](https://github.com/npm/cli/commit/90b61eda9b41af108ed69fc0c43a522a92745047)
[#3053](https://github.com/npm/cli/issues/3053)
fix(contributing.md): explicitely outline dep updates
([@darcyclarke](https://github.com/darcyclarke))

## v7.9.0 (2021-04-08)

### FEATURES
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -51,6 +51,10 @@ We've set up an automated [benchmark](https://github.com/npm/benchmarks) integra

You can learn more about this tool, including how to run & configure it manually, [here](https://github.com/npm/benchmarks)

## Dependency Updates

It should be noted that our team does not accept third-party dependency updates/PRs. We have a [release process](https://github.com/npm/cli/wiki/Release-Process) that includes checks to ensure dependencies are staying up-to-date & will ship security patches for CVEs as they occur. If you submit a PR trying to update our dependencies we will close it with or without a reference to these contribution guidelines.

## Reporting Bugs

When submitting a new bug report, please first [search](https://github.com/npm/cli/issues) for an existing or similar report & then use one of our existing [issue templates](https://github.com/npm/cli/issues/new/choose) if you believe you've come across a unique problem. Duplicate issues, or issues that don't use one of our templates may get closed without a response.
6 changes: 3 additions & 3 deletions docs/content/commands/npm-bugs.md
Expand Up @@ -15,9 +15,9 @@ aliases: issues
### Description

This command tries to guess at the likely location of a package's bug
tracker URL, and then tries to open it using the `--browser` config param.
If no package name is provided, it will search for a `package.json` in the
current folder and use the `name` property.
tracker URL or the `mailto` URL of the support email, and then tries to
open it using the `--browser` config param. If no package name is provided, it
will search for a `package.json` in the current folder and use the `name` property.

### Configuration

Expand Down
83 changes: 50 additions & 33 deletions docs/content/commands/npm-version.md
Expand Up @@ -14,6 +14,56 @@ npm version [<newversion> | major | minor | patch | premajor | preminor | prepat
'npm ls' to inspect current package/dependency versions
```

### Configuration

#### `allow-same-version`

* Default: `false`
* Type: Boolean

Prevents throwing an error when `npm version` is used to set the new version
to the same value as the current version.

#### `git-tag-version`

* Default: `true`
* Type: Boolean

Commit and tag the version change.

#### `commit-hooks`

* Default: `true`
* Type: Boolean

Run git commit hooks when committing the version change.

#### `sign-git-tag`

* Default: `false`
* Type: Boolean

Pass the `-s` flag to git to sign the tag.

Note that you must have a default GPG key set up in your git config for this to work properly.

#### workspaces

* Default: `false`
* Type: Boolean

Enables workspaces context and includes workspaces in reported output
when getting versions. When setting a new version *only the workspaces
will be changed*.

#### workspace

* Default: []
* Type: Array

Enables workspaces context and limits results to only those specified by
this config item.

### Description

Run this in a package directory to bump the version and write the new
Expand Down Expand Up @@ -87,39 +137,6 @@ This runs all your tests and proceeds only if they pass. Then runs your `build`
adds everything in the `dist` directory to the commit. After the commit, it pushes the new commit
and tag up to the server, and deletes the `build/temp` directory.

### Configuration

#### `allow-same-version`

* Default: `false`
* Type: Boolean

Prevents throwing an error when `npm version` is used to set the new version
to the same value as the current version.

#### `git-tag-version`

* Default: `true`
* Type: Boolean

Commit and tag the version change.

#### `commit-hooks`

* Default: `true`
* Type: Boolean

Run git commit hooks when committing the version change.

#### `sign-git-tag`

* Default: `false`
* Type: Boolean

Pass the `-s` flag to git to sign the tag.

Note that you must have a default GPG key set up in your git config for this to work properly.

### See Also

* [npm init](/commands/npm-init)
Expand Down
20 changes: 18 additions & 2 deletions lib/base-command.js
Expand Up @@ -4,6 +4,7 @@ const ConfigDefinitions = require('./utils/config/definitions.js')

class BaseCommand {
constructor (npm) {
this.wrapWidth = 80
this.npm = npm
}

Expand All @@ -27,15 +28,30 @@ class BaseCommand {
usage = `${usage}${this.constructor.usage.map(u => `npm ${this.constructor.name} ${u}`).join('\n')}`

if (this.constructor.params)
// TODO word wrap this along params boundaries
usage = `${usage}\n\nOptions:\n[${this.constructor.params.map(p => ConfigDefinitions[p].usage).join('] [')}]`
usage = `${usage}\n\nOptions:\n${this.wrappedParams}`

// Mostly this just appends aliases, this could be more clear
usage = usageUtil(this.constructor.name, usage)
usage = `${usage}\n\nRun "npm help ${this.constructor.name}" for more info`
return usage
}

get wrappedParams () {
let results = ''
let line = ''

for (const param of this.constructor.params) {
const usage = `[${ConfigDefinitions[param].usage}]`
if (line.length && (line.length + usage.length) > this.wrapWidth) {
results = [results, line].filter(Boolean).join('\n')
line = ''
}
line = [line, usage].filter(Boolean).join(' ')
}
results = [results, line].filter(Boolean).join('\n')
return results
}

usageError (msg) {
if (!msg) {
return Object.assign(new Error(`\nUsage: ${this.usage}`), {
Expand Down
3 changes: 3 additions & 0 deletions lib/bugs.js
Expand Up @@ -43,6 +43,9 @@ class Bugs extends BaseCommand {

if (typeof mani.bugs === 'object' && mani.bugs.url)
return mani.bugs.url

if (typeof mani.bugs === 'object' && mani.bugs.email)
return `mailto:${mani.bugs.email}`
}

// try to get it from the repo, if possible
Expand Down
1 change: 1 addition & 0 deletions lib/utils/config/definitions.js
Expand Up @@ -1389,6 +1389,7 @@ define('prefix', {

define('preid', {
default: '',
hint: 'prerelease-id',
type: String,
description: `
The "prerelease identifier" to use as a prefix for the "prerelease" part
Expand Down
78 changes: 70 additions & 8 deletions lib/version.js
@@ -1,6 +1,11 @@
const libversion = require('libnpmversion')
const libnpmversion = require('libnpmversion')
const { resolve } = require('path')
const { promisify } = require('util')
const readFile = promisify(require('fs').readFile)

const getWorkspaces = require('./workspaces/get-workspaces.js')
const BaseCommand = require('./base-command.js')

class Version extends BaseCommand {
static get description () {
return 'Bump a package version'
Expand All @@ -11,9 +16,23 @@ class Version extends BaseCommand {
return 'version'
}

/* istanbul ignore next - see test/lib/load-all-commands.js */
static get params () {
return [
'allow-same-version',
'commit-hooks',
'git-tag-version',
'json',
'preid',
'sign-git-tag',
'workspace',
'workspaces',
]
}

/* istanbul ignore next - see test/lib/load-all-commands.js */
static get usage () {
return ['[<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]']
return ['[<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease | from-git]']
}

async completion (opts) {
Expand All @@ -37,6 +56,10 @@ class Version extends BaseCommand {
return this.version(args).then(() => cb()).catch(cb)
}

execWorkspaces (args, filters, cb) {
this.versionWorkspaces(args, filters).then(() => cb()).catch(cb)
}

async version (args) {
switch (args.length) {
case 0:
Expand All @@ -48,20 +71,42 @@ class Version extends BaseCommand {
}
}

async versionWorkspaces (args, filters) {
switch (args.length) {
case 0:
return this.listWorkspaces(filters)
case 1:
return this.changeWorkspaces(args, filters)
default:
throw this.usage
}
}

async change (args) {
const prefix = this.npm.config.get('tag-version-prefix')
const version = await libversion(args[0], {
const version = await libnpmversion(args[0], {
...this.npm.flatOptions,
path: this.npm.prefix,
})
return this.npm.output(`${prefix}${version}`)
}

async list () {
const results = {}
const { promisify } = require('util')
const { resolve } = require('path')
const readFile = promisify(require('fs').readFile)
async changeWorkspaces (args, filters) {
const prefix = this.npm.config.get('tag-version-prefix')
const workspaces =
await getWorkspaces(filters, { path: this.npm.localPrefix })
for (const [name, path] of workspaces) {
this.npm.output(name)
const version = await libnpmversion(args[0], {
...this.npm.flatOptions,
'git-tag-version': false,
path,
})
this.npm.output(`${prefix}${version}`)
}
}

async list (results = {}) {
const pj = resolve(this.npm.prefix, 'package.json')

const pkg = await readFile(pj, 'utf8')
Expand All @@ -80,5 +125,22 @@ class Version extends BaseCommand {
else
this.npm.output(results)
}

async listWorkspaces (filters) {
const results = {}
const workspaces =
await getWorkspaces(filters, { path: this.npm.localPrefix })
for (const [, path] of workspaces) {
const pj = resolve(path, 'package.json')
// getWorkspaces has already parsed this so we know it won't error
const pkg = await readFile(pj, 'utf8')
.then(data => JSON.parse(data))

if (pkg.name && pkg.version)
results[pkg.name] = pkg.version
}
return this.list(results)
}
}

module.exports = Version
3 changes: 3 additions & 0 deletions lib/workspaces/get-workspaces.js
Expand Up @@ -3,7 +3,10 @@ const mapWorkspaces = require('@npmcli/map-workspaces')
const minimatch = require('minimatch')
const rpj = require('read-package-json-fast')

// Returns an Map of paths to workspaces indexed by workspace name
// { foo => '/path/to/foo' }
const getWorkspaces = async (filters, { path }) => {
// TODO we need a better error to be bubbled up here if this rpj call fails
const pkg = await rpj(resolve(path, 'package.json'))
const workspaces = await mapWorkspaces({ cwd: path, pkg })
const res = filters.length ? new Map() : workspaces
Expand Down