How to use the resolve-from.silent function in resolve-from

To help you get started, we’ve selected a few resolve-from examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github react-cosmos / react-cosmos / packages / react-cosmos / src / config / resolve.ts View on Github external
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);
}
github zodern / meteor-up / src / load-plugins.js View on Github external
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;
}
github ayakashi-io / ayakashi / src / preloaderCompiler / compiler.ts View on Github external
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}`}
            )
github fastify / fastify-cli / start.js View on Github external
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)
  }
}
github neoclide / coc-tslint / server / index.ts View on Github external
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)
  }
}
github saberland / saber / packages / saber / src / index.ts View on Github external
localResolve(name: string): string {
    return require('resolve-from').silent(this.opts.cwd, name)
  }
github walrusjs / walrus / packages / walrus-cli / src / service.ts View on Github external
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);
  }
github expo / expo-cli / packages / electron-adapter / src / Config.ts View on Github external
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));
}
github expo / expo-cli / packages / config / src / paths / paths.ts View on Github external
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;
}
github walrusjs / walrus / packages / walrus-plugin-commitlint / src / utils / index.ts View on Github external
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.`);
}

resolve-from

Resolve the path of a module like `require.resolve()` but from a given path

MIT
Latest version published 6 years ago

Package Health Score

70 / 100
Full package analysis