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.
jscodeshift-imports
Advanced tools
A JSCodeshift extension with helpers for modifying `import` and `require` statements.
A JSCodeshift extension which
contains helpers for modifying import
and require
statements.
Install extension: npm install jscodeshift-imports
.
Register the extension with jscodeshift:
const imports = require('jscodeshift-imports');
module.exports = function(fileInfo, api) {
const {jscodeshift} = api;
imports.register(jscodeshift, imports.config.CJSBasicRequire);
// Your transform here.
}
Different configs will be needed based on your code style, this extension comes with two default configs:
You can also provide your own custom config.
addImport
This helper allows you to insert require statements into the most appropriate place within a file, it does this in a non destructive way so your codemod will change as little in the file as it can.
Usage:
const imports = require('jscodeshift-imports');
module.exports = function(fileInfo, api) {
const {jscodeshift} = api;
const {statement} = jscodeshift.template;
imports.register(jscodeshift, imports.config.CJSBasicRequire);
return jscodeshift(file.source)
.addImport(statement`
const MyRequireItem = require('MyRequireItem');
`)
.toSource();
}
addImport
accepts any require
or import
statement as long as it matches
one of the config types.
Note: This transform cannot be trusted. Whilst this implementation works in most cases it can give incorrect whitespace due to limitations in the AST. You will need to manually verify the output after running.
FAQs
A JSCodeshift extension with helpers for modifying `import` and `require` statements.
We found that jscodeshift-imports demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 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.
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.