Skip to content

Commit a259eb6

Browse files
committed
fix: add deprecation warnings to access commands
npm/statusboard#500
1 parent c383564 commit a259eb6

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

lib/commands/access.js

Lines changed: 15 additions & 1 deletion
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

Lines changed: 13 additions & 7 deletions
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,7 @@ 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], ['access', 'restricted subcommand will be removed in the next version of npm'])
155157
t.equal(joinedOutput(), '')
156158
})
157159

@@ -274,7 +276,7 @@ t.test('access grant malformed team arg', async t => {
274276
})
275277

276278
t.test('access 2fa-required', async t => {
277-
const { npm, joinedOutput } = await loadMockNpm(t, {
279+
const { npm, joinedOutput, logs } = await loadMockNpm(t, {
278280
config: {
279281
...auth,
280282
},
@@ -286,11 +288,12 @@ t.test('access 2fa-required', async t => {
286288
})
287289
registry.access({ spec: '@scope/pkg', publishRequires2fa: true })
288290
await npm.exec('access', ['2fa-required', '@scope/pkg'])
291+
t.match(logs.warn[0], ['access', '2fa-required subcommand will be removed in the next version of npm'])
289292
t.equal(joinedOutput(), '')
290293
})
291294

292295
t.test('access 2fa-not-required', async t => {
293-
const { npm, joinedOutput } = await loadMockNpm(t, {
296+
const { npm, joinedOutput, logs } = await loadMockNpm(t, {
294297
config: {
295298
...auth,
296299
},
@@ -302,6 +305,7 @@ t.test('access 2fa-not-required', async t => {
302305
})
303306
registry.access({ spec: '@scope/pkg', publishRequires2fa: false })
304307
await npm.exec('access', ['2fa-not-required', '@scope/pkg'])
308+
t.match(logs.warn[0], ['access', '2fa-not-required subcommand will be removed in the next version of npm'])
305309
t.equal(joinedOutput(), '')
306310
})
307311

@@ -348,7 +352,7 @@ t.test('access revoke malformed team arg', async t => {
348352
})
349353

350354
t.test('npm access ls-packages with no team', async t => {
351-
const { npm, joinedOutput } = await loadMockNpm(t, {
355+
const { npm, joinedOutput, logs } = await loadMockNpm(t, {
352356
config: {
353357
...auth,
354358
},
@@ -363,6 +367,7 @@ t.test('npm access ls-packages with no team', async t => {
363367
registry.whoami({ username: team })
364368
registry.lsPackages({ team, packages })
365369
await npm.exec('access', ['ls-packages'])
370+
t.match(logs.warn[0], ['access', 'ls-packages subcommand will be removed in the next version of npm'])
366371
t.match(JSON.parse(joinedOutput()), packages)
367372
})
368373

@@ -385,7 +390,7 @@ t.test('access ls-packages on team', async t => {
385390
})
386391

387392
t.test('access ls-collaborators on current', async t => {
388-
const { npm, joinedOutput } = await loadMockNpm(t, {
393+
const { npm, joinedOutput, logs } = await loadMockNpm(t, {
389394
config: {
390395
...auth,
391396
},
@@ -403,6 +408,7 @@ t.test('access ls-collaborators on current', async t => {
403408
const collaborators = { 'test-user': 'read-write' }
404409
registry.lsCollaborators({ spec: 'yargs', collaborators })
405410
await npm.exec('access', ['ls-collaborators'])
411+
t.match(logs.warn[0], ['access', 'ls-collaborators subcommand will be removed in the next version of npm'])
406412
t.match(JSON.parse(joinedOutput()), collaborators)
407413
})
408414

0 commit comments

Comments
 (0)