Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.