How to use the pkg-up.sync function in pkg-up

To help you get started, we’ve selected a few pkg-up 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 boltpkg / bolt / src / constants.js View on Github external
// @flow
import pkgUp from 'pkg-up';
const boltPkgPath = pkgUp.sync(__dirname);

// $FlowFixMe
const boltPkg = require(boltPkgPath);

export const DEPENDENCY_TYPES = [
  'dependencies',
  'devDependencies',
  'peerDependencies',
  'bundledDependencies',
  'optionalDependencies'
];

export const DEPENDENCY_TYPE_FLAGS_MAP = {
  dev: 'devDependencies',
  peer: 'peerDependencies',
  optional: 'optionalDependencies',
github react-cosmos / react-cosmos / packages / react-cosmos / src / shared / playgroundHtml.ts View on Github external
function getProjectId(rootDir: string) {
  const pkgPath = pkgUp.sync({ cwd: rootDir });
  if (!pkgPath) {
    return rootDir.split('/').pop();
  }

  const pkg = require(pkgPath);
  return pkg.name || '';
}
github sindresorhus / load-grunt-tasks / index.js View on Github external
module.exports = (grunt, options = {}) => {
	const pattern = arrify(options.pattern || ['grunt-*', '@*/grunt-*']);
	const scope = arrify(options.scope || ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']);

	let cwd = process.cwd();
	let config = options.config || pkgUp.sync();

	if (config === null) {
		grunt.fail.fatal('package.json not found. Make sure to create a package.json and install dependencies before you run Grunt.');
	}

	if (typeof config === 'string') {
		const configPath = path.resolve(config);
		cwd = path.dirname(configPath);
		config = require(configPath);
	}

	pattern.push('!grunt', '!grunt-cli');

	const names = scope.reduce((result, property) => {
		const dependencies = config[property] || [];
		return result.concat(Array.isArray(dependencies) ? dependencies : Object.keys(dependencies));
github umijs / umi / packages / af-webpack / src / getWebpackConfig / es5ImcompatibleVersions.js View on Github external
export function getPkgPath(filePath) {
  const dir = dirname(filePath);
  if (dir in pkgPathCache) return pkgPathCache[dir];
  pkgPathCache[dir] = pkgUp.sync({ cwd: filePath });
  return pkgPathCache[dir];
}
github tleunen / babel-plugin-module-resolver / src / normalizeOptions.js View on Github external
  packagejson: startPath => pkgUp.sync({ cwd: startPath }),
};
github embroider-build / embroider / packages / compat / src / v1-app.ts View on Github external
get root(): string {
    return dirname(pkgUpSync(this.app.project.root)!);
  }
github terascope / teraslice / packages / scripts / src / helpers / misc.ts View on Github external
export function getRootDir(cwd: string = process.cwd()): string {
    if (rootDir) return rootDir;
    const rootPkgJSON = pkgUp.sync({ cwd });
    if (!rootPkgJSON) {
        throw new Error('Unable to find root directory, run in the root of the repo');
    }

    if (_getRootInfo(rootPkgJSON) != null) {
        rootDir = path.dirname(rootPkgJSON);
        return rootDir;
    }

    const upOne = path.join(path.dirname(rootPkgJSON), '..');
    if (!fse.existsSync(upOne) || !fse.statSync(upOne).isDirectory()) {
        throw new Error('Unable to find root directory');
    }
    return getRootDir(upOne);
}
github embark-framework / embark / packages / embark / src / bin / embark.js View on Github external
function stop() {
    found = pkgUp.sync(startDir);
    if (found && !closest) {
      closest = found;
    }
    dir = found ? path.dirname(found) : found;
    var stop = !dir || !isDappCmd(embarkJson.cmd);
    if (!stop) {
      startDir = path.join(dir, '..');
    }
    return stop;
  }
  while (!stop()) {
github Financial-Times / x-dash / packages / x-build / register.js View on Github external
matcher(file) {
		const pkgPath = pkgUp.sync(file);
		const root = path.dirname(pkgPath);
		const pkg = readJSON(pkgPath);

		const matches = root !== process.cwd()
			&& pkg.name.startsWith('@financial-times/x-')
			&& pkg.name !== '@financial-times/x-build';

		return !!matches;
	},

pkg-up

Find the closest package.json file

MIT
Latest version published 1 year ago

Package Health Score

58 / 100
Full package analysis

Popular pkg-up functions