expo-atlas
Version:
Inspect bundle contents, on module level, from Metro
79 lines • 4.01 kB
TypeScript
import type metro from 'metro';
import type MetroServer from 'metro/src/Server';
import type { MetroConfig } from 'metro-config';
import type { AtlasBundle, AtlasBundleDelta, AtlasModule, AtlasSource } from './types';
type MetroGraph = metro.Graph | metro.ReadOnlyGraph;
type MetroModule = metro.Module;
type ConvertGraphToAtlasOptions = {
projectRoot: string;
entryPoint: string;
preModules: Readonly<MetroModule[]>;
graph: MetroGraph;
serializeOptions: Readonly<metro.SerializerOptions>;
/** Options passed-through from the Metro config */
metroConfig: {
watchFolders?: Readonly<string[]>;
resolver?: {
sourceExts?: Readonly<string[]>;
assetExts?: Readonly<string[]>;
};
};
};
export declare class MetroGraphSource implements AtlasSource {
/** The Metro delta listener, instantiated when the Metro server is registered */
protected deltaListener: MetroDeltaListener | null;
/** All known entries, and detected changes, stored by ID */
readonly entries: Map<AtlasBundle['id'], {
entry: AtlasBundle;
delta?: AtlasBundleDelta;
}>;
constructor();
listBundles(): {
id: string;
platform: "android" | "ios" | "web" | "server";
projectRoot: string;
sharedRoot: string;
entryPoint: string;
}[];
getBundle(id: string): AtlasBundle;
getBundleDelta(id: string): AtlasBundleDelta | null;
bundleDeltaEnabled(): boolean;
/**
* Serializes the Metro graph, converting it to an Atlas entry.
* This also registers a listener to the Metro server to track changes, when possible.
* All data is kept in memory, where stale data is overwritten by new data.
*/
serializeGraph(options: ConvertGraphToAtlasOptions): AtlasBundle;
/**
* Register the Metro server to listen for changes in serialized graphs.
* Once changes are detected, the delta is generated and stored with the entry.
* Changes allows the client to know when to refetch data.
*/
registerMetro(metro: MetroServer): void;
}
declare class MetroDeltaListener {
private source;
private bundler;
private listeners;
constructor(source: MetroGraphSource, metro: MetroServer);
registerGraph(entryId: AtlasBundle['id'], graph: MetroGraph): void;
/**
* Event handler invoked when a change is detected by Metro, using the DeltaBundler.
* The detected change is combined with the Atlas entry ID, and updates the source entry with the delta.
*/
onMetroChange(entryId: AtlasBundle['id'], delta: metro.DeltaResult<void>, createdAt: Date): void;
}
/** Convert options from the Metro config, used during graph conversions to Atlas */
export declare function convertMetroConfig(config: MetroConfig): ConvertGraphToAtlasOptions['metroConfig'];
/** Convert a Metro graph instance to a JSON-serializable entry */
export declare function convertGraph(options: ConvertGraphToAtlasOptions): AtlasBundle;
/** Find and collect all dependnecies related to the entrypoint within the graph */
export declare function collectEntryPointModules(options: Pick<ConvertGraphToAtlasOptions, 'graph' | 'entryPoint' | 'serializeOptions' | 'metroConfig'>, sharedRoot: string): Map<string, AtlasModule>;
/** Convert a Metro module to a JSON-serializable Atlas module */
export declare function convertModule(options: Pick<ConvertGraphToAtlasOptions, 'graph' | 'metroConfig' | 'serializeOptions'>, module: MetroModule, sharedRoot: string): AtlasModule;
/** Convert Metro transform options to a JSON-serializable object */
export declare function convertTransformOptions(options: Pick<ConvertGraphToAtlasOptions, 'graph'>): AtlasBundle['transformOptions'];
/** Convert Metro serialize options to a JSON-serializable object */
export declare function convertSerializeOptions(options: Pick<ConvertGraphToAtlasOptions, 'serializeOptions'>): AtlasBundle['serializeOptions'];
export {};
//# sourceMappingURL=MetroGraphSource.d.ts.map