zephyr-xpack-internal
Version:
Xpack internals for Zephyr
134 lines (133 loc) • 6.22 kB
JavaScript
;
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__, {
setupZeDeploy: ()=>setupZeDeploy
});
const ze_xpack_upload_agent_js_namespaceObject = require("../xpack-extract/ze-xpack-upload-agent.js");
const external_zephyr_agent_namespaceObject = require("zephyr-agent");
const external_node_path_namespaceObject = require("node:path");
function dependencyList(dependencies) {
return dependencies ? [
...dependencies
].filter((value)=>'string' == typeof value) : [];
}
function collectDependencyPaths(compilation) {
return {
fileDependencies: dependencyList(compilation.fileDependencies),
contextDependencies: dependencyList(compilation.contextDependencies),
missingDependencies: dependencyList(compilation.missingDependencies),
buildDependencies: dependencyList(compilation.buildDependencies)
};
}
function setupZeDeploy(pluginOptions, compiler) {
const { pluginName } = pluginOptions;
let generation = 0;
const finalizedUploads = new WeakMap();
const getSuccessfulStats = (compilation)=>{
const stats = compilation.getStats();
if (!stats.hasErrors?.() && (compilation.errors?.length ?? 0) === 0) return stats;
const error = new external_zephyr_agent_namespaceObject.ZephyrError(external_zephyr_agent_namespaceObject.ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
message: `Zephyr will not upload ${pluginOptions.participant ?? 'xpack'} output because the compilation contains errors.`
});
if (pluginOptions.coordinator && pluginOptions.participant) pluginOptions.coordinator.failParticipant(pluginOptions.participant, error);
else if (pluginOptions.zephyr_engine.hasActiveBuild) pluginOptions.zephyr_engine.build_failed();
throw error;
};
const upload = async (compilation, assets, compilationGeneration, assetsAreFinal)=>{
const stats = getSuccessfulStats(compilation);
const stats_json = stats.toJson();
if (!pluginOptions.coordinator) try {
await pluginOptions.zephyr_engine.start_new_build();
} catch (error) {
if (false !== pluginOptions.zephyr_engine.hasActiveBuild) pluginOptions.zephyr_engine.build_failed();
throw error;
}
await (0, ze_xpack_upload_agent_js_namespaceObject.xpack_zephyr_agent)({
stats,
stats_json,
assets,
pluginOptions: {
...pluginOptions,
generation: compilationGeneration,
dependencyPaths: collectDependencyPaths(compilation),
wait_for_index_html: assetsAreFinal ? false : pluginOptions.wait_for_index_html
}
});
console.log();
};
if (pluginOptions.wait_for_index_html) compiler.hooks.afterEmit.tapPromise(pluginName, async (compilation)=>{
const pending = finalizedUploads.get(compilation);
if (!pending) return;
finalizedUploads.delete(compilation);
await upload(compilation, pending.assets, pending.generation, true);
});
if (pluginOptions.coordinator && pluginOptions.participant) {
const participant = pluginOptions.participant;
compiler.hooks.invalid?.tap(pluginName, (filename)=>{
const invalidatedPath = filename ? external_node_path_namespaceObject.resolve(compiler.context ?? process.cwd(), filename) : filename;
pluginOptions.coordinator?.invalidateParticipant(participant, invalidatedPath);
});
}
compiler.hooks.failed?.tap(pluginName, (error)=>{
if (pluginOptions.coordinator && pluginOptions.participant) pluginOptions.coordinator.failParticipant(pluginOptions.participant, error);
else if (false !== pluginOptions.zephyr_engine.hasActiveBuild) pluginOptions.zephyr_engine.build_failed();
});
compiler.hooks.thisCompilation.tap(pluginName, (compilation)=>{
const compilationGeneration = generation++;
if (pluginOptions.coordinator) {
if (!pluginOptions.participant) 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'
});
pluginOptions.coordinator.beginParticipant(pluginOptions.participant, compilationGeneration);
}
compilation.hooks.processAssets.tapPromise({
name: pluginName,
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT
}, async (assets)=>{
if (pluginOptions.wait_for_index_html) {
getSuccessfulStats(compilation);
finalizedUploads.set(compilation, {
assets,
generation: compilationGeneration
});
return;
}
await upload(compilation, assets, compilationGeneration, false);
});
});
}
exports.setupZeDeploy = __webpack_exports__.setupZeDeploy;
for(var __rspack_i in __webpack_exports__)if (-1 === [
"setupZeDeploy"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
value: true
});
//# sourceMappingURL=ze-setup-ze-deploy.js.map