diff --git a/packages/shipjs-lib/src/lib/config/__tests__/defaultConfig.spec.js b/packages/shipjs-lib/src/lib/config/__tests__/defaultConfig.spec.js index 95b51186..b7b48fc4 100644 --- a/packages/shipjs-lib/src/lib/config/__tests__/defaultConfig.spec.js +++ b/packages/shipjs-lib/src/lib/config/__tests__/defaultConfig.spec.js @@ -7,6 +7,7 @@ const { mergeStrategy: defaultMergeStrategy, shouldRelease, } = defaultConfig; +const publishCommandInStr = 'npm publish --tag latest'; describe('defaultConfig', () => { it('should export an object', () => { @@ -57,6 +58,7 @@ describe('defaultConfig', () => { mergeStrategy, currentVersion, nextVersion, + publishCommandInStr, }); expect(message).toMatchInlineSnapshot(` "## Release Summary @@ -68,6 +70,11 @@ describe('defaultConfig', () => { > Fore more information, please refer to the mergeStrategy section of the [guide](https://github.com/algolia/shipjs/blob/master/GUIDE.md#mergestrategy). > ![Squash and merge](https://raw.githubusercontent.com/algolia/shipjs/v0.5.2/assets/squash-and-merge.png) + --- + This is going to be published by the following command: + \`\`\` + npm publish --tag latest + \`\`\` --- _This pull request is automatically generated by [Ship.js](https://github.com/algolia/shipjs)_" `); @@ -93,6 +100,7 @@ describe('defaultConfig', () => { mergeStrategy, currentVersion, nextVersion, + publishCommandInStr, }); expect(message).toMatchInlineSnapshot(` "## Release Summary @@ -103,6 +111,11 @@ describe('defaultConfig', () => { > Fore more information, please refer to the mergeStrategy section of the [guide](https://github.com/algolia/shipjs/blob/master/GUIDE.md#mergestrategy). > ![Merge pull request](https://raw.githubusercontent.com/algolia/shipjs/v0.5.2/assets/merge-pull-request.png) + --- + This is going to be published by the following command: + \`\`\` + npm publish --tag latest + \`\`\` --- _This pull request is automatically generated by [Ship.js](https://github.com/algolia/shipjs)_" `); diff --git a/packages/shipjs-lib/src/lib/config/defaultConfig.js b/packages/shipjs-lib/src/lib/config/defaultConfig.js index d22c1ac7..48a3d976 100644 --- a/packages/shipjs-lib/src/lib/config/defaultConfig.js +++ b/packages/shipjs-lib/src/lib/config/defaultConfig.js @@ -31,6 +31,7 @@ export default { currentVersion, nextVersion, releaseType, + publishCommandInStr, }) => { const pullRequestTitle = formatPullRequestTitle({ version: nextVersion, @@ -56,6 +57,11 @@ export default { ]), '', '---', + 'This is going to be published by the following command:', + '```', + publishCommandInStr, + '```', + '---', '_This pull request is automatically generated by [Ship.js](https://github.com/algolia/shipjs)_', ]; return lines.join('\n'); diff --git a/packages/shipjs/src/helper/getPublishCommand.js b/packages/shipjs/src/helper/getPublishCommand.js new file mode 100644 index 00000000..27066ead --- /dev/null +++ b/packages/shipjs/src/helper/getPublishCommand.js @@ -0,0 +1,12 @@ +export default function getPublishCommand({ + isYarn, + publishCommand, + tag, + dir, +}) { + const defaultCommand = isYarn + ? `yarn publish --no-git-tag-version --non-interactive --tag ${tag}` + : `npm publish --tag ${tag}`; + + return publishCommand({ isYarn, tag, defaultCommand, dir }); +} diff --git a/packages/shipjs/src/helper/index.js b/packages/shipjs/src/helper/index.js index adb2271b..6dce3537 100644 --- a/packages/shipjs/src/helper/index.js +++ b/packages/shipjs/src/helper/index.js @@ -6,3 +6,4 @@ export { default as getChangelog } from './getChangelog'; export { default as extractSpecificChangelog } from './extractSpecificChangelog'; export { default as gitPush } from './gitPush'; export { default as runPrettier } from './runPrettier'; +export { default as getPublishCommand } from './getPublishCommand'; diff --git a/packages/shipjs/src/step/prepare/createPullRequest.js b/packages/shipjs/src/step/prepare/createPullRequest.js index 521303ed..3494be4d 100644 --- a/packages/shipjs/src/step/prepare/createPullRequest.js +++ b/packages/shipjs/src/step/prepare/createPullRequest.js @@ -1,9 +1,14 @@ -import { hasRemoteBranch, getRepoInfo } from 'shipjs-lib'; +import { + expandPackageList, + hasRemoteBranch, + getRepoInfo, + getReleaseTag, +} from 'shipjs-lib'; import open from 'open'; import Octokit from '@octokit/rest'; import runStep from '../runStep'; -import { getDestinationBranchName } from '../../helper'; -import { print, run, exitProcess } from '../../util'; +import { getDestinationBranchName, getPublishCommand } from '../../helper'; +import { print, run, exitProcess, detectYarn } from '../../util'; import { warning } from '../../color'; export default async ({ @@ -22,8 +27,10 @@ export default async ({ mergeStrategy, formatPullRequestTitle, formatPullRequestMessage, + publishCommand, pullRequestReviewer, remote, + monorepo, } = config; const destinationBranch = getDestinationBranchName({ baseBranch, @@ -48,6 +55,13 @@ export default async ({ exitProcess(0); } const { url: repoURL, owner, name: repo } = getRepoInfo(remote, dir); + const publishCommandInStr = getPublishCommandInStr({ + isYarn: detectYarn(dir), + tag: getReleaseTag(nextVersion), + monorepo, + publishCommand, + dir, + }); const title = formatPullRequestTitle({ version: nextVersion, releaseType }); const message = formatPullRequestMessage({ formatPullRequestTitle, @@ -59,6 +73,7 @@ export default async ({ currentVersion, nextVersion, releaseType, + publishCommandInStr, }); run({ command: `git remote prune ${remote}`, dir, dryRun }); @@ -101,3 +116,29 @@ export default async ({ return { pullRequestUrl: url }; }); + +function getPublishCommandInStr({ + isYarn, + tag, + monorepo, + publishCommand, + dir, +}) { + if (monorepo) { + const { packagesToPublish } = monorepo; + const packageList = expandPackageList(packagesToPublish, dir); + return packageList + .map( + packageDir => + `- ${packageDir} -> ${getPublishCommand({ + isYarn, + publishCommand, + tag, + dir: packageDir, + })}` + ) + .join('\n'); + } else { + return getPublishCommand({ isYarn, publishCommand, tag, dir }); + } +} diff --git a/packages/shipjs/src/step/release/__tests__/runPublish.spec.js b/packages/shipjs/src/step/release/__tests__/runPublish.spec.js index 76acf3a9..e82d6601 100644 --- a/packages/shipjs/src/step/release/__tests__/runPublish.spec.js +++ b/packages/shipjs/src/step/release/__tests__/runPublish.spec.js @@ -2,6 +2,11 @@ import { expandPackageList } from 'shipjs-lib'; import { run, print } from '../../../util'; import runPublish from '../runPublish'; import { mockPrint } from '../../../../tests/util'; +jest.unmock('../../../helper'); +// if `unmock` causes any trouble in the future, +// we might try this: https://github.com/facebook/jest/issues/2649#issuecomment-360467278 +// `runPublish` depends on `getPublishCommand` from `helper` +// and we need it unmocked to successfully run the following tests. describe('runPublish', () => { it('works with yarn', () => { diff --git a/packages/shipjs/src/step/release/runPublish.js b/packages/shipjs/src/step/release/runPublish.js index 049585b9..420b3eee 100644 --- a/packages/shipjs/src/step/release/runPublish.js +++ b/packages/shipjs/src/step/release/runPublish.js @@ -1,29 +1,28 @@ import { expandPackageList } from 'shipjs-lib'; import runStep from '../runStep'; import { run, print } from '../../util'; +import { getPublishCommand } from '../../helper'; import { info } from '../../color'; export default ({ isYarn, config, releaseTag: tag, dir, dryRun }) => runStep({ title: 'Publishing.' }, () => { const { publishCommand, monorepo } = config; - const defaultCommand = isYarn - ? `yarn publish --no-git-tag-version --non-interactive --tag ${tag}` - : `npm publish --tag ${tag}`; + if (monorepo) { const { packagesToPublish } = monorepo; const packageList = expandPackageList(packagesToPublish, dir); packageList.forEach(packageDir => { - const command = publishCommand({ + const command = getPublishCommand({ isYarn, + publishCommand, tag, - defaultCommand, dir: packageDir, }); print(`Running the following at ${info(packageDir)}`); run({ command, dir: packageDir, dryRun }); }); } else { - const command = publishCommand({ isYarn, tag, defaultCommand, dir }); + const command = getPublishCommand({ isYarn, publishCommand, tag, dir }); run({ command, dir, dryRun }); } });