@softarc/native-federation 4.1.3 → 4.2.0
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/LICENSE.md +7 -0
- package/README.md +638 -0
- package/dist/config.js +17 -0
- package/dist/domain.js +2 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +21 -0
- package/{src → dist}/internal.d.ts +6 -7
- package/dist/internal.js +26 -0
- package/dist/lib/config/configuration-context.js +15 -0
- package/dist/lib/config/default-skip-list.js +36 -0
- package/dist/lib/config/get-external-imports.d.ts +2 -0
- package/dist/lib/config/get-external-imports.js +60 -0
- package/dist/lib/config/get-used-dependencies.d.ts +24 -0
- package/dist/lib/config/get-used-dependencies.js +126 -0
- package/{src/lib/utils → dist/lib/config}/mapped-paths.d.ts +2 -2
- package/dist/lib/config/mapped-paths.js +31 -0
- package/dist/lib/config/remove-unused-deps.js +11 -0
- package/dist/lib/config/share-utils.d.ts +20 -0
- package/dist/lib/config/share-utils.js +344 -0
- package/dist/lib/config/with-native-federation.js +80 -0
- package/{src/lib/core → dist/lib/core/build}/build-adapter.d.ts +1 -1
- package/dist/lib/core/build/build-adapter.js +16 -0
- package/dist/lib/core/build/build-for-federation.d.ts +4 -0
- package/dist/lib/core/build/build-for-federation.js +207 -0
- package/{src/lib/utils → dist/lib/core/build}/build-result-map.d.ts +1 -1
- package/dist/lib/core/build/build-result-map.js +39 -0
- package/dist/lib/core/build/bundle-exposed-and-mappings.d.ts +13 -0
- package/dist/lib/core/build/bundle-exposed-and-mappings.js +178 -0
- package/dist/lib/core/build/bundle-shared.d.ts +34 -0
- package/dist/lib/core/build/bundle-shared.js +261 -0
- package/dist/lib/core/build/compute-integrity.d.ts +11 -0
- package/dist/lib/core/build/compute-integrity.js +20 -0
- package/dist/lib/core/build/default-external-list.js +32 -0
- package/dist/lib/core/build/get-externals.d.ts +2 -0
- package/dist/lib/core/build/get-externals.js +9 -0
- package/dist/lib/core/build/rebuild-for-federation.d.ts +4 -0
- package/dist/lib/core/build/rebuild-for-federation.js +52 -0
- package/dist/lib/core/build/rewrite-chunk-imports.d.ts +5 -0
- package/dist/lib/core/build/rewrite-chunk-imports.js +74 -0
- package/dist/lib/core/cache/cache-persistence.d.ts +22 -0
- package/dist/lib/core/cache/cache-persistence.js +63 -0
- package/{src/lib/core → dist/lib/core/cache}/federation-cache.d.ts +2 -2
- package/dist/lib/core/cache/federation-cache.js +22 -0
- package/dist/lib/core/federation-builder.js +53 -0
- package/{src → dist}/lib/core/normalize-options.d.ts +13 -1
- package/dist/lib/core/normalize-options.js +67 -0
- package/dist/lib/core/output/write-federation-info.d.ts +5 -0
- package/dist/lib/core/output/write-federation-info.js +17 -0
- package/dist/lib/core/output/write-import-map.d.ts +11 -0
- package/dist/lib/core/output/write-import-map.js +42 -0
- package/dist/lib/core/rebuild-queue.js +61 -0
- package/{src → dist}/lib/domain/config/external-config.contract.d.ts +2 -2
- package/dist/lib/domain/config/external-config.contract.js +0 -0
- package/dist/lib/domain/config/federation-config.contract.js +0 -0
- package/dist/lib/domain/config/index.js +0 -0
- package/dist/lib/domain/config/skip-list.contract.js +0 -0
- package/dist/lib/domain/core/build-adapter.contract.js +0 -0
- package/dist/lib/domain/core/build-notification-options.contract.js +9 -0
- package/dist/lib/domain/core/chunk.js +12 -0
- package/dist/lib/domain/core/federation-cache.contract.js +0 -0
- package/dist/lib/domain/core/federation-info.contract.js +0 -0
- package/dist/lib/domain/core/federation-options.contract.js +0 -0
- package/dist/lib/domain/core/index.js +9 -0
- package/dist/lib/domain/core/manifest.contract.js +0 -0
- package/dist/lib/domain/utils/file-watcher.contract.js +0 -0
- package/dist/lib/domain/utils/io-port.contract.d.ts +45 -0
- package/dist/lib/domain/utils/io-port.contract.js +0 -0
- package/dist/lib/domain/utils/keyvaluepair.contract.js +0 -0
- package/dist/lib/domain/utils/mapped-path.contract.js +0 -0
- package/dist/lib/domain/utils/package-json.contract.d.ts +27 -0
- package/dist/lib/domain/utils/package-json.contract.js +0 -0
- package/dist/lib/domain/utils/used-dependencies.contract.js +0 -0
- package/dist/lib/utils/errors.js +10 -0
- package/{src → dist}/lib/utils/file-watcher.d.ts +2 -0
- package/dist/lib/utils/file-watcher.js +51 -0
- package/dist/lib/utils/hash-file.d.ts +7 -0
- package/dist/lib/utils/hash-file.js +15 -0
- package/dist/lib/utils/io/node-io-adapter.d.ts +2 -0
- package/dist/lib/utils/io/node-io-adapter.js +68 -0
- package/dist/lib/utils/io/package-json-repository.d.ts +5 -0
- package/dist/lib/utils/io/package-json-repository.js +79 -0
- package/dist/lib/utils/logger.js +29 -0
- package/dist/lib/utils/normalize.js +22 -0
- package/dist/lib/utils/package/entry-point-resolver.d.ts +2 -0
- package/dist/lib/utils/package/entry-point-resolver.js +78 -0
- package/dist/lib/utils/package/esm-detection.d.ts +5 -0
- package/dist/lib/utils/package/esm-detection.js +10 -0
- package/dist/lib/utils/package/exports-resolver.d.ts +13 -0
- package/dist/lib/utils/package/exports-resolver.js +55 -0
- package/dist/lib/utils/package/package-info.d.ts +7 -0
- package/dist/lib/utils/package/package-info.js +31 -0
- package/dist/lib/utils/package/resolve-wildcard-keys.d.ts +3 -0
- package/dist/lib/utils/package/resolve-wildcard-keys.js +22 -0
- package/dist/lib/utils/package/version-maps.d.ts +3 -0
- package/dist/lib/utils/package/version-maps.js +8 -0
- package/dist/lib/utils/path-patterns.d.ts +14 -0
- package/dist/lib/utils/path-patterns.js +28 -0
- package/package.json +45 -22
- package/src/config.js +0 -4
- package/src/domain.js +0 -2
- package/src/index.d.ts +0 -10
- package/src/index.js +0 -10
- package/src/internal.js +0 -11
- package/src/lib/config/configuration-context.js +0 -10
- package/src/lib/config/default-skip-list.js +0 -31
- package/src/lib/config/remove-unused-deps.js +0 -10
- package/src/lib/config/share-utils.d.ts +0 -10
- package/src/lib/config/share-utils.js +0 -302
- package/src/lib/config/with-native-federation.js +0 -79
- package/src/lib/core/build-adapter.js +0 -12
- package/src/lib/core/build-for-federation.d.ts +0 -4
- package/src/lib/core/build-for-federation.js +0 -173
- package/src/lib/core/bundle-exposed-and-mappings.d.ts +0 -7
- package/src/lib/core/bundle-exposed-and-mappings.js +0 -177
- package/src/lib/core/bundle-shared.d.ts +0 -13
- package/src/lib/core/bundle-shared.js +0 -222
- package/src/lib/core/default-external-list.js +0 -29
- package/src/lib/core/federation-builder.js +0 -45
- package/src/lib/core/federation-cache.js +0 -16
- package/src/lib/core/get-externals.d.ts +0 -2
- package/src/lib/core/get-externals.js +0 -6
- package/src/lib/core/normalize-options.js +0 -58
- package/src/lib/core/rebuild-for-federation.d.ts +0 -4
- package/src/lib/core/rebuild-for-federation.js +0 -43
- package/src/lib/core/write-federation-info.d.ts +0 -3
- package/src/lib/core/write-federation-info.js +0 -6
- package/src/lib/core/write-import-map.d.ts +0 -6
- package/src/lib/core/write-import-map.js +0 -33
- package/src/lib/domain/config/external-config.contract.js +0 -1
- package/src/lib/domain/config/federation-config.contract.js +0 -1
- package/src/lib/domain/config/index.js +0 -1
- package/src/lib/domain/config/skip-list.contract.js +0 -1
- package/src/lib/domain/config/with-native-federation.contract.d.ts +0 -2
- package/src/lib/domain/config/with-native-federation.contract.js +0 -1
- package/src/lib/domain/core/build-adapter.contract.js +0 -1
- package/src/lib/domain/core/build-notification-options.contract.js +0 -6
- package/src/lib/domain/core/chunk.js +0 -8
- package/src/lib/domain/core/federation-cache.contract.js +0 -1
- package/src/lib/domain/core/federation-info.contract.js +0 -1
- package/src/lib/domain/core/federation-options.contract.js +0 -1
- package/src/lib/domain/core/index.js +0 -2
- package/src/lib/domain/core/manifest.contract.js +0 -1
- package/src/lib/domain/utils/file-watcher.contract.js +0 -1
- package/src/lib/domain/utils/index.d.ts +0 -2
- package/src/lib/domain/utils/index.js +0 -1
- package/src/lib/domain/utils/keyvaluepair.contract.js +0 -1
- package/src/lib/domain/utils/mapped-path.contract.js +0 -5
- package/src/lib/domain/utils/used-dependencies.contract.js +0 -1
- package/src/lib/utils/build-result-map.js +0 -29
- package/src/lib/utils/cache-persistence.d.ts +0 -19
- package/src/lib/utils/cache-persistence.js +0 -66
- package/src/lib/utils/errors.js +0 -7
- package/src/lib/utils/file-watcher.js +0 -51
- package/src/lib/utils/get-external-imports.d.ts +0 -1
- package/src/lib/utils/get-external-imports.js +0 -80
- package/src/lib/utils/get-used-dependencies.d.ts +0 -8
- package/src/lib/utils/get-used-dependencies.js +0 -123
- package/src/lib/utils/hash-file.d.ts +0 -3
- package/src/lib/utils/hash-file.js +0 -13
- package/src/lib/utils/logger.js +0 -27
- package/src/lib/utils/mapped-paths.js +0 -33
- package/src/lib/utils/normalize.js +0 -17
- package/src/lib/utils/package-info.d.ts +0 -30
- package/src/lib/utils/package-info.js +0 -268
- package/src/lib/utils/rebuild-queue.js +0 -63
- package/src/lib/utils/resolve-glob.d.ts +0 -1
- package/src/lib/utils/resolve-glob.js +0 -29
- package/src/lib/utils/resolve-wildcard-keys.d.ts +0 -29
- package/src/lib/utils/resolve-wildcard-keys.js +0 -126
- package/src/lib/utils/rewrite-chunk-imports.d.ts +0 -2
- package/src/lib/utils/rewrite-chunk-imports.js +0 -48
- /package/{src → dist}/config.d.ts +0 -0
- /package/{src → dist}/domain.d.ts +0 -0
- /package/{src → dist}/lib/config/configuration-context.d.ts +0 -0
- /package/{src → dist}/lib/config/default-skip-list.d.ts +0 -0
- /package/{src → dist}/lib/config/remove-unused-deps.d.ts +0 -0
- /package/{src → dist}/lib/config/with-native-federation.d.ts +0 -0
- /package/{src/lib/core → dist/lib/core/build}/default-external-list.d.ts +0 -0
- /package/{src → dist}/lib/core/federation-builder.d.ts +0 -0
- /package/{src/lib/utils → dist/lib/core}/rebuild-queue.d.ts +0 -0
- /package/{src → dist}/lib/domain/config/federation-config.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/config/index.d.ts +0 -0
- /package/{src → dist}/lib/domain/config/skip-list.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/core/build-adapter.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/core/build-notification-options.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/core/chunk.d.ts +0 -0
- /package/{src → dist}/lib/domain/core/federation-cache.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/core/federation-info.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/core/federation-options.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/core/index.d.ts +0 -0
- /package/{src → dist}/lib/domain/core/manifest.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/utils/file-watcher.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/utils/keyvaluepair.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/utils/mapped-path.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/utils/used-dependencies.contract.d.ts +0 -0
- /package/{src → dist}/lib/utils/errors.d.ts +0 -0
- /package/{src → dist}/lib/utils/logger.d.ts +0 -0
- /package/{src → dist}/lib/utils/normalize.d.ts +0 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import { cwd } from "process";
|
|
3
|
+
import { DEFAULT_SKIP_LIST, isInSkipList, prepareSkipList } from "./default-skip-list.js";
|
|
4
|
+
import {
|
|
5
|
+
sharedPackageJsonRepository,
|
|
6
|
+
findDepPackageJson,
|
|
7
|
+
getVersionMaps
|
|
8
|
+
} from "../utils/package/package-info.js";
|
|
9
|
+
import { getConfigContext } from "./configuration-context.js";
|
|
10
|
+
import { logger } from "../utils/logger.js";
|
|
11
|
+
import { nodeIo } from "../utils/io/node-io-adapter.js";
|
|
12
|
+
import { resolvePackageJsonExportsWildcardCore } from "../utils/package/resolve-wildcard-keys.js";
|
|
13
|
+
let inferVersion = false;
|
|
14
|
+
function findRootTsConfigJson() {
|
|
15
|
+
return findRootTsConfigJsonCore(nodeIo);
|
|
16
|
+
}
|
|
17
|
+
function findRootTsConfigJsonCore(io) {
|
|
18
|
+
const packageJson = findPackageJson(io, cwd());
|
|
19
|
+
const projectRoot = path.dirname(packageJson);
|
|
20
|
+
const tsConfigBaseJson = path.join(projectRoot, "tsconfig.base.json");
|
|
21
|
+
const tsConfigJson = path.join(projectRoot, "tsconfig.json");
|
|
22
|
+
if (io.exists(tsConfigBaseJson)) {
|
|
23
|
+
return tsConfigBaseJson;
|
|
24
|
+
} else if (io.exists(tsConfigJson)) {
|
|
25
|
+
return tsConfigJson;
|
|
26
|
+
}
|
|
27
|
+
throw new Error("Neither a tsconfig.json nor a tsconfig.base.json was found");
|
|
28
|
+
}
|
|
29
|
+
function findPackageJson(io, folder) {
|
|
30
|
+
while (!io.exists(path.join(folder, "package.json")) && path.dirname(folder) !== folder) {
|
|
31
|
+
folder = path.dirname(folder);
|
|
32
|
+
}
|
|
33
|
+
const filePath = path.join(folder, "package.json");
|
|
34
|
+
if (io.exists(filePath)) {
|
|
35
|
+
return filePath;
|
|
36
|
+
}
|
|
37
|
+
throw new Error(
|
|
38
|
+
"no package.json found. Searched the following folder and all parents: " + folder
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
function lookupVersion(key, workspaceRoot, repo) {
|
|
42
|
+
const versionMaps = getVersionMaps(workspaceRoot, workspaceRoot, repo);
|
|
43
|
+
for (const versionMap of versionMaps) {
|
|
44
|
+
const version = lookupVersionInMap(key, versionMap);
|
|
45
|
+
if (version) {
|
|
46
|
+
return version;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Shared Dependency ${key} has requiredVersion:'auto'. However, this dependency is not found in your package.json`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
function lookupVersionInMap(key, versions) {
|
|
54
|
+
const parts = key.split("/");
|
|
55
|
+
if (parts.length >= 2 && parts[0].startsWith("@")) {
|
|
56
|
+
key = parts[0] + "/" + parts[1];
|
|
57
|
+
} else {
|
|
58
|
+
key = parts[0];
|
|
59
|
+
}
|
|
60
|
+
if (!versions[key]) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return versions[key];
|
|
64
|
+
}
|
|
65
|
+
function _findSecondaries(io, libPath, excludes, shareObject, acc, preparedSkipList) {
|
|
66
|
+
const files = io.readDir(libPath);
|
|
67
|
+
const secondaries = files.map((f) => path.join(libPath, f)).filter((f) => io.isDirectory(f) && !f.endsWith("node_modules"));
|
|
68
|
+
for (const s of secondaries) {
|
|
69
|
+
if (io.exists(path.join(s, "package.json"))) {
|
|
70
|
+
const secondaryLibName = s.replace(/\\/g, "/").replace(/^.*node_modules[/]/, "");
|
|
71
|
+
const inCustomSkipList = excludes.some(
|
|
72
|
+
(e) => e === secondaryLibName || e.endsWith("*") && secondaryLibName.startsWith(e.slice(0, -1))
|
|
73
|
+
);
|
|
74
|
+
if (inCustomSkipList) continue;
|
|
75
|
+
if (isInSkipList(secondaryLibName, preparedSkipList)) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
acc[secondaryLibName] = { ...shareObject };
|
|
79
|
+
}
|
|
80
|
+
_findSecondaries(io, s, excludes, shareObject, acc, preparedSkipList);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function findSecondaries(io, libPath, excludes, shareObject, preparedSkipList) {
|
|
84
|
+
const acc = {};
|
|
85
|
+
_findSecondaries(io, libPath, excludes, shareObject, acc, preparedSkipList);
|
|
86
|
+
return acc;
|
|
87
|
+
}
|
|
88
|
+
function getSecondaries(io, includeSecondaries, libPath, key, shareObject, preparedSkipList) {
|
|
89
|
+
let exclude = [];
|
|
90
|
+
let resolveGlob = false;
|
|
91
|
+
if (typeof includeSecondaries === "object") {
|
|
92
|
+
if (includeSecondaries.skip) {
|
|
93
|
+
if (Array.isArray(includeSecondaries.skip)) {
|
|
94
|
+
exclude = includeSecondaries.skip;
|
|
95
|
+
} else if (typeof includeSecondaries.skip === "string") {
|
|
96
|
+
exclude = [includeSecondaries.skip];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
resolveGlob = !!includeSecondaries.resolveGlob;
|
|
100
|
+
}
|
|
101
|
+
if (!io.exists(libPath)) {
|
|
102
|
+
return {};
|
|
103
|
+
}
|
|
104
|
+
const configured = readConfiguredSecondaries(
|
|
105
|
+
io,
|
|
106
|
+
key,
|
|
107
|
+
libPath,
|
|
108
|
+
exclude,
|
|
109
|
+
shareObject,
|
|
110
|
+
preparedSkipList,
|
|
111
|
+
resolveGlob
|
|
112
|
+
);
|
|
113
|
+
if (configured) {
|
|
114
|
+
return configured;
|
|
115
|
+
}
|
|
116
|
+
const secondaries = findSecondaries(io, libPath, exclude, shareObject, preparedSkipList);
|
|
117
|
+
return secondaries;
|
|
118
|
+
}
|
|
119
|
+
function readConfiguredSecondaries(io, parent, libPath, exclude, shareObject, preparedSkipList, resolveGlob) {
|
|
120
|
+
const libPackageJson = path.join(libPath, "package.json");
|
|
121
|
+
if (!io.exists(libPackageJson)) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
const packageJson = JSON.parse(io.readText(libPackageJson));
|
|
125
|
+
const version = packageJson["version"];
|
|
126
|
+
const esm = packageJson["type"] === "module";
|
|
127
|
+
const exports = packageJson["exports"];
|
|
128
|
+
if (!exports) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
const keys = Object.keys(exports).filter(
|
|
132
|
+
(key) => key !== "." && key !== "./package.json" && key.startsWith("./") && (exports[key]?.["default"] || exports[key]?.["import"] || typeof exports[key] === "string")
|
|
133
|
+
);
|
|
134
|
+
const result = {};
|
|
135
|
+
const discoveredFiles = /* @__PURE__ */ new Set();
|
|
136
|
+
for (const key of keys) {
|
|
137
|
+
const secondaryName = path.join(parent, key).replace(/\\/g, "/");
|
|
138
|
+
const inCustomSkipList = exclude.some(
|
|
139
|
+
(e) => e === secondaryName || e.endsWith("*") && secondaryName.startsWith(e.slice(0, -1))
|
|
140
|
+
);
|
|
141
|
+
if (inCustomSkipList) continue;
|
|
142
|
+
if (isInSkipList(secondaryName, preparedSkipList)) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const entry = getDefaultEntry(exports, key);
|
|
146
|
+
if (typeof entry !== "string") {
|
|
147
|
+
console.log("No entry point found for " + secondaryName);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (!key.includes("*") && !isJsFile(entry)) {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const items = resolveGlobSecondaries(
|
|
154
|
+
io,
|
|
155
|
+
key,
|
|
156
|
+
libPath,
|
|
157
|
+
parent,
|
|
158
|
+
secondaryName,
|
|
159
|
+
entry,
|
|
160
|
+
{ discovered: discoveredFiles, skip: exclude },
|
|
161
|
+
resolveGlob
|
|
162
|
+
);
|
|
163
|
+
items.forEach((e) => discoveredFiles.add(typeof e === "string" ? e : e.value));
|
|
164
|
+
for (const item of items) {
|
|
165
|
+
if (typeof item === "object") {
|
|
166
|
+
result[item.key] = {
|
|
167
|
+
...shareObject,
|
|
168
|
+
packageInfo: {
|
|
169
|
+
entryPoint: item.value,
|
|
170
|
+
version: shareObject.version ?? version,
|
|
171
|
+
esm
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
} else {
|
|
175
|
+
result[item] = {
|
|
176
|
+
...shareObject
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
function resolveGlobSecondaries(io, key, libPath, parent, secondaryName, entry, excludes, resolveGlob) {
|
|
184
|
+
let items = [];
|
|
185
|
+
if (key.includes("*")) {
|
|
186
|
+
if (!resolveGlob) return items;
|
|
187
|
+
const expanded = resolvePackageJsonExportsWildcardCore(io, key, entry, libPath);
|
|
188
|
+
items = expanded.map((e) => ({
|
|
189
|
+
key: path.join(parent, e.key),
|
|
190
|
+
value: path.join(libPath, e.value)
|
|
191
|
+
})).filter((i) => {
|
|
192
|
+
if (!isJsFile(i.value)) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
if (excludes.skip.some(
|
|
196
|
+
(e) => e.endsWith("*") ? i.key.startsWith(e.slice(0, -1)) : e === i.key
|
|
197
|
+
)) {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
if (excludes.discovered.has(i.value)) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
return true;
|
|
204
|
+
});
|
|
205
|
+
} else {
|
|
206
|
+
items = [secondaryName];
|
|
207
|
+
}
|
|
208
|
+
return items;
|
|
209
|
+
}
|
|
210
|
+
function isJsFile(file) {
|
|
211
|
+
return file.endsWith(".js") || file.endsWith(".mjs") || file.endsWith(".cjs");
|
|
212
|
+
}
|
|
213
|
+
function getDefaultEntry(exports, key) {
|
|
214
|
+
let entry = "";
|
|
215
|
+
if (typeof exports[key] === "string") {
|
|
216
|
+
entry = exports[key];
|
|
217
|
+
}
|
|
218
|
+
if (!entry) {
|
|
219
|
+
entry = exports[key]?.["default"];
|
|
220
|
+
if (typeof entry === "object") {
|
|
221
|
+
entry = entry["default"];
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (!entry) {
|
|
225
|
+
entry = exports[key]?.["import"];
|
|
226
|
+
if (typeof entry === "object") {
|
|
227
|
+
entry = entry["import"] ?? entry["default"];
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (!entry) {
|
|
231
|
+
entry = exports[key]?.["require"];
|
|
232
|
+
if (typeof entry === "object") {
|
|
233
|
+
entry = entry["require"] ?? entry["default"];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return entry;
|
|
237
|
+
}
|
|
238
|
+
function shareAll(config, opts = {}) {
|
|
239
|
+
return shareAllCore(nodeIo, config, opts);
|
|
240
|
+
}
|
|
241
|
+
function shareAllCore(io, config, opts = {}, repo = sharedPackageJsonRepository) {
|
|
242
|
+
const projectPath = inferProjectPath(opts.projectPath);
|
|
243
|
+
const versionMaps = getVersionMaps(projectPath, projectPath, repo);
|
|
244
|
+
const sharedExternals = {};
|
|
245
|
+
const skipList = opts.skipList ?? DEFAULT_SKIP_LIST;
|
|
246
|
+
for (const versions of versionMaps) {
|
|
247
|
+
for (const key in versions) {
|
|
248
|
+
if (isInSkipList(key, prepareSkipList(skipList))) {
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (!!opts.overrides && Object.keys(opts.overrides).some((o) => key.startsWith(o))) {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
const inferVersion2 = !config.requiredVersion || config.requiredVersion === "auto";
|
|
255
|
+
const requiredVersion = inferVersion2 ? versions[key] : config.requiredVersion;
|
|
256
|
+
if (!sharedExternals[key]) {
|
|
257
|
+
sharedExternals[key] = { ...config, requiredVersion };
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
...shareCore(io, sharedExternals, opts.projectPath, skipList, repo),
|
|
263
|
+
...!opts.overrides ? {} : shareCore(io, opts.overrides, opts.projectPath, skipList, repo)
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function inferProjectPath(projectPath) {
|
|
267
|
+
if (!projectPath && getConfigContext().packageJson) {
|
|
268
|
+
projectPath = path.dirname(getConfigContext().packageJson || "");
|
|
269
|
+
}
|
|
270
|
+
if (!projectPath && getConfigContext().workspaceRoot) {
|
|
271
|
+
projectPath = getConfigContext().workspaceRoot || "";
|
|
272
|
+
}
|
|
273
|
+
if (!projectPath) {
|
|
274
|
+
projectPath = cwd();
|
|
275
|
+
}
|
|
276
|
+
return projectPath;
|
|
277
|
+
}
|
|
278
|
+
function setInferVersion(infer) {
|
|
279
|
+
inferVersion = infer;
|
|
280
|
+
}
|
|
281
|
+
function share(configuredShareObjects, projectPath = "", skipList = DEFAULT_SKIP_LIST) {
|
|
282
|
+
return shareCore(nodeIo, configuredShareObjects, projectPath, skipList);
|
|
283
|
+
}
|
|
284
|
+
function shareCore(io, configuredShareObjects, projectPath = "", skipList = DEFAULT_SKIP_LIST, repo = sharedPackageJsonRepository) {
|
|
285
|
+
projectPath = inferProjectPath(projectPath);
|
|
286
|
+
const packagePath = findPackageJson(io, projectPath);
|
|
287
|
+
const preparedSkipList = prepareSkipList(skipList);
|
|
288
|
+
const shareObjects = { ...configuredShareObjects };
|
|
289
|
+
const result = {};
|
|
290
|
+
let includeSecondaries;
|
|
291
|
+
for (const key in shareObjects) {
|
|
292
|
+
includeSecondaries = false;
|
|
293
|
+
const shareObject = shareObjects[key];
|
|
294
|
+
if (shareObject.requiredVersion === "auto" || inferVersion && typeof shareObject.requiredVersion === "undefined" || shareObject.requiredVersion?.length < 1) {
|
|
295
|
+
const version = lookupVersion(key, projectPath, repo);
|
|
296
|
+
shareObject.requiredVersion = version;
|
|
297
|
+
shareObject.version = version.replace(/^\D*/, "");
|
|
298
|
+
}
|
|
299
|
+
if (typeof shareObject.includeSecondaries === "undefined") {
|
|
300
|
+
shareObject.includeSecondaries = true;
|
|
301
|
+
}
|
|
302
|
+
if (shareObject.includeSecondaries) {
|
|
303
|
+
includeSecondaries = shareObject.includeSecondaries;
|
|
304
|
+
delete shareObject.includeSecondaries;
|
|
305
|
+
if (includeSecondaries?.keepAll) shareObject.includeSecondaries = true;
|
|
306
|
+
}
|
|
307
|
+
result[key] = shareObject;
|
|
308
|
+
if (includeSecondaries) {
|
|
309
|
+
const libPackageJson = findDepPackageJson(key, path.dirname(packagePath), repo);
|
|
310
|
+
if (!libPackageJson) {
|
|
311
|
+
logger.error("Could not find folder containing dep " + key);
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
const libPath = path.dirname(libPackageJson);
|
|
315
|
+
const secondaries = getSecondaries(
|
|
316
|
+
io,
|
|
317
|
+
includeSecondaries,
|
|
318
|
+
libPath,
|
|
319
|
+
key,
|
|
320
|
+
shareObject,
|
|
321
|
+
preparedSkipList
|
|
322
|
+
);
|
|
323
|
+
if (secondaries) {
|
|
324
|
+
addSecondaries(secondaries, result);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return result;
|
|
329
|
+
}
|
|
330
|
+
function addSecondaries(secondaries, result) {
|
|
331
|
+
for (const key in secondaries) {
|
|
332
|
+
result[key] = secondaries[key];
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
export {
|
|
336
|
+
findRootTsConfigJson,
|
|
337
|
+
findRootTsConfigJsonCore,
|
|
338
|
+
getSecondaries,
|
|
339
|
+
setInferVersion,
|
|
340
|
+
share,
|
|
341
|
+
shareAll,
|
|
342
|
+
shareAllCore,
|
|
343
|
+
shareCore
|
|
344
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { getRawMappedPaths } from "./mapped-paths.js";
|
|
2
|
+
import { shareAll, findRootTsConfigJson } from "./share-utils.js";
|
|
3
|
+
import { isInSkipList, prepareSkipList } from "./default-skip-list.js";
|
|
4
|
+
import { logger } from "../utils/logger.js";
|
|
5
|
+
function withNativeFederation(config) {
|
|
6
|
+
const skip = prepareSkipList(config.skip ?? []);
|
|
7
|
+
const chunks = config.chunks ?? true;
|
|
8
|
+
const normalized = {
|
|
9
|
+
$type: "classic",
|
|
10
|
+
name: config.name ?? "",
|
|
11
|
+
exposes: normalizeExposes(config.exposes),
|
|
12
|
+
shared: normalizeShared(config, skip, chunks),
|
|
13
|
+
sharedMappings: removeSkippedMappings(config, skip),
|
|
14
|
+
chunks,
|
|
15
|
+
skip,
|
|
16
|
+
externals: config.externals ?? [],
|
|
17
|
+
features: {
|
|
18
|
+
mappingVersion: config.features?.mappingVersion ?? true,
|
|
19
|
+
ignoreUnusedDeps: config.features?.ignoreUnusedDeps ?? true,
|
|
20
|
+
denseChunking: config.features?.denseChunking ?? false,
|
|
21
|
+
integrityHashes: config.features?.integrityHashes ?? false
|
|
22
|
+
},
|
|
23
|
+
...config.shareScope && { shareScope: config.shareScope }
|
|
24
|
+
};
|
|
25
|
+
return normalized;
|
|
26
|
+
}
|
|
27
|
+
function normalizeExposes(exposes) {
|
|
28
|
+
if (!exposes) return {};
|
|
29
|
+
return Object.fromEntries(
|
|
30
|
+
Object.entries(exposes).map(([key, value]) => [
|
|
31
|
+
key,
|
|
32
|
+
typeof value === "string" ? { file: value } : value
|
|
33
|
+
])
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
function normalizeShared(config, skip, chunks) {
|
|
37
|
+
let result = {};
|
|
38
|
+
const shared = config.shared ?? shareAll({
|
|
39
|
+
singleton: true,
|
|
40
|
+
strictVersion: true,
|
|
41
|
+
requiredVersion: "auto",
|
|
42
|
+
platform: "browser"
|
|
43
|
+
});
|
|
44
|
+
result = Object.keys(shared).reduce((acc, cur) => {
|
|
45
|
+
const key = cur.replace(/\\/g, "/");
|
|
46
|
+
const sharedConfig = shared[cur];
|
|
47
|
+
if (!!sharedConfig.chunks && !sharedConfig.build && sharedConfig.chunks !== chunks) {
|
|
48
|
+
logger.warn(
|
|
49
|
+
`External '${cur}' has explicit chunk settings, consider switching build type to { build: 'package' }.`
|
|
50
|
+
);
|
|
51
|
+
sharedConfig.chunks = chunks;
|
|
52
|
+
}
|
|
53
|
+
const normalizedConfig = {
|
|
54
|
+
requiredVersion: sharedConfig.requiredVersion ?? "auto",
|
|
55
|
+
singleton: sharedConfig.singleton ?? false,
|
|
56
|
+
strictVersion: sharedConfig.strictVersion ?? false,
|
|
57
|
+
version: sharedConfig.version,
|
|
58
|
+
chunks: sharedConfig.chunks ?? chunks,
|
|
59
|
+
includeSecondaries: sharedConfig.includeSecondaries,
|
|
60
|
+
packageInfo: sharedConfig.packageInfo,
|
|
61
|
+
platform: sharedConfig.platform ?? config.platform ?? "browser",
|
|
62
|
+
build: sharedConfig.build ?? "default",
|
|
63
|
+
...sharedConfig.shareScope && { shareScope: sharedConfig.shareScope }
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
...acc,
|
|
67
|
+
[key]: normalizedConfig
|
|
68
|
+
};
|
|
69
|
+
}, {});
|
|
70
|
+
result = Object.keys(result).filter((key) => !isInSkipList(key, skip)).reduce((acc, cur) => ({ ...acc, [cur]: result[cur] }), {});
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
function removeSkippedMappings(config, skipList) {
|
|
74
|
+
const rootTsConfigPath = findRootTsConfigJson();
|
|
75
|
+
const paths = getRawMappedPaths(rootTsConfigPath, config.sharedMappings);
|
|
76
|
+
return Object.entries(paths).filter(([, _import]) => !isInSkipList(_import, skipList)).reduce((acc, [_path, _import]) => ({ ...acc, [_path]: _import }), {});
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
withNativeFederation
|
|
80
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { NFBuildAdapter } from '
|
|
1
|
+
import type { NFBuildAdapter } from '../../domain/core/build-adapter.contract.js';
|
|
2
2
|
export declare function setBuildAdapter(buildAdapter: NFBuildAdapter): void;
|
|
3
3
|
export declare function getBuildAdapter(): NFBuildAdapter;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { logger } from "../../utils/logger.js";
|
|
2
|
+
let _buildAdapter = null;
|
|
3
|
+
function setBuildAdapter(buildAdapter) {
|
|
4
|
+
_buildAdapter = buildAdapter;
|
|
5
|
+
}
|
|
6
|
+
function getBuildAdapter() {
|
|
7
|
+
if (!_buildAdapter) {
|
|
8
|
+
logger.error("Please set a BuildAdapter!");
|
|
9
|
+
throw new Error("BuildAdapter not set");
|
|
10
|
+
}
|
|
11
|
+
return _buildAdapter;
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
getBuildAdapter,
|
|
15
|
+
setBuildAdapter
|
|
16
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FederationInfo } from '../../domain/core/federation-info.contract.js';
|
|
2
|
+
import type { NormalizedFederationOptions } from '../../domain/core/federation-options.contract.js';
|
|
3
|
+
import type { NormalizedFederationConfig } from '../../domain/config/federation-config.contract.js';
|
|
4
|
+
export declare function buildForFederation(config: NormalizedFederationConfig, fedOptions: NormalizedFederationOptions, externals: string[], signal?: AbortSignal): Promise<FederationInfo>;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import {
|
|
2
|
+
bundleExposedAndMappings,
|
|
3
|
+
describeExposed,
|
|
4
|
+
describeSharedMappings
|
|
5
|
+
} from "./bundle-exposed-and-mappings.js";
|
|
6
|
+
import { bundleShared } from "./bundle-shared.js";
|
|
7
|
+
import { writeFederationInfo } from "../output/write-federation-info.js";
|
|
8
|
+
import { writeImportMap } from "../output/write-import-map.js";
|
|
9
|
+
import { logger } from "../../utils/logger.js";
|
|
10
|
+
import { normalizePackageName } from "../../utils/normalize.js";
|
|
11
|
+
import { AbortedError } from "../../utils/errors.js";
|
|
12
|
+
import { addExternalsToCache } from "../cache/federation-cache.js";
|
|
13
|
+
import path from "path";
|
|
14
|
+
async function buildForFederation(config, fedOptions, externals, signal) {
|
|
15
|
+
fedOptions.federationCache.cachePath = path.join(
|
|
16
|
+
fedOptions.federationCache.cachePath,
|
|
17
|
+
fedOptions.projectName
|
|
18
|
+
);
|
|
19
|
+
logger.info("Building federation artifacts");
|
|
20
|
+
logger.notice("Skip packages you don't want to share in your federation config");
|
|
21
|
+
const { sharedBrowser, sharedServer, separateBrowser, separateServer } = splitShared(
|
|
22
|
+
config.shared
|
|
23
|
+
);
|
|
24
|
+
if (Object.keys(sharedBrowser).length > 0) {
|
|
25
|
+
logger.info(`Bundling external npm packages with bundle type 'browser-shared'`);
|
|
26
|
+
const start2 = process.hrtime();
|
|
27
|
+
const sharedPackageInfoBrowser = await bundleShared(
|
|
28
|
+
sharedBrowser,
|
|
29
|
+
config,
|
|
30
|
+
fedOptions,
|
|
31
|
+
externals,
|
|
32
|
+
{ platform: "browser", bundleName: "browser-shared", chunks: config.chunks }
|
|
33
|
+
);
|
|
34
|
+
logger.measure(start2, "Step 2.1) Bundling all shared browser externals");
|
|
35
|
+
addExternalsToCache(fedOptions.federationCache, sharedPackageInfoBrowser);
|
|
36
|
+
if (signal?.aborted) throw new AbortedError("[buildForFederation] After shared-browser bundle");
|
|
37
|
+
}
|
|
38
|
+
if (Object.keys(sharedServer).length > 0) {
|
|
39
|
+
logger.info(`Bundling external npm packages with bundle type 'server-shared'`);
|
|
40
|
+
const start2 = process.hrtime();
|
|
41
|
+
const sharedPackageInfoServer = await bundleShared(
|
|
42
|
+
sharedServer,
|
|
43
|
+
config,
|
|
44
|
+
fedOptions,
|
|
45
|
+
externals,
|
|
46
|
+
{ platform: "node", bundleName: "node-shared", chunks: config.chunks }
|
|
47
|
+
);
|
|
48
|
+
logger.measure(start2, "Step 2.1) Bundling all shared node externals");
|
|
49
|
+
addExternalsToCache(fedOptions.federationCache, sharedPackageInfoServer);
|
|
50
|
+
if (signal?.aborted) throw new AbortedError("[buildForFederation] After shared-node bundle");
|
|
51
|
+
}
|
|
52
|
+
if (Object.keys(separateBrowser).length > 0) {
|
|
53
|
+
logger.info(`Bundling external npm packages with bundle type 'browser-separate'`);
|
|
54
|
+
const start2 = process.hrtime();
|
|
55
|
+
const separatePackageInfoBrowser = await bundleSeparatePackages(
|
|
56
|
+
separateBrowser,
|
|
57
|
+
externals,
|
|
58
|
+
config,
|
|
59
|
+
fedOptions,
|
|
60
|
+
{ platform: "browser" }
|
|
61
|
+
);
|
|
62
|
+
logger.measure(start2, "Step 2.2) Bundling all separate browser external packages");
|
|
63
|
+
addExternalsToCache(fedOptions.federationCache, separatePackageInfoBrowser);
|
|
64
|
+
if (signal?.aborted)
|
|
65
|
+
throw new AbortedError("[buildForFederation] After separate-browser bundle");
|
|
66
|
+
}
|
|
67
|
+
if (Object.keys(separateServer).length > 0) {
|
|
68
|
+
logger.info(`Bundling external npm packages with bundle type 'node-separate'`);
|
|
69
|
+
const start2 = process.hrtime();
|
|
70
|
+
const separatePackageInfoServer = await bundleSeparatePackages(
|
|
71
|
+
separateServer,
|
|
72
|
+
externals,
|
|
73
|
+
config,
|
|
74
|
+
fedOptions,
|
|
75
|
+
{ platform: "node" }
|
|
76
|
+
);
|
|
77
|
+
logger.measure(start2, "Step 2.2) Bundling all separate node external packages");
|
|
78
|
+
addExternalsToCache(fedOptions.federationCache, separatePackageInfoServer);
|
|
79
|
+
}
|
|
80
|
+
if (signal?.aborted) throw new AbortedError("[buildForFederation] After separate-node bundle");
|
|
81
|
+
const start = process.hrtime();
|
|
82
|
+
const artifactInfo = await bundleExposedAndMappings(
|
|
83
|
+
config,
|
|
84
|
+
fedOptions,
|
|
85
|
+
externals,
|
|
86
|
+
void 0,
|
|
87
|
+
signal
|
|
88
|
+
);
|
|
89
|
+
logger.measure(start, "Step 3) Bundling all internal libraries and exposed modules.");
|
|
90
|
+
if (signal?.aborted)
|
|
91
|
+
throw new AbortedError("[buildForFederation] After exposed-and-mappings bundle");
|
|
92
|
+
const exposedInfo = !artifactInfo ? describeExposed(config, fedOptions) : artifactInfo.exposes;
|
|
93
|
+
const sharedMappingInfo = !artifactInfo ? describeSharedMappings(config, fedOptions) : artifactInfo.mappings;
|
|
94
|
+
const sharedExternals = [...fedOptions.federationCache.externals, ...sharedMappingInfo];
|
|
95
|
+
if (config?.shareScope) {
|
|
96
|
+
Object.values(sharedExternals).forEach((external) => {
|
|
97
|
+
if (!external.shareScope) external.shareScope = config.shareScope;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const buildNotificationsEndpoint = fedOptions.buildNotifications?.enable && fedOptions.dev ? fedOptions.buildNotifications?.endpoint : void 0;
|
|
101
|
+
const federationInfo = {
|
|
102
|
+
name: config.name,
|
|
103
|
+
shared: sharedExternals,
|
|
104
|
+
exposes: exposedInfo,
|
|
105
|
+
buildNotificationsEndpoint
|
|
106
|
+
};
|
|
107
|
+
if (fedOptions.federationCache.chunks) {
|
|
108
|
+
federationInfo.chunks = fedOptions.federationCache.chunks;
|
|
109
|
+
}
|
|
110
|
+
if (artifactInfo?.chunks) {
|
|
111
|
+
federationInfo.chunks = { ...federationInfo.chunks ?? {}, ...artifactInfo?.chunks };
|
|
112
|
+
}
|
|
113
|
+
if (config.features.integrityHashes) {
|
|
114
|
+
federationInfo.integrity = {
|
|
115
|
+
...fedOptions.federationCache.integrity ?? {},
|
|
116
|
+
...artifactInfo?.integrity ?? {}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
writeFederationInfo(federationInfo, fedOptions);
|
|
120
|
+
writeImportMap(fedOptions.federationCache, fedOptions, federationInfo.integrity);
|
|
121
|
+
return federationInfo;
|
|
122
|
+
}
|
|
123
|
+
function inferPackageFromSecondary(secondary) {
|
|
124
|
+
const parts = secondary.split("/");
|
|
125
|
+
if (secondary.startsWith("@") && parts.length >= 2) {
|
|
126
|
+
return parts[0] + "/" + parts[1];
|
|
127
|
+
}
|
|
128
|
+
return parts[0];
|
|
129
|
+
}
|
|
130
|
+
async function bundleSeparatePackages(separateBrowser, externals, config, fedOptions, buildOptions) {
|
|
131
|
+
const groupedByPackage = {};
|
|
132
|
+
for (const [key, shared] of Object.entries(separateBrowser)) {
|
|
133
|
+
const packageName = shared.build === "separate" ? key : inferPackageFromSecondary(key);
|
|
134
|
+
if (!groupedByPackage[packageName]) {
|
|
135
|
+
groupedByPackage[packageName] = {
|
|
136
|
+
chunks: shared.chunks,
|
|
137
|
+
entries: {}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
groupedByPackage[packageName].entries[key] = shared;
|
|
141
|
+
}
|
|
142
|
+
const bundlePromises = Object.entries(groupedByPackage).map(
|
|
143
|
+
async ([packageName, packageConfig]) => {
|
|
144
|
+
return bundleShared(
|
|
145
|
+
packageConfig.entries,
|
|
146
|
+
config,
|
|
147
|
+
fedOptions,
|
|
148
|
+
externals.filter((e) => !e.startsWith(packageName)),
|
|
149
|
+
{
|
|
150
|
+
platform: buildOptions.platform,
|
|
151
|
+
chunks: packageConfig.chunks,
|
|
152
|
+
bundleName: `${buildOptions.platform}-${normalizePackageName(packageName)}`
|
|
153
|
+
}
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
);
|
|
157
|
+
const buildResults = await Promise.all(bundlePromises);
|
|
158
|
+
return buildResults.reduce(
|
|
159
|
+
(acc, r) => {
|
|
160
|
+
let chunks = acc.chunks;
|
|
161
|
+
if (r.chunks) {
|
|
162
|
+
chunks = { ...acc.chunks ?? {}, ...r.chunks };
|
|
163
|
+
}
|
|
164
|
+
let integrity = acc.integrity;
|
|
165
|
+
if (r.integrity) {
|
|
166
|
+
integrity = { ...acc.integrity ?? {}, ...r.integrity };
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
externals: [...acc.externals, ...r.externals],
|
|
170
|
+
chunks,
|
|
171
|
+
integrity
|
|
172
|
+
};
|
|
173
|
+
},
|
|
174
|
+
{ externals: [] }
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
function splitShared(shared) {
|
|
178
|
+
const sharedServer = {};
|
|
179
|
+
const sharedBrowser = {};
|
|
180
|
+
const separateBrowser = {};
|
|
181
|
+
const separateServer = {};
|
|
182
|
+
for (const key in shared) {
|
|
183
|
+
const obj = shared[key];
|
|
184
|
+
if (obj?.platform === "node") {
|
|
185
|
+
if (obj.build === "default") {
|
|
186
|
+
sharedServer[key] = obj;
|
|
187
|
+
} else {
|
|
188
|
+
separateServer[key] = obj;
|
|
189
|
+
}
|
|
190
|
+
} else if (obj?.platform === "browser") {
|
|
191
|
+
if (obj.build === "default") {
|
|
192
|
+
sharedBrowser[key] = obj;
|
|
193
|
+
} else {
|
|
194
|
+
separateBrowser[key] = obj;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
sharedBrowser,
|
|
200
|
+
sharedServer,
|
|
201
|
+
separateBrowser,
|
|
202
|
+
separateServer
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
export {
|
|
206
|
+
buildForFederation
|
|
207
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NFBuildAdapterResult } from '
|
|
1
|
+
import type { NFBuildAdapterResult } from '../../domain/core/build-adapter.contract.js';
|
|
2
2
|
export declare function createBuildResultMap(buildResult: NFBuildAdapterResult[], isHashed: boolean, expectedNames?: string[]): Record<string, string>;
|
|
3
3
|
export declare function lookupInResultMap(map: Record<string, string>, requestName: string): string;
|
|
4
4
|
export declare function popFromResultMap(map: Record<string, string>, requestName: string): string;
|