babel-plugin-dynamic-import-node
Advanced tools
Comparing version 2.2.0 to 2.3.0
## Unreleased | ||
## v2.3.0 | ||
- [New] expose createDynamicImportTransform and getImportSource (#75) | ||
- [Docs] Document noInterop option (#70) | ||
## v2.2.0 | ||
@@ -4,0 +8,0 @@ - [Refactor] remove dependency on babel-plugin-syntax-dynamic-import |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -7,10 +7,4 @@ Object.defineProperty(exports, "__esModule", { | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
exports['default'] = function (_ref) { | ||
var template = _ref.template, | ||
t = _ref.types; | ||
var buildImport = template('Promise.resolve().then(() => MODULE)'); | ||
exports["default"] = function (api) { | ||
var transformImport = (0, _utils.createDynamicImportTransform)(api); | ||
return { | ||
@@ -27,27 +21,6 @@ // NOTE: Once we drop support for Babel <= v6 we should | ||
}(), | ||
visitor: { | ||
Import: function () { | ||
function Import(path) { | ||
var importArguments = path.parentPath.node.arguments; | ||
var _importArguments = _slicedToArray(importArguments, 1), | ||
importPath = _importArguments[0]; | ||
var isString = t.isStringLiteral(importPath) || t.isTemplateLiteral(importPath); | ||
if (isString) { | ||
t.removeComments(importPath); | ||
} | ||
var SOURCE = isString ? importArguments : t.templateLiteral([t.templateElement({ raw: '', cooked: '' }), t.templateElement({ raw: '', cooked: '' }, true)], importArguments); | ||
var requireCall = t.callExpression(t.identifier('require'), [].concat(SOURCE)); | ||
var _opts$noInterop = this.opts.noInterop, | ||
noInterop = _opts$noInterop === undefined ? false : _opts$noInterop; | ||
var MODULE = noInterop === true ? requireCall : t.callExpression(this.addHelper('interopRequireWildcard'), [requireCall]); | ||
var newImport = buildImport({ | ||
MODULE: MODULE | ||
}); | ||
path.parentPath.replaceWith(newImport); | ||
transformImport(this, path); | ||
} | ||
@@ -61,2 +34,4 @@ | ||
module.exports = exports['default']; | ||
var _utils = require("./utils"); | ||
module.exports = exports["default"]; |
{ | ||
"name": "babel-plugin-dynamic-import-node", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "Babel plugin to transpile import() to a deferred require(), for node", | ||
@@ -45,3 +45,3 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"airbnb-js-shims": "^2.1.1", | ||
"airbnb-js-shims": "^2.2.0", | ||
"babel-cli": "^6.26.0", | ||
@@ -56,9 +56,9 @@ "babel-core": "^6.26.3", | ||
"babel-register": "^6.26.0", | ||
"eslint": "^5.6.1", | ||
"eslint": "^5.16.0", | ||
"eslint-config-airbnb-base": "^13.1.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-import": "^2.17.3", | ||
"in-publish": "^2.0.0", | ||
"rimraf": "^2.6.2", | ||
"rimraf": "^2.6.3", | ||
"safe-publish-latest": "^1.1.2", | ||
"tape": "^4.9.1" | ||
"tape": "^4.10.2" | ||
}, | ||
@@ -65,0 +65,0 @@ "dependencies": { |
@@ -25,2 +25,14 @@ # babel-plugin-dynamic-import-node | ||
#### Options | ||
- *`noInterop`* - A boolean value, that if true will not interop the require calls. Useful to avoid using `require('module').default` on commonjs modules. | ||
```json | ||
{ | ||
"plugins": [ | ||
["dynamic-import-node", { "noInterop": true }] | ||
] | ||
} | ||
``` | ||
### Via CLI | ||
@@ -27,0 +39,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
11596
11
74
64