UNPKG

zephyr-xpack-internal

Version:

Xpack internals for Zephyr

100 lines (99 loc) • 4.69 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__, { coordinateXPackCompilers: ()=>coordinateXPackCompilers }); const external_node_path_namespaceObject = require("node:path"); const external_xpack_build_coordinator_js_namespaceObject = require("./xpack-build-coordinator.js"); function isServerTarget(target) { const targets = Array.isArray(target) ? target : [ target ]; return targets.some((item)=>'string' == typeof item && /^(?:(?:async-)?node(?:\d+(?:\.\d+)*)?|electron-main)$/.test(item)); } function commonDirectory(paths) { if (0 === paths.length) return; const split = paths.map((item)=>external_node_path_namespaceObject.resolve(item).split(external_node_path_namespaceObject.sep)); const length = Math.min(...split.map((parts)=>parts.length)); let index = 0; while(index < length && split.every((parts)=>parts[index] === split[0]?.[index]))index += 1; const common = split[0]?.slice(0, index).join(external_node_path_namespaceObject.sep); return common ? common || external_node_path_namespaceObject.parse(paths[0]).root : void 0; } function coordinateXPackCompilers(engine, configs, options = {}) { const usedNames = new Set(); const outputPaths = configs.map((config)=>config.output?.path).filter((item)=>!!item); const outputRoot = outputPaths.length === configs.length ? commonDirectory(outputPaths) : void 0; const hasDistinctOutputPaths = new Set(outputPaths.map((item)=>external_node_path_namespaceObject.resolve(item))).size > 1; const preserveTapArtifactPaths = engine.env?.target === 'tap-app'; const compilers = configs.map((config, index)=>{ const role = isServerTarget(config.target) ? 'server' : 'client'; const baseName = config.name?.trim() || `${role}-${index}`; let participant = baseName; let suffix = 1; while(usedNames.has(participant))participant = `${baseName}-${suffix++}`; usedNames.add(participant); let assetPrefix; if (!preserveTapArtifactPaths && hasDistinctOutputPaths && outputRoot && config.output?.path) { const relative = external_node_path_namespaceObject.relative(outputRoot, external_node_path_namespaceObject.resolve(config.output.path)); if (relative && '.' !== relative && !relative.startsWith('..')) assetPrefix = relative.split(external_node_path_namespaceObject.sep).join('/'); } return { participant, role, assetPrefix }; }); const inferredSnapshotType = preserveTapArtifactPaths ? 'csr' : compilers.some(({ role })=>'server' === role) ? 'ssr' : 'csr'; const participantByConfigName = new Map(); configs.forEach((config, index)=>{ if (config.name?.trim() && compilers[index]) participantByConfigName.set(config.name.trim(), compilers[index].participant); }); const coordinator = new external_xpack_build_coordinator_js_namespaceObject.XPackBuildCoordinator(engine, compilers.map(({ participant, role }, index)=>({ name: participant, role, dependencies: (configs[index]?.dependencies ?? []).map((dependency)=>participantByConfigName.get(dependency) ?? dependency) })), { ...options, snapshotType: options.snapshotType ?? inferredSnapshotType }); return { coordinator, compilers }; } exports.coordinateXPackCompilers = __webpack_exports__.coordinateXPackCompilers; for(var __rspack_i in __webpack_exports__)if (-1 === [ "coordinateXPackCompilers" ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i]; Object.defineProperty(exports, '__esModule', { value: true }); //# sourceMappingURL=multi-compiler-coordinator.js.map