@softarc/native-federation-orchestrator 4.0.0-RC1 → 4.0.0-RC4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/@softarc/native-federation-orchestrator.mjs +230 -49
- package/fesm2022/@softarc/native-federation-orchestrator.mjs.map +4 -4
- package/fesm2022/options.mjs +8 -2
- package/fesm2022/options.mjs.map +2 -2
- package/package.json +1 -1
- package/quickstart.mjs +13 -13
- package/types/lib/1.domain/externals/chunks.contract.d.ts +3 -0
- package/types/lib/1.domain/externals/version.contract.d.ts +2 -0
- package/types/lib/1.domain/remote-entry/remote-entry.contract.d.ts +1 -18
- package/types/lib/2.app/config/import-map.contract.d.ts +1 -0
- package/types/lib/2.app/config/log.contract.d.ts +2 -0
- package/types/lib/2.app/driving-ports/driving.contract.d.ts +4 -0
- package/types/lib/2.app/driving-ports/for-shared-chunks-storage.port.d.ts +6 -0
- package/types/lib/2.app/driving-ports/for-sse.port.d.ts +4 -0
- package/types/lib/2.app/driving-ports/index.d.ts +1 -0
- package/types/lib/2.app/flows/dynamic-init/convert-to-import-map.d.ts +2 -1
- package/types/lib/2.app/flows/dynamic-init/get-remote-entry.d.ts +1 -1
- package/types/lib/2.app/flows/dynamic-init/update-cache.d.ts +1 -1
- package/types/lib/2.app/flows/init/commit-changes.d.ts +1 -1
- package/types/lib/2.app/flows/init/generate-import-map.d.ts +1 -1
- package/types/lib/2.app/flows/init/get-remote-entries.d.ts +1 -1
- package/types/lib/2.app/flows/init/process-remote-entries.d.ts +1 -1
- package/types/lib/3.adapters/browser/sse-handler.d.ts +13 -0
- package/types/lib/3.adapters/storage/chunk.repository.d.ts +4 -0
- package/types/lib/4.config/logging/log.config.d.ts +1 -1
|
@@ -1281,7 +1281,7 @@ function createGetRemoteEntries(config, ports) {
|
|
|
1281
1281
|
return (remotesOrManifestUrl = {}) => ports.manifestProvider.provide(remotesOrManifestUrl).catch((e) => {
|
|
1282
1282
|
config.log.error(1, "Could not fetch manifest.", e);
|
|
1283
1283
|
return Promise.reject(new NFError("Failed to fetch manifest"));
|
|
1284
|
-
}).then(addHostRemoteEntry).then(fetchRemoteEntries).then(removeSkippedRemotes);
|
|
1284
|
+
}).then(addHostRemoteEntry).then(fetchRemoteEntries).then(removeSkippedRemotes).then(checkForSSE);
|
|
1285
1285
|
function addHostRemoteEntry(manifest) {
|
|
1286
1286
|
if (!config.hostRemoteEntry) return manifest;
|
|
1287
1287
|
const { name, url, cacheTag } = config.hostRemoteEntry;
|
|
@@ -1344,6 +1344,21 @@ function createGetRemoteEntries(config, ports) {
|
|
|
1344
1344
|
function removeSkippedRemotes(remoteEntries) {
|
|
1345
1345
|
return remoteEntries.filter((entry) => entry !== false);
|
|
1346
1346
|
}
|
|
1347
|
+
function checkForSSE(remoteEntries) {
|
|
1348
|
+
if (config.sse) {
|
|
1349
|
+
remoteEntries.forEach((entry) => {
|
|
1350
|
+
if (entry.buildNotificationsEndpoint) {
|
|
1351
|
+
ports.sse.watchRemoteBuilds(
|
|
1352
|
+
join(getScope(entry.url), entry.buildNotificationsEndpoint)
|
|
1353
|
+
);
|
|
1354
|
+
config.log.debug(1, `Registered SSE endpoint of remote '${entry.name}' `);
|
|
1355
|
+
return;
|
|
1356
|
+
}
|
|
1357
|
+
config.log.debug(1, `Remote ${entry.name} has no defined 'buildNotificationsEndpoint'`);
|
|
1358
|
+
});
|
|
1359
|
+
}
|
|
1360
|
+
return remoteEntries;
|
|
1361
|
+
}
|
|
1347
1362
|
}
|
|
1348
1363
|
|
|
1349
1364
|
// src/lib/2.app/flows/init/process-remote-entries.ts
|
|
@@ -1354,6 +1369,7 @@ function createProcessRemoteEntries(config, ports) {
|
|
|
1354
1369
|
if (remoteEntry?.override) removeCachedRemoteEntry(remoteEntry);
|
|
1355
1370
|
addRemoteInfoToStorage(remoteEntry);
|
|
1356
1371
|
addExternalsToStorage(remoteEntry);
|
|
1372
|
+
addSharedChunksToStorage(remoteEntry);
|
|
1357
1373
|
});
|
|
1358
1374
|
return Promise.resolve(remoteEntries);
|
|
1359
1375
|
} catch (e) {
|
|
@@ -1391,12 +1407,23 @@ function createProcessRemoteEntries(config, ports) {
|
|
|
1391
1407
|
}
|
|
1392
1408
|
});
|
|
1393
1409
|
}
|
|
1410
|
+
function addSharedChunksToStorage(remoteEntry) {
|
|
1411
|
+
if (!remoteEntry.chunks) return;
|
|
1412
|
+
config.log.debug(
|
|
1413
|
+
2,
|
|
1414
|
+
`Adding chunks for remote "${remoteEntry.name}", bundles: [${Object.keys(remoteEntry.chunks).join(", ")}]`
|
|
1415
|
+
);
|
|
1416
|
+
Object.entries(remoteEntry.chunks).forEach(([bundleName, chunks]) => {
|
|
1417
|
+
ports.sharedChunksRepo.addOrReplace(remoteEntry.name, bundleName, chunks);
|
|
1418
|
+
});
|
|
1419
|
+
}
|
|
1394
1420
|
function addSharedExternal(remoteName, sharedInfo, remoteEntry) {
|
|
1395
1421
|
let action = "skip";
|
|
1396
1422
|
const tag = sharedInfo.version ?? ports.versionCheck.smallestVersion(sharedInfo.requiredVersion);
|
|
1397
1423
|
const remote = {
|
|
1398
1424
|
file: sharedInfo.outFileName,
|
|
1399
1425
|
name: remoteName,
|
|
1426
|
+
bundle: sharedInfo.bundle,
|
|
1400
1427
|
strictVersion: sharedInfo.strictVersion,
|
|
1401
1428
|
cached: false,
|
|
1402
1429
|
requiredVersion: sharedInfo.requiredVersion || tag
|
|
@@ -1438,7 +1465,8 @@ function createProcessRemoteEntries(config, ports) {
|
|
|
1438
1465
|
function addScopedExternal(scope, sharedInfo) {
|
|
1439
1466
|
ports.scopedExternalsRepo.addExternal(scope, sharedInfo.packageName, {
|
|
1440
1467
|
tag: sharedInfo.version ?? ports.versionCheck.smallestVersion(sharedInfo.requiredVersion),
|
|
1441
|
-
file: sharedInfo.outFileName
|
|
1468
|
+
file: sharedInfo.outFileName,
|
|
1469
|
+
bundle: sharedInfo.bundle
|
|
1442
1470
|
});
|
|
1443
1471
|
}
|
|
1444
1472
|
}
|
|
@@ -1524,21 +1552,41 @@ function createDetermineSharedExternals(config, ports) {
|
|
|
1524
1552
|
}
|
|
1525
1553
|
}
|
|
1526
1554
|
|
|
1555
|
+
// node_modules/.pnpm/@softarc+native-federation@4.0.0-RC4_typescript@5.9.3_b0fd05590f82ec18d047413a60a6fe2a/node_modules/@softarc/native-federation/src/lib/domain/core/build-notification-options.contract.js
|
|
1556
|
+
var BuildNotificationType;
|
|
1557
|
+
(function(BuildNotificationType2) {
|
|
1558
|
+
BuildNotificationType2["COMPLETED"] = "federation-rebuild-complete";
|
|
1559
|
+
BuildNotificationType2["ERROR"] = "federation-rebuild-error";
|
|
1560
|
+
BuildNotificationType2["CANCELLED"] = "federation-rebuild-cancelled";
|
|
1561
|
+
})(BuildNotificationType || (BuildNotificationType = {}));
|
|
1562
|
+
|
|
1563
|
+
// node_modules/.pnpm/@softarc+native-federation@4.0.0-RC4_typescript@5.9.3_b0fd05590f82ec18d047413a60a6fe2a/node_modules/@softarc/native-federation/src/lib/domain/core/chunk.js
|
|
1564
|
+
var CHUNK_PREFIX = "@nf-internal";
|
|
1565
|
+
function toChunkImport(fileName) {
|
|
1566
|
+
if (fileName.startsWith("./")) {
|
|
1567
|
+
fileName = fileName.slice(2);
|
|
1568
|
+
}
|
|
1569
|
+
const packageName = fileName.replace(/.(m|c)?js$/, "");
|
|
1570
|
+
return CHUNK_PREFIX + "/" + packageName;
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1527
1573
|
// src/lib/2.app/flows/init/generate-import-map.ts
|
|
1528
1574
|
function createGenerateImportMap(config, ports) {
|
|
1529
1575
|
return () => {
|
|
1530
1576
|
const importMap = { imports: {} };
|
|
1577
|
+
const chunkBundles = {};
|
|
1531
1578
|
try {
|
|
1532
|
-
addScopedExternals(importMap);
|
|
1533
|
-
addshareScopeExternals(importMap);
|
|
1534
|
-
addGlobalSharedExternals(importMap);
|
|
1535
|
-
addRemoteInfos(importMap);
|
|
1579
|
+
addScopedExternals(importMap, chunkBundles);
|
|
1580
|
+
addshareScopeExternals(importMap, chunkBundles);
|
|
1581
|
+
addGlobalSharedExternals(importMap, chunkBundles);
|
|
1582
|
+
addRemoteInfos(importMap, chunkBundles);
|
|
1583
|
+
addChunkImports(importMap, chunkBundles);
|
|
1536
1584
|
return Promise.resolve(importMap);
|
|
1537
1585
|
} catch (e) {
|
|
1538
1586
|
return Promise.reject(e);
|
|
1539
1587
|
}
|
|
1540
1588
|
};
|
|
1541
|
-
function addScopedExternals(importMap) {
|
|
1589
|
+
function addScopedExternals(importMap, chunkBundles) {
|
|
1542
1590
|
const scopedExternals = ports.scopedExternalsRepo.getAll();
|
|
1543
1591
|
for (const [remoteName, externals] of Object.entries(scopedExternals)) {
|
|
1544
1592
|
const remote = ports.remoteInfoRepo.tryGet(remoteName).orThrow(() => {
|
|
@@ -1546,6 +1594,7 @@ function createGenerateImportMap(config, ports) {
|
|
|
1546
1594
|
return new NFError("Could not create ImportMap.");
|
|
1547
1595
|
});
|
|
1548
1596
|
addToScope(importMap, remote.scopeUrl, createScopeModules(externals, remote.scopeUrl));
|
|
1597
|
+
Object.values(externals).filter((e) => !!e.bundle).forEach((e) => registerBundleChunks(chunkBundles, remoteName, e.bundle));
|
|
1549
1598
|
}
|
|
1550
1599
|
return importMap;
|
|
1551
1600
|
}
|
|
@@ -1556,14 +1605,14 @@ function createGenerateImportMap(config, ports) {
|
|
|
1556
1605
|
}
|
|
1557
1606
|
return modules;
|
|
1558
1607
|
}
|
|
1559
|
-
function addshareScopeExternals(importMap) {
|
|
1608
|
+
function addshareScopeExternals(importMap, chunkBundles) {
|
|
1560
1609
|
const shareScopes = ports.sharedExternalsRepo.getScopes({ includeGlobal: false });
|
|
1561
1610
|
for (const shareScope of shareScopes) {
|
|
1562
|
-
processshareScope(importMap, shareScope);
|
|
1611
|
+
processshareScope(importMap, shareScope, chunkBundles);
|
|
1563
1612
|
}
|
|
1564
1613
|
return importMap;
|
|
1565
1614
|
}
|
|
1566
|
-
function processshareScope(importMap, shareScope) {
|
|
1615
|
+
function processshareScope(importMap, shareScope, chunkBundles) {
|
|
1567
1616
|
const sharedExternals = ports.sharedExternalsRepo.getFromScope(shareScope);
|
|
1568
1617
|
for (const [externalName, external] of Object.entries(sharedExternals)) {
|
|
1569
1618
|
let override = void 0;
|
|
@@ -1571,31 +1620,35 @@ function createGenerateImportMap(config, ports) {
|
|
|
1571
1620
|
for (const version of external.versions) {
|
|
1572
1621
|
if (version.action === "scope") {
|
|
1573
1622
|
for (const remote of version.remotes) {
|
|
1574
|
-
const remoteScope = getScope2(
|
|
1623
|
+
const remoteScope = getScope2(shareScope, remote.name, externalName);
|
|
1575
1624
|
addToScope(importMap, remoteScope, {
|
|
1576
1625
|
[externalName]: join(remoteScope, remote.file)
|
|
1577
1626
|
});
|
|
1627
|
+
registerBundleChunks(chunkBundles, remote.name, remote.bundle);
|
|
1578
1628
|
remote.cached = true;
|
|
1579
1629
|
}
|
|
1580
1630
|
continue;
|
|
1581
1631
|
}
|
|
1582
|
-
const scope = getScope2(
|
|
1632
|
+
const scope = getScope2(shareScope, version.remotes[0].name, externalName);
|
|
1583
1633
|
let targetFileUrl = join(scope, version.remotes[0].file);
|
|
1584
1634
|
version.remotes[0].cached = true;
|
|
1635
|
+
if (version.action === "share") {
|
|
1636
|
+
registerBundleChunks(chunkBundles, version.remotes[0].name, version.remotes[0].bundle);
|
|
1637
|
+
}
|
|
1585
1638
|
if (version.action === "skip") {
|
|
1586
1639
|
if (!override) {
|
|
1587
1640
|
override = findOverride(external, shareScope, externalName) ?? "NOT_AVAILABLE";
|
|
1588
1641
|
}
|
|
1589
1642
|
if (override !== "NOT_AVAILABLE") {
|
|
1590
1643
|
if (!overrideScope)
|
|
1591
|
-
overrideScope = getScope2(
|
|
1644
|
+
overrideScope = getScope2(shareScope, override.remotes[0].name, externalName);
|
|
1592
1645
|
targetFileUrl = join(overrideScope, override.remotes[0].file);
|
|
1593
1646
|
override.remotes[0].cached = true;
|
|
1594
1647
|
version.remotes[0].cached = false;
|
|
1595
1648
|
}
|
|
1596
1649
|
}
|
|
1597
1650
|
version.remotes.forEach((r) => {
|
|
1598
|
-
const scope2 = getScope2(
|
|
1651
|
+
const scope2 = getScope2(shareScope, r.name, externalName);
|
|
1599
1652
|
addToScope(importMap, scope2, { [externalName]: targetFileUrl });
|
|
1600
1653
|
});
|
|
1601
1654
|
}
|
|
@@ -1630,34 +1683,36 @@ function createGenerateImportMap(config, ports) {
|
|
|
1630
1683
|
}
|
|
1631
1684
|
config.log.warn(4, `ShareScope external ${scopedExternalName} has multiple shared versions.`);
|
|
1632
1685
|
}
|
|
1633
|
-
function addGlobalSharedExternals(importMap) {
|
|
1686
|
+
function addGlobalSharedExternals(importMap, chunkBundles) {
|
|
1634
1687
|
const sharedExternals = ports.sharedExternalsRepo.getFromScope();
|
|
1635
1688
|
for (const [externalName, external] of Object.entries(sharedExternals)) {
|
|
1636
1689
|
for (const version of external.versions) {
|
|
1637
1690
|
if (version.action === "skip") continue;
|
|
1638
1691
|
if (version.action === "scope") {
|
|
1639
1692
|
for (const remote of version.remotes) {
|
|
1640
|
-
const remoteScope = getScope2(
|
|
1693
|
+
const remoteScope = getScope2(GLOBAL_SCOPE, remote.name, externalName);
|
|
1641
1694
|
addToScope(importMap, remoteScope, {
|
|
1642
1695
|
[externalName]: join(remoteScope, remote.file)
|
|
1643
1696
|
});
|
|
1644
1697
|
remote.cached = true;
|
|
1698
|
+
registerBundleChunks(chunkBundles, remote.name, remote.bundle);
|
|
1645
1699
|
}
|
|
1646
1700
|
continue;
|
|
1647
1701
|
}
|
|
1648
1702
|
if (importMap.imports[externalName]) {
|
|
1649
|
-
|
|
1703
|
+
notifyDuplicateGlobalExternal(externalName);
|
|
1650
1704
|
continue;
|
|
1651
1705
|
}
|
|
1652
|
-
const scope = getScope2(
|
|
1706
|
+
const scope = getScope2(GLOBAL_SCOPE, version.remotes[0].name, externalName);
|
|
1653
1707
|
addToGlobal(importMap, { [externalName]: join(scope, version.remotes[0].file) });
|
|
1708
|
+
registerBundleChunks(chunkBundles, version.remotes[0].name, version.remotes[0].bundle);
|
|
1654
1709
|
version.remotes[0].cached = true;
|
|
1655
1710
|
}
|
|
1656
1711
|
ports.sharedExternalsRepo.addOrUpdate(externalName, external);
|
|
1657
1712
|
}
|
|
1658
1713
|
return importMap;
|
|
1659
1714
|
}
|
|
1660
|
-
function
|
|
1715
|
+
function notifyDuplicateGlobalExternal(externalName) {
|
|
1661
1716
|
if (config.strict.strictImportMap) {
|
|
1662
1717
|
config.log.error(4, `[${externalName}] Shared external has multiple shared versions.`);
|
|
1663
1718
|
throw new NFError("Could not create ImportMap.");
|
|
@@ -1672,10 +1727,11 @@ function createGenerateImportMap(config, ports) {
|
|
|
1672
1727
|
function addToGlobal(importMap, imports) {
|
|
1673
1728
|
importMap.imports = Object.assign(importMap.imports, imports);
|
|
1674
1729
|
}
|
|
1675
|
-
function addRemoteInfos(importMap) {
|
|
1730
|
+
function addRemoteInfos(importMap, chunkBundles) {
|
|
1676
1731
|
const remotes = ports.remoteInfoRepo.getAll();
|
|
1677
1732
|
for (const [remoteName, remote] of Object.entries(remotes)) {
|
|
1678
1733
|
addRemoteExposedModules(importMap, remoteName, remote);
|
|
1734
|
+
registerBundleChunks(chunkBundles, remoteName, "mapping-or-exposed");
|
|
1679
1735
|
}
|
|
1680
1736
|
}
|
|
1681
1737
|
function addRemoteExposedModules(importMap, remoteName, remote) {
|
|
@@ -1685,12 +1741,37 @@ function createGenerateImportMap(config, ports) {
|
|
|
1685
1741
|
importMap.imports[moduleName] = moduleUrl;
|
|
1686
1742
|
}
|
|
1687
1743
|
}
|
|
1688
|
-
function
|
|
1744
|
+
function registerBundleChunks(chunkBundles, remoteName, bundleName) {
|
|
1745
|
+
if (!bundleName) return chunkBundles;
|
|
1746
|
+
if (!chunkBundles[remoteName]) chunkBundles[remoteName] = /* @__PURE__ */ new Set();
|
|
1747
|
+
chunkBundles[remoteName].add(bundleName);
|
|
1748
|
+
return chunkBundles;
|
|
1749
|
+
}
|
|
1750
|
+
function addChunkImports(importMap, chunkBundles) {
|
|
1751
|
+
Object.entries(chunkBundles).forEach(([remoteName, bundles]) => {
|
|
1752
|
+
const baseUrl = getScope2("CHUNKS", remoteName);
|
|
1753
|
+
const imports = Array.from(bundles).reduce((_imports, bundleName) => {
|
|
1754
|
+
ports.sharedChunksRepo.tryGet(remoteName, bundleName).ifPresent((files) => {
|
|
1755
|
+
files.forEach((file) => {
|
|
1756
|
+
_imports[toChunkImport(file)] = join(baseUrl, file);
|
|
1757
|
+
});
|
|
1758
|
+
});
|
|
1759
|
+
return _imports;
|
|
1760
|
+
}, {});
|
|
1761
|
+
if (Object.keys(imports).length > 0) addToScope(importMap, baseUrl, imports);
|
|
1762
|
+
});
|
|
1763
|
+
return importMap;
|
|
1764
|
+
}
|
|
1765
|
+
function getScope2(ctx, remoteName, externalName) {
|
|
1689
1766
|
return ports.remoteInfoRepo.tryGet(remoteName).map((remote) => remote.scopeUrl).orThrow(() => {
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1767
|
+
if (externalName) {
|
|
1768
|
+
config.log.error(
|
|
1769
|
+
4,
|
|
1770
|
+
`[${ctx}][${externalName}][${remoteName}] Remote name not found in cache.`
|
|
1771
|
+
);
|
|
1772
|
+
} else {
|
|
1773
|
+
config.log.error(4, `[${ctx}][${remoteName}] Remote name not found in cache.`);
|
|
1774
|
+
}
|
|
1694
1775
|
return new NFError("Could not create ImportMap.");
|
|
1695
1776
|
});
|
|
1696
1777
|
}
|
|
@@ -1708,6 +1789,7 @@ function createCommitChanges(config, ports) {
|
|
|
1708
1789
|
ports.remoteInfoRepo.commit();
|
|
1709
1790
|
ports.scopedExternalsRepo.commit();
|
|
1710
1791
|
ports.sharedExternalsRepo.commit();
|
|
1792
|
+
ports.sharedChunksRepo.commit();
|
|
1711
1793
|
return;
|
|
1712
1794
|
}
|
|
1713
1795
|
}
|
|
@@ -2016,6 +2098,68 @@ var createSharedExternalsRepository = (config) => {
|
|
|
2016
2098
|
};
|
|
2017
2099
|
};
|
|
2018
2100
|
|
|
2101
|
+
// src/lib/3.adapters/browser/sse-handler.ts
|
|
2102
|
+
var createSSEHandler = (config) => {
|
|
2103
|
+
const subscribers = [];
|
|
2104
|
+
return {
|
|
2105
|
+
watchRemoteBuilds: function(endpoint) {
|
|
2106
|
+
const eventSource = new EventSource(endpoint);
|
|
2107
|
+
eventSource.onmessage = function(event) {
|
|
2108
|
+
const data = JSON.parse(event.data);
|
|
2109
|
+
if (data.type === BuildNotificationType.COMPLETED) {
|
|
2110
|
+
subscribers.forEach((sub) => sub.close());
|
|
2111
|
+
config.log.debug(0, "[SSE] Rebuild completed, reloading...");
|
|
2112
|
+
config.reloadBrowserFn();
|
|
2113
|
+
}
|
|
2114
|
+
};
|
|
2115
|
+
eventSource.onerror = function(event) {
|
|
2116
|
+
config.log.error(0, "[SSE] Connection error:", event);
|
|
2117
|
+
};
|
|
2118
|
+
subscribers.push(eventSource);
|
|
2119
|
+
},
|
|
2120
|
+
closeAll: function() {
|
|
2121
|
+
subscribers.forEach((sub) => sub.close());
|
|
2122
|
+
subscribers.length = 0;
|
|
2123
|
+
}
|
|
2124
|
+
};
|
|
2125
|
+
};
|
|
2126
|
+
|
|
2127
|
+
// src/lib/utils/clone-entry.ts
|
|
2128
|
+
var cloneEntry = (name, raw) => {
|
|
2129
|
+
try {
|
|
2130
|
+
if (typeof structuredClone === "function") {
|
|
2131
|
+
return structuredClone(raw);
|
|
2132
|
+
}
|
|
2133
|
+
} catch {
|
|
2134
|
+
}
|
|
2135
|
+
try {
|
|
2136
|
+
return JSON.parse(JSON.stringify(raw));
|
|
2137
|
+
} catch {
|
|
2138
|
+
}
|
|
2139
|
+
throw new NFError(`Could not parse storage entry '${String(name)}'`);
|
|
2140
|
+
};
|
|
2141
|
+
|
|
2142
|
+
// src/lib/3.adapters/storage/chunk.repository.ts
|
|
2143
|
+
var createChunkRepository = (config) => {
|
|
2144
|
+
const STORAGE = config.storage("shared-chunks", {});
|
|
2145
|
+
if (config.clearStorage) STORAGE.clear();
|
|
2146
|
+
const _cache = STORAGE.get() ?? {};
|
|
2147
|
+
return {
|
|
2148
|
+
addOrReplace: function(remoteName, bundleName, chunks) {
|
|
2149
|
+
if (!_cache[remoteName]) _cache[remoteName] = {};
|
|
2150
|
+
_cache[remoteName][bundleName] = chunks;
|
|
2151
|
+
return this;
|
|
2152
|
+
},
|
|
2153
|
+
tryGet: function(remoteName, bundleName) {
|
|
2154
|
+
return Optional.of(_cache[remoteName]?.[bundleName]);
|
|
2155
|
+
},
|
|
2156
|
+
commit: function() {
|
|
2157
|
+
STORAGE.set(_cache);
|
|
2158
|
+
return this;
|
|
2159
|
+
}
|
|
2160
|
+
};
|
|
2161
|
+
};
|
|
2162
|
+
|
|
2019
2163
|
// src/lib/5.di/driving.factory.ts
|
|
2020
2164
|
var createDriving = (config) => {
|
|
2021
2165
|
const adapters = {
|
|
@@ -2025,7 +2169,9 @@ var createDriving = (config) => {
|
|
|
2025
2169
|
remoteInfoRepo: createRemoteInfoRepository(config),
|
|
2026
2170
|
scopedExternalsRepo: createScopedExternalsRepository(config),
|
|
2027
2171
|
sharedExternalsRepo: createSharedExternalsRepository(config),
|
|
2028
|
-
|
|
2172
|
+
sharedChunksRepo: createChunkRepository(config),
|
|
2173
|
+
browser: createBrowser(config),
|
|
2174
|
+
sse: createSSEHandler(config)
|
|
2029
2175
|
};
|
|
2030
2176
|
return { adapters, config };
|
|
2031
2177
|
};
|
|
@@ -2050,7 +2196,10 @@ var useDefaultImportMap = () => ({
|
|
|
2050
2196
|
/* @vite-ignore */
|
|
2051
2197
|
url
|
|
2052
2198
|
),
|
|
2053
|
-
setImportMapFn: replaceInDOM("importmap")
|
|
2199
|
+
setImportMapFn: replaceInDOM("importmap"),
|
|
2200
|
+
reloadBrowserFn: () => {
|
|
2201
|
+
window.location.reload();
|
|
2202
|
+
}
|
|
2054
2203
|
});
|
|
2055
2204
|
|
|
2056
2205
|
// src/lib/4.config/import-map/import-map.config.ts
|
|
@@ -2058,7 +2207,8 @@ var createImportMapConfig = (o) => {
|
|
|
2058
2207
|
const fallback = useDefaultImportMap();
|
|
2059
2208
|
return {
|
|
2060
2209
|
setImportMapFn: o.setImportMapFn ?? fallback.setImportMapFn,
|
|
2061
|
-
loadModuleFn: o.loadModuleFn ?? fallback.loadModuleFn
|
|
2210
|
+
loadModuleFn: o.loadModuleFn ?? fallback.loadModuleFn,
|
|
2211
|
+
reloadBrowserFn: o.reloadBrowserFn ?? fallback.reloadBrowserFn
|
|
2062
2212
|
};
|
|
2063
2213
|
};
|
|
2064
2214
|
|
|
@@ -2119,25 +2269,11 @@ var createLogHandler = (logger, logLevel) => {
|
|
|
2119
2269
|
};
|
|
2120
2270
|
|
|
2121
2271
|
// src/lib/4.config/logging/log.config.ts
|
|
2122
|
-
var createLogConfig = ({ logger, logLevel }) => ({
|
|
2123
|
-
log: createLogHandler(logger ?? noopLogger, logLevel ?? "error")
|
|
2272
|
+
var createLogConfig = ({ logger, logLevel, sse }) => ({
|
|
2273
|
+
log: createLogHandler(logger ?? noopLogger, logLevel ?? "error"),
|
|
2274
|
+
sse: !!sse
|
|
2124
2275
|
});
|
|
2125
2276
|
|
|
2126
|
-
// src/lib/utils/clone-entry.ts
|
|
2127
|
-
var cloneEntry = (name, raw) => {
|
|
2128
|
-
try {
|
|
2129
|
-
if (typeof structuredClone === "function") {
|
|
2130
|
-
return structuredClone(raw);
|
|
2131
|
-
}
|
|
2132
|
-
} catch {
|
|
2133
|
-
}
|
|
2134
|
-
try {
|
|
2135
|
-
return JSON.parse(JSON.stringify(raw));
|
|
2136
|
-
} catch {
|
|
2137
|
-
}
|
|
2138
|
-
throw new NFError(`Could not parse storage entry '${String(name)}'`);
|
|
2139
|
-
};
|
|
2140
|
-
|
|
2141
2277
|
// src/lib/4.config/storage/global-this.storage.ts
|
|
2142
2278
|
var globalThisStorageEntry = (namespace) => (key, initialValue) => {
|
|
2143
2279
|
if (!globalThis[namespace]) {
|
|
@@ -2203,7 +2339,7 @@ var createConfigHandlers = (overrides) => ({
|
|
|
2203
2339
|
});
|
|
2204
2340
|
|
|
2205
2341
|
// src/lib/2.app/flows/dynamic-init/convert-to-import-map.ts
|
|
2206
|
-
function createConvertToImportMap({ log }) {
|
|
2342
|
+
function createConvertToImportMap({ log }, ports) {
|
|
2207
2343
|
return ({ entry, actions }) => {
|
|
2208
2344
|
const importMap = { imports: {} };
|
|
2209
2345
|
addExternals(entry, actions, importMap);
|
|
@@ -2216,6 +2352,7 @@ function createConvertToImportMap({ log }) {
|
|
|
2216
2352
|
return;
|
|
2217
2353
|
}
|
|
2218
2354
|
const remoteEntryScope = getScope(remoteEntry.url);
|
|
2355
|
+
const chunkBundles = /* @__PURE__ */ new Set(["mapping-or-exposed"]);
|
|
2219
2356
|
remoteEntry.shared.forEach((external) => {
|
|
2220
2357
|
if (!external.singleton) {
|
|
2221
2358
|
addToScopes(
|
|
@@ -2224,6 +2361,7 @@ function createConvertToImportMap({ log }) {
|
|
|
2224
2361
|
join(remoteEntryScope, external.outFileName),
|
|
2225
2362
|
importMap
|
|
2226
2363
|
);
|
|
2364
|
+
if (external?.bundle) chunkBundles.add(external?.bundle);
|
|
2227
2365
|
return;
|
|
2228
2366
|
}
|
|
2229
2367
|
if (!actions[external.packageName]) {
|
|
@@ -2245,6 +2383,7 @@ function createConvertToImportMap({ log }) {
|
|
|
2245
2383
|
return;
|
|
2246
2384
|
}
|
|
2247
2385
|
}
|
|
2386
|
+
if (external?.bundle) chunkBundles.add(external?.bundle);
|
|
2248
2387
|
if (actions[external.packageName].action === "scope") {
|
|
2249
2388
|
addToScopes(
|
|
2250
2389
|
remoteEntryScope,
|
|
@@ -2265,6 +2404,7 @@ function createConvertToImportMap({ log }) {
|
|
|
2265
2404
|
}
|
|
2266
2405
|
importMap.imports[external.packageName] = join(remoteEntryScope, external.outFileName);
|
|
2267
2406
|
});
|
|
2407
|
+
addChunkImports(importMap, remoteEntry.name, remoteEntryScope, chunkBundles);
|
|
2268
2408
|
}
|
|
2269
2409
|
function addToScopes(scope, packageName, url, importMap) {
|
|
2270
2410
|
if (!importMap.scopes) importMap.scopes = {};
|
|
@@ -2280,6 +2420,21 @@ function createConvertToImportMap({ log }) {
|
|
|
2280
2420
|
importMap.imports[moduleName] = moduleUrl;
|
|
2281
2421
|
});
|
|
2282
2422
|
}
|
|
2423
|
+
function addChunkImports(importMap, remoteName, remoteEntryScope, chunkBundles) {
|
|
2424
|
+
Array.from(chunkBundles).forEach((bundleName) => {
|
|
2425
|
+
ports.sharedChunksRepo.tryGet(remoteName, bundleName).ifPresent((files) => {
|
|
2426
|
+
files.forEach((file) => {
|
|
2427
|
+
addToScopes(
|
|
2428
|
+
remoteEntryScope,
|
|
2429
|
+
toChunkImport(file),
|
|
2430
|
+
join(remoteEntryScope, file),
|
|
2431
|
+
importMap
|
|
2432
|
+
);
|
|
2433
|
+
});
|
|
2434
|
+
});
|
|
2435
|
+
});
|
|
2436
|
+
return importMap;
|
|
2437
|
+
}
|
|
2283
2438
|
}
|
|
2284
2439
|
|
|
2285
2440
|
// src/lib/2.app/flows/dynamic-init/get-remote-entry.ts
|
|
@@ -2307,7 +2462,7 @@ function createGetRemoteEntry(config, ports) {
|
|
|
2307
2462
|
remoteEntry.override = true;
|
|
2308
2463
|
config.log.debug(7, `Overriding existing remote '${remoteName}' with '${remoteEntryUrl}'.`);
|
|
2309
2464
|
}
|
|
2310
|
-
return Optional.of(remoteEntry);
|
|
2465
|
+
return Optional.of(checkForSSE(remoteEntry));
|
|
2311
2466
|
} catch (error) {
|
|
2312
2467
|
config.log.error(
|
|
2313
2468
|
7,
|
|
@@ -2324,6 +2479,19 @@ function createGetRemoteEntry(config, ports) {
|
|
|
2324
2479
|
(cachedRemoteInfo) => config.profile.overrideCachedRemotes !== "always" || !config.profile.overrideCachedRemotesIfURLMatches && remoteEntryUrl === join(cachedRemoteInfo.scopeUrl, "remoteEntry.json")
|
|
2325
2480
|
).orElse(false);
|
|
2326
2481
|
}
|
|
2482
|
+
function checkForSSE(entry) {
|
|
2483
|
+
if (config.sse) {
|
|
2484
|
+
if (entry.buildNotificationsEndpoint) {
|
|
2485
|
+
ports.sse.watchRemoteBuilds(
|
|
2486
|
+
join(getScope(entry.url), entry.buildNotificationsEndpoint)
|
|
2487
|
+
);
|
|
2488
|
+
config.log.debug(7, `Registered SSE endpoint of remote '${entry.name}' `);
|
|
2489
|
+
} else {
|
|
2490
|
+
config.log.debug(7, `Remote ${entry.name} has no defined 'buildNotificationsEndpoint'`);
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
return entry;
|
|
2494
|
+
}
|
|
2327
2495
|
}
|
|
2328
2496
|
|
|
2329
2497
|
// src/lib/2.app/flows/dynamic-init/update-cache.ts
|
|
@@ -2333,6 +2501,7 @@ function createUpdateCache(config, ports) {
|
|
|
2333
2501
|
if (remoteEntry?.override) removeCachedRemoteEntry(remoteEntry);
|
|
2334
2502
|
addRemoteInfoToStorage(remoteEntry);
|
|
2335
2503
|
const actions = mergeExternalsIntoStorage(remoteEntry);
|
|
2504
|
+
addSharedChunksToStorage(remoteEntry);
|
|
2336
2505
|
return Promise.resolve({ entry: remoteEntry, actions });
|
|
2337
2506
|
} catch (error) {
|
|
2338
2507
|
return Promise.reject(error);
|
|
@@ -2383,6 +2552,16 @@ function createUpdateCache(config, ports) {
|
|
|
2383
2552
|
});
|
|
2384
2553
|
return actions;
|
|
2385
2554
|
}
|
|
2555
|
+
function addSharedChunksToStorage(remoteEntry) {
|
|
2556
|
+
if (!remoteEntry.chunks) return;
|
|
2557
|
+
config.log.debug(
|
|
2558
|
+
8,
|
|
2559
|
+
`Adding chunks for remote "${remoteEntry.name}", bundles: [${Object.keys(remoteEntry.chunks).join(", ")}]`
|
|
2560
|
+
);
|
|
2561
|
+
Object.entries(remoteEntry.chunks).forEach(([bundleName, chunks]) => {
|
|
2562
|
+
ports.sharedChunksRepo.addOrReplace(remoteEntry.name, bundleName, chunks);
|
|
2563
|
+
});
|
|
2564
|
+
}
|
|
2386
2565
|
function addSharedExternal(remoteName, sharedInfo) {
|
|
2387
2566
|
const cached = ports.sharedExternalsRepo.tryGet(sharedInfo.packageName, sharedInfo.shareScope).orElse({ dirty: false, versions: [] });
|
|
2388
2567
|
let action = "skip";
|
|
@@ -2392,6 +2571,7 @@ function createUpdateCache(config, ports) {
|
|
|
2392
2571
|
strictVersion: sharedInfo.strictVersion,
|
|
2393
2572
|
requiredVersion: sharedInfo.requiredVersion || tag,
|
|
2394
2573
|
name: remoteName,
|
|
2574
|
+
bundle: sharedInfo.bundle,
|
|
2395
2575
|
cached: false
|
|
2396
2576
|
};
|
|
2397
2577
|
const scopeType = ports.sharedExternalsRepo.scopeType(sharedInfo.shareScope);
|
|
@@ -2439,7 +2619,8 @@ function createUpdateCache(config, ports) {
|
|
|
2439
2619
|
function addScopedExternal(remoteName, sharedInfo) {
|
|
2440
2620
|
ports.scopedExternalsRepo.addExternal(remoteName, sharedInfo.packageName, {
|
|
2441
2621
|
tag: sharedInfo.version ?? ports.versionCheck.smallestVersion(sharedInfo.requiredVersion),
|
|
2442
|
-
file: sharedInfo.outFileName
|
|
2622
|
+
file: sharedInfo.outFileName,
|
|
2623
|
+
bundle: sharedInfo.bundle
|
|
2443
2624
|
});
|
|
2444
2625
|
}
|
|
2445
2626
|
}
|
|
@@ -2451,7 +2632,7 @@ var createDynamicInitDrivers = ({
|
|
|
2451
2632
|
}) => ({
|
|
2452
2633
|
getRemoteEntry: createGetRemoteEntry(config, adapters),
|
|
2453
2634
|
updateCache: createUpdateCache(config, adapters),
|
|
2454
|
-
convertToImportMap: createConvertToImportMap(config),
|
|
2635
|
+
convertToImportMap: createConvertToImportMap(config, adapters),
|
|
2455
2636
|
commitChanges: createCommitChanges(config, adapters)
|
|
2456
2637
|
});
|
|
2457
2638
|
var DYNAMIC_INIT_FLOW_FACTORY = ({
|