mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-06-12 00:40:23 +01:00
refactor: migrate app.config and Expo config plugins to TypeScript
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).
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const { withPodfile } = require("expo/config-plugins");
|
||||
import { type ConfigPlugin, withPodfile } from "expo/config-plugins";
|
||||
|
||||
const PATCH_START = "## >>> runtime-framework headers";
|
||||
const PATCH_END = "## <<< runtime-framework headers";
|
||||
@@ -13,7 +13,7 @@ const EXTRA_HDRS = [
|
||||
`\${PODS_CONFIGURATION_BUILD_DIR}/React-rendererconsistency/React_rendererconsistency.framework/Headers`,
|
||||
];
|
||||
|
||||
function buildPatch() {
|
||||
function buildPatch(): string {
|
||||
return [
|
||||
PATCH_START,
|
||||
" extra_hdrs = [",
|
||||
@@ -91,7 +91,7 @@ function buildPatch() {
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
module.exports = function withRuntimeFrameworkHeaders(config) {
|
||||
const withRuntimeFrameworkHeaders: ConfigPlugin = (config) => {
|
||||
return withPodfile(config, (config) => {
|
||||
let podfile = config.modResults.contents;
|
||||
|
||||
@@ -125,3 +125,5 @@ end
|
||||
return config;
|
||||
});
|
||||
};
|
||||
|
||||
export default withRuntimeFrameworkHeaders;
|
||||
@@ -1,10 +1,20 @@
|
||||
const {
|
||||
import {
|
||||
type ConfigPlugin,
|
||||
withAndroidColors,
|
||||
withAndroidColorsNight,
|
||||
} = require("expo/config-plugins");
|
||||
} from "expo/config-plugins";
|
||||
|
||||
const withAndroidAlertColors = (config) => {
|
||||
const setColor = (colorsList, name, value) => {
|
||||
interface ColorResourceItem {
|
||||
$: { name: string };
|
||||
_: string;
|
||||
}
|
||||
|
||||
const withAndroidAlertColors: ConfigPlugin = (config) => {
|
||||
const setColor = (
|
||||
colorsList: ColorResourceItem[],
|
||||
name: string,
|
||||
value: string,
|
||||
) => {
|
||||
const existingColor = colorsList.find(
|
||||
(item) => item.$ && item.$.name === name,
|
||||
);
|
||||
@@ -20,7 +30,7 @@ const withAndroidAlertColors = (config) => {
|
||||
|
||||
config = withAndroidColors(config, (config) => {
|
||||
const colors = config.modResults;
|
||||
const colorsList = colors.resources.color || [];
|
||||
const colorsList = (colors.resources.color ?? []) as ColorResourceItem[];
|
||||
setColor(colorsList, "colorPrimary", "#000000");
|
||||
colors.resources.color = colorsList;
|
||||
return config;
|
||||
@@ -28,7 +38,7 @@ const withAndroidAlertColors = (config) => {
|
||||
|
||||
config = withAndroidColorsNight(config, (config) => {
|
||||
const colors = config.modResults;
|
||||
const colorsList = colors.resources.color || [];
|
||||
const colorsList = (colors.resources.color ?? []) as ColorResourceItem[];
|
||||
setColor(colorsList, "colorPrimary", "#FFFFFF");
|
||||
colors.resources.color = colorsList;
|
||||
return config;
|
||||
@@ -37,4 +47,4 @@ const withAndroidAlertColors = (config) => {
|
||||
return config;
|
||||
};
|
||||
|
||||
module.exports = withAndroidAlertColors;
|
||||
export default withAndroidAlertColors;
|
||||
@@ -1,8 +1,12 @@
|
||||
const { withAndroidManifest } = require("expo/config-plugins");
|
||||
import { type ConfigPlugin, withAndroidManifest } from "expo/config-plugins";
|
||||
|
||||
const _withGoogleCastAndroidManifest = (config) =>
|
||||
const withGoogleCastAndroidManifest: ConfigPlugin = (config) =>
|
||||
withAndroidManifest(config, async (mod) => {
|
||||
const mainApplication = mod.modResults.manifest.application[0];
|
||||
const mainApplication = mod.modResults.manifest.application?.[0];
|
||||
|
||||
if (!mainApplication) {
|
||||
return mod;
|
||||
}
|
||||
|
||||
// Initialize activity array if it doesn't exist
|
||||
if (!mainApplication.activity) {
|
||||
@@ -39,4 +43,4 @@ const _withGoogleCastAndroidManifest = (config) =>
|
||||
return mod;
|
||||
});
|
||||
|
||||
module.exports = _withGoogleCastAndroidManifest;
|
||||
export default withGoogleCastAndroidManifest;
|
||||
@@ -1,8 +1,8 @@
|
||||
const { readFileSync, writeFileSync } = require("node:fs");
|
||||
const { join } = require("node:path");
|
||||
const { withDangerousMod } = require("expo/config-plugins");
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { type ConfigPlugin, withDangerousMod } from "expo/config-plugins";
|
||||
|
||||
const withChangeNativeAndroidTextToWhite = (expoConfig) =>
|
||||
const withChangeNativeAndroidTextToWhite: ConfigPlugin = (expoConfig) =>
|
||||
withDangerousMod(expoConfig, [
|
||||
"android",
|
||||
(modConfig) => {
|
||||
@@ -30,4 +30,4 @@ const withChangeNativeAndroidTextToWhite = (expoConfig) =>
|
||||
},
|
||||
]);
|
||||
|
||||
module.exports = withChangeNativeAndroidTextToWhite;
|
||||
export default withChangeNativeAndroidTextToWhite;
|
||||
@@ -1,6 +1,6 @@
|
||||
const { withAppBuildGradle } = require("expo/config-plugins");
|
||||
import { type ConfigPlugin, withAppBuildGradle } from "expo/config-plugins";
|
||||
|
||||
module.exports = function withExcludeMedia3Dash(config) {
|
||||
const withExcludeMedia3Dash: ConfigPlugin = (config) => {
|
||||
return withAppBuildGradle(config, (config) => {
|
||||
const contents = config.modResults.contents;
|
||||
|
||||
@@ -32,3 +32,5 @@ configurations.all {
|
||||
return config;
|
||||
});
|
||||
};
|
||||
|
||||
export default withExcludeMedia3Dash;
|
||||
@@ -1,6 +1,14 @@
|
||||
const { withPodfile } = require("@expo/config-plugins");
|
||||
import { type ConfigPlugin, withPodfile } from "expo/config-plugins";
|
||||
|
||||
const withGitPod = (config, { podName, podspecUrl }) => {
|
||||
interface GitPodOptions {
|
||||
podName: string;
|
||||
podspecUrl: string;
|
||||
}
|
||||
|
||||
const withGitPod: ConfigPlugin<GitPodOptions> = (
|
||||
config,
|
||||
{ podName, podspecUrl },
|
||||
) => {
|
||||
return withPodfile(config, (config) => {
|
||||
const podfile = config.modResults.contents;
|
||||
|
||||
@@ -21,4 +29,4 @@ const withGitPod = (config, { podName, podspecUrl }) => {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = withGitPod;
|
||||
export default withGitPod;
|
||||
@@ -1,12 +1,21 @@
|
||||
const { withGradleProperties } = require("expo/config-plugins");
|
||||
import type { ExpoConfig } from "expo/config";
|
||||
import {
|
||||
AndroidConfig,
|
||||
type ConfigPlugin,
|
||||
withGradleProperties,
|
||||
} from "expo/config-plugins";
|
||||
|
||||
function setGradlePropertiesValue(config, key, value) {
|
||||
function setGradlePropertiesValue(
|
||||
config: ExpoConfig,
|
||||
key: string,
|
||||
value: string,
|
||||
): ExpoConfig {
|
||||
return withGradleProperties(config, (exportedConfig) => {
|
||||
const props = exportedConfig.modResults;
|
||||
const keyIdx = props.findIndex(
|
||||
(item) => item.type === "property" && item.key === key,
|
||||
);
|
||||
const property = {
|
||||
const property: AndroidConfig.Properties.PropertiesItem = {
|
||||
type: "property",
|
||||
key,
|
||||
value,
|
||||
@@ -22,7 +31,7 @@ function setGradlePropertiesValue(config, key, value) {
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = function withCustomPlugin(config) {
|
||||
const withCustomGradleProperties: ConfigPlugin = (config) => {
|
||||
// Expo 52 is not setting this
|
||||
// https://github.com/expo/expo/issues/32558
|
||||
config = setGradlePropertiesValue(config, "android.enableJetifier", "true");
|
||||
@@ -35,3 +44,5 @@ module.exports = function withCustomPlugin(config) {
|
||||
);
|
||||
return config;
|
||||
};
|
||||
|
||||
export default withCustomGradleProperties;
|
||||
@@ -1,6 +1,6 @@
|
||||
const { withXcodeProject } = require("@expo/config-plugins");
|
||||
import { type ConfigPlugin, withXcodeProject } from "expo/config-plugins";
|
||||
|
||||
const withTVOSAppIcon = (config) => {
|
||||
const withTVOSAppIcon: ConfigPlugin = (config) => {
|
||||
// Only apply for TV builds
|
||||
if (process.env.EXPO_TV !== "1") {
|
||||
return config;
|
||||
@@ -28,4 +28,4 @@ const withTVOSAppIcon = (config) => {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = withTVOSAppIcon;
|
||||
export default withTVOSAppIcon;
|
||||
@@ -1,8 +1,10 @@
|
||||
const {
|
||||
import type { ExpoConfig } from "expo/config";
|
||||
import {
|
||||
type ConfigPlugin,
|
||||
withEntitlementsPlist,
|
||||
withInfoPlist,
|
||||
withXcodeProject,
|
||||
} = require("@expo/config-plugins");
|
||||
} from "expo/config-plugins";
|
||||
|
||||
const EXTENSION_TARGET_NAME = "StreamyfinTopShelf";
|
||||
const TARGET_SOURCE_DIR = "../targets/StreamyfinTopShelf";
|
||||
@@ -10,19 +12,29 @@ const APP_GROUP_INFO_PLIST_KEY = "StreamyfinAppGroupIdentifier";
|
||||
const KEYCHAIN_ACCESS_GROUP_INFO_PLIST_KEY =
|
||||
"StreamyfinKeychainAccessGroupIdentifier";
|
||||
|
||||
function getBundleIdentifier(config) {
|
||||
interface AppExtensionConfig {
|
||||
targetName: string;
|
||||
bundleIdentifier: string;
|
||||
entitlements: {
|
||||
"com.apple.security.application-groups": string[];
|
||||
"keychain-access-groups": string[];
|
||||
};
|
||||
}
|
||||
|
||||
function getBundleIdentifier(config: ExpoConfig): string {
|
||||
return config.ios?.bundleIdentifier || "com.fredrikburmester.streamyfin";
|
||||
}
|
||||
|
||||
function getAppGroupIdentifier(config) {
|
||||
function getAppGroupIdentifier(config: ExpoConfig): string {
|
||||
return `group.${getBundleIdentifier(config)}.tvtopshelf`;
|
||||
}
|
||||
|
||||
function getKeychainAccessGroupIdentifier(config) {
|
||||
function getKeychainAccessGroupIdentifier(config: ExpoConfig): string {
|
||||
return `$(AppIdentifierPrefix)${getBundleIdentifier(config)}`;
|
||||
}
|
||||
|
||||
function getBuildConfigurations(project, configurationListId) {
|
||||
// The xcode project object has no usable typings — keep `any` here.
|
||||
function getBuildConfigurations(project: any, configurationListId: string) {
|
||||
const configurationList =
|
||||
project.hash.project.objects.XCConfigurationList[configurationListId];
|
||||
|
||||
@@ -30,18 +42,21 @@ function getBuildConfigurations(project, configurationListId) {
|
||||
|
||||
const buildConfigurations = project.pbxXCBuildConfigurationSection();
|
||||
return configurationList.buildConfigurations
|
||||
.map((config) => buildConfigurations[config.value])
|
||||
.map((config: { value: string }) => buildConfigurations[config.value])
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function ensureAppGroup(value, appGroupIdentifier) {
|
||||
function ensureAppGroup(value: unknown, appGroupIdentifier: string): string[] {
|
||||
const groups = Array.isArray(value) ? value : [];
|
||||
return groups.includes(appGroupIdentifier)
|
||||
? groups
|
||||
: [...groups, appGroupIdentifier];
|
||||
}
|
||||
|
||||
function ensureKeychainAccessGroup(value, keychainAccessGroupIdentifier) {
|
||||
function ensureKeychainAccessGroup(
|
||||
value: unknown,
|
||||
keychainAccessGroupIdentifier: string,
|
||||
): string[] {
|
||||
const groups = Array.isArray(value) ? value : [];
|
||||
return groups.includes(keychainAccessGroupIdentifier)
|
||||
? groups
|
||||
@@ -49,13 +64,13 @@ function ensureKeychainAccessGroup(value, keychainAccessGroupIdentifier) {
|
||||
}
|
||||
|
||||
function ensureAppExtension(
|
||||
appExtensions,
|
||||
targetName,
|
||||
bundleIdentifier,
|
||||
appGroupIdentifier,
|
||||
keychainAccessGroupIdentifier,
|
||||
) {
|
||||
const extensionConfig = {
|
||||
appExtensions: unknown,
|
||||
targetName: string,
|
||||
bundleIdentifier: string,
|
||||
appGroupIdentifier: string,
|
||||
keychainAccessGroupIdentifier: string,
|
||||
): AppExtensionConfig[] {
|
||||
const extensionConfig: AppExtensionConfig = {
|
||||
targetName,
|
||||
bundleIdentifier,
|
||||
entitlements: {
|
||||
@@ -63,7 +78,9 @@ function ensureAppExtension(
|
||||
"keychain-access-groups": [keychainAccessGroupIdentifier],
|
||||
},
|
||||
};
|
||||
const extensions = Array.isArray(appExtensions) ? appExtensions : [];
|
||||
const extensions: AppExtensionConfig[] = Array.isArray(appExtensions)
|
||||
? appExtensions
|
||||
: [];
|
||||
// Keep plugin runs idempotent and preserve unrelated app extension entries.
|
||||
const existingIndex = extensions.findIndex(
|
||||
(appExtension) => appExtension?.targetName === targetName,
|
||||
@@ -78,7 +95,7 @@ function ensureAppExtension(
|
||||
);
|
||||
}
|
||||
|
||||
const withTVOSTopShelf = (config) => {
|
||||
const withTVOSTopShelf: ConfigPlugin = (config) => {
|
||||
const appGroupIdentifier = getAppGroupIdentifier(config);
|
||||
const keychainAccessGroupIdentifier =
|
||||
getKeychainAccessGroupIdentifier(config);
|
||||
@@ -193,4 +210,4 @@ const withTVOSTopShelf = (config) => {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = withTVOSTopShelf;
|
||||
export default withTVOSTopShelf;
|
||||
@@ -1,9 +1,9 @@
|
||||
const { withEntitlementsPlist } = require("expo/config-plugins");
|
||||
import { type ConfigPlugin, withEntitlementsPlist } from "expo/config-plugins";
|
||||
|
||||
/**
|
||||
* Expo config plugin to add User Management entitlement for tvOS profile linking
|
||||
*/
|
||||
const withTVUserManagement = (config) => {
|
||||
const withTVUserManagement: ConfigPlugin = (config) => {
|
||||
// Only add for tvOS builds. The entitlement is restricted by Apple and must
|
||||
// be present in the provisioning profile, so injecting it into mobile builds
|
||||
// breaks signing ("Entitlement ... not found and could not be included in
|
||||
@@ -24,4 +24,4 @@ const withTVUserManagement = (config) => {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = withTVUserManagement;
|
||||
export default withTVUserManagement;
|
||||
@@ -1,7 +1,7 @@
|
||||
const { withDangerousMod } = require("@expo/config-plugins");
|
||||
const { execSync } = require("node:child_process");
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
import { execSync } from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { type ConfigPlugin, withDangerousMod } from "expo/config-plugins";
|
||||
|
||||
/**
|
||||
* Expo config plugin that adds EXPO_TV=1 and NODE_BINARY to .xcode.env.local for TV builds.
|
||||
@@ -12,7 +12,7 @@ const path = require("node:path");
|
||||
*
|
||||
* It also sets NODE_BINARY for nvm users since Xcode can't resolve shell functions.
|
||||
*/
|
||||
const withTVXcodeEnv = (config) => {
|
||||
const withTVXcodeEnv: ConfigPlugin = (config) => {
|
||||
// Only apply for TV builds
|
||||
if (process.env.EXPO_TV !== "1") {
|
||||
return config;
|
||||
@@ -70,7 +70,7 @@ const withTVXcodeEnv = (config) => {
|
||||
/**
|
||||
* Get the actual node binary path, handling nvm installations.
|
||||
*/
|
||||
function getNodeBinaryPath() {
|
||||
function getNodeBinaryPath(): string | null {
|
||||
try {
|
||||
// First try to get node path directly (works for non-nvm installs)
|
||||
const directPath = execSync("which node 2>/dev/null", {
|
||||
@@ -114,4 +114,4 @@ function getNodeBinaryPath() {
|
||||
return null;
|
||||
}
|
||||
|
||||
module.exports = withTVXcodeEnv;
|
||||
export default withTVXcodeEnv;
|
||||
@@ -1,18 +1,29 @@
|
||||
const { AndroidConfig, withAndroidManifest } = require("expo/config-plugins");
|
||||
const path = require("node:path");
|
||||
const fs = require("node:fs");
|
||||
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;
|
||||
|
||||
const withTrustLocalCerts = (config) => {
|
||||
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, androidManifest) {
|
||||
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(
|
||||
@@ -45,4 +56,4 @@ async function setCustomConfigAsync(config, androidManifest) {
|
||||
return androidManifest;
|
||||
}
|
||||
|
||||
module.exports = withTrustLocalCerts;
|
||||
export default withTrustLocalCerts;
|
||||
Reference in New Issue
Block a user