New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

import-unifier

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

import-unifier

Generic import consolidator for TypeScript projects. Merge imports from a source path into a target file.

latest
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

import-unifier

Generic Import Consolidator for TypeScript Projects

import-unifier helps streamline imports by consolidating them from a source path into a single target file. It works seamlessly with any TypeScript project, keeping your imports clean, consistent, and maintainable.

✨ Features

  • 🔄 Consolidates imports from any source path into one target file
  • 🔗 Merges named and default imports automatically
  • 📁 Creates the target file automatically if it doesn't exist
  • 🎯 Supports TypeScript (.ts) and TSX (.tsx) files
  • 🛠️ Provides both CLI and programmatic usage
  • 📊 Logs processed files for easy tracking
  • 🧹 Improves codebase maintainability by avoiding duplicate imports and clutter

📦 Installation

# Using npm
npm install import-unifier --save-dev

# Using yarn
yarn add import-unifier --dev

🚀 Usage

Programmatic Usage

import { consolidateImports } from "import-unifier";

consolidateImports({
  tsConfigPath: "tsconfig.json",                // optional (default: tsconfig.json)
  sourceGlob: "src/**/*.tsx",                   // optional (default: src/**/*.ts{,x})
  sourcePath: "src/components/",                // required: folder to consolidate from
  targetPath: "src/shared/components/index",    // required: target file path
  log: true                                     // optional (default: true)
});

How it works:

  • Scans all files under sourceGlob
  • Collects imports from sourcePath
  • Rewrites imports to point to targetPath
  • Merges imports into the target file (index.ts)

CLI Usage

npx consolidate-imports <tsConfigPath?> <sourcePath> <targetPath>

Arguments:

  • tsConfigPath (optional): Path to your TypeScript config (default: tsconfig.json)
  • sourcePath (required): Folder or module path to consolidate imports from
  • targetPath (required): File path where consolidated imports will be merged

Example:

npx consolidate-imports tsconfig.json src/components/ src/shared/components/index

📋 Example

Before consolidation:

// src/pages/Home.tsx
import { Button } from "src/components/Button";
import { Card } from "src/components/Card";
import { Modal } from "src/components/Modal";

// src/pages/Dashboard.tsx
import { Button } from "src/components/Button";
import { Table } from "src/components/Table";

After running import-unifier:

// src/pages/Home.tsx
import { Button, Card, Modal } from "src/shared/components/index";

// src/pages/Dashboard.tsx
import { Button, Table } from "src/shared/components/index";

// src/shared/components/index.ts (auto-generated)
export { Button } from "../../components/Button";
export { Card } from "../../components/Card";
export { Modal } from "../../components/Modal";
export { Table } from "../../components/Table";

All imports from the source folder are merged into a single import pointing to the target file, making your codebase cleaner and more maintainable.

🎯 Use Cases

  • Component Libraries: Consolidate component imports into a single index file
  • Utility Functions: Merge utility imports from scattered files
  • API Services: Centralize API service imports
  • Constants: Unify constant imports across your project
  • Types: Consolidate TypeScript type imports

⚙️ Configuration Options

OptionTypeDefaultDescription
tsConfigPathstring"tsconfig.json"Path to TypeScript configuration file
sourceGlobstring"src/**/*.ts{,x}"Glob pattern to match files for processing
sourcePathstringRequiredSource folder/path to consolidate imports from
targetPathstringRequiredTarget file path for consolidated imports
logbooleantrueEnable logging of processed files

📝 License

MIT License © [Your Name]

🔧 Requirements

  • Node.js >= 14.0.0
  • TypeScript >= 4.0.0

Made with ❤️ for cleaner TypeScript codebases

Keywords

typescript

FAQs

Package last updated on 24 Sep 2025

Did you know?

Socket

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.

Install

Related posts