# js-transform-plugin

> An ast plugin for transforming js/ts/jsx/tsx files from commonJS to ESmodule.

Latest version **1.1.10** (published 2023-07-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install js-transform-plugin
pnpm add js-transform-plugin
yarn add js-transform-plugin
bun add js-transform-plugin
```

Provides the command `js-transform`.

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.10 |
| Published | 2023-07-05 |
| First published | 2022-03-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 2.7 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | TrumanGao |
| Maintainers | trumangao |
| Keywords | babel, jscodeshift, module, commonjs, esmodules |

## Links

- npm: https://www.npmjs.com/package/js-transform-plugin
- Repository: https://github.com/TrumanGao/js-transform-plugin
- Homepage: https://github.com/TrumanGao/js-transform-plugin#readme
- Issues: https://github.com/TrumanGao/js-transform-plugin/issues
- npm.io page: https://npm.io/package/js-transform-plugin

## Dependencies (2)

- [@babel/core](https://npm.io/package/@babel/core.md) ^7.20.12
- [jscodeshift](https://npm.io/package/jscodeshift.md) ^0.14.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.1.10 (latest) — 2023-07-05
- 1.1.9 — 2023-06-28
- 1.1.8 — 2023-02-17
- 1.1.6 — 2023-02-16
- 1.1.5 — 2023-02-15
- 1.1.4 — 2022-03-09
- 1.1.2 — 2022-03-09
- 1.1.1 — 2022-03-08
- 1.2.1 — 2022-03-08
- 1.2.0 — 2022-03-08
- 1.1.0 — 2022-03-08
- 1.0.0 — 2022-03-08

## README

English | [简体中文](./README.zh.md)

<div align="center">
  <h1>js-transform-plugin</h1>
</div>

An ast plugin for transforming js/ts/jsx/tsx files from commonJS to ESmodule. Here for the [examples](https://github.com/TrumanGao/js-transform-plugin#examples).

[![license](https://img.shields.io/github/license/trumangao/js-transform-plugin?style=flat-square)](https://en.wikipedia.org/wiki/MIT_License)

---

## Usage

1. ```bash
   npm install -D js-transform-plugin
   ```

2. Add this script to package.json

   ```json
   {
     "scripts": {
       "transform": "js-transform"
     }
   }
   ```

3. ```bash
   npm run transform [absolute path]
   ```
   - The default value of [absolute path] is process.cwd().
   - The configuration of ignored files has not been supported. To avoid transforming node_modules dir, you can provide param, like, the absolute path of src dir. Or easier, just delete node_modules dir.

- Then js/ts/jsx/tsx files in [absolute path] will be transformed from commonJS to ESmodule recursively.

## Examples

```js
// before
const a = require("my-package");

// after
import a from "my-package";
```

```js
// before
const { a, b, c } = require("my-package");

// after
import { a, b, c } from "my-package";
```

```js
// before
require("my-package");

// after
import "my-package";
```

```js
// before
module.exports = { ... }

// after
export { ... }
// or
export default { ... }
```

```js
// before
module.exports = abc;
module.exports = new Abc();
module.exports = fun(a, b);
module.exports = function(){};
module.exports = () => {};

// after
export default abc;
export default new Abc();
export default fun(a, b);
export default function(){};
export default () => {};
```

```js
// before
const { b, c } = require("my-package");

// after
import { b, c } from "my-package";
```

```js
// before
const { d: aliasD } = require("my-package");

// after
import { d as aliasD } from "my-package";
```

## Dependencies

[jscodeshift](https://github.com/facebook/jscodeshift)

[@babel/core](https://babeljs.io/docs/en/babel-core)

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