# @zenflux/tsconfig-to-swc

> A tsconfig.json to swc.config.js converter

Latest version **0.1.21** (published 2026-09-09) · 0 weekly downloads

## Install

```sh
npm install @zenflux/tsconfig-to-swc
pnpm add @zenflux/tsconfig-to-swc
yarn add @zenflux/tsconfig-to-swc
bun add @zenflux/tsconfig-to-swc
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.1.21 |
| Published | 2026-09-09 |
| First published | 2023-11-26 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 14.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | inewlegend |

## Links

- npm: https://www.npmjs.com/package/@zenflux/tsconfig-to-swc
- Repository: https://github.com/ZenFlux/zenflux
- npm.io page: https://npm.io/package/@zenflux/tsconfig-to-swc

## Dependencies (1)

- [typescript](https://npm.io/package/typescript.md) ^5.9.0

## Recent versions

- 0.1.21 (latest) — 2026-09-09
- 0.1.20 — 2025-12-11
- 0.1.19 — 2025-11-21
- 0.1.18 — 2025-11-21
- 0.1.17 — 2025-11-20
- 0.1.16 — 2025-11-20
- 0.1.15 — 2025-11-20
- 0.1.14 — 2025-11-20
- 0.1.13 — 2025-11-20
- 0.1.12 — 2025-11-20
- 0.1.11 — 2025-11-20
- 0.1.10 — 2025-11-20
- 0.1.9 — 2025-11-19
- 0.1.8 — 2025-11-19
- 0.1.7 — 2025-11-19
- … 10 more at https://npm.io/package/@zenflux/tsconfig-to-swc/versions

## README

# @zenflux/tsconfig-to-swc

This package provides utilities for converting TypeScript compiler options to SWC compiler options, with support
of `tsconfig.json` *extends* field.

## Installation

```bash
bun install @zenflux/tsconfig-to-swc
```

## Usage

```typescript
import { convertTsConfig, readTsConfig } from "@zenflux/tsconfig-to-swc";

const tsConfig = readTsConfig( "./tsconfig.json" );

const swcOptions = convertTsConfig( tsConfig );

console.log( swcOptions );
```

---

## API

### `readTsConfig(tsConfigPath, [readConfigCallback])`

Reads and parses a TypeScript Configuration file.

**Arguments:**

* `tsConfigPath`: `string` - The file path of the TypeScript Configuration file.
* `readConfigCallback`: `(path: string) => string | undefined` - Optional callback function for reading config files.

**Throws:**

* `Error` - Throws an error if there is an error reading or parsing the file.

**Returns:**

* `ts.ParsedCommandLine`: The parsed TypeScript Configuration object.

**Example:**
```typescript
const tsConfigPath = "path/to/tsconfig.json";

try {
    const tsConfig = tsconfigToSwc.readTsConfig( tsConfigPath );
    console.log( "Parsed TypeScript Configuration:", tsConfig );
} catch ( error ) {
    console.error( "Error reading or parsing TypeScript Configuration:", error.message );
}

```

---

### `convertTsConfig(tsConfig, [inherentOptionsSwcOptions])`

Converts TypeScript compiler options to SWC compiler options

**Arguments:**

* `tsConfig`: `ts.ParsedCommandLine` - TypeScript parsed configuration object
* `inherentOptionsSwcOptions`: `swc.Options` - SWC compiler options object. Default to an empty object

**Returns:**
* `swc.Options`: - The converted/customized SWC options

**Example:**
```typescript
const tsConfig = tsconfigToSwc.readTsConfig( "path/to/tsconfig.json" );
const swcOptions = tsconfigToSwc.convertTsConfig( tsConfig );
console.log( "SWC Compiler Options:", swcOptions );
```

---

### `convertScriptTarget(target)`

Converts TypeScript's ScriptTarget version to SWC JscTarget version.

**Arguments:**

* `target`: `ts.ScriptTarget` - The TypeScript's ScriptTarget version.

**Returns:**

* `swc.JscTarget`: - The corresponding SWC JscTarget version.

---

### `convertModuleOptions(compilerOptions)`

Converts TypeScript CompilerOptions to SWC ModuleConfig.

**Arguments:**

* `compilerOptions`: `ts.CompilerOptions` - TypeScript CompilerOptions

**Returns:**

* `swc.ModuleConfig`: - The corresponding SWC ModuleConfig

---
_Source: https://npm.io/package/@zenflux/tsconfig-to-swc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
