UNPKG

expo-atlas

Version:

Inspect bundle contents, on module level, from Metro

46 lines 2.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createExpoAtlasMiddleware = void 0; var MetroGraphSource_1 = require("./data/MetroGraphSource"); var middleware_1 = require("./utils/middleware"); /** * Iniitalize Expo Atlas to gather statistics from Metro when exporting bundles. * This function adds the required Metro config, and should be used inside the Expo CLI. * * @example ```js * const atlasFromProject = requireFrom(projectRoot, 'expo-atlas/cli'); * const atlas = atlasFromProject?.createExpoAtlasMiddleware(config); * * if (atlas) { * // Register the Atlas middleware, to serve the UI and API. * middleware.use('/_expo/atlas', atlasFromProject.middleware); * * // Register Metro to listen to changes * atlas.registerMetro(metro); * } * ``` */ function createExpoAtlasMiddleware(config) { var _a, _b; var projectRoot = config.projectRoot; var source = new MetroGraphSource_1.MetroGraphSource(); var middleware = (0, middleware_1.createAtlasMiddleware)(source); var registerMetro = source.registerMetro.bind(source); var metroCustomSerializer = (_b = (_a = config.serializer) === null || _a === void 0 ? void 0 : _a.customSerializer) !== null && _b !== void 0 ? _b : (function () { }); var metroConfig = (0, MetroGraphSource_1.convertMetroConfig)(config); // @ts-expect-error Should still be writable at this stage config.serializer.customSerializer = function (entryPoint, preModules, graph, serializeOptions) { source.serializeGraph({ projectRoot: projectRoot, entryPoint: entryPoint, preModules: preModules, graph: graph, serializeOptions: serializeOptions, metroConfig: metroConfig, }); return metroCustomSerializer(entryPoint, preModules, graph, serializeOptions); }; return { source: source, middleware: middleware, registerMetro: registerMetro }; } exports.createExpoAtlasMiddleware = createExpoAtlasMiddleware; //# sourceMappingURL=cli.js.map