import type * as BabelCore from "@babel/core";
import { hasOwnProperty } from "../Utils/utils";
import { PluginOptions } from "./Options";
function hasModule(name: string): boolean {
try {
return !!require.resolve(name);
} catch (error: any) {
if (
error.code === "MODULE_NOT_FOUND" &&
error.message.indexOf(name) !== -1
) {
return false;
}
throw error;
}
}
export function pipelineUsesReanimatedPlugin(
plugins: Array<BabelCore.PluginItem> | null | undefined
): boolean {
if (Array.isArray(plugins)) {
for (const plugin of plugins) {
if (hasOwnProperty(plugin, "key")) {
const key = (plugin as any).key;
if (
typeof key === "string" &&
key.indexOf("react-native-reanimated") !== -1
) {
return true;
}
}
}
}
return hasModule("react-native-reanimated");
}
export function injectReanimatedFlag(options: PluginOptions): PluginOptions {
return {
...options,
environment: {
...options.environment,
enableCustomTypeDefinitionForReanimated: true,
},
};
}