Skip to content

Commit

Permalink
feat!(prettier-config): add index.ts; cleanup config (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusrbrown authored Oct 28, 2024
1 parent bdf7774 commit 7a2a31f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 27 deletions.
6 changes: 6 additions & 0 deletions .changeset/twenty-bears-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@bfra.me/prettier-config": minor
---

Consolidate exports and types in `index.ts`; cleanup config.

13 changes: 6 additions & 7 deletions packages/prettier-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
"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-config"
},
"license": "MIT",
"author": "Marcus R. Brown <[email protected]>",
"type": "module",
"exports": {
".": {
"types": "./lib/prettier.config.d.ts",
"import": "./lib/prettier.config.js"
"types": "./lib/index.d.ts",
"import": "./lib/index.js"
},
"./100-proof": "./lib/prettier.config.js",
"./120-proof": "./lib/120-proof.js",
Expand All @@ -32,13 +32,12 @@
"./*/semi": "./lib/*.js?semi=true",
"./package.json": "./package.json"
},
"main": "./lib/prettier.config.js",
"types": "./lib/prettier.config.d.ts",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"files": [
"lib",
"src",
"!**/*.map",
"!tsup.config.ts"
"!**/*.map"
],
"scripts": {
"build": "tsup",
Expand Down
23 changes: 11 additions & 12 deletions packages/prettier-config/src/120-proof.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import prettierConfig from './prettier.config.js'
import type {Config} from 'prettier'

const {searchParams: params} = new URL(import.meta.url)
const preset = {
semi: params.has('semi') || prettierConfig.semi || false,
printWidth: 120,
} as const satisfies Pick<Config, 'printWidth' | 'semi'>
import defaultConfig, {type DefaultConfig} from './prettier.config.js'

/**
* Shared Prettier configuration for bfra.me projects with `printWidth` set to 120 characters.
*/
const config: Config & typeof preset = {
...prettierConfig,
...preset,
export interface $120ProofConfig extends DefaultConfig {
/** @default 120 */
printWidth: 120 | DefaultConfig['printWidth']
}

export default config
const $120ProofConfig = {
...defaultConfig,
printWidth: 120,
semi: new URL(import.meta.url).searchParams.has('semi', 'true') || defaultConfig.semi,
} as $120ProofConfig

export default $120ProofConfig
5 changes: 5 additions & 0 deletions packages/prettier-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import defaultConfig from './prettier.config.js'
export * from './120-proof.js'
export * from './prettier.config.js'

export default defaultConfig
29 changes: 22 additions & 7 deletions packages/prettier-config/src/prettier.config.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
import {resolve} from './plugins.js'
import {createRequire} from 'node:module'
import type {Config} from 'prettier'

import {createRequire} from 'module'
import {resolve} from './plugins.js'

const require = createRequire(import.meta.url)
const resolvePlugin = resolve.bind(null, require.resolve)
const {searchParams} = new URL(import.meta.url)

const {searchParams: params} = new URL(import.meta.url)
type RequiredConfig = Required<Config>

/**
* Shared Prettier configuration for bfra.me projects.
*/
const config: Config = {
export interface DefaultConfig extends Config {
/** @default avoid */
arrowParens: 'avoid' | RequiredConfig['arrowParens']
/** @default false */
bracketSpacing: false | boolean
/** @default auto */
endOfLine: 'auto' | RequiredConfig['endOfLine']
/** @default 100 */
printWidth: 100 | number
/** @default false */
semi: false | boolean
/** @default true */
singleQuote: true | boolean
}

const config = {
arrowParens: 'avoid',
bracketSpacing: false,
endOfLine: 'auto',
printWidth: 100,
semi: params.has('semi', 'true'),
semi: searchParams.has('semi', 'true'),
singleQuote: true,

overrides: [
Expand Down Expand Up @@ -81,6 +96,6 @@ const config: Config = {
],

plugins: ['@bfra.me/prettier-plugins/package-json'].map(resolvePlugin),
}
} as DefaultConfig

export default config
2 changes: 1 addition & 1 deletion packages/prettier-config/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {defineConfig} from 'tsup'
export default defineConfig({
bundle: false,
clean: true,
dts: true,
dts: 'src/index.ts',
entry: ['./src/*.ts'],
format: ['esm'],
outDir: 'lib',
Expand Down

0 comments on commit 7a2a31f

Please sign in to comment.