From 02a65059b94a63cdadbadbae9fdeb7e85f71e5bd Mon Sep 17 00:00:00 2001 From: Fredrik Burmester Date: Thu, 22 Jan 2026 08:37:14 +0100 Subject: [PATCH] fix(tv): set tv env --- app.json | 1 + plugins/withTVXcodeEnv.js | 47 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 plugins/withTVXcodeEnv.js diff --git a/app.json b/app.json index 0c7690ee..668c6163 100644 --- a/app.json +++ b/app.json @@ -139,6 +139,7 @@ ["./plugins/withTrustLocalCerts.js"], ["./plugins/withGradleProperties.js"], ["./plugins/withTVOSAppIcon.js"], + ["./plugins/withTVXcodeEnv.js"], [ "./plugins/withGitPod.js", { diff --git a/plugins/withTVXcodeEnv.js b/plugins/withTVXcodeEnv.js new file mode 100644 index 00000000..ccdbc842 --- /dev/null +++ b/plugins/withTVXcodeEnv.js @@ -0,0 +1,47 @@ +const { withDangerousMod } = require("@expo/config-plugins"); +const fs = require("node:fs"); +const path = require("node:path"); + +/** + * Expo config plugin that adds EXPO_TV=1 to .xcode.env.local for TV builds. + * + * This ensures that when building directly from Xcode (without using `bun run ios:tv`), + * Metro bundler knows it's a TV build and properly excludes unsupported modules + * like react-native-track-player. + */ +const withTVXcodeEnv = (config) => { + // Only apply for TV builds + if (process.env.EXPO_TV !== "1") { + return config; + } + + return withDangerousMod(config, [ + "ios", + async (config) => { + const iosPath = path.join(config.modRequest.projectRoot, "ios"); + const xcodeEnvLocalPath = path.join(iosPath, ".xcode.env.local"); + + // Read existing content or start fresh + let content = ""; + if (fs.existsSync(xcodeEnvLocalPath)) { + content = fs.readFileSync(xcodeEnvLocalPath, "utf-8"); + } + + // Add EXPO_TV=1 if not already present + const expoTvExport = "export EXPO_TV=1"; + if (!content.includes(expoTvExport)) { + // Ensure we have a newline at the end before adding + if (content.length > 0 && !content.endsWith("\n")) { + content += "\n"; + } + content += `${expoTvExport}\n`; + fs.writeFileSync(xcodeEnvLocalPath, content); + console.log("[withTVXcodeEnv] Added EXPO_TV=1 to .xcode.env.local"); + } + + return config; + }, + ]); +}; + +module.exports = withTVXcodeEnv;