Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
@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 317 weekly downloads. As such, @alcalzone/esm2cjs popularity was classified as not 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 0 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.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.