@softarc/native-federation 4.0.0-RC1 → 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 +2 -2
- package/src/config.d.ts +0 -1
- package/src/domain.d.ts +0 -1
- package/src/index.d.ts +3 -2
- package/src/index.js +3 -1
- package/src/internal.d.ts +5 -4
- package/src/internal.js +3 -1
- package/src/lib/config/configuration-context.d.ts +0 -1
- package/src/lib/config/default-skip-list.d.ts +0 -1
- package/src/lib/config/default-skip-list.js +3 -15
- 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 +0 -2
- package/src/lib/config/share-utils.js +7 -13
- package/src/lib/config/with-native-federation.d.ts +0 -1
- package/src/lib/config/with-native-federation.js +41 -59
- package/src/lib/core/build-adapter.d.ts +0 -1
- package/src/lib/core/build-adapter.js +5 -5
- package/src/lib/core/build-for-federation.d.ts +2 -5
- package/src/lib/core/build-for-federation.js +68 -59
- package/src/lib/core/bundle-exposed-and-mappings.d.ts +5 -6
- package/src/lib/core/bundle-exposed-and-mappings.js +56 -28
- package/src/lib/core/bundle-shared.d.ts +8 -5
- package/src/lib/core/bundle-shared.js +41 -18
- package/src/lib/core/default-external-list.d.ts +0 -1
- package/src/lib/core/default-external-list.js +1 -4
- package/src/lib/core/federation-builder.d.ts +6 -2
- package/src/lib/core/federation-builder.js +19 -8
- 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 +0 -1
- package/src/lib/core/get-externals.js +1 -1
- 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 +0 -1
- package/src/lib/core/write-import-map.d.ts +5 -3
- package/src/lib/core/write-import-map.js +10 -1
- package/src/lib/domain/config/external-config.contract.d.ts +5 -2
- package/src/lib/domain/config/federation-config.contract.d.ts +10 -3
- package/src/lib/domain/config/index.d.ts +0 -1
- package/src/lib/domain/config/skip-list.contract.d.ts +0 -1
- package/src/lib/domain/config/with-native-federation.contract.d.ts +2 -0
- package/src/lib/domain/core/build-adapter.contract.d.ts +23 -11
- package/src/lib/domain/core/build-notification-options.contract.d.ts +0 -1
- 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 +6 -2
- package/src/lib/domain/core/federation-options.contract.d.ts +8 -2
- package/src/lib/domain/core/index.d.ts +5 -5
- package/src/lib/domain/core/index.js +1 -0
- package/src/lib/domain/utils/index.d.ts +1 -2
- package/src/lib/domain/utils/keyvaluepair.contract.d.ts +0 -1
- package/src/lib/domain/utils/mapped-path.contract.d.ts +1 -5
- package/src/lib/domain/utils/mapped-path.contract.js +4 -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 +1 -1
- package/src/lib/utils/build-result-map.js +9 -2
- package/src/lib/utils/{bundle-caching.d.ts → cache-persistence.d.ts} +4 -3
- package/src/lib/utils/{bundle-caching.js → cache-persistence.js} +2 -2
- package/src/lib/utils/errors.d.ts +0 -1
- package/src/lib/utils/get-external-imports.d.ts +0 -1
- 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.d.ts +0 -1
- package/src/lib/utils/logger.d.ts +0 -1
- package/src/lib/utils/mapped-paths.d.ts +7 -8
- package/src/lib/utils/mapped-paths.js +14 -12
- package/src/lib/utils/normalize.d.ts +0 -1
- package/src/lib/utils/package-info.d.ts +0 -1
- package/src/lib/utils/rebuild-queue.d.ts +14 -2
- package/src/lib/utils/rebuild-queue.js +32 -12
- package/src/lib/utils/resolve-glob.d.ts +0 -1
- package/src/lib/utils/resolve-glob.js +4 -4
- package/src/lib/utils/resolve-wildcard-keys.d.ts +29 -3
- package/src/lib/utils/resolve-wildcard-keys.js +105 -38
- package/src/lib/utils/rewrite-chunk-imports.d.ts +0 -3
- package/src/lib/utils/rewrite-chunk-imports.js +3 -10
- package/src/config.d.ts.map +0 -1
- package/src/domain.d.ts.map +0 -1
- package/src/index.d.ts.map +0 -1
- package/src/internal.d.ts.map +0 -1
- package/src/lib/config/configuration-context.d.ts.map +0 -1
- package/src/lib/config/default-skip-list.d.ts.map +0 -1
- package/src/lib/config/share-utils.d.ts.map +0 -1
- package/src/lib/config/with-native-federation.d.ts.map +0 -1
- package/src/lib/core/build-adapter.d.ts.map +0 -1
- package/src/lib/core/build-for-federation.d.ts.map +0 -1
- package/src/lib/core/bundle-exposed-and-mappings.d.ts.map +0 -1
- package/src/lib/core/bundle-shared.d.ts.map +0 -1
- package/src/lib/core/default-external-list.d.ts.map +0 -1
- package/src/lib/core/default-server-deps-list.d.ts +0 -3
- package/src/lib/core/default-server-deps-list.d.ts.map +0 -1
- package/src/lib/core/default-server-deps-list.js +0 -6
- package/src/lib/core/federation-builder.d.ts.map +0 -1
- package/src/lib/core/get-externals.d.ts.map +0 -1
- package/src/lib/core/load-federation-config.d.ts +0 -4
- package/src/lib/core/load-federation-config.d.ts.map +0 -1
- package/src/lib/core/load-federation-config.js +0 -18
- package/src/lib/core/remove-unused-deps.d.ts +0 -3
- package/src/lib/core/remove-unused-deps.d.ts.map +0 -1
- package/src/lib/core/remove-unused-deps.js +0 -88
- package/src/lib/core/write-federation-info.d.ts.map +0 -1
- package/src/lib/core/write-import-map.d.ts.map +0 -1
- package/src/lib/domain/config/external-config.contract.d.ts.map +0 -1
- package/src/lib/domain/config/federation-config.contract.d.ts.map +0 -1
- package/src/lib/domain/config/index.d.ts.map +0 -1
- package/src/lib/domain/config/skip-list.contract.d.ts.map +0 -1
- package/src/lib/domain/core/build-adapter.contract.d.ts.map +0 -1
- package/src/lib/domain/core/build-notification-options.contract.d.ts.map +0 -1
- package/src/lib/domain/core/build-params.contract.d.ts +0 -6
- package/src/lib/domain/core/build-params.contract.d.ts.map +0 -1
- package/src/lib/domain/core/federation-info.contract.d.ts.map +0 -1
- package/src/lib/domain/core/federation-options.contract.d.ts.map +0 -1
- package/src/lib/domain/core/index.d.ts.map +0 -1
- package/src/lib/domain/utils/index.d.ts.map +0 -1
- package/src/lib/domain/utils/keyvaluepair.contract.d.ts.map +0 -1
- package/src/lib/domain/utils/mapped-path.contract.d.ts.map +0 -1
- package/src/lib/utils/build-result-map.d.ts.map +0 -1
- package/src/lib/utils/build-utils.d.ts +0 -3
- package/src/lib/utils/build-utils.d.ts.map +0 -1
- package/src/lib/utils/build-utils.js +0 -5
- package/src/lib/utils/bundle-caching.d.ts.map +0 -1
- package/src/lib/utils/errors.d.ts.map +0 -1
- package/src/lib/utils/get-external-imports.d.ts.map +0 -1
- package/src/lib/utils/hash-file.d.ts.map +0 -1
- package/src/lib/utils/logger.d.ts.map +0 -1
- package/src/lib/utils/mapped-paths.d.ts.map +0 -1
- package/src/lib/utils/normalize.d.ts.map +0 -1
- package/src/lib/utils/package-info.d.ts.map +0 -1
- package/src/lib/utils/rebuild-queue.d.ts.map +0 -1
- package/src/lib/utils/resolve-glob.d.ts.map +0 -1
- package/src/lib/utils/resolve-wildcard-keys.d.ts.map +0 -1
- package/src/lib/utils/rewrite-chunk-imports.d.ts.map +0 -1
- /package/src/lib/domain/{core/build-params.contract.js → config/with-native-federation.contract.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softarc/native-federation",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-RC10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"dependencies": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"chalk": "^5.6.2",
|
|
9
9
|
"fast-glob": "^3.3.3",
|
|
10
10
|
"json5": "^2.2.3",
|
|
11
|
-
"esbuild": "^0.
|
|
11
|
+
"esbuild": "^0.28.0"
|
|
12
12
|
},
|
|
13
13
|
"exports": {
|
|
14
14
|
"./package.json": "./package.json",
|
package/src/config.d.ts
CHANGED
|
@@ -2,4 +2,3 @@ export * from './lib/domain/config/index.js';
|
|
|
2
2
|
export { withNativeFederation } from './lib/config/with-native-federation.js';
|
|
3
3
|
export { findRootTsConfigJson, share, shareAll } from './lib/config/share-utils.js';
|
|
4
4
|
export { DEFAULT_SKIP_LIST } from './lib/config/default-skip-list.js';
|
|
5
|
-
//# sourceMappingURL=config.d.ts.map
|
package/src/domain.d.ts
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export { setBuildAdapter } from './lib/core/build-adapter.js';
|
|
2
2
|
export { buildForFederation } from './lib/core/build-for-federation.js';
|
|
3
|
+
export { rebuildForFederation } from './lib/core/rebuild-for-federation.js';
|
|
4
|
+
export { createFederationCache } from './lib/core/federation-cache.js';
|
|
3
5
|
export { bundleExposedAndMappings } from './lib/core/bundle-exposed-and-mappings.js';
|
|
4
6
|
export { getExternals } from './lib/core/get-externals.js';
|
|
5
|
-
export {
|
|
7
|
+
export { normalizeFederationOptions } from './lib/core/normalize-options.js';
|
|
6
8
|
export { writeFederationInfo } from './lib/core/write-federation-info.js';
|
|
7
9
|
export { type BuildHelperParams, federationBuilder } from './lib/core/federation-builder.js';
|
|
8
10
|
export * from './domain.js';
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export { setBuildAdapter } from './lib/core/build-adapter.js';
|
|
2
2
|
export { buildForFederation } from './lib/core/build-for-federation.js';
|
|
3
|
+
export { rebuildForFederation } from './lib/core/rebuild-for-federation.js';
|
|
4
|
+
export { createFederationCache } from './lib/core/federation-cache.js';
|
|
3
5
|
export { bundleExposedAndMappings } from './lib/core/bundle-exposed-and-mappings.js';
|
|
4
6
|
export { getExternals } from './lib/core/get-externals.js';
|
|
5
|
-
export {
|
|
7
|
+
export { normalizeFederationOptions } from './lib/core/normalize-options.js';
|
|
6
8
|
export { writeFederationInfo } from './lib/core/write-federation-info.js';
|
|
7
9
|
export { federationBuilder } from './lib/core/federation-builder.js';
|
|
8
10
|
export * from './domain.js';
|
package/src/internal.d.ts
CHANGED
|
@@ -2,11 +2,12 @@ export * from './lib/utils/build-result-map.js';
|
|
|
2
2
|
export { hashFile } from './lib/utils/hash-file.js';
|
|
3
3
|
export * from './lib/utils/errors.js';
|
|
4
4
|
export { logger, setLogLevel } from './lib/utils/logger.js';
|
|
5
|
-
export type {
|
|
6
|
-
export { RebuildQueue } from './lib/utils/rebuild-queue.js';
|
|
5
|
+
export type { PathToImport } from './lib/domain/utils/mapped-path.contract.js';
|
|
6
|
+
export { RebuildQueue, type TrackResult } from './lib/utils/rebuild-queue.js';
|
|
7
7
|
export { AbortedError } from './lib/utils/errors.js';
|
|
8
|
-
export { createBuildResultMap, lookupInResultMap } from './lib/utils/build-result-map.js';
|
|
8
|
+
export { createBuildResultMap, lookupInResultMap, popFromResultMap, } from './lib/utils/build-result-map.js';
|
|
9
9
|
export { writeImportMap } from './lib/core/write-import-map.js';
|
|
10
10
|
export type { NormalizedExternalConfig, NormalizedSharedExternalsConfig, } from './lib/domain/config/external-config.contract.js';
|
|
11
11
|
export type { NormalizedFederationConfig } from './lib/domain/config/federation-config.contract.js';
|
|
12
|
-
|
|
12
|
+
export { getDefaultCachePath, getChecksum } from './lib/utils/cache-persistence.js';
|
|
13
|
+
export { isInSkipList, prepareSkipList } from './lib/config/default-skip-list.js';
|
package/src/internal.js
CHANGED
|
@@ -4,5 +4,7 @@ export * from './lib/utils/errors.js';
|
|
|
4
4
|
export { logger, setLogLevel } from './lib/utils/logger.js';
|
|
5
5
|
export { RebuildQueue } from './lib/utils/rebuild-queue.js';
|
|
6
6
|
export { AbortedError } from './lib/utils/errors.js';
|
|
7
|
-
export { createBuildResultMap, lookupInResultMap } from './lib/utils/build-result-map.js';
|
|
7
|
+
export { createBuildResultMap, lookupInResultMap, popFromResultMap, } from './lib/utils/build-result-map.js';
|
|
8
8
|
export { writeImportMap } from './lib/core/write-import-map.js';
|
|
9
|
+
export { getDefaultCachePath, getChecksum } from './lib/utils/cache-persistence.js';
|
|
10
|
+
export { isInSkipList, prepareSkipList } from './lib/config/default-skip-list.js';
|
|
@@ -5,4 +5,3 @@ export interface ConfigurationContext {
|
|
|
5
5
|
export declare function useWorkspace(workspaceRoot: string): void;
|
|
6
6
|
export declare function usePackageJson(packageJson?: string): void;
|
|
7
7
|
export declare function getConfigContext(): ConfigurationContext;
|
|
8
|
-
//# sourceMappingURL=configuration-context.d.ts.map
|
|
@@ -2,4 +2,3 @@ import type { PreparedSkipList, SkipList } from '../domain/config/skip-list.cont
|
|
|
2
2
|
export declare const DEFAULT_SKIP_LIST: SkipList;
|
|
3
3
|
export declare function prepareSkipList(skipList: SkipList): PreparedSkipList;
|
|
4
4
|
export declare function isInSkipList(entry: string, skipList: PreparedSkipList): boolean;
|
|
5
|
-
//# sourceMappingURL=default-skip-list.d.ts.map
|
|
@@ -1,26 +1,14 @@
|
|
|
1
1
|
export const DEFAULT_SKIP_LIST = [
|
|
2
|
-
'@softarc/native-federation-runtime',
|
|
3
2
|
'@softarc/native-federation',
|
|
4
3
|
'@softarc/native-federation-core',
|
|
5
4
|
'@softarc/native-federation-node',
|
|
6
5
|
'@softarc/native-federation-esbuild',
|
|
7
|
-
'@
|
|
8
|
-
'@
|
|
6
|
+
'@softarc/native-federation-runtime',
|
|
7
|
+
'@softarc/native-federation-orchestrator',
|
|
8
|
+
'vanilla-native-federation',
|
|
9
9
|
'es-module-shims',
|
|
10
|
-
'zone.js',
|
|
11
10
|
'tslib/',
|
|
12
|
-
'@angular/localize',
|
|
13
|
-
'@angular/localize/init',
|
|
14
|
-
'@angular/localize/tools',
|
|
15
|
-
// '@angular/platform-server',
|
|
16
|
-
// '@angular/platform-server/init',
|
|
17
|
-
// '@angular/ssr',
|
|
18
|
-
/\/schematics(\/|$)/,
|
|
19
|
-
/^@nx\/angular/,
|
|
20
|
-
pkg => pkg.startsWith('@angular/') && !!pkg.match(/\/testing(\/|$)/),
|
|
21
11
|
pkg => pkg.startsWith('@types/'),
|
|
22
|
-
'express',
|
|
23
|
-
// (pkg) => pkg.startsWith('@angular/common/locales'),
|
|
24
12
|
];
|
|
25
13
|
export function prepareSkipList(skipList) {
|
|
26
14
|
return {
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { NormalizedFederationConfig } from '../domain/config/federation-config.contract.js';
|
|
2
|
+
import type { UsedDependencies } from '../domain/utils/used-dependencies.contract.js';
|
|
3
|
+
export declare function removeUnusedDeps(usedDependencies: UsedDependencies, config: NormalizedFederationConfig): NormalizedFederationConfig;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function removeUnusedDeps(usedDependencies, config) {
|
|
2
|
+
const filteredDependencies = Object.entries(config.shared)
|
|
3
|
+
.filter(([shared, meta]) => !!meta.includeSecondaries || usedDependencies.external.has(shared))
|
|
4
|
+
.reduce((acc, [shared, meta]) => ({ ...acc, [shared]: meta }), {});
|
|
5
|
+
return {
|
|
6
|
+
...config,
|
|
7
|
+
shared: filteredDependencies,
|
|
8
|
+
sharedMappings: usedDependencies.internal,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type SkipList } from '../domain/config/skip-list.contract.js';
|
|
2
2
|
import type { ShareAllExternalsOptions, ShareExternalsOptions } from '../domain/config/external-config.contract.js';
|
|
3
|
-
export declare const DEFAULT_SECONDARIES_SKIP_LIST: string[];
|
|
4
3
|
export declare function findRootTsConfigJson(): string;
|
|
5
4
|
export declare function shareAll(config: ShareAllExternalsOptions, opts?: {
|
|
6
5
|
skipList?: SkipList;
|
|
@@ -9,4 +8,3 @@ export declare function shareAll(config: ShareAllExternalsOptions, opts?: {
|
|
|
9
8
|
}): ShareExternalsOptions | null;
|
|
10
9
|
export declare function setInferVersion(infer: boolean): void;
|
|
11
10
|
export declare function share(configuredShareObjects: ShareExternalsOptions, projectPath?: string, skipList?: SkipList): ShareExternalsOptions;
|
|
12
|
-
//# sourceMappingURL=share-utils.d.ts.map
|
|
@@ -5,9 +5,8 @@ import { DEFAULT_SKIP_LIST, isInSkipList, prepareSkipList } from './default-skip
|
|
|
5
5
|
import { findDepPackageJson, getVersionMaps } from '../utils/package-info.js';
|
|
6
6
|
import { getConfigContext } from './configuration-context.js';
|
|
7
7
|
import { logger } from '../utils/logger.js';
|
|
8
|
-
import {
|
|
8
|
+
import { resolvePackageJsonExportsWildcard } from '../utils/resolve-wildcard-keys.js';
|
|
9
9
|
let inferVersion = false;
|
|
10
|
-
export const DEFAULT_SECONDARIES_SKIP_LIST = ['@angular/router/upgrade', '@angular/common/upgrade'];
|
|
11
10
|
export function findRootTsConfigJson() {
|
|
12
11
|
const packageJson = findPackageJson(cwd());
|
|
13
12
|
const projectRoot = path.dirname(packageJson);
|
|
@@ -49,9 +48,6 @@ function lookupVersionInMap(key, versions) {
|
|
|
49
48
|
else {
|
|
50
49
|
key = parts[0];
|
|
51
50
|
}
|
|
52
|
-
if (key.toLowerCase() === '@angular-architects/module-federation-runtime') {
|
|
53
|
-
key = '@angular-architects/module-federation';
|
|
54
|
-
}
|
|
55
51
|
if (!versions[key]) {
|
|
56
52
|
return null;
|
|
57
53
|
}
|
|
@@ -82,7 +78,7 @@ function findSecondaries(libPath, excludes, shareObject, preparedSkipList) {
|
|
|
82
78
|
return acc;
|
|
83
79
|
}
|
|
84
80
|
function getSecondaries(includeSecondaries, libPath, key, shareObject, preparedSkipList) {
|
|
85
|
-
let exclude = [
|
|
81
|
+
let exclude = [];
|
|
86
82
|
let resolveGlob = false;
|
|
87
83
|
if (typeof includeSecondaries === 'object') {
|
|
88
84
|
if (Array.isArray(includeSecondaries.skip)) {
|
|
@@ -166,7 +162,7 @@ function resolveGlobSecondaries(key, libPath, parent, secondaryName, entry, excl
|
|
|
166
162
|
if (key.includes('*')) {
|
|
167
163
|
if (!resolveGlob)
|
|
168
164
|
return items;
|
|
169
|
-
const expanded =
|
|
165
|
+
const expanded = resolvePackageJsonExportsWildcard(key, entry, libPath);
|
|
170
166
|
items = expanded
|
|
171
167
|
.map(e => ({
|
|
172
168
|
key: path.join(parent, e.key),
|
|
@@ -221,10 +217,10 @@ export function shareAll(config, opts = {}) {
|
|
|
221
217
|
// }
|
|
222
218
|
const versionMaps = getVersionMaps(projectPath, projectPath);
|
|
223
219
|
const sharedExternals = {};
|
|
224
|
-
const
|
|
220
|
+
const skipList = opts.skipList ?? DEFAULT_SKIP_LIST;
|
|
225
221
|
for (const versions of versionMaps) {
|
|
226
222
|
for (const key in versions) {
|
|
227
|
-
if (isInSkipList(key,
|
|
223
|
+
if (isInSkipList(key, prepareSkipList(skipList))) {
|
|
228
224
|
continue;
|
|
229
225
|
}
|
|
230
226
|
if (!!opts.overrides && Object.keys(opts.overrides).some(o => key.startsWith(o))) {
|
|
@@ -238,10 +234,8 @@ export function shareAll(config, opts = {}) {
|
|
|
238
234
|
}
|
|
239
235
|
}
|
|
240
236
|
return {
|
|
241
|
-
...share(sharedExternals, opts.projectPath,
|
|
242
|
-
...(!opts.overrides
|
|
243
|
-
? {}
|
|
244
|
-
: share(opts.overrides, opts.projectPath, opts.skipList ?? DEFAULT_SKIP_LIST)),
|
|
237
|
+
...share(sharedExternals, opts.projectPath, skipList),
|
|
238
|
+
...(!opts.overrides ? {} : share(opts.overrides, opts.projectPath, skipList)),
|
|
245
239
|
};
|
|
246
240
|
}
|
|
247
241
|
function inferProjectPath(projectPath) {
|
|
@@ -1,88 +1,70 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getRawMappedPaths } from '../utils/mapped-paths.js';
|
|
2
2
|
import { shareAll, findRootTsConfigJson } from './share-utils.js';
|
|
3
3
|
import { isInSkipList, prepareSkipList } from './default-skip-list.js';
|
|
4
4
|
import { logger } from '../utils/logger.js';
|
|
5
|
-
import { DEFAULT_SERVER_DEPS_LIST } from '../core/default-server-deps-list.js';
|
|
6
5
|
export function withNativeFederation(config) {
|
|
7
6
|
const skip = prepareSkipList(config.skip ?? []);
|
|
7
|
+
const chunks = config.chunks ?? true;
|
|
8
8
|
const normalized = {
|
|
9
|
+
$type: 'classic',
|
|
9
10
|
name: config.name ?? '',
|
|
10
11
|
exposes: config.exposes ?? {},
|
|
11
|
-
shared: normalizeShared(config, skip),
|
|
12
|
-
sharedMappings:
|
|
12
|
+
shared: normalizeShared(config, skip, chunks),
|
|
13
|
+
sharedMappings: removeSkippedMappings(config, skip),
|
|
14
|
+
chunks,
|
|
13
15
|
skip,
|
|
14
16
|
externals: config.externals ?? [],
|
|
15
17
|
features: {
|
|
16
18
|
mappingVersion: config.features?.mappingVersion ?? false,
|
|
17
|
-
ignoreUnusedDeps: config.features?.ignoreUnusedDeps ??
|
|
19
|
+
ignoreUnusedDeps: config.features?.ignoreUnusedDeps ?? true,
|
|
20
|
+
denseChunking: config.features?.denseChunking ?? false,
|
|
18
21
|
},
|
|
22
|
+
...(config.shareScope && { shareScope: config.shareScope }),
|
|
19
23
|
};
|
|
20
|
-
// This is for being backwards compatible
|
|
21
|
-
if (!normalized.features.ignoreUnusedDeps) {
|
|
22
|
-
normalized.shared = filterShared(normalized.shared);
|
|
23
|
-
}
|
|
24
24
|
return normalized;
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
const keys = Object.keys(shared).filter(k => !k.startsWith('@angular/common/locales'));
|
|
28
|
-
const filtered = keys.reduce((acc, curr) => ({
|
|
29
|
-
...acc,
|
|
30
|
-
[curr]: shared[curr],
|
|
31
|
-
}), {});
|
|
32
|
-
return filtered;
|
|
33
|
-
}
|
|
34
|
-
function normalizeShared(config, skip) {
|
|
26
|
+
function normalizeShared(config, skip, chunks) {
|
|
35
27
|
let result = {};
|
|
36
|
-
const shared = config.shared
|
|
37
|
-
|
|
38
|
-
result = shareAll({
|
|
28
|
+
const shared = config.shared ??
|
|
29
|
+
shareAll({
|
|
39
30
|
singleton: true,
|
|
40
31
|
strictVersion: true,
|
|
41
32
|
requiredVersion: 'auto',
|
|
42
33
|
platform: 'browser',
|
|
43
34
|
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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 {
|
|
47
55
|
...acc,
|
|
48
|
-
[
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
strictVersion: shared[cur].strictVersion ?? false,
|
|
52
|
-
version: shared[cur].version,
|
|
53
|
-
includeSecondaries: shared[cur].includeSecondaries,
|
|
54
|
-
packageInfo: shared[cur].packageInfo,
|
|
55
|
-
platform: shared[cur].platform ?? getDefaultPlatform(cur),
|
|
56
|
-
build: shared[cur].build ?? 'default',
|
|
57
|
-
},
|
|
58
|
-
}), {});
|
|
59
|
-
//result = share(result) as Record<string, NormalizedSharedConfig>;
|
|
60
|
-
}
|
|
56
|
+
[key]: normalizedConfig,
|
|
57
|
+
};
|
|
58
|
+
}, {});
|
|
61
59
|
result = Object.keys(result)
|
|
62
60
|
.filter(key => !isInSkipList(key, skip))
|
|
63
|
-
.reduce((acc, cur) => ({
|
|
64
|
-
...acc,
|
|
65
|
-
[cur]: result[cur],
|
|
66
|
-
}), {});
|
|
61
|
+
.reduce((acc, cur) => ({ ...acc, [cur]: result[cur] }), {});
|
|
67
62
|
return result;
|
|
68
63
|
}
|
|
69
|
-
function
|
|
64
|
+
function removeSkippedMappings(config, skipList) {
|
|
70
65
|
const rootTsConfigPath = findRootTsConfigJson();
|
|
71
|
-
const paths =
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const result = paths.filter(p => !isInSkipList(p.key, skip) && !p.key.includes('*'));
|
|
76
|
-
if (paths.find(p => p.key.includes('*'))) {
|
|
77
|
-
logger.warn('Sharing mapped paths with wildcards (*) not supported');
|
|
78
|
-
}
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
function getDefaultPlatform(cur) {
|
|
82
|
-
if (DEFAULT_SERVER_DEPS_LIST.find(e => cur.startsWith(e))) {
|
|
83
|
-
return 'node';
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
return 'browser';
|
|
87
|
-
}
|
|
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 }), {});
|
|
88
70
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { logger } from '../utils/logger.js';
|
|
2
|
-
let _buildAdapter =
|
|
3
|
-
// TODO: add logger
|
|
4
|
-
logger.error('NF is missing a build adapter!');
|
|
5
|
-
return [];
|
|
6
|
-
};
|
|
2
|
+
let _buildAdapter = null;
|
|
7
3
|
export function setBuildAdapter(buildAdapter) {
|
|
8
4
|
_buildAdapter = buildAdapter;
|
|
9
5
|
}
|
|
10
6
|
export function getBuildAdapter() {
|
|
7
|
+
if (!_buildAdapter) {
|
|
8
|
+
logger.error('Please set a BuildAdapter!');
|
|
9
|
+
throw new Error('BuildAdapter not set');
|
|
10
|
+
}
|
|
11
11
|
return _buildAdapter;
|
|
12
12
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import type { FederationInfo } from '../domain/core/federation-info.contract.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { NormalizedFederationOptions } from '../domain/core/federation-options.contract.js';
|
|
3
3
|
import type { NormalizedFederationConfig } from '../domain/config/federation-config.contract.js';
|
|
4
|
-
|
|
5
|
-
export declare const defaultBuildParams: BuildParams;
|
|
6
|
-
export declare function buildForFederation(config: NormalizedFederationConfig, fedOptions: FederationOptions, externals: string[], buildParams?: BuildParams): Promise<FederationInfo>;
|
|
7
|
-
//# sourceMappingURL=build-for-federation.d.ts.map
|
|
4
|
+
export declare function buildForFederation(config: NormalizedFederationConfig, fedOptions: NormalizedFederationOptions, externals: string[], signal?: AbortSignal): Promise<FederationInfo>;
|
|
@@ -3,88 +3,92 @@ import { bundleShared } from './bundle-shared.js';
|
|
|
3
3
|
import { writeFederationInfo } from './write-federation-info.js';
|
|
4
4
|
import { writeImportMap } from './write-import-map.js';
|
|
5
5
|
import { logger } from '../utils/logger.js';
|
|
6
|
-
import { getCachePath } from './../utils/bundle-caching.js';
|
|
7
6
|
import { normalizePackageName } from '../utils/normalize.js';
|
|
8
7
|
import { AbortedError } from '../utils/errors.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (
|
|
18
|
-
const start = process.hrtime();
|
|
19
|
-
artefactInfo = await bundleExposedAndMappings(config, fedOptions, externals, signal);
|
|
20
|
-
logger.measure(start, '[build artifacts] - To bundle all mappings and exposed.');
|
|
21
|
-
if (signal?.aborted)
|
|
22
|
-
throw new AbortedError('[buildForFederation] After exposed-and-mappings bundle');
|
|
23
|
-
}
|
|
24
|
-
const exposedInfo = !artefactInfo ? describeExposed(config, fedOptions) : artefactInfo.exposes;
|
|
25
|
-
const normalizedCacheFolder = normalizePackageName(config.name);
|
|
26
|
-
if (normalizedCacheFolder.length < 1) {
|
|
27
|
-
logger.warn("Project name in 'federation.config.js' is empty, defaulting to 'shell' cache folder (could collide with other projects in the workspace).");
|
|
28
|
-
}
|
|
29
|
-
const cacheProjectFolder = normalizedCacheFolder.length < 1 ? 'shell' : normalizedCacheFolder;
|
|
30
|
-
const pathToCache = getCachePath(fedOptions.workspaceRoot, cacheProjectFolder);
|
|
31
|
-
if (!buildParams.skipShared && sharedPackageInfoCache.length > 0) {
|
|
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) {
|
|
32
17
|
logger.info('Checksum matched, re-using cached externals.');
|
|
33
18
|
}
|
|
34
|
-
if (
|
|
19
|
+
if (fedOptions.federationCache.externals.length === 0) {
|
|
35
20
|
const { sharedBrowser, sharedServer, separateBrowser, separateServer } = splitShared(config.shared);
|
|
36
21
|
if (Object.keys(sharedBrowser).length > 0) {
|
|
37
|
-
|
|
22
|
+
logger.info(`Bundling external npm packages with bundle type 'browser-shared'`);
|
|
38
23
|
const start = process.hrtime();
|
|
39
|
-
const sharedPackageInfoBrowser = await bundleShared(sharedBrowser, config, fedOptions, externals, 'browser',
|
|
40
|
-
logger.measure(start, '
|
|
41
|
-
|
|
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);
|
|
42
27
|
if (signal?.aborted)
|
|
43
28
|
throw new AbortedError('[buildForFederation] After shared-browser bundle');
|
|
44
29
|
}
|
|
45
30
|
if (Object.keys(sharedServer).length > 0) {
|
|
46
|
-
|
|
31
|
+
logger.info(`Bundling external npm packages with bundle type 'server-shared'`);
|
|
47
32
|
const start = process.hrtime();
|
|
48
|
-
const sharedPackageInfoServer = await bundleShared(sharedServer, config, fedOptions, externals, 'node',
|
|
49
|
-
logger.measure(start, '
|
|
50
|
-
|
|
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);
|
|
51
36
|
if (signal?.aborted)
|
|
52
37
|
throw new AbortedError('[buildForFederation] After shared-node bundle');
|
|
53
38
|
}
|
|
54
39
|
if (Object.keys(separateBrowser).length > 0) {
|
|
55
|
-
|
|
40
|
+
logger.info(`Bundling external npm packages with bundle type 'browser-separate'`);
|
|
56
41
|
const start = process.hrtime();
|
|
57
|
-
const separatePackageInfoBrowser = await bundleSeparatePackages(separateBrowser, externals, config, fedOptions, 'browser'
|
|
58
|
-
logger.measure(start, '
|
|
59
|
-
|
|
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);
|
|
60
45
|
if (signal?.aborted)
|
|
61
46
|
throw new AbortedError('[buildForFederation] After separate-browser bundle');
|
|
62
47
|
}
|
|
63
48
|
if (Object.keys(separateServer).length > 0) {
|
|
64
|
-
|
|
49
|
+
logger.info(`Bundling external npm packages with bundle type 'node-separate'`);
|
|
65
50
|
const start = process.hrtime();
|
|
66
|
-
const separatePackageInfoServer = await bundleSeparatePackages(separateServer, externals, config, fedOptions, 'node'
|
|
67
|
-
logger.measure(start, '
|
|
68
|
-
|
|
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);
|
|
69
54
|
}
|
|
70
55
|
if (signal?.aborted)
|
|
71
56
|
throw new AbortedError('[buildForFederation] After separate-node bundle');
|
|
72
57
|
}
|
|
73
|
-
|
|
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
|
|
74
66
|
? describeSharedMappings(config, fedOptions)
|
|
75
|
-
:
|
|
76
|
-
const
|
|
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
|
+
});
|
|
74
|
+
}
|
|
77
75
|
const buildNotificationsEndpoint = fedOptions.buildNotifications?.enable && fedOptions.dev
|
|
78
76
|
? fedOptions.buildNotifications?.endpoint
|
|
79
77
|
: undefined;
|
|
80
78
|
const federationInfo = {
|
|
81
79
|
name: config.name,
|
|
82
|
-
shared:
|
|
80
|
+
shared: sharedExternals,
|
|
83
81
|
exposes: exposedInfo,
|
|
84
82
|
buildNotificationsEndpoint,
|
|
85
83
|
};
|
|
84
|
+
if (fedOptions.federationCache.chunks) {
|
|
85
|
+
federationInfo.chunks = fedOptions.federationCache.chunks;
|
|
86
|
+
}
|
|
87
|
+
if (artifactInfo?.chunks) {
|
|
88
|
+
federationInfo.chunks = { ...(federationInfo.chunks ?? {}), ...artifactInfo?.chunks };
|
|
89
|
+
}
|
|
86
90
|
writeFederationInfo(federationInfo, fedOptions);
|
|
87
|
-
writeImportMap(
|
|
91
|
+
writeImportMap(fedOptions.federationCache, fedOptions);
|
|
88
92
|
return federationInfo;
|
|
89
93
|
}
|
|
90
94
|
function inferPackageFromSecondary(secondary) {
|
|
@@ -94,28 +98,33 @@ function inferPackageFromSecondary(secondary) {
|
|
|
94
98
|
}
|
|
95
99
|
return parts[0];
|
|
96
100
|
}
|
|
97
|
-
async function bundleSeparatePackages(separateBrowser, externals, config, fedOptions,
|
|
101
|
+
async function bundleSeparatePackages(separateBrowser, externals, config, fedOptions, buildOptions) {
|
|
98
102
|
const groupedByPackage = {};
|
|
99
103
|
for (const [key, shared] of Object.entries(separateBrowser)) {
|
|
100
104
|
const packageName = shared.build === 'separate' ? key : inferPackageFromSecondary(key);
|
|
101
105
|
if (!groupedByPackage[packageName]) {
|
|
102
|
-
groupedByPackage[packageName] = {
|
|
106
|
+
groupedByPackage[packageName] = {
|
|
107
|
+
chunks: shared.chunks,
|
|
108
|
+
entries: {},
|
|
109
|
+
};
|
|
103
110
|
}
|
|
104
|
-
groupedByPackage[packageName][key] = shared;
|
|
111
|
+
groupedByPackage[packageName].entries[key] = shared;
|
|
105
112
|
}
|
|
106
|
-
const bundlePromises = Object.entries(groupedByPackage).map(async ([packageName,
|
|
107
|
-
return bundleShared(
|
|
108
|
-
|
|
109
|
-
|
|
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)}`,
|
|
110
118
|
});
|
|
111
119
|
});
|
|
112
120
|
const buildResults = await Promise.all(bundlePromises);
|
|
113
|
-
return buildResults.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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: [] });
|
|
119
128
|
}
|
|
120
129
|
function splitShared(shared) {
|
|
121
130
|
const sharedServer = {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ArtifactInfo, ExposesInfo, SharedInfo } from '../domain/core/federation-info.contract.js';
|
|
2
2
|
import type { NormalizedFederationConfig } from '../domain/config/federation-config.contract.js';
|
|
3
|
-
import { type
|
|
4
|
-
export declare function bundleExposedAndMappings(config: NormalizedFederationConfig, fedOptions:
|
|
5
|
-
export declare function describeExposed(config: NormalizedFederationConfig, options:
|
|
6
|
-
export declare function describeSharedMappings(config: NormalizedFederationConfig, fedOptions:
|
|
7
|
-
//# sourceMappingURL=bundle-exposed-and-mappings.d.ts.map
|
|
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>;
|