@@ -17,11 +17,11 @@ function manifest_includes_rls(manifest) {
17
17
* @param {string } [channel] Defaults to `nightly`
18
18
* @returns {Promise<string> } Toolchain name
19
19
*/
20
- async function checkDatedDistHasRls ( date , channel = "nightly" ) {
20
+ function checkDatedDistHasRls ( date , channel = "nightly" ) {
21
21
const dateString = _ . isString ( date ) ? date : date . toISOString ( ) . split ( "T" ) [ 0 ]
22
22
const cacheKey = `${ channel } -${ dateString } `
23
23
24
- let fetch =
24
+ const fetch =
25
25
datedNightlyHasRlsCache . get ( cacheKey ) ||
26
26
new Promise ( ( resolve , reject ) => {
27
27
https
@@ -33,7 +33,9 @@ async function checkDatedDistHasRls(date, channel = "nightly") {
33
33
let body = ""
34
34
res . on ( "data" , ( data ) => {
35
35
body += data
36
- if ( manifest_includes_rls ( body ) ) resolve ( cacheKey )
36
+ if ( manifest_includes_rls ( body ) ) {
37
+ resolve ( cacheKey )
38
+ }
37
39
} )
38
40
res . on ( "end" , ( ) => reject ( new Error ( "no 'rls-preview'" ) ) )
39
41
} )
@@ -54,17 +56,22 @@ async function checkDatedDistHasRls(date, channel = "nightly") {
54
56
* @param {string } [channel] Defaults to `nightly`
55
57
* @returns {Promise<string> } Latest channel dated version with rls-preview
56
58
*/
57
- async function fetchLatestDatedDistWithRls ( channel ) {
59
+ function fetchLatestDatedDistWithRls ( channel ) {
58
60
const aDayMillis = 24 * 60 * 60 * 1000
59
61
const minDate = new Date ( Date . now ( ) - 30 * aDayMillis )
60
62
61
63
const check = ( day ) => {
62
64
return checkDatedDistHasRls ( day , channel ) . catch ( ( e ) => {
63
- if ( e && e . code === "ENOTFOUND" ) throw e
65
+ if ( e && e . code === "ENOTFOUND" ) {
66
+ throw e
67
+ }
64
68
65
69
const yesterday = new Date ( day - aDayMillis )
66
- if ( yesterday >= minDate ) return check ( yesterday )
67
- else throw new Error ( "No nightly with 'rls-preview'" )
70
+ if ( yesterday >= minDate ) {
71
+ return check ( yesterday )
72
+ } else {
73
+ throw new Error ( "No nightly with 'rls-preview'" )
74
+ }
68
75
} )
69
76
}
70
77
@@ -76,7 +83,7 @@ async function fetchLatestDatedDistWithRls(channel) {
76
83
* @param {string } [arg.currentVersion] Current installed rustc version
77
84
* @returns {Promise<?string> } New version of update available (falsy otherwise)
78
85
*/
79
- async function fetchLatestDist ( { toolchain, currentVersion = "none" } ) {
86
+ function fetchLatestDist ( { toolchain, currentVersion = "none" } ) {
80
87
return new Promise ( ( resolve , reject ) => {
81
88
https
82
89
. get ( `https://static.rust-lang.org/dist/channel-rust-${ toolchain } .toml` , ( res ) => {
@@ -89,9 +96,11 @@ async function fetchLatestDist({ toolchain, currentVersion = "none" }) {
89
96
res . on ( "data" , ( data ) => ( body += data ) )
90
97
res . on ( "end" , ( ) => {
91
98
// use a subsection as toml is slow to parse fully
92
- let rustcInfo = body . match ( / ( \[ p k g \. r u s t c \] [ ^ [ ] * ) / m)
93
- if ( ! rustcInfo ) return reject ( new Error ( "could not split channel toml output" ) )
94
- let rustcVersion = require ( "toml" ) . parse ( rustcInfo [ 1 ] ) . pkg . rustc . version . trim ( )
99
+ const rustcInfo = body . match ( / ( \[ p k g \. r u s t c ] [ ^ [ ] * ) / m)
100
+ if ( ! rustcInfo ) {
101
+ return reject ( new Error ( "could not split channel toml output" ) )
102
+ }
103
+ const rustcVersion = require ( "toml" ) . parse ( rustcInfo [ 1 ] ) . pkg . rustc . version . trim ( )
95
104
resolve (
96
105
! currentVersion . trim ( ) . endsWith ( rustcVersion ) && manifest_includes_rls ( body ) && `rustc ${ rustcVersion } `
97
106
)
@@ -110,15 +119,15 @@ async function fetchLatestDist({ toolchain, currentVersion = "none" }) {
110
119
* @param {string } toolchain
111
120
* @returns {Promise<boolean> }
112
121
*/
113
- async function checkHasRls ( toolchain ) {
114
- let dated = toolchain . match ( DATED_REGEX )
122
+ function checkHasRls ( toolchain ) {
123
+ const dated = toolchain . match ( DATED_REGEX )
115
124
if ( dated ) {
116
125
return checkDatedDistHasRls ( dated [ 2 ] , dated [ 1 ] )
117
126
. then ( ( ) => true )
118
127
. catch ( ( ) => false )
119
128
}
120
129
return fetchLatestDist ( { toolchain } )
121
- . then ( ( v ) => ! ! v )
130
+ . then ( ( v ) => Boolean ( v ) )
122
131
. catch ( ( ) => false )
123
132
}
124
133
@@ -127,10 +136,12 @@ async function checkHasRls(toolchain) {
127
136
* @returns {Promise<string> } Latest channel dated version with rls-preview or the channel itself if ok
128
137
*/
129
138
async function suggestChannelOrDated ( channel ) {
130
- let latestDatedPromise = fetchLatestDatedDistWithRls ( channel )
139
+ const latestDatedPromise = fetchLatestDatedDistWithRls ( channel )
131
140
try {
132
- let latestIsOk = await fetchLatestDist ( { toolchain : channel } )
133
- if ( latestIsOk ) return channel
141
+ const latestIsOk = await fetchLatestDist ( { toolchain : channel } )
142
+ if ( latestIsOk ) {
143
+ return channel
144
+ }
134
145
} catch ( e ) {
135
146
console . warn ( e )
136
147
}
0 commit comments