Skip to content

Commit 8d965d3

Browse files
committed
fix: finding secondary entrypoints
1 parent c0b27fd commit 8d965d3

File tree

7 files changed

+50
-8
lines changed

7 files changed

+50
-8
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "@softarc/native-federation",
3-
"version": "1.0.0",
3+
"version": "1.0.3",
44
"type": "commonjs",
55
"dependencies": {
66
"json5": "^2.2.0",
77
"npmlog": "^6.0.2",
8-
"@softarc/native-federation-runtime": "1.0.0"
8+
"@softarc/native-federation-runtime": "1.0.3"
99
}
1010
}

libs/native-federation-core/src/lib/config/share-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function readConfiguredSecondaries(
194194
key != '.' &&
195195
key != './package.json' &&
196196
!key.endsWith('*') &&
197-
exports[key]['default']
197+
(exports[key]['default'] || typeof exports[key] === 'string' )
198198
);
199199

200200
const result = {} as Record<string, SharedConfig>;

libs/native-federation-core/src/lib/utils/package-info.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,18 @@ export function getPackageInfo(
5252
relSecondaryPath = './' + relSecondaryPath.replace(/\\/g, '/');
5353
}
5454

55-
let cand = mainPkgJson?.exports?.[relSecondaryPath]?.import;
55+
let cand = mainPkgJson?.exports?.[relSecondaryPath];
56+
57+
if (typeof cand === 'string') {
58+
return {
59+
entryPoint: path.join(mainPkgPath, cand),
60+
packageName,
61+
version,
62+
esm,
63+
};
64+
}
65+
66+
cand = mainPkgJson?.exports?.[relSecondaryPath]?.import;
5667

5768
if (typeof cand === 'object') {
5869
if (cand.module) {

libs/native-federation-esbuild/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@softarc/native-federation-esbuild",
3-
"version": "1.0.0",
3+
"version": "1.0.3",
44
"type": "commonjs",
55
"dependencies": {
66
"@rollup/plugin-commonjs": "^22.0.2",

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const esBuildAdapter: BuildAdapter = createEsBuildAdapter({
2020

2121
export interface EsBuildAdapterConfig {
2222
plugins: esbuild.Plugin[];
23+
fileReplacements?: Record<string, string>
2324
}
2425

2526
export function createEsBuildAdapter(config: EsBuildAdapterConfig) {
@@ -31,7 +32,7 @@ export function createEsBuildAdapter(config: EsBuildAdapterConfig) {
3132
const tmpFolder = `node_modules/.tmp/${pkgName}`;
3233

3334
if (isPkg) {
34-
await prepareNodePackage(entryPoint, external, tmpFolder);
35+
await prepareNodePackage(entryPoint, external, tmpFolder, config);
3536
}
3637

3738
await esbuild.build({
@@ -62,8 +63,15 @@ export function createEsBuildAdapter(config: EsBuildAdapterConfig) {
6263
async function prepareNodePackage(
6364
entryPoint: string,
6465
external: string[],
65-
tmpFolder: string
66+
tmpFolder: string,
67+
config: EsBuildAdapterConfig,
6668
) {
69+
70+
71+
if (config.fileReplacements) {
72+
entryPoint = replaceEntryPoint(entryPoint, config.fileReplacements);
73+
}
74+
6775
const result = await rollup({
6876
input: entryPoint,
6977

@@ -93,3 +101,14 @@ function inferePkgName(entryPoint: string) {
93101
.replace(/.*?node_modules/g, '')
94102
.replace(/[^A-Za-z0-9.]/g, '_');
95103
}
104+
105+
function replaceEntryPoint(entryPoint: string, fileReplacements: Record<string, string>): string {
106+
entryPoint = entryPoint.replace(/\\/g, '/');
107+
108+
for(const key in fileReplacements) {
109+
entryPoint = entryPoint.replace(new RegExp(`${key}$`), fileReplacements[key]);
110+
}
111+
112+
return entryPoint;
113+
}
114+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const reactReplacements = {
2+
dev: {
3+
'node_modules/react/index.js': 'node_modules/react/cjs/react.development.js',
4+
'node_modules/react/jsx-dev-runtime.js' : 'node_modules/react/cjs/react-jsx-dev-runtime.development.js',
5+
'node_modules/react/jsx-runtime.js': 'node_modules/react/cjs/react-jsx-runtime.development.js'
6+
},
7+
prod: {
8+
'node_modules/react/index.js': 'node_modules/react/cjs/react.production.min.js',
9+
'node_modules/react/jsx-dev-runtime.js' : 'node_modules/react/cjs/react-jsx-dev-runtime.production.min.js',
10+
'node_modules/react/jsx-runtime.js': 'node_modules/react/cjs/react-jsx-runtime.production.min.js'
11+
}
12+
}

libs/native-federation-runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@softarc/native-federation-runtime",
3-
"version": "1.0.0",
3+
"version": "1.0.3",
44
"peerDependencies": {},
55
"dependencies": {
66
"tslib": "^2.3.0"

0 commit comments

Comments
 (0)