hypermod-io / hypermod-community

Community-owned global registry and documentation hub for codemods. Write & run codemods, share them with your friends!
https://hypermod.io
MIT License
134 stars 18 forks source link

Feature: Allow adding a TS 4.5 style type import #103

Open IanVS opened 2 years ago

IanVS commented 2 years ago

I'm trying to write a codemod that changes from the old style of type imports:

import type {MyType} from './types';

to the newer style:

import {type MyType} from './types';

I saw you have some import helpers, but don't see anything that allows creation of an ImportSpecifier with importKind: "type", which I think is what is needed. Maybe you could consider adding it?

Thanks!

IanVS commented 2 years ago

Actually, I wonder if this is even possible. I opened a request at https://github.com/facebook/jscodeshift/issues/481, because I think jscodeshift does not allow this kind of creation.

danieldelcore commented 2 years ago

Yeah, in fact i think this is actually a recast thing! Please LMK if you manage to find a solution :)

IanVS commented 2 years ago

I was able to find a way to accomplish what I was trying to do, and published an npm package: https://www.npmjs.com/package/type-import-codemod

It didn't quite seem to fit with the goals of this project (it's not something intended to use with a particular library/package), but I did start off down that road at first and the scaffolding from the cli was helpful, so thanks!

danieldelcore commented 2 years ago

That's actually really cool lib, thanks for sharing!

I can actually see this being incorporated into this library in a few ways!

Just for context, the goal of this project is to do the following:

  1. Provide documentation for writing and publishing codemods
  2. Provide tooling & utilities to make it easier to write and run codemods
  3. Provide a library of community codemods, similar to definitelytyped

Would love to pair with you to add this if you're interested in contributing 👍

IanVS commented 2 years ago

I haven't forgotten about this issue, I've just been preoccupied with other things lately. But, I'm giving a talk at a meetup about codemods using my project above as an example, and will mention CodeshiftCommunity as well. I hope to come back to this once things have settled down a bit.

danieldelcore commented 2 years ago

That sounds fantastic! All the best with your talk!! Send me a link to the recording, would love to watch!

danieldelcore commented 2 years ago

Hey @IanVS, how'd your talk go!? Is there a recording or something I can watch!