--- robots: noindex, nofollow tags: pitch --- For instructions on shaping a project see here: [Shaping a Project](/kX02SXVbS6KzMOQd56i6Cg) # CodeMods - May ### Problem Codemods are great for the use, but they also need to be easy to write and run so the dev supporting them is excited to help upgrade codebases! ### Appetite *From: [Appetite guidance](https://basecamp.com/shapeup/1.5-chapter-06#ingredient-2-appetite)* 2 weeks. The changes necessary are surrounding infrastructure/harnesses. This mostly new code that's being written but it will serve as a base for the rest of the codemod project ### Solution A set of tools built with [ts-morph](https://ts-morph.com/) to solve the following: 1. Framework for testing codemods 1. Interface/class for how a codemod should look 2. Semvar based codemod selection. Each codemod should be related to a semvar for when the break is released. That way it is easy to detect and decide which codemods to apply 2. Applying codemods to a group of files 1. Based on path/blob 2. Based on the ts.config file * Example CLI to run codemods `npx migration.js <path to tsconfig>` 3. Document undocumented TS-morph functionality to make it easy for users to write their own mods. Example codemod ```TYPESCRIPT import { SourceFile } from "ts-morph"; import { utilities } from "../utilities/utilities"; import {ICodeMod} from '..' const searchString=/^office\-ui\-fabric\-react/; const newString = '@fluentui/react'; // This should replace ALL office-ui-fabric-react imports with @fluentui/react export function RepathOfficeToFluentImports(file: SourceFile) { let imports = utilities.getImportsByPath(file, searchString); imports.forEach(val => { utilities.repathImport(val, newString, searchString); }) } export const Foo: ICodeMod = { run: RepathOfficeToFluentImports; version: "8.0.0" } ``` ### Risks (Rabbit holes) *From: [Rabbit hole guidance](https://basecamp.com/shapeup/1.5-chapter-06#ingredient-4-rabbit-holes)* It's possible to spend too much time trying to get the perfect interface. Start with the minimal interface necessary to run a group of codemods and we can build out from there. ### Out of scope (No-gos) *From: [No-gos guidance](https://basecamp.com/shapeup/1.5-chapter-06#ingredient-5-no-gos)* Writing a lot of codemod utilities. Instead this is focused on the core functionality of running a group of codemods based on either semvar or config or both.