fix(mobile): prevent crash when generated/openapi has unexpected files (#32599)

(cherry picked from commit 4f38929bdaaa88d48429ac642abf9ec292e3ca82)
This commit is contained in:
Adam Gastineau
2026-10-22 05:21:00 +03:00
committed by Codex
parent 6aaebd167d
commit 564b720bce
2 changed files with 26 additions and 0 deletions
+6
View File
@@ -139,6 +139,7 @@ depends = ["//:open-api-dart"]
run = [ run = [
# This receives passed `--enforce-lockfile` args # This receives passed `--enforce-lockfile` args
"flutter pub get", "flutter pub get",
{ task = "install:build-runner-patch" },
{ task = "install:ios" }, { task = "install:ios" },
] ]
@@ -198,6 +199,11 @@ fi
cd ios && pod install cd ios && pod install
''' '''
[tasks."install:build-runner-patch"]
description = "Patch build_runner to prevent crashes when sources are deleted"
hide = true
run = "node ./scripts/build_runner_patch.mjs"
[tasks."analyze:dart"] [tasks."analyze:dart"]
description = "Run Dart analysis" description = "Run Dart analysis"
hide = true hide = true
+20
View File
@@ -0,0 +1,20 @@
// Prevents build_runner crashing when a source file is deleted from a path dependency, which commonly occurs to `generated/openapi` on branch switch
//
// Fixed upstream in 2.15.3 (https://github.com/dart-lang/build/pull/5022), but we can't take that dependency due to Dart analyzer being locked
import { readFileSync, writeFileSync } from 'node:fs';
const packageConfig = new URL('../.dart_tool/package_config.json', import.meta.url);
const config = JSON.parse(readFileSync(packageConfig, 'utf8'));
const buildRunner = new URL(config.packages.find(({ name }) => name === 'build_runner').rootUri);
const file = new URL(`${buildRunner}/lib/src/build_plan/build_plan.dart`);
const buggy = 'for (final id in deletedOutputs) {';
const fixed = 'for (final id in deletedOutputs.difference(buildInputs.deletedSources.build().asSet())) {';
const source = readFileSync(file, 'utf8');
if (source.includes(buggy)) {
writeFileSync(file, source.replace(buggy, fixed));
console.log('build_runner patch: stopped deleting removed sources from path dependencies');
}