-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add new codemods package #13884
Add new codemods package #13884
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit f785759:
|
Asset size changesSize Auditor did not detect a change in bundle size for any component! Baseline commit: b4adf81c515bd8fcee8264da0dd93d23f881f3cd (build) |
Perf AnalysisNo significant results to display. All results
Perf Analysis (Fluent)Perf comparison
Perf tests with no regressions
|
packages/codemods/src/codeMods/__tests__/ComponentToCompat/ComponentToCompat.test.ts
Outdated
Show resolved
Hide resolved
packages/codemods/src/codeMods/__tests__/ComponentToCompat/ComponentToCompat.test.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments but for the rest, I'd appreciate if we could do a call where you walk through how various parts of the project and tests are intended to work. (it's a lot of code to try to understand at once)
packages/codemods/src/codeMods/__tests__/ComponentToCompat/ComponentToCompat.test.ts
Outdated
Show resolved
Hide resolved
packages/codemods/src/codeMods/__tests__/ComponentToCompat/ComponentToCompat.test.ts
Outdated
Show resolved
Hide resolved
packages/codemods/src/codeMods/mods/PersonaToAvatar/PersonaToAvatar.mod.ts
Outdated
Show resolved
Hide resolved
replacePersonaImport(file); | ||
replaceIPersonaPropsImport(file); | ||
replacePersonaSizeImport(file); | ||
renamePrimaryTextProp(file); | ||
renameRenderCoin(file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These right here; in my suggestion above, could these be just replacement type
s in a config?
Some of them probably not. E.g. renameRenderCoin
finds Persona
jsx elements and renames onRenderCoin
to onRenderAvatarCoin
(which I think is wrong btw.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, you may need a custom type
which does some sort of manual work programatically. But whatever we can do to simplify and keep the codemod data driven is good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more of a proof of concept for right now that I should make more clear.
As for the config, we could potentially allow some of these to take in a json blob. For the start we should get the api of the functions correct. Trip and I are working on that.
packages/codemods/src/codeMods/mods/ComponentToCompat/CompatHelpers.ts
Outdated
Show resolved
Hide resolved
packages/codemods/src/codeMods/__tests__/ComponentToCompat/ComponentToCompat.test.ts
Outdated
Show resolved
Hide resolved
}); | ||
|
||
it('correctly repaths from index', () => { | ||
const file = project.getSourceFileOrThrow('ImportsStuff.tsx'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having trouble understanding what some of the rest of these do too, since you're using fake files which don't actually reference OUFR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's making sure that the utilities/each individual piece does the job that it's supposed to do. That way when they all get put together it will work as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of what I meant by that was that it would be helpful to have more comments explaining what each one does. And I'm still having trouble how it works with fake files which don't actually reference OUFR.
packages/codemods/src/codeMods/__tests__/ComponentToCompat/ComponentToCompat.test.ts
Outdated
Show resolved
Hide resolved
const tVal = val as InterfaceDeclaration; | ||
const struct = tVal.getStructure(); | ||
expect( | ||
(struct.extends as string[])?.some(str => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if struct.extends
isn't defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has to be defined, at least that's a guarantee when you call getStructure()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case can you use !
instead of ?
packages/codemods/src/codeMods/__tests__/personaToAvatar/componentMod.test.ts
Outdated
Show resolved
Hide resolved
packages/codemods/src/codeMods/__tests__/personaToAvatar/propsMod.test.ts
Outdated
Show resolved
Hide resolved
packages/codemods/src/codeMods/__tests__/personaToAvatar/componentMod.test.ts
Outdated
Show resolved
Hide resolved
packages/codemods/src/codeMods/__tests__/utilities/importUtils.test.ts
Outdated
Show resolved
Hide resolved
packages/codemods/src/codeMods/__tests__/utilities/importUtils.test.ts
Outdated
Show resolved
Hide resolved
packages/codemods/src/codeMods/__tests__/utilities/importUtils.test.ts
Outdated
Show resolved
Hide resolved
packages/codemods/src/codeMods/mods/ComponentToCompat/CompatHelpers.ts
Outdated
Show resolved
Hide resolved
packages/codemods/src/codeMods/__tests__/ComponentToCompat/ComponentToCompat.test.ts
Outdated
Show resolved
Hide resolved
packages/codemods/src/codeMods/mods/PersonaToAvatar/PersonaToAvatar.mod.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Makoto Morimoto <Humberto.Morimoto@microsoft.com> Co-authored-by: Elizabeth Craig <ecraig12345@gmail.com> Co-authored-by: Xu Gao <xugao0131@hotmail.com>
🎉 Handy links: |
Pull request checklist
$ yarn change
Description of changes
Adds the basis for codemods. Work that this completes:
The primary files to focus on are
upgrade.ts
andrunnerUtilities
. These setup the framework for how codemods will run. Additional work still needs to be done to:Focus areas to test
(optional)