Skip to content

Commit b066df2

Browse files
committed
feat(nf-core): add debug mode with more information in remote entry
1 parent 10d6416 commit b066df2

25 files changed

+723
-1965
lines changed
-11 Bytes
Binary file not shown.
20.7 KB
Binary file not shown.

libs/mf/src/schematics/mf/files/webpack.config.js__tmpl__

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { shareAll, withModuleFederationPlugin } = require('@angular-architects/mo
22

33
module.exports = withModuleFederationPlugin({
44
<% if (type === 'remote') { %>
5-
name: 'mfe1',
5+
name: '<%=project%>',
66

77
exposes: {
88
'./Component': './<%=projectSourceRoot%>/app/app.component.ts',
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "@softarc/native-federation",
3-
"version": "1.0.0",
3+
"version": "1.0.0-beta.1",
44
"type": "commonjs",
55
"dependencies": {
6-
"json5": "^2.2.0"
6+
"json5": "^2.2.0",
7+
"npmlog": "^6.0.2"
78
}
89
}

libs/native-federation-core/src/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export { bundleExposed } from './lib/core/bundle-exposed';
99
export { getExternals } from './lib/core/get-externals';
1010
export { loadFederationConfig } from './lib/core/load-federation-config';
1111
export { MappedPath } from './lib/utils/mapped-paths';
12-
export { BuildAdapter } from './lib/core/build-adapter';
12+
export { BuildAdapter, BuildAdapterOptions } from './lib/core/build-adapter';
1313
export { withNativeFederation } from './lib/config/with-native-federation';
1414
export { buildForFederation } from './lib/core/build-for-federation';
1515
export {

libs/native-federation-core/src/lib/config/with-native-federation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function normalizeSharedMappings(
8282
});
8383

8484
const result = paths.filter(
85-
(p) => !isInSkipList(p.key, skip) && p.key.includes('*')
85+
(p) => !isInSkipList(p.key, skip) && !p.key.includes('*')
8686
);
8787

8888
if (paths.find((p) => p.key.includes('*'))) {

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ExposesInfo } from '@softarc/native-federation-runtime';
66
import { hashFile } from '../utils/hash-file';
77
import { FederationOptions } from './federation-options';
88
import { logger } from '../utils/logger';
9+
import { normalize } from '../utils/normalize';
910

1011
export async function bundleExposed(
1112
config: NormalizedFederationConfig,
@@ -19,6 +20,11 @@ export async function bundleExposed(
1920
const outFilePath = path.join(options.outputPath, outFileName);
2021
const entryPoint = config.exposes[key];
2122

23+
const localPath = normalize(path.join(
24+
options.workspaceRoot,
25+
config.exposes[key]
26+
));
27+
2228
logger.info(`Bundling exposed module ${entryPoint}`);
2329

2430
try {
@@ -37,9 +43,17 @@ export async function bundleExposed(
3743
options.outputPath,
3844
hashedOutFileName
3945
);
46+
4047
fs.renameSync(outFilePath, hashedOutFilePath);
4148

42-
result.push({ key, outFileName: hashedOutFileName });
49+
result.push({
50+
key,
51+
outFileName: hashedOutFileName,
52+
debug: !options.debug ? undefined : {
53+
localPath
54+
}
55+
});
56+
4357
} catch (e) {
4458
logger.error('Error bundling exposed module ' + entryPoint);
4559
logger.error(e);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { SharedInfo } from '@softarc/native-federation-runtime';
66
import { hashFile } from '../utils/hash-file';
77
import { FederationOptions } from '../core/federation-options';
88
import { logger } from '../utils/logger';
9+
import { normalize } from '../utils/normalize';
910

1011
export async function bundleSharedMappings(
1112
config: NormalizedFederationConfig,
@@ -46,6 +47,9 @@ export async function bundleSharedMappings(
4647
singleton: true,
4748
strictVersion: false,
4849
version: '',
50+
debug: !fedOptions.debug ? undefined : {
51+
entryPoint: normalize(m.path)
52+
}
4953
});
5054
} catch (e) {
5155
// TODO: add logger

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { FederationOptions } from './federation-options';
88
import { copySrcMapIfExists } from '../utils/copy-src-map-if-exists';
99
import { logger } from '../utils/logger';
1010
import { hashFile } from '../utils/hash-file';
11+
import { normalize } from '../utils/normalize';
1112

1213
export async function bundleShared(
1314
config: NormalizedFederationConfig,
@@ -20,10 +21,10 @@ export async function bundleShared(
2021
.map((packageName) => getPackageInfo(packageName, fedOptions.workspaceRoot))
2122
.filter((pi) => !!pi) as PackageInfo[];
2223

23-
logger.notice('Shared packages are only bundled once as they are cached');
24-
logger.notice(
25-
'Make sure, you skip all unneeded packages in your federation.config.js!'
26-
);
24+
// logger.notice('Shared packages are only bundled once as they are cached');
25+
// logger.notice(
26+
// 'Make sure, you skip all unneeded packages in your federation.config.js!'
27+
// );
2728

2829
const federationConfigPath = path.join(
2930
fedOptions.workspaceRoot,
@@ -32,8 +33,7 @@ export async function bundleShared(
3233
const hash = hashFile(federationConfigPath);
3334

3435
for (const pi of packageInfos) {
35-
// TODO: add logger
36-
logger.info('Bundling shared package ' + pi.packageName);
36+
// logger.info('Bundling shared package ' + pi.packageName);
3737

3838
const encName = pi.packageName.replace(/[^A-Za-z0-9]/g, '_');
3939
const encVersion = pi.version.replace(/[^A-Za-z0-9]/g, '_');
@@ -50,6 +50,9 @@ export async function bundleShared(
5050
const cachedFile = path.join(cachePath, outFileName);
5151

5252
if (!fs.existsSync(cachedFile)) {
53+
54+
logger.info('Preparing shared package ' + pi.packageName);
55+
5356
try {
5457
await bundle({
5558
entryPoint: pi.entryPoint,
@@ -84,6 +87,9 @@ export async function bundleShared(
8487
singleton: shared.singleton,
8588
strictVersion: shared.strictVersion,
8689
version: pi.version,
90+
debug: !fedOptions.debug ? undefined : {
91+
entryPoint: normalize(pi.entryPoint),
92+
}
8793
});
8894

8995
const fullOutputPath = path.join(

libs/native-federation-core/src/lib/core/federation-builder.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { SharedInfo } from '@softarc/native-federation';
12
import { NormalizedFederationConfig } from '../config/federation-config';
23
import { BuildAdapter, setBuildAdapter } from './build-adapter';
34
import { buildForFederation } from './build-for-federation';
5+
import { bundleShared } from './bundle-shared';
46
import { FederationOptions } from './federation-options';
57
import { getExternals } from './get-externals';
68
import { loadFederationConfig } from './load-federation-config';
@@ -25,10 +27,18 @@ async function build(): Promise<void> {
2527
buildForFederation(config, fedOptions, externals);
2628
}
2729

30+
async function buildShared(): Promise<SharedInfo[]> {
31+
return bundleShared(config, fedOptions, externals);
32+
}
33+
2834
export const federationBuilder = {
2935
init,
3036
build,
37+
buildShared,
3138
get externals(): string[] {
3239
return externals;
3340
},
41+
get config(): NormalizedFederationConfig {
42+
return config;
43+
}
3444
};

0 commit comments

Comments
 (0)