diff --git a/.yarn/versions/b62cfa7b.yml b/.yarn/versions/b62cfa7b.yml new file mode 100644 index 000000000000..9077f233ec3b --- /dev/null +++ b/.yarn/versions/b62cfa7b.yml @@ -0,0 +1,5 @@ +releases: + "@yarnpkg/plugin-version": prerelease + +declined: + - "@yarnpkg/cli" diff --git a/packages/gatsby/src/pages/configuration/yarnrc.json b/packages/gatsby/src/pages/configuration/yarnrc.json index 6c1eeb384562..ba3b180c35c6 100644 --- a/packages/gatsby/src/pages/configuration/yarnrc.json +++ b/packages/gatsby/src/pages/configuration/yarnrc.json @@ -16,6 +16,14 @@ "format": "uri-reference", "default": "./.yarn/cache" }, + "changesetBaseRefs": { + "description": "The base git refs that the current HEAD is compared against in the version plugin. This overrides the default behavior of comparing against master, origin/master, and upstream/master. Supports git branches, tags, and commits.", + "type": "array", + "items": { + "type": "string" + }, + "default": ["master", "origin/master", "upstream/master"] + }, "checksumBehavior": { "description": "If `throw` (the default), Yarn will throw an exception on `yarn install` if it detects that a package doesn't match the checksum stored within the lockfile. If `update`, the lockfile checksum will be updated to match the new value. If `ignore`, the checksum check will not happen.", "enum": ["throw", "update", "ignore"], diff --git a/packages/plugin-version/sources/index.ts b/packages/plugin-version/sources/index.ts index 06db33fe073a..4687b1f8d0d5 100644 --- a/packages/plugin-version/sources/index.ts +++ b/packages/plugin-version/sources/index.ts @@ -6,6 +6,13 @@ import version from './commands/version'; const plugin: Plugin = { configuration: { + changesetBaseRefs: { + description: 'The base git refs that the current HEAD is compared against when detecting changes. Supports git branches, tags, and commits.', + type: SettingsType.STRING, + isArray: true, + isNullable: false, + default: [`master`, `origin/master`, `upstream/master`], + }, deferredVersionFolder: { description: `Folder where are stored the versioning files`, type: SettingsType.ABSOLUTE_PATH, diff --git a/packages/plugin-version/sources/versionUtils.ts b/packages/plugin-version/sources/versionUtils.ts index 34ce12cea4bd..465d5c5ddad4 100644 --- a/packages/plugin-version/sources/versionUtils.ts +++ b/packages/plugin-version/sources/versionUtils.ts @@ -19,11 +19,13 @@ export enum Decision { export type Releases = Map>; -export async function fetchBase(root: PortablePath) { - const candidateBases = [`master`, `origin/master`, `upstream/master`]; +export async function fetchBase(root: PortablePath, {baseRefs}: {baseRefs: string[]}) { + if (baseRefs.length === 0) + throw new UsageError(`Can't run this command with zero base refs specified.`); + const ancestorBases = []; - for (const candidate of candidateBases) { + for (const candidate of baseRefs) { const {code} = await execUtils.execvp(`git`, [`merge-base`, candidate, `HEAD`], {cwd: root}); if (code === 0) { ancestorBases.push(candidate); @@ -31,7 +33,7 @@ export async function fetchBase(root: PortablePath) { } if (ancestorBases.length === 0) - throw new UsageError(`No ancestor could be found between any of HEAD and ${candidateBases.join(`, `)}`); + throw new UsageError(`No ancestor could be found between any of HEAD and ${baseRefs.join(`, `)}`); const {stdout: mergeBaseStdout} = await execUtils.execvp(`git`, [`merge-base`, `HEAD`, ...ancestorBases], {cwd: root, strict: true}); const hash = mergeBaseStdout.trim(); @@ -194,7 +196,7 @@ export async function openVersionFile(project: Project, {allowEmpty = false}: {a const root = await fetchRoot(configuration.projectCwd); const base = root !== null - ? await fetchBase(root) + ? await fetchBase(root, {baseRefs: configuration.get('changesetBaseRefs')}) : null; const changedFiles = root !== null