Skip to content

Instantly share code, notes, and snippets.

@holgerd77
Last active June 14, 2023 09:44
Show Gist options
  • Save holgerd77/49baa4159b0bc455e9fd8d37e44b314e to your computer and use it in GitHub Desktop.
Save holgerd77/49baa4159b0bc455e9fd8d37e44b314e to your computer and use it in GitHub Desktop.
ESM Transition - .js File Path Additions - RegEx Cheat Sheet
Add Fully Qualified ESM Imports
-------------------------------
*****************************
In test and src folder
*****************************
RUN TESTS OFTEN (AFTER EACH LARGE OP)!!
EVENTUALLY IN-BETWEEN COMMITS!!
NO REGEX/REGEX EXTREMELY IMPORTANT (OTHERWISE FALSE REPLACEMENTS)!!
First do explicit replacements for both src and all subfolders containing an
index.js file, WITHOUT (!) adding the .js extension yet.
from '(\.[^']*)/src' // Regex
from '$1/src/index'
from '(\.[^']*)/cache' // Regex (e.g. StateManager cache folder)
from '$1/cache/index'
Now do all .js additions with:
from '(\.[^']+)(?<!\.json)' // Regex
from '$1.js'
from '.' // No regex
from './index.js'
from '..' // No regex
from '../index.js'
ethereum-cryptography deep imports:
(e.g. "import { keccak256 } from 'ethereum-cryptography/keccak)")
from 'ethereum-cryptography/([^']+)' // Regex
from 'ethereum-cryptography/$1.js'
Overview searches:
from '. (so no closing single quote) // No regex
from '[^@][^']+(?<!\.js)' // Regex
Do other replacements manually.
Note: mostly deep imports can (and should!) be replaced by
from '../src/index.js' a well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment