Socket
Socket
Sign inDemoInstall

babel-macros

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-macros - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

43

dist/index.js

@@ -38,8 +38,14 @@ 'use strict';

function createMacro(macro) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (options.configName === 'options') {
throw new Error(`You cannot use the configName "options". It is reserved for babel-macros.`);
}
macroWrapper.isBabelMacro = true;
macroWrapper.options = options;
return macroWrapper;
function macroWrapper(options) {
var source = options.source,
isBabelMacrosCall = options.isBabelMacrosCall;
function macroWrapper(args) {
var source = args.source,
isBabelMacrosCall = args.isBabelMacrosCall;

@@ -49,3 +55,3 @@ if (!isBabelMacrosCall) {

}
return macro(options);
return macro(args);
}

@@ -153,2 +159,3 @@ }

}
var config = getConfig(macro, filename, source);
try {

@@ -159,2 +166,3 @@ macro({

babel,
config,
isBabelMacrosCall: true

@@ -174,2 +182,29 @@ });

// eslint-disable-next-line consistent-return
function getConfig(macro, filename, source) {
if (macro.configName) {
try {
// lazy-loading it here to avoid perf issues of loading it up front.
// No I did not measure. Yes I'm a bad person.
// FWIW, this thing told me that cosmiconfig is 227.1 kb of minified JS
// so that's probably significant... https://bundlephobia.com/result?p=cosmiconfig@3.1.0
// Note that cosmiconfig will cache the babel-macros config 👍
var loaded = require('cosmiconfig')('babel-macros', {
packageProp: 'babelMacros',
rc: '.babel-macrosrc',
js: 'babel-macros.config.js',
rcExtensions: true,
sync: true
}).load(filename);
if (loaded) {
return loaded.config[macro.configName];
}
} catch (error) {
// eslint-disable-next-line no-console
console.error(`There was an error trying to load the config "${macro.configName}" ` + `for the macro imported from "${source}. ` + `Please see the error thrown for more information.`);
throw error;
}
}
}
/*

@@ -176,0 +211,0 @@ istanbul ignore next

6

package.json
{
"name": "babel-macros",
"version": "1.0.3",
"version": "1.1.0",
"description": "Enables zero-config, importable babel plugins",

@@ -28,3 +28,5 @@ "main": "dist/index.js",

"license": "MIT",
"dependencies": {},
"dependencies": {
"cosmiconfig": "3.1.0"
},
"devDependencies": {

@@ -31,0 +33,0 @@ "ast-pretty-print": "2.0.1",

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