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 committed Aug 22, 2022
1 parent c383564 commit 481a38e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
16 changes: 15 additions & 1 deletion lib/commands/access.js
Original file line number Diff line number Diff line change
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
20 changes: 13 additions & 7 deletions test/lib/commands/access.js
Original file line number Diff line number Diff line change
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,7 @@ 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 +276,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 +288,12 @@ 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 +305,7 @@ 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 +352,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 +367,7 @@ 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 +390,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 +408,7 @@ 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 481a38e

Please sign in to comment.