How to use @pnpm/core-loggers - 10 common examples

To help you get started, we’ve selected a few @pnpm/core-loggers 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
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 / resolve-dependencies / src / resolveDependencies.ts View on Github external
defaultTag: ctx.defaultTag,
      downloadPriority: -options.currentDepth,
      importerDir: ctx.prefix,
      lockfileDir: ctx.lockfileDir,
      preferredVersions: options.preferredVersions,
      registry: wantedDependency.alias && pickRegistryForPackage(ctx.registries, wantedDependency.alias) || ctx.registries.default,
      sideEffectsCache: ctx.sideEffectsCache,
      // Unfortunately, even when run with --lockfile-only, we need the *real* package.json
      // so fetching of the tarball cannot be ever avoided. Related issue: https://github.com/pnpm/pnpm/issues/1176
      skipFetch: false,
      update,
      workspacePackages: options.workspacePackages,
    })
  } catch (err) {
    if (wantedDependency.optional) {
      skippedOptionalDependencyLogger.debug({
        details: err.toString(),
        package: {
          name: wantedDependency.alias,
          pref: wantedDependency.pref,
          version: wantedDependency.alias ? wantedDependency.pref : undefined,
        },
        parents: nodeIdToParents(createNodeId(options.parentNodeId, 'fake-id'), ctx.resolvedPackagesByPackageId),
        prefix: ctx.prefix,
        reason: 'resolution_failure',
      })
      return null
    }
    throw err
  }

  dependencyResolvedLogger.debug({
github pnpm / pnpm / packages / plugin-commands-rebuild / src / implementation / index.ts View on Github external
}
        await runPostinstallHooks({
          depPath,
          extraBinPaths: ctx.extraBinPaths,
          optional: pkgSnapshot.optional === true,
          pkgRoot,
          prepare: pkgSnapshot.prepare,
          rawConfig: opts.rawConfig,
          rootNodeModulesDir: ctx.rootModulesDir,
          unsafePerm: opts.unsafePerm || false,
        })
        pkgsThatWereRebuilt.add(relDepPath)
      } catch (err) {
        if (pkgSnapshot.optional) {
          // TODO: add parents field to the log
          skippedOptionalDependencyLogger.debug({
            details: err.toString(),
            package: {
              id: pkgSnapshot.id || depPath,
              name: pkgInfo.name,
              version: pkgInfo.version,
            },
            prefix: opts.dir,
            reason: 'build_failure',
          })
          return
        }
        throw err
      }
    }
  ))
github pnpm / pnpm / packages / plugin-commands-recursive / src / recursive.ts View on Github external
// It might make sense to throw an exception in this case
    return false
  }

  const pkgs = Object.values(opts.selectedWsPkgsGraph).map((wsPkg) => wsPkg.package)
  const allPackagesAreSelected = pkgs.length === allWsPkgs.length

  if (pkgs.length === 0) {
    return false
  }
  const manifestsByPath: { [dir: string]: { manifest: ImporterManifest, writeImporterManifest: (manifest: ImporterManifest) => Promise } } = {}
  for (const { dir, manifest, writeImporterManifest } of pkgs) {
    manifestsByPath[dir] = { manifest, writeImporterManifest }
  }

  scopeLogger.debug({
    selected: pkgs.length,
    total: allWsPkgs.length,
    workspacePrefix: opts.workspaceDir,
  })

  const throwOnFail = throwOnCommandFail.bind(null, `pnpm recursive ${cmd}`)

  switch (cmdFullName) {
    case 'why':
    case 'list':
      return list(pkgs, input, cmd, opts as any) // tslint:disable-line:no-any
    case 'outdated':
      return outdated(pkgs, input, cmd, opts as any) // tslint:disable-line:no-any
    case 'add':
      if (!input || !input.length) {
        throw new PnpmError('MISSING_PACKAGE_NAME', '`pnpm recursive add` requires the package name')
github pnpm / pnpm / packages / plugin-commands-installation / src / recursive.ts View on Github external
if (allWsPkgs.length === 0) {
    // It might make sense to throw an exception in this case
    return false
  }

  const pkgs = Object.values(opts.selectedWsPkgsGraph).map((wsPkg) => wsPkg.package)

  if (pkgs.length === 0) {
    return false
  }
  const manifestsByPath: { [dir: string]: Omit } = {}
  for (const { dir, manifest, writeImporterManifest } of pkgs) {
    manifestsByPath[dir] = { manifest, writeImporterManifest }
  }

  scopeLogger.debug({
    selected: pkgs.length,
    total: allWsPkgs.length,
    workspacePrefix: opts.workspaceDir,
  })

  const throwOnFail = throwOnCommandFail.bind(null, `pnpm recursive ${cmdFullName}`)

  const chunks = opts.sort !== false
    ? sortPackages(opts.selectedWsPkgsGraph)
    : [Object.keys(opts.selectedWsPkgsGraph).sort()]

  const store = await createOrConnectStoreController(opts)

  // It is enough to save the store.json file once,
  // once all installations are done.
  // That's why saveState that is passed to the install engine
github pnpm / pnpm / packages / plugin-commands-rebuild / src / recursive.ts View on Github external
if (allWsPkgs.length === 0) {
    // It might make sense to throw an exception in this case
    return
  }

  const pkgs = Object.values(opts.selectedWsPkgsGraph).map((wsPkg) => wsPkg.package)

  if (pkgs.length === 0) {
    return
  }
  const manifestsByPath: { [dir: string]: Omit } = {}
  for (const { dir, manifest, writeImporterManifest } of pkgs) {
    manifestsByPath[dir] = { manifest, writeImporterManifest }
  }

  scopeLogger.debug({
    selected: pkgs.length,
    total: allWsPkgs.length,
    workspacePrefix: opts.workspaceDir,
  })

  const throwOnFail = throwOnCommandFail.bind(null, `pnpm recursive rebuild`)

  const chunks = opts.sort !== false
    ? sortPackages(opts.selectedWsPkgsGraph)
    : [Object.keys(opts.selectedWsPkgsGraph).sort()]

  const store = await createOrConnectStoreController(opts)

  const workspacePackages = arrayOfWorkspacePackagesToMap(allWsPkgs)
  const rebuildOpts = Object.assign(opts, {
    ownLifecycleHooksStdio: 'pipe',
github pnpm / pnpm / packages / pnpm / src / main.ts View on Github external
setTimeout(() => {
      if (config.force === true) {
        logger.warn({
          message: 'using --force I sure hope you know what you are doing',
          prefix: config.dir,
        })
      }

      if (cmd !== 'recursive') {
        scopeLogger.debug(workspaceDir
          ? { selected: 1, workspacePrefix: workspaceDir }
          : { selected: 1 })
      }

      try {
        const result = pnpmCmds[cmd](
          cliArgs,
          // TypeScript doesn't currently infer that the type of config
          // is `Omit` after the `delete config.reporter` statement
          config as Omit,
          argv.remain[0]
        )
        if (result instanceof Promise) {
          result
            .then((output) => {
              if (typeof output === 'string') {
github pnpm / pnpm / packages / modules-cleaner / src / removeDirectDependency.ts View on Github external
opts: {
    binsDir: string,
    dryRun?: boolean,
    modulesDir: string,
    muteLogs?: boolean,
    rootDir: string,
  },
) {
  const results = await Promise.all([
    removeBins(dependency.name, opts),
    !opts.dryRun && remove(path.join(opts.modulesDir, dependency.name)) as any, // tslint:disable-line:no-any
  ])

  const uninstalledPkg = results[0]
  if (!opts.muteLogs) {
    rootLogger.debug({
      prefix: opts.rootDir,
      removed: {
        dependencyType: dependency.dependenciesField === 'devDependencies' && 'dev' ||
          dependency.dependenciesField === 'optionalDependencies' && 'optional' ||
          dependency.dependenciesField === 'dependencies' && 'prod' ||
          undefined,
        name: dependency.name,
        version: uninstalledPkg?.version,
      },
    })
  }
}
github pnpm / pnpm / packages / symlink-dependency / src / symlinkDirectRootDependency.ts View on Github external
destModulesDirReal = await fs.realpath(destModulesDir)
  } catch (err) {
    if (err.code === 'ENOENT') {
      await makeDir(destModulesDir)
      destModulesDirReal = await fs.realpath(destModulesDir)
    } else {
      throw err
    }
  }

  const dependencyRealocation = await fs.realpath(dependencyLocation)

  const dest = path.join(destModulesDirReal, importAs)
  const { reused } = await symlinkDir(dependencyRealocation, dest)
  if (reused) return // if the link was already present, don't log
  rootLogger.debug({
    added: {
      dependencyType: opts.fromDependenciesField && DEP_TYPE_BY_DEPS_FIELD_NAME[opts.fromDependenciesField] as DependencyType,
      linkedFrom: dependencyRealocation,
      name: importAs,
      realName: opts.linkedPackage.name,
      version: opts.linkedPackage.version,
    },
    prefix: opts.prefix,
  })
}
github pnpm / pnpm / packages / modules-cleaner / src / prune.ts View on Github external
const selectedImporterIds = importers.map((importer) => importer.id).sort()
  // In case installation is done on a subset of importers,
  // we may only prune dependencies that are used only by that subset of importers.
  // Otherwise, we would break the node_modules.
  const currentPkgIdsByDepPaths = R.equals(selectedImporterIds, Object.keys(opts.currentLockfile.importers))
    ? getPkgsDepPaths(opts.registries, opts.currentLockfile.packages || {})
    : getPkgsDepPathsOwnedOnlyByImporters(selectedImporterIds, opts.registries, opts.currentLockfile, opts.include, opts.skipped)
  const wantedPkgIdsByDepPaths = getPkgsDepPaths(opts.registries, wantedLockfile.packages || {})

  const oldDepPaths = Object.keys(currentPkgIdsByDepPaths)
  const newDepPaths = Object.keys(wantedPkgIdsByDepPaths)

  const orphanDepPaths = R.difference(oldDepPaths, newDepPaths)
  const orphanPkgIds = new Set(R.props(orphanDepPaths, currentPkgIdsByDepPaths))

  statsLogger.debug({
    prefix: opts.lockfileDir,
    removed: orphanPkgIds.size,
  })

  if (!opts.dryRun) {
    if (orphanDepPaths.length) {
      if (opts.currentLockfile.packages && opts.hoistedModulesDir) {
        const modulesDir = opts.hoistedModulesDir
        const binsDir = path.join(opts.hoistedModulesDir, '.bin')
        const prefix = path.join(opts.virtualStoreDir, '../..')
        await Promise.all(orphanDepPaths.map(async (orphanDepPath) => {
          if (opts.hoistedAliases[orphanDepPath]) {
            await Promise.all(opts.hoistedAliases[orphanDepPath].map((alias) => {
              return removeDirectDependency({
                name: alias,
              }, {