UNPKG

zephyr-xpack-internal

Version:

Xpack internals for Zephyr

124 lines (123 loc) • 5.86 kB
"use strict"; var __webpack_require__ = {}; (()=>{ __webpack_require__.d = (exports1, getters, values)=>{ var define = (defs, kind)=>{ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, { enumerable: true, [kind]: defs[key] }); }; define(getters, "get"); define(values, "value"); }; })(); (()=>{ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop); })(); (()=>{ __webpack_require__.r = (exports1)=>{ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, { value: 'Module' }); Object.defineProperty(exports1, '__esModule', { value: true }); }; })(); var __webpack_exports__ = {}; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { xpack_zephyr_agent: ()=>xpack_zephyr_agent }); const external_zephyr_agent_namespaceObject = require("zephyr-agent"); const get_build_stats_js_namespaceObject = require("../federation-dashboard-legacy/get-build-stats.js"); const external_federation_config_metadata_js_namespaceObject = require("./federation-config-metadata.js"); const index_js_namespaceObject = require("../lifecycle-events/index.js"); const external_build_webpack_assets_map_js_namespaceObject = require("./build-webpack-assets-map.js"); async function xpack_zephyr_agent({ stats, stats_json, assets, pluginOptions }) { external_zephyr_agent_namespaceObject.ze_log.init('Initiating: Zephyr Webpack Upload Agent'); const zeStart = Date.now(); const { wait_for_index_html, zephyr_engine } = pluginOptions; const coordinator = pluginOptions.coordinator; let coordinatedParticipant; const preserveTapArtifactPaths = zephyr_engine.env?.target === 'tap-app'; let logicalDeploymentCompleted = !coordinator; try { if (preserveTapArtifactPaths) zephyr_engine.buildProperties.baseHref = ''; let assetsMap = await (0, external_build_webpack_assets_map_js_namespaceObject.buildWebpackAssetMap)(assets, { wait_for_index_html: preserveTapArtifactPaths ? false : wait_for_index_html, failOnUnsupportedSource: preserveTapArtifactPaths }); if (pluginOptions.assetPrefix && !preserveTapArtifactPaths) assetsMap = prefixAssetPaths(assetsMap, pluginOptions.assetPrefix); if (coordinator) { coordinatedParticipant = pluginOptions.participant; if (!coordinatedParticipant) throw new external_zephyr_agent_namespaceObject.ZephyrError(external_zephyr_agent_namespaceObject.ZeErrors.ERR_DEPLOY_LOCAL_BUILD, { message: 'A coordinated xpack build requires a participant name' }); await coordinator.prepareParticipant(coordinatedParticipant, pluginOptions.generation); } const { EDGE_URL, PLATFORM, DELIMITER } = await zephyr_engine.application_configuration; const dashData = await (0, get_build_stats_js_namespaceObject.getBuildStats)({ stats, stats_json, assets, pluginOptions, EDGE_URL, PLATFORM, DELIMITER }); const mfConfigs = (0, get_build_stats_js_namespaceObject.getModuleFederationConfigs)(pluginOptions.mfConfig); const mfConfig = (0, external_federation_config_metadata_js_namespaceObject.getLegacyModuleFederationConfig)(mfConfigs); if (coordinator && coordinatedParticipant) { logicalDeploymentCompleted = await coordinator.contribute({ participant: coordinatedParticipant, generation: pluginOptions.generation, assetsMap, mfConfigs: mfConfigs.length > 0 ? mfConfigs : void 0, buildStats: dashData, hooks: pluginOptions.hooks, dependencyPaths: pluginOptions.dependencyPaths }); return; } await zephyr_engine.upload_assets({ assetsMap, mfConfigs: mfConfigs.length > 0 ? mfConfigs : void 0, mfConfig, buildStats: dashData, hooks: pluginOptions.hooks }); await zephyr_engine.build_finished(); } catch (err) { if (coordinator) throw err; if (false !== zephyr_engine.hasActiveBuild) zephyr_engine.build_failed(); (0, external_zephyr_agent_namespaceObject.handleGlobalError)(err); } finally{ if (logicalDeploymentCompleted) (0, index_js_namespaceObject.emitDeploymentDone)(); external_zephyr_agent_namespaceObject.ze_log.upload('Zephyr Webpack Upload Agent: Done in', Date.now() - zeStart, 'ms'); } } function prefixAssetPaths(assetsMap, assetPrefix) { const normalizedPrefix = assetPrefix.replace(/\\/g, '/').replace(/^\/+|\/+$/g, ''); if (!normalizedPrefix) return assetsMap; return Object.fromEntries(Object.values(assetsMap).map((asset)=>{ const prefixedPath = asset.path.startsWith(`${normalizedPrefix}/`) ? asset.path : `${normalizedPrefix}/${asset.path.replace(/^\/+/, '')}`; const prefixedAsset = (0, external_zephyr_agent_namespaceObject.zeBuildAssets)({ filepath: prefixedPath, content: asset.buffer }); return [ prefixedAsset.hash, prefixedAsset ]; })); } exports.xpack_zephyr_agent = __webpack_exports__.xpack_zephyr_agent; for(var __rspack_i in __webpack_exports__)if (-1 === [ "xpack_zephyr_agent" ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i]; Object.defineProperty(exports, '__esModule', { value: true }); //# sourceMappingURL=ze-xpack-upload-agent.js.map