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

@corpuscule/babel-preset

v0.2.2

Published

Babel preset for compiling Corpuscule projects

Downloads

29

Readme

🛠 Status: In Development

@corpuscule/babel-preset is currently under development. Feedback is always welcome, but be careful with using it in production.

@corpuscule/babel-preset

Latest Stable Version Build Status GitHub license Test Coverage

Babel plugins preset that allows working with the Corpuscule project while decorator specification is in development.

Rationale

History

The earlier versions of Corpuscule used the second decorator proposal. However, in January 2019, this proposal was deprecated due to the complexity and potential performance penalty, and work on the third proposal was started.

Due to the beginning state of the new specification, the absence of the Babel implementation of it, it was decided to rewrite Corpuscule to the emulation of the new decorator proposal.

Emulation of the proposal

Emulation means that Corpuscule does not follow the specification yet. It respects basic ideas, but the implementation is based on the first decorator proposal (stage 1, also Typescript decorators or legacy decorator proposal) supplemented with the particular Babel plugin that adds missing functionality to it.

This decision is made because the new proposal changes syntax a lot and until Typescript implements this syntax in the compiler they will be incompatible. Implementation of the new syntax requires decorators to be on stage 3 which means that Corpuscule will also wait until it happens.

Plugins

babel-plugin-inject-decorator-initializer

The supplementing Babel plugin that adds missing functionality for the legacy decorator implementation works in the following way:

  1. Each class has two static fields with arrays. The first array contains initializers that will be injected into the constructor (@initializer implementation). The second array contains registrations (@register implementation) that will run after the class is created.
  2. During its work plugin injects a call of a simple iterator function that runs all the callbacks, into the proper place: constructor for initializers and right after class is created for registrations.
  3. Each initializer receives an instance as an argument. Registration receives class target as well, but it is often unnecessary for the legacy proposal because a class is already accessible during the decorator work.
  4. While the decorator's execution you can add new callbacks to the __initializers and __registrations arrays. They will work in the order decorators execute.

Why preset, not a plugin?

First of all, preset contains all necessary decorators to work, because the legacy proposal requires a couple of settings (e.g. @babel/plugin-proposal-class-properties in loose mode).

Then, when decorators become a standard, and the tweaks for legacy implementation are not necessary anymore, this package could be used for other goals like removing property guards in production.

Installation

$ npm install --save-dev @corpuscule/babel-preset

Usage

.babelrc

{
  "presets": ["@corpuscule/babel-preset", "@babel/preset-typescript"]
}