From 5178c52bd3e3f80b913bb25a6f6164e0a2fbbd6b Mon Sep 17 00:00:00 2001 From: fggrimshaw Date: Tue, 14 Apr 2020 18:02:15 -0400 Subject: [PATCH 1/4] Add changesetBaseRef configuration option for versioning (#1195) * Add changesetBaseRef, allowing for comparing files against non-master refs * Update yarnrc documentation accordingly --- packages/gatsby/src/pages/configuration/yarnrc.json | 5 +++++ packages/plugin-version/sources/index.ts | 5 +++++ packages/plugin-version/sources/versionUtils.ts | 6 +++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/gatsby/src/pages/configuration/yarnrc.json b/packages/gatsby/src/pages/configuration/yarnrc.json index 6c1eeb384562..14ba629c1089 100644 --- a/packages/gatsby/src/pages/configuration/yarnrc.json +++ b/packages/gatsby/src/pages/configuration/yarnrc.json @@ -16,6 +16,11 @@ "format": "uri-reference", "default": "./.yarn/cache" }, + "changesetBaseRef": { + "description": "The base git ref 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": "string", + "default": null + }, "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..3d818f389b70 100644 --- a/packages/plugin-version/sources/index.ts +++ b/packages/plugin-version/sources/index.ts @@ -6,6 +6,11 @@ import version from './commands/version'; const plugin: Plugin = { configuration: { + changesetBaseRef: { + description: 'The base git ref that the current HEAD is compared against when detecting changes. Supports git branches, tags, and commits.', + type: SettingsType.STRING, + default: null, + }, 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..7c6b18cfa91b 100644 --- a/packages/plugin-version/sources/versionUtils.ts +++ b/packages/plugin-version/sources/versionUtils.ts @@ -19,8 +19,8 @@ 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, {baseRef}: {baseRef?: string | null}) { + const candidateBases = baseRef !== null ? [baseRef] : [`master`, `origin/master`, `upstream/master`]; const ancestorBases = []; for (const candidate of candidateBases) { @@ -194,7 +194,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, {baseRef: configuration.get('changesetBaseRef')}) : null; const changedFiles = root !== null From 803f8bb57c463d55caca34062646107cb90aed00 Mon Sep 17 00:00:00 2001 From: fggrimshaw Date: Wed, 15 Apr 2020 11:26:54 -0400 Subject: [PATCH 2/4] Update the changesetBaseRef configuration's default values * renamed changesetBaseRef to changesetBaseRefs * updated its type to array, set master, origin/master, upstream/master as default * remove hardcoded candidates, enforce non-nullable configuration * update docs accordingly --- packages/gatsby/src/pages/configuration/yarnrc.json | 9 ++++++--- packages/plugin-version/sources/index.ts | 6 ++++-- packages/plugin-version/sources/versionUtils.ts | 9 ++++----- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/gatsby/src/pages/configuration/yarnrc.json b/packages/gatsby/src/pages/configuration/yarnrc.json index 14ba629c1089..652be7aa4277 100644 --- a/packages/gatsby/src/pages/configuration/yarnrc.json +++ b/packages/gatsby/src/pages/configuration/yarnrc.json @@ -16,10 +16,13 @@ "format": "uri-reference", "default": "./.yarn/cache" }, - "changesetBaseRef": { + "changesetBaseRefs": { "description": "The base git ref 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": "string", - "default": null + "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.", diff --git a/packages/plugin-version/sources/index.ts b/packages/plugin-version/sources/index.ts index 3d818f389b70..f288cc5a9d4c 100644 --- a/packages/plugin-version/sources/index.ts +++ b/packages/plugin-version/sources/index.ts @@ -6,10 +6,12 @@ import version from './commands/version'; const plugin: Plugin = { configuration: { - changesetBaseRef: { + changesetBaseRefs: { description: 'The base git ref that the current HEAD is compared against when detecting changes. Supports git branches, tags, and commits.', type: SettingsType.STRING, - default: null, + isArray: true, + isNullable: false, + default: [`master`, `origin/master`, `upstream/master`], }, deferredVersionFolder: { description: `Folder where are stored the versioning files`, diff --git a/packages/plugin-version/sources/versionUtils.ts b/packages/plugin-version/sources/versionUtils.ts index 7c6b18cfa91b..c2243e1b1328 100644 --- a/packages/plugin-version/sources/versionUtils.ts +++ b/packages/plugin-version/sources/versionUtils.ts @@ -19,11 +19,10 @@ export enum Decision { export type Releases = Map>; -export async function fetchBase(root: PortablePath, {baseRef}: {baseRef?: string | null}) { - const candidateBases = baseRef !== null ? [baseRef] : [`master`, `origin/master`, `upstream/master`]; +export async function fetchBase(root: PortablePath, {baseRefs}: {baseRefs: string[]}) { 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 +30,7 @@ export async function fetchBase(root: PortablePath, {baseRef}: {baseRef?: string } 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 +193,7 @@ export async function openVersionFile(project: Project, {allowEmpty = false}: {a const root = await fetchRoot(configuration.projectCwd); const base = root !== null - ? await fetchBase(root, {baseRef: configuration.get('changesetBaseRef')}) + ? await fetchBase(root, {baseRefs: configuration.get('changesetBaseRefs')}) : null; const changedFiles = root !== null From 3d6f2202bf2fbc0e7173787c3e00a847edd0eb9a Mon Sep 17 00:00:00 2001 From: fggrimshaw Date: Wed, 15 Apr 2020 11:46:54 -0400 Subject: [PATCH 3/4] Add usageError when changesetBaseRefs is [] * Add a usageError for when the changesetBaseRefs is explicitly set to the empty array * ref -> refs in documentation --- packages/gatsby/src/pages/configuration/yarnrc.json | 2 +- packages/plugin-version/sources/index.ts | 2 +- packages/plugin-version/sources/versionUtils.ts | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/gatsby/src/pages/configuration/yarnrc.json b/packages/gatsby/src/pages/configuration/yarnrc.json index 652be7aa4277..ba3b180c35c6 100644 --- a/packages/gatsby/src/pages/configuration/yarnrc.json +++ b/packages/gatsby/src/pages/configuration/yarnrc.json @@ -17,7 +17,7 @@ "default": "./.yarn/cache" }, "changesetBaseRefs": { - "description": "The base git ref 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.", + "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" diff --git a/packages/plugin-version/sources/index.ts b/packages/plugin-version/sources/index.ts index f288cc5a9d4c..4687b1f8d0d5 100644 --- a/packages/plugin-version/sources/index.ts +++ b/packages/plugin-version/sources/index.ts @@ -7,7 +7,7 @@ import version from './commands/version'; const plugin: Plugin = { configuration: { changesetBaseRefs: { - description: 'The base git ref that the current HEAD is compared against when detecting changes. Supports git branches, tags, and commits.', + 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, diff --git a/packages/plugin-version/sources/versionUtils.ts b/packages/plugin-version/sources/versionUtils.ts index c2243e1b1328..465d5c5ddad4 100644 --- a/packages/plugin-version/sources/versionUtils.ts +++ b/packages/plugin-version/sources/versionUtils.ts @@ -20,6 +20,9 @@ export type Releases = Map>; 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 baseRefs) { From 6a1ae87c2ca0739e174d4d203c0be16877f2ec18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Thu, 16 Apr 2020 14:54:43 +0200 Subject: [PATCH 4/4] Adds versions --- .yarn/versions/b62cfa7b.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .yarn/versions/b62cfa7b.yml 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"