Skip to main content

Change Source

Change the source of the import module

import Utils from "utils"

Options

type Options = {
fromSource: string;
toSource: string;
sourceType?: "relative" | "absolute";
};
  • fromSource: change target specifier
  • toSource: changed target specifier
  • sourceType: change target source's type. you can choose absolute or relative

Usage

The usage method differs depending on the source type of the import statement to be converted.

absolute

This is a situation where the source of the import module you want to change is an absolute path.

option.ts
const option = {
sourceType: "absolute",
fromSource: "utils",
toSource: "lib",
};
import Utils from "utils"

relative

This is a situation where the source of the import module you want to change is an absolute path.

option.ts
const option = {
sourceType: "relative",
fromSource: path.join(process.cwd(), "test/utils.ts"),
toSource: path.join(process.cwd(), "test/lib.ts"),
};
import Utils from "./test/utils.ts"