@softarc/native-federation 4.1.1 → 4.1.3
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 +1 -1
- package/src/config.d.ts +1 -1
- package/src/config.js +1 -1
- package/src/lib/config/share-utils.js +2 -1
- package/src/lib/config/with-native-federation.js +10 -1
- package/src/lib/core/build-for-federation.js +1 -1
- package/src/lib/core/bundle-exposed-and-mappings.js +7 -4
- package/src/lib/core/bundle-shared.js +2 -2
- package/src/lib/core/normalize-options.js +1 -1
- package/src/lib/core/rebuild-for-federation.js +1 -1
- package/src/lib/domain/config/federation-config.contract.d.ts +8 -2
- package/src/lib/domain/core/federation-info.contract.d.ts +1 -0
- package/src/lib/domain/core/federation-options.contract.d.ts +0 -1
- package/src/lib/domain/core/index.d.ts +1 -0
- package/src/lib/domain/core/manifest.contract.d.ts +5 -0
- package/src/lib/domain/core/manifest.contract.js +1 -0
- package/src/lib/utils/get-used-dependencies.d.ts +2 -1
- package/src/lib/utils/get-used-dependencies.js +1 -1
package/package.json
CHANGED
package/src/config.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from './lib/domain/config/index.js';
|
|
2
2
|
export { withNativeFederation } from './lib/config/with-native-federation.js';
|
|
3
|
-
export { findRootTsConfigJson, share, shareAll } from './lib/config/share-utils.js';
|
|
3
|
+
export { findRootTsConfigJson, share, shareAll, setInferVersion, } from './lib/config/share-utils.js';
|
|
4
4
|
export { DEFAULT_SKIP_LIST } from './lib/config/default-skip-list.js';
|
package/src/config.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from './lib/domain/config/index.js';
|
|
2
2
|
export { withNativeFederation } from './lib/config/with-native-federation.js';
|
|
3
|
-
export { findRootTsConfigJson, share, shareAll } from './lib/config/share-utils.js';
|
|
3
|
+
export { findRootTsConfigJson, share, shareAll, setInferVersion, } from './lib/config/share-utils.js';
|
|
4
4
|
export { DEFAULT_SKIP_LIST } from './lib/config/default-skip-list.js';
|
|
@@ -264,7 +264,8 @@ export function share(configuredShareObjects, projectPath = '', skipList = DEFAU
|
|
|
264
264
|
includeSecondaries = false;
|
|
265
265
|
const shareObject = shareObjects[key];
|
|
266
266
|
if (shareObject.requiredVersion === 'auto' ||
|
|
267
|
-
(inferVersion && typeof shareObject.requiredVersion === 'undefined')
|
|
267
|
+
(inferVersion && typeof shareObject.requiredVersion === 'undefined') ||
|
|
268
|
+
shareObject.requiredVersion.length < 1) {
|
|
268
269
|
const version = lookupVersion(key, projectPath);
|
|
269
270
|
shareObject.requiredVersion = version;
|
|
270
271
|
shareObject.version = version.replace(/^\D*/, '');
|
|
@@ -8,7 +8,7 @@ export function withNativeFederation(config) {
|
|
|
8
8
|
const normalized = {
|
|
9
9
|
$type: 'classic',
|
|
10
10
|
name: config.name ?? '',
|
|
11
|
-
exposes: config.exposes
|
|
11
|
+
exposes: normalizeExposes(config.exposes),
|
|
12
12
|
shared: normalizeShared(config, skip, chunks),
|
|
13
13
|
sharedMappings: removeSkippedMappings(config, skip),
|
|
14
14
|
chunks,
|
|
@@ -18,11 +18,20 @@ export function withNativeFederation(config) {
|
|
|
18
18
|
mappingVersion: config.features?.mappingVersion ?? true,
|
|
19
19
|
ignoreUnusedDeps: config.features?.ignoreUnusedDeps ?? true,
|
|
20
20
|
denseChunking: config.features?.denseChunking ?? false,
|
|
21
|
+
integrityHashes: config.features?.integrityHashes ?? false,
|
|
21
22
|
},
|
|
22
23
|
...(config.shareScope && { shareScope: config.shareScope }),
|
|
23
24
|
};
|
|
24
25
|
return normalized;
|
|
25
26
|
}
|
|
27
|
+
function normalizeExposes(exposes) {
|
|
28
|
+
if (!exposes)
|
|
29
|
+
return {};
|
|
30
|
+
return Object.fromEntries(Object.entries(exposes).map(([key, value]) => [
|
|
31
|
+
key,
|
|
32
|
+
typeof value === 'string' ? { file: value } : value,
|
|
33
|
+
]));
|
|
34
|
+
}
|
|
26
35
|
function normalizeShared(config, skip, chunks) {
|
|
27
36
|
let result = {};
|
|
28
37
|
const shared = config.shared ??
|
|
@@ -87,7 +87,7 @@ export async function buildForFederation(config, fedOptions, externals, signal)
|
|
|
87
87
|
if (artifactInfo?.chunks) {
|
|
88
88
|
federationInfo.chunks = { ...(federationInfo.chunks ?? {}), ...artifactInfo?.chunks };
|
|
89
89
|
}
|
|
90
|
-
if (
|
|
90
|
+
if (config.features.integrityHashes) {
|
|
91
91
|
federationInfo.integrity = {
|
|
92
92
|
...(fedOptions.federationCache.integrity ?? {}),
|
|
93
93
|
...(artifactInfo?.integrity ?? {}),
|
|
@@ -18,9 +18,9 @@ export async function bundleExposedAndMappings(config, fedOptions, externals, mo
|
|
|
18
18
|
key: mappedImport,
|
|
19
19
|
};
|
|
20
20
|
});
|
|
21
|
-
const exposes = Object.entries(config.exposes).map(([key,
|
|
21
|
+
const exposes = Object.entries(config.exposes).map(([key, expose]) => {
|
|
22
22
|
const outFilePath = key + '.js';
|
|
23
|
-
return { fileName:
|
|
23
|
+
return { fileName: expose.file, outName: outFilePath, key, element: expose.element };
|
|
24
24
|
});
|
|
25
25
|
const entryPoints = [...shared, ...exposes];
|
|
26
26
|
const hash = !fedOptions.dev;
|
|
@@ -75,6 +75,7 @@ export async function bundleExposedAndMappings(config, fedOptions, externals, mo
|
|
|
75
75
|
exposedResult.push({
|
|
76
76
|
key: item.key,
|
|
77
77
|
outFileName: path.basename(distEntryFile),
|
|
78
|
+
...(item.element && { element: item.element }),
|
|
78
79
|
dev: !fedOptions.dev
|
|
79
80
|
? undefined
|
|
80
81
|
: {
|
|
@@ -100,7 +101,7 @@ export async function bundleExposedAndMappings(config, fedOptions, externals, mo
|
|
|
100
101
|
}
|
|
101
102
|
// Must run after rewriteChunkImports so SRI matches the final on-disk bytes.
|
|
102
103
|
let integrity;
|
|
103
|
-
if (
|
|
104
|
+
if (config.features.integrityHashes) {
|
|
104
105
|
integrity = {};
|
|
105
106
|
for (const filePath of [...entryFiles, ...chunkPaths]) {
|
|
106
107
|
if (!fs.existsSync(filePath))
|
|
@@ -113,10 +114,12 @@ export async function bundleExposedAndMappings(config, fedOptions, externals, mo
|
|
|
113
114
|
export function describeExposed(config, options) {
|
|
114
115
|
const result = [];
|
|
115
116
|
for (const key in config.exposes) {
|
|
116
|
-
const
|
|
117
|
+
const expose = config.exposes[key];
|
|
118
|
+
const localPath = normalize(path.normalize(path.join(options.workspaceRoot, expose.file)));
|
|
117
119
|
result.push({
|
|
118
120
|
key,
|
|
119
121
|
outFileName: '',
|
|
122
|
+
...(expose.element && { element: expose.element }),
|
|
120
123
|
dev: !options.dev
|
|
121
124
|
? undefined
|
|
122
125
|
: {
|
|
@@ -22,7 +22,7 @@ export async function bundleShared(sharedBundles, config, fedOptions, externals,
|
|
|
22
22
|
logger.debug(`Checksum of ${buildOptions.bundleName} matched, Skipped artifact bundling`);
|
|
23
23
|
bundleCache.copyFiles(path.join(fedOptions.workspaceRoot, fedOptions.outputPath));
|
|
24
24
|
let integrity = cacheMetadata.integrity;
|
|
25
|
-
if (
|
|
25
|
+
if (config.features.integrityHashes && !integrity) {
|
|
26
26
|
integrity = computeIntegrityForFiles(cacheMetadata.files, fedOptions.federationCache.cachePath);
|
|
27
27
|
}
|
|
28
28
|
return {
|
|
@@ -122,7 +122,7 @@ export async function bundleShared(sharedBundles, config, fedOptions, externals,
|
|
|
122
122
|
}
|
|
123
123
|
const persistedFiles = bundleResult.map(r => r.fileName.split(path.sep).pop() ?? r.fileName);
|
|
124
124
|
// Must run after rewriteImports so SRI matches the bytes copied to dist.
|
|
125
|
-
const integrity =
|
|
125
|
+
const integrity = config.features.integrityHashes
|
|
126
126
|
? computeIntegrityForFiles(persistedFiles, fedOptions.federationCache.cachePath)
|
|
127
127
|
: undefined;
|
|
128
128
|
bundleCache.persist({
|
|
@@ -25,7 +25,7 @@ export async function normalizeFederationOptions(options, cache) {
|
|
|
25
25
|
createFederationCache(getDefaultCachePath(options.workspaceRoot));
|
|
26
26
|
const normalizedOptions = {
|
|
27
27
|
...options,
|
|
28
|
-
entryPoints: options.entryPoints ?? Object.values(config.exposes ?? {}),
|
|
28
|
+
entryPoints: options.entryPoints ?? Object.values(config.exposes ?? {}).map(e => e.file),
|
|
29
29
|
projectName: resolveProjectName(options.projectName ?? config.name),
|
|
30
30
|
cacheExternalArtifacts: options.cacheExternalArtifacts ?? true,
|
|
31
31
|
federationCache,
|
|
@@ -31,7 +31,7 @@ export async function rebuildForFederation(config, fedOptions, externals, modifi
|
|
|
31
31
|
if (artifactInfo?.chunks) {
|
|
32
32
|
federationInfo.chunks = { ...(federationInfo.chunks ?? {}), ...artifactInfo?.chunks };
|
|
33
33
|
}
|
|
34
|
-
if (
|
|
34
|
+
if (config.features.integrityHashes) {
|
|
35
35
|
federationInfo.integrity = {
|
|
36
36
|
...(federationCache.integrity ?? {}),
|
|
37
37
|
...(artifactInfo?.integrity ?? {}),
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { PreparedSkipList, SkipList } from './skip-list.contract.js';
|
|
2
2
|
import type { PathToImport } from '../utils/mapped-path.contract.js';
|
|
3
3
|
import type { NormalizedSharedExternalsConfig, SharedExternalsConfig } from './external-config.contract.js';
|
|
4
|
+
export type ExposeEntry = {
|
|
5
|
+
file: string;
|
|
6
|
+
element?: string;
|
|
7
|
+
};
|
|
4
8
|
export interface FederationConfig {
|
|
5
9
|
name?: string;
|
|
6
|
-
exposes?: Record<string, string>;
|
|
10
|
+
exposes?: Record<string, string | ExposeEntry>;
|
|
7
11
|
shared?: SharedExternalsConfig;
|
|
8
12
|
platform?: 'browser' | 'node';
|
|
9
13
|
sharedMappings?: Array<string>;
|
|
@@ -15,12 +19,13 @@ export interface FederationConfig {
|
|
|
15
19
|
mappingVersion?: boolean;
|
|
16
20
|
ignoreUnusedDeps?: boolean;
|
|
17
21
|
denseChunking?: boolean;
|
|
22
|
+
integrityHashes?: boolean;
|
|
18
23
|
};
|
|
19
24
|
}
|
|
20
25
|
export interface NormalizedFederationConfig {
|
|
21
26
|
$type: 'classic';
|
|
22
27
|
name: string;
|
|
23
|
-
exposes: Record<string,
|
|
28
|
+
exposes: Record<string, ExposeEntry>;
|
|
24
29
|
shared: NormalizedSharedExternalsConfig;
|
|
25
30
|
sharedMappings: PathToImport;
|
|
26
31
|
skip: PreparedSkipList;
|
|
@@ -31,5 +36,6 @@ export interface NormalizedFederationConfig {
|
|
|
31
36
|
mappingVersion: boolean;
|
|
32
37
|
ignoreUnusedDeps: boolean;
|
|
33
38
|
denseChunking: boolean;
|
|
39
|
+
integrityHashes: boolean;
|
|
34
40
|
};
|
|
35
41
|
}
|
|
@@ -13,7 +13,6 @@ export interface FederationOptions {
|
|
|
13
13
|
packageJson?: string;
|
|
14
14
|
entryPoints?: string[];
|
|
15
15
|
buildNotifications?: BuildNotificationOptions;
|
|
16
|
-
integrity?: boolean;
|
|
17
16
|
}
|
|
18
17
|
export interface NormalizedFederationOptions<TBundlerCache = unknown> extends FederationOptions {
|
|
19
18
|
federationCache: FederationCache<TBundlerCache>;
|
|
@@ -4,3 +4,4 @@ export type { FederationOptions, NormalizedFederationOptions, } from './federati
|
|
|
4
4
|
export type { EntryPoint, NFBuildAdapterOptions, NFBuildAdapter, NFBuildAdapterResult, NFBuildAdapterContext, } from './build-adapter.contract.js';
|
|
5
5
|
export { CHUNK_PREFIX, toChunkImport } from './chunk.js';
|
|
6
6
|
export type { FederationCache } from './federation-cache.contract.js';
|
|
7
|
+
export type { FederationManifest } from './manifest.contract.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type PathToImport } from '../domain/utils/mapped-path.contract.js';
|
|
2
2
|
import { type UsedDependencies } from '../domain/utils/used-dependencies.contract.js';
|
|
3
|
+
import { type ExposeEntry } from '../domain/config/federation-config.contract.js';
|
|
3
4
|
export declare function getUsedDependenciesFactory(workspaceRoot: string, fallbackEntryPoints?: string[]): (config: {
|
|
4
5
|
name?: string;
|
|
5
|
-
exposes?: Record<string,
|
|
6
|
+
exposes?: Record<string, ExposeEntry>;
|
|
6
7
|
sharedMappings: PathToImport;
|
|
7
8
|
}) => UsedDependencies;
|
|
@@ -5,7 +5,7 @@ import { getExternalImports as extractExternalImports } from './get-external-imp
|
|
|
5
5
|
import * as path from 'path';
|
|
6
6
|
export function getUsedDependenciesFactory(workspaceRoot, fallbackEntryPoints) {
|
|
7
7
|
return config => {
|
|
8
|
-
let entryPoints = Object.values(config.exposes ?? {});
|
|
8
|
+
let entryPoints = Object.values(config.exposes ?? {}).map(e => e.file);
|
|
9
9
|
if (entryPoints.length < 1)
|
|
10
10
|
entryPoints = fallbackEntryPoints;
|
|
11
11
|
if (!entryPoints || entryPoints.length < 1)
|