@jupyterlab/coreutils
Version:
JupyterLab - Core Utilities
60 lines • 2.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.JupyterPluginRegistry = void 0;
const coreutils_1 = require("@lumino/coreutils");
const PLUGIN_ACTIVATION_TIMEOUT = 5000;
class JupyterPluginRegistry extends coreutils_1.PluginRegistry {
constructor(options) {
var _a;
super(options);
this._pluginData = new Map();
this._expectedActivationTime =
(_a = options === null || options === void 0 ? void 0 : options.expectedActivationTime) !== null && _a !== void 0 ? _a : PLUGIN_ACTIVATION_TIMEOUT;
}
registerPlugin(plugin) {
this._pluginData.set(plugin.id, plugin);
return super.registerPlugin(plugin);
}
async activatePlugin(id) {
const startTime = performance.now();
// Set a timeout to detect if the plugin stalls
let timeoutId = setTimeout(() => {
console.warn(`Plugin ${id} is taking too long to activate.`);
}, this._expectedActivationTime);
try {
const result = await super.activatePlugin(id);
clearTimeout(timeoutId);
const endTime = performance.now();
const activationTime = endTime - startTime;
if (activationTime >= this._expectedActivationTime) {
const dependantCount = this._getDependentCount(id);
console.warn(`Plugin ${id} (with ${dependantCount} dependants) took ${activationTime.toFixed(2)}ms to activate.`);
}
return result;
}
catch (error) {
clearTimeout(timeoutId);
console.error(`Error activating plugin: ${id}`, error);
throw error;
}
}
_getDependentCount(id) {
var _a;
const plugin = this._pluginData.get(id);
if (!(plugin === null || plugin === void 0 ? void 0 : plugin.provides))
return 0;
const tokenName = plugin.provides.name;
let dependentCount = 0;
for (const [otherId, otherPlugin] of this._pluginData.entries()) {
if (otherId === id)
continue;
const isDependant = (_a = otherPlugin.requires) === null || _a === void 0 ? void 0 : _a.filter((token) => !!token).some((token) => token.name === tokenName);
if (isDependant) {
dependentCount++;
}
}
return dependentCount;
}
}
exports.JupyterPluginRegistry = JupyterPluginRegistry;
//# sourceMappingURL=pluginregistry.js.map