How to use the read-pkg-up 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 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 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 facebookarchive / flow-language-server / src / flow-versions / flowBinForRoot.js View on Github external
export async function _flowSemverForRootPath(
  rootPath: string,
  reporter: Reporter,
): Promise {
  const configDir = await flowConfigCache.getConfigDir(rootPath);
  reporter.info('Determining the version of flow for your project...');
  if (!configDir) {
    reporter.error(
      'No valid .flowconfig was found. Use `flow init` in the root of your project to create one.',
    );
    return null;
  }
  const configPath = path.join(configDir, '.flowconfig');
  const {pkg} = await readPkgUp({cwd: rootPath});

  let packageFlowVersion;
  const depRange = idx(pkg, _ => _.dependencies['flow-bin']);
  const devDepRange = idx(pkg, _ => _.devDependencies['flow-bin']);
  if (depRange && semver.validRange(depRange)) {
    packageFlowVersion = depRange;
  } else if (devDepRange && semver.validRange(devDepRange)) {
    packageFlowVersion = devDepRange;
  }
  if (packageFlowVersion) {
    reporter.info(
      `Found flow version requirement ${packageFlowVersion} in your package.json`,
    );
  }

  let configFlowVersion;
github facebookarchive / flow-language-server / src / flow-versions / flowBinForRoot.js View on Github external
export async function _flowSemverForRootPath(rootPath: string, reporter: Reporter): Promise {
  const configDir = await flowConfigCache.getConfigDir(rootPath);
  reporter.info('Determining the version of flow for your project...');
  if (!configDir) {
    reporter.error('No valid .flowconfig was found. Use `flow init` in the root of your project to create one.');
    return;
  }
  const configPath = path.join(configDir, '.flowconfig');
  const {pkg, path: pkgPath} = await readPkgUp({cwd: rootPath});

  let packageFlowVersion;
  const depRange = idx(pkg, _ => _.dependencies['flow-bin']);
  const devDepRange = idx(pkg, _ => _.devDependencies['flow-bin']);
  if (depRange && semver.validRange(depRange)) {
    packageFlowVersion = depRange;
  } else if (devDepRange && semver.validRange(devDepRange)) {
    packageFlowVersion = devDepRange;
  }
  if (packageFlowVersion) {
    reporter.info(`Found flow version requirement ${packageFlowVersion} in your package.json`);
  }

  let configFlowVersion;
  if (configDir) {
    try {

read-pkg-up

Read the closest package.json file

MIT
Latest version published 6 months ago

Package Health Score

58 / 100
Full package analysis