Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!importedModule || !moduleName) {
throw new Error(
this.tool.msg('errors:moduleImportFailed', {
modules: modulesToAttempt.join(', '),
typeName,
}),
);
}
if (!this.contract) {
return importedModule;
}
// An instance was returned instead of the class definition
if (instanceOf(importedModule, this.contract)) {
throw new TypeError(
this.tool.msg('errors:moduleClassInstanceExported', {
appName,
moduleName,
typeName,
}),
);
} else if (typeof importedModule !== 'function') {
throw new TypeError(this.tool.msg('errors:moduleClassDefRequired', { moduleName, typeName }));
}
const ModuleClass = importedModule as ConcreteConstructor;
const module = new ModuleClass(...args);
if (!instanceOf(module, this.contract)) {
throw new TypeError(
addPlugin(typeName: K, plugin: PluginRegistry[K]): this {
const type = this.getRegisteredPlugin(typeName);
if (!instanceOf(plugin, Plugin)) {
throw new TypeError(this.msg('errors:pluginNotExtended', { parent: 'Plugin', typeName }));
} else if (!instanceOf(plugin, type.contract)) {
throw new TypeError(
this.msg('errors:pluginNotExtended', { parent: type.contract.name, typeName }),
);
}
plugin.tool = this;
if (type.beforeBootstrap) {
type.beforeBootstrap(plugin);
}
plugin.bootstrap();
if (type.afterBootstrap) {
addPlugin(typeName: K, plugin: PluginRegistry[K]): this {
const type = this.getRegisteredPlugin(typeName);
if (!instanceOf(plugin, Plugin)) {
throw new TypeError(this.msg('errors:pluginNotExtended', { parent: 'Plugin', typeName }));
} else if (!instanceOf(plugin, type.contract)) {
throw new TypeError(
this.msg('errors:pluginNotExtended', { parent: type.contract.name, typeName }),
);
}
plugin.tool = this;
if (type.beforeBootstrap) {
type.beforeBootstrap(plugin);
}
plugin.bootstrap();
if (type.afterBootstrap) {
type.afterBootstrap(plugin);
}
const plugin = this.getPlugins(typeName).find(p => instanceOf(p, Plugin) && p.name === name);
loadModule(module: string | OptionsObject | Tm, args: any[] = []): Tm {
if (this.contract && instanceOf(module, this.contract)) {
return module as Tm;
} else if (typeof module === 'string') {
return this.importModule(module, args);
} else if (isObject(module)) {
return this.importModuleFromOptions(module, args);
}
throw new TypeError(this.tool.msg('errors:moduleTypeInvalid', { typeName: this.typeName }));
}
getStepProgress(task: Task, type: 'routines' | 'tasks'): string {
if (!task.parent || !instanceOf(task.parent, Routine)) {
return '';
}
return `[${task.metadata.index + 1}/${task.parent![type].length}]`;
}