Skip to content

Translates typescript paths aliases into relative paths

License

Notifications You must be signed in to change notification settings

jpb06/ts-paths-resolver

Repository files navigation

ts-paths-resolver

Open in Visual Studio Code npm downloads npm bundle size Github workflow Quality Gate Status Maintainability Rating Security Rating Reliability Rating Coverage Lines of Code Technical Debt Code Smells Bugs Vulnerabilities Duplicated Lines (%) Last commit

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 { 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)
  )
);

⚡ 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"
  // ...
}

About

Translates typescript paths aliases into relative paths

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published