diff --git a/.changeset/brave-nails-destroy.md b/.changeset/brave-nails-destroy.md new file mode 100644 index 0000000000..edbbd3c82a --- /dev/null +++ b/.changeset/brave-nails-destroy.md @@ -0,0 +1,5 @@ +--- +"@pnpm/plugin-commands-listing": patch +--- + +Don't list hoisted dependencies as unsaved dependencies to avoid confusion. diff --git a/.changeset/violet-cups-swim.md b/.changeset/violet-cups-swim.md new file mode 100644 index 0000000000..9647e51ca0 --- /dev/null +++ b/.changeset/violet-cups-swim.md @@ -0,0 +1,5 @@ +--- +"@pnpm/list": minor +--- + +New option added: `showExtraneous`. When `showExtraneous` is `false`, unsaved dependencies are not listed. diff --git a/packages/list/src/index.ts b/packages/list/src/index.ts index cbcab0bed0..7d1f1778da 100644 --- a/packages/list/src/index.ts +++ b/packages/list/src/index.ts @@ -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, }) } diff --git a/packages/list/src/renderTree.ts b/packages/list/src/renderTree.ts index 324d307511..5f01159e2e 100644 --- a/packages/list/src/renderTree.ts +++ b/packages/list/src/renderTree.ts @@ -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' diff --git a/packages/list/test/index.ts b/packages/list/test/index.ts index 356231e2a3..921b737944 100644 --- a/packages/list/test/index.ts +++ b/packages/list/test/index.ts @@ -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} diff --git a/packages/plugin-commands-listing/src/list.ts b/packages/plugin-commands-listing/src/list.ts index 8083752164..cf4e31a6ff 100644 --- a/packages/plugin-commands-listing/src/list.ts +++ b/packages/plugin-commands-listing/src/list.ts @@ -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)