Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// @scope/name
} else if (
moduleName.match(new RegExp(`^@${modulePattern}/${modulePattern}$`, 'u')) &&
isNotToolOrType
) {
const [scope, customName] = moduleName.split('/');
const customModuleName = `${scope}/${projectName}-${typeName}-${customName}`;
this.debug('Found a shorthand module with custom scope: %s', color.moduleName(moduleName));
resolver.lookupNodeModule(customModuleName);
// tool-plugin-name
} else if (moduleName.match(new RegExp(`^${projectName}-${typeName}-${modulePattern}$`, 'u'))) {
this.debug('Found an explicit public module: %s', color.moduleName(moduleName));
resolver.lookupNodeModule(moduleName);
// The previous 2 patterns if only name provided
} else if (moduleName.match(new RegExp(`^${modulePattern}$`, 'u')) && isNotToolOrType) {
this.debug(
'Resolving modules with internal "%s" scope and public "%s" prefix',
color.toolName(`@${projectName}`),
color.toolName(projectName),
);
// Detect internal scopes before public ones
resolver.lookupNodeModule(this.manager.formatModuleName(moduleName, true));
resolver.lookupNodeModule(this.manager.formatModuleName(moduleName));
// Unknown plugin module pattern
// Determine modules to attempt to load
const modulesToAttempt = [];
let isFilePath = false;
let importedModule: any = null;
let moduleName;
// File path
if (name instanceof Path || name.match(/^\.|\/|\\|[A-Z]:/u)) {
this.debug('Locating %s from path %s', typeName, color.filePath(name));
modulesToAttempt.push(Path.create(name).path());
isFilePath = true;
// Module name
} else {
this.debug('Locating %s module %s', typeName, color.moduleName(name));
if (scoped) {
modulesToAttempt.push(formatModuleName(appName, typeName, name, true));
}
modulesToAttempt.push(formatModuleName(appName, typeName, name));
// Additional scopes to load
this.scopes.forEach(otherScope => {
modulesToAttempt.push(
formatModuleName(otherScope, typeName, name, true),
formatModuleName(otherScope, typeName, name),
);
});
this.debug('Resolving in order: %s', modulesToAttempt.join(', '));
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));
resolver.lookupNodeModule(moduleName);
// @scope/name
} else if (
moduleName.match(new RegExp(`^@${modulePattern}/${modulePattern}$`, 'u')) &&
isNotToolOrType
) {
const ModuleClass = importedModule as ConcreteConstructor;
const module = new ModuleClass(...args);
if (!instanceOf(module, this.contract)) {
throw new TypeError(
this.tool.msg('errors:moduleExportInvalid', {
moduleName,
typeName,
}),
);
}
if (isFilePath) {
this.debug('Found with file path %s', color.filePath(moduleName));
} else {
this.debug('Found with module %s', color.moduleName(moduleName));
(module as any).name = name;
(module as any).moduleName = moduleName;
}
return module;
}