Skip to content

Instantly share code, notes, and snippets.

@marcagba
marcagba / fixReactImports.sh
Last active April 16, 2020 09:44
Move from `import React from 'react'` to `import * as React from 'react'
# 1. Deal with `import React from 'react'` lines
git grep -l "import React " | xargs sed -i '' "s/import\ React\ /import\ \*\ as\ React\ /g"
# 2. Deal with `import React, {...} from 'react'` lines
# Here we need one line with `import * as React from 'react';`
# and the other with `import {...} from 'react;'
# First we remove the `import React,` part
# The we insert befor the line `import * as React from 'react';`
git grep -l "import React," | xargs sed -i '' -e "s/import\ React,/import/g" -e "import\ {.*}\ from\ 'react';/ i\\
import\ \*\ as\ React\ from\ 'react';"