Skip to content

Commit e8c0612

Browse files
authored
fix: make CI Format pass (format broken baseline + add pre-commit hook) (#1190)
* ci: auto-format staged code with a pre-commit hook Adds .githooks/pre-commit that runs oxfmt --write on staged JS/TS/JSON and re-stages them, and wires git config core.hooksPath .githooks into bootstrap so every fresh checkout and worktree activates it. Commits now land already-formatted, so the CI format job (oxfmt --check) stops failing on contributions that skipped running format manually. The hook only touches staged files, matching the existing rule to stage just your own files. It honours .oxfmtrc.json ignorePatterns and no-ops when oxfmt is not yet installed. * chore: format package.json publishConfig to fix CI baseline origin/main was already failing oxfmt --check on 20 package.json files (publishConfig key order: access sorts before exports), so every PR inherited a red Format check regardless of its own contents. Format them once to make the baseline green.
1 parent 6b186bf commit e8c0612

22 files changed

Lines changed: 93 additions & 40 deletions

File tree

.githooks/pre-commit

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
# Auto-format staged code with oxfmt before each commit, so the CI `format` job
3+
# (`oxfmt --check .`) can never fail on a commit that originated here. Activated
4+
# by `git config core.hooksPath .githooks`, which `bun run bootstrap` sets for
5+
# every fresh checkout / agent worktree.
6+
#
7+
# Behaviour: formats the staged JS/TS/JSON files in place and re-stages them.
8+
# oxfmt honours `.oxfmtrc.json` `ignorePatterns` even for explicitly-passed
9+
# paths, so generated/vendored files (bun.lock, routeTree.gen.ts, ...) are
10+
# skipped automatically.
11+
#
12+
# NUL-delimited end to end (handles spaces/newlines in paths) and compatible
13+
# with the bash 3.2 that ships on macOS, so no `mapfile`. A shell variable
14+
# cannot hold NUL bytes, so the staged list is read into an array directly.
15+
#
16+
# Caveat: a file that is only partially staged (staged hunk + a separate
17+
# unstaged hunk in the same file) gets fully re-staged after formatting. Agent
18+
# flows stage whole files (`git add -A`), so this is not a concern in practice.
19+
20+
set -euo pipefail
21+
22+
cd "$(git rev-parse --show-toplevel)"
23+
24+
oxfmt="node_modules/.bin/oxfmt"
25+
if [[ ! -x "$oxfmt" ]]; then
26+
echo "pre-commit: oxfmt not found ($oxfmt) - run 'bun run bootstrap'; skipping format." >&2
27+
exit 0
28+
fi
29+
30+
# Staged Added/Copied/Modified/Renamed files, restricted to extensions oxfmt
31+
# formats. Read NUL records into an array (no NUL-in-variable bug).
32+
files=()
33+
while IFS= read -r -d '' f; do
34+
case "$f" in
35+
*.ts | *.tsx | *.mts | *.cts | *.js | *.jsx | *.mjs | *.cjs | *.json | *.jsonc)
36+
files+=("$f")
37+
;;
38+
esac
39+
done < <(git diff --cached --name-only --diff-filter=ACMR -z)
40+
41+
((${#files[@]})) || exit 0
42+
43+
# Format in place, then re-stage whatever oxfmt may have rewritten.
44+
# --no-error-on-unmatched-pattern keeps the hook from failing when every staged
45+
# file is ignored by .oxfmtrc.json.
46+
"$oxfmt" --write --no-error-on-unmatched-pattern "${files[@]}"
47+
git add -- "${files[@]}"

packages/core/cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
".": "./src/index.ts"
2424
},
2525
"publishConfig": {
26+
"access": "public",
2627
"exports": {
2728
".": {
2829
"import": {
2930
"types": "./dist/index.d.ts",
3031
"default": "./dist/index.js"
3132
}
3233
}
33-
},
34-
"access": "public"
34+
}
3535
},
3636
"scripts": {
3737
"build": "tsup && (tsc --declaration --emitDeclarationOnly --outDir dist --rootDir src || true)",

packages/core/config/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
".": "./src/index.ts"
2020
},
2121
"publishConfig": {
22+
"access": "public",
2223
"exports": {
2324
".": {
2425
"import": {
2526
"types": "./dist/index.d.ts",
2627
"default": "./dist/index.js"
2728
}
2829
}
29-
},
30-
"access": "public"
30+
}
3131
},
3232
"scripts": {
3333
"build": "tsup && (tsc --declaration --emitDeclarationOnly --outDir dist --rootDir src || true)",

packages/core/execution/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"./promise": "./src/promise.ts"
2121
},
2222
"publishConfig": {
23+
"access": "public",
2324
"exports": {
2425
".": {
2526
"import": {
@@ -33,8 +34,7 @@
3334
"default": "./dist/core.js"
3435
}
3536
}
36-
},
37-
"access": "public"
37+
}
3838
},
3939
"scripts": {
4040
"build": "tsup && (tsc --declaration --emitDeclarationOnly --outDir dist --rootDir src || true)",

packages/core/integrations-registry/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
".": "./src/index.ts"
2121
},
2222
"publishConfig": {
23+
"access": "public",
2324
"exports": {
2425
".": {
2526
"import": {
2627
"types": "./dist/index.d.ts",
2728
"default": "./dist/index.js"
2829
}
2930
}
30-
},
31-
"access": "public"
31+
}
3232
},
3333
"scripts": {
3434
"build": "tsup && (tsc --declaration --emitDeclarationOnly --outDir dist --rootDir src || true)",

packages/core/sdk/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"./public-origin": "./src/public-origin.ts"
2929
},
3030
"publishConfig": {
31+
"access": "public",
3132
"exports": {
3233
".": {
3334
"import": {
@@ -83,8 +84,7 @@
8384
"default": "./dist/public-origin.js"
8485
}
8586
}
86-
},
87-
"access": "public"
87+
}
8888
},
8989
"scripts": {
9090
"build": "tsup && (tsc --declaration --emitDeclarationOnly --outDir dist --rootDir src || true)",

packages/core/vite-plugin/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
}
2424
},
2525
"publishConfig": {
26+
"access": "public",
2627
"exports": {
2728
".": {
2829
"import": {
2930
"types": "./dist/index.d.ts",
3031
"default": "./dist/index.js"
3132
}
3233
}
33-
},
34-
"access": "public"
34+
}
3535
},
3636
"scripts": {
3737
"build": "tsup && (tsc --declaration --emitDeclarationOnly --outDir dist --rootDir src || true)",

packages/kernel/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
".": "./src/index.ts"
2020
},
2121
"publishConfig": {
22+
"access": "public",
2223
"exports": {
2324
".": {
2425
"import": {
2526
"types": "./dist/index.d.ts",
2627
"default": "./dist/index.js"
2728
}
2829
}
29-
},
30-
"access": "public"
30+
}
3131
},
3232
"scripts": {
3333
"build": "tsup && (tsc --declaration --emitDeclarationOnly --outDir dist --rootDir src || true)",

packages/kernel/runtime-quickjs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
".": "./src/index.ts"
2020
},
2121
"publishConfig": {
22+
"access": "public",
2223
"exports": {
2324
".": {
2425
"import": {
2526
"types": "./dist/index.d.ts",
2627
"default": "./dist/index.js"
2728
}
2829
}
29-
},
30-
"access": "public"
30+
}
3131
},
3232
"scripts": {
3333
"build": "tsup && (tsc --declaration --emitDeclarationOnly --outDir dist --rootDir src || true)",

packages/plugins/desktop-settings/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"./client": "./src/client.tsx"
2121
},
2222
"publishConfig": {
23+
"access": "public",
2324
"exports": {
2425
"./server": {
2526
"import": {
@@ -33,8 +34,7 @@
3334
"default": "./dist/client.js"
3435
}
3536
}
36-
},
37-
"access": "public"
37+
}
3838
},
3939
"scripts": {
4040
"build": "tsup",

0 commit comments

Comments
 (0)