@@ -76,67 +76,22 @@ module.exports = (rollupConfig, projectOptions) => {
76
76
{ src : 'packages/runtime/LICENSE' , dest : 'packages/runtime/dist' } ,
77
77
] ,
78
78
} ) ,
79
- {
80
- name : 'fix-types-for-nodenext' ,
81
- writeBundle ( ) {
79
+ // 使用 SDK 包中的 NodeNext 类型修复工具
80
+ ( ( ) => {
81
+ try {
82
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
- } ,
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
+ } ) ( ) ,
140
95
) ;
141
96
142
97
return rollupConfig ;
0 commit comments