How to use the @pnpm/lockfile-utils.packageIdFromSnapshot function in @pnpm/lockfile-utils

To help you get started, we’ve selected a few @pnpm/lockfile-utils 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 / resolve-dependencies / src / resolveDependencies.ts View on Github external
if (dependencyLockfile.peerDependencies && dependencyLockfile.dependencies) {
      // This is done to guarantee that the dependency will be relinked with the
      // up-to-date peer dependencies
      // Covered by test: "peer dependency is grouped with dependency when peer is resolved not from a top dependency"
      R.keys(dependencyLockfile.peerDependencies).forEach((peer) => {
        delete dependencyLockfile.dependencies![peer]
      })
    }

    const depPath = dp.resolve(registries, relDepPath)
    return {
      currentResolution: pkgSnapshotToResolution(relDepPath, dependencyLockfile, registries),
      dependencyLockfile,
      depPath,
      optionalDependencyNames: R.keys(dependencyLockfile.optionalDependencies),
      pkgId: packageIdFromSnapshot(relDepPath, dependencyLockfile, registries),
      relDepPath,
      resolvedDependencies: {
        ...dependencyLockfile.dependencies,
        ...dependencyLockfile.optionalDependencies,
      },
    }
  } else {
    return {
      pkgId: dp.tryGetPackageId(registries, relDepPath) || relDepPath, // Does it make sense to set pkgId when we're not sure?
      relDepPath,
    }
  }
}
github pnpm / pnpm / packages / lockfile-to-pnp / src / index.ts View on Github external
},
        ],
      ])
      packageRegistry.set(name, packageStore)
    }
  }
  for (const [relDepPath, pkgSnapshot] of R.toPairs(lockfile.packages || {})) {
    const { name, version, peersSuffix } = nameVerFromPkgSnapshot(relDepPath, pkgSnapshot)
    const pnpVersion = toPnPVersion(version, peersSuffix)
    let packageStore = packageRegistry.get(name)
    if (!packageStore) {
      packageStore = new Map()
      packageRegistry.set(name, packageStore)
    }

    const packageId = packageIdFromSnapshot(relDepPath, pkgSnapshot, opts.registries)
    // TODO: what about packages that are built?
    // Also, storeController has .getPackageLocation()
    let packageLocation
    if (peersSuffix) {
      packageLocation = path.relative(opts.lockfileDirectory, path.join(
        opts.storeDirectory,
        'virtual',
        `${name}-virtual-${version}_${peersSuffix}`,
      ))
    } else {
      packageLocation = path.relative(opts.lockfileDirectory, path.join(
        opts.storeDirectory,
        pkgIdToFilename(packageId, opts.lockfileDirectory),
        'node_modules',
        name,
      ))
github pnpm / pnpm / packages / modules-cleaner / src / prune.ts View on Github external
function getPkgsDepPaths (
  registries: Registries,
  packages: PackageSnapshots,
): {[depPath: string]: string} {
  const pkgIdsByDepPath = {}
  for (const relDepPath of Object.keys(packages)) {
    const depPath = dp.resolve(registries, relDepPath)
    pkgIdsByDepPath[depPath] = packageIdFromSnapshot(relDepPath, packages[relDepPath], registries)
  }
  return pkgIdsByDepPath
}