Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
jscodeshift-add-imports
Advanced tools
add imports/requires if not already present with jscodeshift
Easily add import and require statements with jscodeshift. If something is already imported, returns the locally bound identifier, and avoids name conflicts.
npm install --save jscodeshift-add-imports
const j = require('jscodeshift')
const addImports = require('jscodeshift-add-imports')
const { statement } = j.template
const code = `
// @flow
import {foo, type bar} from 'foo'
import baz from 'baz'
`
const root = j(code)
const result = addImports(root, [
statement`import type {bar, baz} from 'foo'`,
statement`import blah, {type qux} from 'qux'`,
])
console.log(result)
console.log(root.toSource())
Output code:
// @flow
import { foo, type bar } from 'foo'
import baz from 'baz'
import type { baz as baz1 } from 'foo'
import blah, { type qux } from 'qux'
Return value:
{
bar: 'bar',
baz: 'baz1',
blah: 'blah',
qux: 'qux',
}
Currently tested on jscodeshift@0.11.0
with the following parsers:
babylon
ts
There are currently issues with the babel
and flow
parsers.
It won't likely work with other custom parsers unless they output nodes in the same format as Babel for import declarations, variable declarations, require calls, and object patterns.
addImports(root, statments)
root
The jscodeshift-wrapped AST of your source code
statements
The AST of an import declaration or variable declaration with requires to add, or an array of them.
An object where the key is the local identifier you requested in statements
,
and the value is the resulting local identifier used in the modified
code (which could be the existing local identifier already imported in the code or
the local identifier chosen to avoid name conflicts with an existing binding)
FAQs
add imports/requires if not already present with jscodeshift
We found that jscodeshift-add-imports demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.