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

@esmbly/transformer-v8

v0.0.6

Published

An Esmbly transformer that transforms plain JavaScript files to TypeScript by using a V8 type profile that is collected while running a test suite

Downloads

2

Readme

@esmbly/transformer-v8

Turn your tests into types

Transform JavaScript files to TypeScript by collecting V8 runtime type information during test runs.

Installation

# Using Yarn:
yarn add @esmbly/transformer-v8

# Or, using NPM:
npm install @esmbly/transformer-v8 --save

Getting Started

Check out Using the V8 transformer for a step-by-step guide on how to get started with @esmbly/transformer-v8 and the command-line interface.

Usage

The @esmbly/transformer-v8 transforms JavaScript files to TypeScript based on type information collected from V8. In order to use it, make sure you have @esmbly/cli installed. Under the hood, @esmbly/transformer-v8 uses the experimental Inspector API and the V8 inspector protocol which requires you to have at least Node.js version 10 installed.

In order to collect a V8 type profile about a JavaScript program - the program needs to be executed. When the program is executed, type information can be collected from V8 via the V8 inspector protocol. If a program is covered by a test suite, the test suite can be executed in order to run the program and retrieve a type profile from V8.

The following Esmbly configuration will run jest in order to extract a type profile, and then transform all JavaScript files located in the src directory to TypeScript. Files are outputted to the dist directory.

// esmbly.config.js

const V8 = require('@esmbly/transformer-v8');

module.exports = {
  input: ['./src/**/*.js'],
  transformers: [
    V8.createTransformer({
      testCommand: `jest`,
    }),
  ],
  output: [
    {
      format: '.ts',
      outDir: 'dist',
      rootDir: 'src'
    },
  ],
};

Configuration

The createTransformer() method accepts an optional configuration object (see the V8TransformerOptions interface). The following options are possible.

| Option | Description | Type | Default | |----------------------------|------------------------------|---------------|----------| | testCommand | The test command to run in order to extract a type profile, e.g. jest --runInBand | string | |
| debug | Debug whats being printed to stdout/stderr during the test run. | boolean | false |
| customRules (optional) | An object containing any custom rules which should be applied (existing rules can be overridden). Check out the custom-rule example for further details. | CustomRules | |

Supported test runners

The long term goal is to support any test runner, including simply running node to invoke a program that executes the specified input files. Currently, the following test runners are supported:

  • jest
  • jasmine
  • tape

Limitations

The type information that can be retrieved from V8 is somewhat experimental. All primitive types are supported, as well as custom classes. However, V8 does provide any detailed information about arrays or objects literals which will be interpreted as any[] and Object.

Examples

Further reading

Contributing

All types of contributions are very much welcome. Check out our Contributing Guide for instructions on how to get started.