Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
babel-plugin-transform-modules-simple-commonjs
Advanced tools
Simple transformer for ECMAScript 2015 modules (CommonJS).
Converts this code:
import x from '/path/to/x';
import y from '/path/to/y';
doSomething();
export default x + y;
Into this one:
var x = require('/path/to/x');
var y = require('/path/to/y');
doSomething();
module.exports = x + y;
Instead of this one (generated with babel-plugin-transform-es2015-modules-commonjs
):
Object.defineProperty(exports, "__esModule", {
value: true
});
var _x = require('/path/to/x');
var _x2 = _interopRequireDefault(_x);
var _y = require('/path/to/y');
var _y2 = _interopRequireDefault(_y);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
doSomething();
exports.default = _x2.default + _y2.default;
This supports all standard es2015 import and export code with some caveats.
When exporting the final value is used, not the value when writing an export statement. It is not supported to mutate declarations that have been exported. You will not be warned, it will just not work.
You cannot export default and export a named item in the same file as module.exports
assignment will conflict with the exports
assignment. This transform will error if you attempt to do this.
If you mix default imports and importing *
, it will work, but will not be valid in ES2015. E.g. with the following...
// file a
export default 1;
// file b
import * as a from './a';
// file c
export const c = 3;
// file d
import c from './c';
In the official Babel module, a
in file b
will be undefined and c
in file d
will be undefined. Using this module, they will be 1
and 3
respectively.
You may want to use a linter (such as eslint with eslint-plugin-import) in order to ensure that your code is standard whilst using this simplified transform.
$ npm install --save-dev babel-plugin-transform-es2015-modules-simple-commonjs
.babelrc
(Recommended).babelrc
{
"plugins": ["transform-es2015-modules-simple-commonjs"]
}
require('babel').transform('code', {
plugins: ['transform-es2015-modules-simple-commonjs']
});
This replaces the functionality in transform-es2015-modules-commonjs
, but you may be better off using this with the babel-preset-es2015-webpack
preset, which takes the es2015 preset and removes the commonjs transform.
FAQs
Simplified imports and exports
The npm package babel-plugin-transform-modules-simple-commonjs receives a total of 1 weekly downloads. As such, babel-plugin-transform-modules-simple-commonjs popularity was classified as not popular.
We found that babel-plugin-transform-modules-simple-commonjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.