npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

prettier_d_slim

v1.2.0

Published

Makes prettier fast

Downloads

1,792

Readme

prettier_d_slim

Makes prettier fast.

"But prettier is pretty fast already, right?"

Yes, it's really fast. But the node.js startup time and loading all the required modules slows down linting times for a single file to ~700 milliseconds. prettier_d_slim reduces this overhead by running a server in the background. It brings the formatting time down to ~130 milliseconds. If you want to format from within your editor whenever you save a file, prettier_d_slim is for you.

Install

This will install the prettier_d_slim command globally:

$ npm install -g prettier_d_slim

Usage

To start the server and lint a file, just run:

# Prettier needs to know the file name to do its thing.
$ cat file.js | prettier_d_slim --stdin --stdin-filepath file.js
# Or if you already have the content of the file:
$ prettier_d_slim --stdin-filepath file.js --text 'const foo = {}'

On the initial call, the prettier_d_slim server is launched and then the given file is formatted. Subsequent invocations are super fast.

How does this work?

The first time you use prettier_d_slim, a little server is started in the background and bound to a random port. The port number is stored along with [a token][change401] in ~/.prettier_d_slim. You can then run prettier_d_slim commands the same way you would use prettier and it will delegate to the background server. It will load a [separate instance][change220] of prettier for each working directory to make sure settings are kept local. If prettier is found in the current working directories node_modules folder, then this version of prettier is going to be used. Otherwise, the version of prettier that ships with prettier_d_slim is used as a fallback.

To keep the memory footprint low, prettier_d_slim keeps only the last 10 used instances in the internal nanolru cache.

Which versions of prettier are supported?

As far as I'm aware, all of them.

Commands

Control the server like this:

$ prettier_d_slim <command>

Available commands:

  • start: start the server
  • stop: stop the server
  • status: print out whether the server is currently running
  • restart: restart the server
  • [options] file.js [file.js] [dir]: invoke prettier with the given options. The prettier engine will be created in the current directory. If the server is not yet running, it is started.

Type prettier_d_slim --help to see the supported prettier options.

prettier_d_slim will select a free port automatically and store the port number along with an access token in ~/.prettier_d_slim.

Moar speed

If you're really into performance and want the lowest possible latency, talk to the prettier_d_slim server with netcat. This will also eliminate the node.js startup time.

$ PORT=`cat ~/.prettier_d_slim | cut -d" " -f1`
$ TOKEN=`cat ~/.prettier_d_slim | cut -d" " -f2`
$ echo "$TOKEN $PWD file.js" | nc localhost $PORT

Or if you want to work with stdin:

$ echo "$TOKEN $PWD --stdin" | cat - file.js | nc localhost $PORT

This runs prettier in under 50ms!

References

If you're interested in building something similar to this: Most of the logic was extracted to core_d, a library that manages the background server.

Compatibility

  • 1.0.0: prettier ^1.19.1

License

MIT