everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
69 lines (67 loc) • 1.87 kB
JavaScript
const require_merge = require('./resolution/merge.cjs');
//#region src/services/config-slots.ts
function walkConfigSlots(config, visit) {
const app = config.app;
if (require_merge.isPlainObject(app)) for (const [key, entry] of Object.entries(app)) {
if (!require_merge.isPlainObject(entry)) continue;
visit({
slot: `app.${key}`,
entry,
isPluginRef: false
});
if ("ui" in entry) {
const ui = entry.ui;
if (require_merge.isPlainObject(ui) || ui === false) visit({
slot: `app.${key}.ui`,
entry: ui,
isPluginRef: false
});
}
}
const plugins = config.plugins;
if (require_merge.isPlainObject(plugins)) for (const [id, entry] of Object.entries(plugins)) {
if (typeof entry === "string") {
if (entry.length > 0) visit({
slot: `plugins.${id}`,
entry,
isPluginRef: true
});
continue;
}
if (!require_merge.isPlainObject(entry)) continue;
visit({
slot: `plugins.${id}`,
entry,
isPluginRef: false
});
if ("ui" in entry) {
const ui = entry.ui;
if (require_merge.isPlainObject(ui) || ui === false) visit({
slot: `plugins.${id}.ui`,
entry: ui,
isPluginRef: false
});
}
}
}
/**
* Ensure every container of a dotted path exists (creating plain objects along
* the way) and return the container that holds the final segment. Consumers
* keep the final-set semantics (replace vs merge-into) local.
*/
function ensureObjectContainers(target, segments) {
let container = target;
for (const segment of segments) {
const next = container[segment];
if (!require_merge.isPlainObject(next)) {
const created = {};
container[segment] = created;
container = created;
} else container = next;
}
return container;
}
//#endregion
exports.ensureObjectContainers = ensureObjectContainers;
exports.walkConfigSlots = walkConfigSlots;
//# sourceMappingURL=config-slots.cjs.map