How to use @pnpm/get-context - 4 common examples

To help you get started, we’ve selected a few @pnpm/get-context 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 / link / index.ts View on Github external
export default async function link (
  linkFromPkgs: Array<{alias: string, path: string} | string>,
  destModules: string,
  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
github pnpm / pnpm / packages / supi / src / install / index.ts View on Github external
maybeOpts: InstallOptions & {
    preferredVersions?: PreferredVersions,
  },
) {
  const reporter = maybeOpts?.reporter
  if (reporter) {
    streamParser.on('data', reporter)
  }

  const opts = await extendOptions(maybeOpts)

  if (!opts.include.dependencies && opts.include.optionalDependencies) {
    throw new PnpmError('OPTIONAL_DEPS_REQUIRE_PROD_DEPS', 'Optional dependencies cannot be installed without production dependencies')
  }

  const ctx = await getContext(importers, opts)

  for (const { manifest, rootDir } of ctx.importers) {
    if (!manifest) {
      throw new Error(`No package.json found in "${rootDir}"`)
    }
  }

  let result!: Array<{ rootDir: string, manifest: ImporterManifest }>
  try {
    if (opts.lock) {
      result = await lock(ctx.lockfileDir, _install, {
        locks: opts.locks,
        prefix: ctx.lockfileDir,
        stale: opts.lockStaleDuration,
        storeController: opts.storeController,
      })
github pnpm / pnpm / packages / plugin-commands-rebuild / src / implementation / index.ts View on Github external
export async function rebuild (
  importers: Array<{ buildIndex: number, manifest: ImporterManifest, rootDir: string }>,
  maybeOpts: RebuildOptions,
) {
  const reporter = maybeOpts?.reporter
  if (reporter) {
    streamParser.on('data', reporter)
  }
  const opts = await extendOptions(maybeOpts)
  const ctx = await getContext(importers, opts)

  let idsToRebuild: string[] = []

  if (opts.pending) {
    idsToRebuild = ctx.pendingBuilds
  } else if (ctx.currentLockfile?.packages) {
    idsToRebuild = Object.keys(ctx.currentLockfile.packages)
  }

  const pkgsThatWereRebuilt = await _rebuild(
    {
      pkgsToRebuild: new Set(idsToRebuild),
      ...ctx,
    },
    opts,
  )
github pnpm / pnpm / packages / plugin-commands-rebuild / src / implementation / index.ts View on Github external
export async function rebuildPkgs (
  importers: Array<{ manifest: ImporterManifest, rootDir: string }>,
  pkgSpecs: string[],
  maybeOpts: RebuildOptions,
) {
  const reporter = maybeOpts?.reporter
  if (reporter) {
    streamParser.on('data', reporter)
  }
  const opts = await extendOptions(maybeOpts)
  const ctx = await getContext(importers, opts)

  if (!ctx.currentLockfile || !ctx.currentLockfile.packages) return
  const packages = ctx.currentLockfile.packages

  const searched: PackageSelector[] = pkgSpecs.map((arg) => {
    const { fetchSpec, name, raw, type } = npa(arg)
    if (raw === name) {
      return name
    }
    if (type !== 'version' && type !== 'range') {
      throw new Error(`Invalid argument - ${arg}. Rebuild can only select by version or range`)
    }
    return {
      name,
      range: fetchSpec,
    }

@pnpm/get-context

Gets context information about a project

MIT
Latest version published 8 days ago

Package Health Score

57 / 100
Full package analysis