fluttercommunity / import_sorter

🎯 Automatically organize your dart imports. Maintainer: @gleich
https://pub.dev/packages/import_sorter
MIT License
174 stars 40 forks source link

Guidelines / solution to run compiled version #60

Open vkammerer opened 3 years ago

vkammerer commented 3 years ago

Is your feature request related to a problem? Please describe. The current execution of flutter pub run import_sorter:main has a slow start due to the Dart VM initialisation. While it is acceptable if it is ran infrequently (like as a GIT commit hook for example), it is a lot more critical when running frequently (like every time a file is saved for example).

Describe the solution you'd like

Describe alternatives you've considered I have tested the execution time of this library for three different versions:

Results:

Additional context The benefits of running a compiled version are also explained in https://dart.dev/tutorials/server/get-started#6-compile-for-production.

This is what I've done to get a nice experience using this lib:

  1. Compile to native code
    dart compile exe bin/main.dart -o bin/import_sorter
  2. Add bin path to PATH
  3. Use lib in VSCode with https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave I've set it up with the following settings:
    
    "emeraldwalk.runonsave": {
    "commands": [
      {
        "match": "\\.dart$",
        "cmd": "import_sorter ${file}"
      }
    ]
    }


Now every time I save a file in my IDE, the imports are organised instantaneously! This makes it a lot more enjoyable.
gleich commented 2 years ago

See #63