@vwala/tooling-config 1.4.1 → 1.5.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/.vwala/docs/README.md +4 -0
- package/.vwala/docs/react-19.md +119 -0
- package/.vwala/docs/react-compiler.md +128 -0
- package/README.md +20 -2
- package/package.json +16 -4
- package/src/_scripts/check-conventions.mjs +8 -0
- package/src/biome/biome.config.json +1 -1
- package/src/biome/plugins/no-manual-react-memoization.grit +5 -0
- package/src/biome/plugins/no-react-use-context.grit +5 -0
- package/src/react-compiler/build/artifact-inventory.mjs +39 -0
- package/src/react-compiler/build/build-command-process.mjs +58 -0
- package/src/react-compiler/build/compile-react-library.mjs +39 -0
- package/src/react-compiler/build/emitted-artifacts.mjs +34 -0
- package/src/react-compiler/build/is-react-source.mjs +43 -0
- package/src/react-compiler/build/mark-library-compiler-ownership.mjs +47 -0
- package/src/react-compiler/build/overlay-react-library.mjs +53 -0
- package/src/react-compiler/build/read-build-project.mjs +33 -0
- package/src/react-compiler/build/transform-react-source.mjs +72 -0
- package/src/react-compiler/build/watch-react-library.mjs +111 -0
- package/src/react-compiler/policy/advisory-diagnostic.mjs +30 -0
- package/src/react-compiler/policy/biome-exit-code.mjs +30 -0
- package/src/react-compiler/policy/biome-report.mjs +46 -0
- package/src/react-compiler/policy/check-react-19-apis.mjs +30 -0
- package/src/react-compiler/policy/check-react-19-repository.mjs +33 -0
- package/src/react-compiler/policy/check-react-memoization.mjs +30 -0
- package/src/react-compiler/policy/check-repository.mjs +33 -0
- package/src/react-compiler/policy/compiler-scope.mjs +73 -0
- package/src/react-compiler/policy/find-manual-memoization.mjs +50 -0
- package/src/react-compiler/policy/find-react-19-apis.mjs +33 -0
- package/src/react-compiler/policy/memoization-exception.mjs +34 -0
- package/src/react-compiler/policy/react-19-scope.mjs +74 -0
- package/src/react-compiler/policy/react-call-name.mjs +42 -0
- package/src/react-compiler/policy/repository-files.mjs +48 -0
- package/src/react-compiler/policy/run-biome.mjs +55 -0
- package/src/react-compiler/policy/scoped-source.mjs +35 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
# Tooling guides
|
|
2
|
+
|
|
3
|
+
- [React Compiler](react-compiler.md): opt-in compiler diagnostics, memoization policy, shared-library builds, and verification.
|
|
4
|
+
- [React 19 API policy](react-19.md): separately scoped `useContext` and `forwardRef` migrations, editor diagnostics, and enforcement.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# React 19 API policy
|
|
2
|
+
|
|
3
|
+
The React 19 API policy is an explicit package opt-in. It is independent of [React Compiler adoption](react-compiler.md): enabling the compiler does not enable this policy, and enabling this policy does not assert that compiler output is in use. Keep packages that still support React 18 outside this scope.
|
|
4
|
+
|
|
5
|
+
React 19 continues to support [`useContext`](https://react.dev/reference/react/useContext), but adopted packages use [`use(Context)`](https://react.dev/reference/react/use) instead. [`forwardRef`](https://react.dev/reference/react/forwardRef) is no longer needed in React 19 and React plans to deprecate it in a future release. Passing `ref` as a prop and using `useRef` remain supported and are not restricted by this policy.
|
|
6
|
+
|
|
7
|
+
## Adopted package scopes
|
|
8
|
+
|
|
9
|
+
Install `@vwala/tooling-config` at the repository root beside `biome.json` or `biome.jsonc`. Add the plugin and override below while retaining existing plugins and overrides. Replace the example package roots with the React 19 packages that you own.
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"plugins": [
|
|
14
|
+
{
|
|
15
|
+
"path": "./node_modules/@vwala/tooling-config/src/biome/plugins/no-react-use-context.grit",
|
|
16
|
+
"includes": [
|
|
17
|
+
"**/apps/app-web/**",
|
|
18
|
+
"**/packages/platform/ui/**",
|
|
19
|
+
"!**/node_modules/**",
|
|
20
|
+
"!**/.git/**",
|
|
21
|
+
"!**/dist/**",
|
|
22
|
+
"!**/build/**",
|
|
23
|
+
"!**/.next/**",
|
|
24
|
+
"!**/.expo/**",
|
|
25
|
+
"!**/coverage/**",
|
|
26
|
+
"!**/generated/**",
|
|
27
|
+
"!**/__generated__/**",
|
|
28
|
+
"!**/__tests__/**",
|
|
29
|
+
"!**/test-support/**",
|
|
30
|
+
"!**/fixtures/**",
|
|
31
|
+
"!**/__fixtures__/**",
|
|
32
|
+
"!**/vendor/**",
|
|
33
|
+
"!**/vendored/**",
|
|
34
|
+
"!**/*.test.*",
|
|
35
|
+
"!**/*.spec.*",
|
|
36
|
+
"!**/*.d.ts",
|
|
37
|
+
"!**/*.d.mts",
|
|
38
|
+
"!**/*.d.cts"
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
"overrides": [
|
|
43
|
+
{
|
|
44
|
+
"includes": [
|
|
45
|
+
"**/apps/app-web/**",
|
|
46
|
+
"**/packages/platform/ui/**",
|
|
47
|
+
"!**/node_modules/**",
|
|
48
|
+
"!**/.git/**",
|
|
49
|
+
"!**/dist/**",
|
|
50
|
+
"!**/build/**",
|
|
51
|
+
"!**/.next/**",
|
|
52
|
+
"!**/.expo/**",
|
|
53
|
+
"!**/coverage/**",
|
|
54
|
+
"!**/generated/**",
|
|
55
|
+
"!**/__generated__/**",
|
|
56
|
+
"!**/__tests__/**",
|
|
57
|
+
"!**/test-support/**",
|
|
58
|
+
"!**/fixtures/**",
|
|
59
|
+
"!**/__fixtures__/**",
|
|
60
|
+
"!**/vendor/**",
|
|
61
|
+
"!**/vendored/**",
|
|
62
|
+
"!**/*.test.*",
|
|
63
|
+
"!**/*.spec.*",
|
|
64
|
+
"!**/*.d.ts",
|
|
65
|
+
"!**/*.d.mts",
|
|
66
|
+
"!**/*.d.cts"
|
|
67
|
+
],
|
|
68
|
+
"linter": {
|
|
69
|
+
"rules": {
|
|
70
|
+
"suspicious": { "noReactForwardRef": "warn" }
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The two `includes` arrays must contain exactly the same package roots and exclusions. The convention checker rejects mismatches and nonliteral package patterns. Stories remain included; tests, declarations, generated code, fixtures, vendored code, dependencies, coverage, and build output remain excluded.
|
|
79
|
+
|
|
80
|
+
## Migrations
|
|
81
|
+
|
|
82
|
+
Replace context reads with `use(Context)`. Unlike `useContext`, `use` may be called in conditions and loops, while it must still run inside a component or Hook.
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
import { use } from "react";
|
|
86
|
+
|
|
87
|
+
export function AccountName() {
|
|
88
|
+
const account = use(AccountContext);
|
|
89
|
+
return <span>{account.name}</span>;
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Replace `forwardRef` wrappers with a component that accepts `ref` as a prop.
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
import type { ComponentPropsWithRef } from "react";
|
|
97
|
+
|
|
98
|
+
export function TextInput({ ref, ...props }: ComponentPropsWithRef<"input">) {
|
|
99
|
+
return <input ref={ref} {...props} />;
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The binding-aware convention check finds both APIs through named and aliased imports, default and namespace imports, static or computed members, and optional calls. It ignores unrelated and shadowed identifiers. There are no call-specific exceptions inside an adopted package.
|
|
104
|
+
|
|
105
|
+
For component API and provider design during migration, use the installed [`vercel-composition-patterns` skill](../skills/library/vercel-composition-patterns/SKILL.md).
|
|
106
|
+
|
|
107
|
+
## Enforcement
|
|
108
|
+
|
|
109
|
+
`check-conventions` runs `React 19 APIs` as its ninth check. Existing findings in untouched scoped files are warnings. Added, modified, renamed, staged, unstaged, and untracked scoped files fail until every `useContext` and `forwardRef` call in the file is migrated.
|
|
110
|
+
|
|
111
|
+
Local checks compare with the merge base of `origin/main`. CI must set `REACT_19_BASE_REF` to the pull request base or previous push commit and fetch enough history to resolve it. An unavailable comparison base fails the check.
|
|
112
|
+
|
|
113
|
+
When an existing Biome command treats warnings as errors, use the shared wrapper:
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
node node_modules/@vwala/tooling-config/src/react-compiler/policy/run-biome.mjs ci . --error-on-warnings --diagnostic-level=warn
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Within the explicit React 19 scope, only `noReactForwardRef` and `[no-react-use-context]` warnings remain advisory. Unrelated warnings, warnings outside the scope, plugin failures, configuration failures, and ordinary errors retain their failing behavior.
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# React Compiler integration
|
|
2
|
+
|
|
3
|
+
Compilation, compiler diagnostics, and manual-memoization policy are separate capabilities. Enable all three for each adopted application or shared React package. A dependency installation or a clean lint result does not establish that the production artifact was compiled.
|
|
4
|
+
|
|
5
|
+
## Application builds
|
|
6
|
+
|
|
7
|
+
Use React Compiler 1.0.0 through the framework's supported build integration. React 19 supplies `react/compiler-runtime`; no compatibility runtime dependency is needed. Use normal `infer` analysis and `panicThreshold: "none"`. Unsupported functions may be skipped; keep diagnostic reports and artifact evidence alongside build results.
|
|
8
|
+
|
|
9
|
+
Next.js 16 uses `reactCompiler: { compilationMode: "infer", panicThreshold: "none" }`. Expo uses its supported `experiments.reactCompiler` configuration and Babel preset. Vite/Storybook configure the compiler through their React transform. Check the actual production build as well as development.
|
|
10
|
+
|
|
11
|
+
Give each artifact one compiler owner. A library build compiles its published `dist`; a consumer importing original source compiles that source instead. Preserve other required consumer transpilation without deliberately passing already compiled output through React Compiler again.
|
|
12
|
+
|
|
13
|
+
After its original-source compiler pass, the library helper adds documented `"use no memo"` guards to generated modules and functions. These prevent downstream compilers from optimizing the artifact again, including when Next.js or Metro resolves a workspace symlink to its real `dist` path. They are generated ownership markers, not opt-outs added to product source. Existing `"use client"` boundaries remain intact. Storybook also excludes `dist` while compiling its source aliases.
|
|
14
|
+
|
|
15
|
+
Library components that execute as React Server Components need a documented function-level `"use no memo"` in their original source: the client memoization runtime is unavailable there. Keep server-only providers on the server; adding `"use client"` to make them compile can expose server credentials and change their execution model. Verify these boundaries through production HTTP requests, since a build can pass while the server render fails.
|
|
16
|
+
|
|
17
|
+
## Adopted policy scopes
|
|
18
|
+
|
|
19
|
+
Install `@vwala/tooling-config` at the repository root beside `biome.json` or `biome.jsonc`. Pin Biome 2.5.13 and use its matching schema. Merge the following into the root configuration while retaining existing plugins and overrides:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"javascript": {
|
|
24
|
+
"resolver": { "experimentalPnpmCatalogs": true }
|
|
25
|
+
},
|
|
26
|
+
"plugins": [
|
|
27
|
+
{
|
|
28
|
+
"path": "./node_modules/@vwala/tooling-config/src/biome/plugins/no-manual-react-memoization.grit",
|
|
29
|
+
"includes": ["**/apps/app-web/**", "**/packages/platform/ui/**"]
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"overrides": [
|
|
33
|
+
{
|
|
34
|
+
"includes": ["**/apps/app-web/**", "**/packages/platform/ui/**"],
|
|
35
|
+
"linter": {
|
|
36
|
+
"rules": {
|
|
37
|
+
"nursery": { "useReactCompiler": "warn" }
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The plugin's explicit package-root includes declare the policy scope. Keep the compiler override's scopes identical. The leading `**/` is necessary for Biome plugin matching. Do not infer coverage from the repository name, installed dependencies, or a framework flag. React must be declared in the nearest package manifest; enable catalog resolution for `catalog:` declarations and verify peer-only packages too.
|
|
46
|
+
|
|
47
|
+
Append these exclusions to both `includes` arrays above so editor diagnostics have the same source boundaries as the convention checker. Stories remain included.
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
[
|
|
51
|
+
"!**/node_modules/**", "!**/.git/**", "!**/dist/**", "!**/build/**",
|
|
52
|
+
"!**/.next/**", "!**/.expo/**", "!**/coverage/**",
|
|
53
|
+
"!**/generated/**", "!**/__generated__/**", "!**/__tests__/**",
|
|
54
|
+
"!**/test-support/**", "!**/fixtures/**", "!**/__fixtures__/**",
|
|
55
|
+
"!**/vendor/**", "!**/vendored/**", "!**/*.test.*", "!**/*.spec.*",
|
|
56
|
+
"!**/*.d.ts", "!**/*.d.mts", "!**/*.d.cts"
|
|
57
|
+
]
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The convention checker runs with `check-conventions`. It resolves actual React import bindings, including aliases, default and namespace imports, and static member access. Unrelated or shadowed names are ignored. Stories are included; generated output, declarations, tests, fixtures, and vendored code are excluded.
|
|
61
|
+
|
|
62
|
+
Untouched files warn. Added, modified, and renamed source files must resolve every manual memoization call in the file, even after formatting-only changes. Local checks compare against the merge base with `origin/main`, including staged, unstaged, and untracked files. CI supplies `REACT_COMPILER_BASE_REF` with the PR base or the previous push commit and fetches enough history to resolve it. An unavailable comparison base is an error.
|
|
63
|
+
|
|
64
|
+
Where an existing Biome command fails on warnings, invoke the shared wrapper to retain that gate while allowing the two adopted warning categories:
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
node node_modules/@vwala/tooling-config/src/react-compiler/policy/run-biome.mjs ci . --error-on-warnings --diagnostic-level=warn
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The wrapper also accepts `check`, `--write`, changed-file arguments, and the alias `--warnings-as-errors`. Preserve each command's existing warning and diagnostic-level settings; omit the warning flag where warnings were already advisory. It requests a complete JSON report, preserves compiler and plugin warnings in output, and fails on unrelated gated diagnostics, incomplete reports, or tool/configuration failures.
|
|
71
|
+
|
|
72
|
+
## Manual memoization exceptions
|
|
73
|
+
|
|
74
|
+
Prefer plain components, calculations, and functions. Retain memoization only for a concrete need: precise control, library compatibility, a meaningful custom comparison, or measured benefit. Validate removals, especially effect dependencies and callback consumers.
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
import { useCallback } from "react";
|
|
78
|
+
|
|
79
|
+
// biome-ignore lint/plugin/no-manual-react-memoization: The subscription adapter keys registration by callback identity; retain it across unrelated renders.
|
|
80
|
+
const onUpdate = useCallback(() => refresh(accountId), [accountId, refresh]);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Use canonical named React imports for exceptions. Put the exact rule-specific comment immediately before a statement containing exactly one memoization call. An import-level, file-wide, range, or blanket suppression does not satisfy the policy. Tooling checks placement and the presence of a reason; reviewers assess the reason. Editor alias coverage is advisory, so a quiet editor does not prove compliance.
|
|
84
|
+
|
|
85
|
+
Compiler opt-outs need a narrow, documented incompatibility. They do not automatically excuse manual memoization. Never replace memoization with refs or suppress hook diagnostics merely to pass the gate.
|
|
86
|
+
|
|
87
|
+
## Library builds
|
|
88
|
+
|
|
89
|
+
The `compile-react-library` command overlays compiled JavaScript onto an existing TypeScript build:
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
pnpm exec tsc -p tsconfig.build.json
|
|
93
|
+
pnpm exec compile-react-library --project tsconfig.build.json --format esm
|
|
94
|
+
pnpm exec tsc-alias -p tsconfig.build.json
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Use `--format commonjs` for a CommonJS package. The helper processes original React TS/TSX with React Compiler first in Babel, never TypeScript-emitted JavaScript. Existing declarations and runtime resources remain in place, and alias rewriting runs after both emitters. Keep package exports, module formats, JSX runtime, client directives, and source maps compatible with the original build.
|
|
98
|
+
|
|
99
|
+
For comparison tests, pass `--compiler off` to retain the same Babel pipeline without the compiler plugin. Use separate clean output directories or sequential clean builds for the two variants. Compare the overlay against the normal TypeScript build as well.
|
|
100
|
+
|
|
101
|
+
Watch builds must sequence TypeScript, compiler overlay, and alias rewriting. Never run independent watchers that compete to write `dist`. A deletion or failed rebuild must not leave a stale compiled artifact available as if the build succeeded.
|
|
102
|
+
|
|
103
|
+
Use the helper's sequenced watch mode, with a package script for alias rewriting and any remaining asset work:
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
pnpm exec compile-react-library --project tsconfig.build.json --format esm --watch --after build:finish
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`build:finish` must finish before the next rebuild starts. The watch helper owns TypeScript emission too; do not start `tsc --watch` alongside it. Compiler-on/off comparisons use the same helper and post-build script.
|
|
110
|
+
|
|
111
|
+
The watcher observes TypeScript sources and the selected build tsconfig. Restart it after changing an inherited tsconfig outside the package. The helper preserves the configured JSX runtime and maps; it does not add JavaScript downlevel transforms for older runtime targets. A contradictory `.mts`/CommonJS or `.cts`/ESM request fails explicitly.
|
|
112
|
+
|
|
113
|
+
## Verification and rollback
|
|
114
|
+
|
|
115
|
+
- Run behavior suites against actual built library exports with the compiler enabled and disabled; preserve ordinary source tests.
|
|
116
|
+
- Verify representative components and hooks in production artifacts, including libraries without direct React imports in their source. Record compilation successes and skips; a green build alone is insufficient.
|
|
117
|
+
- Build each web application and Storybook, and export production-mode mobile bundles after their workspace dependencies build.
|
|
118
|
+
- Smoke-test session changes, navigation, filters, lists, and modal/sheet interactions relevant to the product. Profile before claiming performance gains.
|
|
119
|
+
- Run the repository's complete `pnpm isEverythingOk` gate. Keep compiler/editor warnings visible while preserving unrelated warning/error gates.
|
|
120
|
+
|
|
121
|
+
Rollback restores an affected build configuration and removes its policy scope together. Restore validated memoization where necessary; do not assume disabling compilation preserves the performance of code whose manual memoization has been removed.
|
|
122
|
+
|
|
123
|
+
## Sources
|
|
124
|
+
|
|
125
|
+
- [React Compiler introduction](https://react.dev/learn/react-compiler/introduction)
|
|
126
|
+
- [Compiler configuration](https://react.dev/reference/react-compiler/configuration)
|
|
127
|
+
- [Compiling libraries](https://react.dev/reference/react-compiler/compiling-libraries)
|
|
128
|
+
- [Biome compiler diagnostics](https://biomejs.dev/linter/rules/use-react-compiler/javascript/)
|
package/README.md
CHANGED
|
@@ -40,6 +40,10 @@ src/
|
|
|
40
40
|
|
|
41
41
|
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.
|
|
42
42
|
|
|
43
|
+
## Updating downstream repositories
|
|
44
|
+
|
|
45
|
+
The private `tooling-config-update-repositories` Agent Skill previews updates to the repositories that consume a tooling-config release. Run `bash .agents/skills/tooling-config-update-repositories/scripts/update-repositories.sh`; add `--apply` only to create branches and ready pull requests. The script runs curated non-secret checks locally, while downstream CI remains the comprehensive merge gate.
|
|
46
|
+
|
|
43
47
|
---
|
|
44
48
|
|
|
45
49
|
## Biome
|
|
@@ -50,14 +54,14 @@ pnpm add -D @vwala/tooling-config @biomejs/biome
|
|
|
50
54
|
|
|
51
55
|
```json
|
|
52
56
|
{
|
|
53
|
-
"$schema": "https://biomejs.dev/schemas/2.5.
|
|
57
|
+
"$schema": "https://biomejs.dev/schemas/2.5.13/schema.json",
|
|
54
58
|
"extends": ["@vwala/tooling-config/biome"]
|
|
55
59
|
}
|
|
56
60
|
```
|
|
57
61
|
|
|
58
62
|
Anything you add alongside `extends` overrides the shared config for that key.
|
|
59
63
|
|
|
60
|
-
> **Requires Biome >= 2.5.
|
|
64
|
+
> **Requires Biome >= 2.5.13.** The React Compiler integration is tested against this version, including compiler diagnostics and pnpm catalog resolution. Upgrade the local binary and schema together before adopting the compiler policy.
|
|
61
65
|
|
|
62
66
|
> **Install it next to your `biome.json`.** Biome resolves plugin paths relative to the directory of the config doing the extending — *not* relative to this package. The shared config therefore refers to its own plugins as `./node_modules/@vwala/tooling-config/src/biome/plugins/*.grit`, which only resolves if the package is installed at the same level as your `biome.json` (normally the repository root). In a monorepo that means a root `devDependency`, not a nested workspace one.
|
|
63
67
|
>
|
|
@@ -78,6 +82,18 @@ Biome's own rules carry the [naming](#naming) and [export](#exports) conventions
|
|
|
78
82
|
|
|
79
83
|
Each plugin file carries a header comment explaining the rule and linking to the governing reference in the [`vwala-conventions`](https://github.com/vwala-be/skills) skill. The plugins have tests in `src/biome/plugins/__tests__/` that drive the real Biome binary over fixture workspaces, so a rule that silently stops matching fails CI.
|
|
80
84
|
|
|
85
|
+
### React Compiler
|
|
86
|
+
|
|
87
|
+
React Compiler adoption is opt-in per application or package. `useReactCompiler` supplies advisory compiler diagnostics; `no-manual-react-memoization.grit` supplies editor warnings; the shared convention checker makes unexplained memoization blocking across every touched file in an adopted scope. The base preset does not activate these rules for consumers that have not enabled compilation.
|
|
88
|
+
|
|
89
|
+
See the [React Compiler integration guide](.vwala/docs/react-compiler.md) for build setup, explicit scopes, exceptions, production verification, and the library build helper. The governing team policy lives in the canonical [`vwala-best-practices`](https://github.com/vwala-be/skills/tree/main/skills/vwala-best-practices) skill.
|
|
90
|
+
|
|
91
|
+
### React 19 APIs
|
|
92
|
+
|
|
93
|
+
React 19 API adoption has its own explicit package scope, independent of React Compiler. The `no-react-use-context.grit` plugin advises migrating `useContext` to `use(Context)`, Biome's `noReactForwardRef` rule advises accepting `ref` as a prop, and the `React 19 APIs` convention check blocks these calls in touched opted-in source. Packages that still support React 18 remain outside the scope; `ref` and `useRef` remain allowed.
|
|
94
|
+
|
|
95
|
+
See the [React 19 API policy guide](.vwala/docs/react-19.md) for the matching plugin and override configuration, exclusions, migrations, CI base reference, and warning-gate wrapper.
|
|
96
|
+
|
|
81
97
|
### Naming
|
|
82
98
|
|
|
83
99
|
Two of Biome's own rules carry the naming convention, both at `warn`:
|
|
@@ -133,6 +149,8 @@ Some conventions are about paths and manifests rather than syntax, and Biome rea
|
|
|
133
149
|
|
|
134
150
|
| Check | Enforces |
|
|
135
151
|
| --- | --- |
|
|
152
|
+
| `React memoization` | Manual React memoization in compiler-adopted packages is documented or removed when a source file changes. |
|
|
153
|
+
| `React 19 APIs` | `useContext` and `forwardRef` are migrated in touched files within separately opted-in React 19 packages. |
|
|
136
154
|
| `naming` | Folders are kebab-case, and a file added since the base ref is named kebab-case — the error half of the [naming](#naming) rules. |
|
|
137
155
|
| `test layout` | The path-level halves of [test layout boundaries](#test-layout-boundaries). |
|
|
138
156
|
| `pnpm` | The halves of the [package manager](#package-manager) convention Biome cannot see — lockfiles, `packageManager`, and the invocations in hooks, workflows and Dockerfiles. |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vwala/tooling-config",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Shared tooling configuration for Vwala repositories",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,10 +13,12 @@
|
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
15
|
"src",
|
|
16
|
+
".vwala/docs",
|
|
16
17
|
"!src/**/__tests__",
|
|
17
18
|
"!src/**/test-support"
|
|
18
19
|
],
|
|
19
20
|
"bin": {
|
|
21
|
+
"compile-react-library": "./src/react-compiler/build/compile-react-library.mjs",
|
|
20
22
|
"ensure-gcp-application-default-credentials": "./src/gcloud/ensure-gcp-application-default-credentials.sh"
|
|
21
23
|
},
|
|
22
24
|
"exports": {
|
|
@@ -31,7 +33,15 @@
|
|
|
31
33
|
"./typescript/expo": "./src/typescript/expo.json"
|
|
32
34
|
},
|
|
33
35
|
"dependencies": {
|
|
34
|
-
"
|
|
36
|
+
"@babel/core": "7.29.7",
|
|
37
|
+
"@babel/parser": "7.29.8",
|
|
38
|
+
"@babel/plugin-transform-modules-commonjs": "7.29.7",
|
|
39
|
+
"@babel/preset-react": "7.29.7",
|
|
40
|
+
"@babel/preset-typescript": "7.29.7",
|
|
41
|
+
"@babel/traverse": "7.29.8",
|
|
42
|
+
"babel-plugin-react-compiler": "1.0.0",
|
|
43
|
+
"commitlint-config-gitmoji": "^2.3.1",
|
|
44
|
+
"jsonc-parser": "3.3.1"
|
|
35
45
|
},
|
|
36
46
|
"scripts": {
|
|
37
47
|
"lint": "biome check .",
|
|
@@ -55,7 +65,7 @@
|
|
|
55
65
|
]
|
|
56
66
|
},
|
|
57
67
|
"devDependencies": {
|
|
58
|
-
"@biomejs/biome": "2.5.
|
|
68
|
+
"@biomejs/biome": "2.5.13",
|
|
59
69
|
"@commitlint/cli": "^21.2.1",
|
|
60
70
|
"@types/node": "^26.1.2",
|
|
61
71
|
"@vwala/tooling-config": "link:.",
|
|
@@ -63,12 +73,14 @@
|
|
|
63
73
|
"cz-emoji-conventional": "^1.2.1",
|
|
64
74
|
"husky": "^9.1.7",
|
|
65
75
|
"lint-staged": "^17.0.8",
|
|
76
|
+
"react": "19.2.8",
|
|
77
|
+
"react-dom": "19.2.8",
|
|
66
78
|
"syncpack": "^15.3.2",
|
|
67
79
|
"typescript": "^7.0.2",
|
|
68
80
|
"vitest": "^4.1.10"
|
|
69
81
|
},
|
|
70
82
|
"peerDependencies": {
|
|
71
|
-
"@biomejs/biome": ">=2.5.
|
|
83
|
+
"@biomejs/biome": ">=2.5.13",
|
|
72
84
|
"@commitlint/cli": ">=19",
|
|
73
85
|
"syncpack": ">=15.0.0",
|
|
74
86
|
"typescript": ">=5.7.0"
|
|
@@ -24,6 +24,14 @@ const sourceRoot = path.resolve(
|
|
|
24
24
|
);
|
|
25
25
|
|
|
26
26
|
const CHECKS = [
|
|
27
|
+
{
|
|
28
|
+
name: "React memoization",
|
|
29
|
+
script: "react-compiler/policy/check-react-memoization.mjs",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "React 19 APIs",
|
|
33
|
+
script: "react-compiler/policy/check-react-19-apis.mjs",
|
|
34
|
+
},
|
|
27
35
|
{ name: "naming", script: "biome/_scripts/check-naming.mjs" },
|
|
28
36
|
{
|
|
29
37
|
name: "test layout",
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Advisory editor feedback. The binding-aware convention checker owns CI policy.
|
|
2
|
+
`$callee($arguments)` as $call where {
|
|
3
|
+
$callee <: r"^(?:useMemo|useCallback|memo)$",
|
|
4
|
+
register_diagnostic(span=$call, message="[no-manual-react-memoization] Prefer React Compiler; manual memoization needs a call-specific documented reason.", severity="warn")
|
|
5
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Advisory editor feedback. The binding-aware convention checker owns CI policy.
|
|
2
|
+
`$callee($arguments)` as $call where {
|
|
3
|
+
$callee <: r"^useContext$",
|
|
4
|
+
register_diagnostic(span=$call, message="[no-react-use-context] Prefer use(Context) in React 19.", severity="warn")
|
|
5
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
export async function artifactInventory({ outDir, current }) {
|
|
5
|
+
const manifest = path.join(outDir, ".react-compiler-artifacts.json");
|
|
6
|
+
let previous = [];
|
|
7
|
+
try {
|
|
8
|
+
previous = JSON.parse(await readFile(manifest, "utf8"));
|
|
9
|
+
} catch (error) {
|
|
10
|
+
if (error.code !== "ENOENT") {
|
|
11
|
+
throw error;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if (
|
|
15
|
+
!Array.isArray(previous) ||
|
|
16
|
+
previous.some(
|
|
17
|
+
(file) =>
|
|
18
|
+
typeof file !== "string" ||
|
|
19
|
+
!/(?:\.[cm]?jsx?|\.d\.[cm]?ts)(?:\.map)?$/.test(file) ||
|
|
20
|
+
path.isAbsolute(file) ||
|
|
21
|
+
file.split(/[\\/]/).includes(".."),
|
|
22
|
+
)
|
|
23
|
+
) {
|
|
24
|
+
throw new Error("Invalid React compiler artifact inventory");
|
|
25
|
+
}
|
|
26
|
+
const remove = async (files) => {
|
|
27
|
+
for (const file of files) {
|
|
28
|
+
await rm(path.join(outDir, file), { force: true });
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
prune: () => remove(previous.filter((file) => !current.includes(file))),
|
|
33
|
+
invalidate: () => remove([...new Set([...previous, ...current])]),
|
|
34
|
+
save: async () => {
|
|
35
|
+
await mkdir(outDir, { recursive: true });
|
|
36
|
+
await writeFile(manifest, JSON.stringify(current));
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
/** Own one sequential build command and its descendant process lifetime. */
|
|
4
|
+
export function createBuildCommandProcess() {
|
|
5
|
+
let active;
|
|
6
|
+
let stopped = false;
|
|
7
|
+
return {
|
|
8
|
+
run({ args, cwd }) {
|
|
9
|
+
if (stopped) {
|
|
10
|
+
return Promise.reject(new Error("Build stopped"));
|
|
11
|
+
}
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const child = spawn("pnpm", args, {
|
|
14
|
+
cwd,
|
|
15
|
+
detached: true,
|
|
16
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
17
|
+
});
|
|
18
|
+
active = child;
|
|
19
|
+
let stdout = "";
|
|
20
|
+
let stderr = "";
|
|
21
|
+
child.stdout.on("data", (chunk) => {
|
|
22
|
+
stdout += chunk;
|
|
23
|
+
});
|
|
24
|
+
child.stderr.on("data", (chunk) => {
|
|
25
|
+
stderr += chunk;
|
|
26
|
+
});
|
|
27
|
+
child.once("error", reject);
|
|
28
|
+
child.once("close", (code, signal) => {
|
|
29
|
+
active = undefined;
|
|
30
|
+
if (code === 0 && !signal && !stopped) {
|
|
31
|
+
resolve({ stdout, stderr });
|
|
32
|
+
} else {
|
|
33
|
+
reject(
|
|
34
|
+
Object.assign(
|
|
35
|
+
new Error(
|
|
36
|
+
`Build command failed (${signal ?? code}): pnpm ${args.join(" ")}`,
|
|
37
|
+
),
|
|
38
|
+
{ stdout, stderr },
|
|
39
|
+
),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
stop() {
|
|
46
|
+
stopped = true;
|
|
47
|
+
if (active?.pid) {
|
|
48
|
+
try {
|
|
49
|
+
process.kill(-active.pid, "SIGTERM");
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (error.code !== "ESRCH") {
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { parseArgs } from "node:util";
|
|
3
|
+
import { overlayReactLibrary } from "./overlay-react-library.mjs";
|
|
4
|
+
import { readBuildProject } from "./read-build-project.mjs";
|
|
5
|
+
import { watchReactLibrary } from "./watch-react-library.mjs";
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
const { values } = parseArgs({
|
|
9
|
+
options: {
|
|
10
|
+
project: { type: "string" },
|
|
11
|
+
format: { type: "string" },
|
|
12
|
+
compiler: { type: "string", default: "on" },
|
|
13
|
+
watch: { type: "boolean" },
|
|
14
|
+
after: { type: "string" },
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
if (
|
|
18
|
+
!values.project ||
|
|
19
|
+
!["esm", "commonjs"].includes(values.format) ||
|
|
20
|
+
!["on", "off"].includes(values.compiler)
|
|
21
|
+
) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
"Usage: compile-react-library --project <tsconfig> --format esm|commonjs [--compiler on|off]",
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
const input = {
|
|
27
|
+
project: readBuildProject(values.project),
|
|
28
|
+
format: values.format,
|
|
29
|
+
compiler: values.compiler === "on",
|
|
30
|
+
};
|
|
31
|
+
if (values.watch) {
|
|
32
|
+
await watchReactLibrary({ ...input, after: values.after });
|
|
33
|
+
} else {
|
|
34
|
+
await overlayReactLibrary(input);
|
|
35
|
+
}
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error(error.message);
|
|
38
|
+
process.exitCode = 1;
|
|
39
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
export function emittedArtifacts(project) {
|
|
4
|
+
return project.files
|
|
5
|
+
.filter((file) => /\.[cm]?tsx?$/.test(file) && !/\.d\.[cm]?ts$/.test(file))
|
|
6
|
+
.flatMap((file) => {
|
|
7
|
+
if (
|
|
8
|
+
file === project.outDir ||
|
|
9
|
+
file.startsWith(`${project.outDir}${path.sep}`)
|
|
10
|
+
) {
|
|
11
|
+
throw new Error(`Source is inside outDir: ${file}`);
|
|
12
|
+
}
|
|
13
|
+
const relative = path.relative(project.rootDir, file);
|
|
14
|
+
if (relative.startsWith("..") || path.isAbsolute(relative)) {
|
|
15
|
+
throw new Error(`Source is outside rootDir: ${file}`);
|
|
16
|
+
}
|
|
17
|
+
let extension = "js";
|
|
18
|
+
if (file.endsWith(".mts")) {
|
|
19
|
+
extension = "mjs";
|
|
20
|
+
} else if (file.endsWith(".cts")) {
|
|
21
|
+
extension = "cjs";
|
|
22
|
+
} else if (file.endsWith(".tsx") && project.options.jsx === "preserve") {
|
|
23
|
+
extension = "jsx";
|
|
24
|
+
}
|
|
25
|
+
const stem = relative.replace(/\.[cm]?tsx?$/, "");
|
|
26
|
+
const declaration = `${stem}.d.${({ mjs: "mts", cjs: "cts" })[extension] ?? "ts"}`;
|
|
27
|
+
return [
|
|
28
|
+
`${stem}.${extension}`,
|
|
29
|
+
`${stem}.${extension}.map`,
|
|
30
|
+
declaration,
|
|
31
|
+
`${declaration}.map`,
|
|
32
|
+
];
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { parse } from "@babel/parser";
|
|
2
|
+
import babelTraverse from "@babel/traverse";
|
|
3
|
+
|
|
4
|
+
const traverse = babelTraverse.default ?? babelTraverse;
|
|
5
|
+
|
|
6
|
+
export function isReactSource({ source, filename }) {
|
|
7
|
+
const ast = parse(source, {
|
|
8
|
+
sourceType: "unambiguous",
|
|
9
|
+
plugins: ["typescript", ...(filename.endsWith("x") ? ["jsx"] : [])],
|
|
10
|
+
});
|
|
11
|
+
let react = false;
|
|
12
|
+
traverse(ast, {
|
|
13
|
+
enter(astPath) {
|
|
14
|
+
const node = astPath.node;
|
|
15
|
+
if (["JSXElement", "JSXFragment"].includes(node.type)) {
|
|
16
|
+
react = true;
|
|
17
|
+
}
|
|
18
|
+
if (node.type === "CallExpression") {
|
|
19
|
+
const name = calleeName(node.callee);
|
|
20
|
+
if (name && /^(use[A-Z0-9]|createElement$)/.test(name)) {
|
|
21
|
+
react = true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (
|
|
25
|
+
node.type === "Directive" &&
|
|
26
|
+
["use memo", "use no memo"].includes(node.value.value)
|
|
27
|
+
) {
|
|
28
|
+
react = true;
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
return react;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function calleeName(callee) {
|
|
36
|
+
if (callee.type === "Identifier") {
|
|
37
|
+
return callee.name;
|
|
38
|
+
}
|
|
39
|
+
if (callee.type === "MemberExpression" && !callee.computed) {
|
|
40
|
+
return callee.property.name;
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|