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.
babel-plugin-list-imports
Advanced tools
Lists the files imported by a ESModule file.
npm i babel-plugin-list-imports
import babel from '@babel/core'
import createImportLister from 'babel-plugin-list-imports'
// Create the plugin
const importLister = createImportLister() // EventEmitter { plugin: [Plugin], state: [Set] }
// Example code, demonstrates all recognized imports
const code = `
// Normal default and named imports
import React from 'react'
import { niceTool, helper as someHelper } from './some-utils.js'
// Importing for side effects only
import 'side-effects.js'
// Extension doesn't matter
import styles from './styles.css'
// Importing all as namespace
import * as namespaceImport from 'some-lib'
// Exporting from source
export { default as something } from './source.js'
// Exporting everything from a source
export * from './another-source.js'
// Dynamic imports
import('dynamic')
// Dynamic imports referencing an unchanged variable
const dynamicSrc = './tool.js'
var unchangedDynamicSrc = '../path/to/import.js'
import(dynamicSrc)
import(unchangedDynamicSrc)
// Non top-level dynamic imports
document.getElementById('load-button').addEventListener('click', () => {
import('string-literal')
import(dynamicSrc)
import(unchangedDynamicSrc)
})
`
// Use the plugin
// You don't need to wait for other plugins to run before accessing the imports
// You can listen for the 'list' event
importLister.once('list', () => {
// You can get the [Set] of imports with the state property
console.log(importLister.state)
/* Set {
'react',
'./some-utils.js',
'side-effects.js',
'./styles.css',
'some-lib',
'./source.js',
'./another-source.js',
'dynamic',
'./tool.js',
'../path/to/import.js',
'string-literal'
} */
// If you are going to reuse this plugin, remember to reset the state
importLister.state.clear()
})
// This example does transformAsync
babel.transformAsync(code, { plugins: [importLister.plugin] })
FAQs
Lists the files imported by a ESModule file.
We found that babel-plugin-list-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.
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.