npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

babel-plugin-transform-class-inject-directive

v4.0.0

Published

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

Downloads

11

Readme

babel-plugin-transform-class-inject-directive

Travis Coveralls github David David

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

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

Out

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

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

Usage

Via .babelrc (Recommended)

.babelrc

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

Via CLI

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

Via Node API

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 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 with commitlint 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 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 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 with my own custom configuration 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 with my custom configuration. The configuration file for the project code is on ./.prettierrc.

Documentation

I use JSDoc 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 to generate a report. The script that runs it is on ./utils/scripts/todo.