Skip to content

Add vite branch plugin - #3922

Open
zeyadkhaled wants to merge 2 commits into
mainfrom
zka/vite-plugin-branch
Open

Add vite branch plugin#3922
zeyadkhaled wants to merge 2 commits into
mainfrom
zka/vite-plugin-branch

Conversation

@zeyadkhaled

Copy link
Copy Markdown
Contributor

Summary

  • Add @osdk/vite-plugin-branch to inject the current Git branch into VITE_FOUNDRY_BRANCH_RID during local Vite development.
  • Add @osdk/shared.branch with shared Git branch detection and normalization utilities.
  • Update the branch CLI to use the shared utilities while preserving existing behavior.
  • Respect branch values supplied through .env, CI, or Foundry runtimes, and skip injection for default or detached branches.
  • Add tests, package metadata, monorepo configuration, lockfile updates, and changesets.

@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size Change
@osdk/api 432 B 0%
@osdk/client 27.88 kB 0%
@osdk/client/experimental 28.52 kB 0%
@osdk/client/observable 54.92 kB 0%
@osdk/oauth 6.54 kB 0%
@osdk/react 58.86 kB 0%
@osdk/react/devtools-registry 184 B 0%
@osdk/react/experimental 58.88 kB 0%
@osdk/react/platform-apis 2.56 kB 0%
@osdk/react/testing 536 B 0%
@osdk/react/experimental/admin 2.56 kB 0%
@osdk/react/experimental/aip 5.21 kB 0%
@osdk/react-components 10 B 0%
@osdk/react-components/experimental 705.88 kB 0%
@osdk/react-components/primitives 40.64 kB 0%
@osdk/react-components/experimental/action-form 277.63 kB 0%
@osdk/react-components/experimental/aip-agent-chat 16.45 kB 0%
@osdk/react-components/experimental/cbac-picker 52.86 kB 0%
@osdk/react-components/experimental/document-viewer 346.70 kB 0%
@osdk/react-components/experimental/email-viewer 21.88 kB 0%
@osdk/react-components/experimental/filter-list 132.14 kB 0%
@osdk/react-components/experimental/image-viewer 3.74 kB 0%
@osdk/react-components/experimental/markdown-renderer 44.18 kB 0%
@osdk/react-components/experimental/object-table 161.34 kB 0%
@osdk/react-components/experimental/pdf-viewer 160.36 kB 0%
@osdk/react-components/experimental/spreadsheet-viewer 106.32 kB 0%
@osdk/react-components/experimental/theme 714 B 0%
@osdk/react-components/experimental/tiff-renderer 29.63 kB 0%
@osdk/react-components/experimental/video-viewer 3.76 kB 0%
@osdk/react-components/experimental/xml-viewer 3.72 kB 0%
@osdk/widget.client-react 10.89 kB 0%

"--abbrev-ref",
"HEAD",
]);
const { stdout } = await execa("git", ["branch", "--show-current"], {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

osdk unstable branch sync now
detects the branch on an unborn branch (fresh git init,
no commits), where rev-parse --abbrev-ref HEAD failed
outright. Detached HEAD now reports "" instead of "HEAD";
both already normalized to "no branch", so nothing else
shifts.

@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Storybook Preview

❌ Storybook preview failed to build or deploy for commit c466254.

Workflow run

github-actions Bot added a commit that referenced this pull request Aug 21, 2026
*/
export async function getGitBranch(): Promise<string | undefined> {
/** The current git branch, or `undefined` if git fails. */
export async function getGitBranch(cwd?: string): Promise<string | undefined> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if there's a way to avoid making this an actual npm package would be nice if it's just some code that gets written once but can be imported and built into the package builds?

@@ -0,0 +1,9 @@
---

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two changesets

* The environment variable a Foundry runtime sets to the branch the application
* is checked out on. `@osdk/client` reads it to scope every request.
*/
export const FOUNDRY_BRANCH_RID_ENV_VAR: string = "VITE_FOUNDRY_BRANCH_RID";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this always a rid?

pinnedBranch,
await readGitBranch(root),
);
if (injectedBranch === undefined) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

== null is convention

* @example
* ```ts
* export default defineConfig({ plugins: [react(), branchPlugin()] });
* ```

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we word this such that it gets these points across:

  • It determines the global branch a user is on and the rules it uses to do this. I think wording could be more concise here.
  • How does it expose it I think we should write more like "make it available to the @osdk/client via import.meta.env.BLAH"

FOUNDRY_BRANCH_RID_ENV_VAR
];

injectedBranch = resolveBranchToInject(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is not really obvious how pinnedBranch is different to injectedBranch?


import { normalizeGitBranch } from "@osdk/shared.branch";

export function resolveBranchToInject(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It feels strange that this file reads so similar to the ones in the shared.branch package

@amishshah amishshah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved! I assume we're going to have to iterate on this as we test it out

const configuredBranch = loadEnv(mode, envDir, "VITE_")[
FOUNDRY_BRANCH_ENV_VAR
];
if (configuredBranch?.trim()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if (configuredBranch?.trim()) {
if (configuredBranch?.trim() != null) {

conventions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants