Skip to content

Commit d2f4a52

Browse files
committed
Fix some dependency resolving logic that incorrectly disabled plugins.
1 parent b4c5780 commit d2f4a52

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

src/ace.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ export default class Ace {
7474

7575
this.resolvePluginDependencies();
7676
this.initializePlugins().then(() => {
77-
const initializedCount = this.plugins.filter(x => x.state === PluginState.ENABLED).length;
78-
if (initializedCount !== this.plugins.length) {
79-
this.addNotification("warning", "Ace Warning", `${this.plugins.length - initializedCount} plugin(s) were not loaded because of version mismatches or other errors during initialization.`);
77+
const activePlugins = this.plugins.filter(x => x.state !== PluginState.DISABLED);
78+
const initializedCount = activePlugins.filter(x => x.state === PluginState.ENABLED).length;
79+
if (initializedCount !== activePlugins.length) {
80+
this.addNotification("warning", "Ace Warning", `${activePlugins.length - initializedCount} plugin(s) were not loaded because of version mismatches or other errors during initialization.`);
8081
}
8182
});
8283
}).catch(e => {
@@ -334,10 +335,9 @@ export default class Ace {
334335
}));
335336

336337
try {
337-
this.initializationOrder = toposort(dependencies)
338-
.reverse()
339-
// Add plugins that don't depend on anything/get depended upon, since they were not in the topological sort.
340-
.concat(this.plugins.filter(x => x.state === PluginState.LOADED && x.dependents.length === 0 && x.dependencies.length === 0).map(x => x.name));
338+
this.initializationOrder = toposort(dependencies).reverse();
339+
this.initializationOrder =
340+
this.initializationOrder.concat(this.plugins.filter(x => x.state === PluginState.LOADED && this.initializationOrder.indexOf(x.name) === -1).map(x => x.name));
341341
} catch (e) {
342342
// Cyclic dependency, disable anything that depends on something else since we can't easily figure out the loop.
343343
this.plugins.filter(x => x.state === PluginState.LOADED && (x.dependents.length !== 0 || x.dependencies.length !== 0)).forEach(p => {
@@ -360,18 +360,20 @@ export default class Ace {
360360
let promiseChain = Promise.resolve();
361361

362362
this.initializationOrder.map(x => this.getPluginWithName(x)!).forEach(plugin => {
363-
if (plugin.state !== PluginState.LOADED) return;
364-
365363
promiseChain = promiseChain.then(() => {
366-
return plugin.setup();
367-
}).catch(e => {
368-
// Log error to console.
369-
console.error(e);
370-
371-
// Disable plugins that depend on this one.
372-
plugin.state = PluginState.ERRORED;
373-
374-
this.addNotification("warning", "Ace Warning", `Error during initialization of '${plugin}': ${e}.`);
364+
if (plugin.state !== PluginState.LOADED) return;
365+
366+
try {
367+
return plugin.setup();
368+
} catch (e) {
369+
// Log error to console.
370+
console.error(e);
371+
372+
// Disable plugins that depend on this one.
373+
plugin.state = PluginState.ERRORED;
374+
375+
this.addNotification("warning", "Ace Warning", `Error during initialization of '${plugin}': ${e}.`);
376+
}
375377
});
376378
});
377379

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import Ace from "./ace";
55
/**
66
* Version metadata. This is both shown in the about screen and used as a version check.
77
*/
8-
window["ACE_VERSION"] = "1.0.0";
8+
window["ACE_VERSION"] = "1.0.1";
99

1010
(<any>window).Ace = new Ace();

0 commit comments

Comments
 (0)