Skip to content

Commit 61f9445

Browse files
Merge branch 'main' into pr7-enhanced-filtering
2 parents 6c6ad1a + 609d477 commit 61f9445

File tree

7 files changed

+76
-5
lines changed

7 files changed

+76
-5
lines changed

.changeset/chatty-avocados-vanish.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/runtime': patch
3+
---
4+
5+
fix(runtime): support TypeScript moduleResolution NodeNext

apps/router-demo/router-remote2-2002/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"@module-federation/rsbuild-plugin": "workspace:*",
1515
"react": "18.3.1",
1616
"react-dom": "18.3.1",
17-
"react-router-dom": "6.24.1"
17+
"react-router-dom": "6.24.1",
18+
"@module-federation/runtime": "workspace:*"
1819
},
1920
"devDependencies": {
2021
"@rsbuild/core": "^1.3.21",

apps/router-demo/router-remote2-2002/src/bootstrap.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { createRoot } from 'react-dom/client';
3-
import App from './App';
3+
import App from './App.jsx';
44

55
//@ts-ignore
66
const root = createRoot(document.getElementById('root')!);

apps/router-demo/router-remote2-2002/src/export-App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import App from './App';
1+
import App from './App.jsx';
22
import { createBridgeComponent } from '@module-federation/bridge-react/v18';
3+
import { createInstance, getInstance } from '@module-federation/runtime';
34

45
// @ts-ignore
56
export const provider = createBridgeComponent({

apps/router-demo/router-remote2-2002/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"baseUrl": "./",
44
"target": "ES2020",
55
"lib": ["DOM", "ES2020"],
6-
"module": "ESNext",
6+
"module": "NodeNext",
77
"jsx": "react-jsx",
88
"strict": true,
99
"skipLibCheck": true,
1010
"isolatedModules": true,
1111
"resolveJsonModule": true,
12-
"moduleResolution": "bundler",
12+
"moduleResolution": "NodeNext",
1313
"useDefineForClassFields": true
1414
},
1515
"include": ["src"]

packages/runtime/rollup.config.cjs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,67 @@ module.exports = (rollupConfig, projectOptions) => {
7676
{ src: 'packages/runtime/LICENSE', dest: 'packages/runtime/dist' },
7777
],
7878
}),
79+
{
80+
name: 'fix-types-for-nodenext',
81+
writeBundle() {
82+
const path = require('path');
83+
const fs = require('fs');
84+
85+
try {
86+
// Read package.json exports to get the list of entries to fix
87+
const pkgPath = path.join(__dirname, 'package.json');
88+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
89+
90+
if (!pkg.exports) {
91+
console.warn(
92+
'⚠️ No exports found in package.json, skipping type fix',
93+
);
94+
return;
95+
}
96+
97+
// Extract entry names from exports (excluding "./*" pattern)
98+
const typesToFix = Object.keys(pkg.exports)
99+
.filter((key) => key !== './*')
100+
.map((key) => (key === '.' ? 'index' : key.replace('./', '')))
101+
.filter((name) => name); // Remove empty strings
102+
103+
if (typesToFix.length === 0) {
104+
console.warn('⚠️ No valid exports found to fix types for');
105+
return;
106+
}
107+
108+
console.log('🔧 Auto-detected types to fix:', typesToFix);
109+
110+
let fixedCount = 0;
111+
typesToFix.forEach((name) => {
112+
const srcPath = path.join(__dirname, 'dist', 'src', `${name}.d.ts`);
113+
const targetPath = path.join(__dirname, 'dist', `${name}.d.ts`);
114+
115+
try {
116+
if (fs.existsSync(srcPath)) {
117+
const content = fs.readFileSync(srcPath, 'utf8');
118+
fs.writeFileSync(targetPath, content);
119+
console.log(`✅ Fixed ${name}.d.ts for NodeNext compatibility`);
120+
fixedCount++;
121+
} else {
122+
console.log(`⚠️ Source file not found: ${srcPath}`);
123+
}
124+
} catch (error) {
125+
console.error(`❌ Error fixing ${name}.d.ts:`, error.message);
126+
}
127+
});
128+
129+
console.log(
130+
`🎉 NodeNext compatibility fix completed! Fixed ${fixedCount}/${typesToFix.length} files`,
131+
);
132+
} catch (error) {
133+
console.error(
134+
'❌ Failed to read package.json or apply type fixes:',
135+
error.message,
136+
);
137+
}
138+
},
139+
},
79140
);
80141

81142
return rollupConfig;

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)