Change Source
Change the source of the import module
- before
- after
import Utils from "utils"
import Utils from "lib"
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",
};
- before
- after
import Utils from "utils"
import Utils from "lib"
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"),
};
- before
- after
import Utils from "./test/utils.ts"
import Utils from "./test/lib.ts"