Skip to content

Commit

Permalink
feat: add deprecation warnings to access commands
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar authored and lukekarrys committed Aug 25, 2022
1 parent 2561822 commit d94a9f5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
13 changes: 6 additions & 7 deletions docs/content/commands/npm-access.md
Expand Up @@ -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 `<user>` 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
Expand Down
16 changes: 15 additions & 1 deletion lib/commands/access.js
Expand Up @@ -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 = [
Expand All @@ -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'
Expand Down Expand Up @@ -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,
})
Expand Down Expand Up @@ -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) {
Expand Down
30 changes: 23 additions & 7 deletions test/lib/commands/access.js
Expand Up @@ -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'
)
})
Expand All @@ -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,
},
Expand All @@ -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(), '')
})

Expand Down Expand Up @@ -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,
},
Expand All @@ -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(), '')
})

Expand Down Expand Up @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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(), '')
})

Expand Down Expand Up @@ -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,
},
Expand All @@ -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)
})

Expand All @@ -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,
},
Expand All @@ -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)
})

Expand Down

0 comments on commit d94a9f5

Please sign in to comment.