mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-11 17:42:43 -04:00
fix(list): don't list unsaved dependencies (#3339)
close #2768 close #3254
This commit is contained in:
5
.changeset/brave-nails-destroy.md
Normal file
5
.changeset/brave-nails-destroy.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-listing": patch
|
||||
---
|
||||
|
||||
Don't list hoisted dependencies as unsaved dependencies to avoid confusion.
|
||||
5
.changeset/violet-cups-swim.md
Normal file
5
.changeset/violet-cups-swim.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/list": minor
|
||||
---
|
||||
|
||||
New option added: `showExtraneous`. When `showExtraneous` is `false`, unsaved dependencies are not listed.
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user