Skip to content

Barabasbalazs/esm-import-modifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

esm-import-modifier

A small script that rewrites ES imports written in Deno using ES Module Lexer and Worker modules.

Installation

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

Settings

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
}

directory

Provide the path of the project that needs to be modified (either by relative or absolute path)

extensions

Only files with the provided extensions will be parsed.

patternToReplace

Imports containing this string will be replaced.

addedString

The string that we'd like to add to the import statements provided in the patterToReplace setting.

ignoreExtensionless

Extensionless imports can be ignored so imports from node_modules won't be affected.

relativeOnly

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)

Run

Once the configuration file is set up, try running the program with the following command:

deno task run

Use case

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published