Skip to content

Commit

Permalink
feat!(prettier-plugins): clean up type definitions and package exports (
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusrbrown authored Oct 28, 2024
1 parent f35f4ce commit e315626
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 31 deletions.
7 changes: 7 additions & 0 deletions .changeset/rude-seas-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@bfra.me/prettier-plugins": minor
"@bfra.me/prettier-config": patch
---

Clean up type definitions and package exports.

8 changes: 5 additions & 3 deletions packages/prettier-plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"bugs": "https://github.com/bfra-me/works/issues",
"repository": {
"type": "git",
"url": "https://github.com/bfra-me/works.git",
"url": "git+https://github.com/bfra-me/works.git",
"directory": "packages/prettier-plugins"
},
"license": "MIT",
Expand All @@ -24,13 +24,14 @@
"exports": {
"./*": {
"types": "./lib/*.d.ts",
"source": "./src/*.ts",
"default": "./lib/*.js"
},
"./package.json": "./package.json"
},
"types": "lib/index.d.ts",
"files": [
"lib",
"src",
"!**/*.map"
],
"scripts": {
Expand All @@ -43,7 +44,8 @@
"@bfra.me/prettier-plugins": "workspace:*",
"@bfra.me/tsconfig": "workspace:*",
"prettier": "3.3.3",
"tsup": "8.3.4"
"tsup": "8.3.4",
"type-fest": "4.26.1"
},
"peerDependencies": {
"prettier": "^3.0.0"
Expand Down
3 changes: 0 additions & 3 deletions packages/prettier-plugins/src/index.ts

This file was deleted.

47 changes: 27 additions & 20 deletions packages/prettier-plugins/src/package-json.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
import type {
ParserOptions as PrettierParserOptions,
SupportOption,
SupportOptions as PrettierSupportOptions,
} from 'prettier'
import prettier from 'prettier'
import {parsers as babelParsers} from 'prettier/plugins/babel'
import {languages as estreeLanguages} from 'prettier/plugins/estree'
import * as estree from 'prettier/plugins/estree'
import {sortPackageJson} from 'sort-package-json'
import type {Writable as Writeable} from 'type-fest'

type SortPackageJsonOptions = NonNullable<Parameters<typeof sortPackageJson>[1]>
export type SortPackageJsonOptions = NonNullable<Parameters<typeof sortPackageJson>[1]>

export type PrettierPackageJsonOptions = {
/** Custom ordering array or comparator function. */
sortPackageJsonSortOrder?: SortPackageJsonOptions['sortOrder']
export interface PrettierPackageJsonOptions {
/** Custom ordering array. */
sortPackageJsonSortOrder: Extract<Writeable<SortPackageJsonOptions['sortOrder']>, string[]>
}

export type ParserOptions<T = any> = PrettierParserOptions<T> & PrettierPackageJsonOptions

const languages = estreeLanguages.filter(({name}) => name === 'JSON.stringify')

export type SupportOptions = PrettierSupportOptions & {
[_ in keyof PrettierPackageJsonOptions]: SupportOption
export interface PrettierPackageJsonSupportOptions extends prettier.SupportOptions {
sortPackageJsonSortOrder: prettier.StringArraySupportOption
}

const options: SupportOptions = {
export const options: PrettierPackageJsonSupportOptions = {
sortPackageJsonSortOrder: {
category: 'JavaScript',
category: 'Format',
type: 'string',
description: 'Custom ordering array.',
default: [{value: [] as string[]}],
array: true,
},
}

export interface ParserOptions<T = any>
extends prettier.ParserOptions<T>,
Partial<PrettierPackageJsonOptions> {}

const {languages: estreeLanguages} = estree as {languages: prettier.SupportLanguage[]}
export const languages = estreeLanguages.filter(({name}) => name === 'JSON.stringify')

const parser = babelParsers['json-stringify']

const parsers: Partial<typeof babelParsers> = {
export const parsers: Partial<typeof babelParsers> = {
'json-stringify': {
...parser,

Expand All @@ -61,4 +60,12 @@ const parsers: Partial<typeof babelParsers> = {
},
}

export {languages, options, parsers}
export interface PrettierPackageJsonPlugin extends prettier.Plugin {}

export const pluginPackageJson: PrettierPackageJsonPlugin = {
languages,
options,
parsers,
} as prettier.Plugin

export default pluginPackageJson
5 changes: 0 additions & 5 deletions packages/prettier-plugins/types/prettier/index.d.ts

This file was deleted.

3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e315626

Please sign in to comment.