beachball
Advanced tools
Comparing version 2.31.0 to 2.31.1
@@ -13,2 +13,76 @@ "use strict"; | ||
const getScopedPackages_1 = require("../monorepo/getScopedPackages"); | ||
/** | ||
* Ensure that adequate history is available to check for changes between HEAD and `options.branch`. | ||
* Otherwise attempting to get changes will fail with an error "no merge base". | ||
*/ | ||
function ensureHistory(options) { | ||
const { fetch, path: cwd, branch } = options; | ||
const { remote, remoteBranch } = workspace_tools_1.parseRemoteBranch(branch); | ||
const fetchMitigationSteps = `- Omit the "--no-fetch" / "--fetch=false" option from the command line | ||
- Remove "fetch: false" from the beachball config | ||
- If this is a CI build, ensure that adequate history is being fetched | ||
- For GitHub Actions (actions/checkout), add the option "fetch-depth: 0" in the checkout step`; | ||
if (fetch) { | ||
// Fetch the latest from the remote branch for comparison | ||
console.log(`fetching latest from remotes "${remote}/${remoteBranch}"`); | ||
workspace_tools_1.fetchRemoteBranch(remote, remoteBranch, cwd); | ||
} | ||
else { | ||
// If fetching is disabled, ensure that the target branch is available for comparison locally | ||
const hasTargetBranch = workspace_tools_1.git(['rev-parse', '--verify', branch], { cwd }).success; | ||
if (!hasTargetBranch) { | ||
// This is most likely to happen in a CI build which does a shallow checkout (github actions/checkout | ||
// does this by default) and for some reason also disables beachball fetching. | ||
const mainError = `Target branch "${branch}" does not exist locally, and fetching is disabled.`; | ||
console.error(` | ||
${mainError} Some possible fixes: | ||
- Fetch the branch manually: git fetch ${remote} ${remoteBranch} | ||
${fetchMitigationSteps} | ||
`); | ||
throw new Error(mainError); | ||
} | ||
} | ||
// Verify that HEAD and the target branch share history | ||
const hasCommonCommit = workspace_tools_1.git(['merge-base', branch, 'HEAD'], { cwd }).success; | ||
if (!hasCommonCommit) { | ||
// This might be a shallow repo, and it's necessary to unshallow the head branch for comparison | ||
const isShallow = workspace_tools_1.git(['rev-parse', '--is-shallow-repository'], { cwd }).stdout.trim() === 'true'; | ||
if (isShallow) { | ||
if (fetch) { | ||
// Fetch more history (if needed, this could be optimized later to only deepen by e.g. 100 commits at a time) | ||
// TODO switch to this after workspace-tools update | ||
// try { | ||
// console.log('This is a shallow clone. Unshallowing to check for changes...'); | ||
// git(['fetch', '--unshallow'], { cwd, throwOnError: true }); | ||
// } catch (err) { | ||
// throw new GitError(`Failed to fetch more history for branch "${branch}"`, err); | ||
// } | ||
console.log('This is a shallow clone. Unshallowing to check for changes...'); | ||
const result = workspace_tools_1.git(['fetch', '--unshallow'], { cwd }); | ||
if (!result.success) { | ||
throw new Error(`Failed to fetch more history for branch "${branch}":\n${result.stderr}`); | ||
} | ||
} | ||
else { | ||
console.error(` | ||
This repo is a shallow clone, fetching is disabled, and not enough history is available to connect HEAD to "${branch}". | ||
Some possible fixes: | ||
- Verify that you're using the correct target branch | ||
- Unshallow or deepen the clone manually | ||
${fetchMitigationSteps} | ||
`); | ||
throw new Error(`Inadequate history available for HEAD to connect it to target branch "${branch}".`); | ||
} | ||
} | ||
else { | ||
// Not a shallow repo, so it's probably using the wrong target branch | ||
throw new Error(`HEAD does not appear to share history with "${branch}" -- are you using the correct target branch?`); | ||
} | ||
} | ||
} | ||
function getMatchingPackageInfo(file, cwd, packageInfosByPath) { | ||
@@ -89,9 +163,5 @@ // Normalize all the paths before comparing (the packageInfosByPath entries should also be normalized) | ||
function getChangedPackages(options, packageInfos) { | ||
const { fetch, path: cwd, branch } = options; | ||
const { path: cwd, branch } = options; | ||
const changePath = paths_1.getChangePath(cwd); | ||
if (fetch) { | ||
const { remote, remoteBranch } = workspace_tools_1.parseRemoteBranch(branch); | ||
console.log(`fetching latest from remotes "${remote}/${remoteBranch}"`); | ||
workspace_tools_1.fetchRemoteBranch(remote, remoteBranch, cwd); | ||
} | ||
ensureHistory(options); | ||
const changedPackages = getAllChangedPackages(options, packageInfos); | ||
@@ -98,0 +168,0 @@ const changeFilesResult = workspace_tools_1.git(['diff', '--name-only', '--relative', '--no-renames', '--diff-filter=A', `${branch}...`], { cwd }); |
@@ -72,11 +72,4 @@ "use strict"; | ||
}; | ||
let questions = [defaultPrompt.changeType, defaultPrompt.description]; | ||
if ((_a = packageInfo.combinedOptions.changeFilePrompt) === null || _a === void 0 ? void 0 : _a.changePrompt) { | ||
/** | ||
* We are providing the package name also as the parameter so | ||
* that the custom changelog can be specified at the package level | ||
*/ | ||
questions = (_b = packageInfo.combinedOptions.changeFilePrompt) === null || _b === void 0 ? void 0 : _b.changePrompt(defaultPrompt, pkg); | ||
} | ||
questions = questions.filter(q => !!q); | ||
const defaultPrompts = [defaultPrompt.changeType, defaultPrompt.description]; | ||
const questions = (((_b = (_a = packageInfo.combinedOptions.changeFilePrompt) === null || _a === void 0 ? void 0 : _a.changePrompt) === null || _b === void 0 ? void 0 : _b.call(_a, defaultPrompt, pkg)) || defaultPrompts).filter((q) => !!q); | ||
let response = { | ||
@@ -87,4 +80,9 @@ type: options.type || 'none', | ||
if (questions.length > 0) { | ||
response = (await prompts_1.default(questions)); | ||
if (Object.keys(response).length === 0) { | ||
let isCancelled = false; | ||
response = (await prompts_1.default(questions, { | ||
onCancel: () => { | ||
isCancelled = true; | ||
}, | ||
})); | ||
if (isCancelled) { | ||
console.log('Cancelled, no change files are written'); | ||
@@ -91,0 +89,0 @@ return; |
@@ -8,2 +8,3 @@ import prompts from 'prompts'; | ||
* Options for customizing change file prompt. | ||
* The package name is provided so that the prompt can be customized by package if desired. | ||
*/ | ||
@@ -10,0 +11,0 @@ export interface ChangeFilePromptOptions { |
{ | ||
"name": "beachball", | ||
"version": "2.31.0", | ||
"version": "2.31.1", | ||
"description": "The Sunniest Semantic Version Bumper", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
311304
3829
2