Skip to content

Commit 67a7bfa

Browse files
authored
feat: support NodeNext module resolution in packages (#3965)
1 parent d591de3 commit 67a7bfa

File tree

8 files changed

+435
-354
lines changed

8 files changed

+435
-354
lines changed

INCREMENTAL_PR_PLAN_REVISED.md

Lines changed: 0 additions & 293 deletions
This file was deleted.

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

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import App from './App.jsx';
22
import { createBridgeComponent } from '@module-federation/bridge-react/v18';
33
import { createInstance, getInstance } from '@module-federation/runtime';
4+
import { generateSnapshotFromManifest } from '@module-federation/sdk';
45

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

packages/runtime/rollup.config.cjs

Lines changed: 15 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -76,67 +76,22 @@ module.exports = (rollupConfig, projectOptions) => {
7676
{ src: 'packages/runtime/LICENSE', dest: 'packages/runtime/dist' },
7777
],
7878
}),
79-
{
80-
name: 'fix-types-for-nodenext',
81-
writeBundle() {
79+
// 使用 SDK 包中的 NodeNext 类型修复工具
80+
(() => {
81+
try {
8282
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-
},
83+
const {
84+
createNodeNextTypeFixPlugin,
85+
} = require('../sdk/scripts/fix-nodenext-types.cjs');
86+
return createNodeNextTypeFixPlugin(__dirname);
87+
} catch (error) {
88+
console.warn(
89+
'⚠️ Failed to load NodeNext type fix plugin, skipping:',
90+
error.message,
91+
);
92+
return { name: 'fix-types-for-nodenext-fallback', writeBundle() {} };
93+
}
94+
})(),
14095
);
14196

14297
return rollupConfig;

0 commit comments

Comments
 (0)