# tsc-es2020-fix

> Make tsc-compiled `es2020` bundles compatible with `"type": "module"` requirements

Latest version **2.3.2** (published 2021-09-07) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install tsc-es2020-fix
pnpm add tsc-es2020-fix
yarn add tsc-es2020-fix
bun add tsc-es2020-fix
```

Provides the command `tsc-es2020-fix`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.3.2 |
| Published | 2021-09-07 |
| First published | 2021-05-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=14.8 |
| Dependencies | 5 |
| Unpacked size | 65.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 85 |
| Author | Anton Golub |
| Maintainers | antongolub |
| Keywords | tsc, es2020, tsc-es2020-fix |

## Links

- npm: https://www.npmjs.com/package/tsc-es2020-fix
- Repository: https://github.com/antongolub/tsc-es2020-fix
- Homepage: https://github.com/antongolub/tsc-es2020-fix/#readme
- Issues: https://github.com/antongolub/tsc-es2020-fix/issues
- npm.io page: https://npm.io/package/tsc-es2020-fix

## Dependencies (5)

- [meow](https://npm.io/package/meow.md) ^10.1.1
- [tslib](https://npm.io/package/tslib.md) ^2.3.0
- [globby](https://npm.io/package/globby.md) ^12.0.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^10.0.0
- [@types/fs-extra](https://npm.io/package/@types/fs-extra.md) ^9.0.12

## Recent versions

- 2.3.2 (latest) — 2021-09-07
- 2.2.1-beta.3 (beta) — 2021-06-10
- 2.3.1 — 2021-08-11
- 2.3.0 — 2021-07-28
- 2.2.2 — 2021-06-10
- 2.2.1-beta.2 — 2021-06-10
- 2.2.1-beta.1 — 2021-06-10
- 2.2.1-beta.0 — 2021-06-10
- 2.2.1 — 2021-06-10
- 2.2.0 — 2021-06-10
- 2.1.0 — 2021-06-10
- 2.0.1 — 2021-06-07
- 2.0.0 — 2021-06-07
- 1.1.2 — 2021-06-07
- 1.1.1 — 2021-05-11
- … 6 more at https://npm.io/package/tsc-es2020-fix/versions

## README

# tsc-es2020-fix
Make tsc-compiled `es2020` bundles compatible with `"type": "module"` requirements


## ⚠️ [DEPRECATED] The package was renamed
**tsc-es2020-fix → [tsc-esm-fix](https://www.npmjs.com/package/tsc-esm-fix)**  
The prev alias is no longer maintained

### Motivation
This workaround is aimed to bypass a pair of **tsc** and **ts-jest** issues _right here and right now_. 
* [TS/issues/13422](https://github.com/microsoft/TypeScript/issues/13422): tsc should add `.js` extensions for rel module paths.
* [ts-jest/issues/1174](https://github.com/kulshekhar/ts-jest/issues/1174): `import.meta` is not allowed.

Hope one day this library will not be needed.

### Features
* Finds and replaces `__dirname` and `__filename` refs with `import.meta`.
* Injects extentions to relative imports/re-exports statements.
    * `import {foo} from './foo'` → `import {foo} from './foo.js'`
    * `import {baz} from 'external/baz'` → `import {baz} from 'external/baz.js'`
    * Pays attention to index files: `import {bar} from './bar'` → `import {bar} from './bar/index.js'`
* Follows `outDir` found in tsconfig.json.  
* Changes files extentions if specified by opts.
* Supports Windows-based runtimes.

## Requirements
Node.js >= 14

## Install
```shell
yarn add -D tsc-es2020-fix
```

## Usage
```shell
tsc-es2020-fix [options]
```

```typescript
import { fix } from 'tsc-es2020-fix'
await fix({
  dirnameVar: true,
  filenameVar: true,
  ext: true
})
```

## API
### CLI
```shell
tsc-es2020-fix [opts]
```
| Option | Description | Default
|---|---|---|
|`--tsconfig`| Path to project's ts-config(s) | `tsconfig.json`
|`--target` | Entry points where compiled files are placed for modification | If not specified inherited from tsconfig.json **compilerOptions.outDir**
|`--dirnameVar` | Replace `__dirname` usages with `import.meta` | true
|`--filenameVar` | Replace `__filename` var references `import.meta` | true
|`--ext` | Append extension to relative imports/re-exports | `.js`
|`--cwd`| cwd | `process.cwd()`
|`--out`| Output dir. Defaults to cwd, so files will be overridden | <cwd>
|`--debug` | Prints debug notes

### JS/TS
```ts
import { fix, IFixOptions } from 'tsc-es2020-fix'

const fixOptions: IFixOptions = {
  tsconfig: 'tsconfig.build.json',
  dirnameVar: true,
  filenameVar: true,
  ext: true
}

await fix(fixOptions)
```
```typescript
export interface IFixOptions {
  cwd: string
  out?: string,
  target?: string | string[]
  tsconfig: string | string[]
  dirnameVar: boolean
  filenameVar: boolean
  ext: boolean | string
}
```

## License
[MIT](./LICENSE)

---
_Source: https://npm.io/package/tsc-es2020-fix · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
