PackedPrettier 2.8.8.211

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global PackedPrettier --version 2.8.8.211                
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local PackedPrettier --version 2.8.8.211                
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=PackedPrettier&version=2.8.8.211                
nuke :add-package PackedPrettier --version 2.8.8.211                

PackedPrettier

The opinionated code formatter Prettier packed as dotnet tool.

What is prettier?

Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.

GitHub - prettier/prettier: Prettier is an opinionated code formatter.

It is written in javascript and requires node to run.

What is PackedPrettier?

PackedPrettier packs prettier in an executable for various platforms.

Including node.

You can install it using dotnet tool install, both as global and local tool.

Getting started

Installation

Install as local dotnet tool:

  1. If you haven't used any other dotnet tools yet, create a tool manifest first:
    dotnet new tool-manifest
    
  2. Install PackedPrettier
    dotnet tool install PackedPrettier
    

How to use

In the terminal:

dotnet pprettier --help

❗ The command is named pprettier for brevity and internally prettier is executed.

In Visual Studio

  1. Install RunOnSave: A Visual Studio extension that can run commands on files when they're saved.

  2. Create a .onsaveconfig with this content:

    [*.{js,jsx,ts,tsx,css,less,scss,vue,json,gql,md}]
    command = dotnet
    arguments = pprettier --write "{file}"
    

When you save a file in VS, prettier will reformat it

Plugins

By default, two plugins are included (always the latest version at time of compilation of prettier):

They aren't used by default. You need to tell prettier where to find them.

Because the plugins are part of the packed prettier binary, the files are stored in a virtual filesystem.

For Windows that's C:\snapshot\node_modules and /snapshot/node_modules for unix systems. This doesn't map to a real directory on your machine but is a placeholder that tells the packed binary to "re-route" the request to the shipped files at runtime.

So if you want to load prettier/plugin-xml, then you need to write:

dotnet pprettier --write <file path> --plugin=/snapshot/node_modules/@prettier/plugin-xml

❗ Do not replace /snapshot/node_modules/ (or C:\snapshot\node_modules on Windows) with a real path!

To make this portable across Windows and Linux machines, PackedPrettier will replace the magic string <NodeModulesPath> at runtime with the correct path.

That means you can just write:

dotnet pprettier --write <file path> --plugin=<NodeModulesPath>/@prettier/plugin-xml

and it will work on any supported operating system.

Example with test.xml:

dotnet pprettier --write test.xml --plugin=<NodeModulesPath>/@prettier/plugin-xml
Plugin File types Lookup Path
prettier-plugin-sh shellscript, Dockerfile, gitignore, dotenv and many more! <NodeModulesPath>/prettier-plugin-sh
@prettier/plugin-xml xml <NodeModulesPath>/@prettier/plugin-xml

Custom .onsaveconfig entries

[*.{xml,csproj,xaml,appxmanifest,props,wapproj}]
command = dotnet
arguments = pprettier --write "{file}" --plugin "<NodeModulesPath>/@prettier/plugin-xml" --parser "xml"

[*.sh]
command = dotnet
arguments = pprettier --write "{file}" --plugin "<NodeModulesPath>/prettier-plugin-sh"

What about C# files (.cs)?

There is a (sort of) port of prettier that supports cs files:

Checkout belav/csharpier: an opinionated code formatter for c#. and install it as dotnet tool. Then add this to your .onsaveconfig file:

[*.cs]
command = dotnet
arguments = csharpier "{file}"

Supported Platforms of PackedPrettier

prettier is compiled for

  • Windows x64

  • Linux x64

and the loader requires either

  • .Net 6

  • .Net 7

❗ Support for .NET Core 3.1 and .NET 5 has been dropped because they are out of support.

Mac OS support

This is not possible because executable has to be signed (with either an adhoc signature) or an Apple Developer ID. Checkout the official pkg readme for details.

Found a bug? Have a suggestion?

Please create an issue.

Pull requests are always welcome 😍

License

This software is released under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
3.2.5.13 6,380 2/10/2024
2.8.8.211 3,179 4/24/2023
2.8.7.181 1,235 3/25/2023
2.8.6.178 772 3/22/2023
2.8.5.177 752 3/21/2023
2.8.4.137 3,304 2/9/2023
2.8.3.112 1,098 1/15/2023
2.8.2.105 880 1/8/2023
2.8.1.100-alpha1 634 12/16/2022
2.7.1.14 2,616 7/3/2022
2.6.2.14 1,964 5/14/2022
2.6.2.11 1,792 5/11/2022
2.5.1.10 3,363 1/22/2022
2.5.1.9 1,452 1/22/2022
2.5.1.8 1,460 1/22/2022