diff --git a/packages/ts-migrate-server/src/migrate/index.ts b/packages/ts-migrate-server/src/migrate/index.ts index 86cfa94..96e5e7b 100644 --- a/packages/ts-migrate-server/src/migrate/index.ts +++ b/packages/ts-migrate-server/src/migrate/index.ts @@ -20,7 +20,7 @@ export default async function migrate({ config, sources, lintConfig, -}: MigrateParams): Promise { +}: MigrateParams): Promise<{ exitCode: number; updatedSourceFiles: Set }> { let exitCode = 0; log.info(`TypeScript version: ${ts.version}`); @@ -115,7 +115,7 @@ export default async function migrate({ log.info(`Wrote ${updatedSourceFiles.size} updated file(s) in ${writeTimer.elapsedStr()}.`); - return exitCode; + return { updatedSourceFiles, exitCode }; } function getSourceFilesToMigrate(project: Project) { diff --git a/packages/ts-migrate-server/tests/commands/migrate/migrate.test.ts b/packages/ts-migrate-server/tests/commands/migrate/migrate.test.ts index b2738d8..39f0e8a 100644 --- a/packages/ts-migrate-server/tests/commands/migrate/migrate.test.ts +++ b/packages/ts-migrate-server/tests/commands/migrate/migrate.test.ts @@ -38,7 +38,7 @@ describe('migrate command', () => { {}, ); - const exitCode = await migrate({ rootDir, config }); + const { exitCode } = await migrate({ rootDir, config }); fs.unlinkSync(path.resolve(rootDir, 'tsconfig.json')); const [rootData, outputData] = getDirData(rootDir, outputDir); expect(rootData).toEqual(outputData); @@ -65,7 +65,7 @@ describe('migrate command', () => { {}, ); - const exitCode = await migrate({ + const { exitCode } = await migrate({ rootDir, config, sources: 'index.ts', @@ -95,7 +95,7 @@ describe('migrate command', () => { {}, ); - const exitCode = await migrate({ + const { exitCode, updatedSourceFiles } = await migrate({ rootDir, config, sources: path.resolve(rootDir, 'index.ts'), @@ -104,6 +104,11 @@ describe('migrate command', () => { const [rootData, outputData] = getDirData(rootDir, outputDir); expect(rootData).toEqual(outputData); expect(exitCode).toBe(0); + + const pathsRelativeToOutputDir = Array.from(updatedSourceFiles).map((filePath) => + path.relative(rootDir, filePath), + ); + expect(pathsRelativeToOutputDir).toEqual(['index.ts']); }); }); @@ -137,7 +142,7 @@ describe('migrate command', () => { {}, ); - const exitCode = await migrate({ rootDir, config }); + const { exitCode } = await migrate({ rootDir, config }); fs.unlinkSync(path.resolve(rootDir, 'tsconfig.json')); const [rootData, outputData] = getDirData(rootDir, outputDir); expect(rootData).toEqual(outputData); diff --git a/packages/ts-migrate/cli.ts b/packages/ts-migrate/cli.ts index 4557c87..d110205 100644 --- a/packages/ts-migrate/cli.ts +++ b/packages/ts-migrate/cli.ts @@ -186,7 +186,7 @@ yargs .addPlugin(eslintFixPlugin, {}); } - const exitCode = await migrate({ rootDir, config, sources }); + const { exitCode } = await migrate({ rootDir, config, sources }); process.exit(exitCode); }, @@ -239,7 +239,7 @@ yargs }) .addPlugin(eslintFixChangedPlugin, {}); - const exitCode = await migrate({ rootDir, config }); + const { exitCode } = await migrate({ rootDir, config }); process.exit(exitCode); }, diff --git a/packages/ts-migrate/tests/commands/migrate/migrate.test.ts b/packages/ts-migrate/tests/commands/migrate/migrate.test.ts index 8c1e60b..e4468e9 100644 --- a/packages/ts-migrate/tests/commands/migrate/migrate.test.ts +++ b/packages/ts-migrate/tests/commands/migrate/migrate.test.ts @@ -29,7 +29,7 @@ describe('migrate command', () => { .addPlugin(tsIgnorePlugin, { messagePrefix: 'FIXME' }) .addPlugin(eslintFixPlugin, {}); - const exitCode = await migrate({ rootDir, config }); + const { exitCode } = await migrate({ rootDir, config }); const [rootData, outputData] = getDirData(rootDir, outputDir); expect(rootData).toEqual(outputData); expect(exitCode).toBe(0);