Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-timing

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-timing

Measure Babel compilation time

  • 0.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.9K
decreased by-27.54%
Maintainers
1
Weekly downloads
 
Created
Source

Babel timing

Build status

Measure Babel compilation time file by file, plugin by plugin.

Get Babel transpilation insights when your application or your tests take ages to build.

Note: this tool is in version 0, any minor release might introduce breaking changes.

Installation

npm i babel-timing -D
yarn add babel-timing -D

Usage

As standalone library via CLI

babel-timing path/to/file-1.js path/to/file-2.js
babel-timing path/to/file-*.js
babel-timing path/to/entrypoint.js --follow-imports

As standalone library via Node

const babelTiming = require('babel-timing').babelTiming;
const results = await babelTiming(['path/to/file.js'], options);

As Webpack integration

Monitor Babel while used by the actual Webpack bundling process.

  1. Import babel-timing/webpack/plugin to Webpack configuration:
const BabelTimingPlugin = require('babel-timing/webpack/plugin');
  1. Add customize option to the existing babel-loader configuration:
module: {
  rules: [
    {
      test: /\.m?js$/,
      use: {
        loader: 'babel-loader',
          options: {
            customize: require.resolve('babel-timing/webpack/babel-loader-customize')
         },
      }
    }
  ]
}
  1. Add babel-timing/webpack/plugin plugin (accepts output and outputPath options):
plugins: [
   new BabelTimingPlugin(),
]

...with options (accepts output and outputPath options):

plugins: [
   new BabelTimingPlugin({output: "json", outputPath: "./results.json"}),
]

As Jest integration

Monitor Babel while running your actual Jest tests.

  1. Add the following transform and reporters entries to the existing Jest configuration:
{
  transform: {
    '^.+\\.jsx?$': 'babel-timing/jest/transformer'
  },
  reporters: [
    'default',
    'babel-timing/jest/reporter'
  ]
}

...with reporter's options (accepts output and outputPath options):

{
  reporters: [
    'default',
    [
      'babel-timing/jest/reporter',
      {output: 'json', outputPath: './results.json'}
    ]
  ]
}
  1. Run tests with --no-cache option

Options

babelConfig / --babel-config

Type: string | false
Default: undefined

Path to a custom babel configuration file. By default Babel will try to load any existing valid configuration file.

followImports / --follow-imports (experimental)

Type: bool
Default: false

Follow imported files/modules and run babel-timing against them.

include / --include

Type: string[] (cli accepts a string containing a comma-separated list)
Default: ['**']

Include paths (imported ones also) according to the provided glob patterns.

exclude / --exclude

Type: string[] (cli accepts a string containing a comma-separated list)
Default: ['**/modules/**']

Exclude paths (imported ones also) according to the provided glob patterns.

resolveMainFields / --resolve-main-fields

Type: string[] (cli accepts a string containing a comma-separated list)
Default: ['browser', 'module', 'main']

Determine which fields in imported modules's package.json are checked.

expandPackages / --expand-packages

Type: bool
Default: false

Expand results relative to node_modules packages file by file.

output / --output

Type: string
Default: "return" ("console" when called via CLI/Webpack)
Options: "return", "console", "json"

Make babel-timing results available as:

  • "return" return results' object
  • "console" render results in console
  • "json" save results as babel-timing-results.json
outputPath / --output-path

Type: string
Default: "./babel-timing-results.json"

Path of output file in case output option is set to "json".

verbose / --verbose

Type: bool
Default: false

Log warnings.

How it works

Compile files with Babel 7 and get collect compilation info through wrapPluginVisitorMethod Babel config option.

Results

Compilation info are extracted into the following data structure:

type Results = {
  name: string;
  totalTime: number;
  plugins: {
    plugin: string;
    timePerVisit: number;
    time: number;
    visits: number;
  }[];
}[];

Notes

This tool started as an attempt of measuring the time taken by Babel while running transpiled tests and compiling Webpack applications.

The main difficulty of monitoring Babel while running the aforementioned tools, consists of relating the wrapPluginVisitorMethod calls to the files actually being compiled.

Any further idea/contribution to get to a better Babel monitoring solution is welcome.

Manual tests :)

node cli.js __fixtures__/file-1.js
node cli.js __fixtures__/file-1.js __fixtures__/file-2.js
node cli.js __fixtures__/*.js
node cli.js __fixtures__/entry.js --follow-imports

Thanks to

Todo

  • Add csv output option
  • Expose wrapPluginVisitorMethod
  • Provide a wider set of integrations (rollup, parcel, ...)
  • Improve existing integrations
  • Make followImports more reliable
  • Consider paginating PluginList output

Keywords

FAQs

Package last updated on 13 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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc