Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ts-migrate-server to pass back a list of migrated files #175

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/ts-migrate-server/src/migrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default async function migrate({
config,
sources,
lintConfig,
}: MigrateParams): Promise<number> {
}: MigrateParams): Promise<{ exitCode: number; updatedSourceFiles: Set<string> }> {
let exitCode = 0;
log.info(`TypeScript version: ${ts.version}`);

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -65,7 +65,7 @@ describe('migrate command', () => {
{},
);

const exitCode = await migrate({
const { exitCode } = await migrate({
rootDir,
config,
sources: 'index.ts',
Expand Down Expand Up @@ -95,7 +95,7 @@ describe('migrate command', () => {
{},
);

const exitCode = await migrate({
const { exitCode, updatedSourceFiles } = await migrate({
rootDir,
config,
sources: path.resolve(rootDir, 'index.ts'),
Expand All @@ -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']);
});
});

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions packages/ts-migrate/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ yargs
.addPlugin(eslintFixPlugin, {});
}

const exitCode = await migrate({ rootDir, config, sources });
const { exitCode } = await migrate({ rootDir, config, sources });

process.exit(exitCode);
},
Expand Down Expand Up @@ -239,7 +239,7 @@ yargs
})
.addPlugin(eslintFixChangedPlugin, {});

const exitCode = await migrate({ rootDir, config });
const { exitCode } = await migrate({ rootDir, config });

process.exit(exitCode);
},
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-migrate/tests/commands/migrate/migrate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down