@ -1,12 +1,11 @@
const yo = require ( 'yo-yo' )
const yo = require ( 'yo-yo' )
const minixhr = require ( 'minixhr' )
const helper = require ( '../../../lib/helper' )
const helper = require ( '../../../lib/helper' )
const addTooltip = require ( '../../ui/tooltip' )
const addTooltip = require ( '../../ui/tooltip' )
const semver = require ( 'semver' )
const semver = require ( 'semver' )
const modalDialogCustom = require ( '../../ui/modal-dialog-custom' )
const modalDialogCustom = require ( '../../ui/modal-dialog-custom' )
const css = require ( '../styles/compile-tab-styles' )
const css = require ( '../styles/compile-tab-styles' )
import { canUseWorker , baseURLBin , baseURLWasm , urlFromVersion , pathToURL } from '../../compiler/compiler-utils'
import { canUseWorker , baseURLBin , baseURLWasm , urlFromVersion , pathToURL , promisedMiniXhr } from '../../compiler/compiler-utils'
class CompilerContainer {
class CompilerContainer {
@ -414,61 +413,42 @@ class CompilerContainer {
if ( this . _view . version ) this . _view . version . innerText = text
if ( this . _view . version ) this . _view . version . innerText = text
}
}
// fetching both normal and wasm builds and creating an array [version, baseUrl]
// fetching both normal and wasm builds and creating a [version, baseUrl] map
fetchAllVersion ( callback ) {
async fetchAllVersion ( callback ) {
let allVersions , selectedVersion , allVersionsWasm , urls
let allVersions , selectedVersion , allVersionsWasm
// fetch normal builds
// fetch normal builds
minixhr ( ` ${ this . data . baseURLBin } /list.json ` , ( json , event ) => {
const binRes = await promisedMiniXhr ( ` ${ this . data . baseURLBin } /list.json ` )
// @TODO: optimise and cache results to improve app loading times #2461
// fetch wasm builds
if ( event . type !== 'error' ) {
const wasmRes = await promisedMiniXhr ( ` ${ this . data . baseURLWasm } /list.json ` )
try {
if ( binRes . event . type === 'error' && wasmRes . event . type === 'error' ) {
const data = JSON . parse ( json )
allVersions = [ { path : 'builtin' , longVersion : 'latest local version' } ]
allVersions = data . builds . slice ( ) . reverse ( )
selectedVersion = 'builtin'
selectedVersion = this . data . defaultVersion
callback ( allVersions , selectedVersion )
if ( this . queryParams . get ( ) . version ) selectedVersion = this . queryParams . get ( ) . version
}
// no fetching wasm builds
try {
minixhr ( ` ${ this . data . baseURLWasm } /list.json ` , ( json , event ) => {
allVersions = JSON . parse ( binRes . json ) . builds . slice ( ) . reverse ( )
// @TODO: optimise and cache results to improve app loading times #2461
selectedVersion = this . data . defaultVersion
if ( event . type !== 'error' ) {
if ( this . queryParams . get ( ) . version ) selectedVersion = this . queryParams . get ( ) . version
try {
if ( wasmRes . event . type !== 'error' ) {
const data = JSON . parse ( json )
allVersionsWasm = JSON . parse ( wasmRes . json ) . builds . slice ( ) . reverse ( )
allVersionsWasm = data . builds . slice ( ) . reverse ( )
//selectedVersion = this.data.defaultVersion
if ( this . queryParams . get ( ) . version ) selectedVersion = this . queryParams . get ( ) . version
// rewriting all versions in allVersions which exist in allVersionsWasm
if ( allVersionsWasm && allVersions )
allVersions . forEach ( ( compiler , index ) => {
const rewritten = allVersionsWasm . findIndex ( oldCompiler => { return oldCompiler . longVersion === compiler . longVersion } )
if ( - 1 !== rewritten ) {
allVersions [ index ] = allVersionsWasm [ rewritten ]
pathToURL [ compiler . path ] = baseURLWasm
} else {
pathToURL [ compiler . path ] = baseURLBin
}
} )
callback ( allVersions , selectedVersion )
} catch ( e ) {
addTooltip ( 'Cannot load compiler version list. It might have been blocked by an advertisement blocker. Please try deactivating any of them from this page and reload.' )
}
} else {
allVersionsWasm = [ { path : 'builtin' , longVersion : 'latest local version' } ]
selectedVersion = 'builtin'
}
//callback(allVersions, selectedVersion)
} )
} catch ( e ) {
addTooltip ( 'Cannot load compiler version list. It might have been blocked by an advertisement blocker. Please try deactivating any of them from this page and reload.' )
}
} else {
allVersions = [ { path : 'builtin' , longVersion : 'latest local version' } ]
selectedVersion = 'builtin'
}
}
//callback(allVersions, selectedVersion)
} catch ( e ) {
} )
addTooltip ( 'Cannot load compiler version list. It might have been blocked by an advertisement blocker. Please try deactivating any of them from this page and reload. Error: ' + e )
}
// replace in allVersions those compiler builds which exist in allVersionsWasm with new once
if ( allVersionsWasm && allVersions ) {
allVersions . forEach ( ( compiler , index ) => {
const wasmIndex = allVersionsWasm . findIndex ( wasmCompiler => { return wasmCompiler . longVersion === compiler . longVersion } )
if ( wasmIndex !== - 1 ) {
allVersions [ index ] = allVersionsWasm [ wasmIndex ]
pathToURL [ compiler . path ] = baseURLWasm
} else {
pathToURL [ compiler . path ] = baseURLBin
}
} )
}
callback ( allVersions , selectedVersion )
}
}
scheduleCompilation ( ) {
scheduleCompilation ( ) {
if ( ! this . config . get ( 'autoCompile' ) ) return
if ( ! this . config . get ( 'autoCompile' ) ) return
if ( this . data . compileTimeout ) window . clearTimeout ( this . data . compileTimeout )
if ( this . data . compileTimeout ) window . clearTimeout ( this . data . compileTimeout )