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

Merged
merged 18 commits into from
Dec 15, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,62 @@
## 7.2.0 (2020-12-15)

### FEATURES

* [`a9c4b158c`](https://github.com/npm/cli/commit/a9c4b158c46dd0d0c8d8744a97750ffd0c30cc09)
[#2342](https://github.com/npm/cli/issues/2342)
allow npm rebuild to accept a path to a module
([@nlf](https://github.com/nlf))

### DEPENDENCIES

* [`beb371800`](https://github.com/npm/cli/commit/beb371800292140bf3882253c447168a378bc154)
[#2334](https://github.com/npm/cli/issues/2334)
remove unused top level dep tough-cookie
([@darcyclarke](https://github.com/darcyclarke))
* [`d45e181d1`](https://github.com/npm/cli/commit/d45e181d17dd88d82b3a97f8d9cd5fa5b6230e48)
[#2335](https://github.com/npm/cli/issues/2335)
`ini@2.0.0`, `@npmcli/config@1.2.7`
([@isaacs](https://github.com/isaacs))
* [`ef4b18b5a`](https://github.com/npm/cli/commit/ef4b18b5a70381b264d234817cff32eeb6848a73)
[#2309](https://github.com/npm/cli/issues/2309)
`@npmcli/arborist@2.0.2`
* properly remove deps when no lockfile and package.json is present
* [`c6c013e6e`](https://github.com/npm/cli/commit/c6c013e6ebc4fe036695db1fd491eb68f3b57c68)
`readdir-scoped-modules@1.1.0`
* [`a1a2134aa`](https://github.com/npm/cli/commit/a1a2134aa9a1092493db6d6c9a729ff5203f0dd4)
remove unused sorted-object dep
([@nlf](https://github.com/nlf))
* [`85c2a2d31`](https://github.com/npm/cli/commit/85c2a2d318ae066fb2c161174f5aea97e18bc9c5)
[#2344](https://github.com/npm/cli/issues/2344)
remove editor dependency
([@nlf](https://github.com/nlf))

### TESTING

* [`3a6dd511c`](https://github.com/npm/cli/commit/3a6dd511c944c5f2699825a99bba1dde333a45ef)
npm edit
([@nlf](https://github.com/nlf))
* [`3ba5de4e7`](https://github.com/npm/cli/commit/3ba5de4e7f6c5c0f995a29844926d6ed2833addd)
[#2347](https://github.com/npm/cli/issues/2347)
npm help-search
([@nlf](https://github.com/nlf))
* [`6caf19f49`](https://github.com/npm/cli/commit/6caf19f491e144be3e2a1a50f492dad48b01f361)
[#2348](https://github.com/npm/cli/issues/2348)
npm help
([@nlf](https://github.com/nlf))
* [`cb5847e32`](https://github.com/npm/cli/commit/cb5847e3203c52062485b5de68e4f6d29b33c361)
[#2349](https://github.com/npm/cli/issues/2349)
npm hook
([@nlf](https://github.com/nlf))
* [`996a2f6b1`](https://github.com/npm/cli/commit/996a2f6b130d6678998a2f6a5ec97d75534d5f66)
[#2353](https://github.com/npm/cli/issues/2353)
npm org
([@nlf](https://github.com/nlf))
* [`8c67c38a4`](https://github.com/npm/cli/commit/8c67c38a4f476ff5be938db6b6b3ee9ac6b44db5)
[#2354](https://github.com/npm/cli/issues/2354)
npm set
([@nlf](https://github.com/nlf))

## 7.1.2 (2020-12-11)

### DEPENDENCIES
Expand Down
15 changes: 10 additions & 5 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { promisify } = require('util')
const fs = require('fs')
const readFile = promisify(fs.readFile)
const writeFile = promisify(fs.writeFile)
const editor = promisify(require('editor'))
const { spawn } = require('child_process')
const { EOL } = require('os')
const ini = require('ini')

Expand Down Expand Up @@ -138,9 +138,6 @@ const del = async key => {

const edit = async () => {
const { editor: e, global } = npm.flatOptions
if (!e)
throw new Error('No `editor` config or EDITOR environment variable set')

const where = global ? 'global' : 'user'
const file = npm.config.data.get(where).source

Expand Down Expand Up @@ -183,7 +180,15 @@ ${defData}
`.split('\n').join(EOL)
await mkdirp(dirname(file))
await writeFile(file, tmpData, 'utf8')
await editor(file, { editor: e })
await new Promise((resolve, reject) => {
const [bin, ...args] = e.split(/\s+/)
const editor = spawn(bin, [...args, file], { stdio: 'inherit' })
editor.on('exit', (code) => {
if (code)
return reject(new Error(`editor process exited with code: ${code}`))
return resolve()
})
})
}

const publicVar = k => !/^(\/\/[^:]+:)?_/.test(k)
Expand Down
72 changes: 28 additions & 44 deletions lib/edit.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,36 @@
// npm edit <pkg>
// open the package folder in the $EDITOR

module.exports = edit
edit.usage = 'npm edit <pkg>[/<subpkg>...]'
const { resolve } = require('path')
const fs = require('graceful-fs')
const { spawn } = require('child_process')
const npm = require('./npm.js')
const usageUtil = require('./utils/usage.js')
const splitPackageNames = require('./utils/split-package-names.js')

edit.completion = require('./utils/completion/installed-shallow.js')

var npm = require('./npm.js')
var path = require('path')
var fs = require('graceful-fs')
var editor = require('editor')
var noProgressTillDone = require('./utils/no-progress-while-running').tillDone
const usage = usageUtil('edit', 'npm edit <pkg>[/<subpkg>...]')
const completion = require('./utils/completion/installed-shallow.js')

function edit (args, cb) {
var p = args[0]
if (args.length !== 1 || !p)
return cb(edit.usage)
var e = npm.config.get('editor')
if (!e) {
return cb(new Error(
"No editor set. Set the 'editor' config, or $EDITOR environ."
))
}
p = p.split('/')
// combine scoped parts
.reduce(function (parts, part) {
if (parts.length === 0)
return [part]

var lastPart = parts[parts.length - 1]
// check if previous part is the first part of a scoped package
if (lastPart[0] === '@' && !lastPart.includes('/'))
parts[parts.length - 1] += '/' + part
else
parts.push(part)

return parts
}, [])
.join('/node_modules/')
.replace(/(\/node_modules)+/, '/node_modules')
var f = path.resolve(npm.dir, p)
fs.lstat(f, function (er) {
if (er)
return cb(er)
editor(f, { editor: e }, noProgressTillDone(function (er) {
if (er)
return cb(er)
npm.commands.rebuild(args, cb)
}))
if (args.length !== 1)
return cb(usage)

const path = splitPackageNames(args[0])
const dir = resolve(npm.dir, path)

fs.lstat(dir, (err) => {
if (err)
return cb(err)

const [bin, ...args] = npm.config.get('editor').split(/\s+/)
const editor = spawn(bin, [...args, dir], { stdio: 'inherit' })
editor.on('exit', (code) => {
if (code)
return cb(new Error(`editor process exited with code: ${code}`))

npm.commands.rebuild([dir], cb)
})
})
}

module.exports = Object.assign(edit, { completion, usage })
27 changes: 10 additions & 17 deletions lib/help-search.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const fs = require('fs')
const path = require('path')
const npm = require('./npm.js')
const glob = require('glob')
const color = require('ansicolors')
const output = require('./utils/output.js')
const usageUtil = require('./utils/usage.js')
const { promisify } = require('util')
const glob = promisify(require('glob'))
const readFile = promisify(fs.readFile)
const didYouMean = require('./utils/did-you-mean.js')
const { cmdList } = require('./utils/cmd-list.js')
Expand All @@ -23,12 +23,17 @@ const helpSearch = async args => {

const docPath = path.resolve(__dirname, '..', 'docs/content')

// XXX: make glob return a promise and remove this wrapping
const files = await new Promise((res, rej) =>
glob(`${docPath}/*/*.md`, (er, files) => er ? rej(er) : res(files)))

const files = await glob(`${docPath}/*/*.md`)
const data = await readFiles(files)
const results = await searchFiles(args, data, files)
// if only one result, then just show that help section.
if (results.length === 1) {
return npm.commands.help([path.basename(results[0].file, '.md')], er => {
if (er)
throw er
})
}

const formatted = formatResults(args, results)
if (!formatted.trim())
npmUsage(false)
Expand Down Expand Up @@ -125,15 +130,6 @@ const searchFiles = async (args, data, files) => {
})
}

// if only one result, then just show that help section.
if (results.length === 1) {
npm.commands.help([results[0].file.replace(/\.md$/, '')], er => {
if (er)
throw er
})
return []
}

// sort results by number of results found, then by number of hits
// then by number of matching lines
return results.sort((a, b) =>
Expand All @@ -147,9 +143,6 @@ const searchFiles = async (args, data, files) => {
}

const formatResults = (args, results) => {
if (!results)
return 'No results for ' + args.map(JSON.stringify).join(' ')

const cols = Math.min(process.stdout.columns || Infinity, 80) + 1

const out = results.map(res => {
Expand Down
7 changes: 6 additions & 1 deletion lib/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ function viewMan (man, cb) {
break

case 'browser':
openUrl(htmlMan(man), 'help available at the following URL', cb)
try {
var url = htmlMan(man)
} catch (err) {
return cb(err)
}
openUrl(url, 'help available at the following URL', cb)
break

default:
Expand Down
4 changes: 2 additions & 2 deletions lib/org.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ function orgSet (org, user, role, opts) {
memDeets.org.size,
memDeets.user,
memDeets.role,
])
].join('\t'))
} else if (!opts.silent && opts.loglevel !== 'silent')
output(`Added ${memDeets.user} as ${memDeets.role} to ${memDeets.org.name}. You now ${memDeets.org.size} member${memDeets.org.size === 1 ? '' : 's'} in this org.`)
output(`Added ${memDeets.user} as ${memDeets.role} to ${memDeets.org.name}. You now have ${memDeets.org.size} member${memDeets.org.size === 1 ? '' : 's'} in this org.`)

return memDeets
})
Expand Down
13 changes: 11 additions & 2 deletions lib/rebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,25 @@ const getFilterFn = args => {
const spec = npa(arg)
if (spec.type === 'tag' && spec.rawSpec === '')
return spec
if (spec.type !== 'range' && spec.type !== 'version')

if (spec.type !== 'range' && spec.type !== 'version' && spec.type !== 'directory')
throw new Error('`npm rebuild` only supports SemVer version/range specifiers')

return spec
})

return node => specs.some(spec => {
const { version } = node.package
if (spec.type === 'directory')
return node.path === spec.fetchSpec

if (spec.name !== node.name)
return false

if (spec.rawSpec === '' || spec.rawSpec === '*')
return true

const { version } = node.package
// TODO: add tests for a package with missing version
return semver.satisfies(version, spec.fetchSpec)
})
}
Expand Down
9 changes: 0 additions & 9 deletions lib/utils/child-path.js

This file was deleted.

23 changes: 0 additions & 23 deletions lib/utils/completion/file-completion.js

This file was deleted.

14 changes: 0 additions & 14 deletions lib/utils/deep-sort-object.js

This file was deleted.

55 changes: 0 additions & 55 deletions lib/utils/git.js

This file was deleted.

Loading