Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
babel-plugin-module-deps
Advanced tools
Babel plugin to annotate CJS modules with what they require
This Babel plugin redefines require
within all (CJS) modules to record any
required modules in an array of resolved filenames called module.deps
.
(Note that the array may have duplicates.)
It only works with
Node.js CommonJS modules
(though with
@babel/plugin-transform-modules-commonjs
you can still use ESM syntax).
The module.deps
arrays let a tool later discover what other modules
each module depends on, by inspecting require.cache[filename].deps
.
This can be useful to deep-reload a module, or to detect when a module
should be called according to whether a generated file is older
than the module or dependency code.
Add the module as a plugin to your Babel configuration, as in:
{
"plugins": ["babel-plugin-module-deps"]
}
Generally you want this plugin to run last,
so list it last
in the "plugins"
array.
In particular, this plugin should run after
@babel/plugin-transform-modules-commonjs
(if you're using ESM syntax in CJS),
so that require
is redefined before import
s get executed
(as they are simulated by require
).
Then you can access the current module's dependencies via module.deps
,
or an arbitrary module's dependencies via require.cache[filename].deps
,
where filename
is the require.resolve
d filename for a module.
If you've just run require(modname)
with
@babel/register
configured to run this plugin, then calling the function below as
walkDeps(modname)
should give an array of all recursive module dependencies
that modname
require
s or import
s as require.resolve
d filenames
(including require.resolve(modname)
itself, but excluding duplicates).
function walkDeps(modname) {
const deps = {};
function recurse(submodname) {
deps[submodname] = true;
const submod = require.cache[submodname];
if (!submod) return;
const subdeps = submod.deps;
if (!subdeps) return;
for (dep of subdeps)
if (!dep in deps)
recurse(dep);
}
recurse(require.resolve(modname));
return Object.keys(deps);
}
FAQs
Babel plugin to annotate CJS modules with what they require
The npm package babel-plugin-module-deps receives a total of 1 weekly downloads. As such, babel-plugin-module-deps popularity was classified as not popular.
We found that babel-plugin-module-deps 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 uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.