
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
@alcalzone/esm2cjs
Advanced tools
Command line utility to compile a JS project from ES modules to CommonJS
Command line utility to compile a JS project from ES modules to CommonJS. This is handy when building hybrid ESM/CommonJS npm packages.
Built on top of the blazing fast esbuild and supports all modern JS features.
Either globally:
# using npm
npm i -g @alcalzone/esm2cjs
# using yarn
yarn add --global @alcalzone/esm2cjs
Or locally as a devDependency
:
# using npm
npm i -D @alcalzone/esm2cjs
# using yarn
yarn add --dev @alcalzone/esm2cjs
Using the binary outside of package.json
scripts requires global installation.
esm2cjs --in path/to/input --out path/to/output [options]
Detailed help is shown on the command line using
esm2cjs --help
Configure tsconfig.json
to write ESM output into build/esm
:
// tsconfig.json
{
// ...
"compilerOption": {
// ...
"outDir": "build/esm",
"module": "ES2020" // or some of the new options in TS 4.5 "node12", "nodenext"
}
}
Add a postbuild
script that transforms the ESM output to CommonJS:
// package.json
{
// ...
"scripts": {
// ...
"postbuild": "esm2cjs --in build/esm --out build/cjs -l error"
}
}
Set up the exports
field in package.json
. Note that the syntax for types
might need additional changes when TypeScript 4.5 lands.
// package.json
{
"main": "build/cjs/index.js",
"module": "build/esm/index.js",
"exports": {
".": {
"import": "./build/esm/index.js",
"require": "./build/cjs/index.js"
},
// This is necessary to require/import `your-library/package.json`
"./package.json": "./package.json",
// additional subpath exports go here, e.g. your-library/tools
"./tools": {
"import": "./build/esm/tools.js",
"require": "./build/cjs/tools.js"
},
// or everything in the source root:
"./*": {
"import": "./build/esm/*.js",
"require": "./build/cjs/*.js"
}
},
// ...
}
This assumes your ESM modules are located in lib/
and the cjs output goes to dist/cjs/
.
Add a build
script that transforms the ESM output to CommonJS:
// package.json
{
// ...
"scripts": {
// ...
"build": "esm2cjs --in lib --out dist/cjs -l error"
}
}
Set up the exports
field in package.json
.
// package.json
{
"main": "dist/cjs/index.js",
"module": "lib/index.js",
"exports": {
".": {
"import": "./lib/index.js",
"require": "./dist/cjs/index.js"
},
// This is necessary to require/import `your-library/package.json`
"./package.json": "./package.json",
// additional subpath exports go here, e.g. `your-library/tools`
"./tools": {
"import": "./lib/tools.js",
"require": "./dist/cjs/tools.js"
},
// or everything in the lib folder:
"./*": {
"import": "./lib/*.js",
"require": "./dist/cjs/*.js"
}
}
// ...
}
zwave-js
No. of input files | total size | time taken |
---|---|---|
141 | 987 KB | 390 ms |
keepNames
option to true
by defaultimports
field in package.json
sideEffects
in the generated package.json
as a hint for bundlersimport.meta.url
by defaultDependency updates
Dependency updates
Support specifying output target and platform
Initial release
FAQs
Command line utility to compile a JS project from ES modules to CommonJS
The npm package @alcalzone/esm2cjs receives a total of 1,054 weekly downloads. As such, @alcalzone/esm2cjs popularity was classified as popular.
We found that @alcalzone/esm2cjs demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.