Skip to content

Commit d967143

Browse files
committed
fix pkg check for list, revoke, fix unknown issue for entity provider
1 parent 127a146 commit d967143

File tree

6 files changed

+7
-11
lines changed

6 files changed

+7
-11
lines changed

lib/commands/trust/github.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class TrustGitHub extends TrustCommand {
5252

5353
validateEntity (entity) {
5454
if (entity.split('/').length !== 2) {
55-
throw new Error(`${this.providerEntity} must be specified in the format owner/repository`)
55+
throw new Error(`${this.constructor.providerEntity} must be specified in the format owner/repository`)
5656
}
5757
}
5858

lib/commands/trust/gitlab.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class TrustGitLab extends TrustCommand {
5151

5252
validateEntity (entity) {
5353
if (entity.split('/').length < 2) {
54-
throw new Error(`${this.providerEntity} must be specified in the format group/project or group/subgroup/project`)
54+
throw new Error(`${this.constructor.providerEntity} must be specified in the format group/project or group/subgroup/project`)
5555
}
5656
}
5757

lib/commands/trust/list.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const pkgJson = require('@npmcli/package-json')
21
const { otplease } = require('../../utils/auth.js')
32
const npmFetch = require('npm-registry-fetch')
43
const npa = require('npm-package-arg')
@@ -30,9 +29,8 @@ class TrustList extends TrustCommand {
3029
return TrustCommand.bodyToOptions(body)
3130
}
3231

33-
async exec (args) {
34-
const { content } = await pkgJson.normalize(this.npm.prefix)
35-
const packageName = args[0] || content.name
32+
async exec (positionalArgs) {
33+
const packageName = positionalArgs[0] || (await this.optionalPkgJson()).name
3634
if (!packageName) {
3735
throw new Error('Package name must be specified either as an argument or in the package.json file')
3836
}

lib/commands/trust/revoke.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const globalDefinitions = require('@npmcli/config/lib/definitions/definitions.js')
22
const Definition = require('@npmcli/config/lib/definitions/definition.js')
3-
const pkgJson = require('@npmcli/package-json')
43
const { otplease } = require('../../utils/auth.js')
54
const npmFetch = require('npm-registry-fetch')
65
const npa = require('npm-package-arg')
@@ -27,8 +26,7 @@ class TrustRevoke extends TrustCommand {
2726

2827
async exec (positionalArgs, flags) {
2928
const dryRun = this.config.get('dry-run')
30-
const { content } = await pkgJson.normalize(this.npm.prefix)
31-
const pkgName = positionalArgs[0] || content.name
29+
const pkgName = positionalArgs[0] || (await this.optionalPkgJson()).name
3230
if (!pkgName) {
3331
throw new Error('Package name must be specified either as an argument or in the package.json file')
3432
}

test/lib/commands/trust/list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ t.test('list without package name and no package.json', async t => {
122122

123123
await t.rejects(
124124
npm.exec('trust', ['list']),
125-
{ message: /Could not read package\.json/ }
125+
{ message: /Package name must be specified either as an argument or in the package\.json file/ }
126126
)
127127
})
128128

test/lib/commands/trust/revoke.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ t.test('revoke without package name and no package.json', async t => {
8484

8585
await t.rejects(
8686
npm.exec('trust', ['revoke', '--id', 'test-id']),
87-
{ message: /Could not read package\.json/ }
87+
{ message: /Package name must be specified either as an argument or in the package\.json file/ }
8888
)
8989
})
9090

0 commit comments

Comments
 (0)