From d94a9f56cce1de32bfd87f841d7678e8394d8ea6 Mon Sep 17 00:00:00 2001 From: Gar Date: Thu, 25 Aug 2022 09:46:12 -0700 Subject: [PATCH] feat: add deprecation warnings to access commands --- docs/content/commands/npm-access.md | 13 ++++++------- lib/commands/access.js | 16 ++++++++++++++- test/lib/commands/access.js | 30 ++++++++++++++++++++++------- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/docs/content/commands/npm-access.md b/docs/content/commands/npm-access.md index 162e94f1fec02..f7a98af654714 100644 --- a/docs/content/commands/npm-access.md +++ b/docs/content/commands/npm-access.md @@ -35,29 +35,28 @@ For all of the subcommands, `npm access` will perform actions on the packages in the current working directory if no package name is passed to the subcommand. -* public / restricted: +* public / restricted (deprecated): Set a package to be either publicly accessible or restricted. -* grant / revoke: +* grant / revoke (deprecated): Add or remove the ability of users and teams to have read-only or read-write access to a package. -* 2fa-required / 2fa-not-required: +* 2fa-required / 2fa-not-required (deprecated): Configure whether a package requires that anyone publishing it have two-factor authentication enabled on their account. -* ls-packages: +* ls-packages (deprecated): Show all of the packages a user or a team is able to access, along with the access level, except for read-only public packages (it won't print the whole registry listing) -* ls-collaborators: +* ls-collaborators (deprecated): Show all of the access privileges for a package. Will only show permissions for packages to which you have at least read access. If `` is passed in, the list is filtered only to teams _that_ user happens to belong to. -* edit: - Set the access privileges for a package at once using `$EDITOR`. +* edit (not implemented) ### Details diff --git a/lib/commands/access.js b/lib/commands/access.js index 0a80da8ddd006..3621861537171 100644 --- a/lib/commands/access.js +++ b/lib/commands/access.js @@ -5,6 +5,7 @@ const readPackageJson = require('read-package-json-fast') const otplease = require('../utils/otplease.js') const getIdentity = require('../utils/get-identity.js') +const log = require('../utils/log-shim.js') const BaseCommand = require('../base-command.js') const subcommands = [ @@ -19,6 +20,15 @@ const subcommands = [ '2fa-not-required', ] +const deprecated = [ + '2fa-not-required', + '2fa-required', + 'ls-collaborators', + 'ls-packages', + 'public', + 'restricted', +] + class Access extends BaseCommand { static description = 'Set access level on published packages' static name = 'access' @@ -78,6 +88,10 @@ class Access extends BaseCommand { throw this.usageError(`${cmd} is not a recognized subcommand.`) } + if (deprecated.includes(cmd)) { + log.warn('access', `${cmd} subcommand will be removed in the next version of npm`) + } + return this[cmd](args, { ...this.npm.flatOptions, }) @@ -175,7 +189,7 @@ class Access extends BaseCommand { } async edit () { - throw new Error('edit subcommand is not implemented yet') + throw new Error('edit subcommand is not implemented') } modifyPackage (pkg, opts, fn, requireScope = true) { diff --git a/test/lib/commands/access.js b/test/lib/commands/access.js index 130522b3be3e4..aa748b10681df 100644 --- a/test/lib/commands/access.js +++ b/test/lib/commands/access.js @@ -57,7 +57,7 @@ t.test('edit', async t => { const { npm } = await loadMockNpm(t) await t.rejects( npm.exec('access', ['edit', '@scoped/another']), - /edit subcommand is not implemented yet/, + /edit subcommand is not implemented/, 'should throw not implemented yet error' ) }) @@ -79,7 +79,7 @@ t.test('access public on unscoped package', async t => { t.test('access public on scoped package', async t => { const name = '@scoped/npm-access-public-pkg' - const { npm, joinedOutput } = await loadMockNpm(t, { + const { npm, joinedOutput, logs } = await loadMockNpm(t, { config: { ...auth, }, @@ -94,6 +94,7 @@ t.test('access public on scoped package', async t => { }) registry.access({ spec: name, access: 'public' }) await npm.exec('access', ['public']) + t.match(logs.warn[0], ['access', 'public subcommand will be removed in the next version of npm']) t.equal(joinedOutput(), '') }) @@ -137,7 +138,7 @@ t.test('access restricted on unscoped package', async t => { t.test('access restricted on scoped package', async t => { const name = '@scoped/npm-access-restricted-pkg' - const { npm, joinedOutput } = await loadMockNpm(t, { + const { npm, joinedOutput, logs } = await loadMockNpm(t, { config: { ...auth, }, @@ -152,6 +153,9 @@ t.test('access restricted on scoped package', async t => { }) registry.access({ spec: name, access: 'restricted' }) await npm.exec('access', ['restricted']) + t.match(logs.warn[0], + ['access', 'restricted subcommand will be removed in the next version of npm'] + ) t.equal(joinedOutput(), '') }) @@ -274,7 +278,7 @@ t.test('access grant malformed team arg', async t => { }) t.test('access 2fa-required', async t => { - const { npm, joinedOutput } = await loadMockNpm(t, { + const { npm, joinedOutput, logs } = await loadMockNpm(t, { config: { ...auth, }, @@ -286,11 +290,14 @@ t.test('access 2fa-required', async t => { }) registry.access({ spec: '@scope/pkg', publishRequires2fa: true }) await npm.exec('access', ['2fa-required', '@scope/pkg']) + t.match(logs.warn[0], + ['access', '2fa-required subcommand will be removed in the next version of npm'] + ) t.equal(joinedOutput(), '') }) t.test('access 2fa-not-required', async t => { - const { npm, joinedOutput } = await loadMockNpm(t, { + const { npm, joinedOutput, logs } = await loadMockNpm(t, { config: { ...auth, }, @@ -302,6 +309,9 @@ t.test('access 2fa-not-required', async t => { }) registry.access({ spec: '@scope/pkg', publishRequires2fa: false }) await npm.exec('access', ['2fa-not-required', '@scope/pkg']) + t.match(logs.warn[0], + ['access', '2fa-not-required subcommand will be removed in the next version of npm'] + ) t.equal(joinedOutput(), '') }) @@ -348,7 +358,7 @@ t.test('access revoke malformed team arg', async t => { }) t.test('npm access ls-packages with no team', async t => { - const { npm, joinedOutput } = await loadMockNpm(t, { + const { npm, joinedOutput, logs } = await loadMockNpm(t, { config: { ...auth, }, @@ -363,6 +373,9 @@ t.test('npm access ls-packages with no team', async t => { registry.whoami({ username: team }) registry.lsPackages({ team, packages }) await npm.exec('access', ['ls-packages']) + t.match(logs.warn[0], + ['access', 'ls-packages subcommand will be removed in the next version of npm'] + ) t.match(JSON.parse(joinedOutput()), packages) }) @@ -385,7 +398,7 @@ t.test('access ls-packages on team', async t => { }) t.test('access ls-collaborators on current', async t => { - const { npm, joinedOutput } = await loadMockNpm(t, { + const { npm, joinedOutput, logs } = await loadMockNpm(t, { config: { ...auth, }, @@ -403,6 +416,9 @@ t.test('access ls-collaborators on current', async t => { const collaborators = { 'test-user': 'read-write' } registry.lsCollaborators({ spec: 'yargs', collaborators }) await npm.exec('access', ['ls-collaborators']) + t.match(logs.warn[0], + ['access', 'ls-collaborators subcommand will be removed in the next version of npm'] + ) t.match(JSON.parse(joinedOutput()), collaborators) })