Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
get-es-imports-exports
Advanced tools
Recursively get imports and exports for files using ES import/export syntax
Recursively or non-recursively gets all ES6 imports and exports used within a project.
E.g.
// a.js
import b from './b';
export b;
...
// b.js
export * from './c';
...
// c.js
import { find } from 'lodash';
export { find };
...
Returns an object in the form:
{
imports: {
'full path of ./b': ['default'],
'full path of ./c': ['*'],
'full path of lodash': ['find'],
},
exports: {
'full path of ./a': ['default'],
'full path of ./b': ['*'],
'full path of ./c': ['find'],
}
}
import getEsImportsExports from 'get-es-imports-exports';
const { imports, exports, loadedFiles, stats } = await getEsImportsExports({
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 resolve imports.
imports
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'; // '*'
Note that exports can also report as an import.
export * from 'lodash'; // equates to import * from 'lodash'
exports
is also a map of absolute filepath to an array, but this time, exports. As before, the same naming convention is used.
export const five = 5; // 'five'
export { five as FIVE } // 'FIVE'
export default 5; // 'default'
export * from './a'; // '*'
loadedFiles
is the files that were loaded and checked.
stats
is an array of warnings. Currently the only warning is if a file failed to parse, and had an extension that wasn't .js (which would otherwise throw).
The default parser and default parser options are exported for your convenience.
To use babel-eslint
, use,
getEsImportsExports({
...
parser: 'babel-eslint',
...
})
FAQs
Recursively get imports and exports for files using ES import/export syntax
The npm package get-es-imports-exports receives a total of 5 weekly downloads. As such, get-es-imports-exports popularity was classified as not popular.
We found that get-es-imports-exports 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
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.