fix(list): don't list unsaved dependencies (#3339)

close #2768
close #3254
This commit is contained in:
Zoltan Kochan
2021-04-13 00:57:49 +03:00
committed by GitHub
parent 561276d2c8
commit 1729f7b99a
6 changed files with 36 additions and 14 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-listing": patch
---
Don't list hoisted dependencies as unsaved dependencies to avoid confusion.

View File

@@ -0,0 +1,5 @@
---
"@pnpm/list": minor
---
New option added: `showExtraneous`. When `showExtraneous` is `false`, unsaved dependencies are not listed.

View File

@@ -14,6 +14,7 @@ const DEFAULTS = {
long: false,
registries: undefined,
reportAs: 'tree' as const,
showExtraneous: true,
}
export async function forPackages (
@@ -59,6 +60,7 @@ export async function forPackages (
depth: opts.depth,
long: opts.long,
search: Boolean(packages.length),
showExtraneous: opts.showExtraneous,
})
}
@@ -72,6 +74,7 @@ export default async function (
include?: { [dependenciesField in DependenciesField]: boolean }
reportAs?: 'parseable' | 'tree' | 'json'
registries?: Registries
showExtraneous?: boolean
}
) {
const opts = { ...DEFAULTS, ...maybeOpts }
@@ -108,6 +111,7 @@ export default async function (
depth: opts.depth,
long: opts.long,
search: false,
showExtraneous: opts.showExtraneous,
})
}

View File

@@ -17,14 +17,17 @@ const NOT_SAVED_DEP_CLR = chalk.red
const LEGEND = `Legend: ${PROD_DEP_CLR('production dependency')}, ${OPTIONAL_DEP_CLR('optional only')}, ${DEV_DEP_ONLY_CLR('dev only')}\n\n`
export interface RenderTreeOptions {
alwaysPrintRootPackage: boolean
depth: number
long: boolean
search: boolean
showExtraneous: boolean
}
export default async function (
packages: PackageDependencyHierarchy[],
opts: {
alwaysPrintRootPackage: boolean
depth: number
long: boolean
search: boolean
}
opts: RenderTreeOptions
) {
const output = (
await Promise.all(packages.map(async (pkg) => renderTreeForPackage(pkg, opts)))
@@ -36,19 +39,14 @@ export default async function (
async function renderTreeForPackage (
pkg: PackageDependencyHierarchy,
opts: {
alwaysPrintRootPackage: boolean
depth: number
long: boolean
search: boolean
}
opts: RenderTreeOptions
) {
if (
!opts.alwaysPrintRootPackage &&
!pkg.dependencies?.length &&
!pkg.devDependencies?.length &&
!pkg.optionalDependencies?.length &&
!pkg.unsavedDependencies?.length
(!opts.showExtraneous || !pkg.unsavedDependencies?.length)
) return ''
let label = ''
@@ -62,7 +60,13 @@ async function renderTreeForPackage (
label += pkg.path
let output = `${chalk.bold.underline(label)}\n`
const useColumns = opts.depth === 0 && !opts.long && !opts.search
for (const dependenciesField of [...DEPENDENCIES_FIELDS.sort(), 'unsavedDependencies']) {
const dependenciesFields: string[] = [
...DEPENDENCIES_FIELDS.sort(),
]
if (opts.showExtraneous) {
dependenciesFields.push('unsavedDependencies')
}
for (const dependenciesField of dependenciesFields) {
if (pkg[dependenciesField]?.length) {
const depsLabel = chalk.cyanBright(
dependenciesField !== 'unsavedDependencies'

View File

@@ -465,6 +465,7 @@ test('unsaved dependencies are marked', async () => {
depth: 0,
long: false,
search: true,
showExtraneous: true,
}
)).toBe(`${LEGEND}
@@ -590,6 +591,7 @@ test('write long lists in columns', async () => {
depth: 0,
long: false,
search: false,
showExtraneous: false,
}
)).toBe(`${LEGEND}
@@ -658,6 +660,7 @@ test('sort list items', async () => {
depth: 0,
long: false,
search: false,
showExtraneous: false,
}
)).toBe(`${LEGEND}

View File

@@ -167,6 +167,7 @@ export async function render (
long: opts.long,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
reportAs: (opts.parseable ? 'parseable' : (opts.json ? 'json' : 'tree')) as ('parseable' | 'json' | 'tree'),
showExtraneous: false,
}
return (params.length > 0)
? listForPackages(params, prefixes, listOpts)