typescript-transform-paths
Transforms module resolution paths using TypeScript path mapping
Last updated 4 years ago by nonara .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install typescript-transform-paths 
SYNC missed versions from official npm registry.

typescript-transform-paths

npm version Build Status Appveyor Build status Conventional Commits code style: prettier All Contributors

Transform module resolution paths in compiled output source to conform with TypeScript internal resolution via tsconfig.json settings (paths, rootDirs, baseUrl)

Install

# NPM
npm i -D typescript-transform-paths

# Yarn
yarn add -D typescript-transform-paths

Usage with ttypescript or ts-patch

Add it to plugins in your tsconfig.json

Example Config

{
  "compilerOptions": {
    "baseUrl": "./",
    "paths": {
      "@utils/*": ["utils/*"]
    },
    "plugins": [
      // Tranform paths in output .js files
      { "transform": "typescript-transform-paths" },

      // Tranform paths in output .d.ts files
      { "transform": "typescript-transform-paths", "afterDeclarations": true }
    ]
  }
}

core/index.ts

import { sum } from "@utils/sum";
sum(2, 3);

core/index.js (compiled output)

// core/index.js
var sum_1 = require("../utils/sum");
sum_1.sum(2, 3);

Virtual Directories

TS allows defining virtual directories via the rootDirs compiler option.
To enable virtual directory mapping, use the useRootDirs plugin option.

{
  "compilerOptions": {
    "rootDirs": [ "src", "generated" ],
    "baseUrl": ".",
    "paths": {
      "#root/*": [ "./src/*", "./generated/*" ]
    },
    "plugins": [
      { "transform": "typescript-transform-paths", "useRootDirs": true },
      { "transform": "typescript-transform-paths", "useRootDirs": true, "afterDeclarations": true }
    ]
  }
}

Example

- src/
    - subdir/
      - sub-file.ts
    - file1.ts
- generated/
    - file2.ts

src/file1.ts

import '#root/file2.ts' // resolves to './file2'

src/subdir/sub-file.ts

import '#root/file2.ts' // resolves to '../file2'
import '#root/file1.ts' // resolves to '../file1'

Articles

Project Guidelines for Contributors

  • Package Manager: yarn (yarn install)
  • Commit messages: Conventional Commit Specs
  • Format before commit: prettier (yarn run format)
  • Releases: standard-version (yarn run release)

Maintainers


Ron S.

Daniel Perez Alvarez

Contributors

Thanks goes to these wonderful people (emoji key):


Daniel Perez Alvarez

πŸ’» 🚧 ⚠️

ΠœΠΈΡ…Π°ΠΉΠ»ΠΎΠ² Антон

πŸ’» πŸ› ⚠️

Joshua Avalon

πŸ› πŸ“¦

Robert Laverty

πŸ› ⚠️

Ole Ersoy

πŸ› πŸ“

sbmw

πŸ›

richardspence

πŸ›

Vitaly Pinchuk

πŸ›

laij84

πŸ›

dko-slapdash

πŸ›

hedwiggggg

πŸ› ⚠️ πŸ’»

kuskoman

πŸ“–

alex weidner

πŸ›

Ron S.

πŸ› ⚠️ πŸ’»

Vladimir Yakovlev

πŸ›

vwpo

πŸ›

This project follows the all-contributors specification. Contributions of any kind welcome!

Current Tags

  • 3.4.0-alpha                                ...           alpha (3 years ago)
  • 2.1.0-beta                                ...           beta (4 years ago)
  • 2.1.0-beta1                                ...           beta1 (4 years ago)
  • 2.1.0-beta2                                ...           beta2 (4 years ago)
  • 3.5.2                                ...           latest (2 months ago)
  • 3.4.10-1723087060.2b01c26                                ...           testing (5 months ago)

60 Versions

  • 3.5.2                                ...           2 months ago
  • 3.5.1                                ...           3 months ago
  • 3.5.0                                ...           4 months ago
  • 3.4.11                                ...           4 months ago
  • 3.4.10                                ...           5 months ago
  • 3.4.10-1723087060.2b01c26                                ...           5 months ago
  • 3.4.10-1723086173.5a2b0c9                                ...           5 months ago
  • 3.4.9                                ...           5 months ago
  • 3.4.9-0                                ...           5 months ago
  • 3.4.8                                ...           5 months ago
  • 3.4.7                                ...           10 months ago
  • 3.4.6                                ...           2 years ago
  • 3.4.5                                ...           2 years ago
  • 3.4.4                                ...           2 years ago
  • 3.4.3                                ...           2 years ago
  • 3.4.2                                ...           2 years ago
  • 3.4.1                                ...           2 years ago
  • 3.4.0                                ...           2 years ago
  • 3.4.0-alpha                                ...           3 years ago
  • 3.3.1                                ...           3 years ago
  • 3.3.0                                ...           3 years ago
  • 3.2.1                                ...           3 years ago
  • 3.2.0                                ...           3 years ago
  • 3.1.0                                ...           3 years ago
  • 3.0.2                                ...           3 years ago
  • 3.0.1                                ...           3 years ago
  • 3.0.0                                ...           4 years ago
  • 2.2.4                                ...           4 years ago
  • 2.2.3                                ...           4 years ago
  • 2.2.2                                ...           4 years ago
  • 2.2.1                                ...           4 years ago
  • 2.2.0                                ...           4 years ago
  • 2.1.0                                ...           4 years ago
  • 2.1.0-beta2                                ...           4 years ago
  • 2.1.0-beta1 [deprecated]           ...           4 years ago
  • 2.1.0-beta                                ...           4 years ago
  • 2.0.4                                ...           4 years ago
  • 2.0.3                                ...           4 years ago
  • 2.0.2                                ...           4 years ago
  • 2.0.1                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.1.15                                ...           4 years ago
  • 1.1.14                                ...           5 years ago
  • 1.1.13                                ...           5 years ago
  • 1.1.12                                ...           5 years ago
  • 1.1.11                                ...           5 years ago
  • 1.1.10                                ...           5 years ago
  • 1.1.9                                ...           5 years ago
  • 1.1.8                                ...           5 years ago
  • 1.1.7                                ...           5 years ago
  • 1.1.6                                ...           5 years ago
  • 1.1.5                                ...           5 years ago
  • 1.1.4                                ...           6 years ago
  • 1.1.3                                ...           6 years ago
  • 1.1.2                                ...           6 years ago
  • 1.1.1                                ...           6 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.2                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (2)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (12)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE