A small script that rewrites ES imports written in Deno using ES Module Lexer and Worker modules.
Install Deno (if not already set up) using the instructions below:
https://docs.deno.com/runtime/manual/getting_started/installation
Clone the repository
git clone https://github.com/Barabasbalazs/esm-imports-ts-to-js.git
The project can be configured trough the config.json file in the root directory.
{
"directory": "./tests/testing-util/example-directory",
"extensions": [".js", ".ts"],
"patternToReplace": ".js",
"addedString": ".ts",
"ignoreExtensionless": false,
"relativeOnly": true
}
Provide the path of the project that needs to be modified (either by relative or absolute path)
Only files with the provided extensions will be parsed.
Imports containing this string will be replaced.
The string that we'd like to add to the import statements provided in the patterToReplace setting.
Extensionless imports can be ignored so imports from node_modules won't be affected.
Only relative imports will be rewritten. The following starting paths are used to identify these:
[".", "/", "~", "@", "src"]
Important
Since
ES Module Lexer
only supports .js and .ts files, projects using other file extensions, can't be parsed (.vue, .tsx)
Once the configuration file is set up, try running the program with the following command:
deno task run
This project was created with the goal of making it easier to refactor import statements in modern ESM based projects.
Unfortunately ESM, TS and other frameworks/libraries often times have different requirements when it comes to import syntax.
One example for this problem would be TSC and Node.js not playing well together.
The project aims to simplify this arduous process.