Skip to content

Instantly share code, notes, and snippets.

@Retsam
Created February 13, 2024 22:31
Show Gist options
  • Save Retsam/4f87a0e128f5a1628f61c95960e3cd8f to your computer and use it in GitHub Desktop.
Save Retsam/4f87a0e128f5a1628f61c95960e3cd8f to your computer and use it in GitHub Desktop.
ts-morph script to migrate to react-jsx
const { Project } = require("ts-morph");
/**
* Loops through all TSX files and removes unused imports,
* which will cleanup the `import React from "react"` if it's no longer needed
*/
const project = new Project({
tsConfigFilePath: "tsconfig.json",
});
const reactFiles = project
.getSourceFiles()
.filter(f => f.getBaseName().endsWith(".tsx"));
async function main() {
await Promise.all(
reactFiles.map(file => {
file.fixUnusedIdentifiers();
return file.save();
}),
);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment