From e315626ce5073c6f03dc136209ef467f06ce073e Mon Sep 17 00:00:00 2001 From: "Marcus R. Brown" Date: Mon, 28 Oct 2024 13:32:08 -0700 Subject: [PATCH] feat!(prettier-plugins): clean up type definitions and package exports (#542) --- .changeset/rude-seas-retire.md | 7 +++ packages/prettier-plugins/package.json | 8 ++-- packages/prettier-plugins/src/index.ts | 3 -- packages/prettier-plugins/src/package-json.ts | 47 +++++++++++-------- .../types/prettier/index.d.ts | 5 -- pnpm-lock.yaml | 3 ++ 6 files changed, 42 insertions(+), 31 deletions(-) create mode 100644 .changeset/rude-seas-retire.md delete mode 100644 packages/prettier-plugins/src/index.ts delete mode 100644 packages/prettier-plugins/types/prettier/index.d.ts diff --git a/.changeset/rude-seas-retire.md b/.changeset/rude-seas-retire.md new file mode 100644 index 00000000..14d3f6f4 --- /dev/null +++ b/.changeset/rude-seas-retire.md @@ -0,0 +1,7 @@ +--- +"@bfra.me/prettier-plugins": minor +"@bfra.me/prettier-config": patch +--- + +Clean up type definitions and package exports. + \ No newline at end of file diff --git a/packages/prettier-plugins/package.json b/packages/prettier-plugins/package.json index 0ed90d1d..16798931 100644 --- a/packages/prettier-plugins/package.json +++ b/packages/prettier-plugins/package.json @@ -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", @@ -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": { @@ -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" diff --git a/packages/prettier-plugins/src/index.ts b/packages/prettier-plugins/src/index.ts deleted file mode 100644 index 10e0ae77..00000000 --- a/packages/prettier-plugins/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import * as PluginPackageJson from './package-json.js' - -export {PluginPackageJson} diff --git a/packages/prettier-plugins/src/package-json.ts b/packages/prettier-plugins/src/package-json.ts index 49ce8a46..d451f8a5 100644 --- a/packages/prettier-plugins/src/package-json.ts +++ b/packages/prettier-plugins/src/package-json.ts @@ -1,31 +1,23 @@ -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[1]> +export type SortPackageJsonOptions = NonNullable[1]> -export type PrettierPackageJsonOptions = { - /** Custom ordering array or comparator function. */ - sortPackageJsonSortOrder?: SortPackageJsonOptions['sortOrder'] +export interface PrettierPackageJsonOptions { + /** Custom ordering array. */ + sortPackageJsonSortOrder: Extract, string[]> } -export type ParserOptions = PrettierParserOptions & 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[]}], @@ -33,9 +25,16 @@ const options: SupportOptions = { }, } +export interface ParserOptions + extends prettier.ParserOptions, + Partial {} + +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 = { +export const parsers: Partial = { 'json-stringify': { ...parser, @@ -61,4 +60,12 @@ const parsers: Partial = { }, } -export {languages, options, parsers} +export interface PrettierPackageJsonPlugin extends prettier.Plugin {} + +export const pluginPackageJson: PrettierPackageJsonPlugin = { + languages, + options, + parsers, +} as prettier.Plugin + +export default pluginPackageJson diff --git a/packages/prettier-plugins/types/prettier/index.d.ts b/packages/prettier-plugins/types/prettier/index.d.ts deleted file mode 100644 index 430169c4..00000000 --- a/packages/prettier-plugins/types/prettier/index.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type {SupportLanguage} from 'prettier' - -declare module 'prettier/plugins/estree' { - export const languages: SupportLanguage[] -} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f04d8f14..b801de36 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -298,6 +298,9 @@ importers: tsup: specifier: 8.3.4 version: 8.3.4(@microsoft/api-extractor@7.47.11(@types/node@20.17.1))(@swc/core@1.7.39)(jiti@2.3.3)(postcss@8.4.47)(tsx@4.19.1)(typescript@5.6.3) + type-fest: + specifier: 4.26.1 + version: 4.26.1 packages/semantic-release: devDependencies: