Translates typescript paths aliases into relative paths.
bun i -D ts-paths-resolver
pnpm i -D ts-paths-resolver
yarn add -D ts-paths-resolver
npm i -D ts-paths-resolver
resolve-ts-paths -d [distPath] -tsc [tsconfigPath] -pj [packageJsonPath]
Options:
--help Show help [boolean]
--version Show version number [boolean]
-d The path to the repo [default: "./dist"]
--tsc The height [default: "./tsconfig.json"]
--pj The height [default: "./package.json"]
Examples:
resolve-ts-paths -d ./dist -tsc ./tsconfig.json -pj ./package.json
bun resolve-ts-paths -d ./dist -tsc ./tsconfig.json -pj ./package.json
bun resolve-ts-paths-esm -d ./dist -tsc ./tsconfig.json -pj ./package.json
import { resolveTsPaths } from 'ts-paths-resolver';
const distPath = './dist';
const tsconfigPath = './tsconfig.json';
const packageJsonPath = './package.json';
await resolveTsPaths({
distPath,
tsconfigPath,
packageJsonPath,
});
You can also import the effect:
import { NodeFileSystem } from '@effect/platform-node';
import { Effect, pipe } from 'effect';
import { runPromise } from 'effect-errors';
import { resolveTsPathsEffect } from 'ts-paths-resolver';
await runPromise(
pipe(
resolveTsPathsEffect({
distPath: 'dist',
tsconfigPath: './tsconfig.json',
packageJsonPath: './package.json',
}),
Effect.provide(NodeFileSystem.layer)
)
);
This module takes the following input to translate paths aliases import/require statements into relative paths within a folder.
The transpiled code location.
rootDir
: Root folder within your source files.paths
: 1 set of entries that re-map imports to additional lookup locations.
{
"compilerOptions": {
// ...
"rootDir": "./src",
"paths": {
"@dependencies/*": ["./src/dependencies/*"],
"@regex": ["./src/util/regex/regex.ts"]
}
}
}
main
:cjs
entry point.module
:esm
entry point.types
: declaration files entry point.
{
"main": "./cjs/index.js",
"module": "./esm/index.js",
"types": "./dts/index.d.ts"
// ...
}