fix: pnpm oudtated --long

PR #2828
This commit is contained in:
Zoltan Kochan
2020-09-04 16:12:03 +03:00
committed by GitHub
parent cc4761f905
commit 1c2a8e03d8
12 changed files with 100 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-outdated": patch
---
`pnpm outdated --long` should print details about the outdated dependency.

View File

@@ -0,0 +1,5 @@
---
"@pnpm/outdated": minor
---
`outdatedDepsOfProjects()` accepts a new option: `fullMetadata`. When `fullMetadata` is `true`, the full version of the package's latest manifest is returned.

View File

@@ -0,0 +1 @@
!node_modules

View File

@@ -0,0 +1 @@
shared-workspace-lockfile=false

View File

@@ -0,0 +1,18 @@
hoistPattern:
- '*'
hoistedDependencies: {}
included:
dependencies: true
devDependencies: true
optionalDependencies: true
layoutVersion: 4
packageManager: pnpm@5.5.10
pendingBuilds: []
publicHoistPattern:
- '@types/*'
- '*eslint*'
registries:
default: 'https://registry.npmjs.org/'
skipped: []
storeDir: /home/zoltan/.pnpm-store/v3
virtualStoreDir: .pnpm

View File

@@ -0,0 +1,10 @@
{
"name": "has-2-outdated-deps",
"version": "1.0.0",
"dependencies": {
"is-negative": "^1.0.0"
},
"devDependencies": {
"is-positive": "^1.0.0"
}
}

View File

@@ -0,0 +1,21 @@
dependencies:
is-negative: 1.0.1
devDependencies:
is-positive: 1.0.0
lockfileVersion: 5.1
packages:
/is-negative/1.0.1:
dev: false
engines:
node: '>=0.10.0'
resolution:
integrity: sha1-3GuHKO69A8db+HYIftzVDpy1aZQ=
/is-positive/1.0.0:
dev: true
engines:
node: '>=0.10.0'
resolution:
integrity: sha1-iACYVrZKLx632LsBeUGEJK4EUss=
specifiers:
is-negative: ^1.0.0
is-positive: ^1.0.0

View File

@@ -15,7 +15,7 @@ interface GetManifestOpts {
export type ManifestGetterOptions = Omit<ClientOptions, 'authConfig'>
& GetManifestOpts
& { rawConfig: Record<string, string> }
& { fullMetadata: boolean, rawConfig: Record<string, string> }
export function createManifestGetter (
opts: ManifestGetterOptions

View File

@@ -17,10 +17,10 @@ import R = require('ramda')
export default async function outdatedDepsOfProjects (
pkgs: Array<{dir: string, manifest: ProjectManifest}>,
args: string[],
opts: Omit<ManifestGetterOptions, 'storeDir' | 'lockfileDir'> & {
opts: Omit<ManifestGetterOptions, 'fullMetadata' | 'storeDir' | 'lockfileDir'> & {
compatible?: boolean
include: IncludedDependencies
} & Partial<Pick<ManifestGetterOptions, 'storeDir' | 'lockfileDir'>>
} & Partial<Pick<ManifestGetterOptions, 'fullMetadata' | 'storeDir' | 'lockfileDir'>>
): Promise<OutdatedPackage[][]> {
if (!opts.lockfileDir) {
return R.unnest(await Promise.all(
@@ -37,6 +37,7 @@ export default async function outdatedDepsOfProjects (
const storeDir = await storePath(opts.dir, opts.storeDir)
const getLatestManifest = createManifestGetter({
...opts,
fullMetadata: opts.fullMetadata === true,
lockfileDir,
storeDir,
})

View File

@@ -171,7 +171,11 @@ export async function handler (
manifest: await readProjectManifestOnly(opts.dir, opts),
},
]
const [outdatedPackages] = (await outdatedDepsOfProjects(packages, params, { ...opts, include }))
const [outdatedPackages] = await outdatedDepsOfProjects(packages, params, {
...opts,
fullMetadata: opts.long,
include,
})
if (!outdatedPackages.length) return { output: '', exitCode: 0 }

View File

@@ -49,7 +49,7 @@ export default async (
opts: OutdatedCommandOptions & { include: IncludedDependencies }
) => {
const outdatedMap = {} as Record<string, OutdatedInWorkspace>
const outdatedPackagesByProject = await outdatedDepsOfProjects(pkgs, params, opts)
const outdatedPackagesByProject = await outdatedDepsOfProjects(pkgs, params, { ...opts, fullMetadata: opts.long })
for (let i = 0; i < outdatedPackagesByProject.length; i++) {
const { dir, manifest } = pkgs[i]
outdatedPackagesByProject[i].forEach((outdatedPkg) => {

View File

@@ -12,6 +12,7 @@ import test = require('tape')
const fixtures = path.join(__dirname, '../../../fixtures')
const hasOutdatedDepsFixture = path.join(fixtures, 'has-outdated-deps')
const has2OutdatedDepsFixture = path.join(fixtures, 'has-2-outdated-deps')
const hasOutdatedDepsFixtureAndExternalLockfile = path.join(fixtures, 'has-outdated-deps-and-external-shrinkwrap', 'pkg')
const hasNotOutdatedDepsFixture = path.join(fixtures, 'has-not-outdated-deps')
const hasMajorOutdatedDepsFixture = path.join(fixtures, 'has-major-outdated-deps')
@@ -66,6 +67,34 @@ test('pnpm outdated: show details', async (t) => {
t.end()
})
test('pnpm outdated: show details (using the public registry to verify that full metadata is being requested)', async (t) => {
tempDir(t)
await fs.mkdir(path.resolve('node_modules/.pnpm'), { recursive: true })
await fs.copyFile(path.join(has2OutdatedDepsFixture, 'node_modules/.pnpm/lock.yaml'), path.resolve('node_modules/.pnpm/lock.yaml'))
await fs.copyFile(path.join(has2OutdatedDepsFixture, 'package.json'), path.resolve('package.json'))
const { output, exitCode } = await outdated.handler({
...OUTDATED_OPTIONS,
dir: process.cwd(),
long: true,
rawConfig: { registry: 'https://registry.npmjs.org/' },
registries: { default: 'https://registry.npmjs.org/' },
})
t.equal(exitCode, 1)
t.equal(stripAnsi(output), `\
┌───────────────────┬─────────┬────────┬─────────────────────────────────────────────┐
│ Package │ Current │ Latest │ Details │
├───────────────────┼─────────┼────────┼─────────────────────────────────────────────┤
│ is-negative │ 1.0.1 │ 2.1.0 │ https://github.com/kevva/is-negative#readme │
├───────────────────┼─────────┼────────┼─────────────────────────────────────────────┤
│ is-positive (dev) │ 1.0.0 │ 3.1.0 │ https://github.com/kevva/is-positive#readme │
└───────────────────┴─────────┴────────┴─────────────────────────────────────────────┘
`)
t.end()
})
test('pnpm outdated: showing only prod or dev dependencies', async (t) => {
tempDir(t)