@vwala/tooling-config 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,12 +9,23 @@ src/
9
9
  ├── biome/ Biome config + custom GritQL rules (consumed via npm)
10
10
  │ ├── biome.config.json
11
11
  │ └── plugins/
12
+ ├── commitlint/ Commit-message rules + git hooks (consumed via npm and GitHub Actions)
13
+ │ ├── action.yml
14
+ │ ├── commitlint.config.js
15
+ │ └── hooks/
16
+ ├── typescript/ tsconfig presets (consumed via npm)
17
+ │ ├── base.json
18
+ │ ├── bundler.json
19
+ │ ├── node.json
20
+ │ ├── react-library.json
21
+ │ ├── nextjs.json
22
+ │ └── expo.json
12
23
  └── zizmor/ GitHub Actions security policy (consumed via GitHub Actions)
13
24
  ├── action.yml
14
25
  └── zizmor.yml
15
26
  ```
16
27
 
17
- The two tools are consumed differently — npm for anything a local toolchain reads, a GitHub Action for anything only CI runs — but they version together off the same git tag.
28
+ The tools are consumed differently — npm for anything a local toolchain reads, a GitHub Action for anything only CI runs — but they version together off the same git tag.
18
29
 
19
30
  ---
20
31
 
@@ -68,6 +79,43 @@ It reads tracked files from `git ls-files`, so run it from the repository root.
68
79
 
69
80
  ---
70
81
 
82
+ ## TypeScript
83
+
84
+ ```bash
85
+ pnpm add -D @vwala/tooling-config typescript
86
+ ```
87
+
88
+ ```json
89
+ {
90
+ "extends": "@vwala/tooling-config/typescript/nextjs"
91
+ }
92
+ ```
93
+
94
+ Anything you add alongside `extends` overrides the preset for that key. In a monorepo each workspace package needs its own `devDependency` on `@vwala/tooling-config`, because pnpm only lets a package resolve what its own `package.json` declares — and `extends` is resolved from the directory of the `tsconfig.json` doing the extending.
95
+
96
+ ### Presets
97
+
98
+ `base` holds everything that is not negotiable — `strict`, `noUncheckedIndexedAccess`, `isolatedModules`, declaration output, ES2024 target — and the other five layer onto it.
99
+
100
+ | Preset | Extends | For |
101
+ | --- | --- | --- |
102
+ | `typescript/base` | — | Node-resolved libraries. `module`/`moduleResolution` are `NodeNext`, so relative imports need file extensions. |
103
+ | `typescript/bundler` | `base` | Anything a bundler resolves — `ESNext` + `Bundler`, so extensionless relative imports work. |
104
+ | `typescript/node` | `base` | Node services and CLIs. Narrows `lib` to `es2022` and pulls in `@types/node`. |
105
+ | `typescript/react-library` | `base` | React packages published for Node resolution. Adds the automatic JSX runtime. |
106
+ | `typescript/nextjs` | `bundler` | Next.js apps. Adds the `next` language-service plugin, `jsx: preserve` and `noEmit`. |
107
+ | `typescript/expo` | `bundler` | Expo apps. Adds the automatic JSX runtime and `noEmit`. |
108
+
109
+ Reach for `bundler` rather than `base` whenever the code is compiled by Vite, Next, Metro, esbuild or Vitest. Writing `"extends": ".../base"` and then overriding `module` and `moduleResolution` by hand is the same thing spelled longer.
110
+
111
+ The presets have tests in `src/typescript/__tests__/` that resolve each one through the real `tsc --showConfig` and assert the merged result, plus a check that every preset file is reachable through the package's `exports` map — a broken entry otherwise only surfaces in a consumer.
112
+
113
+ > **Requires TypeScript >= 5.7.** `base` targets ES2024, and 5.6 and earlier reject `es2024` for `--target` and `--lib` outright (`TS6046`). The presets are otherwise valid on 5.7, 6 and 7 alike.
114
+
115
+ > **TypeScript 7 dropped the compiler API.** `typescript@7` ships the native `tsc` binary and nothing else: no `lib/typescript.js` and no `lib/tsserver.js`. Editors cannot point "Use Workspace Version" at it, and any tool that reads the TypeScript API breaks. Pick the version your toolchain needs — `@typescript/typescript6` still carries the API — and note that `plugins` (such as Next's) configures the language service, so tsc 7 accepts it but never acts on it.
116
+
117
+ ---
118
+
71
119
  ## zizmor
72
120
 
73
121
  [zizmor](https://docs.zizmor.sh) audits GitHub Actions workflows. The shared policy lives in `src/zizmor/zizmor.yml` and reaches zizmor through a composite action that bundles it, so consuming repositories get the zizmor version, the config and the standard arguments from one place.
@@ -86,16 +134,122 @@ jobs:
86
134
  with:
87
135
  persist-credentials: false
88
136
 
137
+ - name: Mint a token that can read this repository
138
+ id: policy-token
139
+ uses: actions/create-github-app-token@v2
140
+ with:
141
+ app-id: ${{ vars.APP_ID }}
142
+ private-key: ${{ secrets.APP_PRIVATE_KEY }}
143
+ owner: vwala-be
144
+ repositories: tooling-config
145
+ permission-contents: read
146
+
89
147
  - uses: vwala-be/tooling-config/src/zizmor@v1.0.0
148
+ with:
149
+ token: ${{ steps.policy-token.outputs.token }}
90
150
  ```
91
151
 
92
152
  This needs the repository to be readable by the caller — already set (`Settings → Actions → General → Access → Accessible from repositories in the organization`), which is what lets a private repo share actions with other private repos in the org.
93
153
 
154
+ ### Why `token` is not optional in practice
155
+
156
+ Two different permissions are at play, and the org-level setting above only covers one of them.
157
+
158
+ The Actions *runtime* can check this action out. But zizmor then audits the very workflow that references it, and it resolves every `uses:` through the GitHub *API* using the job's token. The default `GITHUB_TOKEN` is scoped to the calling repository, so it cannot read `vwala-be/tooling-config`, and the `ref-confusion` audit fails hard:
159
+
160
+ ```text
161
+ fatal: no audit was performed
162
+ 'ref-confusion' audit failed on file://./.github/workflows/ci.yml
163
+
164
+ Caused by:
165
+ 0: error in 'ref-confusion' audit
166
+ 1: couldn't list branches for vwala-be/tooling-config
167
+ 2: can't access vwala-be/tooling-config: missing or you have no access
168
+ ```
169
+
170
+ That is an audit *error*, not a finding, so an inline `# zizmor: ignore[ref-confusion]` does not suppress it. Pass a token that can read this repository instead.
171
+
172
+ The GitHub App has to be installed on `tooling-config` with read access to contents and metadata. A repository-scoped installation token can still read public repositories, so the same token also covers the third-party actions in the audited workflows.
173
+
174
+ Our own CI never hits this: it dogfoods the action through the local `./src/zizmor` path, which gives zizmor no cross-repository `uses:` to resolve. The failure is invisible here by construction and only surfaces in consuming repositories.
175
+
94
176
  ### The policy is not overridable
95
177
 
96
178
  zizmor has no `extends` or import mechanism, and passing `--config` disables local config discovery entirely. That is deliberate here: a repository cannot quietly weaken the org-wide policy with its own `zizmor.yml`. Exceptions go in `src/zizmor/zizmor.yml` via a PR against this repo.
97
179
 
98
- Only operational knobs are exposed as action inputs — `inputs` (paths), `persona`, and `advanced-security`.
180
+ Only operational knobs are exposed as action inputs — `inputs` (paths), `persona`, `advanced-security`, and `token`. Severity and rule selection stay central.
99
181
 
100
182
  `advanced-security` is **off** by default. Uploading to the security tab needs GitHub Advanced Security, which private repositories only have under a licence; with it off you get inline PR annotations instead, which need no entitlement. The upstream action defaults this to `true` and refuses to run with both it and `annotations` enabled, so the wrapper derives `annotations` from it.
101
183
 
184
+ ---
185
+
186
+ ## Commit messages
187
+
188
+ Commit messages follow **Conventional Commits with a leading gitmoji** — every message needs an emoji plus a `type: subject`, e.g. `🎉 feat: add the widget`, `🐛 fix: correct the resolver`. The convention is enforced in two places: a local git hook that blocks a bad message as you commit, and a CI gate that blocks it at the PR (so it can't be skipped with `git commit --no-verify` or by never installing the hook).
189
+
190
+ ### Local: the shared config + hooks (npm)
191
+
192
+ ```bash
193
+ pnpm add -D @vwala/tooling-config @commitlint/cli commitizen cz-emoji-conventional husky lint-staged
194
+ ```
195
+
196
+ Point your `commitlint.config.js` at the shared config (it layers gitmoji on top of Conventional Commits, so you no longer declare `commitlint-config-gitmoji` yourself — it comes transitively):
197
+
198
+ ```js
199
+ // commitlint.config.js (use `export default { … }` if your repo is "type": "module")
200
+ module.exports = { extends: ["@vwala/tooling-config/commitlint"] };
201
+ ```
202
+
203
+ Wire the hooks into `package.json`. The `prepare` script runs husky, then the shipped installer copies the canonical `commit-msg`, `pre-commit` and `prepare-commit-msg` hooks into your `.husky/` — so every repo runs identical hooks from one source of truth:
204
+
205
+ ```jsonc
206
+ {
207
+ "scripts": {
208
+ "commit": "cz",
209
+ "prepare": "husky && node node_modules/@vwala/tooling-config/src/commitlint/_scripts/install-hooks.mjs"
210
+ },
211
+ "config": {
212
+ "commitizen": {
213
+ "path": "node_modules/cz-emoji-conventional",
214
+ "useGitmojis": true
215
+ }
216
+ },
217
+ "lint-staged": {
218
+ "*": ["biome check --write --no-errors-on-unmatched"]
219
+ }
220
+ }
221
+ ```
222
+
223
+ `pnpm install` runs `prepare`, so the hooks land on the first install. `pnpm commit` opens the interactive gitmoji + conventional prompt; `commit-msg` then lints whatever message you end up with, and `pre-commit` runs Biome over staged files via lint-staged.
224
+
225
+ ### CI: the bypass-proof gate (GitHub Action)
226
+
227
+ Add a step to the workflow you already have. Check out with `fetch-depth: 0` so the whole commit range is present, install first, then run the shared action over the PR's `base..head`:
228
+
229
+ ```yaml
230
+ jobs:
231
+ ci:
232
+ runs-on: ubuntu-latest
233
+ steps:
234
+ - uses: actions/checkout@v6
235
+ with:
236
+ persist-credentials: false
237
+ fetch-depth: 0
238
+
239
+ - uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
240
+ - uses: actions/setup-node@v6
241
+ with:
242
+ node-version: 24
243
+ cache: "pnpm"
244
+ - run: pnpm install --frozen-lockfile
245
+
246
+ - name: Lint commit messages
247
+ if: github.event_name == 'pull_request'
248
+ uses: vwala-be/tooling-config/src/commitlint@v1.1.0
249
+ with:
250
+ from: ${{ github.event.pull_request.base.sha }}
251
+ to: ${{ github.event.pull_request.head.sha }}
252
+ ```
253
+
254
+ The action pins and fetches nothing — it runs your repo's own installed commitlint against the shared config, so the commitlint version stays under your lockfile. Make it a **required status check** (branch protection) so a non-conventional commit can't be merged.
255
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vwala/tooling-config",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "description": "Shared tooling configuration for Vwala repositories",
6
6
  "license": "UNLICENSED",
@@ -17,22 +17,65 @@
17
17
  "!src/**/test-support"
18
18
  ],
19
19
  "exports": {
20
- "./biome": "./src/biome/biome.config.json"
20
+ "./biome": "./src/biome/biome.config.json",
21
+ "./commitlint": "./src/commitlint/commitlint.config.js",
22
+ "./typescript/base": "./src/typescript/base.json",
23
+ "./typescript/bundler": "./src/typescript/bundler.json",
24
+ "./typescript/node": "./src/typescript/node.json",
25
+ "./typescript/react-library": "./src/typescript/react-library.json",
26
+ "./typescript/nextjs": "./src/typescript/nextjs.json",
27
+ "./typescript/expo": "./src/typescript/expo.json"
28
+ },
29
+ "dependencies": {
30
+ "commitlint-config-gitmoji": "^2.3.1"
21
31
  },
22
32
  "scripts": {
23
33
  "lint": "biome check .",
24
34
  "format": "biome check --write .",
35
+ "typecheck": "tsc --noEmit",
25
36
  "test": "vitest run",
26
- "isEverythingOk": "biome ci . && vitest run"
37
+ "commit": "cz",
38
+ "prepare": "husky && node src/commitlint/_scripts/install-hooks.mjs",
39
+ "isEverythingOk": "biome ci . && tsc --noEmit && vitest run"
40
+ },
41
+ "config": {
42
+ "commitizen": {
43
+ "path": "node_modules/cz-emoji-conventional",
44
+ "useGitmojis": true
45
+ }
46
+ },
47
+ "lint-staged": {
48
+ "*": [
49
+ "biome check --write --no-errors-on-unmatched"
50
+ ]
27
51
  },
28
52
  "devDependencies": {
29
53
  "@biomejs/biome": "2.5.6",
54
+ "@commitlint/cli": "^21.2.1",
30
55
  "@types/node": "^26.1.2",
31
56
  "@vwala/tooling-config": "link:.",
57
+ "commitizen": "^4.3.2",
58
+ "cz-emoji-conventional": "^1.2.1",
59
+ "husky": "^9.1.7",
60
+ "lint-staged": "^17.0.8",
61
+ "typescript": "^7.0.2",
32
62
  "vitest": "^4.1.10"
33
63
  },
34
64
  "peerDependencies": {
35
- "@biomejs/biome": ">=2.5.0"
65
+ "@biomejs/biome": ">=2.5.0",
66
+ "@commitlint/cli": ">=19",
67
+ "typescript": ">=5.7.0"
68
+ },
69
+ "peerDependenciesMeta": {
70
+ "@biomejs/biome": {
71
+ "optional": true
72
+ },
73
+ "@commitlint/cli": {
74
+ "optional": true
75
+ },
76
+ "typescript": {
77
+ "optional": true
78
+ }
36
79
  },
37
80
  "packageManager": "pnpm@11.15.0"
38
81
  }
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Installs Vwala's shared git hooks into the consuming repository's `.husky/`.
4
+ *
5
+ * husky itself (run first, via `"prepare": "husky && node …/install-hooks.mjs"`)
6
+ * points `core.hooksPath` at `.husky/` and creates its internal `.husky/_/`.
7
+ * This script then copies the shipped hook templates from the package's
8
+ * `../hooks/` folder into `.husky/`, so every repo runs byte-identical
9
+ * `commit-msg`, `pre-commit` and `prepare-commit-msg` hooks from one source of
10
+ * truth. It overwrites on every run — the shipped copy is canonical — and is
11
+ * safe to run repeatedly.
12
+ *
13
+ * It writes into `process.cwd()`, which is the repo root during the `prepare`
14
+ * lifecycle, and reads the templates relative to its own location, so it works
15
+ * both here (dogfooding, `src/commitlint/hooks`) and from a consumer's
16
+ * `node_modules/@vwala/tooling-config/src/commitlint/hooks`.
17
+ */
18
+ import { chmod, copyFile, mkdir, readdir } from "node:fs/promises";
19
+ import path from "node:path";
20
+ import { fileURLToPath } from "node:url";
21
+
22
+ const scriptDirectory = path.dirname(fileURLToPath(import.meta.url));
23
+ const hooksSource = path.resolve(scriptDirectory, "..", "hooks");
24
+ const huskyDirectory = path.join(process.cwd(), ".husky");
25
+
26
+ const hooks = await readdir(hooksSource);
27
+ await mkdir(huskyDirectory, { recursive: true });
28
+
29
+ for (const hook of hooks) {
30
+ const destination = path.join(huskyDirectory, hook);
31
+ await copyFile(path.join(hooksSource, hook), destination);
32
+ // Git only runs a hook that is executable.
33
+ await chmod(destination, 0o755);
34
+ }
35
+
36
+ console.log(` ✔ installed ${hooks.length} git hook(s) into .husky/`);
@@ -0,0 +1,43 @@
1
+ name: Vwala commitlint
2
+ description: >-
3
+ Lint a range of commit messages with Vwala's shared conventional-commit +
4
+ gitmoji config.
5
+
6
+ # Runs commitlint over a commit range using the repository's own installed
7
+ # @commitlint/cli and the shared @vwala/tooling-config/commitlint config — so the
8
+ # convention the local commit-msg hook enforces is enforced again in CI, where it
9
+ # cannot be skipped with `git commit --no-verify` or by never installing the
10
+ # hook. This is the bypass-proof half of the enforcement; the husky hook is the
11
+ # fast-feedback half.
12
+ #
13
+ # The caller must (1) check out with `fetch-depth: 0` so the whole commit range
14
+ # is present, and (2) install dependencies first, so `node_modules/.bin/commitlint`
15
+ # and the shared config exist. The action pins nothing and fetches nothing — it
16
+ # reuses what the repository already declares, keeping the commitlint version
17
+ # under the consumer's lockfile rather than this action.
18
+
19
+ inputs:
20
+ from:
21
+ description: >-
22
+ Ref or SHA to lint commits from (exclusive). For a pull request, the base
23
+ SHA (e.g. github.event.pull_request.base.sha).
24
+ required: true
25
+ to:
26
+ description: Ref or SHA to lint commits to (inclusive).
27
+ required: false
28
+ default: HEAD
29
+
30
+ runs:
31
+ using: composite
32
+ steps:
33
+ # `${{ inputs.* }}` is routed through env and referenced as "$VAR" rather than
34
+ # interpolated straight into the script, so a crafted ref can't break out of
35
+ # the command (zizmor: template-injection). `npx --no` resolves the locally
36
+ # installed binary and refuses to fetch one, so this never becomes an
37
+ # unpinned package pull (zizmor: adhoc-packages).
38
+ - name: Lint commit messages
39
+ shell: bash
40
+ env:
41
+ FROM: ${{ inputs.from }}
42
+ TO: ${{ inputs.to }}
43
+ run: npx --no -- commitlint --from "$FROM" --to "$TO" --verbose
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Vwala's shared commitlint config — the one place the commit-message convention
3
+ * lives. Consumers extend it from their own `commitlint.config.js`:
4
+ *
5
+ * export default { extends: ["@vwala/tooling-config/commitlint"] };
6
+ *
7
+ * It layers on `commitlint-config-gitmoji`, which is the gitmoji flavor of
8
+ * Conventional Commits: every message needs a leading gitmoji plus a
9
+ * conventional `type: subject`. commitlint resolves nested `extends` recursively
10
+ * and looks the package up relative to THIS file, so `commitlint-config-gitmoji`
11
+ * is a runtime dependency of @vwala/tooling-config — a consumer no longer
12
+ * declares it directly.
13
+ *
14
+ * `rules` is intentionally left empty: it is the seam for Vwala-specific
15
+ * overrides on top of the gitmoji base. Keep the allowed types/emoji aligned
16
+ * with the vocabulary in `.github/release-drafter.yml` so commit messages and
17
+ * PR-title labeling do not drift.
18
+ *
19
+ * @type {import("@commitlint/types").UserConfig}
20
+ */
21
+ export default {
22
+ extends: ["gitmoji"],
23
+ rules: {},
24
+ };
@@ -0,0 +1 @@
1
+ npx --no -- commitlint --edit "$1"
@@ -0,0 +1 @@
1
+ pnpm lint-staged
@@ -0,0 +1,7 @@
1
+ # Skip cz whenever Git is already supplying a commit message.
2
+ # That covers amend, rebase, merge, squash, and cherry-pick flows.
3
+ if [ -n "${2:-}" ]; then
4
+ exit 0
5
+ fi
6
+
7
+ exec < /dev/tty && npx cz --hook || true
@@ -0,0 +1,19 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "declarationMap": true,
6
+ "esModuleInterop": true,
7
+ "incremental": false,
8
+ "isolatedModules": true,
9
+ "lib": ["es2024", "DOM", "DOM.Iterable"],
10
+ "module": "NodeNext",
11
+ "moduleDetection": "force",
12
+ "moduleResolution": "NodeNext",
13
+ "noUncheckedIndexedAccess": true,
14
+ "resolveJsonModule": true,
15
+ "skipLibCheck": true,
16
+ "strict": true,
17
+ "target": "ES2024"
18
+ }
19
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./base.json",
4
+ "compilerOptions": {
5
+ "module": "ESNext",
6
+ "moduleResolution": "Bundler"
7
+ }
8
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./bundler.json",
4
+ "compilerOptions": {
5
+ "allowJs": true,
6
+ "jsx": "react-jsx",
7
+ "noEmit": true
8
+ }
9
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./bundler.json",
4
+ "compilerOptions": {
5
+ "plugins": [{ "name": "next" }],
6
+ "allowJs": true,
7
+ "jsx": "preserve",
8
+ "noEmit": true
9
+ }
10
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./base.json",
4
+ "compilerOptions": {
5
+ "lib": ["es2022"],
6
+ "types": ["node"]
7
+ }
8
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./base.json",
4
+ "compilerOptions": {
5
+ "jsx": "react-jsx"
6
+ }
7
+ }
@@ -28,6 +28,26 @@ inputs:
28
28
  entitlement and no security-events permission.
29
29
  required: false
30
30
  default: "false"
31
+ token:
32
+ description: >-
33
+ GitHub API token for zizmor's online audits. Defaults to the calling
34
+ job's GITHUB_TOKEN, which is scoped to the calling repository alone.
35
+
36
+ A consuming repository normally has to override this. Adding this action
37
+ puts `vwala-be/tooling-config/src/zizmor@vX.Y.Z` into that repository's
38
+ own workflow, and zizmor resolves every `uses:` through the API. This
39
+ repository is private, so the default token cannot read it and the
40
+ `ref-confusion` audit fails hard with "missing or you have no access".
41
+ That is an audit error rather than a finding, so no `# zizmor: ignore`
42
+ can suppress it. Pass a token that can read this repository instead —
43
+ for example one minted by `actions/create-github-app-token` scoped to
44
+ `tooling-config` with `permission-contents: read`.
45
+
46
+ Our own CI never hits this, because it dogfoods the action through the
47
+ local `./src/zizmor` path and so has no cross-repository `uses:` to
48
+ resolve.
49
+ required: false
50
+ default: ${{ github.token }}
31
51
 
32
52
  runs:
33
53
  using: composite
@@ -51,6 +71,7 @@ runs:
51
71
  version: "1.29.0"
52
72
  persona: ${{ inputs.persona }}
53
73
  advanced-security: ${{ inputs.advanced-security }}
74
+ token: ${{ inputs.token }}
54
75
  # The action rejects advanced-security and annotations both being true.
55
76
  annotations: ${{ inputs.advanced-security == 'true' && 'false' || 'true' }}
56
77