Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ntbosscher/fix-imports
https://github.com/ntbosscher/fix-imports
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/ntbosscher/fix-imports
- Owner: ntbosscher
- Created: 2022-03-03T20:02:59.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-03-03T20:36:34.000Z (almost 3 years ago)
- Last Synced: 2024-06-20T05:26:48.455Z (7 months ago)
- Language: Go
- Size: 4.88 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Fix-Imports
Refactoring a big JS library and breaking imports?
This is a fast way to automatically update your incorrect imports after a refactor.
```bash
import {Header} from "../Misc/Header";
-> Error: Cannot find module "../Misc/Header"> fix-imports --write
> scanning project/src...
> "../Misc/Header" -> import {Header} from "../../Header";
```## Getting started
```bash
> go install github.com/ntbosscher/fix-imports@latest
> cd project_root;
> fix-imports
```## Algorithm
By default fix-imports runs with `--write=false`, so you can see what updates will happen before applying them.
- Scan all imports (project with 800 files takes about 1.2s on my MBP)
- For imports that don't resolve, search for potential matches (e.g. `../Misc/Header`)
- Search for `Misc/Header.ts` (and similar)
- If one possible match is found, use that one
- If multiple matches are found, choose the one that is the closest in the directory structure
- If none are found, remove folders and run search again `Header.ts`
All changes are logged to the console, so you can see what's going on.