Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

app.config.ts

506 lines18.5 KB

1import type { ExpoConfig } from "expo/config";
2​
3import { BRAND_ASSET_PATHS } from "../../scripts/lib/brand-assets.ts";
4import { loadRepoEnv } from "../../scripts/lib/public-config.ts";
5​
6type AppVariant = "development" | "preview" | "production";
7​
8const repoEnv = loadRepoEnv();
9Object.assign(process.env, repoEnv);
10// Expo's TypeScript setup otherwise installs `typescript` on every start; we typecheck with tsrs.
11process.env.EXPO_NO_TYPESCRIPT_SETUP = "1";
12​
13const APP_VARIANT = resolveAppVariant(repoEnv.APP_VARIANT);
14const isIosPersonalTeamBuild = repoEnv.T3CODE_IOS_PERSONAL_TEAM === "1";
15const runtimeVersionPolicy =
16 process.env.MOBILE_VERSION_POLICY ??
17 (APP_VARIANT === "development" ? "appVersion" : "fingerprint");
18​
19const personalTeamBundleIdentifier = repoEnv.T3CODE_IOS_PERSONAL_TEAM_BUNDLE_ID?.trim();
20const IOS_BUNDLE_IDENTIFIER_PATTERN = /^[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)+$/;
21​
22// Compiled into the native project. Without a relay, Observe's native side could dispatch to
23// Expo's own ingest before observe.ts turns it off; `.invalid` never resolves (RFC 6761).
24const observeEndpointUrl = repoEnv.T3CODE_RELAY_URL?.trim()
25 ? new URL("/v1/mobile/observe", repoEnv.T3CODE_RELAY_URL.trim()).toString()
26 : "https://observe.invalid";
27​
28const fromRepoRoot = (relativePath: string) => `../../${relativePath}`;
29const androidAdaptiveForeground = "./assets/android-icon-foreground.png";
30​
31if (
32 isIosPersonalTeamBuild &&
33 (!personalTeamBundleIdentifier ||
34 !IOS_BUNDLE_IDENTIFIER_PATTERN.test(personalTeamBundleIdentifier))
35) {
36 throw new Error(
37 "T3CODE_IOS_PERSONAL_TEAM_BUNDLE_ID must be a reverse-DNS identifier such as com.example.t3code when T3CODE_IOS_PERSONAL_TEAM=1.",
38 );
40​
41const DEVELOPMENT_ASSETS = {
42 appIcon: fromRepoRoot(BRAND_ASSET_PATHS.developmentIosIconPng),
43 iosIcon: fromRepoRoot(BRAND_ASSET_PATHS.developmentIconComposerProject),
44 splashIcon: fromRepoRoot(BRAND_ASSET_PATHS.developmentIosIconPng),
45 androidAdaptiveForeground,
46 androidAdaptiveBackgroundColor: "#347FF8",
47 androidAdaptiveBackgroundImage: "./assets/android-icon-background-dev.png",
48 androidSplashIcon: "./assets/android-splash-icon-dev.png",
49 androidMonochromeIcon: "./assets/android-icon-mark.png",
50 androidNotificationIcon: "./assets/android-notification-icon.png",
51 androidNotificationColor: "#00639B",
52} as const;
53​
54const PREVIEW_ASSETS = {
55 appIcon: fromRepoRoot(BRAND_ASSET_PATHS.nightlyIosIconPng),
56 iosIcon: fromRepoRoot(BRAND_ASSET_PATHS.nightlyIconComposerProject),
57 splashIcon: fromRepoRoot(BRAND_ASSET_PATHS.nightlyIosIconPng),
58 androidAdaptiveForeground,
59 androidAdaptiveBackgroundColor: "#111533",
60 androidAdaptiveBackgroundImage: "./assets/android-icon-background-nightly.png",
61 androidSplashIcon: "./assets/android-splash-icon-nightly.png",
62 androidMonochromeIcon: "./assets/android-icon-mark.png",
63 androidNotificationIcon: "./assets/android-notification-icon.png",
64 androidNotificationColor: "#7565C7",
65} as const;
66​
67const RELEASE_ASSETS = {
68 appIcon: fromRepoRoot(BRAND_ASSET_PATHS.productionIosIconPng),
69 iosIcon: fromRepoRoot(BRAND_ASSET_PATHS.productionIconComposerProject),
70 splashIcon: fromRepoRoot(BRAND_ASSET_PATHS.productionIosIconPng),
71 androidAdaptiveForeground,
72 androidAdaptiveBackgroundColor: "#000000",
73 androidAdaptiveBackgroundImage: undefined,
74 androidSplashIcon: "./assets/android-splash-icon-prod.png",
75 androidMonochromeIcon: "./assets/android-icon-mark.png",
76 androidNotificationIcon: "./assets/android-notification-icon.png",
77 androidNotificationColor: "#FFFFFF",
78} as const;
79​
80const VARIANT_CONFIG = {
81 development: {
82 appName: "T3 Code Dev",
83 scheme: "t3code-dev",
84 iosBundleIdentifier: "com.t3tools.t3code.dev",
85 androidPackage: "com.t3tools.t3code.dev",
86 relyingParty: "clerk.t3.codes",
87 assets: DEVELOPMENT_ASSETS,
88 },
89 preview: {
90 appName: "T3 Code Preview",
91 scheme: "t3code-preview",
92 iosBundleIdentifier: "com.t3tools.t3code.preview",
93 androidPackage: "com.t3tools.t3code.preview",
94 relyingParty: "clerk.t3.codes",
95 assets: PREVIEW_ASSETS,
96 },
97 production: {
98 appName: "T3 Code",
99 scheme: "t3code",
100 iosBundleIdentifier: "com.t3tools.t3code",
101 androidPackage: "com.t3tools.t3code",
102 relyingParty: "clerk.t3.codes",
103 assets: RELEASE_ASSETS,
104 },
105} as const;
106​
107function resolveAppVariant(value: string | undefined): AppVariant {
108 switch (value) {
109 case "development":
110 case "preview":
111 case "production":
112 return value;
113 case undefined:
114 return "production";
115 default:
116 throw new Error("APP_VARIANT must be development, preview, or production.");
117 }
119​
120const variant = VARIANT_CONFIG[APP_VARIANT];
121// Copied thread links open the app. app.t3.codes/.well-known lists every variant's identifiers.
122const HOSTED_APP_HOST = "app.t3.codes";
123const iosBundleIdentifier = isIosPersonalTeamBuild
124 ? personalTeamBundleIdentifier!
125 : variant.iosBundleIdentifier;
126​
127const dmSansFonts = {
128 regular: "@expo-google-fonts/dm-sans/400Regular/DMSans_400Regular.ttf",
129 medium: "@expo-google-fonts/dm-sans/500Medium/DMSans_500Medium.ttf",
130 bold: "@expo-google-fonts/dm-sans/700Bold/DMSans_700Bold.ttf",
131} as const;
132​
133const widgetsPlugin: NonNullable<ExpoConfig["plugins"]>[number] = [
134 "expo-widgets",
135 {
136 bundleIdentifier: `${iosBundleIdentifier}.widgets`,
137 groupIdentifier: `group.${iosBundleIdentifier}`,
138 enablePushNotifications: true,
139 // Frequent updates need the iOS entitlement to avoid early throttling.
140 frequentUpdates: true,
141 enableAndroid: true,
142 widgets: [
143 {
144 name: "SubscriptionUsage",
145 displayName: "Subscription usage",
146 description: "Subscription quotas from your connected T3 Code environments.",
147 ios: {
148 configuration: {
149 title: "Subscription usage",
150 description:
151 "Both shows Session and Weekly when available. The Lock Screen shows the tightest selected limit.",
152 parameters: {
153 codexPeriod: {
154 title: "Codex limits",
155 type: "enum",
156 default: "auto",
157 values: [
158 { name: "Both", value: "auto" },
159 { name: "Session", value: "session" },
160 { name: "Weekly", value: "weekly" },
161 ],
162 },
163 claudePeriod: {
164 title: "Claude limits",
165 type: "enum",
166 default: "auto",
167 values: [
168 { name: "Both", value: "auto" },
169 { name: "Session", value: "session" },
170 { name: "Weekly", value: "weekly" },
171 ],
172 },
173 },
174 },
175 supportedFamilies: [
176 "systemSmall",
177 "systemMedium",
178 "systemLarge",
179 "systemExtraLarge",
180 "accessoryRectangular",
181 ],
182 },
183 android: {
184 minWidth: 250,
185 minHeight: 180,
186 minResizeWidth: 180,
187 minResizeHeight: 130,
188 targetCellWidth: 4,
189 targetCellHeight: 3,
190 resizeMode: "both",
191 // The embedded layout renders before first launch; publishing replaces it with stored props.
192 initialLayout: "./src/widgets/SubscriptionUsage.android.tsx",
193 },
194 },
195 {
196 name: "AgentActivity",
197 displayName: "Agent Activity",
198 description: "Shows the current state of active T3 Code agents.",
199 android: null,
200 ios: {
201 supportedFamilies: ["systemSmall", "systemMedium", "accessoryRectangular"],
202 // Embeds the layout so the gallery preview and a new widget render
203 // before the app has run once; the app replaces it on publish.
204 initialLayout: "./src/widgets/AgentActivityWidget.tsx",
205 },
206 },
207 ],
208 },
209];
210​
211const sharingPlugin: NonNullable<ExpoConfig["plugins"]>[number] = [
212 "expo-sharing",
213 {
214 ios: {
215 // Personal Teams cannot sign App Groups or extension targets; keep local builds usable.
216 enabled: !isIosPersonalTeamBuild,
217 extensionBundleIdentifier: `${iosBundleIdentifier}.sharing`,
218 appGroupId: `group.${iosBundleIdentifier}`,
219 activationRule: {
220 supportsText: true,
221 supportsWebUrlWithMaxCount: 1,
222 supportsImageWithMaxCount: 8,
223 supportsMovieWithMaxCount: 8,
224 supportsFileWithMaxCount: 8,
225 },
226 },
227 android: {
228 enabled: true,
229 singleShareMimeTypes: ["*/*"],
230 multipleShareMimeTypes: ["*/*"],
231 },
232 },
233];
234​
235// Match iOS PostScript names on Android so RN and the native composer share fonts before runtime loading.
236​
237const config: ExpoConfig = {
238 name: variant.appName,
239 slug: "t3-code",
240 platforms: ["ios", "android"],
241 scheme: variant.scheme,
242 version: repoEnv.T3CODE_MOBILE_VERSION ?? "2.4.0",
243 runtimeVersion: {
244 // Skip costly fingerprinting on dev launches; preview and production OTAs require matching native projects.
245 policy: runtimeVersionPolicy,
246 },
247 orientation: "portrait",
248 icon: variant.assets.appIcon,
249 userInterfaceStyle: "automatic",
250 updates: {
251 enabled: repoEnv.T3CODE_MOBILE_UPDATES_ENABLED !== "0",
252 url: "https://u.expo.dev/d763fcb8-d37c-41ea-a773-b54a0ab4a454",
253 checkAutomatically: "ON_LOAD",
254 fallbackToCacheTimeout: 0,
255 },
256 ios: {
257 icon: variant.assets.iosIcon,
258 supportsTablet: true,
259 requireFullScreen: process.env.T3_SHOWCASE_CAPTURE_BUILD === "1",
260 bundleIdentifier: iosBundleIdentifier,
261 // Avoid Personal Team fallback: it cannot sign App Groups, Apple sign-in or push entitlements.
262 appleTeamId: "ARK85ZXQ4Z",
263 associatedDomains: [
264 `applinks:${variant.relyingParty}`,
265 `webcredentials:${variant.relyingParty}`,
266 `applinks:${HOSTED_APP_HOST}`,
267 ],
268 entitlements: {
269 "keychain-access-groups": [`$(AppIdentifierPrefix)${variant.iosBundleIdentifier}`],
270 },
271 infoPlist: {
272 UISupportedInterfaceOrientations: [
273 "UIInterfaceOrientationPortrait",
274 "UIInterfaceOrientationLandscapeLeft",
275 "UIInterfaceOrientationLandscapeRight",
276 ],
277 NSAppTransportSecurity: {
278 NSAllowsArbitraryLoads: true,
279 },
280 NSLocalNetworkUsageDescription:
281 "Allow T3 Code to connect to T3 Code servers on your local network or tailnet.",
282 // Built with the iOS 27 SDK, only view controllers can hide or style the status bar.
283 UIViewControllerBasedStatusBarAppearance: true,
284 NSPhotoLibraryAddUsageDescription: "Allow T3 Code to save images to your photo library.",
285 // System picture in picture needs background audio to start and survive outside the app.
286 UIBackgroundModes: ["audio"],
287 ITSAppUsesNonExemptEncryption: false,
288 // Capture builds disable multitasking because iPadOS otherwise ignores orientation requests.
289 ...(process.env.T3_SHOWCASE_CAPTURE_BUILD === "1"
290 ? {
291 "UISupportedInterfaceOrientations~ipad": [
292 "UIInterfaceOrientationPortrait",
293 "UIInterfaceOrientationPortraitUpsideDown",
294 "UIInterfaceOrientationLandscapeLeft",
295 "UIInterfaceOrientationLandscapeRight",
296 ],
297 }
298 : {}),
299 },
300 },
301 android: {
302 icon: variant.assets.appIcon,
303 package: variant.androidPackage,
304 ...(repoEnv.T3CODE_ANDROID_GOOGLE_SERVICES_FILE
305 ? { googleServicesFile: repoEnv.T3CODE_ANDROID_GOOGLE_SERVICES_FILE }
306 : {}),
307 adaptiveIcon: {
308 backgroundColor: variant.assets.androidAdaptiveBackgroundColor,
309 ...(variant.assets.androidAdaptiveBackgroundImage
310 ? { backgroundImage: variant.assets.androidAdaptiveBackgroundImage }
311 : {}),
312 foregroundImage: variant.assets.androidAdaptiveForeground,
313 monochromeImage: variant.assets.androidMonochromeIcon,
314 },
315 // JS back dispatch needs RN's Android 16 shim and withAndroidPredictiveBackCompat on Android 13-15.
316 predictiveBackGestureEnabled: true,
317 // expo-sensors declares this for its pedometer, which the app does not use.
318 blockedPermissions: ["android.permission.ACTIVITY_RECOGNITION"],
319 intentFilters: [
320 {
321 action: "VIEW",
322 autoVerify: true,
323 data: [{ scheme: "https", host: HOSTED_APP_HOST, pathPrefix: "/threads/" }],
324 category: ["BROWSABLE", "DEFAULT"],
325 },
326 ],
327 },
328 web: {
329 favicon: variant.assets.appIcon,
330 },
331 plugins: [
332 "expo-asset",
333 [
334 "expo-font",
335 {
336 ios: {
337 fonts: [dmSansFonts.regular, dmSansFonts.medium, dmSansFonts.bold],
338 },
339 android: {
340 fonts: [
341 {
342 fontFamily: "DMSans-Regular",
343 fontDefinitions: [{ path: dmSansFonts.regular, weight: 400 }],
344 },
345 {
346 fontFamily: "DMSans-Medium",
347 fontDefinitions: [{ path: dmSansFonts.medium, weight: 500 }],
348 },
349 {
350 fontFamily: "DMSans-Bold",
351 // Android picks fallback glyphs (such as Vietnamese) at the requested weight, so bold text
352 // asks for 700; the 400 entry lets a relative bold step (Typeface.BOLD) land on 700 too.
353 fontDefinitions: [
354 { path: dmSansFonts.bold, weight: 400 },
355 { path: dmSansFonts.bold, weight: 700 },
356 ],
357 },
358 ],
359 },
360 },
361 ],
362 "expo-secure-store",
363 "expo-sqlite",
364 ...(isIosPersonalTeamBuild
365 ? [sharingPlugin]
366 : ["./plugins/withShareExtensionDisplayName.cjs", sharingPlugin]),
367 [
368 "expo-notifications",
369 {
370 icon: variant.assets.androidNotificationIcon,
371 color: variant.assets.androidNotificationColor,
372 mode: APP_VARIANT === "development" ? "development" : "production",
373 },
374 ],
375 // Gate Clerk here: withoutIosPersonalTeamCapabilities runs too early to strip its entitlement.
376 ["@clerk/expo", { theme: "./clerk-theme.json", appleSignIn: !isIosPersonalTeamBuild }],
377 "expo-web-browser",
378 [
379 "expo-quick-actions",
380 {
381 androidIcons: {
382 shortcut_icon: {
383 foregroundImage: variant.assets.androidAdaptiveForeground,
384 backgroundColor: variant.assets.androidAdaptiveBackgroundColor,
385 ...(variant.assets.androidAdaptiveBackgroundImage
386 ? { backgroundImage: variant.assets.androidAdaptiveBackgroundImage }
387 : {}),
388 },
389 },
390 },
391 ],
392 [
393 "expo-audio",
394 {
395 microphonePermission: "Allow T3 Code to use your microphone for voice input.",
396 recordAudioAndroid: true,
397 enableBackgroundPlayback: false,
398 enableBackgroundRecording: false,
399 },
400 ],
401 [
402 "expo-camera",
403 {
404 cameraPermission: "Allow T3 Code to access your camera so you can scan pairing QR codes.",
405 microphonePermission: false,
406 barcodeScannerEnabled: true,
407 recordAudioAndroid: false,
408 },
409 ],
410 [
411 "expo-image-picker",
412 {
413 photosPermission: false,
414 // `false` makes this plugin add RECORD_AUDIO to blockedPermissions, breaking Android dictation.
415 microphonePermission: "Allow T3 Code to use your microphone for voice input.",
416 },
417 ],
418 [
419 "expo-splash-screen",
420 {
421 image: variant.assets.splashIcon,
422 resizeMode: "contain",
423 backgroundColor: "#ffffff",
424 imageWidth: 220,
425 dark: {
426 image: variant.assets.splashIcon,
427 backgroundColor: "#0a0a0a",
428 },
429 android: {
430 // Android 12+ masks the central two thirds of the 288dp canvas; adaptive layers avoid clipped corners.
431 image: variant.assets.androidSplashIcon,
432 imageWidth: 288,
433 dark: { image: variant.assets.androidSplashIcon },
434 },
435 },
436 ],
437 [
438 "expo-build-properties",
439 {
440 android: {
441 minSdkVersion: 24,
442 // SDK 58 lacks Kotlin 2.3's runtime-inert annotation. R8 needs explicit InputMerger constructors for widgets.
443 extraProguardRules: [
444 "-dontwarn kotlin.MustUseReturnValues",
445 "-keep class * extends androidx.work.InputMerger { <init>(); }",
446 ].join("\n"),
447 },
448 ios: {
449 deploymentTarget: "18.0",
450 // AppCheckCore 11.3+ includes Swift and needs module maps for these Objective-C dependencies.
451 extraPods: [
452 { name: "GoogleUtilities", modular_headers: true },
453 { name: "RecaptchaInterop", modular_headers: true },
454 ],
455 },
456 },
457 ],
458 "./plugins/withIosCocoaPodsUuidCache.cjs",
459 // Compile out the unused pedometer to avoid an iOS motion purpose string.
460 ["expo-sensors", { motionPermission: false }],
461 // Mods run in reverse order; expo-widgets must create and wipe the target before assets are added.
462 ...(!isIosPersonalTeamBuild ? ["./plugins/withWidgetLogoAsset.cjs", widgetsPlugin] : []),
463 "./plugins/withAndroidNetworkSecurityConfig.cjs",
464 "./plugins/withAndroidGradleHeap.cjs",
465 "./plugins/withAndroidInputBackground.cjs",
466 "./plugins/withAndroidModernPopupMenu.cjs",
467 "./plugins/withAndroidModernAlertDialog.cjs",
468 "./plugins/withAndroidPredictiveBackCompat.cjs",
469 // MainActivity mods run in reverse order; extend the tablet-orientation override.
470 "./plugins/withAndroidWindowDisplayMetrics.cjs",
471 "./plugins/withAndroidTabletOrientation.cjs",
472 ...(isIosPersonalTeamBuild ? ["./plugins/withoutIosPersonalTeamCapabilities.cjs"] : []),
473 ],
474 extra: {
475 appVariant: APP_VARIANT,
476 iosPersonalTeamBuild: isIosPersonalTeamBuild,
477 relay: {
478 url: repoEnv.T3CODE_RELAY_URL ?? null,
479 },
480 clerk: {
481 publishableKey: repoEnv.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY ?? null,
482 jwtTemplate: repoEnv.EXPO_PUBLIC_CLERK_JWT_TEMPLATE ?? null,
483 },
484 // Clerk reads these exact names at prebuild. Omit unset values: manifest null becomes truthy {}.
485 EXPO_PUBLIC_CLERK_GOOGLE_WEB_CLIENT_ID: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_WEB_CLIENT_ID,
486 EXPO_PUBLIC_CLERK_GOOGLE_IOS_CLIENT_ID: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_IOS_CLIENT_ID,
487 EXPO_PUBLIC_CLERK_GOOGLE_ANDROID_CLIENT_ID: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_ANDROID_CLIENT_ID,
488 EXPO_PUBLIC_CLERK_GOOGLE_IOS_URL_SCHEME: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_IOS_URL_SCHEME,
489 observability: {
490 tracesUrl: repoEnv.EXPO_PUBLIC_OTLP_TRACES_URL ?? "https://api.axiom.co/v1/traces",
491 tracesDataset: repoEnv.EXPO_PUBLIC_OTLP_TRACES_DATASET ?? null,
492 tracesToken: repoEnv.EXPO_PUBLIC_OTLP_TRACES_TOKEN ?? null,
493 },
494 eas: {
495 projectId: "d763fcb8-d37c-41ea-a773-b54a0ab4a454",
496 observe: { endpointUrl: observeEndpointUrl },
497 },
498 },
499 owner: "pingdotgg",
500 experiments: {
501 // Metro only runs babel-plugin-react-compiler when this is set; see src/reactCompilerCoverage.test.ts.
502 reactCompiler: true,
503 },
504};
505​
506export default config;