@softarc/native-federation 4.1.0 → 4.1.2

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.0",
3
+ "version": "4.1.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "dependencies": {
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*/, '');
@@ -15,9 +15,10 @@ export function withNativeFederation(config) {
15
15
  skip,
16
16
  externals: config.externals ?? [],
17
17
  features: {
18
- mappingVersion: config.features?.mappingVersion ?? false,
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
  };
@@ -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 (fedOptions.integrity) {
90
+ if (config.features.integrityHashes) {
91
91
  federationInfo.integrity = {
92
92
  ...(fedOptions.federationCache.integrity ?? {}),
93
93
  ...(artifactInfo?.integrity ?? {}),
@@ -4,3 +4,4 @@ import { type NormalizedFederationOptions } from '../domain/core/federation-opti
4
4
  export declare function bundleExposedAndMappings(config: NormalizedFederationConfig, fedOptions: NormalizedFederationOptions, externals: string[], modifiedFiles?: string[], signal?: AbortSignal): Promise<ArtifactInfo>;
5
5
  export declare function describeExposed(config: NormalizedFederationConfig, options: NormalizedFederationOptions): Array<ExposesInfo>;
6
6
  export declare function describeSharedMappings(config: NormalizedFederationConfig, fedOptions: NormalizedFederationOptions): Array<SharedInfo>;
7
+ export declare function getMappingVersion(fileName: string, workspaceRoot: string): string;
@@ -65,19 +65,7 @@ export async function bundleExposedAndMappings(config, fedOptions, externals, mo
65
65
  // Pick shared-mappings
66
66
  for (const item of shared) {
67
67
  const distEntryFile = popFromResultMap(resultMap, item.outName);
68
- sharedResult.push({
69
- packageName: item.key,
70
- outFileName: path.basename(distEntryFile),
71
- requiredVersion: '',
72
- singleton: true,
73
- strictVersion: false,
74
- version: config.features.mappingVersion ? getMappingVersion(item.fileName) : '',
75
- dev: !fedOptions.dev
76
- ? undefined
77
- : {
78
- entryPoint: normalize(path.normalize(item.fileName)),
79
- },
80
- });
68
+ sharedResult.push(toSharedMappingInfo(item.fileName, item.key, path.basename(distEntryFile), config, fedOptions));
81
69
  entryFiles.push(distEntryFile);
82
70
  }
83
71
  const exposedResult = [];
@@ -112,7 +100,7 @@ export async function bundleExposedAndMappings(config, fedOptions, externals, mo
112
100
  }
113
101
  // Must run after rewriteChunkImports so SRI matches the final on-disk bytes.
114
102
  let integrity;
115
- if (fedOptions.integrity) {
103
+ if (config.features.integrityHashes) {
116
104
  integrity = {};
117
105
  for (const filePath of [...entryFiles, ...chunkPaths]) {
118
106
  if (!fs.existsSync(filePath))
@@ -141,30 +129,46 @@ export function describeExposed(config, options) {
141
129
  export function describeSharedMappings(config, fedOptions) {
142
130
  const result = [];
143
131
  for (const [mappedPath, mappedImport] of Object.entries(config.sharedMappings)) {
144
- result.push({
145
- packageName: mappedImport,
146
- outFileName: '',
147
- requiredVersion: '',
148
- singleton: true,
149
- strictVersion: false,
150
- version: config.features.mappingVersion ? getMappingVersion(mappedPath) : '',
151
- dev: !fedOptions.dev
152
- ? undefined
153
- : {
154
- entryPoint: normalize(path.normalize(mappedPath)),
155
- },
156
- });
132
+ result.push(toSharedMappingInfo(mappedPath, mappedImport, '', config, fedOptions));
157
133
  }
158
134
  return result;
159
135
  }
160
- function getMappingVersion(fileName) {
161
- const entryFileDir = path.dirname(fileName);
162
- const cand1 = path.join(entryFileDir, 'package.json');
163
- const cand2 = path.join(path.dirname(entryFileDir), 'package.json');
164
- const packageJsonPath = [cand1, cand2].find(cand => fs.existsSync(cand));
165
- if (packageJsonPath) {
166
- const json = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
167
- return json.version ?? '';
136
+ function toSharedMappingInfo(mappedPath, mappedImport, outFileName, config, fedOptions) {
137
+ const mappingVersion = config.features.mappingVersion
138
+ ? getMappingVersion(mappedPath, fedOptions.workspaceRoot)
139
+ : '';
140
+ return {
141
+ packageName: mappedImport,
142
+ outFileName,
143
+ requiredVersion: mappingVersion.length > 0 ? '~' + mappingVersion : '',
144
+ singleton: true,
145
+ strictVersion: config.features.mappingVersion,
146
+ version: mappingVersion,
147
+ dev: !fedOptions.dev
148
+ ? undefined
149
+ : {
150
+ entryPoint: normalize(path.normalize(mappedPath)),
151
+ },
152
+ };
153
+ }
154
+ export function getMappingVersion(fileName, workspaceRoot) {
155
+ const resolvedRoot = path.resolve(workspaceRoot);
156
+ let dir = path.dirname(path.resolve(fileName));
157
+ while (true) {
158
+ const candidate = path.join(dir, 'package.json');
159
+ try {
160
+ const json = JSON.parse(fs.readFileSync(candidate, 'utf-8'));
161
+ if (typeof json.version === 'string' && json.version)
162
+ return json.version;
163
+ }
164
+ catch (err) {
165
+ if (err.code !== 'ENOENT') {
166
+ logger.warn(`[getMappingVersion] Failed to parse ${candidate}: ${err.message}`);
167
+ }
168
+ }
169
+ const parent = path.dirname(dir);
170
+ if (dir === resolvedRoot || parent === dir)
171
+ return '';
172
+ dir = parent;
168
173
  }
169
- return '';
170
174
  }
@@ -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 (fedOptions.integrity && !integrity) {
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 = fedOptions.integrity
125
+ const integrity = config.features.integrityHashes
126
126
  ? computeIntegrityForFiles(persistedFiles, fedOptions.federationCache.cachePath)
127
127
  : undefined;
128
128
  bundleCache.persist({
@@ -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 (fedOptions.integrity) {
34
+ if (config.features.integrityHashes) {
35
35
  federationInfo.integrity = {
36
36
  ...(federationCache.integrity ?? {}),
37
37
  ...(artifactInfo?.integrity ?? {}),
@@ -15,6 +15,7 @@ export interface FederationConfig {
15
15
  mappingVersion?: boolean;
16
16
  ignoreUnusedDeps?: boolean;
17
17
  denseChunking?: boolean;
18
+ integrityHashes?: boolean;
18
19
  };
19
20
  }
20
21
  export interface NormalizedFederationConfig {
@@ -31,5 +32,6 @@ export interface NormalizedFederationConfig {
31
32
  mappingVersion: boolean;
32
33
  ignoreUnusedDeps: boolean;
33
34
  denseChunking: boolean;
35
+ integrityHashes: boolean;
34
36
  };
35
37
  }
@@ -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>;