Skip to content

Commit e75a33e

Browse files
committed
fix(migrate): tailor tsup fallback guidance
1 parent 8849dca commit e75a33e

6 files changed

Lines changed: 109 additions & 44 deletions

File tree

crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_from_tsup/snapshots/migration_from_tsup_config_collision.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ tsup configuration detected. Auto-migrating to tsdown...
1818
Automatic tsup migration was skipped because these tsdown configs already exist:
1919
tsdown.config.ts
2020
21-
Choose one of these manual migration methods:
22-
1. Run `vp dlx tsdown-migrate` in the project root.
23-
2. Use the tsdown migration skill:
24-
https://github.com/rolldown/tsdown/blob/main/skills/tsdown-migrate/SKILL.md
21+
Resolve this configuration conflict manually:
22+
1. Merge the tsup and tsdown configurations into `pack` in `vite.config.*`.
23+
2. Do not run `tsdown-migrate`. It can overwrite the existing tsdown configuration.
24+
25+
Use the tsdown migration skill for guidance:
26+
https://github.com/rolldown/tsdown/blob/main/skills/tsdown-migrate/SKILL.md
2527
Complete the tsup migration manually, then re-run `vp migrate`.
2628
```
2729

crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_from_tsup/snapshots/migration_from_tsup_custom_config.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ Automatic tsup migration was skipped because these scripts use configs that cann
2828
package.json#build -> configs/legacy.ts
2929
package.json#irregular -> ././tsup.config.ts
3030
31-
Choose one of these manual migration methods:
32-
1. Run `vp dlx tsdown-migrate` in the project root.
33-
2. Use the tsdown migration skill:
34-
https://github.com/rolldown/tsdown/blob/main/skills/tsdown-migrate/SKILL.md
31+
Resolve these config paths manually:
32+
1. Migrate each listed config into `pack` in `vite.config.*`.
33+
2. Update each listed script.
34+
3. Do not run `tsdown-migrate`. It cannot safely resolve these config paths.
35+
36+
Use the tsdown migration skill for guidance:
37+
https://github.com/rolldown/tsdown/blob/main/skills/tsdown-migrate/SKILL.md
3538
Complete the tsup migration manually, then re-run `vp migrate`.
3639
```
3740

crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_from_tsup/snapshots/migration_from_tsup_inline_config.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ tsup configuration detected. Auto-migrating to tsdown...
2323
Automatic tsup migration was skipped because these inline tsup configs cannot be migrated automatically:
2424
package.json#tsup
2525
26-
Choose one of these manual migration methods:
27-
1. Run `vp dlx tsdown-migrate` in the project root.
28-
2. Use the tsdown migration skill:
29-
https://github.com/rolldown/tsdown/blob/main/skills/tsdown-migrate/SKILL.md
26+
Resolve this inline configuration manually:
27+
1. Move each `package.json#tsup` configuration into `pack` in `vite.config.*`.
28+
2. Do not run `tsdown-migrate`. Vite+ Pack does not read `package.json#tsdown`.
29+
30+
Use the tsdown migration skill for guidance:
31+
https://github.com/rolldown/tsdown/blob/main/skills/tsdown-migrate/SKILL.md
3032
Complete the tsup migration manually, then re-run `vp migrate`.
3133
```
3234

crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_from_tsup/snapshots/migration_from_tsup_inline_config_collision.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ tsup configuration detected. Auto-migrating to tsdown...
2626
Automatic tsup migration was skipped because these tsdown configs already exist:
2727
package.json#tsdown
2828
29-
Choose one of these manual migration methods:
30-
1. Run `vp dlx tsdown-migrate` in the project root.
31-
2. Use the tsdown migration skill:
32-
https://github.com/rolldown/tsdown/blob/main/skills/tsdown-migrate/SKILL.md
29+
Resolve this configuration conflict manually:
30+
1. Merge the tsup and tsdown configurations into `pack` in `vite.config.*`.
31+
2. Do not run `tsdown-migrate`. It can overwrite the existing tsdown configuration.
32+
33+
Use the tsdown migration skill for guidance:
34+
https://github.com/rolldown/tsdown/blob/main/skills/tsdown-migrate/SKILL.md
3335
Complete the tsup migration manually, then re-run `vp migrate`.
3436
```
3537

packages/cli/src/migration/__tests__/tsup.spec.ts

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ function manualMigrationOptions(targetLabel = 'the project root'): string {
4545
].join('\n');
4646
}
4747

48+
function migrationSkillGuidance(instructions: string[]): string {
49+
return [
50+
...instructions,
51+
'',
52+
'Use the tsdown migration skill for guidance:',
53+
` ${TSDOWN_MIGRATION_SKILL_URL}`,
54+
].join('\n');
55+
}
56+
4857
describe('tsup migration', () => {
4958
let projectPath: string;
5059

@@ -114,7 +123,13 @@ describe('tsup migration', () => {
114123
expect(mockWarn).toHaveBeenCalledWith(
115124
'Automatic tsup migration was skipped because these tsdown configs already exist:\n tsdown.config.ts',
116125
);
117-
expect(mockInfo).toHaveBeenCalledWith(manualMigrationOptions());
126+
expect(mockInfo).toHaveBeenCalledWith(
127+
migrationSkillGuidance([
128+
'Resolve this configuration conflict manually:',
129+
' 1. Merge the tsup and tsdown configurations into `pack` in `vite.config.*`.',
130+
' 2. Do not run `tsdown-migrate`. It can overwrite the existing tsdown configuration.',
131+
]),
132+
);
118133
});
119134

120135
it('refuses to overwrite an inline tsdown config', async () => {
@@ -140,7 +155,13 @@ describe('tsup migration', () => {
140155
expect(mockWarn).toHaveBeenCalledWith(
141156
'Automatic tsup migration was skipped because these tsdown configs already exist:\n package.json#tsdown',
142157
);
143-
expect(mockInfo).toHaveBeenCalledWith(manualMigrationOptions());
158+
expect(mockInfo).toHaveBeenCalledWith(
159+
migrationSkillGuidance([
160+
'Resolve this configuration conflict manually:',
161+
' 1. Merge the tsup and tsdown configurations into `pack` in `vite.config.*`.',
162+
' 2. Do not run `tsdown-migrate`. It can overwrite the existing tsdown configuration.',
163+
]),
164+
);
144165
});
145166

146167
it('refuses to migrate an inline tsup config', async () => {
@@ -165,7 +186,13 @@ describe('tsup migration', () => {
165186
expect(mockWarn).toHaveBeenCalledWith(
166187
'Automatic tsup migration was skipped because these inline tsup configs cannot be migrated automatically:\n package.json#tsup',
167188
);
168-
expect(mockInfo).toHaveBeenCalledWith(manualMigrationOptions());
189+
expect(mockInfo).toHaveBeenCalledWith(
190+
migrationSkillGuidance([
191+
'Resolve this inline configuration manually:',
192+
' 1. Move each `package.json#tsup` configuration into `pack` in `vite.config.*`.',
193+
' 2. Do not run `tsdown-migrate`. Vite+ Pack does not read `package.json#tsdown`.',
194+
]),
195+
);
169196
});
170197

171198
it('refuses to migrate a script that uses a custom tsup config', async () => {
@@ -191,7 +218,14 @@ describe('tsup migration', () => {
191218
expect(mockWarn).toHaveBeenCalledWith(
192219
'Automatic tsup migration was skipped because these scripts use configs that cannot be migrated automatically:\n package.json#build -> configs/legacy.ts',
193220
);
194-
expect(mockInfo).toHaveBeenCalledWith(manualMigrationOptions());
221+
expect(mockInfo).toHaveBeenCalledWith(
222+
migrationSkillGuidance([
223+
'Resolve these config paths manually:',
224+
' 1. Migrate each listed config into `pack` in `vite.config.*`.',
225+
' 2. Update each listed script.',
226+
' 3. Do not run `tsdown-migrate`. It cannot safely resolve these config paths.',
227+
]),
228+
);
195229
});
196230

197231
it('refuses a default config path that cleanup cannot remove', async () => {
@@ -215,7 +249,14 @@ describe('tsup migration', () => {
215249
expect(mockWarn).toHaveBeenCalledWith(
216250
'Automatic tsup migration was skipped because these scripts use configs that cannot be migrated automatically:\n package.json#build -> ././tsup.config.ts',
217251
);
218-
expect(mockInfo).toHaveBeenCalledWith(manualMigrationOptions());
252+
expect(mockInfo).toHaveBeenCalledWith(
253+
migrationSkillGuidance([
254+
'Resolve these config paths manually:',
255+
' 1. Migrate each listed config into `pack` in `vite.config.*`.',
256+
' 2. Update each listed script.',
257+
' 3. Do not run `tsdown-migrate`. It cannot safely resolve these config paths.',
258+
]),
259+
);
219260
});
220261

221262
it('refuses to remove selectors for multiple standard tsup configs', async () => {
@@ -242,7 +283,14 @@ describe('tsup migration', () => {
242283
expect(mockWarn).toHaveBeenCalledWith(
243284
'Automatic tsup migration was skipped because these scripts use configs that cannot be migrated automatically:\n package.json#buildJs -> tsup.config.js',
244285
);
245-
expect(mockInfo).toHaveBeenCalledWith(manualMigrationOptions());
286+
expect(mockInfo).toHaveBeenCalledWith(
287+
migrationSkillGuidance([
288+
'Resolve these config paths manually:',
289+
' 1. Migrate each listed config into `pack` in `vite.config.*`.',
290+
' 2. Update each listed script.',
291+
' 3. Do not run `tsdown-migrate`. It cannot safely resolve these config paths.',
292+
]),
293+
);
246294
});
247295

248296
it('detects a workspace-only tsup config', () => {

packages/cli/src/migration/migrator/tsup.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ function showTsdownMigrationOptions(
3131
prompts.log.info(lines.join('\n'));
3232
}
3333

34+
function showTsdownMigrationSkillGuidance(instructions: string[]): void {
35+
prompts.log.info(
36+
[
37+
...instructions,
38+
'',
39+
'Use the tsdown migration skill for guidance:',
40+
` ${TSDOWN_MIGRATION_SKILL_URL}`,
41+
].join('\n'),
42+
);
43+
}
44+
3445
export function detectTsupProject(
3546
projectPath: string,
3647
packages?: WorkspacePackage[],
@@ -108,7 +119,6 @@ interface SharedTsupConfig {
108119

109120
interface TsupConfigLocation {
110121
configPath: string;
111-
targetPath: string;
112122
}
113123

114124
interface UnsupportedTsupConfigConsumer {
@@ -180,13 +190,13 @@ function collectTsupConfigCollisions(tsupTargets: string[]): TsupConfigLocation[
180190
for (const target of tsupTargets) {
181191
const tsdownConfig = detectConfigs(target).tsdownConfig;
182192
if (tsdownConfig) {
183-
collisions.push({ configPath: path.join(target, tsdownConfig), targetPath: target });
193+
collisions.push({ configPath: path.join(target, tsdownConfig) });
184194
}
185195
const packageJsonPath = path.join(target, 'package.json');
186196
if (fs.existsSync(packageJsonPath)) {
187197
const packageJson = readJsonFile(packageJsonPath);
188198
if (Object.hasOwn(packageJson, 'tsdown')) {
189-
collisions.push({ configPath: `${packageJsonPath}#tsdown`, targetPath: target });
199+
collisions.push({ configPath: `${packageJsonPath}#tsdown` });
190200
}
191201
}
192202
}
@@ -199,7 +209,7 @@ function collectInlineTsupConfigs(tsupTargets: string[]): TsupConfigLocation[] {
199209
if (!fs.existsSync(packageJsonPath) || !Object.hasOwn(readJsonFile(packageJsonPath), 'tsup')) {
200210
return [];
201211
}
202-
return [{ configPath: `${packageJsonPath}#tsup`, targetPath: target }];
212+
return [{ configPath: `${packageJsonPath}#tsup` }];
203213
});
204214
}
205215

@@ -427,12 +437,11 @@ export async function migrateTsupToTsdown(
427437
.map(({ configPath }) => ` ${displayRelative(configPath, projectPath)}`)
428438
.join('\n')}`,
429439
);
430-
const firstCollisionTarget = configCollisions[0].targetPath;
431-
const targetLabel =
432-
firstCollisionTarget === rootPath
433-
? 'the project root'
434-
: displayRelative(firstCollisionTarget, projectPath);
435-
showTsdownMigrationOptions(targetLabel);
440+
showTsdownMigrationSkillGuidance([
441+
'Resolve this configuration conflict manually:',
442+
' 1. Merge the tsup and tsdown configurations into `pack` in `vite.config.*`.',
443+
' 2. Do not run `tsdown-migrate`. It can overwrite the existing tsdown configuration.',
444+
]);
436445
return false;
437446
}
438447
const inlineTsupConfigs = collectInlineTsupConfigs(tsupTargets);
@@ -442,12 +451,11 @@ export async function migrateTsupToTsdown(
442451
.map(({ configPath }) => ` ${displayRelative(configPath, projectPath)}`)
443452
.join('\n')}`,
444453
);
445-
const firstInlineTarget = inlineTsupConfigs[0].targetPath;
446-
const targetLabel =
447-
firstInlineTarget === rootPath
448-
? 'the project root'
449-
: displayRelative(firstInlineTarget, projectPath);
450-
showTsdownMigrationOptions(targetLabel);
454+
showTsdownMigrationSkillGuidance([
455+
'Resolve this inline configuration manually:',
456+
' 1. Move each `package.json#tsup` configuration into `pack` in `vite.config.*`.',
457+
' 2. Do not run `tsdown-migrate`. Vite+ Pack does not read `package.json#tsdown`.',
458+
]);
451459
return false;
452460
}
453461
const unsupportedConfigConsumers = collectUnsupportedTsupConfigConsumers(tsupTargets);
@@ -460,12 +468,12 @@ export async function migrateTsupToTsdown(
460468
)
461469
.join('\n')}`,
462470
);
463-
const firstConsumerTarget = unsupportedConfigConsumers[0].packagePath;
464-
const targetLabel =
465-
firstConsumerTarget === rootPath
466-
? 'the project root'
467-
: displayRelative(firstConsumerTarget, projectPath);
468-
showTsdownMigrationOptions(targetLabel);
471+
showTsdownMigrationSkillGuidance([
472+
'Resolve these config paths manually:',
473+
' 1. Migrate each listed config into `pack` in `vite.config.*`.',
474+
' 2. Update each listed script.',
475+
' 3. Do not run `tsdown-migrate`. It cannot safely resolve these config paths.',
476+
]);
469477
return false;
470478
}
471479
const sharedConfigs = collectSharedTsupConfigs(projectPath, packages, tsupTargets);

0 commit comments

Comments
 (0)