How to use @pnpm/read-modules-dir - 3 common examples

To help you get started, we’ve selected a few @pnpm/read-modules-dir 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
wantedDependencies: [],
          })
          break
        case 'install': {
          await installCase(importer)
          break
        }
        case 'installSome': {
          await installSome({
            ...importer,
            updatePackageManifest: true,
          })
          break
        }
        case 'unlink': {
          const packageDirs = await readModulesDirs(importer.modulesDir)
          const externalPackages = await pFilter(
            packageDirs!,
            (packageDir: string) => isExternalLink(ctx.storeDir, importer.modulesDir, packageDir),
          )
          const allDeps = getAllDependenciesFromPackage(importer.manifest)
          const packagesToInstall: string[] = []
          for (const pkgName of externalPackages) {
            await rimraf(path.join(importer.modulesDir, pkgName))
            if (allDeps[pkgName]) {
              packagesToInstall.push(pkgName)
            }
          }
          if (!packagesToInstall.length) return importers

          // TODO: install only those that were unlinked
          // but don't update their version specs in package.json
github pnpm / pnpm / packages / modules-cleaner / src / prune.ts View on Github external
await Promise.all(importers.map(async ({ binsDir, id, modulesDir, pruneDirectDependencies, removePackages, rootDir }) => {
    const currentImporter = opts.currentLockfile.importers[id] || {} as LockfileImporter
    const currentPkgs = R.toPairs(mergeDependencies(currentImporter))
    const wantedPkgs = R.toPairs(mergeDependencies(wantedLockfile.importers[id]))

    const allCurrentPackages = new Set(
      (pruneDirectDependencies || removePackages?.length)
        ? (await readModulesDir(modulesDir) || [])
        : [],
    )
    const depsToRemove = new Set([
      ...(removePackages || []).filter((removePackage) => allCurrentPackages.has(removePackage)),
      ...R.difference(currentPkgs, wantedPkgs).map(([depName]) => depName),
    ])
    if (pruneDirectDependencies) {
      if (allCurrentPackages.size > 0) {
        const newPkgsSet = new Set(wantedPkgs.map(([depName]) => depName))
        for (const currentPackage of Array.from(allCurrentPackages)) {
          if (!newPkgsSet.has(currentPackage)) {
            depsToRemove.add(currentPackage)
          }
        }
      }
    }
github pnpm / pnpm / packages / supi / src / unlink / index.ts View on Github external
export async function unlink (maybeOpts: InstallOptions) {
  const reporter = maybeOpts && maybeOpts.reporter
  if (reporter) {
    streamParser.on('data', reporter)
  }
  const opts = await _extendOptions(maybeOpts)
  const ctx = await getContext(opts)
  opts.store = ctx.storePath

  if (ctx.importers.length > 1) throw new Error('Unlink not implemented for multiple importers yet')
  const importer = ctx.importers[0]

  const packageDirs = await readModulesDirs(importer.modulesDir)
  const externalPackages = await pFilter(
    packageDirs,
    (packageDir: string) => isExternalLink(opts.store, importer.modulesDir, packageDir),
  )

  await _unlinkPkgs(externalPackages, opts, ctx.importers)

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

@pnpm/read-modules-dir

Finds all direct packages in node_modules

MIT
Latest version published 7 months ago

Package Health Score

61 / 100
Full package analysis

Popular @pnpm/read-modules-dir functions

Similar packages