"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Chunk = void 0; exports.graphToSerialAssetsAsync = graphToSerialAssetsAsync; exports.getSortedModules = getSortedModules; const bundleToString_1 = __importDefault(require("@expo/metro/metro/lib/bundleToString")); const isResolvedDependency_1 = require("@expo/metro/metro/lib/isResolvedDependency"); const assert_1 = __importDefault(require("assert")); const path_1 = __importDefault(require("path")); const debugId_1 = require("./debugId"); const exportPath_1 = require("./exportPath"); const getCssDeps_1 = require("./getCssDeps"); const getAssets_1 = __importDefault(require("../transform-worker/getAssets")); const filePath_1 = require("../utils/filePath"); // Lazy-loaded to avoid pulling in metro-source-map at startup let _buildHermesBundleAsync; function getBuildHermesBundleAsync() { if (!_buildHermesBundleAsync) { _buildHermesBundleAsync = require('./exportHermes').buildHermesBundleAsync; } return _buildHermesBundleAsync; } // Lazy-loaded to avoid pulling in metro's getAppendScripts -> sourceMapString -> @babel/traverse at startup let _sourceMapString; function getSourceMapString() { if (!_sourceMapString) { _sourceMapString = require('@expo/metro/metro/DeltaBundler/Serializers/sourceMapString').sourceMapString; } return _sourceMapString; } let _baseJSBundleWithDependencies; function getBaseJSBundleWithDependencies() { if (!_baseJSBundleWithDependencies) { _baseJSBundleWithDependencies = require('./fork/baseJSBundle').baseJSBundleWithDependencies; } return _baseJSBundleWithDependencies; } let _getBaseUrlOption; function getBaseUrlOption(...args) { if (!_getBaseUrlOption) { _getBaseUrlOption = require('./fork/baseJSBundle').getBaseUrlOption; } return _getBaseUrlOption(...args); } let _getPlatformOption; function getPlatformOption(...args) { if (!_getPlatformOption) { _getPlatformOption = require('./fork/baseJSBundle').getPlatformOption; } return _getPlatformOption(...args); } async function graphToSerialAssetsAsync(config, serializeChunkOptions, ...props) { const [entryFile, preModules, graph, options] = props; const cssDeps = (0, getCssDeps_1.getCssSerialAssets)(graph.dependencies, { entryFile, projectRoot: options.projectRoot, }); // Create chunks for splitting. const chunks = new Set(); gatherChunks(preModules, chunks, { test: pathToRegex(entryFile) }, preModules, graph, options, false, true); const entryChunk = findEntryChunk(chunks, entryFile); if (entryChunk) { removeEntryDepsFromAsyncChunks(entryChunk, chunks); const commonChunk = extractCommonChunk(chunks, graph, options); if (commonChunk) { entryChunk.requiredChunks.add(commonChunk); chunks.add(commonChunk); } deduplicateAgainstKnownChunks(chunks, entryChunk, commonChunk); removeEmptyChunks(chunks); if (commonChunk) { createRuntimeChunk(entryChunk, chunks, graph, options); } } const jsAssets = await serializeChunksAsync(chunks, config.serializer ?? {}, serializeChunkOptions); // TODO: Can this be anything besides true? const isExporting = true; const baseUrl = getBaseUrlOption(graph, { serializerOptions: serializeChunkOptions }); const assetPublicUrl = (baseUrl.replace(/\/+$/, '') ?? '') + '/assets'; const platform = getPlatformOption(graph, options) ?? 'web'; const isHosted = platform === 'web' || (graph.transformOptions?.customTransformOptions?.hosted && isExporting); const publicPath = isExporting ? isHosted ? `/assets?export_path=${assetPublicUrl}` : assetPublicUrl : '/assets/?unstable_path=.'; // TODO: Convert to serial assets // TODO: Disable this call dynamically in development since assets are fetched differently. const metroAssets = (await (0, getAssets_1.default)(graph.dependencies, { processModuleFilter: options.processModuleFilter, assetPlugins: config.transformer?.assetPlugins ?? [], platform, projectRoot: options.projectRoot, // this._getServerRootDir(), publicPath, isHosted, })); return { artifacts: [...jsAssets, ...cssDeps], assets: metroAssets, }; } class Chunk { name; entries; graph; options; isAsync; isVendor; isEntry; deps = new Set(); preModules = new Set(); // Chunks that are required to be loaded synchronously before this chunk. // These are included in the HTML as