TS Import Extractor: which components from your library are imported?
Analyse a library’s TypeScript and TSX imports across projects, export a CSV and prepare a UI kit migration with TS Import Extractor.
Know which projects depend on a UI kit component
You maintain a React component library shared across several applications. Before changing a modal’s API, a question arises: which projects still import it? package.json tells you an application depends on the UI kit, without listing the components it imports. Searching manually through each repository becomes repetitive.
I created TS Import Extractor to meet this inventory need. This small Python script traverses local projects, collects named imports from a library in TypeScript and TSX files, then gathers them in a CSV. The original need, documented in the repository, concerns a UI kit used by several front-end projects. The dependency name is configurable.
The result provides a starting point for a design-system migration or examining component adoption. It moves from a declared dependency to a list of imported symbols, within the limitations of a text search.
Prepare a migration and identify consumers to check
If a component’s props change, the CSV helps identify projects where adaptations need finding. You can filter by its name in a spreadsheet and compare the inventory with each application’s declared UI kit version. A team can then prepare migration tasks by project and locate affected files in its editor.
The inventory can also inform a discussion about maintaining an old component. A rarely imported symbol becomes a candidate to examine. Deleting it still requires checking consumers outside the analysed scope and import forms the script does not recognise. An empty report therefore does not prove that a component is unused.
To track change, you can retain two dated exports and compare their rows over an identical scope. The script provides inventories; it calculates neither migration progress nor business priority. Import count remains a technical indicator to interpret alongside the affected flows.
Analyse a TypeScript library across several local projects
The README specifies Python 3.8 or later and projects present on your machine. The script uses only Python’s standard library: no Python package installation is needed. In the repository, the file to run is main.py.
git clone https://github.com/dokor/ts_import_extractor.git
cd ts_import_extractorIn main.py, replace dependance_to_analyze with the package name and populate projects_input with project roots. Here is a fictional configuration for a library named @exemple/ui; adapt the paths to your machine.
dependance_to_analyze = '@exemple/ui'
projects_input = {
'portail': '/chemin/vers/portail',
'administration': '/chemin/vers/administration',
}Traversal is recursive and has no directory exclusions. A root containing node_modules, generated files or tests includes them if they have a .ts or .tsx extension. For a first inventory, choose a targeted copy preserving the root package.json and desired sources, or a clone before dependency installation. Record that scope so exports can be compared.
python3 main.py
# Sous Windows, si le lanceur Python est installé :
# py -3 main.pyanalyse_kitui.csv is written to the current directory and replaced on every run. Its separator is a semicolon and its UTF-8 encoding includes a BOM to make opening in Excel easier. Processing reads local sources without network calls and does not modify them.
Read the CSV: an import is not a component rendering
Take a fictional example. In the portal, one page imports Button and Modal, aliased as Dialog. It uses Button three times in its JSX. In the admin application, two files each import Button. The following snippets explain counting based on the script’s code; they describe neither a real project nor a production measurement.
// portail/src/Page.tsx
import { Button, Modal as Dialog } from '@exemple/ui';
export function Page() {
return <Dialog><Button /><Button /><Button /></Dialog>;
}
// administration/src/Entete.tsx
import { Button } from '@exemple/ui';
// administration/src/Actions.tsx
import { Button } from '@exemple/ui';With the fictional package.json versions below, the expected rows are as follows. The Dialog alias maps back to the imported name Modal. Button counts once in the portal and twice in the admin application.
Project Name;Project Version;KitUI Version;Component;Usage Count
portail;1.4.0;^2.3.0;Button;1
portail;1.4.0;^2.3.0;Modal;1
administration;0.9.0;~2.2.0;Button;2Project Version comes from the root package.json version field. KitUI Version copies the declaration found in dependencies or, failing that, devDependencies. A range such as ^2.3.0 remains a range: the script does not read the lockfile to find the actually installed version. A missing version or unreadable package.json produces N/A. A project with no recognised import has no CSV row.
Syntax and files to check before deciding
The version consulted on 2 November 2026 searches imports using a regular expression. It recognises import { Button } from '@exemple/ui';, including across multiple lines, and handles aliases written with as. It expects a semicolon after the module string. The package name is inserted unchanged into the expression: regex special characters in that name can distort matching.
- Default imports, namespace imports and dynamic imports are not collected.
- The import type { ... } form and export { ... } from re-exports are not recognised. import { type Theme } is counted under the name type Theme, without normalisation. Package subpaths are not aggregated with the root name.
- Comments and strings are not parsed as TypeScript. Text resembling an import can produce a false positive.
- The report does not provide source file paths or track symbol usage after import. You need to return to the code to prepare the change.
Before interpreting an empty CSV, check configured paths: a nonexistent path may produce only the header without an error message. A source file read error may interrupt analysis. These situations require checking scope before concluding that imports are absent.
For an exhaustive audit, these limitations may justify analysis based on TypeScript’s syntax tree. To try this small tool, first choose a component whose consumers you know, check a few imports manually, then compare against the CSV. This first check lets you judge whether the inventory suits your project before basing a migration decision on it.
Sources and useful links
- TS Import Extractor: get the script on GitHub
- README: uses, prerequisites and limitations, consulted on 2 November 2026
- main.py: extraction, counting and CSV export in the examined version
- My products and personal tools
- Assess the need for a tool and its adoption cost
- Prepare a migration pull request that is easy to review