Seperate Named Specifier
Change the specifier of the import module and the identifier that uses it. but local variable is not converted. only convert global value
- before
- after
import { calculateSum, calculateSubtract } from "utils";
import { calculateSum } from "lib";
import { calculateSubtract } from "utils";
Options
type Options {
specifiers: string[];
fromSource: string;
toSource: string;
sourceType?: "relative" | "absolute";
}
- specifiers: seperate named specifier's specifiers
- fromSource: seperate named specifier's source
- toSource: seperate named specifier's target source
- sourceType: seperate named specifier's 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 = {
specifiers: ["calculateSum"],
sourceType: "absolute",
fromSource: "utils",
toSource: "lib",
};
- before
- after
import { calculateSum } from "utils";
import { calculateSum } 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",
specifiers: ["calculateSum"],
fromSource: path.join(process.cwd(), "../test/utils.ts"),
toSource: path.join(process.cwd(), "../lib.ts"),
};
- before
- after
import { sum } from "./utils.ts"
console.log(sum())
import { calculateSum } from "./utils.ts"
console.log(calculateSum())