From 564b720bcedf6cda61a5f3ba51fd0b9017ed9970 Mon Sep 17 00:00:00 2001 From: Adam Gastineau Date: Tue, 20 Oct 2026 06:18:55 -0700 Subject: [PATCH] fix(mobile): prevent crash when generated/openapi has unexpected files (#32599) (cherry picked from commit 4f38929bdaaa88d48429ac642abf9ec292e3ca82) --- mobile/mise.toml | 6 ++++++ mobile/scripts/build_runner_patch.mjs | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 mobile/scripts/build_runner_patch.mjs diff --git a/mobile/mise.toml b/mobile/mise.toml index d43e55860..7495288f2 100644 --- a/mobile/mise.toml +++ b/mobile/mise.toml @@ -139,6 +139,7 @@ depends = ["//:open-api-dart"] run = [ # This receives passed `--enforce-lockfile` args "flutter pub get", + { task = "install:build-runner-patch" }, { task = "install:ios" }, ] @@ -198,6 +199,11 @@ fi 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"] description = "Run Dart analysis" hide = true diff --git a/mobile/scripts/build_runner_patch.mjs b/mobile/scripts/build_runner_patch.mjs new file mode 100644 index 000000000..77226de2e --- /dev/null +++ b/mobile/scripts/build_runner_patch.mjs @@ -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'); +}