typeorm-codebase-sync
Version:
Automatically update your codebase to add migrations, entities and subscribers to your `data-source.ts` file
23 lines • 870 B
JavaScript
import path from "path";
export function getRelativeImportPath(containingFilePath, importedFilePath, moduleSystem) {
let relativePath = path.relative(path.dirname(containingFilePath), importedFilePath);
const extName = path.extname(relativePath);
const changeExtName = (newExt) => relativePath = relativePath.slice(0, -extName.length) + newExt;
if (extName === ".mts")
changeExtName(".mjs");
else if (extName === ".cts")
changeExtName(".cjs");
else if (extName === ".ts") {
if (moduleSystem === "esm")
changeExtName(".js");
else
changeExtName("");
}
relativePath = relativePath
.split(path.sep)
.join("/");
if (!relativePath.startsWith("."))
relativePath = "./" + relativePath;
return relativePath;
}
//# sourceMappingURL=getRelativeImportPath.js.map