1 | # typescript-transform-paths
|
2 |
|
3 | [![npm version](https://img.shields.io/npm/v/typescript-transform-paths.svg)](https://www.npmjs.com/package/typescript-transform-paths)
|
4 | [![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2FLeDDGroup%2Ftypescript-transform-paths%2Fbadge%3Fref%3Dmaster&style=flat)](https://actions-badge.atrox.dev/LeDDGroup/typescript-transform-paths/goto?ref=master)
|
5 | [![Appveyor Build status](https://ci.appveyor.com/api/projects/status/4i7egn9rn7iepg31/branch/master?svg=true)](https://ci.appveyor.com/project/danielpza/typescript-transform-paths/branch/master)
|
6 | [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
|
7 | [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
|
8 | [![All Contributors](https://img.shields.io/badge/all_contributors-10-orange.svg?style=flat-square)](#contributors)
|
9 |
|
10 | Transforms absolute imports to relative from `paths` in your tsconfig.json
|
11 |
|
12 | ## Install
|
13 |
|
14 | npm:
|
15 |
|
16 | ```sh
|
17 | npm i -D typescript-transform-paths
|
18 | ```
|
19 |
|
20 | yarn:
|
21 |
|
22 | ```sh
|
23 | yarn add -D typescript-transform-paths
|
24 | ```
|
25 |
|
26 | ## Usage with [ttypescript](https://github.com/cevek/ttypescript/)
|
27 |
|
28 | Add it to _plugins_ in your _tsconfig.json_
|
29 |
|
30 | ```json
|
31 | {
|
32 | "compilerOptions": {
|
33 | "baseUrl": "./",
|
34 | "paths": {
|
35 | "@utils/*": ["utils/*"]
|
36 | },
|
37 | "plugins": [{ "transform": "typescript-transform-paths" }]
|
38 | }
|
39 | }
|
40 | ```
|
41 |
|
42 | ### Transforming declaration paths
|
43 |
|
44 | If you want to generate declaration (_.d.ts_) files with transformed paths you have to
|
45 | modify your _tsconfig.json_ file:
|
46 |
|
47 | ```json
|
48 | "compilerOptions": {
|
49 | "baseUrl": "./",
|
50 | "paths": {
|
51 | "@utils/*": ["utils/*"]
|
52 | },
|
53 | "declaration": true,
|
54 | "plugins": [
|
55 | { "transform": "typescript-transform-paths" },
|
56 | { "transform": "typescript-transform-paths", "afterDeclarations": true }
|
57 | ]
|
58 | }
|
59 | ```
|
60 |
|
61 | See [issue4](https://github.com/LeDDGroup/typescript-transform-paths/issues/4#issuecomment-486380340) for more information.
|
62 |
|
63 | ## Example
|
64 |
|
65 | ```json
|
66 | // tsconfig.json
|
67 | {
|
68 | "compilerOptions": {
|
69 | "baseUrl": "./",
|
70 | "paths": {
|
71 | "@utils/*": ["utils/*"]
|
72 | }
|
73 | }
|
74 | }
|
75 | ```
|
76 |
|
77 | ```tsx
|
78 | // core/index.ts
|
79 | import { sum } from "@utils/sum";
|
80 |
|
81 | sum(2, 3);
|
82 | ```
|
83 |
|
84 | Gets compiled to:
|
85 |
|
86 | ```js
|
87 | // core/index.js
|
88 | var sum_1 = require("../utils/sum");
|
89 | sum_1.sum(2, 3);
|
90 | ```
|
91 |
|
92 | ## Articles
|
93 |
|
94 | - [Node Consumable Modules With Typescript Paths](https://medium.com/@ole.ersoy/node-consumable-modules-with-typescript-paths-ed88a5f332fa?postPublishedType=initial) by [oleersoy](https://github.com/oleersoy")
|
95 |
|
96 | ## Contributting
|
97 |
|
98 | - make sure to format code with prettier:
|
99 |
|
100 | ```sh
|
101 | npm install --global prettier
|
102 | prettier --write src/index.ts
|
103 | ```
|
104 |
|
105 | ## Contributors
|
106 |
|
107 | Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | <table>
|
113 | <tr>
|
114 | <td align="center"><a href="https://github.com/danielpza"><img src="https://avatars2.githubusercontent.com/u/17787042?v=4" width="100px;" alt=""/><br /><sub><b>Daniel Perez Alvarez</b></sub></a><br /><a href="https://github.com/LeDDGroup/typescript-transform-paths/commits?author=danielpza" title="Code">π»</a> <a href="#maintenance-danielpza" title="Maintenance">π§</a> <a href="https://github.com/LeDDGroup/typescript-transform-paths/commits?author=danielpza" title="Tests">β οΈ</a></td>
|
115 | <td align="center"><a href="https://github.com/anion155"><img src="https://avatars1.githubusercontent.com/u/4786672?v=4" width="100px;" alt=""/><br /><sub><b>ΠΠΈΡ
Π°ΠΉΠ»ΠΎΠ² ΠΠ½ΡΠΎΠ½</b></sub></a><br /><a href="https://github.com/LeDDGroup/typescript-transform-paths/commits?author=anion155" title="Code">π»</a> <a href="https://github.com/LeDDGroup/typescript-transform-paths/issues?q=author%3Aanion155" title="Bug reports">π</a> <a href="https://github.com/LeDDGroup/typescript-transform-paths/commits?author=anion155" title="Tests">β οΈ</a></td>
|
116 | <td align="center"><a href="https://joshuaavalon.io"><img src="https://avatars0.githubusercontent.com/u/7152420?v=4" width="100px;" alt=""/><br /><sub><b>Joshua Avalon</b></sub></a><br /><a href="https://github.com/LeDDGroup/typescript-transform-paths/issues?q=author%3Ajoshuaavalon" title="Bug reports">π</a> <a href="#platform-joshuaavalon" title="Packaging/porting to new platform">π¦</a></td>
|
117 | <td align="center"><a href="https://roblav96.github.io/resume"><img src="https://avatars1.githubusercontent.com/u/1457327?v=4" width="100px;" alt=""/><br /><sub><b>Robert Laverty</b></sub></a><br /><a href="https://github.com/LeDDGroup/typescript-transform-paths/issues?q=author%3Aroblav96" title="Bug reports">π</a> <a href="https://github.com/LeDDGroup/typescript-transform-paths/commits?author=roblav96" title="Tests">β οΈ</a></td>
|
118 | <td align="center"><a href="https://github.com/oleersoy"><img src="https://avatars3.githubusercontent.com/u/1163873?v=4" width="100px;" alt=""/><br /><sub><b>Ole Ersoy</b></sub></a><br /><a href="https://github.com/LeDDGroup/typescript-transform-paths/issues?q=author%3Aoleersoy" title="Bug reports">π</a> <a href="#blog-oleersoy" title="Blogposts">π</a></td>
|
119 | <td align="center"><a href="https://github.com/sbmw"><img src="https://avatars0.githubusercontent.com/u/30099628?v=4" width="100px;" alt=""/><br /><sub><b>sbmw</b></sub></a><br /><a href="https://github.com/LeDDGroup/typescript-transform-paths/issues?q=author%3Asbmw" title="Bug reports">π</a></td>
|
120 | <td align="center"><a href="https://github.com/richardspence"><img src="https://avatars2.githubusercontent.com/u/9914123?v=4" width="100px;" alt=""/><br /><sub><b>richardspence</b></sub></a><br /><a href="https://github.com/LeDDGroup/typescript-transform-paths/issues?q=author%3Arichardspence" title="Bug reports">π</a></td>
|
121 | </tr>
|
122 | <tr>
|
123 | <td align="center"><a href="http://codepen.io/viT-1/"><img src="https://avatars1.githubusercontent.com/u/19496430?v=4" width="100px;" alt=""/><br /><sub><b>Vitaly Pinchuk</b></sub></a><br /><a href="https://github.com/LeDDGroup/typescript-transform-paths/issues?q=author%3AviT-1" title="Bug reports">π</a></td>
|
124 | <td align="center"><a href="https://github.com/laij84"><img src="https://avatars0.githubusercontent.com/u/18145822?v=4" width="100px;" alt=""/><br /><sub><b>laij84</b></sub></a><br /><a href="https://github.com/LeDDGroup/typescript-transform-paths/issues?q=author%3Alaij84" title="Bug reports">π</a></td>
|
125 | <td align="center"><a href="https://github.com/dko-slapdash"><img src="https://avatars0.githubusercontent.com/u/46383452?v=4" width="100px;" alt=""/><br /><sub><b>dko-slapdash</b></sub></a><br /><a href="https://github.com/LeDDGroup/typescript-transform-paths/issues?q=author%3Adko-slapdash" title="Bug reports">π</a></td>
|
126 | <td align="center"><a href="https://github.com/hedwiggggg"><img src="https://avatars1.githubusercontent.com/u/42947316?v=4" width="100px;" alt=""/><br /><sub><b>hedwiggggg</b></sub></a><br /><a href="https://github.com/LeDDGroup/typescript-transform-paths/issues?q=author%3Ahedwiggggg" title="Bug reports">π</a> <a href="https://github.com/LeDDGroup/typescript-transform-paths/commits?author=hedwiggggg" title="Tests">β οΈ</a> <a href="https://github.com/LeDDGroup/typescript-transform-paths/commits?author=hedwiggggg" title="Code">π»</a></td>
|
127 | <td align="center"><a href="https://github.com/kuskoman"><img src="https://avatars3.githubusercontent.com/u/15456923?v=4" width="100px;" alt=""/><br /><sub><b>kuskoman</b></sub></a><br /><a href="https://github.com/LeDDGroup/typescript-transform-paths/commits?author=kuskoman" title="Documentation">π</a></td>
|
128 | <td align="center"><a href="https://github.com/booninite"><img src="https://avatars3.githubusercontent.com/u/13647495?v=4" width="100px;" alt=""/><br /><sub><b>alex weidner</b></sub></a><br /><a href="https://github.com/LeDDGroup/typescript-transform-paths/issues?q=author%3Abooninite" title="Bug reports">π</a></td>
|
129 | <td align="center"><a href="https://github.com/nonara"><img src="https://avatars0.githubusercontent.com/u/1427565?v=4" width="100px;" alt=""/><br /><sub><b>Ron S.</b></sub></a><br /><a href="https://github.com/LeDDGroup/typescript-transform-paths/issues?q=author%3Anonara" title="Bug reports">π</a> <a href="https://github.com/LeDDGroup/typescript-transform-paths/commits?author=nonara" title="Tests">β οΈ</a> <a href="https://github.com/LeDDGroup/typescript-transform-paths/commits?author=nonara" title="Code">π»</a></td>
|
130 | </tr>
|
131 | </table>
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 | This project follows the [all-contributors](https://github.com/all-contributors/all-contributors)
|
138 | specification. Contributions of any kind welcome!
|