diff --git a/docs/lib/content/commands/npm-adduser.md b/docs/lib/content/commands/npm-adduser.md deleted file mode 100644 index a7f0d0a1a9fbb..0000000000000 --- a/docs/lib/content/commands/npm-adduser.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -title: npm-adduser -section: 1 -description: Add a registry user account ---- - -### Synopsis - - - -### Description - -Create a new user in the specified registry, and save the credentials to the `.npmrc` file. -If no registry is specified, the default registry will be used (see [`registry`](/using-npm/registry)). - -When you run `npm adduser`, the CLI automatically generates a legacy token of `publish` type. -For more information, see [About legacy tokens](/about-access-tokens#about-legacy-tokens). - -When using `legacy` for your `auth-type`, the username, password, and email are read in from prompts. - -### Configuration - - - -### See Also - -* [npm registry](/using-npm/registry) -* [npm config](/commands/npm-config) -* [npmrc](/configuring-npm/npmrc) -* [npm owner](/commands/npm-owner) -* [npm whoami](/commands/npm-whoami) -* [npm token](/commands/npm-token) -* [npm profile](/commands/npm-profile) diff --git a/docs/lib/content/commands/npm-deprecate.md b/docs/lib/content/commands/npm-deprecate.md index 183c65113a160..d83320743ce0d 100644 --- a/docs/lib/content/commands/npm-deprecate.md +++ b/docs/lib/content/commands/npm-deprecate.md @@ -28,7 +28,7 @@ npm deprecate my-thing@1.x "1.x is no longer supported" In this case, a version `my-thing@1.0.0-beta.0` will also be deprecated. You must be the package owner to deprecate something. -See the `owner` and `adduser` help topics. +See the `owner` and `login` help topics. To un-deprecate a package, specify an empty string (`""`) for the `message` argument. Note that you must use double quotes with no space between them to format an empty string. @@ -43,4 +43,4 @@ Note that you must use double quotes with no space between them to format an emp * [npm publish](/commands/npm-publish) * [npm registry](/using-npm/registry) * [npm owner](/commands/npm-owner) -* [npm adduser](/commands/npm-adduser) +* [npm login](/commands/npm-login) diff --git a/docs/lib/content/commands/npm-logout.md b/docs/lib/content/commands/npm-logout.md index 4d31727bb02d5..05cf90b67c3f4 100644 --- a/docs/lib/content/commands/npm-logout.md +++ b/docs/lib/content/commands/npm-logout.md @@ -24,7 +24,7 @@ If `--scope` is provided, this will find the credentials for the registry connec ### See Also -* [npm adduser](/commands/npm-adduser) +* [npm login](/commands/npm-login) * [npm registry](/using-npm/registry) * [npm config](/commands/npm-config) * [npm whoami](/commands/npm-whoami) diff --git a/docs/lib/content/commands/npm-owner.md b/docs/lib/content/commands/npm-owner.md index 4bea77a0f9aac..32f9d28d6db20 100644 --- a/docs/lib/content/commands/npm-owner.md +++ b/docs/lib/content/commands/npm-owner.md @@ -35,4 +35,4 @@ If you have two-factor authentication enabled with `auth-and-writes` (see [`npm- * [npm profile](/commands/npm-profile) * [npm publish](/commands/npm-publish) * [npm registry](/using-npm/registry) -* [npm adduser](/commands/npm-adduser) +* [npm login](/commands/npm-login) diff --git a/docs/lib/content/commands/npm-profile.md b/docs/lib/content/commands/npm-profile.md index fc69cef28918e..cc001aff499d4 100644 --- a/docs/lib/content/commands/npm-profile.md +++ b/docs/lib/content/commands/npm-profile.md @@ -55,7 +55,7 @@ Some of these commands may not be available on non npmjs.com registries. ### See Also -* [npm adduser](/commands/npm-adduser) +* [npm login](/commands/npm-login) * [npm registry](/using-npm/registry) * [npm config](/commands/npm-config) * [npmrc](/configuring-npm/npmrc) diff --git a/docs/lib/content/commands/npm-publish.md b/docs/lib/content/commands/npm-publish.md index b2cf7f143e47f..8b1bd6e55541e 100644 --- a/docs/lib/content/commands/npm-publish.md +++ b/docs/lib/content/commands/npm-publish.md @@ -98,7 +98,7 @@ See [`package.json`](/configuring-npm/package-json) for more info on what can an * [npm-packlist package](http://npm.im/npm-packlist) * [npm registry](/using-npm/registry) * [npm scope](/using-npm/scope) -* [npm adduser](/commands/npm-adduser) +* [npm login](/commands/npm-login) * [npm owner](/commands/npm-owner) * [npm deprecate](/commands/npm-deprecate) * [npm dist-tag](/commands/npm-dist-tag) diff --git a/docs/lib/content/commands/npm-star.md b/docs/lib/content/commands/npm-star.md index 431ee396761aa..6c3813abc09ea 100644 --- a/docs/lib/content/commands/npm-star.md +++ b/docs/lib/content/commands/npm-star.md @@ -41,4 +41,4 @@ You can see all your starred packages using [`npm stars`](/commands/npm-stars) * [npm stars](/commands/npm-stars) * [npm view](/commands/npm-view) * [npm whoami](/commands/npm-whoami) -* [npm adduser](/commands/npm-adduser) +* [npm login](/commands/npm-login) diff --git a/docs/lib/content/commands/npm-stars.md b/docs/lib/content/commands/npm-stars.md index 750b7bacff970..7b9a6cf7e93d2 100644 --- a/docs/lib/content/commands/npm-stars.md +++ b/docs/lib/content/commands/npm-stars.md @@ -24,4 +24,4 @@ You may also want to see your friend's favorite packages, in this case you will * [npm unstar](/commands/npm-unstar) * [npm view](/commands/npm-view) * [npm whoami](/commands/npm-whoami) -* [npm adduser](/commands/npm-adduser) +* [npm login](/commands/npm-login) diff --git a/docs/lib/content/commands/npm-token.md b/docs/lib/content/commands/npm-token.md index 5395466c68920..5a1d2702340cc 100644 --- a/docs/lib/content/commands/npm-token.md +++ b/docs/lib/content/commands/npm-token.md @@ -34,7 +34,7 @@ A revoked token will immediately be removed from the registry and you will no lo ### See Also -* [npm adduser](/commands/npm-adduser) +* [npm login](/commands/npm-login) * [npm registry](/using-npm/registry) * [npm config](/commands/npm-config) * [npmrc](/configuring-npm/npmrc) diff --git a/docs/lib/content/commands/npm-unpublish.md b/docs/lib/content/commands/npm-unpublish.md index 152af8b55212d..ffd04fd4ff7ec 100644 --- a/docs/lib/content/commands/npm-unpublish.md +++ b/docs/lib/content/commands/npm-unpublish.md @@ -18,7 +18,7 @@ Consider using the [`deprecate`](/commands/npm-deprecate) command instead, if yo This removes a package version from the registry, deleting its entry and removing the tarball. -The npm registry will return an error if you are not [logged in](/commands/npm-adduser). +The npm registry will return an error if you are not [logged in](/commands/npm-login). If you do not specify a package name at all, the name and version to be unpublished will be pulled from the project in the current directory. @@ -38,6 +38,5 @@ If you unpublish the entire package, you may not publish any new versions of tha * [npm deprecate](/commands/npm-deprecate) * [npm publish](/commands/npm-publish) * [npm registry](/using-npm/registry) -* [npm adduser](/commands/npm-adduser) * [npm owner](/commands/npm-owner) -* [npm login](/commands/npm-adduser) +* [npm login](/commands/npm-login) diff --git a/docs/lib/content/commands/npm-unstar.md b/docs/lib/content/commands/npm-unstar.md index 51124d8b1e65a..40c09d51d03fc 100644 --- a/docs/lib/content/commands/npm-unstar.md +++ b/docs/lib/content/commands/npm-unstar.md @@ -34,5 +34,5 @@ You can see all your starred packages using [`npm stars`](/commands/npm-stars) * [npm stars](/commands/npm-stars) * [npm view](/commands/npm-view) * [npm whoami](/commands/npm-whoami) -* [npm adduser](/commands/npm-adduser) +* [npm login](/commands/npm-login) diff --git a/docs/lib/content/commands/npm-whoami.md b/docs/lib/content/commands/npm-whoami.md index 4f87e954761c2..04a9e8b65e4a3 100644 --- a/docs/lib/content/commands/npm-whoami.md +++ b/docs/lib/content/commands/npm-whoami.md @@ -24,4 +24,4 @@ If logged into a registry that uses Basic Auth, then simply print the `username` * [npm config](/commands/npm-config) * [npmrc](/configuring-npm/npmrc) -* [npm adduser](/commands/npm-adduser) +* [npm login](/commands/npm-login) diff --git a/docs/lib/content/commands/npm.md b/docs/lib/content/commands/npm.md index 44dd0475d145e..f4c8ff37742e1 100644 --- a/docs/lib/content/commands/npm.md +++ b/docs/lib/content/commands/npm.md @@ -78,8 +78,8 @@ If you're using npm to develop and publish your code, check out the following he * install: It's a good idea to install things if you don't need the symbolic link. Especially, installing other peoples code from the registry is done via [`npm install`](/commands/npm-install) -* adduser: - Create an account or log in. +* login: + Log in to the registry and store credentials. When you do this, npm will store credentials in the user config file. * publish: Use the [`npm publish`](/commands/npm-publish) command to upload your code to the registry. diff --git a/docs/lib/content/nav.yml b/docs/lib/content/nav.yml index 810696069d07e..cb7644db47331 100644 --- a/docs/lib/content/nav.yml +++ b/docs/lib/content/nav.yml @@ -12,9 +12,6 @@ - title: npm access url: /commands/npm-access description: Set access level on published packages - - title: npm adduser - url: /commands/npm-adduser - description: Add a registry user account - title: npm audit url: /commands/npm-audit description: Run a security audit diff --git a/docs/lib/content/using-npm/developers.md b/docs/lib/content/using-npm/developers.md index de0cb848c59ff..7f86dc123db6c 100644 --- a/docs/lib/content/using-npm/developers.md +++ b/docs/lib/content/using-npm/developers.md @@ -173,16 +173,7 @@ Then go into the node-repl, and try using require("my-thing") to bring in your m ### Create a User Account -Create a user with the adduser command. -It works like this: - -```bash -npm adduser -``` - -and then follow the prompts. - -This is documented better in [npm adduser](/commands/npm-adduser). +Create a user account on the [npm website](https://www.npmjs.com/signup). ### Publish your Package @@ -211,5 +202,5 @@ Tell the world how easy it is to install your program! * [package.json](/configuring-npm/package-json) * [npm scripts](/using-npm/scripts) * [npm publish](/commands/npm-publish) -* [npm adduser](/commands/npm-adduser) +* [npm login](/commands/npm-login) * [npm registry](/using-npm/registry) diff --git a/lib/commands/adduser.js b/lib/commands/adduser.js deleted file mode 100644 index cf64e7a7e7438..0000000000000 --- a/lib/commands/adduser.js +++ /dev/null @@ -1,50 +0,0 @@ -const { log, output } = require('proc-log') -const { redactLog: replaceInfo } = require('@npmcli/redact') -const auth = require('../utils/auth.js') -const BaseCommand = require('../base-cmd.js') - -class AddUser extends BaseCommand { - static description = 'Add a registry user account' - static name = 'adduser' - static params = [ - 'registry', - 'scope', - 'auth-type', - ] - - async exec () { - const scope = this.npm.config.get('scope') - let registry = this.npm.config.get('registry') - - if (scope) { - const scopedRegistry = this.npm.config.get(`${scope}:registry`) - const cliRegistry = this.npm.config.get('registry', 'cli') - if (scopedRegistry && !cliRegistry) { - registry = scopedRegistry - } - } - - const creds = this.npm.config.getCredentialsByURI(registry) - - log.notice('', `Log in on ${replaceInfo(registry)}`) - - const { message, newCreds } = await auth.adduser(this.npm, { - ...this.npm.flatOptions, - creds, - registry, - }) - - this.npm.config.delete('_token', 'user') // prevent legacy pollution - this.npm.config.setCredentialsByURI(registry, newCreds) - - if (scope) { - this.npm.config.set(scope + ':registry', registry, 'user') - } - - await this.npm.config.save('user') - - output.standard(message) - } -} - -module.exports = AddUser diff --git a/lib/utils/auth.js b/lib/utils/auth.js index a617ab9430b2a..55e40d5c3c269 100644 --- a/lib/utils/auth.js +++ b/lib/utils/auth.js @@ -1,4 +1,4 @@ -const { webAuthOpener, adduserWeb, loginWeb, loginCouch, adduserCouch } = require('npm-profile') +const { webAuthOpener, loginWeb, loginCouch } = require('npm-profile') const { log } = require('proc-log') const { createOpener } = require('../utils/open-url.js') const read = require('../utils/read-user-info.js') @@ -32,43 +32,6 @@ const otplease = async (npm, opts, fn) => { } } -const adduser = async (npm, { creds, ...opts }) => { - const authType = npm.config.get('auth-type') - let res - if (authType === 'web') { - try { - res = await adduserWeb(createOpener(npm, 'Create your account at'), opts) - } catch (err) { - if (err.code === 'ENYI') { - log.verbose('web add user not supported, trying couch') - } else { - throw err - } - } - } - - // auth type !== web or ENYI error w/ web adduser - if (!res) { - const username = await read.username('Username:', creds.username) - const password = await read.password('Password:', creds.password) - const email = await read.email('Email (this will be public):', creds.email) - // npm registry quirk: If you "add" an existing user with their current - // password, it's effectively a login, and if that account has otp you'll - // be prompted for it. - res = await otplease(npm, opts, (reqOpts) => adduserCouch(username, email, password, reqOpts)) - } - - // We don't know the username if it was a web login, all we can reliably log is scope and registry - const message = `Logged in${opts.scope ? ` to scope ${opts.scope}` : ''} on ${opts.registry}.` - - log.info('adduser', message) - - return { - message, - newCreds: { token: res.token }, - } -} - const login = async (npm, { creds, ...opts }) => { const authType = npm.config.get('auth-type') let res @@ -103,7 +66,6 @@ const login = async (npm, { creds, ...opts }) => { } module.exports = { - adduser, login, otplease, } diff --git a/lib/utils/cmd-list.js b/lib/utils/cmd-list.js index ec1d50dcc0c56..6e9080ee4021e 100644 --- a/lib/utils/cmd-list.js +++ b/lib/utils/cmd-list.js @@ -4,7 +4,6 @@ const abbrev = require('abbrev') // Please keep this list sorted alphabetically const commands = [ 'access', - 'adduser', 'audit', 'bugs', 'cache', @@ -137,7 +136,7 @@ const aliases = { sit: 'install-ci-test', urn: 'run', ogr: 'org', - 'add-user': 'adduser', + } const deref = (c) => { diff --git a/lib/utils/error-message.js b/lib/utils/error-message.js index 9faf4c339b1a5..e9678c823e979 100644 --- a/lib/utils/error-message.js +++ b/lib/utils/error-message.js @@ -277,7 +277,7 @@ const errorMessage = (er, npm) => { case 'ENEEDAUTH': summary.push(['need auth', er.message]) - detail.push(['need auth', 'You need to authorize this machine using `npm adduser`']) + detail.push(['need auth', 'You need to authorize this machine using `npm login`']) break case 'ECONNRESET': diff --git a/mock-registry/lib/index.js b/mock-registry/lib/index.js index b99dfe6b156aa..6f3b022467f35 100644 --- a/mock-registry/lib/index.js +++ b/mock-registry/lib/index.js @@ -228,27 +228,6 @@ class MockRegistry { } } - couchadduser ({ username, email, password, token = 'npm_default-test-token' }) { - this.nock = this.nock.put(this.fullPath(`/-/user/org.couchdb.user:${username}`), body => { - this.#tap.match(body, { - _id: `org.couchdb.user:${username}`, - name: username, - email, // Sole difference from couchlogin - password, - type: 'user', - roles: [], - }) - if (!body.date) { - return false - } - return true - }).reply(201, { - id: 'org.couchdb.user:undefined', - rev: '_we_dont_use_revs_any_more', - token, - }) - } - couchlogin ({ username, password, token = 'npm_default-test-token' }) { this.nock = this.nock.put(this.fullPath(`/-/user/org.couchdb.user:${username}`), body => { this.#tap.match(body, { diff --git a/smoke-tests/tap-snapshots/test/index.js.test.cjs b/smoke-tests/tap-snapshots/test/index.js.test.cjs index 2ac65a85d8e30..eb42ee329eebe 100644 --- a/smoke-tests/tap-snapshots/test/index.js.test.cjs +++ b/smoke-tests/tap-snapshots/test/index.js.test.cjs @@ -21,16 +21,15 @@ npm help npm more involved overview All commands: - access, adduser, audit, bugs, cache, ci, completion, - config, dedupe, deprecate, diff, dist-tag, docs, doctor, - edit, exec, explain, explore, find-dupes, fund, get, help, - help-search, init, install, install-ci-test, install-test, - link, ll, login, logout, ls, org, outdated, owner, pack, - ping, pkg, prefix, profile, prune, publish, query, rebuild, - repo, restart, root, run, sbom, search, set, shrinkwrap, - star, stars, start, stop, team, test, token, trust, - undeprecate, uninstall, unpublish, unstar, update, version, - view, whoami + access, audit, bugs, cache, ci, completion, config, + dedupe, deprecate, diff, dist-tag, docs, doctor, edit, exec, + explain, explore, find-dupes, fund, get, help, help-search, + init, install, install-ci-test, install-test, link, ll, + login, logout, ls, org, outdated, owner, pack, ping, pkg, + prefix, profile, prune, publish, query, rebuild, repo, + restart, root, run, sbom, search, set, shrinkwrap, star, + stars, start, stop, team, test, token, trust, undeprecate, + uninstall, unpublish, unstar, update, version, view, whoami Specify configs in the ini-formatted file: {NPM}/{TESTDIR}/home/.npmrc diff --git a/tap-snapshots/test/lib/commands/completion.js.test.cjs b/tap-snapshots/test/lib/commands/completion.js.test.cjs index 43a99252d4200..6a96d5be46eb8 100644 --- a/tap-snapshots/test/lib/commands/completion.js.test.cjs +++ b/tap-snapshots/test/lib/commands/completion.js.test.cjs @@ -61,11 +61,9 @@ exports[`test/lib/commands/completion.js TAP completion multiple command names > Array [ String( access - adduser audit author add - add-user ), ] ` diff --git a/tap-snapshots/test/lib/commands/publish.js.test.cjs b/tap-snapshots/test/lib/commands/publish.js.test.cjs index e7507118a28f5..2029b3c84c438 100644 --- a/tap-snapshots/test/lib/commands/publish.js.test.cjs +++ b/tap-snapshots/test/lib/commands/publish.js.test.cjs @@ -153,7 +153,6 @@ Object { "main": "./index.js", "man": Array [ "man/man1/npm-access.1", - "man/man1/npm-adduser.1", "man/man1/npm-audit.1", "man/man1/npm-bugs.1", "man/man1/npm-cache.1", diff --git a/tap-snapshots/test/lib/docs.js.test.cjs b/tap-snapshots/test/lib/docs.js.test.cjs index 9eb3219128ad5..c8ad57845c7ca 100644 --- a/tap-snapshots/test/lib/docs.js.test.cjs +++ b/tap-snapshots/test/lib/docs.js.test.cjs @@ -36,7 +36,6 @@ npm@{VERSION} {BASEDIR} exports[`test/lib/docs.js TAP command list > aliases 1`] = ` Object { "add": "install", - "add-user": "adduser", "author": "owner", "c": "config", "cit": "install-ci-test", @@ -97,7 +96,6 @@ Object { exports[`test/lib/docs.js TAP command list > commands 1`] = ` Array [ "access", - "adduser", "audit", "bugs", "cache", @@ -2822,42 +2820,6 @@ Note: This command is unaware of workspaces. #### \`registry\` ` -exports[`test/lib/docs.js TAP usage adduser > must match snapshot 1`] = ` -Add a registry user account - -Usage: -npm adduser - -Options: -[--registry ] [--scope <@scope>] [--auth-type ] - - --registry - The base URL of the npm registry. - - --scope - Associate an operation with a scope for a scoped registry. - - --auth-type - What authentication strategy to use with \`login\`. - - -alias: add-user - -Run "npm help adduser" for more info - -\`\`\`bash -npm adduser - -alias: add-user -\`\`\` - -Note: This command is unaware of workspaces. - -#### \`registry\` -#### \`scope\` -#### \`auth-type\` -` - exports[`test/lib/docs.js TAP usage audit > must match snapshot 1`] = ` Run a security audit diff --git a/tap-snapshots/test/lib/npm.js.test.cjs b/tap-snapshots/test/lib/npm.js.test.cjs index 888af047882fa..44a7bdcc3d796 100644 --- a/tap-snapshots/test/lib/npm.js.test.cjs +++ b/tap-snapshots/test/lib/npm.js.test.cjs @@ -31,16 +31,15 @@ npm help npm more involved overview All commands: - access, adduser, audit, bugs, cache, ci, completion, - config, dedupe, deprecate, diff, dist-tag, docs, doctor, - edit, exec, explain, explore, find-dupes, fund, get, help, - help-search, init, install, install-ci-test, install-test, - link, ll, login, logout, ls, org, outdated, owner, pack, - ping, pkg, prefix, profile, prune, publish, query, rebuild, - repo, restart, root, run, sbom, search, set, shrinkwrap, - star, stars, start, stop, team, test, token, trust, - undeprecate, uninstall, unpublish, unstar, update, version, - view, whoami + access, audit, bugs, cache, ci, completion, config, + dedupe, deprecate, diff, dist-tag, docs, doctor, edit, exec, + explain, explore, find-dupes, fund, get, help, help-search, + init, install, install-ci-test, install-test, link, ll, + login, logout, ls, org, outdated, owner, pack, ping, pkg, + prefix, profile, prune, publish, query, rebuild, repo, + restart, root, run, sbom, search, set, shrinkwrap, star, + stars, start, stop, team, test, token, trust, undeprecate, + uninstall, unpublish, unstar, update, version, view, whoami Specify configs in the ini-formatted file: {USERCONFIG} @@ -68,10 +67,10 @@ npm help npm more involved overview All commands: - access, adduser, - audit, bugs, cache, ci, - completion, config, - dedupe, deprecate, diff, + access, audit, bugs, + cache, ci, completion, + config, dedupe, + deprecate, diff, dist-tag, docs, doctor, edit, exec, explain, explore, find-dupes, @@ -121,10 +120,10 @@ npm help npm more involved overview All commands: - access, adduser, - audit, bugs, cache, ci, - completion, config, - dedupe, deprecate, diff, + access, audit, bugs, + cache, ci, completion, + config, dedupe, + deprecate, diff, dist-tag, docs, doctor, edit, exec, explain, explore, find-dupes, @@ -174,16 +173,15 @@ npm help npm more involved overview All commands: - access, adduser, audit, bugs, cache, ci, completion, - config, dedupe, deprecate, diff, dist-tag, docs, doctor, - edit, exec, explain, explore, find-dupes, fund, get, help, - help-search, init, install, install-ci-test, install-test, - link, ll, login, logout, ls, org, outdated, owner, pack, - ping, pkg, prefix, profile, prune, publish, query, rebuild, - repo, restart, root, run, sbom, search, set, shrinkwrap, - star, stars, start, stop, team, test, token, trust, - undeprecate, uninstall, unpublish, unstar, update, version, - view, whoami + access, audit, bugs, cache, ci, completion, config, + dedupe, deprecate, diff, dist-tag, docs, doctor, edit, exec, + explain, explore, find-dupes, fund, get, help, help-search, + init, install, install-ci-test, install-test, link, ll, + login, logout, ls, org, outdated, owner, pack, ping, pkg, + prefix, profile, prune, publish, query, rebuild, repo, + restart, root, run, sbom, search, set, shrinkwrap, star, + stars, start, stop, team, test, token, trust, undeprecate, + uninstall, unpublish, unstar, update, version, view, whoami Specify configs in the ini-formatted file: {USERCONFIG} @@ -211,10 +209,10 @@ npm help npm more involved overview All commands: - access, adduser, - audit, bugs, cache, ci, - completion, config, - dedupe, deprecate, diff, + access, audit, bugs, + cache, ci, completion, + config, dedupe, + deprecate, diff, dist-tag, docs, doctor, edit, exec, explain, explore, find-dupes, @@ -264,10 +262,10 @@ npm help npm more involved overview All commands: - access, adduser, - audit, bugs, cache, ci, - completion, config, - dedupe, deprecate, diff, + access, audit, bugs, + cache, ci, completion, + config, dedupe, + deprecate, diff, dist-tag, docs, doctor, edit, exec, explain, explore, find-dupes, @@ -317,10 +315,10 @@ npm help npm more involved overview All commands: - access, adduser, audit, - bugs, cache, ci, - completion, config, - dedupe, deprecate, diff, + access, audit, bugs, + cache, ci, completion, + config, dedupe, + deprecate, diff, dist-tag, docs, doctor, edit, exec, explain, explore, find-dupes, @@ -368,9 +366,9 @@ npm help npm more involved overview All commands: - access, adduser, audit, bugs, cache, ci, completion, - config, dedupe, deprecate, diff, dist-tag, docs, doctor, - edit, exec, explain, explore, find-dupes, fund, get, help, + access, audit, bugs, cache, ci, completion, config, + dedupe, deprecate, diff, dist-tag, docs, doctor, edit, + exec, explain, explore, find-dupes, fund, get, help, help-search, init, install, install-ci-test, install-test, link, ll, login, logout, ls, org, outdated, owner, pack, ping, pkg, prefix, profile, prune, publish, query, rebuild, @@ -405,16 +403,15 @@ npm help npm more involved overview All commands: - access, adduser, audit, bugs, cache, ci, completion, - config, dedupe, deprecate, diff, dist-tag, docs, doctor, - edit, exec, explain, explore, find-dupes, fund, get, help, - help-search, init, install, install-ci-test, install-test, - link, ll, login, logout, ls, org, outdated, owner, pack, - ping, pkg, prefix, profile, prune, publish, query, rebuild, - repo, restart, root, run, sbom, search, set, shrinkwrap, - star, stars, start, stop, team, test, token, trust, - undeprecate, uninstall, unpublish, unstar, update, version, - view, whoami + access, audit, bugs, cache, ci, completion, config, + dedupe, deprecate, diff, dist-tag, docs, doctor, edit, exec, + explain, explore, find-dupes, fund, get, help, help-search, + init, install, install-ci-test, install-test, link, ll, + login, logout, ls, org, outdated, owner, pack, ping, pkg, + prefix, profile, prune, publish, query, rebuild, repo, + restart, root, run, sbom, search, set, shrinkwrap, star, + stars, start, stop, team, test, token, trust, undeprecate, + uninstall, unpublish, unstar, update, version, view, whoami Specify configs in the ini-formatted file: {USERCONFIG} @@ -442,16 +439,15 @@ npm help npm more involved overview All commands: - access, adduser, audit, bugs, cache, ci, completion, - config, dedupe, deprecate, diff, dist-tag, docs, doctor, - edit, exec, explain, explore, find-dupes, fund, get, help, - help-search, init, install, install-ci-test, install-test, - link, ll, login, logout, ls, org, outdated, owner, pack, - ping, pkg, prefix, profile, prune, publish, query, rebuild, - repo, restart, root, run, sbom, search, set, shrinkwrap, - star, stars, start, stop, team, test, token, trust, - undeprecate, uninstall, unpublish, unstar, update, version, - view, whoami + access, audit, bugs, cache, ci, completion, config, + dedupe, deprecate, diff, dist-tag, docs, doctor, edit, exec, + explain, explore, find-dupes, fund, get, help, help-search, + init, install, install-ci-test, install-test, link, ll, + login, logout, ls, org, outdated, owner, pack, ping, pkg, + prefix, profile, prune, publish, query, rebuild, repo, + restart, root, run, sbom, search, set, shrinkwrap, star, + stars, start, stop, team, test, token, trust, undeprecate, + uninstall, unpublish, unstar, update, version, view, whoami Specify configs in the ini-formatted file: {USERCONFIG} diff --git a/tap-snapshots/test/lib/utils/error-message.js.test.cjs b/tap-snapshots/test/lib/utils/error-message.js.test.cjs index c180cb0f28377..ad3c49afe7897 100644 --- a/tap-snapshots/test/lib/utils/error-message.js.test.cjs +++ b/tap-snapshots/test/lib/utils/error-message.js.test.cjs @@ -1612,7 +1612,7 @@ Object { "detail": Array [ Array [ "need auth", - "You need to authorize this machine using \`npm adduser\`", + "You need to authorize this machine using \`npm login\`", ], ], "summary": Array [ diff --git a/test/lib/commands/adduser.js b/test/lib/commands/adduser.js deleted file mode 100644 index c69d996f91486..0000000000000 --- a/test/lib/commands/adduser.js +++ /dev/null @@ -1,181 +0,0 @@ -const t = require('tap') -const fs = require('node:fs') -const path = require('node:path') -const ini = require('ini') - -const { load: loadMockNpm } = require('../../fixtures/mock-npm.js') -const mockGlobals = require('@npmcli/mock-globals') -const MockRegistry = require('@npmcli/mock-registry') -const stream = require('node:stream') - -const mockAddUser = async (t, { stdin: stdinLines, registry: registryUrl, ...options } = {}) => { - if (stdinLines) { - const stdin = new stream.PassThrough() - for (const l of stdinLines) { - stdin.write(l + '\n') - } - mockGlobals(t, { - 'process.stdin': stdin, - 'process.stdout': new stream.PassThrough(), // to quiet readline - }, { replace: true }) - } - const mock = await loadMockNpm(t, { - ...options, - command: 'adduser', - }) - const registry = new MockRegistry({ - tap: t, - registry: registryUrl ?? mock.npm.config.get('registry'), - }) - return { - registry, - rc: () => ini.parse(fs.readFileSync(path.join(mock.home, '.npmrc'), 'utf8')), - ...mock, - } -} - -t.test('usage', async t => { - const { adduser } = await loadMockNpm(t, { command: 'adduser' }) - t.match(adduser.usage, 'adduser', 'usage has command name in it') -}) - -t.test('legacy', async t => { - t.test('simple adduser', async t => { - const { npm, rc, registry, adduser } = await mockAddUser(t, { - stdin: ['test-user', 'test-password', 'test-email@npmjs.org'], - config: { 'auth-type': 'legacy' }, - homeDir: { - '.npmrc': [ - '//registry.npmjs.org/:_authToken=user', - '//registry.npmjs.org/:always-auth=user', - '//registry.npmjs.org/:email=test-email-old@npmjs.org', - ].join('\n'), - }, - }) - registry.couchadduser({ - username: 'test-user', - password: 'test-password', - email: 'test-email@npmjs.org', - token: 'npm_test-token', - }) - await adduser.exec([]) - t.same(npm.config.get('email'), 'test-email-old@npmjs.org') - t.same(npm.config.get('//registry.npmjs.org/:_authToken'), 'npm_test-token') - t.same(rc(), { - '//registry.npmjs.org/:_authToken': 'npm_test-token', - email: 'test-email-old@npmjs.org', - }, 'should only have token and un-nerfed old email') - }) - - t.test('scoped adduser', async t => { - const { npm, rc, registry, adduser } = await mockAddUser(t, { - stdin: ['test-user', 'test-password', 'test-email@npmjs.org'], - config: { - 'auth-type': 'legacy', - scope: '@myscope', - }, - }) - registry.couchadduser({ - username: 'test-user', - password: 'test-password', - email: 'test-email@npmjs.org', - token: 'npm_test-token', - }) - await adduser.exec([]) - t.same(npm.config.get('//registry.npmjs.org/:_authToken'), 'npm_test-token') - t.same(npm.config.get('@myscope:registry'), 'https://registry.npmjs.org/') - t.same(rc(), { - '//registry.npmjs.org/:_authToken': 'npm_test-token', - '@myscope:registry': 'https://registry.npmjs.org/', - }, 'should only have token and scope:registry') - }) - - t.test('scoped adduser with valid scoped registry config', async t => { - const { npm, rc, registry, adduser } = await mockAddUser(t, { - stdin: ['test-user', 'test-password', 'test-email@npmjs.org'], - registry: 'https://diff-registry.npmjs.org', - homeDir: { - '.npmrc': '@myscope:registry=https://diff-registry.npmjs.org', - }, - config: { - 'auth-type': 'legacy', - scope: '@myscope', - }, - }) - registry.couchadduser({ - username: 'test-user', - password: 'test-password', - email: 'test-email@npmjs.org', - token: 'npm_test-token', - }) - await adduser.exec([]) - t.same(npm.config.get('//diff-registry.npmjs.org/:_authToken'), 'npm_test-token') - t.same(npm.config.get('@myscope:registry'), 'https://diff-registry.npmjs.org') - t.same(rc(), { - '@myscope:registry': 'https://diff-registry.npmjs.org', - '//diff-registry.npmjs.org/:_authToken': 'npm_test-token', - }, 'should only have token and scope:registry') - }) - - t.test('save config failure', async t => { - const { registry, adduser } = await mockAddUser(t, { - stdin: ['test-user', 'test-password', 'test-email@npmjs.org'], - config: { 'auth-type': 'legacy' }, - homeDir: { - '.npmrc': {}, - }, - }) - registry.couchadduser({ - username: 'test-user', - password: 'test-password', - email: 'test-email@npmjs.org', - token: 'npm_test-token', - }) - await t.rejects(adduser.exec([])) - }) - t.end() -}) - -t.test('web', t => { - t.test('basic adduser', async t => { - const { npm, rc, registry, adduser } = await mockAddUser(t, { - config: { 'auth-type': 'web' }, - }) - registry.webadduser({ token: 'npm_test-token' }) - await adduser.exec([]) - t.same(npm.config.get('//registry.npmjs.org/:_authToken'), 'npm_test-token') - t.same(rc(), { - '//registry.npmjs.org/:_authToken': 'npm_test-token', - }) - }) - - t.test('server error', async t => { - const { adduser, registry } = await mockAddUser(t, { - config: { 'auth-type': 'web' }, - }) - registry.nock.post(registry.fullPath('/-/v1/login')) - .reply(503, {}) - await t.rejects( - adduser.exec([]), - { message: /503/ } - ) - }) - - t.test('fallback', async t => { - const { npm, registry, adduser } = await mockAddUser(t, { - stdin: ['test-user', 'test-password', 'test-email@npmjs.org'], - config: { 'auth-type': 'web' }, - }) - registry.nock.post(registry.fullPath('/-/v1/login')) - .reply(404, {}) - registry.couchadduser({ - username: 'test-user', - password: 'test-password', - email: 'test-email@npmjs.org', - token: 'npm_test-token', - }) - await adduser.exec([]) - t.same(npm.config.get('//registry.npmjs.org/:_authToken'), 'npm_test-token') - }) - t.end() -}) diff --git a/test/lib/commands/completion.js b/test/lib/commands/completion.js index f3a2c4e12ff8f..1f07f651296db 100644 --- a/test/lib/commands/completion.js +++ b/test/lib/commands/completion.js @@ -152,10 +152,10 @@ t.test('completion', async t => { }) t.test('commands with no completion', async t => { - const { outputs, completion } = await loadMockCompletionComp(t, 2, 'npm adduser ') + const { outputs, completion } = await loadMockCompletionComp(t, 2, 'npm whoami ') - // quotes around adduser are to ensure coverage when unescaping commands - await completion.exec(['npm', "'adduser'", '']) + // quotes around whoami are to ensure coverage when unescaping commands + await completion.exec(['npm', "'whoami'", '']) t.matchSnapshot(outputs, 'no results') })