Skip to content

Commit dc46b5d

Browse files
authored
[Branching] Add new vite branch plugin (#3922)
1 parent 691c32e commit dc46b5d

19 files changed

Lines changed: 682 additions & 16 deletions

.changeset/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"@osdk/api",
88
"@osdk/client.unstable",
99
"@osdk/client",
10+
"@osdk/vite-plugin-branch",
1011
"@osdk/react",
1112
"@osdk/create-app.template-packager",
1213
"@osdk/create-app.template.*",

.changeset/petite-otters-tickle.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@osdk/vite-plugin-branch": minor
3+
"@osdk/cli": patch
4+
---
5+
6+
Add branch-aware local development and update CLI branch detection.

.lintstagedrc.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const OXC_NESTED_CONFIG_PACKAGES = {
8787
"tool.generate-with-mock-ontology":
8888
"packages/tool.generate-with-mock-ontology/oxlint.config.ts",
8989
"version-updater": "packages/version-updater/oxlint.config.ts",
90+
"vite-plugin-branch": "packages/vite-plugin-branch/oxlint.config.ts",
9091
"vite-plugin-oac": "packages/vite-plugin-oac/oxlint.config.ts",
9192
"vite-plugin-superrepo": "packages/vite-plugin-superrepo/oxlint.config.ts",
9293
"vite-plugin-status-reporter":

.monorepolint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ const archetypeRules = archetypes(standardPackageRules, {
288288
"@osdk/vite-plugin-superrepo",
289289
"@osdk/vite-plugin-status-reporter",
290290
"@osdk/vite-plugin-code-workspace-preview",
291+
"@osdk/vite-plugin-branch",
291292
],
292293
{
293294
...LIBRARY_RULES,

dprint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"packages/tool.release/",
8282
"packages/tool.generate-with-mock-ontology/",
8383
"packages/version-updater/",
84+
"packages/vite-plugin-branch/",
8485
"packages/vite-plugin-code-workspace-preview/",
8586
"packages/vite-plugin-oac/",
8687
"packages/vite-plugin-superrepo/",

packages/cli/src/commands/branch/utils/getGitBranch.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,12 @@
1616

1717
import { execa } from "execa";
1818

19-
/**
20-
* The current git branch (`git rev-parse --abbrev-ref HEAD`), or `undefined` if
21-
* git fails. Detached HEAD returns the literal "HEAD".
22-
*/
23-
export async function getGitBranch(): Promise<string | undefined> {
19+
/** The current git branch, or `undefined` if git fails. */
20+
export async function getGitBranch(cwd?: string): Promise<string | undefined> {
2421
try {
25-
const { stdout } = await execa("git", [
26-
"rev-parse",
27-
"--abbrev-ref",
28-
"HEAD",
29-
]);
22+
const { stdout } = await execa("git", ["branch", "--show-current"], {
23+
cwd,
24+
});
3025
return stdout.trim();
3126
} catch {
3227
return undefined;

packages/cli/src/commands/branch/utils/resolveBranch.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
const NON_BRANCH = new Set(["main", "master", "HEAD"]);
17+
const NON_BRANCH: ReadonlySet<string> = new Set(["main", "master", "HEAD"]);
18+
19+
function normalizeGitBranch(branch: string | undefined): string | undefined {
20+
const trimmed = branch?.trim();
21+
if (trimmed == null || trimmed === "" || NON_BRANCH.has(trimmed)) {
22+
return undefined;
23+
}
24+
return trimmed;
25+
}
1826

1927
/**
2028
* Resolve the branch context: `argBranchName` wins; else `gitBranchName`, with
@@ -28,9 +36,5 @@ export function resolveBranch(
2836
if (argBranch != null && argBranch !== "") {
2937
return argBranch;
3038
}
31-
const gitBranch = gitBranchName?.trim();
32-
if (gitBranch == null || gitBranch === "" || NON_BRANCH.has(gitBranch)) {
33-
return undefined;
34-
}
35-
return gitBranch;
39+
return normalizeGitBranch(gitBranchName);
3640
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2026 Palantir Technologies, Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { defineConfig } from "oxlint";
18+
19+
import root from "../../oxlint.config.ts";
20+
21+
// Nested oxlint config for @osdk/vite-plugin-branch. It inherits
22+
// the whole repo ruleset by `extends`-ing the root config.
23+
//
24+
// `extends` only carries `rules`/`plugins`/`overrides`, so the root's
25+
// `ignorePatterns` are re-applied explicitly (otherwise generated/ignored files
26+
// would start being linted).
27+
export default defineConfig({
28+
extends: [root],
29+
ignorePatterns: root.ignorePatterns,
30+
31+
rules: {},
32+
});
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"name": "@osdk/vite-plugin-branch",
3+
"version": "0.0.0",
4+
"license": "Apache-2.0",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/palantir/osdk-ts.git"
8+
},
9+
"exports": {
10+
".": {
11+
"browser": "./build/browser/index.js",
12+
"import": {
13+
"types": "./build/types/index.d.ts",
14+
"default": "./build/esm/index.js"
15+
},
16+
"require": "./build/cjs/index.cjs",
17+
"default": "./build/browser/index.js"
18+
},
19+
"./*": {
20+
"browser": "./build/browser/public/*.js",
21+
"import": {
22+
"types": "./build/types/public/*.d.ts",
23+
"default": "./build/esm/public/*.js"
24+
},
25+
"require": "./build/cjs/public/*.cjs",
26+
"default": "./build/browser/public/*.js"
27+
}
28+
},
29+
"scripts": {
30+
"check-attw": "attw --pack .",
31+
"check-spelling": "cspell --quiet .",
32+
"clean": "rm -rf lib dist types build tsconfig.tsbuildinfo",
33+
"fix-lint": "oxlint -c ./oxlint.config.ts --fix . && oxfmt -c ../../oxfmt.config.ts .",
34+
"lint": "oxlint -c ./oxlint.config.ts . && oxfmt -c ../../oxfmt.config.ts --check .",
35+
"test": "vitest run",
36+
"transpileBrowser": "monorepo.tool.transpile -f esm -m normal -t browser",
37+
"transpileCjs": "monorepo.tool.transpile -f cjs -m bundle -t node",
38+
"transpileEsm": "monorepo.tool.transpile -f esm -m normal -t node",
39+
"transpileTypes": "monorepo.tool.transpile -f esm -m types -t node",
40+
"typecheck": "tsc --noEmit --emitDeclarationOnly false",
41+
"watch": "tsc --watch"
42+
},
43+
"dependencies": {
44+
"execa": "^9.6.0"
45+
},
46+
"peerDependencies": {
47+
"vite": "*"
48+
},
49+
"devDependencies": {
50+
"@osdk/monorepo.api-extractor": "workspace:~",
51+
"@osdk/monorepo.tsconfig": "workspace:~",
52+
"@types/node": "^20.19.13",
53+
"typescript": "~5.5.4"
54+
},
55+
"publishConfig": {
56+
"access": "public"
57+
},
58+
"files": [
59+
"build/cjs",
60+
"build/esm",
61+
"build/browser",
62+
"build/types",
63+
"CHANGELOG.md",
64+
"package.json",
65+
"templates",
66+
"*.d.ts"
67+
],
68+
"main": "./build/cjs/index.cjs",
69+
"module": "./build/esm/index.js",
70+
"types": "./build/cjs/index.d.cts",
71+
"type": "module"
72+
}

0 commit comments

Comments
 (0)