File tree 8 files changed +63
-3
lines changed
8 files changed +63
-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 @@ -61,6 +61,8 @@ export abstract class Provider {
61
61
this . logger = logger ;
62
62
}
63
63
64
+ abstract hasRequiredPermissions ( ) : Promise < boolean > ;
65
+
64
66
abstract getVersions ( name : string ) : Promise < Versions > ;
65
67
66
68
abstract getRepositoryUrl ( name : string , version ?: 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, main, logger } : DenoLandProviderOptions = { } ) {
14
15
super ( { main, logger } ) ;
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 @@ -30,6 +30,15 @@ export class GithubProvider extends Provider {
30
30
this . githubToken = token ;
31
31
}
32
32
33
+ async hasRequiredPermissions ( ) : Promise < boolean > {
34
+ const apiUrl = new URL ( this . apiUrl ) ;
35
+ const permissionStatus = await Deno . permissions . query ( {
36
+ name : "net" ,
37
+ host : apiUrl . host ,
38
+ } ) ;
39
+ return permissionStatus . state === "granted" ;
40
+ }
41
+
33
42
async getVersions (
34
43
_name : string ,
35
44
) : Promise < GithubVersions > {
Original file line number Diff line number Diff line change @@ -40,6 +40,15 @@ export class JsrProvider extends Provider {
40
40
: options . name ;
41
41
}
42
42
43
+ async hasRequiredPermissions ( ) : Promise < boolean > {
44
+ const apiUrl = new URL ( this . repositoryUrl ) ;
45
+ const permissionStatus = await Deno . permissions . query ( {
46
+ name : "net" ,
47
+ host : apiUrl . host ,
48
+ } ) ;
49
+ return permissionStatus . state === "granted" ;
50
+ }
51
+
43
52
async getVersions (
44
53
name : string ,
45
54
) : Promise < Versions > {
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, main, logger } : NestLandProviderOptions = { } ) {
14
15
super ( { main, logger } ) ;
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 @@ -31,6 +31,15 @@ export class NpmProvider extends Provider {
31
31
}
32
32
}
33
33
34
+ async hasRequiredPermissions ( ) : Promise < boolean > {
35
+ const apiUrl = new URL ( this . apiUrl ) ;
36
+ const permissionStatus = await Deno . permissions . query ( {
37
+ name : "net" ,
38
+ host : apiUrl . host ,
39
+ } ) ;
40
+ return permissionStatus . state === "granted" ;
41
+ }
42
+
34
43
async getVersions (
35
44
name : string ,
36
45
) : Promise < Versions > {
Original file line number Diff line number Diff line change @@ -169,6 +169,10 @@ export class UpgradeCommand extends Command {
169
169
return versions ;
170
170
}
171
171
172
+ public async hasRequiredPermissions ( ) : Promise < boolean > {
173
+ return await this . getProvider ( ) . hasRequiredPermissions ( ) ;
174
+ }
175
+
172
176
public async getLatestVersion ( ) : Promise < string > {
173
177
const { latest } = await this . getVersions ( ) ;
174
178
return latest ;
You can’t perform that action at this time.
0 commit comments