From ff61290417a18c8f544785fba10e92b96043447b Mon Sep 17 00:00:00 2001 From: Yao Ding Date: Mon, 25 Jan 2021 10:17:16 -0500 Subject: [PATCH] feat: print an info message when there is no new packages to publish recursively (#3099) * feat: print an info message when there is no new packages to publish recursively * feat: use publishedPkgDirs to check close #2775 --- .changeset/afraid-dryers-sin.md | 5 ++ .../plugin-commands-publishing/package.json | 4 ++ .../src/recursivePublish.ts | 8 +++ .../test/recursivePublish.ts | 55 +++++++++++++++++++ pnpm-lock.yaml | 2 + 5 files changed, 74 insertions(+) create mode 100644 .changeset/afraid-dryers-sin.md diff --git a/.changeset/afraid-dryers-sin.md b/.changeset/afraid-dryers-sin.md new file mode 100644 index 0000000000..7f487d3679 --- /dev/null +++ b/.changeset/afraid-dryers-sin.md @@ -0,0 +1,5 @@ +--- +"@pnpm/plugin-commands-publishing": minor +--- + +feat: print an info message when there's nothing new to publish recursively diff --git a/packages/plugin-commands-publishing/package.json b/packages/plugin-commands-publishing/package.json index 66c269e4a2..899eb9bf5f 100644 --- a/packages/plugin-commands-publishing/package.json +++ b/packages/plugin-commands-publishing/package.json @@ -35,6 +35,7 @@ "homepage": "https://github.com/pnpm/pnpm/blob/master/packages/plugin-commands-publishing#readme", "devDependencies": { "@pnpm/filter-workspace-packages": "workspace:2.3.6", + "@pnpm/logger": "^3.2.3", "@pnpm/prepare": "workspace:0.0.17", "@types/cross-spawn": "^6.0.2", "@types/mz": "^2.7.3", @@ -71,5 +72,8 @@ "render-help": "^1.0.1", "write-json-file": "^4.3.0" }, + "peerDependencies": { + "@pnpm/logger": "^3.2.3" + }, "funding": "https://opencollective.com/pnpm" } diff --git a/packages/plugin-commands-publishing/src/recursivePublish.ts b/packages/plugin-commands-publishing/src/recursivePublish.ts index 28f262bfce..ea367f8a50 100644 --- a/packages/plugin-commands-publishing/src/recursivePublish.ts +++ b/packages/plugin-commands-publishing/src/recursivePublish.ts @@ -1,5 +1,6 @@ import { createResolver } from '@pnpm/client' import { Config } from '@pnpm/config' +import logger from '@pnpm/logger' import pickRegistryForPackage from '@pnpm/pick-registry-for-package' import { ResolveFunction } from '@pnpm/resolver-base' import sortPackages from '@pnpm/sort-packages' @@ -64,6 +65,13 @@ export default async function ( }, pkg.manifest.name, pkg.manifest.version)) }) const publishedPkgDirs = new Set(pkgsToPublish.map(({ dir }) => dir)) + if (publishedPkgDirs.size === 0) { + logger.info({ + message: 'There are no new packages that should be published', + prefix: opts.dir, + }) + return + } const appendedArgs = [] if (opts.cliOptions['access']) { appendedArgs.push(`--access=${opts.cliOptions['access'] as string}`) diff --git a/packages/plugin-commands-publishing/test/recursivePublish.ts b/packages/plugin-commands-publishing/test/recursivePublish.ts index 35a21f3e07..ed0baeaf84 100644 --- a/packages/plugin-commands-publishing/test/recursivePublish.ts +++ b/packages/plugin-commands-publishing/test/recursivePublish.ts @@ -1,4 +1,5 @@ import { readProjects } from '@pnpm/filter-workspace-packages' +import { streamParser } from '@pnpm/logger' import { publish } from '@pnpm/plugin-commands-publishing' import { preparePackages } from '@pnpm/prepare' import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock' @@ -114,3 +115,57 @@ test('recursive publish', async () => { expect(stdout.toString().includes('next: 2.0.0')).toBeTruthy() } }) + +test('print info when no packages are published', async () => { + preparePackages([ + // This will not be published because is-positive@1.0.0 is in the registry + { + name: 'is-positive', + version: '1.0.0', + + scripts: { + prepublishOnly: 'exit 1', + }, + }, + // This will not be published because it is a private package + { + name: 'i-am-private', + version: '1.0.0', + + private: true, + scripts: { + prepublishOnly: 'exit 1', + }, + }, + // Package with no name is skipped + { + location: 'no-name', + package: { + scripts: { + prepublishOnly: 'exit 1', + }, + }, + }, + ]) + + await fs.writeFile('.npmrc', CREDENTIALS, 'utf8') + + const reporter = jest.fn() + streamParser.on('data', reporter) + + await publish.handler({ + ...DEFAULT_OPTS, + ...await readProjects(process.cwd(), []), + dir: process.cwd(), + dryRun: true, + recursive: true, + }, []) + + streamParser.removeListener('data', reporter) + expect(reporter).toBeCalledWith(expect.objectContaining({ + level: 'info', + message: 'There are no new packages that should be published', + name: 'pnpm', + prefix: process.cwd(), + })) +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ef7f4c108b..32194048db 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1936,6 +1936,7 @@ importers: write-json-file: 4.3.0 devDependencies: '@pnpm/filter-workspace-packages': link:../filter-workspace-packages + '@pnpm/logger': 3.2.3 '@pnpm/plugin-commands-publishing': 'link:' '@pnpm/prepare': link:../../privatePackages/prepare '@types/cross-spawn': 6.0.2 @@ -1956,6 +1957,7 @@ importers: '@pnpm/exportable-manifest': workspace:1.2.1 '@pnpm/filter-workspace-packages': workspace:2.3.6 '@pnpm/lifecycle': workspace:9.6.4 + '@pnpm/logger': ^3.2.3 '@pnpm/pick-registry-for-package': workspace:1.0.6 '@pnpm/plugin-commands-publishing': 'link:' '@pnpm/prepare': workspace:0.0.17