From 2e9280072f9852466fa0944d3a0fdb0c8af156a9 Mon Sep 17 00:00:00 2001 From: Gar Date: Thu, 8 Sep 2022 09:50:33 -0700 Subject: [PATCH] feat: remove `npm bin` (#5459) BREAKING CHANGE: this removes the `npm bin` command The output of this command is misleading and incomplete. The `.bin` resolution of npm is much more nuanced than this command implies, and the output of `npm bin` is not something end users should be dealing with. `npm` itself is responsible for running the `bin` entries of modules, with the exception of global bins, which end up in the same folder as `node` itself, presumably already in a user's path since they can run node. Closes https://github.com/npm/statusboard/issues/537 --- lib/commands/bin.js | 23 ------------- lib/utils/cmd-list.js | 1 - .../tap-snapshots/test/index.js.test.cjs | 2 +- .../test/lib/commands/completion.js.test.cjs | 1 - .../test/lib/load-all-commands.js.test.cjs | 12 ------- tap-snapshots/test/lib/npm.js.test.cjs | 18 +++-------- .../test/lib/utils/cmd-list.js.test.cjs | 4 +-- test/lib/commands/bin.js | 32 ------------------- 8 files changed, 6 insertions(+), 87 deletions(-) delete mode 100644 lib/commands/bin.js delete mode 100644 test/lib/commands/bin.js diff --git a/lib/commands/bin.js b/lib/commands/bin.js deleted file mode 100644 index 9ba3cb4003241..0000000000000 --- a/lib/commands/bin.js +++ /dev/null @@ -1,23 +0,0 @@ -const log = require('../utils/log-shim.js') -const BaseCommand = require('../base-command.js') -// TODO this may not be needed at all. Ignoring because our tests normalize -// process.env.path already -/* istanbul ignore next */ -const path = process.env.path || process.env.Path || process.env.PATH -const { delimiter } = require('path') - -class Bin extends BaseCommand { - static description = 'Display npm bin folder' - static name = 'bin' - static params = ['global'] - static ignoreImplicitWorkspace = true - - async exec (args) { - const b = this.npm.bin - this.npm.output(b) - if (this.npm.global && !path.split(delimiter).includes(b)) { - log.error('bin', '(not in PATH env variable)') - } - } -} -module.exports = Bin diff --git a/lib/utils/cmd-list.js b/lib/utils/cmd-list.js index 38439542a21f9..4dca7df2d304b 100644 --- a/lib/utils/cmd-list.js +++ b/lib/utils/cmd-list.js @@ -74,7 +74,6 @@ const cmdList = [ 'access', 'adduser', 'audit', - 'bin', 'bugs', 'cache', 'ci', diff --git a/smoke-tests/tap-snapshots/test/index.js.test.cjs b/smoke-tests/tap-snapshots/test/index.js.test.cjs index 68145ce52b12e..6b0b7b3940605 100644 --- a/smoke-tests/tap-snapshots/test/index.js.test.cjs +++ b/smoke-tests/tap-snapshots/test/index.js.test.cjs @@ -21,7 +21,7 @@ npm help npm more involved overview All commands: - access, adduser, audit, bin, bugs, cache, ci, completion, + access, adduser, audit, bugs, cache, ci, completion, config, dedupe, deprecate, diff, dist-tag, docs, doctor, edit, exec, explain, explore, find-dupes, fund, get, help, hook, init, install, install-ci-test, install-test, link, diff --git a/tap-snapshots/test/lib/commands/completion.js.test.cjs b/tap-snapshots/test/lib/commands/completion.js.test.cjs index f08ef0f37c360..6bd7901e205fb 100644 --- a/tap-snapshots/test/lib/commands/completion.js.test.cjs +++ b/tap-snapshots/test/lib/commands/completion.js.test.cjs @@ -47,7 +47,6 @@ Array [ access adduser audit - bin bugs cache ci diff --git a/tap-snapshots/test/lib/load-all-commands.js.test.cjs b/tap-snapshots/test/lib/load-all-commands.js.test.cjs index eac037f4b2708..6ea63931ce874 100644 --- a/tap-snapshots/test/lib/load-all-commands.js.test.cjs +++ b/tap-snapshots/test/lib/load-all-commands.js.test.cjs @@ -57,18 +57,6 @@ Options: Run "npm help audit" for more info ` -exports[`test/lib/load-all-commands.js TAP load each command bin > must match snapshot 1`] = ` -Display npm bin folder - -Usage: -npm bin - -Options: -[-g|--global] - -Run "npm help bin" for more info -` - exports[`test/lib/load-all-commands.js TAP load each command birthday > must match snapshot 1`] = ` Birthday, deprecated diff --git a/tap-snapshots/test/lib/npm.js.test.cjs b/tap-snapshots/test/lib/npm.js.test.cjs index 094792afd5620..fcd167742b442 100644 --- a/tap-snapshots/test/lib/npm.js.test.cjs +++ b/tap-snapshots/test/lib/npm.js.test.cjs @@ -21,7 +21,7 @@ npm help npm more involved overview All commands: - access, adduser, audit, bin, bugs, cache, ci, completion, + access, adduser, audit, bugs, cache, ci, completion, config, dedupe, deprecate, diff, dist-tag, docs, doctor, edit, exec, explain, explore, find-dupes, fund, get, help, hook, init, install, install-ci-test, install-test, link, @@ -57,7 +57,7 @@ npm help npm more involved overview All commands: - access, adduser, audit, bin, bugs, cache, ci, completion, + access, adduser, audit, bugs, cache, ci, completion, config, dedupe, deprecate, diff, dist-tag, docs, doctor, edit, exec, explain, explore, find-dupes, fund, get, help, hook, init, install, install-ci-test, install-test, link, @@ -93,7 +93,7 @@ npm help npm more involved overview All commands: - access, adduser, audit, bin, bugs, cache, ci, completion, + access, adduser, audit, bugs, cache, ci, completion, config, dedupe, deprecate, diff, dist-tag, docs, doctor, edit, exec, explain, explore, find-dupes, fund, get, help, hook, init, install, install-ci-test, install-test, link, @@ -129,7 +129,7 @@ npm help npm more involved overview (in a browser) All commands: - access, adduser, audit, bin, bugs, cache, ci, completion, + access, adduser, audit, bugs, cache, ci, completion, config, dedupe, deprecate, diff, dist-tag, docs, doctor, edit, exec, explain, explore, find-dupes, fund, get, help, hook, init, install, install-ci-test, install-test, link, @@ -211,16 +211,6 @@ All commands: Run "npm help audit" for more info - bin Display npm bin folder - - Usage: - npm bin - - Options: - [-g|--global] - - Run "npm help bin" for more info - bugs Report bugs for a package in a web browser Usage: diff --git a/tap-snapshots/test/lib/utils/cmd-list.js.test.cjs b/tap-snapshots/test/lib/utils/cmd-list.js.test.cjs index dd0df9b868c7a..e88cf67fa54e7 100644 --- a/tap-snapshots/test/lib/utils/cmd-list.js.test.cjs +++ b/tap-snapshots/test/lib/utils/cmd-list.js.test.cjs @@ -30,8 +30,7 @@ Object { "auth": "author", "autho": "author", "author": "author", - "bi": "bin", - "bin": "bin", + "b": "bugs", "bu": "bugs", "bug": "bugs", "bugs": "bugs", @@ -418,7 +417,6 @@ Object { "access", "adduser", "audit", - "bin", "bugs", "cache", "ci", diff --git a/test/lib/commands/bin.js b/test/lib/commands/bin.js deleted file mode 100644 index 46170e765de82..0000000000000 --- a/test/lib/commands/bin.js +++ /dev/null @@ -1,32 +0,0 @@ -const t = require('tap') -const { load: loadMockNpm } = require('../../fixtures/mock-npm') -const mockGlobals = require('../../fixtures/mock-globals') - -t.test('bin not global', async t => { - const { npm, joinedOutput, logs } = await loadMockNpm(t) - await npm.exec('bin', []) - t.match(joinedOutput(), npm.localBin) - t.match(logs.error, []) -}) - -t.test('bin global in env.path', async t => { - const { npm, joinedOutput, logs } = await loadMockNpm(t, { - config: { global: true }, - }) - - mockGlobals(t, { - 'process.env': { path: npm.globalBin }, - }) - await npm.exec('bin', []) - t.match(joinedOutput(), npm.globalBin) - t.match(logs.error, []) -}) - -t.test('bin not in path', async t => { - const { npm, joinedOutput, logs } = await loadMockNpm(t, { - config: { global: true }, - }) - await npm.exec('bin', []) - t.match(joinedOutput(), npm.globalBin) - t.match(logs.error, [['bin', '(not in PATH env variable)']]) -})