Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Object.values(this.tool.getRegisteredPlugins()).forEach(type => {
const { contract, singularName, pluralName } = type!;
this.debug('Generating %s blueprint', color.pluginName(singularName));
// prettier-ignore
pluginsBlueprint[pluralName] = array(union>([
string().notEmpty(),
shape({ [singularName]: string().notEmpty() }),
instance(contract, true),
], []));
});
createResolver(name: ModuleName): PathResolver {
const resolver = new PathResolver();
const { singularName: typeName, projectName } = this.manager;
const moduleName = name.toLowerCase();
const modulePattern = MODULE_PART_PATTERN.source;
const isNotToolOrType = !moduleName.includes(projectName) && !moduleName.includes(typeName);
this.debug('Resolving possible %s modules', color.pluginName(typeName));
// @scope/tool-plugin-name
if (
moduleName.match(
new RegExp(`^@${modulePattern}/${projectName}-${typeName}-${modulePattern}$`, 'u'),
)
) {
this.debug('Found an explicit module with custom scope: %s', color.moduleName(moduleName));
resolver.lookupNodeModule(moduleName);
// @tool/plugin-name
} else if (
moduleName.match(new RegExp(`^@${projectName}/${typeName}-${modulePattern}$`, 'u'))
) {
this.debug('Found an explicit internal module with scope: %s', color.moduleName(moduleName));
registerPlugin(
typeName: K,
contract: AbstractConstructor,
options: Partial<
Pick, 'afterBootstrap' | 'beforeBootstrap' | 'scopes'>
> = {},
): this {
if (this.pluginTypes[typeName]) {
throw new Error(this.msg('errors:pluginContractExists', { typeName }));
}
const name = String(typeName);
const { afterBootstrap = null, beforeBootstrap = null, scopes = [] } = options;
this.debug('Registering new plugin type: %s', color.pluginName(name));
this.plugins[typeName] = new Set();
this.pluginTypes[typeName] = {
afterBootstrap,
beforeBootstrap,
contract,
loader: new ModuleLoader(this, name, contract, scopes),
pluralName: pluralize(name),
scopes,
singularName: name,
};
return this;
}
registerType(
typeName: K,
options: Pick, 'afterBootstrap' | 'beforeBootstrap' | 'validate'>,
): this {
if (this.types[typeName]) {
throw new RuntimeError('plugin', 'PG_EXISTS_TYPE', [typeName]);
}
const name = String(typeName);
const { afterBootstrap, beforeBootstrap, validate } = options;
this.debug('Registering new plugin type: %s', color.pluginName(name));
this.plugins[typeName] = [];
this.types[typeName] = {
afterBootstrap,
beforeBootstrap,
pluralName: pluralize(name),
singularName: name,
validate,
};
return this;
}
constructor(projectName: string, typeName: string, options: ManagerOptions) {
super(options);
this.projectName = kebabCase(projectName);
this.singularName = kebabCase(typeName);
this.pluralName = pluralize(this.singularName);
this.debug = createDebugger([this.singularName, 'manager']);
this.loader = new Loader(this);
this.debug('Creating new plugin type: %s', color.pluginName(typeName));
}