Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
get-es-imports
Advanced tools
Recursively or non-recursively gets all ES6 imports used within a project.
Recursively or non-recursively gets all ES6 imports used within a project.
E.g.
// a.js
import b from './b';
...
// b.js
import * as c from './c';
...
// c.js
import { find } from 'lodash';
...
Returns an object in the form:
{
'full path of ./b': ['default'],
'full path of ./c': ['*'],
'full path of lodash': ['find'],
}
import getEsImports from 'get-es-imports';
const { dependencies, loadedFiles } = await getEsImports({
files = [],
recurse = true,
exclude = [],
parser = defaultParser,
parserOptions = defaultParserOptions,
resolveOptions = {},
});
files
is an array of paths for JS files you want to check.
The recurse
option will recursively look at the files imported to find more imports. Will not recurse and look for dependencies within node_modules, but imports to these files are still recorded.
The exclude
option is an array of file globs for files you don't want to check when recursing. As with node_modules, imports to these files are still reported.
The parser
and parserOptions
options are identical to ESLint. By default, it will supports ES6 modules and JSX.
The resolveOptions
is passed to resolve to resolvev imports.
dependencies
is a map of absolute file path to an array of imports. Named imports are left as-is, default imports are reported as 'default'
, and namespace imports are reported as '*'
.
I.e.
import { a } from './a'; // 'a'
import { a as b } from './a'; // 'a'
import a from './a'; // 'default'
import * as a from './a'; // '*'
loadedFiles
is the files that were loaded and checked.
The default parser and default parser options are exported for your convenience.
To use babel-eslint
, use,
getEsImports({
...
parser: 'babel-eslint',
...
})
FAQs
Recursively get imported files and respective import names for files using ES import/export syntax
The npm package get-es-imports receives a total of 2 weekly downloads. As such, get-es-imports popularity was classified as not popular.
We found that get-es-imports 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.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
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.