mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-06-12 00:40:23 +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).
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import {
|
|
AndroidConfig,
|
|
type ConfigPlugin,
|
|
type ExportedConfigWithProps,
|
|
withAndroidManifest,
|
|
} from "expo/config-plugins";
|
|
|
|
const fsPromises = fs.promises;
|
|
|
|
const { getMainApplicationOrThrow } = AndroidConfig.Manifest;
|
|
|
|
type AndroidManifest = AndroidConfig.Manifest.AndroidManifest;
|
|
|
|
const withTrustLocalCerts: ConfigPlugin = (config) => {
|
|
return withAndroidManifest(config, async (mod) => {
|
|
mod.modResults = await setCustomConfigAsync(mod, mod.modResults);
|
|
return mod;
|
|
});
|
|
};
|
|
|
|
async function setCustomConfigAsync(
|
|
config: ExportedConfigWithProps<AndroidManifest>,
|
|
androidManifest: AndroidManifest,
|
|
): Promise<AndroidManifest> {
|
|
const src_file_path = path.join(__dirname, "network_security_config.xml");
|
|
const res_file_path = path.join(
|
|
await AndroidConfig.Paths.getResourceFolderAsync(
|
|
config.modRequest.projectRoot,
|
|
),
|
|
"xml",
|
|
"network_security_config.xml",
|
|
);
|
|
|
|
const res_dir = path.resolve(res_file_path, "..");
|
|
|
|
if (!fs.existsSync(res_dir)) {
|
|
await fsPromises.mkdir(res_dir);
|
|
}
|
|
|
|
try {
|
|
await fsPromises.copyFile(src_file_path, res_file_path);
|
|
} catch (e) {
|
|
throw new Error(
|
|
`Failed to copy network security config file from ${src_file_path} to ${res_file_path}. [Hint: Check Android write permissions and file paths]`,
|
|
{ cause: e },
|
|
);
|
|
}
|
|
const mainApplication = getMainApplicationOrThrow(androidManifest);
|
|
if (!mainApplication.$["android:networkSecurityConfig"]) {
|
|
mainApplication.$["android:networkSecurityConfig"] =
|
|
"@xml/network_security_config";
|
|
}
|
|
|
|
return androidManifest;
|
|
}
|
|
|
|
export default withTrustLocalCerts;
|