File tree 6 files changed +45
-3
lines changed
6 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,11 @@ export async function checkVersion(cmd: Command<any>): Promise<void> {
10
10
if ( ! isUpgradeCommand ( upgradeCommand ) ) {
11
11
return ;
12
12
}
13
+
14
+ if ( ! await upgradeCommand . hasRequiredPermissions ( ) ) {
15
+ // If not all required permissions were pre-granted, skip the version check to prevent prompting user
16
+ return ;
17
+ }
13
18
const latestVersion = await upgradeCommand . getLatestVersion ( ) ;
14
19
const currentVersion = mainCommand . getVersion ( ) ;
15
20
@@ -23,9 +28,11 @@ export async function checkVersion(cmd: Command<any>): Promise<void> {
23
28
}
24
29
25
30
function isUpgradeCommand ( command : unknown ) : command is UpgradeCommandImpl {
26
- return command instanceof Command && "getLatestVersion" in command ;
31
+ return command instanceof Command && "getLatestVersion" in command &&
32
+ "hasRequiredPermissions" in command ;
27
33
}
28
34
29
35
interface UpgradeCommandImpl {
36
+ hasRequiredPermissions ( ) : Promise < boolean > ;
30
37
getLatestVersion ( ) : Promise < string > ;
31
38
}
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ export abstract class Provider {
21
21
protected readonly maxListSize : number = 25 ;
22
22
private maxCols = 8 ;
23
23
24
+ abstract hasRequiredPermissions ( ) : Promise < boolean > ;
25
+
24
26
abstract getVersions ( name : string ) : Promise < Versions > ;
25
27
26
28
abstract getRepositoryUrl ( name : string ) : string ;
Original file line number Diff line number Diff line change @@ -8,18 +8,28 @@ export class DenoLandProvider extends Provider {
8
8
name = "deno.land" ;
9
9
private readonly repositoryUrl = "https://deno.land/x/" ;
10
10
private readonly registryUrl = "https://deno.land/x/" ;
11
+ private readonly apiUrl = "https://cdn.deno.land/" ;
11
12
private readonly moduleName ?: string ;
12
13
13
14
constructor ( { name } : DenoLandProviderOptions = { } ) {
14
15
super ( ) ;
15
16
this . moduleName = name ;
16
17
}
17
18
19
+ async hasRequiredPermissions ( ) : Promise < boolean > {
20
+ const apiUrl = new URL ( this . apiUrl ) ;
21
+ const permissionStatus = await Deno . permissions . query ( {
22
+ name : "net" ,
23
+ host : apiUrl . host ,
24
+ } ) ;
25
+ return permissionStatus . state === "granted" ;
26
+ }
27
+
18
28
async getVersions (
19
29
name : string ,
20
30
) : Promise < Versions > {
21
31
const response = await fetch (
22
- `https://cdn.deno.land/ ${ this . moduleName ?? name } /meta/versions.json` ,
32
+ `${ this . apiUrl } ${ this . moduleName ?? name } /meta/versions.json` ,
23
33
) ;
24
34
if ( ! response . ok ) {
25
35
throw new Error (
Original file line number Diff line number Diff line change @@ -28,6 +28,15 @@ export class GithubProvider extends Provider {
28
28
this . githubToken = token ;
29
29
}
30
30
31
+ async hasRequiredPermissions ( ) : Promise < boolean > {
32
+ const apiUrl = new URL ( this . apiUrl ) ;
33
+ const permissionStatus = await Deno . permissions . query ( {
34
+ name : "net" ,
35
+ host : apiUrl . host ,
36
+ } ) ;
37
+ return permissionStatus . state === "granted" ;
38
+ }
39
+
31
40
async getVersions (
32
41
_name : string ,
33
42
) : Promise < GithubVersions > {
Original file line number Diff line number Diff line change @@ -8,17 +8,27 @@ export class NestLandProvider extends Provider {
8
8
name = "nest.land" ;
9
9
private readonly repositoryUrl = "https://nest.land/package/" ;
10
10
private readonly registryUrl = "https://x.nest.land/" ;
11
+ private readonly apiUrl = "https://nest.land/api/" ;
11
12
private readonly moduleName ?: string ;
12
13
13
14
constructor ( { name } : NestLandProviderOptions = { } ) {
14
15
super ( ) ;
15
16
this . moduleName = name ;
16
17
}
17
18
19
+ async hasRequiredPermissions ( ) : Promise < boolean > {
20
+ const apiUrl = new URL ( this . apiUrl ) ;
21
+ const permissionStatus = await Deno . permissions . query ( {
22
+ name : "net" ,
23
+ host : apiUrl . host ,
24
+ } ) ;
25
+ return permissionStatus . state === "granted" ;
26
+ }
27
+
18
28
async getVersions (
19
29
name : string ,
20
30
) : Promise < Versions > {
21
- const response = await fetch ( `https://nest.land/api/ package-client` , {
31
+ const response = await fetch ( `${ this . apiUrl } package-client` , {
22
32
method : "post" ,
23
33
body : JSON . stringify ( { data : { name : this . moduleName ?? name } } ) ,
24
34
headers : { "Content-Type" : "application/json" } ,
Original file line number Diff line number Diff line change @@ -89,6 +89,10 @@ export class UpgradeCommand extends Command {
89
89
return versions ;
90
90
}
91
91
92
+ public async hasRequiredPermissions ( ) : Promise < boolean > {
93
+ return await this . getProvider ( ) . hasRequiredPermissions ( ) ;
94
+ }
95
+
92
96
public async getLatestVersion ( ) : Promise < string > {
93
97
const { latest } = await this . getVersions ( ) ;
94
98
return latest ;
You can’t perform that action at this time.
0 commit comments