Skip to content

Commit ef93d22

Browse files
committed
feat(nf-core): add hash value of federation.config to shared bundle names
1 parent 1a6ff71 commit ef93d22

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

apps/playground/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { initFederation } from '@angular-architects/native-federation';
22

33
initFederation({
4-
// 'mfe1': 'http://localhost:3001/remoteEntry.json'
4+
//'mfe1': 'http://localhost:3001/remoteEntry.json'
55
})
66
.then(() => import('./bootstrap'))
77
.catch((e) => console.error('err', e));

libs/native-federation-core/src/lib/core/bundle-shared.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { SharedInfo } from '@softarc/native-federation-runtime';
77
import { FederationOptions } from './federation-options';
88
import { copySrcMapIfExists } from '../utils/copy-src-map-if-exists';
99
import { logger } from '../utils/logger';
10+
import { hashFile } from '../utils/hash-file';
1011

1112
export async function bundleShared(
1213
config: NormalizedFederationConfig,
@@ -24,14 +25,17 @@ export async function bundleShared(
2425
'Make sure, you skip all unneeded packages in your federation.config.js'
2526
);
2627

28+
const federationConfigPath = path.join(fedOptions.workspaceRoot, fedOptions.federationConfig);
29+
const hash = hashFile(federationConfigPath);
30+
2731
for (const pi of packageInfos) {
2832
// TODO: add logger
2933
logger.info('Bundling shared package ' + pi.packageName);
3034

3135
const encName = pi.packageName.replace(/[^A-Za-z0-9]/g, '_');
3236
const encVersion = pi.version.replace(/[^A-Za-z0-9]/g, '_');
3337

34-
const outFileName = `${encName}-${encVersion}.js`;
38+
const outFileName = `${encName}-${encVersion}-${hash}.js`;
3539

3640
const cachePath = path.join(
3741
fedOptions.workspaceRoot,
@@ -56,10 +60,14 @@ export async function bundleShared(
5660
});
5761
} catch (e) {
5862
logger.error('Error bundling ' + pi.packageName);
63+
if (e instanceof Error) {
64+
logger.error(e.message);
65+
}
66+
logger.error('For more information, run in verbose mode');
5967
logger.notice(
6068
`If you don't need this package, skip it in your federation.config.js!`
6169
);
62-
logger.error(e);
70+
logger.verbose(e);
6371
continue;
6472
}
6573
}

libs/native-federation/src/utils/rollup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export async function runRollup(
5050
exports: 'named',
5151
});
5252
} catch (e) {
53-
logger.error('Error bundling/ preparing shared package');
53+
logger.error('Rollup error');
5454
throw e;
5555
}
5656
}

0 commit comments

Comments
 (0)