
Security News
Nx npm Packages Compromised in Supply Chain Attack Weaponizing AI CLI Tools
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Transform CommonJS module, hoisting `require` and `exports` statements to top-level.
Transform CommonJS module, hoisting require
and exports
statements to top-level.
const {parse} = require("acorn");
const {transform} = require("cjs-hoist");
const {code} = transform({
parse,
code: `
if (foo) {
const bar = require("bar");
}
`
});
/* code -> `
const _require_bar_ = require("bar");
if (foo) {
const bar = _require_bar_;
}
`
This module exports following members.
transform
: A function which can convert CJS module synax into ES module syntax.options
has following members:
parse
: function. A parser function which can parse JavaScript code into ESTree.code
: string. The JavaScript source code.sourceMap?
: boolean. If true then generate the source map. Default: false
ignoreDynamicRequire?
: boolean. If true then the dynamic require (i.e. Promise.resolve(require("..."))
) is ignored. Default: true
The result object has following members:
code
: string. The result JavaScript code.map?
: object. The source map object generated by magicString.generateMap
.isTouched
: boolean. If false then the code isn't changed.0.1.3 (Apr 26, 2018)
0.1.2 (Apr 26, 2018)
0.1.1 (Apr 26, 2018)
isTouched
prop.0.1.0 (Apr 26, 2018)
FAQs
Transform CommonJS module, hoisting `require` and `exports` statements to top-level.
We found that cjs-hoist 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
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.