@@ -106,13 +106,13 @@ interface SharedTsupConfig {
106106 consumers : Map < string , SharedTsupConsumer > ;
107107}
108108
109- interface TsdownConfigCollision {
109+ interface TsupConfigLocation {
110110 configPath : string ;
111111 targetPath : string ;
112112}
113113
114114interface UnsupportedTsupConfigConsumer {
115- configPath : string ;
115+ configArgument : string ;
116116 packagePath : string ;
117117 scriptName : string ;
118118}
@@ -175,8 +175,8 @@ function collectSharedTsupConfigs(
175175 return sharedConfigs ;
176176}
177177
178- function collectTsupConfigCollisions ( tsupTargets : string [ ] ) : TsdownConfigCollision [ ] {
179- const collisions : TsdownConfigCollision [ ] = [ ] ;
178+ function collectTsupConfigCollisions ( tsupTargets : string [ ] ) : TsupConfigLocation [ ] {
179+ const collisions : TsupConfigLocation [ ] = [ ] ;
180180 for ( const target of tsupTargets ) {
181181 const tsdownConfig = detectConfigs ( target ) . tsdownConfig ;
182182 if ( tsdownConfig ) {
@@ -193,6 +193,25 @@ function collectTsupConfigCollisions(tsupTargets: string[]): TsdownConfigCollisi
193193 return collisions ;
194194}
195195
196+ function collectInlineTsupConfigs ( tsupTargets : string [ ] ) : TsupConfigLocation [ ] {
197+ return tsupTargets . flatMap ( ( target ) => {
198+ const packageJsonPath = path . join ( target , 'package.json' ) ;
199+ if ( ! fs . existsSync ( packageJsonPath ) || ! Object . hasOwn ( readJsonFile ( packageJsonPath ) , 'tsup' ) ) {
200+ return [ ] ;
201+ }
202+ return [ { configPath : `${ packageJsonPath } #tsup` , targetPath : target } ] ;
203+ } ) ;
204+ }
205+
206+ function isRemovableDefaultConfigArgument ( configArgument : string , defaultConfig ?: string ) : boolean {
207+ return (
208+ ! ! defaultConfig &&
209+ ( configArgument === defaultConfig ||
210+ configArgument === `./${ defaultConfig } ` ||
211+ configArgument === `.\\${ defaultConfig } ` )
212+ ) ;
213+ }
214+
196215function collectUnsupportedTsupConfigConsumers (
197216 tsupTargets : string [ ] ,
198217) : UnsupportedTsupConfigConsumer [ ] {
@@ -219,12 +238,15 @@ function collectUnsupportedTsupConfigConsumers(
219238
220239 for ( const [ scriptName , script ] of Object . entries ( packageJson . scripts ?? { } ) ) {
221240 for ( const match of script . matchAll ( TSUP_CONFIG_OPTION_RE ) ) {
222- const configPath = resolveScriptConfigPath ( target , match [ 1 ] ?? match [ 2 ] ?? match [ 3 ] ) ;
223- const isDefaultConfig = configPath === defaultConfigPath ;
241+ const configArgument = match [ 1 ] ?? match [ 2 ] ?? match [ 3 ] ;
242+ const configPath = resolveScriptConfigPath ( target , configArgument ) ;
243+ const isDefaultConfig =
244+ configPath === defaultConfigPath &&
245+ isRemovableDefaultConfigArgument ( configArgument , detectedConfig ) ;
224246 const isSharedMigratedConfig =
225247 migratedConfigPaths . has ( configPath ) && path . dirname ( configPath ) !== target ;
226248 if ( ! isDefaultConfig && ! isSharedMigratedConfig ) {
227- unsupported . push ( { configPath , packagePath : target , scriptName } ) ;
249+ unsupported . push ( { configArgument , packagePath : target , scriptName } ) ;
228250 }
229251 }
230252 }
@@ -413,13 +435,28 @@ export async function migrateTsupToTsdown(
413435 showTsdownMigrationOptions ( targetLabel ) ;
414436 return false ;
415437 }
438+ const inlineTsupConfigs = collectInlineTsupConfigs ( tsupTargets ) ;
439+ if ( inlineTsupConfigs . length > 0 ) {
440+ prompts . log . warn (
441+ `Automatic tsup migration was skipped because these inline tsup configs cannot be migrated automatically:\n${ inlineTsupConfigs
442+ . map ( ( { configPath } ) => ` ${ displayRelative ( configPath , projectPath ) } ` )
443+ . join ( '\n' ) } `,
444+ ) ;
445+ const firstInlineTarget = inlineTsupConfigs [ 0 ] . targetPath ;
446+ const targetLabel =
447+ firstInlineTarget === rootPath
448+ ? 'the project root'
449+ : displayRelative ( firstInlineTarget , projectPath ) ;
450+ showTsdownMigrationOptions ( targetLabel ) ;
451+ return false ;
452+ }
416453 const unsupportedConfigConsumers = collectUnsupportedTsupConfigConsumers ( tsupTargets ) ;
417454 if ( unsupportedConfigConsumers . length > 0 ) {
418455 prompts . log . warn (
419456 `Automatic tsup migration was skipped because these scripts use configs that cannot be migrated automatically:\n${ unsupportedConfigConsumers
420457 . map (
421- ( { configPath , packagePath, scriptName } ) =>
422- ` ${ displayRelative ( path . join ( packagePath , 'package.json' ) , projectPath ) } #${ scriptName } -> ${ displayRelative ( configPath , projectPath ) } ` ,
458+ ( { configArgument , packagePath, scriptName } ) =>
459+ ` ${ displayRelative ( path . join ( packagePath , 'package.json' ) , projectPath ) } #${ scriptName } -> ${ configArgument } ` ,
423460 )
424461 . join ( '\n' ) } `,
425462 ) ;
0 commit comments