fusebox-unassert-plugin
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

UnassertPlugin

A fuse-box plugin for unassert: Encourages programming with assertions by providing tools to compile them away.

Description

UnassertPlugin is a fuse-box plugin to remove assertions on production builds.

See unassert project for more documentation.

Installation

Install fusebox-unassert-plugin via npm:

$ npm install --save-dev fusebox-unassert-plugin

Usage

Setup

Import plugin

const { UnassertPlugin } = require("fusebox-unassert-plugin");

Inject into a chain

fuse.bundle("app").plugin(UnassertPlugin());

Or add it to the main config plugins list to make it available across bundles.

FuseBox.init({
  plugins: [UnassertPlugin()],
});

The plugin will parse source files (.js, .jsx, .ts, .tsx) into syntax trees by using esprima, and then re-generate JavaScript using escodegen. It is primarily intended for Quantum and uglified builds since the output will not have identical formatting to the input.

FuseBox.init({
  plugins: [
    ...
    this.isProduction && UnassertPlugin(),
    this.isProduction && QuantumPlugin({ uglify:true })
  ],
});

Options

You can pass unassert options, if not passed, default options (Same as unassert.defaultOptions()) will be used.

{
    assertionPatterns: [
        'assert(value, [message])',
        'assert.ok(value, [message])',
        'assert.equal(actual, expected, [message])',
        'assert.notEqual(actual, expected, [message])',
        'assert.strictEqual(actual, expected, [message])',
        'assert.notStrictEqual(actual, expected, [message])',
        'assert.deepEqual(actual, expected, [message])',
        'assert.notDeepEqual(actual, expected, [message])',
        'assert.deepStrictEqual(actual, expected, [message])',
        'assert.notDeepStrictEqual(actual, expected, [message])',
        'assert.fail(actual, expected, message, operator)',
        'assert.throws(block, [error], [message])',
        'assert.doesNotThrow(block, [message])',
        'assert.ifError(value)',
        'console.assert(value, [message])'
    ],
    requirePatterns: [
        'assert = require("assert")',
        'assert = require("power-assert")'
    ],
    importPatterns: [
        'import assert from "assert"',
        'import * as assert from "assert"',
        'import assert from "power-assert"',
        'import * as assert from "power-assert"'
    ]
}

Readme

Keywords

Package Sidebar

Install

npm i fusebox-unassert-plugin

Weekly Downloads

2

Version

1.0.0

License

NLPL

Unpacked Size

7.28 kB

Total Files

8

Last publish

Collaborators

  • fredli74