Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@tigre/dev-warning

tigre3SEE LICENSE IN LICENSE1.0.0TypeScript support: included

Provides development only warning messages. Messages are designed to only trigger a single time per application refresh to avoid being annoying.

readme

@tigre/dev-warning

A simple, tiny library for enabling development only warnings to be easily published to the console.

The library automatically stops producing the warnings when built in production mode. To build in production mode use whichever bundler you like and ensure that process.env.NODE_ENV is set to equal production.

This module does nothing useful in production mode, so if you have tree-shaking enabled you can wrap any call to this module with:

import createDevWarning from "@tigre/dev-warning";

if (process.env.NODE_ENV === "development") {

    // Perform the check that needs a development warning
    if (/* someone made a development mistake */) {
        createDevWarning(
            "<The error message>",         // A useful and descriptive error message
            {                             // This object is optional, when included it will only 
                                        // display the message once per unique set of switches in the file
                                        // All fields in this object are optional.
                file: __filename,         // Typically useful to include, `__filename` needs to be enabled in webpack
                warning: "warning",     // Also very useful unless a single warning possible
                detail: "detail",
                extra: "extra"
            }, 
            { 
                more: "details"         // Optional object that gets printed in the console.warn call.
                                        //  This can be used to provide extra diagnostic details to solve the problem.
            }
        );
    }
}

Recommended usage:

import createDevWarning from "@tigre/dev-warning";

// Easy, repeats every time
if (process.env.NODE_ENV === "development") {
    createDevWarning("Repeating warning");
}

// Medium, only triggers once
if (process.env.NODE_ENV === "development") {
    createDevWarning("warning", {
        file: __filename,
        warning: "single time"
    });
}

// Detailed, only triggers once, gives lots of how to fix details
if (process.env.NODE_ENV === "development") {
    createDevWarning("warning", {
        file: __filename,
        warning: "single time"
    }, {
        causedBy: "information",
        reason: "bad"
    });
}