The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 18:15 UTC
ci: unused dependency patches fail in check:changed, not after push (#23988)
Theo Browne committed
Oct 23, 2026 at 04:29 UTC
b2377db9432591a4b844ebff8237ae958bf6a828
1 file changed
+78
-2
scripts/check-changed.ts
+78
-2
@@ -2,7 +2,8 @@
2
// Runs CI's fast checks for this branch's changes: format and lint of the
3
// changed files, knip, generated GraphQL operations, typecheck of the affected
4
// packages and their dependents, and the test files beside the changed files.
5
-// CI still runs the full test suites and the jobs listed in the summary.
5
+// A dependency change also gets the unused-patch install check below. CI still
6
+// runs the full test suites and the jobs listed in the summary.
7
//
8
// vp run check:changed compare against the merge base with origin/main
9
// vp run check:changed <ref> compare against the merge base with <ref>
@@ -11,6 +12,7 @@
12
// .github/scripts/ci-changes.cjs, the same mapping CI uses to gate its jobs.
13
import * as NodeChildProcess from "node:child_process";
14
import * as NodeFS from "node:fs";
15
+import * as NodeOS from "node:os";
16
import * as NodePath from "node:path";
17
import { decide, readWorkspace } from "../.github/scripts/ci-changes.cjs";
18
@@ -71,6 +73,72 @@ const runKnip = files.some(
73
(file) => CODE.test(file) || NodePath.basename(file) === "package.json" || file === "knip.jsonc",
74
);
75
76
+// A version bump can strand a patch in pnpm-workspace.yaml: no resolved
77
+// version uses it and pnpm rejects the install with ERR_PNPM_UNUSED_PATCH.
78
+// CI catches that before merge through Release Smoke, because ci-changes.cjs
79
+// runs everything for any package.json and for root paths it does not map to
80
+// a package (pnpm-workspace.yaml, pnpm-lock.yaml, patches/). The local run
81
+// had no such check, so a stranded patch passed here and failed after push.
82
+const runPatchCheck = files.some(
83
+ (file) =>
84
+ file === "pnpm-workspace.yaml" ||
85
+ file === "pnpm-lock.yaml" ||
86
+ file === ".pnpmfile.cjs" ||
87
+ file.startsWith("patches/") ||
88
+ file.startsWith("apps/mobile/deps/") ||
89
+ NodePath.basename(file) === "package.json",
90
+);
91
+
92
+// Mirror Release Smoke's temp-copy install: copy the workspace manifests to
93
+// a temp dir, omit the lockfile, and install with --lockfile-only, so the
94
+// working tree and its lockfile stay untouched (the mobile modules are
95
+// mobile file: dependencies, not workspace packages). Local pnpm may resolve
96
+// from cached registry metadata, so this catches patches stranded by your
97
+// own change, not registry drift.
98
+const checkPatches = (): boolean => {
99
+ const temp = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-patch-check-"));
100
+ try {
101
+ const copy = (relative: string) => {
102
+ const dest = NodePath.join(temp, relative);
103
+ NodeFS.mkdirSync(NodePath.dirname(dest), { recursive: true });
104
+ NodeFS.cpSync(NodePath.join(root, relative), dest, { recursive: true });
105
+ };
106
+ copy("package.json");
107
+ copy("pnpm-workspace.yaml");
108
+ for (const pkg of packages) copy(`${pkg.dir}/package.json`);
109
+ const modulesDir = NodePath.join(root, "apps/mobile/modules");
110
+ if (NodeFS.existsSync(modulesDir)) {
111
+ for (const entry of NodeFS.readdirSync(modulesDir)) {
112
+ const manifest = `apps/mobile/modules/${entry}/package.json`;
113
+ if (NodeFS.existsSync(NodePath.join(root, manifest))) copy(manifest);
114
+ }
115
+ }
116
+ for (const extra of ["apps/mobile/deps", "patches", ".pnpmfile.cjs"]) {
117
+ if (NodeFS.existsSync(NodePath.join(root, extra))) copy(extra);
118
+ }
119
+ const { status, stdout, stderr, error } = NodeChildProcess.spawnSync(
120
+ "vp",
121
+ ["install", "--lockfile-only", "--ignore-scripts"],
122
+ { cwd: temp, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 },
123
+ );
124
+ if (status === 0) return true;
125
+ if (stdout) console.log(stdout);
126
+ if (stderr) console.error(stderr);
127
+ if (error) console.error(error.message);
128
+ if (`${stdout ?? ""}${stderr ?? ""}`.includes("ERR_PNPM_UNUSED_PATCH")) {
129
+ console.error(
130
+ "Unused dependency patches: remove each patch named above from " +
131
+ "patchedDependencies in pnpm-workspace.yaml and from patches/, " +
132
+ "update it to the version the install resolves, " +
133
+ "or pin the dependency that pulls it in to the patched version.",
134
+ );
135
+ }
136
+ return false;
137
+ } finally {
138
+ NodeFS.rmSync(temp, { recursive: true, force: true });
139
+ }
140
+};
141
+
142
// CI's Lint job checks that generated GraphQL operations match their sources.
143
const graphql = ["apps/server", "packages/source-control-github"].filter((dir) =>
144
files.some((file) => file.startsWith(`${dir}/`)),
@@ -78,6 +146,8 @@ const graphql = ["apps/server", "packages/source-control-github"].filter((dir) =
146
147
const filters = (names: ReadonlyArray<string>) => names.flatMap((name) => ["--filter", name]);
148
const steps = [
149
+ // Runs first; it takes about a second.
150
+ runPatchCheck && { name: "unused patches", run: checkPatches },
151
present.length > 0 && {
152
name: "format",
153
args: ["fmt", "--check", "--no-error-on-unmatched-pattern", ...present],
@@ -103,7 +173,12 @@ console.log(`check:changed: ${files.length} files since ${base.slice(0, 12)}`);
173
const results = steps.map((step) => {
174
console.log(`\n> vp ${step.name}`);
175
const started = performance.now();
106
- const { status } = NodeChildProcess.spawnSync("vp", step.args, { cwd: root, stdio: "inherit" });
176
+ const status =
177
+ "args" in step
178
+ ? NodeChildProcess.spawnSync("vp", step.args, { cwd: root, stdio: "inherit" }).status
179
+ : step.run()
180
+ ? 0
181
+ : 1;
182
const seconds = ((performance.now() - started) / 1000).toFixed(1);
183
return { name: step.name, ok: status === 0, seconds };
184
});
@@ -120,5 +195,6 @@ const ciOnly = Object.entries({
195
"release smoke": outputs.release_smoke,
196
}).flatMap(([job, runs]) => (runs ? [job] : []));
197
if (ciOnly.length > 0) console.log(` CI also runs: ${ciOnly.join(", ")}`);
198
+if (!runPatchCheck) console.log(" unused patch check skipped: no dependency files changed");
199
if (!runKnip) console.log(" knip skipped: no code or manifest changed");
200
if (results.some((result) => !result.ok)) process.exit(1);