@@ -17,11 +17,11 @@ function manifest_includes_rls(manifest) {
1717 * @param {string } [channel] Defaults to `nightly`
1818 * @returns {Promise<string> } Toolchain name
1919 */
20- async function checkDatedDistHasRls ( date , channel = "nightly" ) {
20+ function checkDatedDistHasRls ( date , channel = "nightly" ) {
2121 const dateString = _ . isString ( date ) ? date : date . toISOString ( ) . split ( "T" ) [ 0 ]
2222 const cacheKey = `${ channel } -${ dateString } `
2323
24- let fetch =
24+ const fetch =
2525 datedNightlyHasRlsCache . get ( cacheKey ) ||
2626 new Promise ( ( resolve , reject ) => {
2727 https
@@ -33,7 +33,9 @@ async function checkDatedDistHasRls(date, channel = "nightly") {
3333 let body = ""
3434 res . on ( "data" , ( data ) => {
3535 body += data
36- if ( manifest_includes_rls ( body ) ) resolve ( cacheKey )
36+ if ( manifest_includes_rls ( body ) ) {
37+ resolve ( cacheKey )
38+ }
3739 } )
3840 res . on ( "end" , ( ) => reject ( new Error ( "no 'rls-preview'" ) ) )
3941 } )
@@ -54,17 +56,22 @@ async function checkDatedDistHasRls(date, channel = "nightly") {
5456 * @param {string } [channel] Defaults to `nightly`
5557 * @returns {Promise<string> } Latest channel dated version with rls-preview
5658 */
57- async function fetchLatestDatedDistWithRls ( channel ) {
59+ function fetchLatestDatedDistWithRls ( channel ) {
5860 const aDayMillis = 24 * 60 * 60 * 1000
5961 const minDate = new Date ( Date . now ( ) - 30 * aDayMillis )
6062
6163 const check = ( day ) => {
6264 return checkDatedDistHasRls ( day , channel ) . catch ( ( e ) => {
63- if ( e && e . code === "ENOTFOUND" ) throw e
65+ if ( e && e . code === "ENOTFOUND" ) {
66+ throw e
67+ }
6468
6569 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+ }
6875 } )
6976 }
7077
@@ -76,7 +83,7 @@ async function fetchLatestDatedDistWithRls(channel) {
7683 * @param {string } [arg.currentVersion] Current installed rustc version
7784 * @returns {Promise<?string> } New version of update available (falsy otherwise)
7885 */
79- async function fetchLatestDist ( { toolchain, currentVersion = "none" } ) {
86+ function fetchLatestDist ( { toolchain, currentVersion = "none" } ) {
8087 return new Promise ( ( resolve , reject ) => {
8188 https
8289 . get ( `https://static.rust-lang.org/dist/channel-rust-${ toolchain } .toml` , ( res ) => {
@@ -89,9 +96,11 @@ async function fetchLatestDist({ toolchain, currentVersion = "none" }) {
8996 res . on ( "data" , ( data ) => ( body += data ) )
9097 res . on ( "end" , ( ) => {
9198 // 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 ( )
95104 resolve (
96105 ! currentVersion . trim ( ) . endsWith ( rustcVersion ) && manifest_includes_rls ( body ) && `rustc ${ rustcVersion } `
97106 )
@@ -110,15 +119,15 @@ async function fetchLatestDist({ toolchain, currentVersion = "none" }) {
110119 * @param {string } toolchain
111120 * @returns {Promise<boolean> }
112121 */
113- async function checkHasRls ( toolchain ) {
114- let dated = toolchain . match ( DATED_REGEX )
122+ function checkHasRls ( toolchain ) {
123+ const dated = toolchain . match ( DATED_REGEX )
115124 if ( dated ) {
116125 return checkDatedDistHasRls ( dated [ 2 ] , dated [ 1 ] )
117126 . then ( ( ) => true )
118127 . catch ( ( ) => false )
119128 }
120129 return fetchLatestDist ( { toolchain } )
121- . then ( ( v ) => ! ! v )
130+ . then ( ( v ) => Boolean ( v ) )
122131 . catch ( ( ) => false )
123132}
124133
@@ -127,10 +136,12 @@ async function checkHasRls(toolchain) {
127136 * @returns {Promise<string> } Latest channel dated version with rls-preview or the channel itself if ok
128137 */
129138async function suggestChannelOrDated ( channel ) {
130- let latestDatedPromise = fetchLatestDatedDistWithRls ( channel )
139+ const latestDatedPromise = fetchLatestDatedDistWithRls ( channel )
131140 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+ }
134145 } catch ( e ) {
135146 console . warn ( e )
136147 }
0 commit comments