
Product
Introducing Pull Request Stories to Help Security Teams Track Supply Chain Risks
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
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.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.