UNPKG

@rechunk/babel-plugin

Version:

Babel plugin for transforming and processing ReChunk directives in React Native applications

66 lines (63 loc) 3.28 kB
import * as Babel from '@babel/core'; import { ConfigAPI, TransformCaller } from '@babel/core'; import { BabelPresetExpoOptions } from 'babel-preset-expo'; /** * Checks if the Babel transformation is being invoked by the ReChunk bundler. * * This function examines the `caller` object to determine if the `name` property * matches `'rechunk'`, indicating that the current Babel transformation is being * executed by the ReChunk bundler. * * @param {TransformCaller} caller - The caller object provided by Babel's `api.caller` function. * This object typically contains metadata about the tool invoking the Babel transformation. * * @returns {boolean} Returns `true` if the `caller.name` is `'rechunk'`, otherwise `false`. * * @example * ```typescript * const isRechunkBundler = api.caller(getIsRechunkBundler); * if (isRechunkBundler) { * console.log('Transformation is running in the ReChunk bundler'); * } * ``` */ declare function getIsRechunkBundler(caller: TransformCaller): boolean; declare function export_default(api: ConfigAPI): Babel.PluginObj; /** * Modifies React Native Babel preset options when running in the ReChunk bundler environment. * * This function customizes the Babel preset options based on whether the code is being processed * by the ReChunk bundler. It disables both the Babel runtime and import/export transforms when * running in ReChunk to prevent conflicts and ensure proper bundle compatibility. * * @param {ConfigAPI} api - The Babel configuration API object that provides info about the current transformation * @param {Record<string, unknown>} options - The current React Native Babel preset options object * @returns {Record<string, unknown>} A modified options object with adjusted settings for ReChunk compatibility * * @example * ```typescript * const modifiedOptions = withReactNativeBabelPresetOptions(api, defaultOptions); * // Returns options with enableBabelRuntime and importExportTransform disabled if running in ReChunk * ``` */ declare function withReactNativeBabelPresetOptions(api: ConfigAPI, options?: Record<string, unknown>): Record<string, unknown>; /** * Modifies Babel Preset Expo options when running in the ReChunk bundler environment. * * This function takes the current Babel Preset Expo options and adjusts them based on * whether the code is being processed by the ReChunk bundler. Specifically, it disables * the Babel runtime when running in ReChunk to prevent conflicts with ReChunk's own * runtime handling. * * @param {ConfigAPI} api - The Babel configuration API object that provides information about the current transformation * @param {BabelPresetExpoOptions} options - The current Babel Preset Expo options object * @returns {BabelPresetExpoOptions} A modified options object with adjusted settings for ReChunk compatibility * * @example * ```typescript * const modifiedOptions = withBabelPresetExpoOptions(api, defaultOptions); * // Returns options with enableBabelRuntime disabled if running in ReChunk * ``` */ declare function withBabelPresetExpoOptions(api: ConfigAPI, options?: BabelPresetExpoOptions): BabelPresetExpoOptions; export { export_default as default, getIsRechunkBundler, withBabelPresetExpoOptions, withReactNativeBabelPresetOptions };