ts-paths-resolver
v1.1.9
Published
Yet another paths resolver for typescript paths aliases
Downloads
849
Readme
ts-paths-resolver
Translates typescript paths aliases into relative paths.
⚡ Usage
🔶 Install
bun i -D ts-paths-resolver
pnpm i -D ts-paths-resolver
yarn add -D ts-paths-resolver
npm i -D ts-paths-resolver
🔶 cli
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
🧿 cjs
bun resolve-ts-paths -d ./dist -tsc ./tsconfig.json -pj ./package.json
🧿 esm
bun resolve-ts-paths-esm -d ./dist -tsc ./tsconfig.json -pj ./package.json
🔶 node
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 { Effect } from 'effect';
import { resolveTsPathsEffect } from 'ts-paths-resolver';
await Effect.runPromise(
resolveTsPathsEffect({
distPath,
tsconfigPath,
packageJsonPath,
})
);
⚡ Required inputs
This module takes the following input to translate paths aliases import/require statements into relative paths within a folder.
🧿 dist folder
The transpiled code location.
🧿 tsconfig.json
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"]
}
}
}
🧿 package.json
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"
// ...
}