Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add changesetBaseRef configuration option for versioning (#1195) #1201

Merged
merged 4 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/gatsby/src/pages/configuration/yarnrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
5 changes: 5 additions & 0 deletions packages/plugin-version/sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-version/sources/versionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export enum Decision {
export type Releases =
Map<Workspace, Exclude<Decision, Decision.UNDECIDED>>;

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`];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking, what do you think about making it an array of refs instead, that would default to ['master', 'origin/master', 'upstream/master'] (what it currently is)? This way people who want to use a custom branch would be able to keep the behaviour that tries to take the origin into account if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to do that, but did not know how to use an array type. I see now I just need to add isArray: true. I will add this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Maël, I have updated the code and documentation accordingly. I've tested it and it works well. The only limitation is that using the environment variable will only allow a single ref to be set, not a huge deal imo. That could also be user error, I didn't take the time to see if there was a syntax to pass an array.

const ancestorBases = [];

for (const candidate of candidateBases) {
Expand Down Expand Up @@ -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
Expand Down