Skip to content

Commit 6d6e40d

Browse files
committed
feat(ng-esbuild):add call of compensateExports to output files
1 parent 2cdad2b commit 6d6e40d

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export {
1111
BuildAdapterOptions,
1212
BuildResult,
1313
BuildKind,
14+
EntryPoint,
1415
} from './lib/core/build-adapter';
1516
export { withNativeFederation } from './lib/config/with-native-federation';
1617
export { buildForFederation } from './lib/core/build-for-federation';

libs/native-federation-esbuild/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
"name": "@softarc/native-federation-esbuild",
33
"version": "2.0.8",
44
"type": "commonjs",
5+
"repository": {
6+
"type": "git",
7+
"url": "angular-architects/module-federation-plugin.git",
8+
"directory": "libs/native-federation-esbuild"
9+
},
510
"dependencies": {
611
"@rollup/plugin-commonjs": "^22.0.2",
712
"@rollup/plugin-node-resolve": "^13.3.0",

libs/native-federation-esbuild/src/lib/adapter.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {
22
BuildAdapter,
33
BuildAdapterOptions,
44
BuildResult,
5+
EntryPoint,
6+
logger,
57
} from '@softarc/native-federation/build';
68
import * as esbuild from 'esbuild';
79
import { rollup } from 'rollup';
@@ -24,10 +26,18 @@ export type ReplacementConfig = {
2426
file: string;
2527
};
2628

29+
type EntryPointWithMeta = EntryPoint & {
30+
meta: {
31+
isPkg: boolean;
32+
originalFileName: string;
33+
};
34+
};
35+
2736
export interface EsBuildAdapterConfig {
2837
plugins: esbuild.Plugin[];
2938
fileReplacements?: Record<string, string | ReplacementConfig>;
3039
skipRollup?: boolean;
40+
/** Identify packages for which compensating missing named exports */
3141
compensateExports?: RegExp[];
3242
loader?: { [ext: string]: esbuild.Loader };
3343
}
@@ -42,11 +52,17 @@ export function createEsBuildAdapter(config: EsBuildAdapterConfig) {
4252

4353
// TODO: Do we need to prepare packages anymore as esbuild has evolved?
4454

45-
for (const entryPoint of entryPoints) {
55+
const preparedEntryPoints = entryPoints as EntryPointWithMeta[];
56+
for (const entryPoint of preparedEntryPoints) {
4657
const isPkg = entryPoint.fileName.includes('node_modules');
4758
const pkgName = isPkg ? inferePkgName(entryPoint.fileName) : '';
4859
const tmpFolder = `node_modules/.tmp/${pkgName}`;
4960

61+
entryPoint.meta = {
62+
originalFileName: entryPoint.fileName,
63+
isPkg,
64+
};
65+
5066
if (isPkg) {
5167
await prepareNodePackage(
5268
entryPoint.fileName,
@@ -55,13 +71,12 @@ export function createEsBuildAdapter(config: EsBuildAdapterConfig) {
5571
config,
5672
!!options.dev
5773
);
58-
5974
entryPoint.fileName = tmpFolder;
6075
}
6176
}
6277

6378
const ctx = await esbuild.context({
64-
entryPoints: entryPoints.map((ep) => ({
79+
entryPoints: preparedEntryPoints.map((ep) => ({
6580
in: ep.fileName,
6681
out: path.parse(ep.outName).name,
6782
})),
@@ -81,16 +96,18 @@ export function createEsBuildAdapter(config: EsBuildAdapterConfig) {
8196
const result = await ctx.rebuild();
8297
const writtenFiles = writeResult(result, outdir);
8398
ctx.dispose();
99+
preparedEntryPoints.forEach((entryPoint) => {
100+
const { meta, fileName, outName } = entryPoint;
101+
const normEntryPoint = meta.originalFileName.replace(/\\/g, '/');
102+
if (
103+
meta.isPkg &&
104+
config?.compensateExports?.find((regExp) => regExp.exec(normEntryPoint))
105+
) {
106+
logger.verbose('compensate exports for ' + meta.originalFileName);
107+
compensateExports(fileName, path.join(outdir, outName));
108+
}
109+
});
84110
return writtenFiles.map((fileName) => ({ fileName }));
85-
86-
// const normEntryPoint = entryPoint.replace(/\\/g, '/');
87-
// if (
88-
// isPkg &&
89-
// config?.compensateExports?.find((regExp) => regExp.exec(normEntryPoint))
90-
// ) {
91-
// logger.verbose('compensate exports for ' + tmpFolder);
92-
// compensateExports(tmpFolder, outfile);
93-
// }
94111
};
95112
}
96113

0 commit comments

Comments
 (0)