Socket
Book a DemoInstallSign in
Socket

@esmbly/transformer-v8

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@esmbly/transformer-v8

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

0.0.6
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

@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.

OptionDescriptionTypeDefault
testCommandThe test command to run in order to extract a type profile, e.g. jest --runInBandstring
debugDebug whats being printed to stdout/stderr during the test run.booleanfalse
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.

Keywords

esmbly

FAQs

Package last updated on 24 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.