question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Publish a codemod to migrate away from the deprecated "styled-components/native" imports

See original GitHub issue

It’d be great to write a babel-codemod that quickly rewrites all imports and requires from styled-components/native to just styled-components;

Examples include:

// in
import /* ... */ from 'styled-components/native';
require('styled-components/native');

// out
import /* ... */ from 'styled-components';
require('styled-components');

Starting point would be the babel-codemod repo: https://github.com/square/babel-codemod

Here’s a good example of how to write a babel-codemod plugin: https://github.com/kentcdodds/babel-codemod-example

And finally this is how we target imports/requires in our babel plugin:

Hope this helps someone to get started with contributing to styled-components ❤️

The codemod should probably live in its own little repo that we can migrate to the styled-components org 💟

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
RIP21commented, Jan 23, 2018

@philpl I wrote ramda-codemod with almost the same approach and it worked well for over 500+ files with no issues at all. I think it’s quite safe to do it this way. This codemod is not a rocket science. So changing it to something more sophisticated is preliminary optimization and overengineering IMO, somebody will tell us if there will be issues. (I would personally just run search and replace against my project dir in IDE for such migration)

About TS, by default, js-codeshift is running against .js files. So .ts files will not be touched until user say so using extensions flag like: --extensions ts,js,jsx,tsx.

0reactions
probablyupcommented, Jun 21, 2018

@bbuckland That’s great! Want to add it to the RN section of the website?

(anyone else is welcome to do the same for their versions)

Read more comments on GitHub >

github_iconTop Results From Across the Web

[v3] Typescript needs to switch typings over to RN automatically
kitten mentioned this issue on Jan 23, 2018. Publish a codemod to migrate away from the deprecated "styled-components/native" imports #1441.
Read more >
Releases - styled-components
This release also deprecates the old styled-components/native import, so make sure to migrate. We also now log a warning when the web-version of...
Read more >
Write Code to Rewrite Your Code: jscodeshift - Toptal
Up your refactoring game by using codemods, scripts used to rewrite other scripts. ... deprecated.input.js import g from 'geometry'; import otherModule from ...
Read more >
Turborepo Codemods
Turborepo provides Codemod transformations and automatic migration scripts to help upgrade your Turborepo codebase when a feature is deprecated.
Read more >
Creating a custom transform for jscodeshift - Spencer Miskoviak
However, it took some effort to get the react-codemod to work properly ... manually convert "coffee" to faCoffee , add the import, deal...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found