babel-macros
Advanced tools
Comparing version 1.0.3 to 1.1.0
@@ -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 |
{ | ||
"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", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22270
214
1
+ Addedcosmiconfig@3.1.0
+ Addedargparse@1.0.10(transitive)
+ Addedcosmiconfig@3.1.0(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-directory@0.3.1(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedparse-json@3.0.0(transitive)
+ Addedrequire-from-string@2.0.2(transitive)
+ Addedsprintf-js@1.0.3(transitive)