@softarc/native-federation 4.1.0 → 4.1.1

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.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -15,7 +15,7 @@ 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
21
  },
@@ -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 = [];
@@ -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
  }