@@ -112,7 +112,86 @@ describe('tsup migration', () => {
112112 expect ( fs . readFileSync ( tsupConfigPath , 'utf8' ) ) . toBe ( originalTsupConfig ) ;
113113 expect ( fs . readFileSync ( tsdownConfigPath , 'utf8' ) ) . toBe ( originalTsdownConfig ) ;
114114 expect ( mockWarn ) . toHaveBeenCalledWith (
115- 'Automatic tsup migration was skipped because these tsdown config files already exist:\n tsdown.config.ts' ,
115+ 'Automatic tsup migration was skipped because these tsdown configs already exist:\n tsdown.config.ts' ,
116+ ) ;
117+ expect ( mockInfo ) . toHaveBeenCalledWith ( manualMigrationOptions ( ) ) ;
118+ } ) ;
119+
120+ it ( 'refuses to overwrite an inline tsdown config' , async ( ) => {
121+ fs . unlinkSync ( path . join ( projectPath , 'tsup.config.ts' ) ) ;
122+ const packageJsonPath = path . join ( projectPath , 'package.json' ) ;
123+ const originalPackageJson = {
124+ name : 'fixture' ,
125+ scripts : { build : 'tsup' } ,
126+ devDependencies : { tsup : '^8.5.0' } ,
127+ tsup : { entry : [ 'src/index.ts' ] } ,
128+ tsdown : { entry : [ 'src/existing.ts' ] } ,
129+ } ;
130+ fs . writeFileSync ( packageJsonPath , `${ JSON . stringify ( originalPackageJson , null , 2 ) } \n` ) ;
131+
132+ await expect (
133+ migrateTsupToTsdown ( projectPath , false , PackageManager . npm , 'package.json#tsup' , undefined , {
134+ silent : true ,
135+ } ) ,
136+ ) . resolves . toBe ( false ) ;
137+
138+ expect ( mockRunCommandSilently ) . not . toHaveBeenCalled ( ) ;
139+ expect ( readJsonFile ( packageJsonPath ) ) . toEqual ( originalPackageJson ) ;
140+ expect ( mockWarn ) . toHaveBeenCalledWith (
141+ 'Automatic tsup migration was skipped because these tsdown configs already exist:\n package.json#tsdown' ,
142+ ) ;
143+ expect ( mockInfo ) . toHaveBeenCalledWith ( manualMigrationOptions ( ) ) ;
144+ } ) ;
145+
146+ it ( 'refuses to migrate a script that uses a custom tsup config' , async ( ) => {
147+ const packageJsonPath = path . join ( projectPath , 'package.json' ) ;
148+ const originalPackageJson = {
149+ name : 'fixture' ,
150+ scripts : { build : 'tsup --config configs/legacy.ts' } ,
151+ devDependencies : { tsup : '^8.5.0' } ,
152+ } ;
153+ fs . mkdirSync ( path . join ( projectPath , 'configs' ) ) ;
154+ fs . writeFileSync ( path . join ( projectPath , 'configs/legacy.ts' ) , 'export default {};\n' ) ;
155+ fs . writeFileSync ( packageJsonPath , `${ JSON . stringify ( originalPackageJson , null , 2 ) } \n` ) ;
156+
157+ await expect (
158+ migrateTsupToTsdown ( projectPath , false , PackageManager . npm , 'tsup.config.ts' , undefined , {
159+ silent : true ,
160+ } ) ,
161+ ) . resolves . toBe ( false ) ;
162+
163+ expect ( mockRunCommandSilently ) . not . toHaveBeenCalled ( ) ;
164+ expect ( readJsonFile ( packageJsonPath ) ) . toEqual ( originalPackageJson ) ;
165+ expect ( fs . existsSync ( path . join ( projectPath , 'tsup.config.ts' ) ) ) . toBe ( true ) ;
166+ expect ( mockWarn ) . toHaveBeenCalledWith (
167+ 'Automatic tsup migration was skipped because these scripts use configs that cannot be migrated automatically:\n package.json#build -> configs/legacy.ts' ,
168+ ) ;
169+ expect ( mockInfo ) . toHaveBeenCalledWith ( manualMigrationOptions ( ) ) ;
170+ } ) ;
171+
172+ it ( 'refuses to remove selectors for multiple standard tsup configs' , async ( ) => {
173+ fs . writeFileSync ( path . join ( projectPath , 'tsup.config.js' ) , 'export default {};\n' ) ;
174+ const packageJsonPath = path . join ( projectPath , 'package.json' ) ;
175+ const originalPackageJson = {
176+ name : 'fixture' ,
177+ scripts : {
178+ buildTs : 'tsup --config tsup.config.ts' ,
179+ buildJs : 'tsup --config tsup.config.js' ,
180+ } ,
181+ devDependencies : { tsup : '^8.5.0' } ,
182+ } ;
183+ fs . writeFileSync ( packageJsonPath , `${ JSON . stringify ( originalPackageJson , null , 2 ) } \n` ) ;
184+
185+ await expect (
186+ migrateTsupToTsdown ( projectPath , false , PackageManager . npm , 'tsup.config.ts' , undefined , {
187+ silent : true ,
188+ } ) ,
189+ ) . resolves . toBe ( false ) ;
190+
191+ expect ( mockRunCommandSilently ) . not . toHaveBeenCalled ( ) ;
192+ expect ( readJsonFile ( packageJsonPath ) ) . toEqual ( originalPackageJson ) ;
193+ expect ( mockWarn ) . toHaveBeenCalledWith (
194+ 'Automatic tsup migration was skipped because these scripts use configs that cannot be migrated automatically:\n package.json#buildJs -> tsup.config.js' ,
116195 ) ;
117196 expect ( mockInfo ) . toHaveBeenCalledWith ( manualMigrationOptions ( ) ) ;
118197 } ) ;
@@ -446,6 +525,7 @@ describe('tsup migration', () => {
446525 build : 'tsup --config ./tsup.config.ts' ,
447526 watch : 'tsup --watch --config=tsup.config.ts' ,
448527 wrapped : 'cross-env NODE_ENV=test tsup -c "tsup.config.ts" --watch' ,
528+ quotedData : "echo 'tsdown'" ,
449529 } ,
450530 devDependencies : { tsup : '^8.5.0' } ,
451531 } ,
@@ -478,53 +558,7 @@ describe('tsup migration', () => {
478558 build : 'tsdown' ,
479559 watch : 'tsdown --watch' ,
480560 wrapped : 'cross-env NODE_ENV=test tsdown --watch' ,
481- } ) ;
482- } ) ;
483-
484- it ( 'rewrites tsdown commands nested in quoted runner arguments' , async ( ) => {
485- fs . writeFileSync (
486- path . join ( projectPath , 'package.json' ) ,
487- `${ JSON . stringify (
488- {
489- name : 'fixture' ,
490- scripts : {
491- build : 'concurrently "tsup --watch --config=tsup.config.ts" "tsc --watch"' ,
492- wrapped : 'concurrently "pnpm exec tsup --watch" "tsc --watch"' ,
493- singleQuoted : "concurrently 'tsup' 'tsc'" ,
494- } ,
495- devDependencies : { tsup : '^8.5.0' } ,
496- } ,
497- null ,
498- 2 ,
499- ) } \n`,
500- ) ;
501- mockRunCommandSilently . mockImplementation ( async ( ) => {
502- const packageJsonPath = path . join ( projectPath , 'package.json' ) ;
503- const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf8' ) ) ;
504- for ( const scriptName of Object . keys ( packageJson . scripts ) ) {
505- packageJson . scripts [ scriptName ] = packageJson . scripts [ scriptName ] . replaceAll (
506- 'tsup' ,
507- 'tsdown' ,
508- ) ;
509- }
510- packageJson . devDependencies . tsdown = '0.22.14' ;
511- delete packageJson . devDependencies . tsup ;
512- fs . writeFileSync ( packageJsonPath , `${ JSON . stringify ( packageJson , null , 2 ) } \n` ) ;
513- fs . writeFileSync ( path . join ( projectPath , 'tsdown.config.ts' ) , 'export default {};\n' ) ;
514- fs . unlinkSync ( path . join ( projectPath , 'tsup.config.ts' ) ) ;
515- return { exitCode : 0 , stdout : Buffer . alloc ( 0 ) , stderr : Buffer . alloc ( 0 ) } ;
516- } ) ;
517-
518- await expect (
519- migrateTsupToTsdown ( projectPath , false , PackageManager . pnpm , 'tsup.config.ts' , undefined , {
520- silent : true ,
521- } ) ,
522- ) . resolves . toBe ( true ) ;
523-
524- expect ( readJsonFile ( path . join ( projectPath , 'package.json' ) ) . scripts ) . toEqual ( {
525- build : 'concurrently "vp pack --watch" "tsc --watch"' ,
526- wrapped : 'concurrently "pnpm exec vp pack --watch" "tsc --watch"' ,
527- singleQuoted : "concurrently 'vp pack' 'tsc'" ,
561+ quotedData : "echo 'tsdown'" ,
528562 } ) ;
529563 } ) ;
530564
0 commit comments