How to use @pnpm/read-package-json - 6 common examples

To help you get started, we’ve selected a few @pnpm/read-package-json 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 pnpm / pnpm / packages / build-modules / src / index.ts View on Github external
message: `The store server disabled upload requests, could not upload ${depNode.packageId}`,
            prefix: opts.lockfileDir,
          })
        } else {
          logger.warn({
            error: err,
            message: `An error occurred while uploading ${depNode.packageId}`,
            prefix: opts.lockfileDir,
          })
        }
      }
    }
  } catch (err) {
    if (depNode.optional) {
      // TODO: add parents field to the log
      const pkg = await readPackageFromDir(path.join(depNode.peripheralLocation)) as DependencyManifest
      skippedOptionalDependencyLogger.debug({
        details: err.toString(),
        package: {
          id: depNode.packageId,
          name: pkg.name,
          version: pkg.version,
        },
        prefix: opts.lockfileDir,
        reason: 'build_failure',
      })
      return
    }
    throw err
  }
}
github pnpm / pnpm / packages / package-requester / src / packageRequester.ts View on Github external
)
        const integrity = fileIntegrities
          .reduce((acc, info) => {
            Object.assign(acc, info)
            return acc
          }, {})
        await writeJsonFile(path.join(target, 'integrity.json'), integrity, { indent: undefined })
      } else {
        // TODO: save only filename: {size}
        await writeJsonFile(path.join(target, 'integrity.json'), filesIndex, { indent: undefined })
      }
      finishing.resolve(undefined)

      let pkgName: string | undefined = opts.pkgName
      if (!pkgName || opts.fetchRawManifest) {
        const manifest = await readPkgFromDir(tempLocation) as DependencyManifest
        bundledManifest.resolve(pickBundledManifest(manifest))
        if (!pkgName) {
          pkgName = manifest.name
        }
      }

      const unpacked = path.join(target, 'node_modules', pkgName)
      await makeDir(path.dirname(unpacked))

      // rename(oldPath, newPath) is an atomic operation, so we do it at the
      // end
      await renameOverwrite(tempLocation, unpacked)
      await symlinkDir(unpacked, linkToUnpacked)

      if (isLocalTarballDep && opts.resolution['integrity']) { // tslint:disable-line:no-string-literal
        await fs.writeFile(path.join(target, TARBALL_INTEGRITY_FILENAME), opts.resolution['integrity'], 'utf8') // tslint:disable-line:no-string-literal
github pnpm / pnpm / packages / supi / src / unlink / index.ts View on Github external
export async function _unlinkPkgs (
  pkgNames: string[],
  opts: StrictInstallOptions,
  importers: Array<{ modulesDir: string, prefix: string }>,
) {
  if (importers.length > 1) throw new Error('Unlink not implemented for multiple importers yet')
  const importer = importers[0]
  const pkg = await readPkgFromDir(importer.prefix)
  const allDeps = getAllDependenciesFromPackage(pkg)
  const packagesToInstall: string[] = []

  for (const pkgName of pkgNames) {
    try {
      if (!await isExternalLink(opts.store, importer.modulesDir, pkgName)) {
        logger.warn({
          message: `${pkgName} is not an external link`,
          prefix: importer.prefix,
        })
        continue
      }
    } catch (err) {
      if (err['code'] !== 'ENOENT') throw err // tslint:disable-line:no-string-literal
    }
    await rimraf(path.join(importer.modulesDir, pkgName))
github pnpm / pnpm / packages / package-requester / src / packageRequester.ts View on Github external
async function readBundledManifest (dir: string): Promise {
  return pickBundledManifest(await readPkgFromDir(dir) as DependencyManifest)
}
github pnpm / pnpm / packages / list / src / readPkg.ts View on Github external
export default (pkgPath: string) => limitPkgReads(() => readPackageJson(pkgPath))
github pnpm / pnpm / packages / utils / src / safeReadPkg.ts View on Github external
export default async function safeReadPkg (pkgPath: string): Promise {
  try {
    return await readPkg(pkgPath)
  } catch (err) {
    if ((err as NodeJS.ErrnoException).code !== 'ENOENT') throw err
    return null
  }
}

@pnpm/read-package-json

Read a package.json

MIT
Latest version published 4 days ago

Package Health Score

68 / 100
Full package analysis

Popular @pnpm/read-package-json functions