From c70f36678f723861a1c64df9b28bcaeae774d2cc Mon Sep 17 00:00:00 2001 From: niceSprite Date: Wed, 27 Jan 2021 20:03:24 +0800 Subject: [PATCH] fix: pnpm recursive list/why with parseable render produce needless newlines (#3101) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: pnpm why --parseable filter empty string * docs: ✏️ run changeset * test: add test for list monorepo with parseable --- .changeset/eleven-panthers-agree.md | 6 ++++++ .../workspace-with-different-deps/package.json | 1 + .../packages/bar/package.json | 7 +++++++ .../packages/foo/package.json | 6 ++++++ .../pnpm-lock.yaml | 18 ++++++++++++++++++ .../pnpm-workspace.yaml | 2 ++ packages/list/src/renderParseable.ts | 2 +- packages/list/test/index.ts | 18 ++++++++++++++++++ 8 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 .changeset/eleven-panthers-agree.md create mode 100644 fixtures/workspace-with-different-deps/package.json create mode 100644 fixtures/workspace-with-different-deps/packages/bar/package.json create mode 100644 fixtures/workspace-with-different-deps/packages/foo/package.json create mode 100644 fixtures/workspace-with-different-deps/pnpm-lock.yaml create mode 100644 fixtures/workspace-with-different-deps/pnpm-workspace.yaml diff --git a/.changeset/eleven-panthers-agree.md b/.changeset/eleven-panthers-agree.md new file mode 100644 index 0000000000..27985de2cf --- /dev/null +++ b/.changeset/eleven-panthers-agree.md @@ -0,0 +1,6 @@ +--- +"@pnpm/list": patch +"@pnpm/plugin-commands-listing": patch +--- + +Remove redundant empty lines when run `pnpm why --parseable` diff --git a/fixtures/workspace-with-different-deps/package.json b/fixtures/workspace-with-different-deps/package.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/fixtures/workspace-with-different-deps/package.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/fixtures/workspace-with-different-deps/packages/bar/package.json b/fixtures/workspace-with-different-deps/packages/bar/package.json new file mode 100644 index 0000000000..ff981108b5 --- /dev/null +++ b/fixtures/workspace-with-different-deps/packages/bar/package.json @@ -0,0 +1,7 @@ +{ + "name": "bar", + "version": "0.0.0", + "dependencies": { + "is-positive": "3.1.0" + } +} diff --git a/fixtures/workspace-with-different-deps/packages/foo/package.json b/fixtures/workspace-with-different-deps/packages/foo/package.json new file mode 100644 index 0000000000..a3e625ce11 --- /dev/null +++ b/fixtures/workspace-with-different-deps/packages/foo/package.json @@ -0,0 +1,6 @@ +{ + "name": "foo", + "version": "0.0.0", + "dependencies": { + } +} diff --git a/fixtures/workspace-with-different-deps/pnpm-lock.yaml b/fixtures/workspace-with-different-deps/pnpm-lock.yaml new file mode 100644 index 0000000000..b6c65e3ad9 --- /dev/null +++ b/fixtures/workspace-with-different-deps/pnpm-lock.yaml @@ -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= diff --git a/fixtures/workspace-with-different-deps/pnpm-workspace.yaml b/fixtures/workspace-with-different-deps/pnpm-workspace.yaml new file mode 100644 index 0000000000..eccc335f93 --- /dev/null +++ b/fixtures/workspace-with-different-deps/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +packages: + - 'packages/**' \ No newline at end of file diff --git a/packages/list/src/renderParseable.ts b/packages/list/src/renderParseable.ts index 1574c07cec..7cd639cf7f 100644 --- a/packages/list/src/renderParseable.ts +++ b/packages/list/src/renderParseable.ts @@ -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 ( diff --git a/packages/list/test/index.ts b/packages/list/test/index.ts index 2503a1a12f..26a900cd4a 100644 --- a/packages/list/test/index.ts +++ b/packages/list/test/index.ts @@ -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