Skip to content

Commit d94a9f5

Browse files
wraithgarlukekarrys
authored andcommitted
feat: add deprecation warnings to access commands
1 parent 2561822 commit d94a9f5

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

docs/content/commands/npm-access.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,28 @@ For all of the subcommands, `npm access` will perform actions on the packages
3535
in the current working directory if no package name is passed to the
3636
subcommand.
3737
38-
* public / restricted:
38+
* public / restricted (deprecated):
3939
Set a package to be either publicly accessible or restricted.
4040
41-
* grant / revoke:
41+
* grant / revoke (deprecated):
4242
Add or remove the ability of users and teams to have read-only or read-write
4343
access to a package.
4444
45-
* 2fa-required / 2fa-not-required:
45+
* 2fa-required / 2fa-not-required (deprecated):
4646
Configure whether a package requires that anyone publishing it have two-factor
4747
authentication enabled on their account.
4848
49-
* ls-packages:
49+
* ls-packages (deprecated):
5050
Show all of the packages a user or a team is able to access, along with the
5151
access level, except for read-only public packages (it won't print the whole
5252
registry listing)
5353
54-
* ls-collaborators:
54+
* ls-collaborators (deprecated):
5555
Show all of the access privileges for a package. Will only show permissions
5656
for packages to which you have at least read access. If `<user>` is passed in,
5757
the list is filtered only to teams _that_ user happens to belong to.
5858
59-
* edit:
60-
Set the access privileges for a package at once using `$EDITOR`.
59+
* edit (not implemented)
6160
6261
### Details
6362

lib/commands/access.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const readPackageJson = require('read-package-json-fast')
55

66
const otplease = require('../utils/otplease.js')
77
const getIdentity = require('../utils/get-identity.js')
8+
const log = require('../utils/log-shim.js')
89
const BaseCommand = require('../base-command.js')
910

1011
const subcommands = [
@@ -19,6 +20,15 @@ const subcommands = [
1920
'2fa-not-required',
2021
]
2122

23+
const deprecated = [
24+
'2fa-not-required',
25+
'2fa-required',
26+
'ls-collaborators',
27+
'ls-packages',
28+
'public',
29+
'restricted',
30+
]
31+
2232
class Access extends BaseCommand {
2333
static description = 'Set access level on published packages'
2434
static name = 'access'
@@ -78,6 +88,10 @@ class Access extends BaseCommand {
7888
throw this.usageError(`${cmd} is not a recognized subcommand.`)
7989
}
8090

91+
if (deprecated.includes(cmd)) {
92+
log.warn('access', `${cmd} subcommand will be removed in the next version of npm`)
93+
}
94+
8195
return this[cmd](args, {
8296
...this.npm.flatOptions,
8397
})
@@ -175,7 +189,7 @@ class Access extends BaseCommand {
175189
}
176190

177191
async edit () {
178-
throw new Error('edit subcommand is not implemented yet')
192+
throw new Error('edit subcommand is not implemented')
179193
}
180194

181195
modifyPackage (pkg, opts, fn, requireScope = true) {

test/lib/commands/access.js

+23-7
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ t.test('edit', async t => {
5757
const { npm } = await loadMockNpm(t)
5858
await t.rejects(
5959
npm.exec('access', ['edit', '@scoped/another']),
60-
/edit subcommand is not implemented yet/,
60+
/edit subcommand is not implemented/,
6161
'should throw not implemented yet error'
6262
)
6363
})
@@ -79,7 +79,7 @@ t.test('access public on unscoped package', async t => {
7979

8080
t.test('access public on scoped package', async t => {
8181
const name = '@scoped/npm-access-public-pkg'
82-
const { npm, joinedOutput } = await loadMockNpm(t, {
82+
const { npm, joinedOutput, logs } = await loadMockNpm(t, {
8383
config: {
8484
...auth,
8585
},
@@ -94,6 +94,7 @@ t.test('access public on scoped package', async t => {
9494
})
9595
registry.access({ spec: name, access: 'public' })
9696
await npm.exec('access', ['public'])
97+
t.match(logs.warn[0], ['access', 'public subcommand will be removed in the next version of npm'])
9798
t.equal(joinedOutput(), '')
9899
})
99100

@@ -137,7 +138,7 @@ t.test('access restricted on unscoped package', async t => {
137138

138139
t.test('access restricted on scoped package', async t => {
139140
const name = '@scoped/npm-access-restricted-pkg'
140-
const { npm, joinedOutput } = await loadMockNpm(t, {
141+
const { npm, joinedOutput, logs } = await loadMockNpm(t, {
141142
config: {
142143
...auth,
143144
},
@@ -152,6 +153,9 @@ t.test('access restricted on scoped package', async t => {
152153
})
153154
registry.access({ spec: name, access: 'restricted' })
154155
await npm.exec('access', ['restricted'])
156+
t.match(logs.warn[0],
157+
['access', 'restricted subcommand will be removed in the next version of npm']
158+
)
155159
t.equal(joinedOutput(), '')
156160
})
157161

@@ -274,7 +278,7 @@ t.test('access grant malformed team arg', async t => {
274278
})
275279

276280
t.test('access 2fa-required', async t => {
277-
const { npm, joinedOutput } = await loadMockNpm(t, {
281+
const { npm, joinedOutput, logs } = await loadMockNpm(t, {
278282
config: {
279283
...auth,
280284
},
@@ -286,11 +290,14 @@ t.test('access 2fa-required', async t => {
286290
})
287291
registry.access({ spec: '@scope/pkg', publishRequires2fa: true })
288292
await npm.exec('access', ['2fa-required', '@scope/pkg'])
293+
t.match(logs.warn[0],
294+
['access', '2fa-required subcommand will be removed in the next version of npm']
295+
)
289296
t.equal(joinedOutput(), '')
290297
})
291298

292299
t.test('access 2fa-not-required', async t => {
293-
const { npm, joinedOutput } = await loadMockNpm(t, {
300+
const { npm, joinedOutput, logs } = await loadMockNpm(t, {
294301
config: {
295302
...auth,
296303
},
@@ -302,6 +309,9 @@ t.test('access 2fa-not-required', async t => {
302309
})
303310
registry.access({ spec: '@scope/pkg', publishRequires2fa: false })
304311
await npm.exec('access', ['2fa-not-required', '@scope/pkg'])
312+
t.match(logs.warn[0],
313+
['access', '2fa-not-required subcommand will be removed in the next version of npm']
314+
)
305315
t.equal(joinedOutput(), '')
306316
})
307317

@@ -348,7 +358,7 @@ t.test('access revoke malformed team arg', async t => {
348358
})
349359

350360
t.test('npm access ls-packages with no team', async t => {
351-
const { npm, joinedOutput } = await loadMockNpm(t, {
361+
const { npm, joinedOutput, logs } = await loadMockNpm(t, {
352362
config: {
353363
...auth,
354364
},
@@ -363,6 +373,9 @@ t.test('npm access ls-packages with no team', async t => {
363373
registry.whoami({ username: team })
364374
registry.lsPackages({ team, packages })
365375
await npm.exec('access', ['ls-packages'])
376+
t.match(logs.warn[0],
377+
['access', 'ls-packages subcommand will be removed in the next version of npm']
378+
)
366379
t.match(JSON.parse(joinedOutput()), packages)
367380
})
368381

@@ -385,7 +398,7 @@ t.test('access ls-packages on team', async t => {
385398
})
386399

387400
t.test('access ls-collaborators on current', async t => {
388-
const { npm, joinedOutput } = await loadMockNpm(t, {
401+
const { npm, joinedOutput, logs } = await loadMockNpm(t, {
389402
config: {
390403
...auth,
391404
},
@@ -403,6 +416,9 @@ t.test('access ls-collaborators on current', async t => {
403416
const collaborators = { 'test-user': 'read-write' }
404417
registry.lsCollaborators({ spec: 'yargs', collaborators })
405418
await npm.exec('access', ['ls-collaborators'])
419+
t.match(logs.warn[0],
420+
['access', 'ls-collaborators subcommand will be removed in the next version of npm']
421+
)
406422
t.match(JSON.parse(joinedOutput()), collaborators)
407423
})
408424

0 commit comments

Comments
 (0)