How to use locate-path - 6 common examples

To help you get started, we’ve selected a few locate-path 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 alan-ai / alan-sdk-reactnative / testtools / node_modules / read-pkg-up / node_modules / find-up / index.js View on Github external
module.exports.sync = (filename, opts) => {
	opts = opts || {};

	let dir = path.resolve(opts.cwd || '');
	const root = path.parse(dir).root;

	const filenames = [].concat(filename);

	// eslint-disable-next-line no-constant-condition
	while (true) {
		const file = locatePath.sync(filenames, {cwd: dir});

		if (file) {
			return path.join(dir, file);
		} else if (dir === root) {
			return null;
		}

		dir = path.dirname(dir);
	}
};
github frctl / fractal / packages / cli / src / loaders / config.js View on Github external
let configPath;
  let config = {};

  if (pkgPath) {
    /*
    * package.json exists, load it and look for a config file.
    * Custom config file names can be specified using
    * the `fractal.cli.config` property in the package.json
    */

    const pkg = require(pkgPath);
    const pkgConfig = pkg.fractal;
    const fileNames = toArray(get(pkgConfig || {}, 'cli.config', opts.config));
    const filePaths = fileNames.map(p => join(process.cwd(), p.replace(/^\.\//, '')));

    configPath = locatePath.sync(filePaths);

    if (!configPath && pkgConfig) {
      configPath = join(process.cwd(), 'package.json');
      config = pkgConfig;
      debug(`no config file found, using config from package.json`);
    } else if (configPath) {
      debug(`config file found: %s`, configPath);
      config = require(configPath);
      debug(`config file read OK`);
    } else {
      /* istanbul ignore next */
      debug(`no config file found, looked for %s`, fileNames.join(', '));
    }
  }

  return {configPath, config};
github goabstract / abstract-sdk / src / AbstractCLI / index.js View on Github external
// Relative to node_modules in cwd (also makes test easier)
      path.join(
        cwd,
        "node_modules/@elasticprojects/abstract-cli/bin/abstract-cli"
      ),
      // macOS App
      "/Applications/Abstract.app/Contents/Resources/app.asar.unpacked/node_modules/@elasticprojects/abstract-cli/bin/abstract-cli"
    ],
    apiUrl = "https://api.goabstract.com"
  }: Options = {}) {
    this.cwd = cwd;
    this._optionAccessToken = accessToken;
    this.apiUrl = apiUrl;

    try {
      this.cliPath = path.resolve(cwd, locatePath.sync(cliPath));
    } catch (error) {
      throw new Error(`Cannot find abstract-cli in "${cliPath.join(":")}"`);
    }
  }
github sx1989827 / DOClever / Client / node_modules / find-up / index.js View on Github external
module.exports.sync = (filename, opts) => {
	opts = opts || {};

	let dir = path.resolve(opts.cwd || '');
	const root = path.parse(dir).root;

	const filenames = [].concat(filename);

	// eslint-disable-next-line no-constant-condition
	while (true) {
		const file = locatePath.sync(filenames, {cwd: dir});

		if (file) {
			return path.join(dir, file);
		} else if (dir === root) {
			return null;
		}

		dir = path.dirname(dir);
	}
};
github sindresorhus / find-up / index.js View on Github external
const runMatcher = locateOptions => {
		if (typeof name !== 'function') {
			return locatePath.sync(paths, locateOptions);
		}

		const foundPath = name(locateOptions.cwd);
		if (typeof foundPath === 'string') {
			return locatePath.sync([foundPath], locateOptions);
		}

		return foundPath;
	};
github sindresorhus / find-up / index.js View on Github external
const runMatcher = locateOptions => {
		if (typeof name !== 'function') {
			return locatePath.sync(paths, locateOptions);
		}

		const foundPath = name(locateOptions.cwd);
		if (typeof foundPath === 'string') {
			return locatePath.sync([foundPath], locateOptions);
		}

		return foundPath;
	};

locate-path

Get the first path that exists on disk of multiple paths

MIT
Latest version published 2 years ago

Package Health Score

70 / 100
Full package analysis

Popular locate-path functions