How to use read-pkg-up - 10 common examples

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 prisma / prisma2 / cli / sdk / src / getPackedPackage.ts View on Github external
name: string,
  target: string,
  packageDir?: string,
): Promise {
  if (!target) {
    throw new Error(`Error in getPackage: Please provide a target`)
  }
  packageDir =
    packageDir ||
    resolvePkg(name, { cwd: __dirname }) ||
    resolvePkg(name, { cwd: target })

  debug({ packageDir })

  if (!packageDir) {
    const pkg = await readPkgUp({
      cwd: target,
    })
    if (pkg && pkg.packageJson.name === name) {
      packageDir = path.dirname(pkg.path)
    }
  }

  if (!packageDir) {
    throw new Error(
      `Error in getPackage: Could not resolve package ${name} from ${__dirname}`,
    )
  }
  const tmpDir = tempy.directory() // thanks Sindre
  const archivePath = path.join(tmpDir, `package.tgz`)

  // pack into a .tgz in a tmp dir
github huan / matrix-appservice-wechaty / src / cli / check-update.ts View on Github external
export function checkUpdate (): void {
  readPkgUp({ cwd: __dirname })
    .then(pack => {
      if (!pack) {
        throw new Error('package.json not found')
      }

      const pkg = pack.package
      // 1 week
      const updateCheckInterval = 1000 * 60 * 60 * 24 * 7

      const notifier  = new UpdateNotifier({
        pkg,
        updateCheckInterval,
      })
      notifier.notify()
      return null
    })
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 mastilver / dynamic-cdn-webpack-plugin / src / index.js View on Github external
async addModule(contextPath, modulePath, {env}) {
        const isModuleExcluded = this.exclude.includes(modulePath) ||
            (this.only && !this.only.includes(modulePath));
        if (isModuleExcluded) {
            return false;
        }

        const moduleName = modulePath.match(moduleRegex)[1];
        const {pkg: {version, peerDependencies}} = await readPkgUp({cwd: resolvePkg(moduleName, {cwd: contextPath})});

        const isModuleAlreadyLoaded = Boolean(this.modulesFromCdn[modulePath]);
        if (isModuleAlreadyLoaded) {
            const isSameVersion = this.modulesFromCdn[modulePath].version === version;
            if (isSameVersion) {
                return this.modulesFromCdn[modulePath].var;
            }

            return false;
        }

        const cdnConfig = await this.resolver(modulePath, version, {env});

        if (cdnConfig == null) {
            if (this.verbose) {
                console.log(`❌ '${modulePath}' couldn't be found, please add it to https://github.com/mastilver/module-to-cdn/blob/master/modules.json`);
github havardh / workflow / packages / workflow-cmd / src / commands / version.js View on Github external
async function printDependenciesVersion() {
  const { pkg } = await readPkgUp({ cwd: baseFolder });

  for (let [key, value] of Object.entries(pkg.dependencies)) {
    console.log(` - ${key}: ${value}`);
  }
}
github frinyvonnick / gitmoji-changelog / packages / gitmoji-changelog-cli / src / presets / node.spec.js View on Github external
it('should extract github repo info from package.json', async () => {
    readPkgUp.mockImplementationOnce(() => Promise.resolve({
      pkg: {
        name: 'gitmoji-changelog',
        version: '0.0.1',
        description: 'Gitmoji Changelog CLI',
      },
    }))

    const result = await loadProjectInfo()

    expect(result).toEqual({
      name: 'gitmoji-changelog',
      version: '0.0.1',
      description: 'Gitmoji Changelog CLI',
    })
  })
})
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)
}

read-pkg-up

Read the closest package.json file

MIT
Latest version published 4 months ago

Package Health Score

58 / 100
Full package analysis