@@ -147,16 +147,17 @@ yargs
147147 ? targets [ 0 ]
148148 : undefined ;
149149
150- const entries : { [ key : string ] : string } = {
151- 'main' : target
152- ? path . join ( output , target , 'index.js' )
150+ const entries : {
151+ [ key in 'source' | 'main' | 'module' | 'types' ] ?: string ;
152+ } = {
153+ source : path . join ( source , entryFile ) ,
154+ main : target
155+ ? path . join ( output , target , 'index.cjs' )
153156 : path . join ( source , entryFile ) ,
154- 'react-native' : path . join ( source , entryFile ) ,
155- 'source' : path . join ( source , entryFile ) ,
156157 } ;
157158
158159 if ( targets . includes ( 'module' ) ) {
159- entries . module = path . join ( output , 'module' , 'index.js ' ) ;
160+ entries . module = path . join ( output , 'module' , 'index.mjs ' ) ;
160161 }
161162
162163 if ( targets . includes ( 'typescript' ) ) {
@@ -181,9 +182,9 @@ yargs
181182 esModuleInterop : true ,
182183 forceConsistentCasingInFileNames : true ,
183184 jsx : 'react' ,
184- lib : [ 'esnext ' ] ,
185- module : 'esnext ' ,
186- moduleResolution : 'node ' ,
185+ lib : [ 'ESNext ' ] ,
186+ module : 'ESNext ' ,
187+ moduleResolution : 'Bundler ' ,
187188 noFallthroughCasesInSwitch : true ,
188189 noImplicitReturns : true ,
189190 noImplicitUseStrict : false ,
@@ -194,7 +195,7 @@ yargs
194195 resolveJsonModule : true ,
195196 skipLibCheck : true ,
196197 strict : true ,
197- target : 'esnext ' ,
198+ target : 'ESNext ' ,
198199 verbatimModuleSyntax : true ,
199200 } ,
200201 } ,
@@ -214,7 +215,7 @@ yargs
214215 ] ;
215216
216217 for ( const key in entries ) {
217- const entry = entries [ key ] ;
218+ const entry = entries [ key as keyof typeof entries ] ;
218219
219220 if ( pkg [ key ] && pkg [ key ] !== entry ) {
220221 const { replace } = await prompts ( {
@@ -232,6 +233,41 @@ yargs
232233 }
233234 }
234235
236+ if ( Object . values ( entries ) . some ( ( entry ) => entry . endsWith ( '.ms' ) ) ) {
237+ let replace = false ;
238+
239+ if ( pkg . exports ) {
240+ replace = (
241+ await prompts ( {
242+ type : 'confirm' ,
243+ name : 'replace' ,
244+ message : `Your package.json has 'exports' field set. Do you want to replace it?` ,
245+ initial : true ,
246+ } )
247+ ) . replace ;
248+ } else {
249+ replace = true ;
250+ }
251+
252+ if ( replace ) {
253+ pkg . exports = {
254+ '.' : { } ,
255+ } ;
256+
257+ if ( entries . types ) {
258+ pkg . exports [ '.' ] . types = entries . types ;
259+ }
260+
261+ if ( entries . module ) {
262+ pkg . exports [ '.' ] . import = entries . module ;
263+ }
264+
265+ if ( entries . main ) {
266+ pkg . exports [ '.' ] . require = entries . main ;
267+ }
268+ }
269+ }
270+
235271 if ( pkg . scripts ?. prepare && pkg . scripts . prepare !== prepare ) {
236272 const { replace } = await prompts ( {
237273 type : 'confirm' ,
0 commit comments