Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
@babel/helper-module-imports
Advanced tools
The @babel/helper-module-imports package is a utility that allows Babel plugins to add module imports to a file in a consistent way. It provides functions to programmatically add import statements or require calls within the code being transformed by Babel.
addDefault
Adds a default import statement to the file. For example, it can add `import lodash from 'lodash';` to the code.
import { addDefault } from '@babel/helper-module-imports';
const path = /* ... */;
const imported = addDefault(path, 'lodash', { nameHint: 'lodash' });
addNamed
Adds a named import statement to the file. For example, it can add `import { map } from 'lodash';` to the code.
import { addNamed } from '@babel/helper-module-imports';
const path = /* ... */;
const imported = addNamed(path, 'map', 'lodash', { nameHint: 'map' });
addNamespace
Adds a namespace import statement to the file. For example, it can add `import * as lodash from 'lodash';` to the code.
import { addNamespace } from '@babel/helper-module-imports';
const path = /* ... */;
const imported = addNamespace(path, 'lodash', { nameHint: 'lodash' });
addSideEffect
Adds an import statement that will include a module for its side effects only, without importing any bindings. For example, it can add `import 'normalize.css';` to the code.
import { addSideEffect } from '@babel/helper-module-imports';
const path = /* ... */;
addSideEffect(path, 'normalize.css');
A Babel plugin that allows you to import components from libraries in a modular way, often used with UI libraries like Ant Design. It can transform named imports to individual path imports to reduce bundle size, which is a different approach compared to @babel/helper-module-imports that focuses on adding imports programmatically within Babel plugins.
A Babel plugin that allows you to add aliases for imports in your project, making it easier to manage paths. It can be used to rewrite the paths of imports and requires, which is different from @babel/helper-module-imports that is used to add new imports rather than modify existing ones.
This plugin transforms member style imports (e.g., `import { map } from 'lodash'`) into default import style imports (e.g., `import map from 'lodash/map'`). This can help with reducing bundle sizes by only including the parts of a module that are used. It serves a different purpose than @babel/helper-module-imports, which is more about adding imports rather than optimizing them.
npm install @babel/helper-module-imports --save
import "source"
import { addSideEffect } from "@babel/helper-module-imports";
addSideEffect(path, 'source');
import { named } from "source"
import { addNamed } from "@babel/helper-module-imports";
addNamed(path, 'named', 'source');
import { named as _hintedName } from "source"
import { addNamed } from "@babel/helper-module-imports";
addNamed(path, 'named', 'source', { nameHint: "hintedName" });
import _default from "source"
import { addDefault } from "@babel/helper-module-imports";
addDefault(path, 'source');
import hintedName from "source"
import { addDefault } from "@babel/helper-module-imports";
addDefault(path, 'source', { nameHint: "hintedName" })
import * as _namespace from "source"
import { addNamespace } from "@babel/helper-module-imports";
addNamespace(path, 'source');
import { addNamed } from "@babel/helper-module-imports";
export default function({ types: t }) {
return {
visitor: {
ReferencedIdentifier(path) {
let importName = this.importName;
if (importName) {
importName = t.cloneDeep(importName);
} else {
// require('bluebird').coroutine
importName = this.importName = addNamed(path, 'coroutine', 'bluebird');
}
path.replaceWith(importName);
}
},
};
}
FAQs
Babel helper functions for inserting module loads
The npm package @babel/helper-module-imports receives a total of 39,411,801 weekly downloads. As such, @babel/helper-module-imports popularity was classified as popular.
We found that @babel/helper-module-imports demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.