# babel-plugin-transform-class-inject-directive

> Detect an inject directive on a class constructor and define a static property with the list of dependencies.

Latest version **4.0.0** (published 2022-05-21) · MIT license · 0 weekly downloads

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

## Install

```sh
npm install babel-plugin-transform-class-inject-directive
pnpm add babel-plugin-transform-class-inject-directive
yarn add babel-plugin-transform-class-inject-directive
bun add babel-plugin-transform-class-inject-directive
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2022-05-21 |
| First published | 2018-11-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=14 |
| Dependencies | 1 |
| Unpacked size | 79.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Leonardo Apiwan |
| Maintainers | homer0 |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-transform-class-inject-directive
- Repository: https://github.com/homer0/babel-plugin-transform-class-inject-directive
- Homepage: https://homer0.github.io/babel-plugin-transform-class-inject-directive/
- Issues: https://github.com/homer0/babel-plugin-transform-class-inject-directive/issues
- npm.io page: https://npm.io/package/babel-plugin-transform-class-inject-directive

## Dependencies (1)

- [@babel/types](https://npm.io/package/@babel/types.md) 7.18.0

## Recent versions

- 4.0.0 (latest) — 2022-05-21
- 3.0.2 — 2020-04-14
- 3.0.1 — 2020-04-13
- 3.0.0 — 2019-12-24
- 2.0.2 — 2019-11-24
- 2.0.1 — 2019-07-21
- 2.0.0 — 2019-02-09
- 1.0.2 — 2018-11-19

## README

# babel-plugin-transform-class-inject-directive

[![Travis](https://img.shields.io/travis/homer0/babel-plugin-transform-class-inject-directive.svg?style=flat-square)](https://travis-ci.org/homer0/babel-plugin-transform-class-inject-directive)
[![Coveralls github](https://img.shields.io/coveralls/github/homer0/babel-plugin-transform-class-inject-directive.svg?style=flat-square)](https://coveralls.io/github/homer0/babel-plugin-transform-class-inject-directive?branch=master)
[![David](https://img.shields.io/david/homer0/babel-plugin-transform-class-inject-directive.svg?style=flat-square)](https://david-dm.org/homer0/babel-plugin-transform-class-inject-directive)
[![David](https://img.shields.io/david/dev/homer0/babel-plugin-transform-class-inject-directive.svg?style=flat-square)](https://david-dm.org/homer0/babel-plugin-transform-class-inject-directive)

This is a utility for projects that relay heavily on classes and dependency injection. If a class constructor uses an `'inject'` directive, the list of parameter names will be copied as strings and placed on an `inject` static property, so your DI tool can read them.

## Example

### In

```js
class MyService {
  constructor(depOne, depTwo) {
    'inject';
    ...
  }
}
```

### Out

```js
class MyService {
  constructor(depOne, depTwo) {
    'inject';
    ...
  }
}

MyService.inject = ['depOne', 'depTwo']
```

## Usage

### Via `.babelrc` (Recommended)

**.babelrc**

```json
{
  "plugins": ["transform-class-inject-directive"]
}
```

### Via CLI

```sh
babel --plugins transform-class-inject-directive script.js
```

### Via Node API

```javascript
require('@babel/core').transform('code', {
  plugins: ['transform-class-inject-directive'],
});
```

## Options

### `directive`

`string`, defaults to `inject`.

Tells the plugin which is the name of the directive it should find in order to apply the transformation.

### `property`

`string`, defaults to `inject`.

This is the name of the property the plugin will create in order to define the list of dependencies.

## Warning

This only works on classes and regular functions (no arrow). The idea was for it to only work on classes, and the only reason it also works with functions is in order to add support in case you are transforming classes.

## Development

### NPM/Yarn Tasks

| Task           | Description                         |
|----------------|-------------------------------------|
| `test`         | Run the project unit tests.         |
| `run lint`     | Lint the modified files.            |
| `run lint:all` | Lint the project code.              |
| `run docs`     | Generate the project documentation. |
| `run todo`     | List all the pending to-do's.       |

### Repository hooks

I use [`husky`](https://yarnpkg.com/package/husky) to automatically install the repository hooks so the code will be tested and linted before any commit, and the dependencies updated after every merge.

#### Commits convention

I use [conventional commits](https://www.conventionalcommits.org) with [`commitlint`](https://commitlint.js.org) in order to support semantic releases. The one that sets it up is actually husky, that installs a script that runs `commitlint` on the `git commit` command.

The configuration is on the `commitlint` property of the `package.json`.

### Releases

I use [`semantic-release`](https://yarnpkg.com/package/semantic-release) and a GitHub action to automatically release on NPM everything that gets merged to main.

The configuration for `semantic-release` is on `./releaserc` and the workflow for the release is on `./.github/workflow/release.yml`.

### Testing

I use [Jest](https://facebook.github.io/jest/) to test the project.

The configuration file is on `./.jestrc.js`, the tests are on `./tests` and the script that runs it is on `./utils/scripts/test`.

### Linting && Formatting

I use [ESlint](https://eslint.org) with [my own custom configuration](https://yarnpkg.com/en/package/@homer0/eslint-plugin) to validate all the JS code. The configuration file for the project code is on `./.eslintrc` and the one for the tests is on `./tests/.eslintrc`. There's also an `./.eslintignore` to exclude some files on the process. The script that runs it is on `./utils/scripts/lint-all`.

For formatting I use [Prettier](https://prettier.io) with [my custom configuration](https://yarnpkg.com/en/package/@homer0/prettier-config). The configuration file for the project code is on `./.prettierrc`.

### Documentation

I use [JSDoc](https://jsdoc.app) to generate an HTML documentation site for the project.

The configuration file is on `./.jsdoc.js` and the script that runs it is on `./utils/scripts/docs`.

### To-Dos

I use `@todo` comments to write all the pending improvements and fixes, and [Leasot](https://yarnpkg.com/en/package/leasot) to generate a report. The script that runs it is on `./utils/scripts/todo`.

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