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

To help you get started, we’ve selected a few read-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 Raathigesh / majestic / server / index.ts View on Github external
import { GraphQLServer } from "graphql-yoga";
import "reflect-metadata";
import { getSchema } from "./api";
import resultHandlerApi from "./services/result-handler-api";
import getPort from "get-port";
import * as parseArgs from "minimist";
import * as chromeLauncher from "chrome-launcher";
import * as opn from "open";
import "consola";
import { initializeStaticRoutes } from "./static-files";
import { root } from "./services/cli";
import * as readPkgUp from "read-pkg-up";

const pkg = readPkgUp.sync({
  cwd: __dirname
}).pkg;
declare var consola: any;

const args = parseArgs(process.argv);
const defaultPort = args.port || 4000;
process.env.DEBUG_LOG = args.debug ? "log" : "";

if (args.root) {
  process.env.ROOT = args.root;
}

if (args.version) {
  console.log(`v${pkg.version}`);
  process.exit();
}
github sindresorhus / npm-home / cli.js View on Github external
(async () => {
	if (cli.input.length > 0) {
		await openPackage(cli.input[0]);
	} else {
		const result = readPkgUp.sync();

		if (!result) {
			console.error('You\'re not in an npm package');
			process.exit(1);
		}

		await openPackage(result.package.name);
	}
})();
github 0soft / mui-form-fields / webpack.config.js View on Github external
const path = require('path');
const packageinfo = require("read-pkg-up").sync().package;
const camelCase = require("camelcase");


module.exports = {
  entry: './src/index.ts',
  output: {
    path: path.resolve(path.join(__dirname, '.', 'dist')),
    filename: 'mui-form-fields.js',
    library: 'MuiFormFields',
    libraryTarget: 'umd',
    globalObject: 'this',
  },
  module: {
    rules: [
      {
        test: /\.js$/,
github t9md / atom-mprettier / lib / formatter.js View on Github external
function getStandard (editor) {
  const result = readPgkUp.sync({cwd: Path.dirname(editor.getPath())})
  if (result && result.pkg) {
    const {dependencies, devDependencies} = result.pkg
    if ((dependencies && 'standard' in dependencies) || (devDependencies && 'standard' in devDependencies)) {
      const libPath = Path.join(Path.dirname(result.path), 'node_modules', 'standard')
      return require(libPath)
    }
  }
  if (!BUNDLED_STANDARD) BUNDLED_STANDARD = require('standard')
  return BUNDLED_STANDARD
}
github t9md / atom-mprettier / lib / formatter.js View on Github external
function hasClosestPackageJsonHasPackage (cwd, name) {
  const result = readPgkUp.sync({cwd})
  if (!result || !result.pkg) return false
  const {dependencies, devDependencies} = result.pkg
  return (dependencies && name in dependencies) || (devDependencies && name in devDependencies)
}
github silklabs / silk / eslint-plugin / no-extraneous-dependencies.js View on Github external
function getPkg(cwd) {
  try {
    return readPkgUp.sync({cwd, normalize: false});
  } catch (e) {
    return null;
  }
}
github wechaty / wechaty / src / puppet-manager.ts View on Github external
protected static getModuleVersion (moduleName: string): string {
    const modulePath = path.dirname(
      require.resolve(
        moduleName,
      ),
    )
    const pkg     = readPkgUp.sync({ cwd: modulePath })!.packageJson
    const version = pkg.version

    return version
  }
github unboundedsystems / adapt / core / src / packageinfo.ts View on Github external
export function findPackageInfo(dir: string): PackageInfo {
    const ret = readPkgUp.sync({cwd: dir, normalize: false });
    const pkgJson = ret.pkg;
    if (!pkgJson || !pkgJson.name || !pkgJson.version) {
        throw new Error(`Invalid plugin registration. Cannot find package.json info in directory ${dir}.`);
    }
    const root = path.dirname(ret.path);
    const main = path.resolve(path.join(root, pkgJson.main || "index.js"));
    return {
        main,
        name: pkgJson.name,
        root,
        version: pkgJson.version,
    };
}
github vuejs / vetur / server / src / utils / prettier / requirePkg.ts View on Github external
function findPkg(fspath: string, pkgName: string): string | undefined {
  const { pkg, path: pkgPath } = readPkgUp.sync({ cwd: fspath, normalize: false });
  const { root } = path.parse(fspath);
  if (
    pkg &&
    ((pkg.dependencies && pkg.dependencies[pkgName]) || (pkg.devDependencies && pkg.devDependencies[pkgName]))
  ) {
    return resolve.sync(pkgName, { basedir: pkgPath });
  } else if (pkgPath) {
    const parent = path.resolve(path.dirname(pkgPath), '..');
    if (parent !== root) {
      return findPkg(parent, pkgName);
    }
  }
  return;
}
github AndersDJohnson / webpack-babel-env-deps / src / index.js View on Github external
export function getNeedBabel(options) {
  const pathInPkg = options.path || process.cwd()
  const pkg = readPkgUp.sync({
    cwd: pathInPkg
  })

  const dependencies = getDependencies(pathInPkg, options)

  return getNeedBabelFromPackageAndDependencies(pkg, dependencies, options)
}

read-pkg-up

Read the closest package.json file

MIT
Latest version published 6 months ago

Package Health Score

58 / 100
Full package analysis