How to use resolve-from - 10 common examples

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 pikapkg / web / src / index.ts View on Github external
function resolveWebDependency(dep: string, isExplicit: boolean): DependencyLoc {
  // if the path includes a file extension, just use it
  if (path.extname(dep)) {
    const isJSFile = ['.js', '.mjs', '.cjs'].includes(path.extname(dep));
    return {
      type: isJSFile ? 'JS' : 'ASSET',
      loc: resolveFrom(cwd, dep),
    };
  }

  const depManifestLoc = resolveFrom(cwd, `${dep}/package.json`);
  const depManifest = require(depManifestLoc);
  let foundEntrypoint: string =
    depManifest['browser:module'] || depManifest.module || depManifest.browser;
  // If the package was a part of the explicit whitelist, fallback to it's main CJS entrypoint.
  if (!foundEntrypoint && isExplicit) {
    foundEntrypoint = depManifest.main || 'index.js';
  }
  if (!foundEntrypoint) {
    throw new ErrorWithHint(
      `dependency "${dep}" has no native "module" entrypoint.`,
      chalk.italic(
        `Tip: Find modern, web-ready packages at ${chalk.underline('https://www.pika.dev')}`,
github itgalaxy / generate-robotstxt / src / cli.js View on Github external
}
    }
  }
);

const optionsBase = {};

if (cli.flags.config) {
  // Should check these possibilities:
  //   a. name of a node_module
  //   b. absolute path
  //   c. relative path relative to `process.cwd()`.
  // If none of the above work, we'll try a relative path starting
  // in `process.cwd()`.
  optionsBase.configFile =
    resolveFrom(process.cwd(), cli.flags.config) ||
    path.join(process.cwd(), cli.flags.config);
}

Promise.resolve()
  .then(() => Object.assign({}, optionsBase))
  .then(options => standalone(options))
  .then(output => {
    if (cli.input.length === 0) {
      throw new Error("Require `dest` argument");
    }

    const dest = path.resolve(cli.input.pop());

    return Promise.resolve().then(() => fs.outputFile(dest, output));
  })
  .catch(error => {
github storybookjs / storybook / lib / theming / paths.js View on Github external
const { dirname } = require('path');
const resolveFrom = require('resolve-from');

const resolve = resolveFrom.bind(null, __dirname);

// These paths need to be aliased in the manager webpack config to ensure that all
// code running inside the manager uses the *same* versions of each package.
module.exports = {
  '@emotion/core': dirname(resolve('@emotion/core/package.json')),
  '@emotion/styled': dirname(resolve('@emotion/styled/package.json')),
  'emotion-theming': dirname(resolve('emotion-theming/package.json')),
};
github novemberborn / hullabaloo-config-manager / test / Verifier.js View on Github external
test('verifyEnv() can use cache', async t => {
  const dir = path.join(tmpDir, 'use-cache')
  fse.copySync(fixture('verifier', 'pkg'), dir)
  const plugin = resolveFrom(dir, './plugin.js')

  const cache = prepareCache()
  const verifier = await (await fromDirectory(dir)).createVerifier()
  await verifier.verifyEnv(null, null, cache)

  t.deepEqual(Array.from(cache.dependencyHashes.keys()), [
    plugin
  ])
  t.deepEqual(Array.from(cache.fileExistence.keys()), [
    path.join(dir, '.babelrc'),
    path.join(dir, '.babelrc.js')
  ])
  t.deepEqual(Array.from(cache.files.keys()), [
    path.join(dir, 'extends.json5'),
    path.join(dir, 'package.json'),
    plugin
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 sanity-io / sanity / packages / @sanity / cli / src / bin / sanity.js View on Github external
function getCoreModulePath() {
  const pkgPath = resolveFrom(workDir, '@sanity/core')
  if (pkgPath) {
    return pkgPath
  }

  const hasManifest = fs.existsSync(path.join(workDir, 'sanity.json'))
  if (hasManifest && process.argv.indexOf('install') === -1) {
    console.warn(chalk.yellow([
      '@sanity/core not installed in current project',
      'Project-specific commands not available until you run `sanity install`'
    ].join('\n')))
  }

  return undefined
}
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)
  }
}

resolve-from

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

MIT
Latest version published 5 years ago

Package Health Score

70 / 100
Full package analysis