Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-inline-imports-commonjs

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-inline-imports-commonjs - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

CHANGELOG.md

5

package.json
{
"name": "babel-plugin-transform-inline-imports-commonjs",
"version": "1.0.0",
"version": "1.1.0",
"description": "A Babel transform that turns imports into lazily loaded commonjs requires",

@@ -20,3 +20,4 @@ "keywords": [

"dependencies": {
"babel-plugin-transform-strict-mode": "^6.8.0"
"babel-plugin-transform-strict-mode": "^6.8.0",
"builtin-modules": "^1.1.1"
},

@@ -23,0 +24,0 @@ "devDependencies": {

@@ -74,1 +74,11 @@ # babel-plugin-transform-inline-imports-commonjs

```
#### Additional settings
* `excludeNodeBuiltins` (default: `false`)
- Do not apply "inline-imports" to[Node builtin modules](https://github.com/sindresorhus/builtin-modules/blob/v1.1.1/builtin-modules.json). These modules are usually already in the module cache, so there may be no need to lazily load them.
```js
import * as path from 'path'; // transforms to plain `require` with interop
import foo from 'bar'; // transforms to inline import
```

32

transform-inline-imports-commonjs.js
'use strict';
const pathModule = require('path');
const builtinModules = new Set(require('builtin-modules/static'));

@@ -190,9 +191,2 @@ const THIS_BREAK_KEYS = [

const filename = pathModule.basename(source, pathModule.extname(source));
const memoizedID =
path.scope.generateUidIdentifier(filename);
const memoizedFunction =
path.scope.generateUidIdentifier('load' + memoizedID.name);
// require(moduleID);

@@ -206,2 +200,26 @@ const requireCallExpression = buildRequire(t.stringLiteral(source)).expression;

if (this.opts.excludeNodeBuiltins && builtinModules.has(source)) {
// var memoizedID;
const declID = path.scope.generateUidIdentifier(source);
const varDecl = t.variableDeclaration('var', [
t.variableDeclarator(declID, wrappedRequireCall)
]);
// Copy location from the original import statement for sourcemap
// generation.
if (imports[source]) {
varDecl.loc = imports[source].loc;
}
if (typeof blockHoist === 'number' && blockHoist > 0) {
varDecl._blockHoist = blockHoist;
}
topNodes.push(varDecl);
return requires[cacheKey] = declID;
}
const filename = pathModule.basename(source, pathModule.extname(source));
const memoizedID =
path.scope.generateUidIdentifier(filename);
const memoizedFunction =
path.scope.generateUidIdentifier('load' + memoizedID.name);
// var memoizedID;

@@ -208,0 +226,0 @@ const memoizerVarDecl =

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