Add vite branch plugin - #3922
Conversation
size-limit report 📦
|
| "--abbrev-ref", | ||
| "HEAD", | ||
| ]); | ||
| const { stdout } = await execa("git", ["branch", "--show-current"], { |
There was a problem hiding this comment.
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.
Storybook Preview❌ Storybook preview failed to build or deploy for commit |
| */ | ||
| 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> { |
There was a problem hiding this comment.
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 @@ | |||
| --- | |||
| * 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"; |
| pinnedBranch, | ||
| await readGitBranch(root), | ||
| ); | ||
| if (injectedBranch === undefined) { |
| * @example | ||
| * ```ts | ||
| * export default defineConfig({ plugins: [react(), branchPlugin()] }); | ||
| * ``` |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
It is not really obvious how pinnedBranch is different to injectedBranch?
|
|
||
| import { normalizeGitBranch } from "@osdk/shared.branch"; | ||
|
|
||
| export function resolveBranchToInject( |
There was a problem hiding this comment.
It feels strange that this file reads so similar to the ones in the shared.branch package
amishshah
left a comment
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
| if (configuredBranch?.trim()) { | |
| if (configuredBranch?.trim() != null) { |
conventions
Summary