babel-plugin-optional-require
Advanced tools
Comparing version 0.1.1 to 0.2.0
14
index.js
@@ -5,2 +5,3 @@ /* @flow */ | ||
const resolve = require('resolve-from'); | ||
const isBuiltin = require('is-builtin-module'); | ||
@@ -22,3 +23,8 @@ module.exports = function rewire(babel /*: any */) { | ||
const name = p.node.arguments[0].value; | ||
const name = p.get('arguments')[0].evaluate().value; | ||
if (typeof name !== 'string') { | ||
return; | ||
} | ||
const cwd = | ||
@@ -30,3 +36,7 @@ state.file && state.file.opts && state.file.opts.filename | ||
try { | ||
resolve(cwd, name); | ||
if (state.opts.builtins !== true && isBuiltin(name)) { | ||
throw new Error(`Cannot resolve builtin module '${name}'`); | ||
} else { | ||
resolve(cwd, name); | ||
} | ||
} catch (e) { | ||
@@ -33,0 +43,0 @@ p.replaceWith( |
{ | ||
"name": "babel-plugin-optional-require", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Babel plugin to transpile object styles to template literal", | ||
@@ -28,4 +28,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"is-builtin-module": "^2.0.0", | ||
"resolve-from": "^4.0.0" | ||
} | ||
} |
@@ -25,2 +25,6 @@ # babel-plugin-optional-require | ||
## Options | ||
- `builtins: boolean`: Whether to resolve Node builtins. Default: `false`. | ||
## Example | ||
@@ -27,0 +31,0 @@ |
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
3305
46
44
2
+ Addedis-builtin-module@^2.0.0
+ Addedbuiltin-modules@2.0.0(transitive)
+ Addedis-builtin-module@2.0.0(transitive)