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.9.0 #3051

Merged
merged 5 commits into from Apr 8, 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
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions CHANGELOG.md
@@ -1,4 +1,23 @@
## v7.9.0 (2021-04-08)

### FEATURES

* [`1f3e88eba`](https://github.com/npm/cli/commit/1f3e88ebaf4901d8f9f07b43404d824fef7e5ff5)
[#3032](https://github.com/npm/cli/issues/3032)
feat(dist-tag): add workspace support
([@nlf](https://github.com/nlf))
* [`6e31df4e7`](https://github.com/npm/cli/commit/6e31df4e7957337962fd3d93e495931e3592bb9e)
[#3033](https://github.com/npm/cli/issues/3033)
feat(pack): add workspace support
([@wraithgar](https://github.com/wraithgar))

### DEPENDENCIES

* [`ba4f7fea8`](https://github.com/npm/cli/commit/ba4f7fea8fca8e3509469a218f094fe69095888b)
`licensee@8.2.0`

## v7.8.0 (2021-04-01)

### FEATURES


Expand Down
12 changes: 12 additions & 0 deletions docs/content/commands/npm-dist-tag.md
Expand Up @@ -88,6 +88,18 @@ semver as `>=1.4.0 <1.5.0`. See <https://github.com/npm/npm/issues/6082>.
The simplest way to avoid semver problems with tags is to use tags that do
not begin with a number or the letter `v`.

### Configuration

#### workspaces

Only supported by `ls`. Enables listing dist-tags of all workspace
contexts defined in the current `package.json`.

#### workspace

Only supported by `ls`. Enables listing dist-tags of workspace contexts
limiting results to only those specified by this config item.

### See Also

* [npm publish](/commands/npm-publish)
Expand Down
23 changes: 19 additions & 4 deletions docs/content/commands/npm-pack.md
Expand Up @@ -10,6 +10,25 @@ description: Create a tarball from a package
npm pack [[<@scope>/]<pkg>...] [--dry-run]
```

### Configuration

#### dry-run

Do everything that pack usually does without actually packing anything.
That is, report on what would have gone into the tarball, but nothing
else.

#### workspaces

Enables workspaces context while creating tarballs. Tarballs for each
workspaces will be generated.

#### workspace

Enables workspaces context and limits results to only those specified by
this config item. Tarballs will only be generated for the packages
named in the workspaces given here.

### Description

For anything that's installable (that is, a package folder, tarball,
Expand All @@ -23,10 +42,6 @@ overwritten the second time.

If no arguments are supplied, then npm packs the current package folder.

The `--dry-run` argument will do everything that pack usually does without
actually packing anything. That is, it reports on what would have gone
into the tarball, but nothing else.

### See Also

* [npm-packlist package](http://npm.im/npm-packlist)
Expand Down
56 changes: 52 additions & 4 deletions lib/dist-tag.js
Expand Up @@ -5,13 +5,19 @@ const semver = require('semver')

const otplease = require('./utils/otplease.js')
const readLocalPkgName = require('./utils/read-local-package.js')
const getWorkspaces = require('./workspaces/get-workspaces.js')
const BaseCommand = require('./base-command.js')

class DistTag extends BaseCommand {
static get description () {
return 'Modify package distribution tags'
}

/* istanbul ignore next - see test/lib/load-all-commands.js */
static get params () {
return ['workspace', 'workspaces']
}

/* istanbul ignore next - see test/lib/load-all-commands.js */
static get name () {
return 'dist-tag'
Expand Down Expand Up @@ -43,15 +49,14 @@ class DistTag extends BaseCommand {

async distTag ([cmdName, pkg, tag]) {
const opts = this.npm.flatOptions
const has = (items) => new Set(items).has(cmdName)

if (has(['add', 'a', 'set', 's']))
if (['add', 'a', 'set', 's'].includes(cmdName))
return this.add(pkg, tag, opts)

if (has(['rm', 'r', 'del', 'd', 'remove']))
if (['rm', 'r', 'del', 'd', 'remove'].includes(cmdName))
return this.remove(pkg, tag, opts)

if (has(['ls', 'l', 'sl', 'list']))
if (['ls', 'l', 'sl', 'list'].includes(cmdName))
return this.list(pkg, opts)

if (!pkg) {
Expand All @@ -62,6 +67,33 @@ class DistTag extends BaseCommand {
throw this.usage
}

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

async distTagWorkspaces ([cmdName, pkg, tag], filters) {
// cmdName is some form of list
// pkg is one of:
// - unset
// - .
// - .@version
if (['ls', 'l', 'sl', 'list'].includes(cmdName) && (!pkg || pkg === '.' || /^\.@/.test(pkg)))
return this.listWorkspaces(filters)

// pkg is unset
// cmdName is one of:
// - unset
// - .
// - .@version
if (!pkg && (!cmdName || cmdName === '.' || /^\.@/.test(cmdName)))
return this.listWorkspaces(filters)

// anything else is just a regular dist-tag command
// so we fallback to the non-workspaces implementation
log.warn('Ignoring workspaces for specified package')
return this.distTag([cmdName, pkg, tag])
}

async add (spec, tag, opts) {
spec = npa(spec || '')
const version = spec.rawSpec
Expand Down Expand Up @@ -145,6 +177,22 @@ class DistTag extends BaseCommand {
}
}

async listWorkspaces (filters) {
const workspaces =
await getWorkspaces(filters, { path: this.npm.localPrefix })

for (const [name] of workspaces) {
try {
this.npm.output(`${name}:`)
await this.list(npa(name), this.npm.flatOptions)
} catch (err) {
// set the exitCode directly, but ignore the error
// since it will have already been logged by this.list()
process.exitCode = 1
}
}
}

async fetchTags (spec, opts) {
const data = await regFetch.json(
`/-/package/${spec.escapedName}/dist-tags`,
Expand Down
23 changes: 22 additions & 1 deletion lib/pack.js
Expand Up @@ -3,6 +3,7 @@ const log = require('npmlog')
const pacote = require('pacote')
const libpack = require('libnpmpack')
const npa = require('npm-package-arg')
const getWorkspaces = require('./workspaces/get-workspaces.js')

const { getContents, logTar } = require('./utils/tar.js')

Expand All @@ -23,7 +24,7 @@ class Pack extends BaseCommand {

/* istanbul ignore next - see test/lib/load-all-commands.js */
static get params () {
return ['dry-run']
return ['dry-run', 'workspace', 'workspaces']
}

/* istanbul ignore next - see test/lib/load-all-commands.js */
Expand All @@ -35,6 +36,10 @@ class Pack extends BaseCommand {
this.pack(args).then(() => cb()).catch(cb)
}

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

async pack (args) {
if (args.length === 0)
args = ['.']
Expand Down Expand Up @@ -62,5 +67,21 @@ class Pack extends BaseCommand {
this.npm.output(tar.filename.replace(/^@/, '').replace(/\//, '-'))
}
}

async packWorkspaces (args, filters) {
// If they either ask for nothing, or explicitly include '.' in the args,
// we effectively translate that into each workspace requested

const useWorkspaces = args.length === 0 || args.includes('.')

if (!useWorkspaces) {
this.npm.log.warn('Ignoring workspaces for specified package(s)')
return this.pack(args)
}

const workspaces =
await getWorkspaces(filters, { path: this.npm.localPrefix })
return this.pack([...workspaces.values(), ...args.filter(a => a !== '.')])
}
}
module.exports = Pack
2 changes: 1 addition & 1 deletion lib/view.js
Expand Up @@ -151,7 +151,7 @@ class View extends BaseCommand {

const local = /^\.@/.test(pkg) || pkg === '.'
if (!local) {
this.npm.log.warn('Ignoring workspaces for remote package')
this.npm.log.warn('Ignoring workspaces for specified package(s)')
return this.view([pkg, ...args])
}
let wholePackument = false
Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,5 +1,5 @@
{
"version": "7.8.0",
"version": "7.9.0",
"name": "npm",
"description": "a package manager for JavaScript",
"keywords": [
Expand Down