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:
niceSprite
2021-01-27 20:03:24 +08:00
committed by GitHub
parent e97b9ac8ac
commit c70f36678f
8 changed files with 59 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/list": patch
"@pnpm/plugin-commands-listing": patch
---
Remove redundant empty lines when run `pnpm why --parseable`

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1,7 @@
{
"name": "bar",
"version": "0.0.0",
"dependencies": {
"is-positive": "3.1.0"
}
}

View File

@@ -0,0 +1,6 @@
{
"name": "foo",
"version": "0.0.0",
"dependencies": {
}
}

View 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=

View File

@@ -0,0 +1,2 @@
packages:
- 'packages/**'

View File

@@ -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 (

View File

@@ -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