Skip to content

Instantly share code, notes, and snippets.

@hi-ogawa
Last active October 27, 2022 03:07
Show Gist options
  • Save hi-ogawa/1eff844e6231f90448094663ebcefb3e to your computer and use it in GitHub Desktop.
Save hi-ogawa/1eff844e6231f90448094663ebcefb3e to your computer and use it in GitHub Desktop.
replace star import with default import

to help migrating a code base when enabling esModuleInterop (https://www.typescriptlang.org/tsconfig#esModuleInterop)

# import * as path from "path"
#
# import path from "path"

git grep -z -l 'import \* as' | xargs -0 perl -pi -e 's/import \* as /import /g'

# only simple module name (e.g. "some-module" but not "./some-file")
git grep -z -l 'import \* as' | xargs -0 perl -pi -e 's/import \* as (\w+) from ("[^\/]+")/import $1 from $2/g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment