How to use @pnpm/lockfile-file - 10 common examples

To help you get started, we’ve selected a few @pnpm/lockfile-file 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 / supi / src / install / index.ts View on Github external
// skipped packages might have not been reanalized on a repeat install
      // so lets just ignore those by excluding nulls
      .filter(Boolean)
      .map(({ fetchingFiles }) => fetchingFiles()),
  )

  // waiting till package requests are finished
  await Promise.all(R.values(resolvedPackagesByPackageId).map(({ finishing }) => finishing()))

  const lockfileOpts = { forceSharedFormat: opts.forceSharedLockfile }
  if (opts.lockfileOnly) {
    await writeWantedLockfile(ctx.lockfileDir, result.wantedLockfile, lockfileOpts)
  } else {
    await Promise.all([
      opts.useLockfile
        ? writeLockfiles({
          currentLockfile: result.currentLockfile,
          currentLockfileDir: ctx.virtualStoreDir,
          wantedLockfile: result.wantedLockfile,
          wantedLockfileDir: ctx.lockfileDir,
          ...lockfileOpts,
        })
        : writeCurrentLockfile(ctx.virtualStoreDir, result.currentLockfile, lockfileOpts),
      (() => {
        if (result.currentLockfile.packages === undefined && result.removedDepPaths.size === 0) {
          return Promise.resolve()
        }
        return writeModulesYaml(ctx.rootModulesDir, {
          ...ctx.modulesFile,
          hoistedAliases: result.newHoistedAliases,
          hoistPattern: ctx.hoistPattern,
          included: ctx.include,
github pnpm / pnpm / packages / supi / src / link / index.ts View on Github external
maybeOpts: LinkOptions & {
    linkToBin?: string,
    dir: string,
  },
) {
  const reporter = maybeOpts?.reporter
  if (reporter) {
    streamParser.on('data', reporter)
  }
  const opts = await extendOptions(maybeOpts)
  const ctx = await getContextForSingleImporter(opts.manifest, {
    ...opts,
    extraBinPaths: [], // ctx.extraBinPaths is not needed, so this is fine
  })

  const importerId = getLockfileImporterId(ctx.lockfileDir, opts.dir)
  const currentLockfile = R.clone(ctx.currentLockfile)
  const linkedPkgs: Array<{path: string, manifest: DependencyManifest, alias: string}> = []
  const specsToUpsert = [] as PackageSpecObject[]

  for (const linkFrom of linkFromPkgs) {
    let linkFromPath: string
    let linkFromAlias: string | undefined
    if (typeof linkFrom === 'string') {
      linkFromPath = linkFrom
    } else {
      linkFromPath = linkFrom.path
      linkFromAlias = linkFrom.alias
    }
    const { manifest } = await readImporterManifest(linkFromPath) as { manifest: DependencyManifest }
    specsToUpsert.push({
      alias: manifest.name,
github pnpm / pnpm / packages / get-context / src / readLockfiles.ts View on Github external
virtualStoreDir: string,
  },
): Promise<{
  currentLockfile: Lockfile,
  existsCurrentLockfile: boolean,
  existsWantedLockfile: boolean,
  wantedLockfile: Lockfile,
}> {
  // ignore `pnpm-lock.yaml` on CI servers
  // a latest pnpm should not break all the builds
  const lockfileOpts = {
    ignoreIncompatible: opts.force || isCI,
    wantedVersion: LOCKFILE_VERSION,
  }
  const files = await Promise.all([
    opts.useLockfile && readWantedLockfile(opts.lockfileDir, lockfileOpts)
      || await existsWantedLockfile(opts.lockfileDir) &&
        logger.warn({
          message: `A ${WANTED_LOCKFILE} file exists. The current configuration prohibits to read or write a lockfile`,
          prefix: opts.lockfileDir,
        }),
    readCurrentLockfile(opts.virtualStoreDir, lockfileOpts),
  ])
  const sopts = { lockfileVersion: LOCKFILE_VERSION }
  const importerIds = opts.importers.map((importer) => importer.id)
  const currentLockfile = files[1] || createLockfileObject(importerIds, sopts)
  for (const importerId of importerIds) {
    if (!currentLockfile.importers[importerId]) {
      currentLockfile.importers[importerId] = {
        specifiers: {},
      }
    }
github pnpm / pnpm / packages / get-context / src / readLockfiles.ts View on Github external
wantedLockfile: Lockfile,
}> {
  // ignore `pnpm-lock.yaml` on CI servers
  // a latest pnpm should not break all the builds
  const lockfileOpts = {
    ignoreIncompatible: opts.force || isCI,
    wantedVersion: LOCKFILE_VERSION,
  }
  const files = await Promise.all([
    opts.useLockfile && readWantedLockfile(opts.lockfileDir, lockfileOpts)
      || await existsWantedLockfile(opts.lockfileDir) &&
        logger.warn({
          message: `A ${WANTED_LOCKFILE} file exists. The current configuration prohibits to read or write a lockfile`,
          prefix: opts.lockfileDir,
        }),
    readCurrentLockfile(opts.virtualStoreDir, lockfileOpts),
  ])
  const sopts = { lockfileVersion: LOCKFILE_VERSION }
  const importerIds = opts.importers.map((importer) => importer.id)
  const currentLockfile = files[1] || createLockfileObject(importerIds, sopts)
  for (const importerId of importerIds) {
    if (!currentLockfile.importers[importerId]) {
      currentLockfile.importers[importerId] = {
        specifiers: {},
      }
    }
  }
  const wantedLockfile = files[0] ||
    currentLockfile && R.clone(currentLockfile) ||
    createLockfileObject(importerIds, sopts)
  for (const importerId of importerIds) {
    if (!wantedLockfile.importers[importerId]) {
github pnpm / pnpm / packages / supi / src / install / index.ts View on Github external
// waiting till the skipped packages are downloaded to the store
  await Promise.all(
    R.props(Array.from(ctx.skipped), resolvedPackagesByPackageId)
      // skipped packages might have not been reanalized on a repeat install
      // so lets just ignore those by excluding nulls
      .filter(Boolean)
      .map(({ fetchingFiles }) => fetchingFiles()),
  )

  // waiting till package requests are finished
  await Promise.all(R.values(resolvedPackagesByPackageId).map(({ finishing }) => finishing()))

  const lockfileOpts = { forceSharedFormat: opts.forceSharedLockfile }
  if (opts.lockfileOnly) {
    await writeWantedLockfile(ctx.lockfileDir, result.wantedLockfile, lockfileOpts)
  } else {
    await Promise.all([
      opts.useLockfile
        ? writeLockfiles({
          currentLockfile: result.currentLockfile,
          currentLockfileDir: ctx.virtualStoreDir,
          wantedLockfile: result.wantedLockfile,
          wantedLockfileDir: ctx.lockfileDir,
          ...lockfileOpts,
        })
        : writeCurrentLockfile(ctx.virtualStoreDir, result.currentLockfile, lockfileOpts),
      (() => {
        if (result.currentLockfile.packages === undefined && result.removedDepPaths.size === 0) {
          return Promise.resolve()
        }
        return writeModulesYaml(ctx.rootModulesDir, {
github pnpm / pnpm / packages / get-context / src / readLockfiles.ts View on Github external
},
): Promise<{
  currentLockfile: Lockfile,
  existsCurrentLockfile: boolean,
  existsWantedLockfile: boolean,
  wantedLockfile: Lockfile,
}> {
  // ignore `pnpm-lock.yaml` on CI servers
  // a latest pnpm should not break all the builds
  const lockfileOpts = {
    ignoreIncompatible: opts.force || isCI,
    wantedVersion: LOCKFILE_VERSION,
  }
  const files = await Promise.all([
    opts.useLockfile && readWantedLockfile(opts.lockfileDir, lockfileOpts)
      || await existsWantedLockfile(opts.lockfileDir) &&
        logger.warn({
          message: `A ${WANTED_LOCKFILE} file exists. The current configuration prohibits to read or write a lockfile`,
          prefix: opts.lockfileDir,
        }),
    readCurrentLockfile(opts.virtualStoreDir, lockfileOpts),
  ])
  const sopts = { lockfileVersion: LOCKFILE_VERSION }
  const importerIds = opts.importers.map((importer) => importer.id)
  const currentLockfile = files[1] || createLockfileObject(importerIds, sopts)
  for (const importerId of importerIds) {
    if (!currentLockfile.importers[importerId]) {
      currentLockfile.importers[importerId] = {
        specifiers: {},
      }
    }
  }
github pnpm / pnpm / packages / plugin-commands-audit / src / audit.ts View on Github external
export async function handler (
  args: string[],
  opts: Pick & {
    auditLevel?: 'low' | 'moderate' | 'high' | 'critical',
    include: IncludedDependencies
    json?: boolean,
    lockfileDir?: string,
    registries: Registries,
  },
  command: string,
) {
  const lockfile = await readWantedLockfile(opts.lockfileDir || opts.dir, { ignoreIncompatible: true })
  if (!lockfile) {
    throw new PnpmError('AUDIT_NO_LOCKFILE', `No ${WANTED_LOCKFILE} found: Cannot audit a project without a lockfile`)
  }
  const auditReport = await audit(lockfile, { include: opts.include, registry: opts.registries.default })
  if (opts.json) {
    return JSON.stringify(auditReport, null, 2)
  }

  let output = ''
  const auditLevel = AUDIT_LEVEL_NUMBER[opts.auditLevel || 'low']
  const advisories = Object.values(auditReport.advisories)
    .filter(({ severity }) => AUDIT_LEVEL_NUMBER[severity] >= auditLevel)
    .sort((a1, a2) => AUDIT_LEVEL_NUMBER[a2.severity] - AUDIT_LEVEL_NUMBER[a1.severity])
  for (const advisory of advisories) {
    output += table([
      [AUDIT_COLOR[advisory.severity](advisory.severity), chalk.bold(advisory.title)],
github pnpm / pnpm / packages / supi / src / link / index.ts View on Github external
updatedWantedLockfile.importers[importerId].specifiers[alias] = getSpecFromPackageManifest(newPkg, alias)
    }
  } else {
    newPkg = opts.manifest
  }
  const lockfileOpts = { forceSharedFormat: opts.forceSharedLockfile }
  if (opts.useLockfile) {
    await writeLockfiles({
      currentLockfile: updatedCurrentLockfile,
      currentLockfileDir: ctx.virtualStoreDir,
      wantedLockfile: updatedWantedLockfile,
      wantedLockfileDir: ctx.lockfileDir,
      ...lockfileOpts,
    })
  } else {
    await writeCurrentLockfile(ctx.virtualStoreDir, updatedCurrentLockfile, lockfileOpts)
  }

  summaryLogger.debug({ prefix: opts.dir })

  if (reporter) {
    streamParser.removeListener('data', reporter)
  }

  return newPkg
}
github pnpm / pnpm / packages / supi / src / uninstall / index.ts View on Github external
newLockfile,
    oldLockfile: ctx.currentLockfile,
    registries: ctx.registries,
    storeController: opts.storeController,
    virtualStoreDir: ctx.virtualStoreDir,
  })
  ctx.pendingBuilds = ctx.pendingBuilds.filter((pkgId) => !removedPkgIds.has(dp.resolve(ctx.registries, pkgId)))
  await opts.storeController.close()
  const currentLockfile = makePartialCurrentLockfile
    ? pruneLockfile(ctx.currentLockfile, pkg, ctx.importerId, { defaultRegistry: ctx.registries.default })
    : newLockfile
  const lockfileOpts = { forceSharedFormat: opts.forceSharedLockfile }
  if (opts.useLockfile) {
    await writeLockfiles(ctx.lockfileDirectory, newLockfile, currentLockfile, lockfileOpts)
  } else {
    await writeCurrentLockfile(ctx.lockfileDirectory, currentLockfile, lockfileOpts)
  }

  if (opts.shamefullyFlatten) {
    ctx.hoistedAliases = await shamefullyFlattenByLockfile(currentLockfile, ctx.importerId, {
      getIndependentPackageLocation: opts.independentLeaves
        ? async (packageId: string, packageName: string) => {
          const { directory } = await opts.storeController.getPackageLocation(packageId, packageName, {
            lockfileDirectory: ctx.lockfileDirectory,
            targetEngine: opts.sideEffectsCacheRead && ENGINE_NAME || undefined,
          })
          return directory
        }
        : undefined,
      lockfileDirectory: opts.lockfileDirectory,
      modulesDir: ctx.modulesDir,
      registries: ctx.registries,
github pnpm / pnpm / packages / supi / src / install / index.ts View on Github external
await Promise.all(R.values(resolvedPackagesByPackageId).map(({ finishing }) => finishing()))

  const lockfileOpts = { forceSharedFormat: opts.forceSharedLockfile }
  if (opts.lockfileOnly) {
    await writeWantedLockfile(ctx.lockfileDir, result.wantedLockfile, lockfileOpts)
  } else {
    await Promise.all([
      opts.useLockfile
        ? writeLockfiles({
          currentLockfile: result.currentLockfile,
          currentLockfileDir: ctx.virtualStoreDir,
          wantedLockfile: result.wantedLockfile,
          wantedLockfileDir: ctx.lockfileDir,
          ...lockfileOpts,
        })
        : writeCurrentLockfile(ctx.virtualStoreDir, result.currentLockfile, lockfileOpts),
      (() => {
        if (result.currentLockfile.packages === undefined && result.removedDepPaths.size === 0) {
          return Promise.resolve()
        }
        return writeModulesYaml(ctx.rootModulesDir, {
          ...ctx.modulesFile,
          hoistedAliases: result.newHoistedAliases,
          hoistPattern: ctx.hoistPattern,
          included: ctx.include,
          independentLeaves: ctx.independentLeaves,
          layoutVersion: LAYOUT_VERSION,
          packageManager: `${opts.packageManager.name}@${opts.packageManager.version}`,
          pendingBuilds: ctx.pendingBuilds,
          registries: ctx.registries,
          shamefullyHoist: ctx.shamefullyHoist,
          skipped: Array.from(ctx.skipped),