![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
babel-plugin-debug-macros
Advanced tools
Package description
The babel-plugin-debug-macros package is a Babel plugin that allows you to conditionally include or exclude code based on compile-time flags. This is particularly useful for debugging, logging, and feature flagging in JavaScript applications.
Conditional Code Inclusion
This feature allows you to include or exclude code based on a compile-time flag. In this example, the console.log statement will only be included if the DEBUG flag is set to true.
const DEBUG = true;
if (DEBUG) {
console.log('Debugging is enabled');
}
Feature Flagging
This feature allows you to enable or disable features based on environment variables. In this example, the console.log statement will only be included if the FEATURE_X_ENABLED environment variable is set to 'true'.
const FEATURE_X_ENABLED = process.env.FEATURE_X_ENABLED === 'true';
if (FEATURE_X_ENABLED) {
console.log('Feature X is enabled');
}
Debugging
This feature allows you to include debugging code that will only be included in non-production environments. In this example, the console.log statement will only be included if the NODE_ENV environment variable is not set to 'production'.
const DEBUG = process.env.NODE_ENV !== 'production';
if (DEBUG) {
console.log('This is a debug message');
}
This package allows you to inline environment variables into your code at compile time. It is similar to babel-plugin-debug-macros in that it allows you to conditionally include or exclude code based on environment variables, but it does not provide the same level of flexibility for feature flagging and debugging.
This package allows you to evaluate code at build time and inline the result into your code. It is similar to babel-plugin-debug-macros in that it allows you to include or exclude code based on compile-time conditions, but it is more focused on inlining the results of computations rather than conditional code inclusion.
This package allows you to conditionally include or exclude code based on compile-time flags. It is very similar to babel-plugin-debug-macros, but it is less focused on debugging and more focused on general-purpose conditional code inclusion.
Readme
This provides debug macros and feature flagging.
The plugin takes 5 types options: envFlags
, features
, debugTools
, externalizeHelpers
and svelte
. 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 you're own helpers using the externalizeHelpers
options.
{
plugins: [
['babel-debug-macros', {
// @required
envFlags: {
importSpecifier: '@ember/env-flags',
flags: { DEBUG: 1 }
},
// @required
debugTools: {
importSpecifier: 'debug-tools'
},
// @optional
features: [{
name: 'ember-source',
importSpecifier: '@ember/features',
flags: { FEATURE_A: 0, FEATURE_B: 1, DEPRECATED_CONTROLLERS: "2.12.0" }
}],
// @optional
svelte: {
'ember-source': "2.15.0"
},
// @optional
externalizeHelpers: {
module: 'my-helpers' // or true to retain the name in code
// global: '__my_global_ns__'
}
}]
]
}
Flags and features are inlined into consuming module so that something like UglifyJS with DCE them when they are unreachable.
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:
const DEBUG = 1;
const FEATURE_A = 0;
cosnt FEATURE_B = 1;
if (DEBUG) {
console.log('Hello from debug');
}
let woot;
if (FEATURE_A) {
woot = () => 'woot';
} else if (FEATURE_B) {
woot = () => 'toow';
}
woot();
warn
macro expansionimport { warn } from 'debug-tools';
warn('this is a warning');
Expands into:
const DEBUG = 1;
(DEBUG && console.warn('this is a warning'));
assert
macro expansionimport { assert } from 'debug-tools';
assert((() => {
return 1 === 1;
})(), 'You bad!');
Expands into:
const DEBUG = 1;
(DEBUG && console.assert((() => { return 1 === 1;})(), 'this is a warning'));
deprecate
macro expansionimport { deprecate } from 'debug-tools';
let foo = 2;
deprecate('This is deprecated.', foo % 2, {
id: 'old-and-busted',
url: 'http://example.com',
until: '4.0.0'
});
Expands into:
const DEBUG = 1;
let foo = 2;
(DEBUG && foo % 2 && console.warn('DEPRECATED [old-and-busted]: This is deprecated. Will be removed in 4.0.0. Please see http://example.com for more details.'));
When you externalize helpers you must provide runtime implementations for the above macros. An expansion will still occur however we will use 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:
const DEBUG = 1;
(DEBUG && 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:
const DEBUG = 1;
import { warn } from 'my-helpers';
(DEBUG && warn('this is a warning'));
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 ember-source@2.10.0
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 ember-source@2.11.0
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"
}
As you may notice that we inject DEBUG
into the code when we expand the macro. We gurantee that the binding is unique when injected and follow the local binding name if it is imported directly.
FAQs
Debug macros and feature flag stripping
The npm package babel-plugin-debug-macros receives a total of 360,979 weekly downloads. As such, babel-plugin-debug-macros popularity was classified as popular.
We found that babel-plugin-debug-macros demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.