feat: interactive update with many lockfiles
Interactive update should work on a workspace that uses dedicated pnpm-lock.yaml file per each project. ref #2271
This commit is contained in:
4 files changed
+25
-26
No files matched your search
@@ -52,12 +52,14 @@
|
||||
"@pnpm/utils": "workspace:0.12.3",
|
||||
"dependency-path": "workspace:4.0.3",
|
||||
"lru-cache": "5.1.1",
|
||||
"ramda": "0.26.1",
|
||||
"semver": "7.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@pnpm/logger": "3.1.0",
|
||||
"@pnpm/outdated": "link:",
|
||||
"@types/lru-cache": "^5.1.0",
|
||||
"@types/ramda": "^0.26.39",
|
||||
"@types/semver": "^6.2.0",
|
||||
"npm-run-all": "4.1.5"
|
||||
}
|
||||
|
||||
@@ -13,8 +13,9 @@ import {
|
||||
ProjectManifest,
|
||||
} from '@pnpm/types'
|
||||
import path = require('path')
|
||||
import R = require('ramda')
|
||||
import { createManifestGetter, ManifestGetterOptions } from './createManifestGetter'
|
||||
import outdated from './outdated'
|
||||
import outdated, { OutdatedPackage } from './outdated'
|
||||
|
||||
export default async function outdatedDepsOfProjects (
|
||||
pkgs: Array<{dir: string, manifest: ProjectManifest}>,
|
||||
@@ -23,7 +24,14 @@ export default async function outdatedDepsOfProjects (
|
||||
compatible?: boolean,
|
||||
include: IncludedDependencies,
|
||||
} & Partial<Pick<ManifestGetterOptions, 'storeDir' | 'lockfileDir'>>,
|
||||
) {
|
||||
): Promise<Array<{ manifest: ProjectManifest, outdatedPackages: OutdatedPackage[], prefix: string }>> {
|
||||
if (!opts.lockfileDir) {
|
||||
return R.unnest(await Promise.all(
|
||||
pkgs.map((pkg) =>
|
||||
outdatedDepsOfProjects([pkg], args, { ...opts, lockfileDir: pkg.dir }),
|
||||
),
|
||||
))
|
||||
}
|
||||
const lockfileDir = opts.lockfileDir ?? opts.dir
|
||||
const modules = await readModulesManifest(path.join(lockfileDir, 'node_modules'))
|
||||
const virtualStoreDir = modules?.virtualStoreDir ?? path.join(lockfileDir, 'node_modules/.pnpm')
|
||||
|
||||
@@ -51,30 +51,15 @@ export default async (
|
||||
opts: OutdatedCommandOptions & { include: IncludedDependencies },
|
||||
) => {
|
||||
const outdatedMap = {} as Record<string, OutdatedInWorkspace>
|
||||
if (opts.lockfileDir) {
|
||||
const outdatedPackagesByProject = await outdatedDepsOfProjects(pkgs, args, opts)
|
||||
for (let { prefix, outdatedPackages, manifest } of outdatedPackagesByProject) {
|
||||
outdatedPackages.forEach((outdatedPkg) => {
|
||||
const key = JSON.stringify([outdatedPkg.packageName, outdatedPkg.current, outdatedPkg.belongsTo])
|
||||
if (!outdatedMap[key]) {
|
||||
outdatedMap[key] = { ...outdatedPkg, dependentPkgs: [] }
|
||||
}
|
||||
outdatedMap[key].dependentPkgs.push({ location: prefix, manifest })
|
||||
})
|
||||
}
|
||||
} else {
|
||||
await Promise.all(pkgs.map(async ({ dir, manifest }) => {
|
||||
const { outdatedPackages } = (
|
||||
await outdatedDepsOfProjects([{ manifest, dir }], args, { ...opts, lockfileDir: dir })
|
||||
)[0]
|
||||
outdatedPackages.forEach((outdatedPkg) => {
|
||||
const key = JSON.stringify([outdatedPkg.packageName, outdatedPkg.current, outdatedPkg.belongsTo])
|
||||
if (!outdatedMap[key]) {
|
||||
outdatedMap[key] = { ...outdatedPkg, dependentPkgs: [] }
|
||||
}
|
||||
outdatedMap[key].dependentPkgs.push({ location: getLockfileImporterId(opts.dir, dir), manifest })
|
||||
})
|
||||
}))
|
||||
const outdatedPackagesByProject = await outdatedDepsOfProjects(pkgs, args, opts)
|
||||
for (let { prefix, outdatedPackages, manifest } of outdatedPackagesByProject) {
|
||||
outdatedPackages.forEach((outdatedPkg) => {
|
||||
const key = JSON.stringify([outdatedPkg.packageName, outdatedPkg.current, outdatedPkg.belongsTo])
|
||||
if (!outdatedMap[key]) {
|
||||
outdatedMap[key] = { ...outdatedPkg, dependentPkgs: [] }
|
||||
}
|
||||
outdatedMap[key].dependentPkgs.push({ location: prefix, manifest })
|
||||
})
|
||||
}
|
||||
|
||||
if (R.isEmpty(outdatedMap)) return ''
|
||||
|
||||
Generated
+4
@@ -1104,11 +1104,13 @@ importers:
|
||||
'@pnpm/utils': 'link:../utils'
|
||||
dependency-path: 'link:../dependency-path'
|
||||
lru-cache: 5.1.1
|
||||
ramda: 0.26.1
|
||||
semver: 7.1.1
|
||||
devDependencies:
|
||||
'@pnpm/logger': 3.1.0
|
||||
'@pnpm/outdated': 'link:'
|
||||
'@types/lru-cache': 5.1.0
|
||||
'@types/ramda': 0.26.39
|
||||
'@types/semver': 6.2.0
|
||||
npm-run-all: 4.1.5
|
||||
specifiers:
|
||||
@@ -1126,10 +1128,12 @@ importers:
|
||||
'@pnpm/types': 'workspace:5.0.0'
|
||||
'@pnpm/utils': 'workspace:0.12.3'
|
||||
'@types/lru-cache': ^5.1.0
|
||||
'@types/ramda': ^0.26.39
|
||||
'@types/semver': ^6.2.0
|
||||
dependency-path: 'workspace:4.0.3'
|
||||
lru-cache: 5.1.1
|
||||
npm-run-all: 4.1.5
|
||||
ramda: 0.26.1
|
||||
semver: 7.1.1
|
||||
packages/package-bins:
|
||||
dependencies:
|
||||
|
||||
Reference in new issue
Block a user