Skip to content

Commit

Permalink
Merge branch 'latest' into docs-using-npm-workspaces-order
Browse files Browse the repository at this point in the history
  • Loading branch information
behnammodi committed Sep 29, 2021
2 parents de78f0c + 7fe0d8b commit 08400d0
Show file tree
Hide file tree
Showing 145 changed files with 4,635 additions and 2,229 deletions.
7 changes: 7 additions & 0 deletions AUTHORS
Expand Up @@ -792,3 +792,10 @@ Demira Dimitrova <demiradimitrova@github.com>
AkiJoey <akijoey1010635951@gmail.com>
austincho <austin.cho14@gmail.com>
Nathan Fritz <fritzy@github.com>
tripu <1016538+tripu@users.noreply.github.com>
Matsuuu <huhta.matias@gmail.com>
Anders Kaseorg <andersk@mit.edu>
John Gee <john@ruru.gen.nz>
Ayush Rawal <royalrawal.2001@gmail.com>
Nate Green <heynategreen@gmail.com>
Jacob Yacovelli <jjyacovelli@gmail.com>
111 changes: 111 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,114 @@
## v7.24.0 (2021-09-16)

### FEATURES

* [`c7787b3fb`](https://github.com/npm/cli/commit/c7787b3fb7630aab84aae83ebf9a7117c7173b6b)
[`1fbbe1e04`](https://github.com/npm/cli/commit/1fbbe1e04be5d79c7b49910324e64c19ed599eeb)
bundled npm-install-checks ([@wraithgar](https://github.com/wraithgar))

### BUG FIXES

* [`0320bd77e`](https://github.com/npm/cli/commit/0320bd77e2a38f48a88e377df4b122fd21043a83)
[#3739](https://github.com/npm/cli/issues/3739)
fix(view): Show the correct publish date for versions selected by range ([@andersk](https://github.com/andersk))
* [`e4a521857`](https://github.com/npm/cli/commit/e4a5218573583149af795982a39fa64a4116cdab)
[#3748](https://github.com/npm/cli/issues/3748)
fix(install.sh): don't remove old npm first
([@wraithgar](https://github.com/wraithgar))
* [`b4aac345b`](https://github.com/npm/cli/commit/b4aac345b0a7cdec4d713c5be4daea37330b2b26)
[#3754](https://github.com/npm/cli/issues/3754)
fix(config): user-agent properly shows ci
([@wraithgar](https://github.com/wraithgar))
* [`b807cd62e`](https://github.com/npm/cli/commit/b807cd62eabe337e3243415c9870ea36d9289e12)
[#3738](https://github.com/npm/cli/issues/3738)
fix(search): return valid json for no results
([@AyushRawal](https://github.com/AyushRawal))
* [`2def17a3b`](https://github.com/npm/cli/commit/2def17a3b625b92b40c6185ff4b47e8ed006492c)
[#3760](https://github.com/npm/cli/issues/3760)
fix(install): use configured registry when checking manifest
([@yacoman89](https://github.com/yacoman89))
* [`ca792acdd`](https://github.com/npm/cli/commit/ca792acdd4ba683d8415c88188ec6739033fb4fd)
[#3761](https://github.com/npm/cli/issues/3761)
fix(logs): clean args for failed commands
([@wraithgar](https://github.com/wraithgar))

### DEPENDENCIES

* [`59743972c`](https://github.com/npm/cli/commit/59743972c2ae1d2dd601aaa6c59974c686b1cb29)
[#3747](https://github.com/npm/cli/issues/3747)
fix(did-you-mean): succeed if cwd is not a package
([@wraithgar](https://github.com/wraithgar))
* [`ac8e4ad18`](https://github.com/npm/cli/commit/ac8e4ad18a6b726dd2c3abcb0f605701cca0ae2c)
`init-package-json@2.0.5`:
* fix: bin script path
* [`371655a6b`](https://github.com/npm/cli/commit/371655a6b0e6664fec67f16cb247cc9f174a5197)
`minipass@3.1.5`:
* fix: re-emit 'error' event if missed and new listener added
* fix: do not blow up if process is missing

### DOCUMENTATION

* [`4d93b484a`](https://github.com/npm/cli/commit/4d93b484abb50e3704fb436db572b93fb36c7ac3)
[#3759](https://github.com/npm/cli/issues/3759)
fix(docs): use correct hyperlink to package-json
([@nategreen](https://github.com/nategreen))

## v7.23.0 (2021-09-09)

### FEATURES

* [`6c12500ae`](https://github.com/npm/cli/commit/6c12500ae14a6f8b78e3ab091ee6cc8e2ea9fd23)
[#3731](https://github.com/npm/cli/issues/3731)
feat(install): very strict global npm engines
([@wraithgar](https://github.com/wraithgar))

### BUG FIXES

* [`1ad093824`](https://github.com/npm/cli/commit/1ad0938243110d983284e8763da41a57b561563d)
[#3732](https://github.com/npm/cli/issues/3732)
fix(error-message): clean urls from 404 error
([@wraithgar](https://github.com/wraithgar))

### DOCUMENTATION

* [`64f7d1a55`](https://github.com/npm/cli/commit/64f7d1a55db99b1aaf8fb59557b3dedcdcd954a0)
[#3727](https://github.com/npm/cli/issues/3727)
docs(contributing): add note on changes to tooling
([@darcyclarke](https://github.com/darcyclarke))
* [`eda9162f2`](https://github.com/npm/cli/commit/eda9162f2db19b512d3af6b0d43201d54045c13a)
[#3715](https://github.com/npm/cli/issues/3715)
Add --if-present flag documentation to workspaces
([@Matsuuu](https://github.com/Matsuuu))

## v7.22.0 (2021-09-02)

### BUG FIXES
* [`6f431fe23`](https://github.com/npm/cli/commit/6f431fe2325f77b4370f95848359a36fe7a011d1)
[#3690](https://github.com/npm/cli/issues/3690)
Fix one “see also” link
([@tripu](https://github.com/tripu))

### DEPENDENCIES
* [`033e948c9`](https://github.com/npm/cli/commit/033e948c95b3455812e03a860ad1bd96a635e7eb)
`read-package-json@4.1.1`:
* feat: add types lookup
* fix(man): don't lose relative man path
* [`1fa549db0`](https://github.com/npm/cli/commit/1fa549db0955b55fd680a658809a6d97be306b06)
`@npmcli/config@2.3.0`:
* feat: export npm_config_local_prefix and npm_config_global_prefix to the environment
* [`e91578d10`](https://github.com/npm/cli/commit/e91578d10b1d5d930fec32e7070d975af4892140)
`minpass-fetch@1.4.1`:
* Made rejectUnauthorized depend on NODE_TLS_REJECT_UNAUTHORIZED
* [`6125db545`](https://github.com/npm/cli/commit/6125db545315da0217fe7b05062fd0a504c9a45b)
`are-we-there-yet@1.1.6`
* [`0dcda73b0`](https://github.com/npm/cli/commit/0dcda73b022083338c4cb755390a275757b9627b)
`string_decoder@1.3.0`
* [`4b913417c`](https://github.com/npm/cli/commit/4b913417c4e30980505a02eec50810f895dd52d7)
`npmlog@5.0.1`
* [`876c755eb`](https://github.com/npm/cli/commit/876c755eb0dfc215123682f798b5fca415f7c7d9)
`@npmcli/arborist@2.8.3`:
* fix: do not fail adding unresolvable optional dep

## v7.21.1 (2021-08-26)

### BUG FIXES
Expand Down
14 changes: 10 additions & 4 deletions CONTRIBUTING.md
Expand Up @@ -4,6 +4,10 @@

All interactions in the **npm** organization on GitHub are considered to be covered by our standard [Code of Conduct](https://docs.npmjs.com/policies/conduct).

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

## Development

**1. Clone this repository...**
Expand Down Expand Up @@ -33,7 +37,7 @@ $ npm run test

## Test Coverage

We expect that every new feature or bug fix comes with corresponding tests that validate the solutions. We strive to have as close to, if not exactly, 100% code coverage.
We use [`tap`](https://node-tap.org/) for testing & expect that every new feature or bug fix comes with corresponding tests that validate the solutions. We strive to have as close to, if not exactly, 100% code coverage.

**You can find out what the current test coverage percentage is by running...**

Expand All @@ -51,10 +55,12 @@ 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
## What _not_ to contribute?

### Dependencies

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
### Tools/Automation

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.
Our core team is responsible for the maintenance of the tooling/automation in this project & we ask collaborators to kindly not make changes to these when contributing (ex. `.github/*`, `.eslintrc.json`, `.licensee.json` etc.)
2 changes: 1 addition & 1 deletion docs/content/commands/npm-deprecate.md
Expand Up @@ -76,4 +76,4 @@ password, npm will prompt on the command line for one.
* [npm publish](/commands/npm-publish)
* [npm registry](/using-npm/registry)
* [npm owner](/commands/npm-owner)
* [npm owner](/commands/npm-adduser)
* [npm adduser](/commands/npm-adduser)
2 changes: 1 addition & 1 deletion docs/content/using-npm/scripts.md
Expand Up @@ -259,7 +259,7 @@ package.json file, then your package scripts would have the
in your code with `process.env.npm_package_name` and
`process.env.npm_package_version`, and so on for other fields.

See [`package-json.md`](/using-npm/package-json) for more on package configs.
See [`package-json.md`](/configuring-npm/package-json) for more on package configs.

#### current lifecycle event

Expand Down
12 changes: 11 additions & 1 deletion docs/content/using-npm/workspaces.md
Expand Up @@ -176,7 +176,7 @@ npm run test --workspaces

Will run the `test` script in both `./packages/a` and `./packages/b`.

commands will be run in each workspace in the order they appear in your `package.json`
Commands will be run in each workspace in the order they appear in your `package.json`

```
{
Expand All @@ -190,6 +190,16 @@ Order of run is different with:
{
"workspaces": [ "packages/b", "packages/a" ]
}
### Ignoring missing scripts
It is not required for all of the workspaces to implement scripts run with the `npm run` command.
By running the command with the `--if-present` flag, npm will ignore workspaces missing target script.
```
npm run test --workspaces --if-present
```
### See also
Expand Down
23 changes: 21 additions & 2 deletions lib/install.js
Expand Up @@ -8,6 +8,8 @@ const log = require('npmlog')
const { resolve, join } = require('path')
const Arborist = require('@npmcli/arborist')
const runScript = require('@npmcli/run-script')
const pacote = require('pacote')
const checks = require('npm-install-checks')

const ArboristWorkspaceCmd = require('./workspaces/arborist-cmd.js')
class Install extends ArboristWorkspaceCmd {
Expand Down Expand Up @@ -126,6 +128,24 @@ class Install extends ArboristWorkspaceCmd {
const ignoreScripts = this.npm.config.get('ignore-scripts')
const isGlobalInstall = this.npm.config.get('global')
const where = isGlobalInstall ? globalTop : this.npm.prefix
const forced = this.npm.config.get('force')
const isDev = this.npm.config.get('dev')
const scriptShell = this.npm.config.get('script-shell') || undefined

// be very strict about engines when trying to update npm itself
const npmInstall = args.find(arg => arg.startsWith('npm@') || arg === 'npm')
if (isGlobalInstall && npmInstall) {
const npmOptions = this.npm.flatOptions
const npmManifest = await pacote.manifest(npmInstall, npmOptions)
try {
checks.checkEngine(npmManifest, npmManifest.version, process.version)
} catch (e) {
if (forced)
this.npm.log.warn('install', `Forcing global npm install with incompatible version ${npmManifest.version} into node ${process.version}`)
else
throw e
}
}

// don't try to install the prefix into itself
args = args.filter(a => resolve(a) !== this.npm.prefix)
Expand All @@ -135,7 +155,7 @@ class Install extends ArboristWorkspaceCmd {
args = ['.']

// TODO: Add warnings for other deprecated flags? or remove this one?
if (this.npm.config.get('dev'))
if (isDev)
log.warn('install', 'Usage of the `--dev` option is deprecated. Use `--include=dev` instead.')

const opts = {
Expand All @@ -150,7 +170,6 @@ class Install extends ArboristWorkspaceCmd {
await arb.reify(opts)

if (!args.length && !isGlobalInstall && !ignoreScripts) {
const scriptShell = this.npm.config.get('script-shell') || undefined
const scripts = [
'preinstall',
'install',
Expand Down
2 changes: 1 addition & 1 deletion lib/search/format-package-stream.js
Expand Up @@ -42,7 +42,7 @@ class JSONOutputStream extends Minipass {
}

end () {
super.write(this._didFirst ? ']\n' : '\n]\n')
super.write(this._didFirst ? ']\n' : '\n[]\n')
super.end()
}
}
Expand Down
12 changes: 11 additions & 1 deletion lib/utils/config/definitions.js
Expand Up @@ -2053,10 +2053,14 @@ define('user-agent', {
.replace(/\{workspaces\}/gi, inWorkspaces)
.replace(/\{ci\}/gi, ciName ? `ci/${ciName}` : '')
.trim()

// We can't clobber the original or else subsequent flattening will fail
// (i.e. when we change the underlying config values)
// obj[key] = flatOptions.userAgent

// user-agent is a unique kind of config item that gets set from a template
// and ends up translated. Because of this, the normal "should we set this
// to process.env also doesn't work
obj[key] = flatOptions.userAgent
process.env.npm_config_user_agent = flatOptions.userAgent
},
})
Expand Down Expand Up @@ -2140,6 +2144,9 @@ define('workspace', {
a workspace which does not yet exist, to create the folder and set it
up as a brand new workspace within the project.
`,
flatten: (key, obj, flatOptions) => {
definitions['user-agent'].flatten('user-agent', obj, flatOptions)
},
})

define('workspaces', {
Expand All @@ -2151,6 +2158,9 @@ define('workspaces', {
Enable running a command in the context of **all** the configured
workspaces.
`,
flatten: (key, obj, flatOptions) => {
definitions['user-agent'].flatten('user-agent', obj, flatOptions)
},
})

define('yes', {
Expand Down
29 changes: 15 additions & 14 deletions lib/utils/did-you-mean.js
Expand Up @@ -3,25 +3,26 @@ const readJson = require('read-package-json-fast')
const { cmdList } = require('./cmd-list.js')

const didYouMean = async (npm, path, scmd) => {
const bestCmd = cmdList
let best = cmdList
.filter(cmd => distance(scmd, cmd) < scmd.length * 0.4 && scmd !== cmd)
.map(str => ` npm ${str} # ${npm.commands[str].description}`)

const pkg = await readJson(`${path}/package.json`)
const { scripts } = pkg
// We would already be suggesting this in `npm x` so omit them here
const runScripts = ['stop', 'start', 'test', 'restart']
const bestRun = Object.keys(scripts || {})
.filter(cmd => distance(scmd, cmd) < scmd.length * 0.4 &&
!runScripts.includes(cmd))
.map(str => ` npm run ${str} # run the "${str}" package script`)

const { bin } = pkg
const bestBin = Object.keys(bin || {})
.filter(cmd => distance(scmd, cmd) < scmd.length * 0.4)
.map(str => ` npm exec ${str} # run the "${str}" command from either this or a remote npm package`)

const best = [...bestCmd, ...bestRun, ...bestBin]
try {
const { bin, scripts } = await readJson(`${path}/package.json`)
best = best.concat(
Object.keys(scripts || {})
.filter(cmd => distance(scmd, cmd) < scmd.length * 0.4 &&
!runScripts.includes(cmd))
.map(str => ` npm run ${str} # run the "${str}" package script`),
Object.keys(bin || {})
.filter(cmd => distance(scmd, cmd) < scmd.length * 0.4)
.map(str => ` npm exec ${str} # run the "${str}" command from either this or a remote npm package`)
)
} catch (_) {
// gracefully ignore not being in a folder w/ a package.json
}

if (best.length === 0)
return ''
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/error-message.js
Expand Up @@ -181,7 +181,7 @@ module.exports = (er, npm) => {
const pkg = er.pkgid.replace(/(?!^)@.*$/, '')

detail.push(['404', ''])
detail.push(['404', '', "'" + er.pkgid + "' is not in the npm registry."])
detail.push(['404', '', `'${replaceInfo(er.pkgid)}' is not in this registry.`])

const valResult = nameValidator(pkg)

Expand Down Expand Up @@ -367,7 +367,7 @@ module.exports = (er, npm) => {
detail.push(['signal', er.signal])

if (er.cmd && Array.isArray(er.args))
detail.push(['command', ...[er.cmd, ...er.args]])
detail.push(['command', ...[er.cmd, ...er.args.map(replaceInfo)]])

if (er.stdout)
detail.push(['', er.stdout.trim()])
Expand Down
2 changes: 1 addition & 1 deletion lib/view.js
Expand Up @@ -336,7 +336,7 @@ class View extends BaseCommand {
email: color.cyan(manifest._npmUser.email),
}),
modified: !packument.time ? undefined
: color.yellow(relativeDate(packument.time[packument.version])),
: color.yellow(relativeDate(packument.time[manifest.version])),
maintainers: (packument.maintainers || []).map((u) => unparsePerson({
name: color.yellow(u.name),
email: color.cyan(u.email),
Expand Down
6 changes: 4 additions & 2 deletions node_modules/@npmcli/arborist/bin/actual.js

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

0 comments on commit 08400d0

Please sign in to comment.