Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
modulesToAttempt.some(modName => {
try {
importedModule = requireModule(modName);
moduleName = modName;
return true;
} catch (error) {
if (error.message.startsWith(`Cannot find module '${modName}'`)) {
this.debug('Failed to import module: %s', error.message);
return false;
}
// Unknown error occurred, abort process
throw error;
}
});
loadConfig(filePath: Path): ConfigObject {
const config: ConfigObject = requireModule(filePath);
if (typeof config === 'function') {
throw new TypeError(this.tool.msg('errors:configNoFunction', { name: filePath.name() }));
}
this.options.driver.onLoadModuleConfig.emit([this.context, filePath, config]);
return config;
}
load(name: ModuleName, options: object = {}): Plugin {
const { originalPath, resolvedPath } = this.createResolver(name).resolve();
this.debug('Loading "%s" from %s', name, color.filePath(resolvedPath));
const factory: Factory = requireModule(resolvedPath);
if (typeof factory !== 'function') {
throw new TypeError(
`Plugin modules must export a default function, found ${typeof factory}.`,
);
}
const plugin = factory(options);
if (isObject(plugin) && !plugin.name) {
plugin.name = originalPath.path();
}
return plugin;
}
}
.forEach(pkgPath => {
const pkg: { name: string; version: string } = requireModule(
path.join(pkgPath, 'package.json'),
);
this.add(pkg.name, pkg.version);
});
bootstrapConfigModule() {
this.debug('Bootstrapping configuration module');
const { module } = this.config;
let bootstrap: Function | null = null;
try {
if (module === '@local') {
bootstrap = requireModule(this.getConfigModuleRoot().append('index.js'));
} else {
bootstrap = requireModule(module);
}
} catch {
this.debug('No index.js file detected, aborting bootstrap');
return this;
}
const isFunction = typeof bootstrap === 'function';
this.debug.invariant(isFunction, 'Executing bootstrap function', 'Found', 'Not found');
if (bootstrap && isFunction) {
bootstrap(this);
}
return this;