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

@discourse/babel-plugin-debug-macros

v0.4.0-pre1

Published

Debug macros and feature flag stripping (Discourse-owned fork to maintain deprecate() calls in production)

Downloads

160

Readme

Babel Debug Macros And Feature Flags

This provides debug macros and feature flagging.

Setup

The plugin takes 4 types options: flags, svelte, debugTools, and externalizeHelpers. The importSpecifier is used as a hint to this plugin as to where macros are being imported and completely configurable by the host.

Like Babel you can supply your own helpers using the externalizeHelpers options.

{
  plugins: [
    ['babel-debug-macros', {
      // @optional
      debugTools: {
        isDebug: true,
        source: 'debug-tools',
        // @optional
        assertPredicateIndex: 0
      },

      flags: [
        { source: '@ember/env-flags', flags: { DEBUG: true } },
        {
          name: 'ember-source',
          source: '@ember/features',
          flags: {
            FEATURE_A: false,
            FEATURE_B: true,
            DEPRECATED_CONTROLLERS: "2.12.0"
          }
        }
      ],

      // @optional
      svelte: {
        'ember-source': "2.15.0"
      },

      // @optional
      externalizeHelpers: {
        module: true,
        // global: '__my_global_ns__'
      }
    }]
  ]
}

Flags and features are inlined into the consuming module so that something like UglifyJS will DCE them when they are unreachable.

Simple environment and feature flags

import { DEBUG } from '@ember/env-flags';
import { FEATURE_A, FEATURE_B } from '@ember/features';

if (DEBUG) {
  console.log('Hello from debug');
}

let woot;
if (FEATURE_A) {
  woot = () => 'woot';
} else if (FEATURE_B) {
  woot = () => 'toow';
}

woot();

Transforms to:

if (true /* DEBUG */) {
  console.log('Hello from debug');
}

let woot;
if (false /* FEATURE_A */) {
  woot = () => 'woot';
} else if (true) {
  woot = () => 'toow';
}

woot();

warn macro expansion

import { warn } from 'debug-tools';

warn('this is a warning');

Expands into:

(true && console.warn('this is a warning'));

assert macro expansion

The assert macro can expand in a more intelligent way with the correct configuration. When babel-plugin-debug-macros is provided with the assertPredicateIndex the predicate is injected in front of the assertion in order to avoid costly assertion message generation when not needed.

import { assert } from 'debug-tools';

assert((() => {
  return 1 === 1;
})(), 'You bad!');

With the debugTools: { assertPredicateIndex: 0 } configuration the following expansion is done:

(true && !((() => { return 1 === 1;})()) && console.assert(false, 'this is a warning'));

When assertPredicateIndex is not specified, the following expansion is done:

(true && console.assert((() => { return 1 === 1;})(), 'this is a warning'));

deprecate macro expansion

import { deprecate } from 'debug-tools';

let foo = 2;

deprecate('This is deprecated.', foo % 2);

Expands into:

let foo = 2;

(true && !(foo % 2) && console.warn('This is deprecated.'));

Externalized Helpers

When you externalize helpers you must provide runtime implementations for the above macros. An expansion will still occur, however we will emit references to those runtime helpers.

A global expansion looks like the following:

import { warn } from 'debug-tools';

warn('this is a warning');

Expands into:

(true && Ember.warn('this is a warning'));

While externalizing the helpers to a module looks like the following:

import { warn } from 'debug-tools';

warn('this is a warning');

Expands into:

(true && warn('this is a warning'));

Svelte

Svelte allows for consumers to opt into stripping deprecated code from your dependecies. By adding a package name and minimum version that contains no deprecations, that code will be compiled away.

For example, consider you are on [email protected] and you have no deprecations. All deprecated code in ember-source that is <=2.10.0 will be removed.


svelte: {
  "ember-source": "2.10.0"
}

Now if you bump to [email protected] you may encounter new deprecations. The workflow would then be to clear out all deprecations and then bump the version in the svelte options.

svelte: {
  "ember-source": "2.11.0"
}