Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function resolveModule(rootDir: string, moduleId: string) {
// Use to deal with file paths and module names interchangeably.
return path.isAbsolute(moduleId)
? moduleId
: resolveFrom.silent(rootDir, moduleId) ||
// Final attempt: Resolve relative paths that don't either
// 1. Don't start with ./
// 2. Don't point to an existing file
path.join(rootDir, moduleId);
}
log('plugin installed locally with mup');
return mupLocal;
} catch (e) {
// Continues to next location to resolve from
}
const appLocalPath = resolveFrom.silent(appPath, name);
if (appLocalPath) {
log('plugin installed locall in app folder');
return appLocalPath;
}
log(`global install path: ${globalModules}`);
const globalPath = resolveFrom.silent(resolve(globalModules, '..'), name);
if (globalPath) {
log('plugin installed globally');
return globalPath;
}
log('plugin not found');
return name;
}
export function compile(
workingDir: string,
entry: string,
namespace: string,
cacheFolder: string,
useFileName: boolean,
noCache?: boolean
): Promise<{wrapper: string, source: string}> {
if (!entry || (typeof entry !== "string" && typeof entry !== "function")) {
return Promise.reject(new Error("invalid_compilation_target"));
}
if (!namespace || typeof namespace !== "string") return Promise.reject(new Error("invalid_namespace"));
if ((!cacheFolder || typeof namespace !== "string") && !noCache)
return Promise.reject(new Error("invalid_cache_folder"));
const input = resolveFrom.silent(workingDir, entry);
if (!input) return Promise.reject(`Could not resolve module ${entry}`);
const cacheFileName = createHash("sha1").update(input).digest("hex");
let wrapperName: string;
if (useFileName) {
wrapperName = input.split(sep)[input.split(sep).length - 1];
wrapperName = wrapperName.split(".")[0];
} else {
wrapperName = entry;
}
return new Promise(function(res, rej) {
const b = browserify(
Object.assign(
{},
JSON.parse(JSON.stringify(browserifyInc.args)),
{standalone: `${namespace}__${wrapperName}`}
)
function loadModules (opts) {
try {
const basedir = path.resolve(process.cwd(), opts._[0])
Fastify = require(resolveFrom.silent(basedir, 'fastify') || 'fastify')
fastifyPackageJSON = require(resolveFrom.silent(basedir, 'fastify/package.json') || 'fastify/package.json')
} catch (e) {
module.exports.stop(e)
}
}
export function resolveModule(name: string, localPath: string, globalPath: string): Promise {
if (localPath) {
let path = resolveFrom.silent(localPath, name)
if (path) return Promise.resolve(path)
}
try {
let path = resolveFrom(globalPath, name)
return Promise.resolve(path)
} catch (e) {
return Promise.reject(e)
}
}
localResolve(name: string): string {
return require('resolve-from').silent(this.opts.cwd, name)
}
localRequire(name: string, { silent, cwd }: { silent?: boolean; cwd?: string } = {}) {
cwd = cwd || this.context;
const resolved = silent ? resolveFrom.silent(cwd, name) : resolveFrom(cwd, name);
return resolved && require(resolved);
}
function resolveFile(projectRoot: string, localPath: string, packagePath: string): string {
const localTemplate = resolveFrom.silent(projectRoot, localPath);
if (localTemplate) {
return path.relative(projectRoot, localTemplate);
}
return path.relative(projectRoot, resolveFrom(projectRoot, packagePath));
}
export function resolveFromSilentWithExtensions(
fromDirectory: string,
moduleId: string,
extensions: string[]
): string | null {
for (const extension of extensions) {
const modulePath = resolveFrom.silent(fromDirectory, `${moduleId}.${extension}`);
if (modulePath && modulePath.endsWith(extension)) {
return modulePath;
}
}
return resolveFrom.silent(fromDirectory, moduleId) || null;
}
export function loadFormatter(config, flags) {
const moduleName = flags.format || config.formatter || '@commitlint/format';
const modulePath =
resolveFrom.silent(__dirname, moduleName) ||
resolveFrom.silent(flags.cwd, moduleName) ||
resolveGlobal.silent(moduleName);
if (modulePath) {
const moduleInstance = require(modulePath);
if (_.isFunction(moduleInstance.default)) {
return moduleInstance.default;
}
return moduleInstance;
}
throw new Error(`Using format ${moduleName}, but cannot find the module.`);
}