babel-plugin-optional-require
Advanced tools
Comparing version 0.2.0 to 0.3.0
16
index.js
@@ -22,2 +22,8 @@ /* @flow */ | ||
const { | ||
builtins = false, | ||
blacklist = [], | ||
whitelist = [], | ||
} = state.opts; | ||
const name = p.get('arguments')[0].evaluate().value; | ||
@@ -29,2 +35,6 @@ | ||
if (whitelist.includes(name)) { | ||
return; | ||
} | ||
const cwd = | ||
@@ -36,3 +46,7 @@ state.file && state.file.opts && state.file.opts.filename | ||
try { | ||
if (state.opts.builtins !== true && isBuiltin(name)) { | ||
if (blacklist.includes(name)) { | ||
throw new Error(`Cannot find module '${name}'`); | ||
} | ||
if (builtins !== true && isBuiltin(name)) { | ||
throw new Error(`Cannot resolve builtin module '${name}'`); | ||
@@ -39,0 +53,0 @@ } else { |
{ | ||
"name": "babel-plugin-optional-require", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Babel plugin to transpile object styles to template literal", | ||
@@ -12,2 +12,9 @@ "main": "index.js", | ||
"license": "MIT", | ||
"keywords": [ | ||
"babel-plugin", | ||
"babel", | ||
"module", | ||
"require", | ||
"import" | ||
], | ||
"scripts": { | ||
@@ -14,0 +21,0 @@ "lint": "eslint .", |
@@ -28,2 +28,4 @@ # babel-plugin-optional-require | ||
- `builtins: boolean`: Whether to resolve Node builtins. Default: `false`. | ||
- `blacklist: string[]`: List of modules we assume to always unavailable without resolving. Default: `[]`. | ||
- `whitelist: string[]`: List of modules we assume to always available without resolving. Default: `[]`. | ||
@@ -30,0 +32,0 @@ ## Example |
3952
57
46