Skip to content

Commit 3bac8bf

Browse files
authored
feat: Support paths aliases (#53)
1 parent b9679b6 commit 3bac8bf

File tree

13 files changed

+542
-257
lines changed

13 files changed

+542
-257
lines changed

README.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# ts2esm
22

3-
Converts your TypeScript import & export declarations into ESM-compatible declarations. 🪄
3+
You want to transform your project into an ECMAScript module (ESM)? Look no further! This tool (`ts2esm`) converts your TypeScript import and export declarations into ESM-compatible ones. 🪄
4+
5+
It also [works with JavaScript](https://github.com/bennycode/ts2esm/issues/20#issuecomment-1894702085) projects since TypeScript is a superset of JavaScript.
46

57
## Guide
68

7-
Convert your CommonJS TypeScript project into an ECMAScript module with these simple steps:
9+
Convert your CommonJS projects (TypeScript or JavaScript) into ECMAScript modules with these simple steps:
810

911
1. Add `"type": "module"` in your `package.json`
1012
2. Set [module](https://www.typescriptlang.org/tsconfig#module) to `"nodenext"` in your `tsconfig.json`
@@ -22,32 +24,34 @@ Watch this 5-minute video and learn how to migrate from CommonJS to ESM:
2224

2325
## Examples
2426

25-
### Imports
27+
Here you can see the transformations that `ts2esm` applies.
28+
29+
### Import Declarations
2630

27-
Turns:
31+
Before:
2832

2933
```ts
3034
import {AccountAPI} from '../account';
3135
import {RESTClient} from './client/RESTClient';
3236
```
3337

34-
Into:
38+
After:
3539

3640
```ts
3741
import {AccountAPI} from '../account/index.js';
3842
import {RESTClient} from './client/RESTClient.js';
3943
```
4044

41-
### Exports
45+
### Export Declarations
4246

43-
Turns:
47+
Before:
4448

4549
```ts
4650
export * from './account';
4751
export * from './UserAPI';
4852
```
4953

50-
Into:
54+
After:
5155

5256
```ts
5357
export * from './account/index.js';
@@ -56,27 +60,27 @@ export * from './UserAPI.js';
5660

5761
### JSON Import Assertions
5862

59-
Turns:
63+
Before:
6064

6165
```ts
6266
import listAccounts from '../test/fixtures/listAccounts.json';
6367
```
6468

65-
Into:
69+
After:
6670

6771
```ts
6872
import listAccounts from '../test/fixtures/listAccounts.json' assert {type: 'json'};
6973
```
7074

7175
### CSS Import Assertions
7276

73-
Turns:
77+
Before:
7478

7579
```ts
7680
import styles from './MyComponent.module.css';
7781
```
7882

79-
Into:
83+
After:
8084

8185
```ts
8286
import styles from './MyComponent.module.css' assert {type: 'css'};
@@ -90,19 +94,19 @@ Simply run this command to install `ts2esm` globally on your machine:
9094
npm i -g ts2esm
9195
```
9296

93-
Afterwards, just launch the program inside the directory of your TS project (it will ask you for your `tsconfig.json`):
97+
Afterwards, just launch the program inside the directory of your project (it will ask you for your `tsconfig.json`):
9498

9599
```bash
96100
ts2esm
97101
```
98102

99-
Or you can provide a list of tsconfig paths (no prompt):
103+
You can also provide a list of tsconfigs (no prompt):
100104

101105
```bash
102106
ts2esm packages/foo/tsconfig.json packages/bar/tsconfig.json
103107
```
104108

105-
You can also enable verbose logging with:
109+
There is also a debug mode with verbose logging:
106110

107111
```bash
108112
ts2esm --debug

0 commit comments

Comments
 (0)