-
Notifications
You must be signed in to change notification settings - Fork 75
[Branching] Add new vite branch plugin #3922
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9016c11
Add vite branch plugin
zeyadkhaled c466254
Changes
zeyadkhaled cb9450b
Changes/Self review
zeyadkhaled a5f4b34
CI fixes
zeyadkhaled ae49175
Snapshot
zeyadkhaled a8455ae
Fixes to CI
zeyadkhaled 9556cdd
Revert "Fixes to CI"
zeyadkhaled d1c98b3
Fix snapshot release
zeyadkhaled e314d40
Lint
zeyadkhaled 76fa7cf
Revert shared package and duplicate utils
zeyadkhaled 5b79b93
reset release
zeyadkhaled File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| "@osdk/vite-plugin-branch": minor | ||
| "@osdk/cli": patch | ||
| --- | ||
|
|
||
| Add a Vite plugin that makes local development branch-aware. | ||
|
|
||
| On dev server start `branchPlugin()` sets `VITE_FOUNDRY_BRANCH_RID` to the checked out git branch name, so `@osdk/client` scopes objects, actions, and queries to the matching Foundry branch with no change to `createClient`. Previously a repository checked out on a branch locally read and wrote on the default branch unless the branch was threaded through by hand. | ||
|
|
||
| An existing value wins, whether it comes from a `.env` file, the shell, or CI, so the in-platform dev server and pull request previews keep supplying their own branch. Nothing is injected on `main`/`master`, on a detached HEAD, or outside a git repository, and the plugin is dev-server only so a local git branch name is never baked into a production build. | ||
|
|
||
| The branch CLI now shares the same git branch detection and normalization logic as the plugin. It also detects unborn branches in repositories with no commits; detached HEAD remains equivalent to no branch. Requires git >= 2.22. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| { | ||
| "name": "@osdk/shared.branch", | ||
| "private": true, | ||
| "version": "0.0.0", | ||
| "license": "Apache-2.0", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/palantir/osdk-ts.git" | ||
| }, | ||
| "exports": { | ||
| ".": { | ||
| "import": { | ||
| "types": "./build/types/index.d.ts", | ||
| "default": "./build/esm/index.js" | ||
| }, | ||
| "default": "./build/esm/index.js" | ||
| }, | ||
| "./*": { | ||
| "import": { | ||
| "types": "./build/types/public/*.d.ts", | ||
| "default": "./build/esm/public/*.js" | ||
| }, | ||
| "default": "./build/esm/public/*.js" | ||
| } | ||
| }, | ||
| "scripts": { | ||
| "check-spelling": "cspell --quiet .", | ||
| "clean": "rm -rf lib dist types build tsconfig.tsbuildinfo", | ||
| "fix-lint": "oxlint -c ../../oxlint.config.ts --fix . && oxfmt -c ../../oxfmt.config.ts .", | ||
| "lint": "oxlint -c ../../oxlint.config.ts . && oxfmt -c ../../oxfmt.config.ts --check .", | ||
| "test": "vitest run", | ||
| "transpileEsm": "monorepo.tool.transpile -f esm -m normal -t node", | ||
| "transpileTypes": "monorepo.tool.transpile -f esm -m types -t node", | ||
| "typecheck": "tsc --noEmit --emitDeclarationOnly false" | ||
| }, | ||
| "dependencies": { | ||
| "execa": "^9.6.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@osdk/monorepo.api-extractor": "workspace:~", | ||
| "@osdk/monorepo.tsconfig": "workspace:~", | ||
| "typescript": "~5.5.4" | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "files": [ | ||
| ], | ||
| "module": "./build/esm/index.js", | ||
| "types": "./build/esm/index.d.ts", | ||
| "type": "module" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * Copyright 2026 Palantir Technologies, Inc. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { execFileSync } from "node:child_process"; | ||
| import { mkdtempSync, realpathSync, rmSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import path from "node:path"; | ||
|
|
||
| import { afterAll, describe, expect, it } from "vitest"; | ||
|
|
||
| import { getGitBranch } from "./getGitBranch.js"; | ||
|
|
||
| const tempDirs: string[] = []; | ||
|
|
||
| function makeTempDir(): string { | ||
| const dir = mkdtempSync( | ||
| path.join(realpathSync(tmpdir()), "osdk-git-branch-"), | ||
| ); | ||
| tempDirs.push(dir); | ||
| return dir; | ||
| } | ||
|
|
||
| afterAll(() => { | ||
| for (const dir of tempDirs) { | ||
| rmSync(dir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| describe(getGitBranch, () => { | ||
| it("reads the branch of a repository", async () => { | ||
| const dir = makeTempDir(); | ||
| execFileSync("git", ["init", "--initial-branch", "zka/some-branch"], { | ||
| cwd: dir, | ||
| stdio: "ignore", | ||
| }); | ||
|
|
||
| await expect(getGitBranch(dir)).resolves.toBe("zka/some-branch"); | ||
| }); | ||
|
|
||
| it("returns undefined outside a repository", async () => { | ||
| await expect(getGitBranch(makeTempDir())).resolves.toBeUndefined(); | ||
| }); | ||
|
|
||
| it("returns undefined for a directory that does not exist", async () => { | ||
| await expect( | ||
| getGitBranch(path.join(makeTempDir(), "nope")), | ||
| ).resolves.toBeUndefined(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| * Copyright 2026 Palantir Technologies, Inc. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| export { getGitBranch } from "./getGitBranch.js"; | ||
| export { normalizeGitBranch } from "./normalizeGitBranch.js"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * Copyright 2026 Palantir Technologies, Inc. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { normalizeGitBranch } from "./normalizeGitBranch.js"; | ||
|
|
||
| describe("normalizeGitBranch", () => { | ||
| it("returns the branch when on a feature branch", () => { | ||
| expect(normalizeGitBranch("my-feature")).toBe("my-feature"); | ||
| expect(normalizeGitBranch("zka/my-branch")).toBe("zka/my-branch"); | ||
| }); | ||
|
|
||
| it("returns undefined on main/master/detached", () => { | ||
| expect(normalizeGitBranch("main")).toBeUndefined(); | ||
| expect(normalizeGitBranch("master")).toBeUndefined(); | ||
| expect(normalizeGitBranch("HEAD")).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("returns undefined when the branch is missing/empty", () => { | ||
| expect(normalizeGitBranch(undefined)).toBeUndefined(); | ||
| expect(normalizeGitBranch("")).toBeUndefined(); | ||
| expect(normalizeGitBranch(" ")).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("trims whitespace", () => { | ||
| expect(normalizeGitBranch(" feature/x ")).toBe("feature/x"); | ||
| expect(normalizeGitBranch(" main ")).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("keeps a branch that merely contains a non-branch name", () => { | ||
| expect(normalizeGitBranch("zka/main-fix")).toBe("zka/main-fix"); | ||
| expect(normalizeGitBranch("mainline")).toBe("mainline"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Copyright 2026 Palantir Technologies, Inc. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| const NON_BRANCH: ReadonlySet<string> = new Set(["main", "master", "HEAD"]); | ||
|
|
||
| /** | ||
| * The Foundry branch a git branch corresponds to: `branch` trimmed, or | ||
| * `undefined` if it is blank or names no branch (`main`/`master`/detached HEAD). | ||
| */ | ||
| export function normalizeGitBranch( | ||
| branch: string | undefined, | ||
| ): string | undefined { | ||
| const trimmed = branch?.trim(); | ||
| if (trimmed == null || trimmed === "" || NON_BRANCH.has(trimmed)) { | ||
| return undefined; | ||
| } | ||
| return trimmed; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "extends": "@osdk/monorepo.tsconfig/base.json", | ||
| "compilerOptions": { | ||
| "rootDir": "src", | ||
| "outDir": "build/esm" | ||
| }, | ||
| "include": [ | ||
| "./src/**/*" | ||
| ], | ||
| "references": [] | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.