@softarc/native-federation 4.1.2 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softarc/native-federation",
3
- "version": "4.1.2",
3
+ "version": "4.1.3",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -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,
@@ -24,6 +24,14 @@ export function withNativeFederation(config) {
24
24
  };
25
25
  return normalized;
26
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
+ }
27
35
  function normalizeShared(config, skip, chunks) {
28
36
  let result = {};
29
37
  const shared = config.shared ??
@@ -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, entry]) => {
21
+ const exposes = Object.entries(config.exposes).map(([key, expose]) => {
22
22
  const outFilePath = key + '.js';
23
- return { fileName: entry, outName: outFilePath, key };
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
  : {
@@ -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 localPath = normalize(path.normalize(path.join(options.workspaceRoot, config.exposes[key])));
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
  : {
@@ -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,
@@ -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>;
@@ -21,7 +25,7 @@ export interface FederationConfig {
21
25
  export interface NormalizedFederationConfig {
22
26
  $type: 'classic';
23
27
  name: string;
24
- exposes: Record<string, string>;
28
+ exposes: Record<string, ExposeEntry>;
25
29
  shared: NormalizedSharedExternalsConfig;
26
30
  sharedMappings: PathToImport;
27
31
  skip: PreparedSkipList;
@@ -24,6 +24,7 @@ export type IntegrityMap = Record<string, string>;
24
24
  export interface ExposesInfo {
25
25
  key: string;
26
26
  outFileName: string;
27
+ element?: string;
27
28
  dev?: {
28
29
  entryPoint: string;
29
30
  };
@@ -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,5 @@
1
+ export type FederationManifest = Record<string, string | {
2
+ url: string;
3
+ integrity?: string;
4
+ main?: string;
5
+ }>;
@@ -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, 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)