mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-12 01:54:53 -04:00
fix: pnpm recursive list/why with parseable render produce needless newlines (#3101)
* fix: pnpm why --parseable filter empty string
* docs: ✏️ run changeset
* test: add test for list monorepo with parseable
This commit is contained in:
6
.changeset/eleven-panthers-agree.md
Normal file
6
.changeset/eleven-panthers-agree.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/list": patch
|
||||
"@pnpm/plugin-commands-listing": patch
|
||||
---
|
||||
|
||||
Remove redundant empty lines when run `pnpm why --parseable`
|
||||
1
fixtures/workspace-with-different-deps/package.json
Normal file
1
fixtures/workspace-with-different-deps/package.json
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "bar",
|
||||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"is-positive": "3.1.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "foo",
|
||||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
}
|
||||
}
|
||||
18
fixtures/workspace-with-different-deps/pnpm-lock.yaml
generated
Normal file
18
fixtures/workspace-with-different-deps/pnpm-lock.yaml
generated
Normal file
@@ -0,0 +1,18 @@
|
||||
importers:
|
||||
.:
|
||||
specifiers: {}
|
||||
packages/bar:
|
||||
dependencies:
|
||||
is-positive: 3.1.0
|
||||
specifiers:
|
||||
is-positive: 3.1.0
|
||||
packages/foo:
|
||||
specifiers: {}
|
||||
lockfileVersion: 5.2
|
||||
packages:
|
||||
/is-positive/3.1.0:
|
||||
dev: false
|
||||
engines:
|
||||
node: '>=0.10.0'
|
||||
resolution:
|
||||
integrity: sha1-hX21hKG6XRyymAUn/DtsQ103sP0=
|
||||
@@ -0,0 +1,2 @@
|
||||
packages:
|
||||
- 'packages/**'
|
||||
@@ -13,7 +13,7 @@ export default async function (
|
||||
search: boolean
|
||||
}
|
||||
) {
|
||||
return pkgs.map((pkg) => renderParseableForPackage(pkg, opts)).join('\n')
|
||||
return pkgs.map((pkg) => renderParseableForPackage(pkg, opts)).filter(p => p.length !== 0).join('\n')
|
||||
}
|
||||
|
||||
function renderParseableForPackage (
|
||||
|
||||
@@ -26,6 +26,7 @@ const fixtureWithNoPkgNameAndNoVersion = path.join(fixtures, 'fixture-with-no-pk
|
||||
const fixtureWithNoPkgVersion = path.join(fixtures, 'fixture-with-no-pkg-version')
|
||||
const fixtureWithExternalLockfile = path.join(fixtures, 'fixture-with-external-shrinkwrap', 'pkg')
|
||||
const workspaceWith2Pkgs = path.join(fixtures, 'workspace-with-2-pkgs')
|
||||
const workspaceWithDifferentDeps = path.join(fixtures, 'workspace-with-different-deps')
|
||||
const emptyFixture = path.join(fixtures, 'empty')
|
||||
const fixtureWithAliasedDep = path.join(fixtures, 'with-aliased-dep')
|
||||
|
||||
@@ -367,6 +368,23 @@ ${path.join(fixture, 'node_modules/.pnpm/is-positive@3.1.0')}`
|
||||
)
|
||||
})
|
||||
|
||||
test('parseable list with depth 1 without unnecessary empty newlines', async () => {
|
||||
expect(await listForPackages(
|
||||
['is-positive'],
|
||||
[
|
||||
path.join(workspaceWithDifferentDeps, 'packages/bar'),
|
||||
path.join(workspaceWithDifferentDeps, 'packages/foo'),
|
||||
], {
|
||||
alwaysPrintRootPackage: false,
|
||||
lockfileDir: workspaceWithDifferentDeps,
|
||||
depth: 1,
|
||||
reportAs: 'parseable',
|
||||
}
|
||||
)).toBe(`${path.join(workspaceWithDifferentDeps, 'packages/bar')}
|
||||
${path.join(workspaceWithDifferentDeps, 'packages/bar', 'node_modules/.pnpm/is-positive@3.1.0')}`
|
||||
)
|
||||
})
|
||||
|
||||
test('long parseable list with depth 1', async () => {
|
||||
expect(await list([fixture], { reportAs: 'parseable', depth: 1, lockfileDir: fixture, long: true })).toBe(`${fixture}:fixture@1.0.0
|
||||
${path.join(fixture, 'node_modules/.pnpm/detect-indent@5.0.0')}:detect-indent@5.0.0
|
||||
|
||||
Reference in New Issue
Block a user