Created
February 13, 2024 22:31
-
-
Save Retsam/4f87a0e128f5a1628f61c95960e3cd8f to your computer and use it in GitHub Desktop.
ts-morph script to migrate to react-jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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