vanilla-native-federation
Version:
A lightweight **runtime micro frontend orchestrator** that loads micro frontends built with native federation into any web page. It can cache dependencies across page reloads, making it perfect for traditional server-rendered hosts (PHP, Java, Rails, etc.
100 lines (94 loc) • 2.38 kB
JavaScript
var __defProp = Object.defineProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
// src/lib/1.domain/externals/external.contract.ts
var GLOBAL_SCOPE = "__GLOBAL__";
var STRICT_SCOPE = "strict";
// src/lib/utils/optional.ts
var Optional = class _Optional {
constructor(item) {
this.item = item;
}
static of(item) {
return new _Optional(item);
}
static empty() {
return _Optional.of(void 0);
}
isPresent() {
return typeof this.item !== "undefined" && this.item !== null;
}
set(other) {
return _Optional.of(other);
}
ifPresent(callback) {
if (this.isPresent()) callback(this.item);
}
map(callback) {
if (!this.isPresent()) return _Optional.empty();
const result = callback(this.item);
return result instanceof _Optional ? result : _Optional.of(result);
}
orElse(other) {
return this.isPresent() ? this.item : other;
}
orThrow(error) {
if (this.isPresent()) return this.item;
if (typeof error === "function") throw error();
throw typeof error === "string" ? new Error(error) : error;
}
get() {
return this.item;
}
};
// src/lib/utils/path.ts
var path_exports = {};
__export(path_exports, {
getScope: () => getScope,
join: () => join
});
function join(pathA, pathB) {
pathA = pathA.endsWith("/") ? pathA.slice(0, -1) : pathA;
pathB = pathB.startsWith("/") ? pathB.slice(1) : pathB;
return `${pathA}/${pathB}`;
}
function getScope(path) {
if (!path) return "";
const parts = path.split("/");
if (parts[parts.length - 1] === "" || parts[parts.length - 1].includes(".")) {
parts.pop();
}
if (parts.length < 1) return "";
return `${parts.join("/")}/`;
}
// src/lib/native-federation.error.ts
var NFError = class extends Error {
constructor(message, cause) {
super(message, cause);
this.name = "NFError";
}
};
// src/lib/utils/clone-entry.ts
var cloneEntry = (name, raw) => {
try {
if (typeof structuredClone === "function") {
return structuredClone(raw);
}
} catch {
}
try {
return JSON.parse(JSON.stringify(raw));
} catch {
}
throw new NFError(`Could not parse storage entry '${String(name)}'`);
};
export {
GLOBAL_SCOPE,
Optional,
STRICT_SCOPE,
path_exports as _path,
cloneEntry
};
//# sourceMappingURL=sdk.mjs.map