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

@elegantech/prettier-multi-config

v1.1.0

Published

Pre-configuration builder for Prettier 3 to support multiple file formats.

Downloads

8

Readme

@elegantech/prettier-multi-config

semantic-release

Multi-configurations presets for Prettier 3. Compatibility with some plugins (PHP, Blade templates, Bash, etc).

Requirements

  • Prettier >= 3.0.0: Base prettier and plugins are compatible with Prettier >= 3 only.
  • Node.js:
    • Minimum: 14.18.0 (for ESM config compatibility and default plugins)
  • npm:
    • Minimum: 7.2.0 (automatic install of peerDependencies).

Note: Some optional plugins may require a more recent version of Node.js.

Installing

In the following instructions it will be used npm, but commands arguments are the same for yarn.

Add Prettier and this package to your project:

# Base Prettier 3
npm add -D --save-exact prettier

# This package
npm add -D @elegantech/prettier-multi-config

Prettier's team recommends to use --save-exact for prettier dependency.

Installing plugins dependencies

There are other optional dependencies that vary depending of the presets you are using. Check that sections for instructions.

Depending on how are you creating your own config file, you may choose to install the required plugins packages as:

  • devDependencies (-D, --save-dev).
  • peerDependencies (--save-peer).
  • dependencies.

In the following plugin installation instructions, it is assumed you are building your configuration directly into your project, and therefore plugin packages should be installed as devDependencies (using the -D npm/yarn alias).

Available presets

There are some presets available with default configurations and plugins for specific languages or cases. These will help you create your own configuration file.

Check for examples in the Usage section.

Base preset (base)

Includes general base rules for all the languages/files officially supported by Prettier. Also, there are options for formatting the package.json file.

Required plugins:

npm add -D prettier-plugin-pkg

PHP preset (php)

Compatibility with PHP.

Note: You need to set the phpVersion option depending of your PHP environment.

Required plugins:

npm add -D @prettier/plugin-php

Bash Script preset (sh)

Compatibility with Shell Script for Bash or sh.

Required plugins:

npm add -D prettier-plugin-sh

Multiline preset (sh)

Multiline elements for some languages.

Required plugins:

npm add -D prettier-plugin-multiline-arrays

Usage

Simple usage

Although this package is not intended to be used directly as a shared configuration or plugin, you can still use the default export as your prettier setup.

In your package.json:

{
  "prettier": "@elegantech/prettier-multi-config"
}

Or in your .prettierrc.json:

"@elegantech/prettier-multi-config"

This includes the base preset only.

You can use this technique to create your shared configuration using this package. 😉

Check out the following sections to create your own customized configuration file.

The config file

You have to use .js, .cjs or .mjs formats to be able to customize your presets. As you can see, this package it's available for ESM and CommonJs modules.

Remember: If your project is an ESM ({ "type": "module" } in your package.json), by using .prettierrc.js it will import the ESM build, but in the other hand, it will be required the commonjs version. To avoid this, you can use .cjs or .mjs extensions instead.

Initial state for .prettier.mjs:

/** @type {import("prettier").Config} */
const config = {
  // ...
};

export default config;

Read more about config formats in the Prettier documentation.

Examples

Note: Most of the following examples will assume you are using .prettierrc.mjs (ESM), but you are free to use .cjs format instead.

In your .prettier.mjs:

import {
  getMergedGlobalOptionsFor,
  getPluginsFor,
  getMergedOverrideFor,
} from '@elegantech/prettier-multi-config/presets';

const selectedPresets = [
  'base',
  'php',
  'sh',
];

/** @type {import("prettier").Config} */
const config = {
  // Add global configurations for selected presets
  ...getMergedGlobalOptionsFor(selectedPresets, {
    // Here you can add your own global options
  }),

  // Add plugins for selected presets
  plugins: getPluginsFor(selectedPresets, [
    // Here you can add other plugins
    'prettier-plugin-organize-imports',
  ]),

  overrides: [
    // Specific options for presets
    ...getMergedOverrideFor('base'),
    ...getMergedOverrideFor('php', {
      config: {
        // You can override some default options in the preset
        options: { phpVersion: '8.1' },
      },
    }),
    ...getMergedOverrideFor('sh'),

    // Here ypu can add your custom config override
    {
      files: ['.prettierrc.json'],
      options: {
        printWidth: 80,
      },
    },
  ],
};

The order of included options is respected. Be careful of options

Publish a package for your config file (🚧 WIP)

You can create a package that builds the config, using Typescript directly.

Check this example using unbuild to create a config.

🚧 WIP

IDEs

VS Code

Check the .vscode directory for extensions and settings recommendations.

Sponsors

License

Licensed under the Apache License, Version 2.0.