Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
detect-import-require
Advanced tools
This is like detective, but with a narrow focus and thin API, specifically aimed at supporting either import
and/or require
statements, and not much more.
npm install detect-import-require --save
Given the following file:
source.js
var foo = require('a').foo
var bar = require('./blah.js')
import { uniq } from 'lodash'
import { resolve } from 'path'
var fs = require('fs')
var detect = require('detect-import-require')
var src = fs.readFileSync('source.js', 'utf8')
console.log(detect(src))
//=> [ 'a', './blah.js', 'lodash', 'path' ]
modules = detect(src, [opt])
Returns an array of module names (require paths) from the given src
String or Buffer, which is assumed to be ES6/ES5. By default, looks for import
and require
statements. Results are not de-duplicated, and are in the order they are found.
Options:
imports
(Boolean) - whether to look for import
statements, default truerequires
(Boolean) - whether to look for require
statements, default truemodules = detect.find(src, [opt])
Takes the same options as above, but returns an object with the following additional data:
{
strings: [],
expressions: [],
nodes: []
}
Where strings
is the array of module names, expressions
is an array of expressions from dynamic require()
statements, and nodes
is an array of AST nodes for each found require/import statement.
Expressions do not appear in imports, and look like this:
[
"path.join(__dirname, '/foo.js')",
"__dirname + '/file.js'"
]
MIT, see LICENSE.md for details.
FAQs
list require and import paths from a JavaScript source
The npm package detect-import-require receives a total of 62 weekly downloads. As such, detect-import-require popularity was classified as not popular.
We found that detect-import-require 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 found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.