@softarc/native-federation 3.5.5 → 4.0.0-RC10
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/package.json +33 -5
- package/src/config.d.ts +4 -1
- package/src/config.js +4 -6
- package/src/domain.d.ts +2 -0
- package/src/domain.js +2 -0
- package/src/index.d.ts +10 -1
- package/src/index.js +10 -5
- package/src/internal.d.ts +13 -0
- package/src/internal.js +10 -0
- package/src/lib/config/configuration-context.js +3 -9
- package/src/lib/config/default-skip-list.d.ts +4 -0
- package/src/lib/config/default-skip-list.js +31 -0
- package/src/lib/config/remove-unused-deps.d.ts +3 -0
- package/src/lib/config/remove-unused-deps.js +10 -0
- package/src/lib/config/share-utils.d.ts +6 -18
- package/src/lib/config/share-utils.js +49 -128
- package/src/lib/config/with-native-federation.d.ts +1 -1
- package/src/lib/config/with-native-federation.js +48 -75
- package/src/lib/core/build-adapter.d.ts +3 -28
- package/src/lib/core/build-adapter.js +8 -13
- package/src/lib/core/build-for-federation.d.ts +4 -10
- package/src/lib/core/build-for-federation.js +84 -79
- package/src/lib/core/bundle-exposed-and-mappings.d.ts +6 -10
- package/src/lib/core/bundle-exposed-and-mappings.js +78 -60
- package/src/lib/core/bundle-shared.d.ts +11 -6
- package/src/lib/core/bundle-shared.js +88 -72
- package/src/lib/core/default-external-list.js +1 -8
- package/src/lib/core/federation-builder.d.ts +11 -6
- package/src/lib/core/federation-builder.js +27 -21
- package/src/lib/core/federation-cache.d.ts +8 -0
- package/src/lib/core/federation-cache.js +11 -0
- package/src/lib/core/get-externals.d.ts +1 -1
- package/src/lib/core/get-externals.js +2 -6
- package/src/lib/core/normalize-options.d.ts +12 -0
- package/src/lib/core/normalize-options.js +57 -0
- package/src/lib/core/rebuild-for-federation.d.ts +4 -0
- package/src/lib/core/rebuild-for-federation.js +37 -0
- package/src/lib/core/write-federation-info.d.ts +2 -2
- package/src/lib/core/write-federation-info.js +3 -8
- package/src/lib/core/write-import-map.d.ts +6 -3
- package/src/lib/core/write-import-map.js +13 -9
- package/src/lib/domain/config/external-config.contract.d.ts +43 -0
- package/src/lib/domain/config/external-config.contract.js +1 -0
- package/src/lib/domain/config/federation-config.contract.d.ts +35 -0
- package/src/lib/domain/config/federation-config.contract.js +1 -0
- package/src/lib/domain/config/index.d.ts +3 -0
- package/src/lib/domain/config/index.js +1 -0
- package/src/lib/{core/default-skip-list.d.ts → domain/config/skip-list.contract.d.ts} +0 -3
- package/src/lib/domain/config/skip-list.contract.js +1 -0
- package/src/lib/domain/config/with-native-federation.contract.d.ts +2 -0
- package/src/lib/domain/config/with-native-federation.contract.js +1 -0
- package/src/lib/domain/core/build-adapter.contract.d.ts +40 -0
- package/src/lib/domain/core/build-adapter.contract.js +1 -0
- package/src/lib/domain/core/build-notification-options.contract.d.ts +9 -0
- package/src/lib/domain/core/build-notification-options.contract.js +6 -0
- package/src/lib/domain/core/chunk.d.ts +2 -0
- package/src/lib/domain/core/chunk.js +8 -0
- package/src/lib/domain/core/federation-cache.contract.d.ts +7 -0
- package/src/lib/domain/core/federation-cache.contract.js +1 -0
- package/src/lib/domain/core/federation-info.contract.d.ts +33 -0
- package/src/lib/domain/core/federation-info.contract.js +1 -0
- package/src/lib/domain/core/federation-options.contract.d.ts +21 -0
- package/src/lib/domain/core/federation-options.contract.js +1 -0
- package/src/lib/domain/core/index.d.ts +6 -0
- package/src/lib/domain/core/index.js +2 -0
- package/src/lib/domain/utils/index.d.ts +2 -0
- package/src/lib/domain/utils/index.js +1 -0
- package/src/lib/domain/utils/keyvaluepair.contract.d.ts +4 -0
- package/src/lib/domain/utils/keyvaluepair.contract.js +1 -0
- package/src/lib/domain/utils/mapped-path.contract.d.ts +1 -0
- package/src/lib/domain/utils/mapped-path.contract.js +5 -0
- package/src/lib/domain/utils/used-dependencies.contract.d.ts +5 -0
- package/src/lib/domain/utils/used-dependencies.contract.js +1 -0
- package/src/lib/utils/build-result-map.d.ts +3 -2
- package/src/lib/utils/build-result-map.js +14 -13
- package/src/lib/utils/{bundle-caching.d.ts → cache-persistence.d.ts} +6 -4
- package/src/lib/utils/cache-persistence.js +66 -0
- package/src/lib/utils/errors.js +1 -6
- package/src/lib/utils/get-external-imports.js +5 -10
- package/src/lib/utils/get-used-dependencies.d.ts +7 -0
- package/src/lib/utils/get-used-dependencies.js +123 -0
- package/src/lib/utils/hash-file.js +3 -8
- package/src/lib/utils/logger.js +10 -16
- package/src/lib/utils/mapped-paths.d.ts +7 -10
- package/src/lib/utils/mapped-paths.js +18 -37
- package/src/lib/utils/normalize.js +2 -7
- package/src/lib/utils/package-info.js +36 -47
- package/src/lib/utils/rebuild-queue.d.ts +14 -1
- package/src/lib/utils/rebuild-queue.js +36 -21
- package/src/lib/utils/resolve-glob.js +7 -12
- package/src/lib/utils/resolve-wildcard-keys.js +9 -15
- package/src/lib/utils/rewrite-chunk-imports.d.ts +0 -2
- package/src/lib/utils/rewrite-chunk-imports.js +13 -29
- package/LICENSE +0 -8
- package/README.md +0 -509
- package/build.d.ts +0 -1
- package/build.js +0 -5
- package/build.js.map +0 -1
- package/src/build.d.ts +0 -19
- package/src/build.js +0 -38
- package/src/build.js.map +0 -1
- package/src/config.js.map +0 -1
- package/src/index.js.map +0 -1
- package/src/lib/config/configuration-context.js.map +0 -1
- package/src/lib/config/federation-config.d.ts +0 -55
- package/src/lib/config/federation-config.js +0 -3
- package/src/lib/config/federation-config.js.map +0 -1
- package/src/lib/config/share-utils.js.map +0 -1
- package/src/lib/config/with-native-federation.js.map +0 -1
- package/src/lib/core/build-adapter.js.map +0 -1
- package/src/lib/core/build-for-federation.js.map +0 -1
- package/src/lib/core/bundle-exposed-and-mappings.js.map +0 -1
- package/src/lib/core/bundle-shared.js.map +0 -1
- package/src/lib/core/default-external-list.js.map +0 -1
- package/src/lib/core/default-server-deps-list.d.ts +0 -2
- package/src/lib/core/default-server-deps-list.js +0 -10
- package/src/lib/core/default-server-deps-list.js.map +0 -1
- package/src/lib/core/default-skip-list.js +0 -49
- package/src/lib/core/default-skip-list.js.map +0 -1
- package/src/lib/core/federation-builder.js.map +0 -1
- package/src/lib/core/federation-options.d.ts +0 -14
- package/src/lib/core/federation-options.js +0 -3
- package/src/lib/core/federation-options.js.map +0 -1
- package/src/lib/core/get-externals.js.map +0 -1
- package/src/lib/core/load-federation-config.d.ts +0 -3
- package/src/lib/core/load-federation-config.js +0 -24
- package/src/lib/core/load-federation-config.js.map +0 -1
- package/src/lib/core/remove-unused-deps.d.ts +0 -2
- package/src/lib/core/remove-unused-deps.js +0 -98
- package/src/lib/core/remove-unused-deps.js.map +0 -1
- package/src/lib/core/write-federation-info.js.map +0 -1
- package/src/lib/core/write-import-map.js.map +0 -1
- package/src/lib/utils/build-result-map.js.map +0 -1
- package/src/lib/utils/build-utils.d.ts +0 -2
- package/src/lib/utils/build-utils.js +0 -9
- package/src/lib/utils/build-utils.js.map +0 -1
- package/src/lib/utils/bundle-caching.js +0 -78
- package/src/lib/utils/bundle-caching.js.map +0 -1
- package/src/lib/utils/config-utils.d.ts +0 -2
- package/src/lib/utils/config-utils.js +0 -13
- package/src/lib/utils/config-utils.js.map +0 -1
- package/src/lib/utils/errors.js.map +0 -1
- package/src/lib/utils/get-external-imports.js.map +0 -1
- package/src/lib/utils/hash-file.js.map +0 -1
- package/src/lib/utils/logger.js.map +0 -1
- package/src/lib/utils/mapped-paths.js.map +0 -1
- package/src/lib/utils/normalize.js.map +0 -1
- package/src/lib/utils/package-info.js.map +0 -1
- package/src/lib/utils/rebuild-queue.js.map +0 -1
- package/src/lib/utils/resolve-glob.js.map +0 -1
- package/src/lib/utils/resolve-wildcard-keys.js.map +0 -1
- package/src/lib/utils/rewrite-chunk-imports.js.map +0 -1
|
@@ -1,97 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const default_server_deps_list_1 = require("../core/default-server-deps-list");
|
|
9
|
-
function withNativeFederation(config) {
|
|
10
|
-
const skip = (0, default_skip_list_1.prepareSkipList)(config.skip ?? []);
|
|
1
|
+
import { getRawMappedPaths } from '../utils/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
|
+
export function withNativeFederation(config) {
|
|
6
|
+
const skip = prepareSkipList(config.skip ?? []);
|
|
7
|
+
const chunks = config.chunks ?? true;
|
|
11
8
|
const normalized = {
|
|
9
|
+
$type: 'classic',
|
|
12
10
|
name: config.name ?? '',
|
|
13
11
|
exposes: config.exposes ?? {},
|
|
14
|
-
shared: normalizeShared(config, skip),
|
|
15
|
-
sharedMappings:
|
|
12
|
+
shared: normalizeShared(config, skip, chunks),
|
|
13
|
+
sharedMappings: removeSkippedMappings(config, skip),
|
|
14
|
+
chunks,
|
|
16
15
|
skip,
|
|
17
16
|
externals: config.externals ?? [],
|
|
18
17
|
features: {
|
|
19
18
|
mappingVersion: config.features?.mappingVersion ?? false,
|
|
20
|
-
ignoreUnusedDeps: config.features?.ignoreUnusedDeps ??
|
|
19
|
+
ignoreUnusedDeps: config.features?.ignoreUnusedDeps ?? true,
|
|
20
|
+
denseChunking: config.features?.denseChunking ?? false,
|
|
21
21
|
},
|
|
22
|
+
...(config.shareScope && { shareScope: config.shareScope }),
|
|
22
23
|
};
|
|
23
|
-
// This is for being backwards compatible
|
|
24
|
-
if (!normalized.features.ignoreUnusedDeps) {
|
|
25
|
-
normalized.shared = filterShared(normalized.shared);
|
|
26
|
-
}
|
|
27
24
|
return normalized;
|
|
28
25
|
}
|
|
29
|
-
function
|
|
30
|
-
const keys = Object.keys(shared).filter((k) => !k.startsWith('@angular/common/locales'));
|
|
31
|
-
const filtered = keys.reduce((acc, curr) => ({
|
|
32
|
-
...acc,
|
|
33
|
-
[curr]: shared[curr],
|
|
34
|
-
}), {});
|
|
35
|
-
return filtered;
|
|
36
|
-
}
|
|
37
|
-
function normalizeShared(config, skip) {
|
|
26
|
+
function normalizeShared(config, skip, chunks) {
|
|
38
27
|
let result = {};
|
|
39
|
-
const shared = config.shared
|
|
40
|
-
|
|
41
|
-
result = (0, share_utils_1.shareAll)({
|
|
28
|
+
const shared = config.shared ??
|
|
29
|
+
shareAll({
|
|
42
30
|
singleton: true,
|
|
43
31
|
strictVersion: true,
|
|
44
32
|
requiredVersion: 'auto',
|
|
45
33
|
platform: 'browser',
|
|
46
34
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
35
|
+
result = Object.keys(shared).reduce((acc, cur) => {
|
|
36
|
+
const key = cur.replace(/\\/g, '/');
|
|
37
|
+
const sharedConfig = shared[cur];
|
|
38
|
+
if (!!sharedConfig.chunks && !sharedConfig.build && sharedConfig.chunks !== chunks) {
|
|
39
|
+
logger.warn(`External '${cur}' has explicit chunk settings, consider switching build type to { build: 'package' }.`);
|
|
40
|
+
sharedConfig.chunks = chunks;
|
|
41
|
+
}
|
|
42
|
+
const normalizedConfig = {
|
|
43
|
+
requiredVersion: sharedConfig.requiredVersion ?? 'auto',
|
|
44
|
+
singleton: sharedConfig.singleton ?? false,
|
|
45
|
+
strictVersion: sharedConfig.strictVersion ?? false,
|
|
46
|
+
version: sharedConfig.version,
|
|
47
|
+
chunks: sharedConfig.chunks ?? chunks,
|
|
48
|
+
includeSecondaries: sharedConfig.includeSecondaries,
|
|
49
|
+
packageInfo: sharedConfig.packageInfo,
|
|
50
|
+
platform: sharedConfig.platform ?? config.platform ?? 'browser',
|
|
51
|
+
build: sharedConfig.build ?? 'default',
|
|
52
|
+
...(sharedConfig.shareScope && { shareScope: sharedConfig.shareScope }),
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
50
55
|
...acc,
|
|
51
|
-
[
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
strictVersion: shared[cur].strictVersion ?? false,
|
|
55
|
-
version: shared[cur].version,
|
|
56
|
-
includeSecondaries: shared[cur].includeSecondaries,
|
|
57
|
-
packageInfo: shared[cur].packageInfo,
|
|
58
|
-
platform: shared[cur].platform ?? getDefaultPlatform(cur),
|
|
59
|
-
build: shared[cur].build ?? 'default',
|
|
60
|
-
},
|
|
61
|
-
}), {});
|
|
62
|
-
//result = share(result) as Record<string, NormalizedSharedConfig>;
|
|
63
|
-
}
|
|
56
|
+
[key]: normalizedConfig,
|
|
57
|
+
};
|
|
58
|
+
}, {});
|
|
64
59
|
result = Object.keys(result)
|
|
65
|
-
.filter(
|
|
66
|
-
.reduce((acc, cur) => ({
|
|
67
|
-
...acc,
|
|
68
|
-
[cur]: result[cur],
|
|
69
|
-
}), {});
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
72
|
-
function normalizeSharedMappings(config, skipList) {
|
|
73
|
-
const rootTsConfigPath = (0, share_utils_1.findRootTsConfigJson)();
|
|
74
|
-
const paths = (0, mapped_paths_1.getMappedPaths)({
|
|
75
|
-
rootTsConfigPath,
|
|
76
|
-
sharedMappings: config.sharedMappings,
|
|
77
|
-
});
|
|
78
|
-
const result = paths.filter((p) => !(0, default_skip_list_1.isInSkipList)(p.key, skipList));
|
|
79
|
-
const importsWithDot = paths.filter((p) => p.key.includes('.'));
|
|
80
|
-
if (importsWithDot.length > 0) {
|
|
81
|
-
importsWithDot.forEach((e) => {
|
|
82
|
-
logger_1.logger.warn(`Shared mapping import '${e}' contains a dot.`);
|
|
83
|
-
});
|
|
84
|
-
logger_1.logger.warn('details: https://github.com/vitejs/vite/issues/21036');
|
|
85
|
-
throw new Error('Native-federation does not support dots (.) in imports paths. ');
|
|
86
|
-
}
|
|
60
|
+
.filter(key => !isInSkipList(key, skip))
|
|
61
|
+
.reduce((acc, cur) => ({ ...acc, [cur]: result[cur] }), {});
|
|
87
62
|
return result;
|
|
88
63
|
}
|
|
89
|
-
function
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
64
|
+
function removeSkippedMappings(config, skipList) {
|
|
65
|
+
const rootTsConfigPath = findRootTsConfigJson();
|
|
66
|
+
const paths = getRawMappedPaths(rootTsConfigPath, config.sharedMappings);
|
|
67
|
+
return Object.entries(paths)
|
|
68
|
+
.filter(([, _import]) => !isInSkipList(_import, skipList))
|
|
69
|
+
.reduce((acc, [_path, _import]) => ({ ...acc, [_path]: _import }), {});
|
|
96
70
|
}
|
|
97
|
-
//# sourceMappingURL=with-native-federation.js.map
|
|
@@ -1,28 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
fileName: string;
|
|
5
|
-
outName: string;
|
|
6
|
-
}
|
|
7
|
-
export interface BuildAdapterOptions {
|
|
8
|
-
entryPoints: EntryPoint[];
|
|
9
|
-
tsConfigPath?: string;
|
|
10
|
-
external: Array<string>;
|
|
11
|
-
outdir: string;
|
|
12
|
-
mappedPaths: MappedPath[];
|
|
13
|
-
packageName?: string;
|
|
14
|
-
esm?: boolean;
|
|
15
|
-
dev?: boolean;
|
|
16
|
-
watch?: boolean;
|
|
17
|
-
kind: BuildKind;
|
|
18
|
-
hash: boolean;
|
|
19
|
-
platform?: 'browser' | 'node';
|
|
20
|
-
optimizedMappings?: boolean;
|
|
21
|
-
signal?: AbortSignal;
|
|
22
|
-
}
|
|
23
|
-
export interface BuildResult {
|
|
24
|
-
fileName: string;
|
|
25
|
-
}
|
|
26
|
-
export type BuildAdapter = (options: BuildAdapterOptions) => Promise<BuildResult[]>;
|
|
27
|
-
export declare function setBuildAdapter(buildAdapter: BuildAdapter): void;
|
|
28
|
-
export declare function getBuildAdapter(): BuildAdapter;
|
|
1
|
+
import type { NFBuildAdapter } from '../domain/core/build-adapter.contract.js';
|
|
2
|
+
export declare function setBuildAdapter(buildAdapter: NFBuildAdapter): void;
|
|
3
|
+
export declare function getBuildAdapter(): NFBuildAdapter;
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.getBuildAdapter = getBuildAdapter;
|
|
5
|
-
const logger_1 = require("../utils/logger");
|
|
6
|
-
let _buildAdapter = async () => {
|
|
7
|
-
// TODO: add logger
|
|
8
|
-
logger_1.logger.error('Please set a BuildAdapter!');
|
|
9
|
-
return [];
|
|
10
|
-
};
|
|
11
|
-
function setBuildAdapter(buildAdapter) {
|
|
1
|
+
import { logger } from '../utils/logger.js';
|
|
2
|
+
let _buildAdapter = null;
|
|
3
|
+
export function setBuildAdapter(buildAdapter) {
|
|
12
4
|
_buildAdapter = buildAdapter;
|
|
13
5
|
}
|
|
14
|
-
function getBuildAdapter() {
|
|
6
|
+
export function getBuildAdapter() {
|
|
7
|
+
if (!_buildAdapter) {
|
|
8
|
+
logger.error('Please set a BuildAdapter!');
|
|
9
|
+
throw new Error('BuildAdapter not set');
|
|
10
|
+
}
|
|
15
11
|
return _buildAdapter;
|
|
16
12
|
}
|
|
17
|
-
//# sourceMappingURL=build-adapter.js.map
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import { FederationInfo } from '
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export
|
|
5
|
-
skipMappingsAndExposed: boolean;
|
|
6
|
-
skipShared: boolean;
|
|
7
|
-
signal?: AbortSignal;
|
|
8
|
-
}
|
|
9
|
-
export declare const defaultBuildParams: BuildParams;
|
|
10
|
-
export declare function buildForFederation(config: NormalizedFederationConfig, fedOptions: FederationOptions, externals: string[], buildParams?: BuildParams): Promise<FederationInfo>;
|
|
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>;
|
|
@@ -1,93 +1,94 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const sharedPackageInfoCache = [];
|
|
19
|
-
async function buildForFederation(config, fedOptions, externals, buildParams = exports.defaultBuildParams) {
|
|
20
|
-
const signal = buildParams.signal;
|
|
21
|
-
let artefactInfo;
|
|
22
|
-
if (!buildParams.skipMappingsAndExposed) {
|
|
23
|
-
const start = process.hrtime();
|
|
24
|
-
artefactInfo = await (0, bundle_exposed_and_mappings_1.bundleExposedAndMappings)(config, fedOptions, externals, signal);
|
|
25
|
-
logger_1.logger.measure(start, '[build artifacts] - To bundle all mappings and exposed.');
|
|
26
|
-
if (signal?.aborted)
|
|
27
|
-
throw new errors_1.AbortedError('[buildForFederation] After exposed-and-mappings bundle');
|
|
28
|
-
}
|
|
29
|
-
const exposedInfo = !artefactInfo
|
|
30
|
-
? (0, bundle_exposed_and_mappings_1.describeExposed)(config, fedOptions)
|
|
31
|
-
: artefactInfo.exposes;
|
|
32
|
-
const cacheProjectFolder = (0, config_utils_1.resolveProjectName)(config);
|
|
33
|
-
const pathToCache = (0, bundle_caching_1.getCachePath)(fedOptions.workspaceRoot, cacheProjectFolder);
|
|
34
|
-
if (!buildParams.skipShared && sharedPackageInfoCache.length > 0) {
|
|
35
|
-
logger_1.logger.info('Checksum matched, re-using cached externals.');
|
|
1
|
+
import { bundleExposedAndMappings, describeExposed, describeSharedMappings, } from './bundle-exposed-and-mappings.js';
|
|
2
|
+
import { bundleShared } from './bundle-shared.js';
|
|
3
|
+
import { writeFederationInfo } from './write-federation-info.js';
|
|
4
|
+
import { writeImportMap } from './write-import-map.js';
|
|
5
|
+
import { logger } from '../utils/logger.js';
|
|
6
|
+
import { normalizePackageName } from '../utils/normalize.js';
|
|
7
|
+
import { AbortedError } from '../utils/errors.js';
|
|
8
|
+
import { addExternalsToCache } from './federation-cache.js';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
export async function buildForFederation(config, fedOptions, externals, signal) {
|
|
11
|
+
// 1. Setup
|
|
12
|
+
fedOptions.federationCache.cachePath = path.join(fedOptions.federationCache.cachePath, fedOptions.projectName);
|
|
13
|
+
logger.info('Building federation artifacts');
|
|
14
|
+
logger.notice("Skip packages you don't want to share in your federation config");
|
|
15
|
+
// 2. Externals
|
|
16
|
+
if (fedOptions.federationCache.externals.length > 0) {
|
|
17
|
+
logger.info('Checksum matched, re-using cached externals.');
|
|
36
18
|
}
|
|
37
|
-
if (
|
|
19
|
+
if (fedOptions.federationCache.externals.length === 0) {
|
|
38
20
|
const { sharedBrowser, sharedServer, separateBrowser, separateServer } = splitShared(config.shared);
|
|
39
21
|
if (Object.keys(sharedBrowser).length > 0) {
|
|
40
|
-
|
|
22
|
+
logger.info(`Bundling external npm packages with bundle type 'browser-shared'`);
|
|
41
23
|
const start = process.hrtime();
|
|
42
|
-
const sharedPackageInfoBrowser = await
|
|
43
|
-
|
|
44
|
-
|
|
24
|
+
const sharedPackageInfoBrowser = await bundleShared(sharedBrowser, config, fedOptions, externals, { platform: 'browser', bundleName: 'browser-shared', chunks: config.chunks });
|
|
25
|
+
logger.measure(start, 'Step 2.1) Bundling all shared browser externals');
|
|
26
|
+
addExternalsToCache(fedOptions.federationCache, sharedPackageInfoBrowser);
|
|
45
27
|
if (signal?.aborted)
|
|
46
|
-
throw new
|
|
28
|
+
throw new AbortedError('[buildForFederation] After shared-browser bundle');
|
|
47
29
|
}
|
|
48
30
|
if (Object.keys(sharedServer).length > 0) {
|
|
49
|
-
|
|
31
|
+
logger.info(`Bundling external npm packages with bundle type 'server-shared'`);
|
|
50
32
|
const start = process.hrtime();
|
|
51
|
-
const sharedPackageInfoServer = await
|
|
52
|
-
|
|
53
|
-
|
|
33
|
+
const sharedPackageInfoServer = await bundleShared(sharedServer, config, fedOptions, externals, { platform: 'node', bundleName: 'node-shared', chunks: config.chunks });
|
|
34
|
+
logger.measure(start, 'Step 2.1) Bundling all shared node externals');
|
|
35
|
+
addExternalsToCache(fedOptions.federationCache, sharedPackageInfoServer);
|
|
54
36
|
if (signal?.aborted)
|
|
55
|
-
throw new
|
|
37
|
+
throw new AbortedError('[buildForFederation] After shared-node bundle');
|
|
56
38
|
}
|
|
57
39
|
if (Object.keys(separateBrowser).length > 0) {
|
|
58
|
-
|
|
40
|
+
logger.info(`Bundling external npm packages with bundle type 'browser-separate'`);
|
|
59
41
|
const start = process.hrtime();
|
|
60
|
-
const separatePackageInfoBrowser = await bundleSeparatePackages(separateBrowser, externals, config, fedOptions, 'browser'
|
|
61
|
-
|
|
62
|
-
|
|
42
|
+
const separatePackageInfoBrowser = await bundleSeparatePackages(separateBrowser, externals, config, fedOptions, { platform: 'browser' });
|
|
43
|
+
logger.measure(start, 'Step 2.2) Bundling all separate browser external packages');
|
|
44
|
+
addExternalsToCache(fedOptions.federationCache, separatePackageInfoBrowser);
|
|
63
45
|
if (signal?.aborted)
|
|
64
|
-
throw new
|
|
46
|
+
throw new AbortedError('[buildForFederation] After separate-browser bundle');
|
|
65
47
|
}
|
|
66
48
|
if (Object.keys(separateServer).length > 0) {
|
|
67
|
-
|
|
49
|
+
logger.info(`Bundling external npm packages with bundle type 'node-separate'`);
|
|
68
50
|
const start = process.hrtime();
|
|
69
|
-
const separatePackageInfoServer = await bundleSeparatePackages(separateServer, externals, config, fedOptions, 'node'
|
|
70
|
-
|
|
71
|
-
|
|
51
|
+
const separatePackageInfoServer = await bundleSeparatePackages(separateServer, externals, config, fedOptions, { platform: 'node' });
|
|
52
|
+
logger.measure(start, 'Step 2.2) Bundling all separate node external packages');
|
|
53
|
+
addExternalsToCache(fedOptions.federationCache, separatePackageInfoServer);
|
|
72
54
|
}
|
|
73
55
|
if (signal?.aborted)
|
|
74
|
-
throw new
|
|
56
|
+
throw new AbortedError('[buildForFederation] After separate-node bundle');
|
|
57
|
+
}
|
|
58
|
+
// 2. Shared mappings and exposed modules
|
|
59
|
+
const start = process.hrtime();
|
|
60
|
+
const artifactInfo = await bundleExposedAndMappings(config, fedOptions, externals, undefined, signal);
|
|
61
|
+
logger.measure(start, 'Step 3) Bundling all internal libraries and exposed modules.');
|
|
62
|
+
if (signal?.aborted)
|
|
63
|
+
throw new AbortedError('[buildForFederation] After exposed-and-mappings bundle');
|
|
64
|
+
const exposedInfo = !artifactInfo ? describeExposed(config, fedOptions) : artifactInfo.exposes;
|
|
65
|
+
const sharedMappingInfo = !artifactInfo
|
|
66
|
+
? describeSharedMappings(config, fedOptions)
|
|
67
|
+
: artifactInfo.mappings;
|
|
68
|
+
const sharedExternals = [...fedOptions.federationCache.externals, ...sharedMappingInfo];
|
|
69
|
+
if (config?.shareScope) {
|
|
70
|
+
Object.values(sharedExternals).forEach(external => {
|
|
71
|
+
if (!external.shareScope)
|
|
72
|
+
external.shareScope = config.shareScope;
|
|
73
|
+
});
|
|
75
74
|
}
|
|
76
|
-
const sharedMappingInfo = !artefactInfo
|
|
77
|
-
? (0, bundle_exposed_and_mappings_1.describeSharedMappings)(config, fedOptions)
|
|
78
|
-
: artefactInfo.mappings;
|
|
79
|
-
const sharedInfo = [...sharedPackageInfoCache, ...sharedMappingInfo];
|
|
80
75
|
const buildNotificationsEndpoint = fedOptions.buildNotifications?.enable && fedOptions.dev
|
|
81
76
|
? fedOptions.buildNotifications?.endpoint
|
|
82
77
|
: undefined;
|
|
83
78
|
const federationInfo = {
|
|
84
79
|
name: config.name,
|
|
85
|
-
shared:
|
|
80
|
+
shared: sharedExternals,
|
|
86
81
|
exposes: exposedInfo,
|
|
87
82
|
buildNotificationsEndpoint,
|
|
88
83
|
};
|
|
89
|
-
(
|
|
90
|
-
|
|
84
|
+
if (fedOptions.federationCache.chunks) {
|
|
85
|
+
federationInfo.chunks = fedOptions.federationCache.chunks;
|
|
86
|
+
}
|
|
87
|
+
if (artifactInfo?.chunks) {
|
|
88
|
+
federationInfo.chunks = { ...(federationInfo.chunks ?? {}), ...artifactInfo?.chunks };
|
|
89
|
+
}
|
|
90
|
+
writeFederationInfo(federationInfo, fedOptions);
|
|
91
|
+
writeImportMap(fedOptions.federationCache, fedOptions);
|
|
91
92
|
return federationInfo;
|
|
92
93
|
}
|
|
93
94
|
function inferPackageFromSecondary(secondary) {
|
|
@@ -97,28 +98,33 @@ function inferPackageFromSecondary(secondary) {
|
|
|
97
98
|
}
|
|
98
99
|
return parts[0];
|
|
99
100
|
}
|
|
100
|
-
async function bundleSeparatePackages(separateBrowser, externals, config, fedOptions,
|
|
101
|
+
async function bundleSeparatePackages(separateBrowser, externals, config, fedOptions, buildOptions) {
|
|
101
102
|
const groupedByPackage = {};
|
|
102
103
|
for (const [key, shared] of Object.entries(separateBrowser)) {
|
|
103
104
|
const packageName = shared.build === 'separate' ? key : inferPackageFromSecondary(key);
|
|
104
105
|
if (!groupedByPackage[packageName]) {
|
|
105
|
-
groupedByPackage[packageName] = {
|
|
106
|
+
groupedByPackage[packageName] = {
|
|
107
|
+
chunks: shared.chunks,
|
|
108
|
+
entries: {},
|
|
109
|
+
};
|
|
106
110
|
}
|
|
107
|
-
groupedByPackage[packageName][key] = shared;
|
|
111
|
+
groupedByPackage[packageName].entries[key] = shared;
|
|
108
112
|
}
|
|
109
|
-
const bundlePromises = Object.entries(groupedByPackage).map(async ([packageName,
|
|
110
|
-
return (
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
const bundlePromises = Object.entries(groupedByPackage).map(async ([packageName, packageConfig]) => {
|
|
114
|
+
return bundleShared(packageConfig.entries, config, fedOptions, externals.filter(e => !e.startsWith(packageName)), {
|
|
115
|
+
platform: buildOptions.platform,
|
|
116
|
+
chunks: packageConfig.chunks,
|
|
117
|
+
bundleName: `${buildOptions.platform}-${normalizePackageName(packageName)}`,
|
|
113
118
|
});
|
|
114
119
|
});
|
|
115
120
|
const buildResults = await Promise.all(bundlePromises);
|
|
116
|
-
return buildResults.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
return buildResults.reduce((acc, r) => {
|
|
122
|
+
let chunks = acc.chunks;
|
|
123
|
+
if (r.chunks) {
|
|
124
|
+
chunks = { ...(acc.chunks ?? {}), ...r.chunks };
|
|
125
|
+
}
|
|
126
|
+
return { externals: [...acc.externals, ...r.externals], chunks };
|
|
127
|
+
}, { externals: [] });
|
|
122
128
|
}
|
|
123
129
|
function splitShared(shared) {
|
|
124
130
|
const sharedServer = {};
|
|
@@ -127,7 +133,7 @@ function splitShared(shared) {
|
|
|
127
133
|
const separateServer = {};
|
|
128
134
|
for (const key in shared) {
|
|
129
135
|
const obj = shared[key];
|
|
130
|
-
if (obj
|
|
136
|
+
if (obj?.platform === 'node') {
|
|
131
137
|
if (obj.build === 'default') {
|
|
132
138
|
sharedServer[key] = obj;
|
|
133
139
|
}
|
|
@@ -135,7 +141,7 @@ function splitShared(shared) {
|
|
|
135
141
|
separateServer[key] = obj;
|
|
136
142
|
}
|
|
137
143
|
}
|
|
138
|
-
else if (obj
|
|
144
|
+
else if (obj?.platform === 'browser') {
|
|
139
145
|
if (obj.build === 'default') {
|
|
140
146
|
sharedBrowser[key] = obj;
|
|
141
147
|
}
|
|
@@ -151,4 +157,3 @@ function splitShared(shared) {
|
|
|
151
157
|
separateServer,
|
|
152
158
|
};
|
|
153
159
|
}
|
|
154
|
-
//# sourceMappingURL=build-for-federation.js.map
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { ExposesInfo, SharedInfo } from '
|
|
2
|
-
import { NormalizedFederationConfig } from '../config/federation-config';
|
|
3
|
-
import {
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
export declare function bundleExposedAndMappings(config: NormalizedFederationConfig, fedOptions: FederationOptions, externals: string[], signal?: AbortSignal): Promise<ArtefactInfo>;
|
|
9
|
-
export declare function describeExposed(config: NormalizedFederationConfig, options: FederationOptions): Array<ExposesInfo>;
|
|
10
|
-
export declare function describeSharedMappings(config: NormalizedFederationConfig, fedOptions: FederationOptions): Array<SharedInfo>;
|
|
1
|
+
import type { ArtifactInfo, ExposesInfo, SharedInfo } from '../domain/core/federation-info.contract.js';
|
|
2
|
+
import type { NormalizedFederationConfig } from '../domain/config/federation-config.contract.js';
|
|
3
|
+
import { type NormalizedFederationOptions } from '../domain/core/federation-options.contract.js';
|
|
4
|
+
export declare function bundleExposedAndMappings(config: NormalizedFederationConfig, fedOptions: NormalizedFederationOptions, externals: string[], modifiedFiles?: string[], signal?: AbortSignal): Promise<ArtifactInfo>;
|
|
5
|
+
export declare function describeExposed(config: NormalizedFederationConfig, options: NormalizedFederationOptions): Array<ExposesInfo>;
|
|
6
|
+
export declare function describeSharedMappings(config: NormalizedFederationConfig, fedOptions: NormalizedFederationOptions): Array<SharedInfo>;
|