@vwala/tooling-config 1.4.1 → 1.5.2
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 +130 -0
- package/README.md +29 -2
- package/package.json +18 -5
- 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 +85 -0
- package/src/react-compiler/policy/scoped-source.mjs +35 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { parse } from "@babel/parser";
|
|
2
|
+
import traverseModule from "@babel/traverse";
|
|
3
|
+
import { reactCallName } from "./react-call-name.mjs";
|
|
4
|
+
|
|
5
|
+
const traverse = traverseModule.default ?? traverseModule;
|
|
6
|
+
const legacyApiNames = new Set(["useContext", "forwardRef"]);
|
|
7
|
+
|
|
8
|
+
/** Find calls to React APIs superseded by React 19 syntax. */
|
|
9
|
+
export function findReact19Apis({ source, filename }) {
|
|
10
|
+
const ast = parse(source, {
|
|
11
|
+
sourceType: "unambiguous",
|
|
12
|
+
sourceFilename: filename,
|
|
13
|
+
plugins: [
|
|
14
|
+
"typescript",
|
|
15
|
+
...(/\.[cm]?ts$/.test(filename) ? [] : ["jsx"]),
|
|
16
|
+
"decorators-legacy",
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
const findings = [];
|
|
20
|
+
traverse(ast, {
|
|
21
|
+
"CallExpression|OptionalCallExpression"(call) {
|
|
22
|
+
const name = reactCallName(call.get("callee"));
|
|
23
|
+
if (legacyApiNames.has(name)) {
|
|
24
|
+
findings.push({
|
|
25
|
+
name,
|
|
26
|
+
line: call.node.loc.start.line,
|
|
27
|
+
column: call.node.loc.start.column + 1,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
return findings;
|
|
33
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Exceptions are deliberately statement-local and use canonical named calls. */
|
|
2
|
+
export function hasMemoizationException({
|
|
3
|
+
finding,
|
|
4
|
+
findings,
|
|
5
|
+
source,
|
|
6
|
+
comments,
|
|
7
|
+
}) {
|
|
8
|
+
if (!finding.canonical || !finding.statement) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (
|
|
12
|
+
findings.filter(
|
|
13
|
+
(other) =>
|
|
14
|
+
other.start >= finding.statement.start &&
|
|
15
|
+
other.start < finding.statement.end,
|
|
16
|
+
).length !== 1
|
|
17
|
+
) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const statementLine = finding.statement.loc.start.line;
|
|
21
|
+
if (
|
|
22
|
+
!comments.some(
|
|
23
|
+
(comment) =>
|
|
24
|
+
comment.type === "CommentLine" &&
|
|
25
|
+
comment.loc.end.line === statementLine - 1,
|
|
26
|
+
)
|
|
27
|
+
) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const previousLine = source.split(/\r?\n/)[statementLine - 2] ?? "";
|
|
31
|
+
return /^\s*\/\/ biome-ignore lint\/plugin\/no-manual-react-memoization:\s*\S.*$/.test(
|
|
32
|
+
previousLine,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { parse } from "jsonc-parser";
|
|
4
|
+
|
|
5
|
+
export const react19Plugin = "no-react-use-context.grit";
|
|
6
|
+
|
|
7
|
+
/** Return package roots that explicitly adopt the React 19 API policy. */
|
|
8
|
+
export function readReact19Scope({ root }) {
|
|
9
|
+
const filename = ["biome.json", "biome.jsonc"]
|
|
10
|
+
.map((name) => path.join(root, name))
|
|
11
|
+
.find(existsSync);
|
|
12
|
+
if (!filename) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
const errors = [];
|
|
16
|
+
const config = parse(readFileSync(filename, "utf8"), errors, {
|
|
17
|
+
allowTrailingComma: true,
|
|
18
|
+
});
|
|
19
|
+
if (errors.length || !config || typeof config !== "object") {
|
|
20
|
+
throw new Error("Invalid root Biome JSONC configuration");
|
|
21
|
+
}
|
|
22
|
+
const plugins = (config.plugins ?? []).filter(
|
|
23
|
+
(plugin) =>
|
|
24
|
+
path.basename(
|
|
25
|
+
typeof plugin === "string" ? plugin : (plugin.path ?? ""),
|
|
26
|
+
) === react19Plugin,
|
|
27
|
+
);
|
|
28
|
+
if (!plugins.length) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
const patterns = plugins.flatMap((plugin) => {
|
|
32
|
+
if (
|
|
33
|
+
typeof plugin === "string" ||
|
|
34
|
+
!Array.isArray(plugin.includes) ||
|
|
35
|
+
!plugin.includes.length
|
|
36
|
+
) {
|
|
37
|
+
throw new Error("React 19 scope requires explicit package-root includes");
|
|
38
|
+
}
|
|
39
|
+
return plugin.includes;
|
|
40
|
+
});
|
|
41
|
+
for (const pattern of patterns.filter((value) => !value.startsWith("!"))) {
|
|
42
|
+
if (
|
|
43
|
+
typeof pattern !== "string" ||
|
|
44
|
+
!/^\*\*\/(?:[a-zA-Z0-9_-]+\/)+[a-zA-Z0-9_-]+\/\*\*$/.test(pattern)
|
|
45
|
+
) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`React 19 scope must use literal package-root patterns: ${pattern}`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const diagnosticPatterns = (config.overrides ?? []).flatMap((override) => {
|
|
52
|
+
const rule = override.linter?.rules?.suspicious?.noReactForwardRef;
|
|
53
|
+
const level = typeof rule === "string" ? rule : rule?.level;
|
|
54
|
+
if (level && level !== "off" && level !== "warn") {
|
|
55
|
+
throw new Error(
|
|
56
|
+
"React 19 noReactForwardRef scope must use warn severity",
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return level === "warn" ? (override.includes ?? []) : [];
|
|
60
|
+
});
|
|
61
|
+
const normalize = (values) => JSON.stringify([...new Set(values)].sort());
|
|
62
|
+
if (normalize(patterns) !== normalize(diagnosticPatterns)) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
"React 19 forwardRef diagnostic scope must exactly match useContext plugin scope",
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
return [
|
|
68
|
+
...new Set(
|
|
69
|
+
patterns
|
|
70
|
+
.filter((pattern) => !pattern.startsWith("!"))
|
|
71
|
+
.map((pattern) => pattern.slice(3, -3)),
|
|
72
|
+
),
|
|
73
|
+
];
|
|
74
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
function reactImportBinding(identifier) {
|
|
2
|
+
if (!identifier.isIdentifier()) {
|
|
3
|
+
return undefined;
|
|
4
|
+
}
|
|
5
|
+
const binding = identifier.scope.getBinding(identifier.node.name)?.path;
|
|
6
|
+
return binding?.parentPath.isImportDeclaration() &&
|
|
7
|
+
binding.parent.source.value === "react"
|
|
8
|
+
? binding
|
|
9
|
+
: undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Resolve a call's API name only when its callee is bound to a React import. */
|
|
13
|
+
export function reactCallName(callee) {
|
|
14
|
+
if (callee.isIdentifier()) {
|
|
15
|
+
const binding = reactImportBinding(callee);
|
|
16
|
+
return binding?.isImportSpecifier()
|
|
17
|
+
? (binding.node.imported.name ?? binding.node.imported.value)
|
|
18
|
+
: undefined;
|
|
19
|
+
}
|
|
20
|
+
if (!callee.isMemberExpression() && !callee.isOptionalMemberExpression()) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const binding = reactImportBinding(callee.get("object"));
|
|
24
|
+
const importsDefault =
|
|
25
|
+
binding?.isImportSpecifier() &&
|
|
26
|
+
(binding.node.imported.name ?? binding.node.imported.value) === "default";
|
|
27
|
+
if (
|
|
28
|
+
!binding?.isImportDefaultSpecifier() &&
|
|
29
|
+
!binding?.isImportNamespaceSpecifier() &&
|
|
30
|
+
!importsDefault
|
|
31
|
+
) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
if (!callee.node.computed) {
|
|
35
|
+
return callee.node.property.name;
|
|
36
|
+
}
|
|
37
|
+
const property = callee.get("property");
|
|
38
|
+
if (property.isTemplateLiteral() && property.node.expressions.length === 0) {
|
|
39
|
+
return property.node.quasis[0].value.cooked;
|
|
40
|
+
}
|
|
41
|
+
return property.node.value;
|
|
42
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
/** Snapshot files and every changed destination without parsing human Git output. */
|
|
4
|
+
export function repositoryFiles({ root, baseRef }) {
|
|
5
|
+
const git = (args) =>
|
|
6
|
+
execFileSync("git", args, {
|
|
7
|
+
cwd: root,
|
|
8
|
+
encoding: "utf8",
|
|
9
|
+
maxBuffer: 32 * 1024 * 1024,
|
|
10
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
11
|
+
});
|
|
12
|
+
const list = (args) => git(args).split("\0").filter(Boolean);
|
|
13
|
+
let base;
|
|
14
|
+
try {
|
|
15
|
+
base = baseRef
|
|
16
|
+
? git([
|
|
17
|
+
"rev-parse",
|
|
18
|
+
"--verify",
|
|
19
|
+
"--end-of-options",
|
|
20
|
+
`${baseRef}^{commit}`,
|
|
21
|
+
]).trim()
|
|
22
|
+
: git(["merge-base", "origin/main", "HEAD"]).trim();
|
|
23
|
+
} catch (error) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`Repository comparison history unavailable for ${baseRef ?? "origin/main"}; fetch the comparison commit and retry`,
|
|
26
|
+
{ cause: error },
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
const untracked = list(["ls-files", "--others", "--exclude-standard", "-z"]);
|
|
30
|
+
const diff = [
|
|
31
|
+
"diff",
|
|
32
|
+
"--name-only",
|
|
33
|
+
"--no-renames",
|
|
34
|
+
"--diff-filter=ACMRT",
|
|
35
|
+
"-z",
|
|
36
|
+
];
|
|
37
|
+
return {
|
|
38
|
+
files: [
|
|
39
|
+
...new Set([...list(["ls-files", "--cached", "-z"]), ...untracked]),
|
|
40
|
+
].sort(),
|
|
41
|
+
touched: new Set([
|
|
42
|
+
...list([...diff, base, "HEAD", "--"]),
|
|
43
|
+
...list([...diff, "--cached", "--"]),
|
|
44
|
+
...list([...diff, "--"]),
|
|
45
|
+
...untracked,
|
|
46
|
+
]),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { biomeExitCode } from "./biome-exit-code.mjs";
|
|
8
|
+
import { readBiomeReport } from "./biome-report.mjs";
|
|
9
|
+
import { readCompilerScope } from "./compiler-scope.mjs";
|
|
10
|
+
import { readReact19Scope } from "./react-19-scope.mjs";
|
|
11
|
+
|
|
12
|
+
let reportDirectory;
|
|
13
|
+
try {
|
|
14
|
+
const root = process.cwd();
|
|
15
|
+
const args = process.argv.slice(2);
|
|
16
|
+
const informational = args.some((arg) =>
|
|
17
|
+
["--help", "-h", "--version", "-V"].includes(arg),
|
|
18
|
+
);
|
|
19
|
+
const scopes = informational ? [] : readCompilerScope({ root });
|
|
20
|
+
const react19Scopes = informational ? [] : readReact19Scope({ root });
|
|
21
|
+
if (
|
|
22
|
+
!informational &&
|
|
23
|
+
args.some((arg) =>
|
|
24
|
+
/^--(?:reporter-file|max-diagnostics)(?:=|\s*$)/.test(arg),
|
|
25
|
+
)
|
|
26
|
+
) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
"The wrapper owns --reporter-file and --max-diagnostics to require complete JSON diagnostics",
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
const warningFlags = new Set(["--error-on-warnings", "--warnings-as-errors"]);
|
|
32
|
+
const warningsAsErrors = args.some((arg) => warningFlags.has(arg));
|
|
33
|
+
const require = createRequire(path.join(root, "package.json"));
|
|
34
|
+
if (!informational) {
|
|
35
|
+
reportDirectory = mkdtempSync(path.join(tmpdir(), "vwala-biome-"));
|
|
36
|
+
}
|
|
37
|
+
const reportFile =
|
|
38
|
+
reportDirectory && path.join(reportDirectory, "diagnostics.json");
|
|
39
|
+
const result = spawnSync(
|
|
40
|
+
process.execPath,
|
|
41
|
+
[
|
|
42
|
+
require.resolve("@biomejs/biome/bin/biome"),
|
|
43
|
+
...args.filter((arg) => !warningFlags.has(arg)),
|
|
44
|
+
...(informational
|
|
45
|
+
? []
|
|
46
|
+
: [
|
|
47
|
+
...(args.some((arg) => /^--reporter(?:=|$)/.test(arg))
|
|
48
|
+
? []
|
|
49
|
+
: ["--reporter=default"]),
|
|
50
|
+
"--reporter=json",
|
|
51
|
+
`--reporter-file=${reportFile}`,
|
|
52
|
+
"--max-diagnostics=none",
|
|
53
|
+
]),
|
|
54
|
+
],
|
|
55
|
+
{ cwd: root, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 },
|
|
56
|
+
);
|
|
57
|
+
process.stdout.write(result.stdout ?? "");
|
|
58
|
+
process.stderr.write(result.stderr ?? "");
|
|
59
|
+
if (result.error) {
|
|
60
|
+
throw result.error;
|
|
61
|
+
}
|
|
62
|
+
if (result.signal) {
|
|
63
|
+
throw new Error(`Biome terminated by ${result.signal}`);
|
|
64
|
+
}
|
|
65
|
+
if (informational) {
|
|
66
|
+
process.exitCode = result.status ?? 1;
|
|
67
|
+
} else {
|
|
68
|
+
const report = readBiomeReport(readFileSync(reportFile, "utf8"));
|
|
69
|
+
process.exitCode = biomeExitCode({
|
|
70
|
+
report,
|
|
71
|
+
status: result.status,
|
|
72
|
+
warningsAsErrors,
|
|
73
|
+
root,
|
|
74
|
+
scopes,
|
|
75
|
+
react19Scopes,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error(`vwala-biome: ${error.message}`);
|
|
80
|
+
process.exitCode = 1;
|
|
81
|
+
} finally {
|
|
82
|
+
if (reportDirectory) {
|
|
83
|
+
rmSync(reportDirectory, { recursive: true, force: true });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const excludedDirectories = [
|
|
2
|
+
"node_modules",
|
|
3
|
+
".git",
|
|
4
|
+
"dist",
|
|
5
|
+
"build",
|
|
6
|
+
".next",
|
|
7
|
+
".expo",
|
|
8
|
+
"coverage",
|
|
9
|
+
"generated",
|
|
10
|
+
"__generated__",
|
|
11
|
+
"__tests__",
|
|
12
|
+
"test-support",
|
|
13
|
+
"fixtures",
|
|
14
|
+
"__fixtures__",
|
|
15
|
+
"vendor",
|
|
16
|
+
"vendored",
|
|
17
|
+
];
|
|
18
|
+
export const memoizationExclusions = [
|
|
19
|
+
...excludedDirectories.map((directory) => `!**/${directory}/**`),
|
|
20
|
+
"!**/*.test.*",
|
|
21
|
+
"!**/*.spec.*",
|
|
22
|
+
"!**/*.d.ts",
|
|
23
|
+
"!**/*.d.mts",
|
|
24
|
+
"!**/*.d.cts",
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
/** Production React-capable source within explicitly adopted package roots. */
|
|
28
|
+
export function isScopedSource({ filename, scopes }) {
|
|
29
|
+
return (
|
|
30
|
+
scopes.some((scope) => filename.startsWith(`${scope}/`)) &&
|
|
31
|
+
/\.[cm]?[jt]sx?$/.test(filename) &&
|
|
32
|
+
!/\.(?:test|spec)\.[^/]+$|\.d\.[cm]?ts$/.test(filename) &&
|
|
33
|
+
!filename.split("/").some((part) => excludedDirectories.includes(part))
|
|
34
|
+
);
|
|
35
|
+
}
|