Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
babel-plugin-amd-default-export
Advanced tools
A Babel plugin to make the generated AMD modules export the default export directly and not wrapped in an object with a default property.
A Babel plugin to make the AMD modules generated by @babel/plugin-transform-modules-amd export the default export directly and not wrapped in an object with a default
property, which happen in Babel 6 and newer: { default: ... }
. It will export just the exported value in module.exports
, similarly to the return
statement in an AMD module.
This plugin is supposed to be used especially with requirejs-babel7, which al,lows mixing AMD and ESM modules in one project and a consistent handling of default exports is necessary.
This module can be installed in your project using NPM, PNPM or Yarn. Make sure, that you use Node.js version 6 or newer.
npm i -D babel-plugin-amd-default-export
pnpm i -D babel-plugin-amd-default-export
yarn add babel-plugin-amd-default-export
Prevent the transpiler to wrap source files that are already wrapped by define
or require
as AMD modules:
{
plugins: ['amd-default-export']
}
A typical configuration combined with @babel/plugin-transform-modules-amd:
{
plugins: [
'transform-modules-amd',
'amd-default-export'
]
}
Another complete configuration example:
{
plugins: [
'amd-checker',
'transform-modules-amd',
[
'module-resolver',
{
resolvePath: function (sourcePath, currentFile, opts) {
// Avoid prefixing modules handled by other plugins.
if (sourcePath.indexOf('!') < 0) {
return 'es6!' + sourcePath;
}
}
}
],
[
'amd-default-export',
{ addDefaultProperty: true }
]
]
}
The option addDefaultProperty
enables setting the exported value to a default
property in addition. It can improve the compatibility with consumers expecting the default export directly, or wrapped. It may interfere with some cases, where additional properties cannot be included in exported objects.
In lieu of a formal styleguide, take care to maintain the existing coding style. Lint and test your code.
Copyright (c) 2022 Ferdinand Prantl
Licensed under the MIT license.
FAQs
A Babel plugin to make the generated AMD modules export the default export directly and not wrapped in an object with a default property.
We found that babel-plugin-amd-default-export 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.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.