mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-06-11 16:30:24 +01:00
Migrate the dynamic Expo config and all 12 local config plugins from CommonJS .js to typed TypeScript: - app.config.js -> app.config.ts (typed ConfigContext/ExpoConfig, behavior-identical port) - plugins/*.js -> plugins/*.ts with `ConfigPlugin` typings from expo/config-plugins; plugin options are now type-checked (withGitPod) - app.json plugin references updated to the .ts paths - imports unified on expo/config-plugins (some plugins used the @expo/config-plugins alias) Node evaluates the config at prebuild time and cannot parse TypeScript plugin modules on its own (verified empirically: Expo transpiles app.config.ts itself but not its imports), so the documented tsx approach is used: `import "tsx/cjs"` at the top of app.config.ts plus tsx as a devDependency. Validation: resolved prebuild configs (expo config --type prebuild) are byte-identical to the old JS config for both mobile and TV (modulo plugin path extensions and the builtAt timestamp); full `bun run prebuild` and `bun run prebuild:tv` pass and all Android plugin mods are present in the generated project (media3 exclusions, gradle properties, cast activity, network security config, alert colors).
80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
// Registers the tsx require hook so the TypeScript config plugins referenced
|
|
// from app.json ("./plugins/*.ts") can be loaded by Node during config evaluation.
|
|
import "tsx/cjs";
|
|
import { execFileSync } from "node:child_process";
|
|
import type { ConfigContext, ExpoConfig } from "expo/config";
|
|
|
|
// Build metadata, injected into `extra.build` and read at runtime via
|
|
// expo-constants (see utils/version.ts). Sources in priority order:
|
|
// EAS cloud build → GitHub Actions → explicit EXPO_PUBLIC_* → local git → null.
|
|
const git = (args: string[]): string | null => {
|
|
try {
|
|
return execFileSync("git", args, { stdio: ["ignore", "pipe", "ignore"] })
|
|
.toString()
|
|
.trim();
|
|
} catch {
|
|
return null;
|
|
}
|
|
};
|
|
|
|
const buildMeta = {
|
|
commit:
|
|
(
|
|
process.env.EAS_BUILD_GIT_COMMIT_HASH ||
|
|
process.env.GITHUB_SHA ||
|
|
process.env.EXPO_PUBLIC_GIT_COMMIT ||
|
|
git(["rev-parse", "HEAD"]) ||
|
|
""
|
|
).slice(0, 7) || null,
|
|
branch:
|
|
process.env.EAS_BUILD_GIT_BRANCH ||
|
|
process.env.GITHUB_HEAD_REF ||
|
|
process.env.GITHUB_REF_NAME ||
|
|
process.env.EXPO_PUBLIC_GIT_BRANCH ||
|
|
git(["rev-parse", "--abbrev-ref", "HEAD"]) ||
|
|
null,
|
|
profile:
|
|
process.env.EAS_BUILD_PROFILE ||
|
|
process.env.EXPO_PUBLIC_BUILD_PROFILE ||
|
|
null,
|
|
// GitHub Actions run number (#2098) — lets anyone map a sideloaded CI build back
|
|
// to its Actions run (artifacts + logs) without Expo access. Null outside CI.
|
|
runNumber:
|
|
process.env.GITHUB_RUN_NUMBER ||
|
|
process.env.EXPO_PUBLIC_GIT_RUN_NUMBER ||
|
|
null,
|
|
builtAt: new Date().toISOString(),
|
|
};
|
|
|
|
export default ({ config }: ConfigContext): ExpoConfig => {
|
|
if (process.env.EXPO_TV !== "1") {
|
|
config.plugins?.push("expo-background-task");
|
|
|
|
config.plugins?.push([
|
|
"react-native-google-cast",
|
|
{ useDefaultExpandedMediaControls: true },
|
|
]);
|
|
|
|
config.plugins?.push([
|
|
"expo-camera",
|
|
{
|
|
cameraPermission:
|
|
"Allow Streamyfin to access the camera to scan QR codes for TV login.",
|
|
},
|
|
]);
|
|
}
|
|
|
|
// Only override googleServicesFile if env var is set
|
|
const androidConfig: { googleServicesFile?: string } = {};
|
|
if (process.env.GOOGLE_SERVICES_JSON) {
|
|
androidConfig.googleServicesFile = process.env.GOOGLE_SERVICES_JSON;
|
|
}
|
|
|
|
config.extra = { ...config.extra, build: buildMeta };
|
|
|
|
return {
|
|
...(Object.keys(androidConfig).length > 0 && { android: androidConfig }),
|
|
...config,
|
|
} as ExpoConfig;
|
|
};
|