/** @babel */
/** @jsx etch.dom */
import {BufferedProcess} from 'atom'
import etch from 'etch'
import VIEW_URI from './view-uri'
const REBUILDING = 'rebuilding'
const REBUILD_FAILED = 'rebuild-failed'
const REBUILD_SUCCEEDED = 'rebuild-succeeded'
export default class IncompatiblePackagesComponent {
constructor (packageManager) {
this.rebuildStatuses = new Map
this.rebuildFailureOutputs = new Map
this.rebuildInProgress = false
this.rebuiltPackageCount = 0
this.packageManager = packageManager
this.loaded = false
etch.initialize(this)
if (this.packageManager.getActivePackages().length > 0) {
this.populateIncompatiblePackages()
} else {
global.setImmediate(this.populateIncompatiblePackages.bind(this))
}
this.element.addEventListener('click', (event) => {
if (event.target === this.refs.rebuildButton) {
this.rebuildIncompatiblePackages()
} else if (event.target === this.refs.reloadButton) {
atom.reload()
} else if (event.target.classList.contains('view-settings')) {
atom.workspace.open(`atom://config/packages/${event.target.package.name}`)
}
})
}
update () {}
render () {
if (!this.loaded) {
return
Loading...
}
return (
{this.renderHeading()}
{this.renderIncompatiblePackageList()}
)
}
renderHeading () {
if (this.incompatiblePackages.length > 0) {
if (this.rebuiltPackageCount > 0) {
let alertClass =
(this.rebuiltPackageCount === this.incompatiblePackages.length)
? 'alert-success icon-check'
: 'alert-warning icon-bug'
return (
{this.rebuiltPackageCount} of {this.incompatiblePackages.length} packages
were rebuilt successfully. Reload Atom to activate them.
)
} else {
return (
Some installed packages could not be loaded because they contain native
modules that were compiled for an earlier version of Atom.
)
}
} else {
return (
None of your packages contain incompatible native modules.
)
}
}
renderIncompatiblePackageList () {
return (
{
this.incompatiblePackages.map(this.renderIncompatiblePackage.bind(this))
}
)
}
renderIncompatiblePackage (pack) {
let rebuildStatus = this.rebuildStatuses.get(pack)
return (
{this.renderRebuildStatusIndicator(rebuildStatus)}
{pack.name} {pack.metadata.version}
{
rebuildStatus
? this.renderRebuildOutput(pack)
: this.renderIncompatibleModules(pack)
}
)
}
renderRebuildStatusIndicator (rebuildStatus) {
if (rebuildStatus === REBUILDING) {
return (
Rebuilding
)
} else if (rebuildStatus === REBUILD_SUCCEEDED) {
return (
Rebuild Succeeded
)
} else if (rebuildStatus === REBUILD_FAILED) {
return (
Rebuild Failed
)
} else {
return ''
}
}
renderRebuildOutput (pack) {
if (this.rebuildStatuses.get(pack) === REBUILD_FAILED) {
return {this.rebuildFailureOutputs.get(pack)}
} else {
return ''
}
}
renderIncompatibleModules (pack) {
return (
)
}
populateIncompatiblePackages () {
this.incompatiblePackages =
this.packageManager
.getLoadedPackages()
.filter(pack => !pack.isCompatible())
for (let pack of this.incompatiblePackages) {
let buildFailureOutput = pack.getBuildFailureOutput()
if (buildFailureOutput) {
this.setPackageStatus(pack, REBUILD_FAILED)
this.setRebuildFailureOutput(pack, buildFailureOutput)
}
}
this.loaded = true
etch.update(this)
}
async rebuildIncompatiblePackages () {
this.rebuildInProgress = true
let rebuiltPackageCount = 0
for (let pack of this.incompatiblePackages) {
this.setPackageStatus(pack, REBUILDING)
let {code, stderr} = await pack.rebuild()
if (code === 0) {
this.setPackageStatus(pack, REBUILD_SUCCEEDED)
rebuiltPackageCount++
} else {
this.setRebuildFailureOutput(pack, stderr)
this.setPackageStatus(pack, REBUILD_FAILED)
}
}
this.rebuildInProgress = false
this.rebuiltPackageCount = rebuiltPackageCount
etch.update(this)
}
setPackageStatus (pack, status) {
this.rebuildStatuses.set(pack, status)
etch.update(this)
}
setRebuildFailureOutput (pack, output) {
this.rebuildFailureOutputs.set(pack, output)
etch.update(this)
}
getTitle () {
return 'Incompatible Packages'
}
getURI () {
return VIEW_URI
}
getIconName () {
return 'package'
}
serialize () {
return {deserializer: 'IncompatiblePackagesComponent'}
}
}