Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
shape({ [singularName]: string().notEmpty() }),
instance(contract, true),
], []));
});
const config = optimal(
this.inheritFromArgs(this.parseAndExtend(configPath), args),
{
...configBlueprint,
...pluginsBlueprint,
debug: bool(),
extends: array(string()),
locale: string(),
output: number(2).between(1, 3, true),
// shape() requires a non-empty object
settings: isEmpty(settingsBlueprint) ? object() : shape(settingsBlueprint),
silent: bool(),
theme: string('default').notEmpty(),
},
{
file: configPath instanceof Path ? configPath.name() : '',
name: 'ConfigLoader',
unknown: true,
},
);
return (config as unknown) as T;
}
protected loadPlugins(): this {
if (this.initialized) {
return this;
}
if (isEmpty(this.config)) {
throw new Error(this.msg('errors:configNotLoaded', { name: 'plugins' }));
}
Object.keys(this.pluginTypes).forEach(type => {
const typeName = type as keyof PluginRegistry;
const { loader, pluralName } = this.pluginTypes[typeName]!;
const plugins = loader.loadModules((this.config as any)[pluralName]);
// Sort plugins by priority
loader.debug('Sorting by priority');
plugins.sort((a, b) =>
instanceOf(a, Plugin) && instanceOf(b, Plugin) ? a.priority - b.priority : 0,
);
// Bootstrap each plugin with the tool
protected loadReporters(): this {
if (this.initialized) {
return this;
}
if (isEmpty(this.config)) {
throw new Error(this.msg('errors:configNotLoaded', { name: 'reporters' }));
}
const reporters = this.plugins.reporter!;
const { loader } = this.pluginTypes.reporter!;
// Use a special reporter when in a CI
// istanbul ignore next
if (this.isCI() && !env('ENV')) {
loader.debug('CI environment detected, using %s CI reporter', color.moduleName('boost'));
this.addPlugin('reporter', new CIReporter());
// Use default reporter
} else if (
reporters.size === 0 ||
loadConfig(args: Arguments): T {
if (isEmpty(this.package) || !this.package.name) {
throw new Error(this.tool.msg('errors:packageJsonNotLoaded'));
}
this.debug('Locating configuration');
const { configBlueprint, settingsBlueprint, root } = this.tool.options;
const pluginsBlueprint: any = {};
const configPath =
this.findConfigFromArg(args.config) ||
this.findConfigInPackageJSON(this.package) ||
this.findConfigInLocalFiles(root) ||
this.findConfigInWorkspaceRoot(root);
if (!configPath) {
throw new Error(this.tool.msg('errors:configNotFound'));
}