Skip to content

Instantly share code, notes, and snippets.

@martypdx
Last active October 16, 2021 09:02
Show Gist options
  • Save martypdx/ba0ab45094f9a71f7cf204687767456c to your computer and use it in GitHub Desktop.
Save martypdx/ba0ab45094f9a71f7cf204687767456c to your computer and use it in GitHub Desktop.
# rename all .js to .mjs
for f in **/*.js; do mv -- "$f" "${f%.js}.mjs"; done
# add .mjs to all file-based import statements*
find . -type f -name "*.mjs" -exec sed -i '' -E "s/(import.+'\.[a-zA-Z0-9\.\/-]+)';/\1\.mjs';/g" {} \;
# *NOTES:
# 1. This will double up existing .mjs extension in imports.
# Couldn't get phrase negation working in this sed substitution regex :(
#
# 2. Doesn't work on multi-line import statements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment