From d87f5ae085ffc38a2aacc2b5b59b0ef67a1a7f66 Mon Sep 17 00:00:00 2001 From: Stephen Zhou Date: Sun, 21 Apr 2024 20:50:47 +0800 Subject: [PATCH] feat: support custom publish command --- docs/pages/_app.js | 9 --------- docs/pages/config.mdx | 14 +++++++------ src/index.js | 47 ++++++++++++++++++++++++++----------------- 3 files changed, 36 insertions(+), 34 deletions(-) delete mode 100644 docs/pages/_app.js diff --git a/docs/pages/_app.js b/docs/pages/_app.js deleted file mode 100644 index ec824cf..0000000 --- a/docs/pages/_app.js +++ /dev/null @@ -1,9 +0,0 @@ -import 'remark-github-alerts/styles/github-colors-light.css' -import 'remark-github-alerts/styles/github-colors-dark-class.css' -import 'remark-github-alerts/styles/github-base.css' -import '../styles.css' - -// eslint-disable-next-line no-unused-vars -export default function MyApp({ Component, pageProps }) { - return -} diff --git a/docs/pages/config.mdx b/docs/pages/config.mdx index 73fd12c..4e75d99 100644 --- a/docs/pages/config.mdx +++ b/docs/pages/config.mdx @@ -7,11 +7,12 @@ import { Callout } from "nextra/components"; changelog file. -| Key | Type | Default | Description | -| :--------------: | :-------: | :-------------: | :--------------------------------: | -| `disableRelease` | `boolean` | `undefined` | Do not create a release on GitHub. | -| `inFile` | `string` | `undefined` | Path to the changelog file. | -| `header` | `string` | `"# Changelog"` | Header of the changelog file. | +| Key | Type | Default | Description | +| :--------------: | :-------: | :----------------------------------------------------------: | :--------------------------------: | +| `disableRelease` | `boolean` | `undefined` | Do not create a release on GitHub. | +| `inFile` | `string` | `undefined` | Path to the changelog file. | +| `header` | `string` | `"# Changelog"` | Header of the changelog file. | +| `publishCommand` | `string` | `pnpm -r publish --access public --no-git-checks --tag $tag` | Command to publish the package. | Example: @@ -20,7 +21,8 @@ Example: "plugins": { "release-it-pnpm": { "disableRelease": true, - "inFile": "CHANGELOG.md" + "inFile": "CHANGELOG.md", + "publishCommand": "vsce publish --no-dependencies" } } } diff --git a/src/index.js b/src/index.js index 2c2de0d..0ab8f9f 100644 --- a/src/index.js +++ b/src/index.js @@ -24,6 +24,8 @@ const prompts = { }, } +const defaultPublishCommand = 'pnpm -r publish --access public --no-git-checks --tag $tag' + class ReleaseItPnpmPlugin extends Plugin { static disablePlugin() { return ['npm', 'version'] @@ -133,6 +135,8 @@ class ReleaseItPnpmPlugin extends Plugin { async bump(newVersion) { this.setContext({ newVersion }) + + const { publishCommand = defaultPublishCommand } = this.options let needPublish = false if (!this.options['dry-run']) { @@ -144,38 +148,43 @@ class ReleaseItPnpmPlugin extends Plugin { recursive: true, release: newVersion, }) - if (updatedFiles.length > 0) { - for (const file of updatedFiles) { - const { private: isPrivate } = JSON.parse(fs.readFileSync(file, 'utf8')) - if (!isPrivate) { - needPublish = true - break - } + if (updatedFiles.length === 0) + return + + // Only publish when some packages is not private + for (const file of updatedFiles) { + const { private: isPrivate } = JSON.parse(fs.readFileSync(file, 'utf8')) + if (!isPrivate) { + needPublish = true + break } } - } - this.debug( - 'release-it-pnpm:bump', - { - newVersion, - parsed: semver.parse(newVersion), - }, - ) + // Using custom publish command + if (!publishCommand?.startsWith('pnpm')) + needPublish = true + } const { prerelease } = semver.parse(newVersion) const includePrerelease = prerelease.length > 0 - const prereleaseTag = includePrerelease ? `--tag ${prerelease[0]}` : '' - this.setContext({ prereleaseTag }) + const tag = prerelease[0] ?? 'latest' this.debug( 'release-it-pnpm:bump', - { prereleaseTag, needPublish }, + { + needPublish, + publishCommand, + includePrerelease, + prerelease, + tag, + newVersion, + parsedNewVersion: semver.parse(newVersion), + }, ) if (needPublish) { await this.step({ - task: () => this.exec(`pnpm -r publish --access public --no-git-checks ${prereleaseTag}`), + task: () => this.exec(publishCommand.replace('$tag', tag)), label: 'Publishing packages(s)', prompt: 'publish', })