Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

import-conductor

kreuzerk3kISC2.6.1TypeScript support: included

Automatically organize your Typescript import statements

Clean, Code, Imports, Automatization

readme

Logo

All Contributors

import-conductor

Automatically organize your TypeScript imports to keep them clean and readable.

Demo

What it does

Import conductor will order all imports into the following blocks:

1. Block - third party libraries

2. Block - user / company libraries

3. Block - imports from other modules or directories in your codebase

4. Block - imports for the same module

Take a look at the following source file. It's hard to distinguish between third-party imports, company wide imports and files from same module.

import { Component, OnInit } from '@angular/core';
import { CustomerService } from './customer.service';
import { Customer } from './customer.model';
import { Order } from '../order/order.model';
import { LoggerService } from '@myorg/logger';
import { Observable } from 'rxjs';

A cleaner version that is easy scannable would look like this:

import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';

import { LoggerService } from '@myorg/logger';

import { Order } from '../order/order.model';

import { Customer } from './customer.model';
import { CustomerService } from './customer.service';

Of course, it's a lot of work to order all import statements in existing code bases. Furthermore, in bigger development teams it's hard to enforce this syntax so that every developer orders their imports accordingly. Especially with AutoImports in IDEs.

That's where import-conductor comes into play. Import-conductor can reorder all imports in your project, and combined with tools like husky you can automatically reorder imports of changed files in a pre commit hook.

Usage

  • Run in the command line:

`shell script npx import-conductor -s customer.component.ts -p @myorg


- Run as a npm script:

```json
 "scripts": {
    "import-conductor": "import-conductor -p @myorg"
 },
  • Integrate with tools like husky:
  "lint-staged": {
    "*.{ts,tsx}": [
      "import-conductor --staged -p @myorg",
      "prettier --write",
      "eslint --fix",
      "git add"
    ]
  },

Options

  • source - Regex to that matches the source files: (defaults to [./src/**/*.ts])

`shell script import-conductor --source mySrc//*.ts anotherSrc//.ts import-conductor -s mySrc/**/.ts anotherSrc//*.ts import-conductor mySrc//.ts anotherSrc/**/.ts


- `ignore`\* - Ignore files that match the pattern: (defaults to `[]`)

```shell script
import-conductor --ignore 'mySrc/**/*some.ts' 'main.ts'
import-conductor -i 'mySrc/**/*some.ts' 'main.ts'

*Note: you can also skip a file by adding the following comment at the top:

// import-conductor-skip
...
  • userLibPrefixes - The prefix of custom user libraries - the prefix used to distinguish between third party libraries and company libs: (defaults to [])

`shell script import-conductor --userLibPrefixes @customA @customB import-conductor -p @customA @customB


- `separator` - The string separator between the imports sections: (defaults to `\n`)

```shell script
import-conductor --separator '' ==> no separator
  • groupOrder - The group order to follow: (defaults to [thirdParty, userLibrary, differentModule, sameModule])

`shell script import-conductor --groupOrder 'userLibrary' 'differentModule' 'sameModule' 'thirdParty' import-conductor -g 'userLibrary' 'differentModule' 'sameModule' 'thirdParty'


- `staged` - Run against staged files: (defaults to `false`)

```shell script
import-conductor --staged
  • noAutoMerge - Disable automatically merging 2 import statements from the same source: (defaults to false)

`shell script import-conductor --noAutoMerge


- `autoAdd` - Automatically adding the committed files when using the staged option: (defaults to `false`)

```shell script
import-conductor --autoAdd
import-conductor -a
  • dryRun - Run without applying any changes: (defaults to false)

`shell script import-conductor --dryRun import-conductor -d


- `verbose` - Run with detailed log output: (defaults to `false`)

```shell script
import-conductor --verbose
import-conductor -v
  • version:

`shell script import-conductor --version


- `help`:

```shell script
import-conductor --help
import-conductor -h

Core Team


Kevin Kreuzer


Shahar Kazaz

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Kevin Kreuzer
Kevin Kreuzer

💻 🎨 📖 🤔 🚇 🚧 ⚠️
Shahar Kazaz
Shahar Kazaz

💻 📖 🤔 🚇 🚧 ⚠️
Robert Laurenz
Robert Laurenz

📖
Lonli-Lokli
Lonli-Lokli

💻 ⚠️ 🐛
Yuri Santos
Yuri Santos

💻
markoberholzer-es
markoberholzer-es

💻 🤔
Michael Trefzer
Michael Trefzer

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

changelog

2.6.1 (2023-06-01)

Bug Fixes

  • using npm 9 with lockfileVersion 3 (eddbbbb)

2.6.0 (2023-01-11)

Features

  • switch to fast-glob for performance (f0dc90a)

2.5.0 (2022-07-01)

Features

2.4.1 (2022-06-25)

Bug Fixes

  • 🐛 veryify actions before updating a file (667a80f)
  • verifyng action before update file (0ba0c63)

2.4.0 (2022-04-05)

Features

  • 🎸 (organize) export organize imports function (9e9bac5)

2.3.0 (2022-04-05)

Features

  • 🎸 (conduct) allow conduct usage from code (12d83ce)

2.2.6 (2022-04-01)

Bug Fixes

  • 🐛 (vulnearbility) update simple git (e91e4c1)

2.2.5 (2021-03-25)

Bug Fixes

  • 🐛 remove accidental debug console.log (3b2a742)

2.2.4 (2021-03-25)

Bug Fixes

  • 🐛 handle multiple line endings (6fc41ff)

2.2.3 (2021-03-24)

Bug Fixes

  • 🐛 handle third party libraries that are not installed (aab3f11)

2.2.2 (2021-02-11)

Bug Fixes

  • 🐛 Fixed case with empty separator added (6419a16)

2.2.1 (2020-10-13)

Bug Fixes

  • 🐛 code between import statements gets deleted (90e3f90), closes #40

2.2.0 (2020-10-11)

Features

  • 🎸 allow changing the sections separator (800dbd9), closes #34

2.1.0 (2020-10-11)

Bug Fixes

  • 🐛 cli default option wasn't working (9304f31)

Features

  • 🎸 support multiple sources (5e16de2)

2.0.3 (2020-09-05)

Bug Fixes

  • 🐛 re-runing the conductor adds an extra new line (ff8bc6d), closes #37

2.0.2 (2020-09-01)

Bug Fixes

  • 🐛 conductor removing comments from the imports section (05f0215), closes #25

2.0.1 (2020-08-31)

Bug Fixes

  • 🐛 merge statements breaks with trailing comma (661d594)
  • 🐛 third party wrong classification (7e33e47)

2.0.0 (2020-08-29)

Features

  • 🎸 support ignore files and dry run (4a28554), closes #20

BREAKING CHANGES

  • 🧨 config options

1.5.1 (2020-08-21)

Bug Fixes

  • 🐛 custom imports not categorised correctly (a735201), closes #21

1.5.0 (2020-08-07)

Features

  • options: trigger new release (1f4d380)

1.4.4 (2020-07-27)

Bug Fixes

  • imports: fix wrong import of gitChangedFiles (f775f69)

1.4.3 (2020-07-05)

Bug Fixes

  • imports: adjust imports (ce3607a)

1.4.2 (2020-06-26)

Bug Fixes

1.4.1 (2020-06-26)

Bug Fixes

1.4.0 (2020-06-26)

Features

  • regex: use regex instead of path (607a062)

1.3.0 (2020-06-25)

Features

  • organization: touch imports only (6bb5545)

1.2.0 (2020-06-25)

Features

1.1.0 (2020-06-25)

Features

  • merge: merge import statments from same lib (ee6c247)

1.0.1 (2020-06-24)

Bug Fixes

  • deps: add TypeScript as a dependency (5765ffe)

1.0.0 (2020-06-24)

Bug Fixes

  • newlines: do not add newlines if previous category is empty (33c82ea)
  • newlines: improve newline detection (ef06b06)

Features

  • add: automatically add files on staged option (861e659)
  • add: log processed files (21a4fd0)
  • files: run only against staged files (6a7a6ac)
  • map: create import statement map (fa3b61f)
  • pots: split import paths to pots (ec26683)
  • statements: update content and sort statements (83dad60)