Skip to content

Commit

Permalink
Merge branch 'main' into feat/works/add-eslint-config
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusrbrown committed Sep 28, 2024
2 parents 30c2570 + d514086 commit 9b23446
Show file tree
Hide file tree
Showing 26 changed files with 454 additions and 217 deletions.
37 changes: 25 additions & 12 deletions .github/actions/pnpm-install/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,38 @@ description: Setup pnpm and install dependencies
runs:
using: 'composite'
steps:
- id: pnpm-config
name: Expose pnpm config(s) through "$GITHUB_OUTPUT"
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
shell: 'bash -Eeuo pipefail {0}'
- name: Setup pnpm
uses: pnpm/action-setup@ac5bf11548bf5e19b8aadb8182072616590fa4a6
with:
run_install: false

- name: Setup Node.js
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
node-version-file: '.node-version'

- id: cache-rotation
name: Cache rotation keys
- id: cache-config
name: Configure cache
run: |
echo "YEAR_MONTH=$(/bin/date -u "+%Y%m")" >> $GITHUB_OUTPUT
pnpm_store_path="$(pnpm store path --silent)"
if [ -z "pnpm_store_path" ]; then
echo "Failed to get pnpm store path"
exit 1
fi
mkdir -p "pnpm_store_path" || exit 1
echo "path=$pnpm_store_path" >> $GITHUB_OUTPUT
year_month=$(date -u '+%Y%m')
base_key="${{ runner.os }}-pnpm-cache-v${year_month}"
echo "key=${base_key}-${{ hashFiles('**/pnpm-lock.yaml') }}" >> $GITHUB_OUTPUT
echo "restore-keys=${base_key}-" >> $GITHUB_OUTPUT
shell: 'bash -Eeuo pipefail {0}'

- name: Setup pnpm cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ${{ steps.pnpm-config.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-
key: ${{ steps.cache-config.outputs.key }}
path: ${{ steps.cache-config.outputs.path }}
restore-keys: ${{ steps.cache-config.outputs.restore-keys }}

- name: Bootstrap monorepo
env:
Expand Down
19 changes: 0 additions & 19 deletions .github/actions/prepare/action.yaml

This file was deleted.

7 changes: 4 additions & 3 deletions .github/workflows/cache-cleanup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ name: Cache Cleanup

jobs:
cleanup:
name: Cleanup cache
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Checkout repository
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- id: cache-info
name: Get branch name and cache keys
Expand All @@ -32,7 +33,7 @@ jobs:
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
if [ -n "$BRANCH" ]; then
# Get cache keys that don't include the branch's SHA (if not a PR)
gh actions-cache list -R ${{ github.repository }} -B $BRANCH --order asc --sort last-use | cut -f 1 > cache-keys.txt
gh actions-cache list -R ${{ github.repository }} -B $BRANCH --order asc --sort last-used | cut -f 1 > cache-keys.txt
[ -z "${{ github.event.pull_request }}" ] && grep -v ${{ github.sha }} cache-keys.txt > cache-keys.txt.tmp && mv cache-keys.txt.tmp cache-keys.txt
echo cache-keys="$(cat cache-keys.txt | tr '\n' ' ')" >> $GITHUB_OUTPUT
fi
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: Prepare job
uses: ./.github/actions/prepare
uses: ./.github/actions/pnpm-install

- name: Check formatting
run: pnpm run check-format
Expand Down Expand Up @@ -64,13 +64,13 @@ jobs:
git config --global user.name 'bfra-me[bot]'
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
with:
fetch-depth: 0
token: ${{ steps.get-workflow-access-token.outputs.token }}

- name: Prepare job
uses: ./.github/actions/prepare
uses: ./.github/actions/pnpm-install

- name: Perform a dry run of `pnpm publish`
run: pnpm -r publish --dry-run
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@changesets/cli": "2.27.7",
"@eslint/config-inspector": "0.5.4",
"@manypkg/cli": "0.21.4",
"@microsoft/api-extractor": "7.47.9",
"@swisspost/design-system-changelog-github": "1.0.2",
"@types/node": "20.16.1",
"eslint": "9.11.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/prettier-config/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
*.d.ts
*.js
test/_fixtures
4 changes: 1 addition & 3 deletions packages/prettier-config/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
!*.d.ts
!*.js
test/fixtures/**
test/fixtures/
9 changes: 9 additions & 0 deletions packages/prettier-config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @bfra.me/prettier-config

## 0.7.3
### Patch Changes



- Refactor and add `languages` to the `package-json` plugin; improve types (by [@marcusrbrown](https://github.com/marcusrbrown) with [#407](https://github.com/bfra-me/works/pull/407))
- Updated dependencies:
- @bfra.me/prettier-plugins@0.4.0

## 0.7.2
### Patch Changes

Expand Down
27 changes: 13 additions & 14 deletions packages/prettier-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bfra.me/prettier-config",
"version": "0.7.2",
"version": "0.7.3",
"description": "Shared Prettier configuration for bfra.me",
"keywords": [
"bfra.me",
Expand All @@ -22,27 +22,26 @@
"type": "module",
"exports": {
".": {
"types": "./prettier.config.d.ts",
"import": "./prettier.config.js"
"types": "./lib/prettier.config.d.ts",
"import": "./lib/prettier.config.js"
},
"./100-proof": "./prettier.config.js",
"./120-proof": "./120-proof.js",
"./semi/*": "./*.js?semi=true",
"./semi": "./prettier.config.js?semi=true",
"./*/semi": "./*.js?semi=true",
"./100-proof": "./lib/prettier.config.js",
"./120-proof": "./lib/120-proof.js",
"./semi/*": "./lib/*.js?semi=true",
"./semi": "./lib/prettier.config.js?semi=true",
"./*/semi": "./lib/*.js?semi=true",
"./package.json": "./package.json"
},
"main": "prettier.config.js",
"types": "prettier.config.d.ts",
"main": "./lib/prettier.config.js",
"types": "./lib/prettier.config.d.ts",
"files": [
"*.js",
"*.ts",
"lib",
"src",
"!**/*.map",
"!tsup.config.ts"
],
"scripts": {
"build": "tsup && pnpm run format",
"format": "prettier --ignore-path .prettierignore --log-level log --write .",
"build": "tsup",
"test": "vitest"
},
"dependencies": {
Expand Down
26 changes: 0 additions & 26 deletions packages/prettier-config/plugins.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import prettierConfig from '@bfra.me/prettier-config'
import prettierConfig from './prettier.config.js'
import type {Config} from 'prettier'

const {searchParams: params} = new URL(import.meta.url)
Expand Down
17 changes: 17 additions & 0 deletions packages/prettier-config/src/plugins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type {Plugin} from 'prettier'
import * as PluginPackageJson from '@bfra.me/prettier-plugins/package-json'

const resolvedPlugins: Record<string, Plugin> = {
'@bfra.me/prettier-plugins/package-json': PluginPackageJson,
}

export const resolve = (resolver: (id: string) => string, plugin: string): string | Plugin => {
try {
if (resolvedPlugins[plugin]) {
return resolvedPlugins[plugin]
}
return resolver(plugin)
} finally {
return plugin
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const config: Config = {
'**/.next/**',
'**/.nuxt/**',
'**/.output/**',
'**/.tsup/**',
'**/.vercel/**',
'**/.vitepress/cache/**',
'**/.vite-inspect/**',
Expand Down
7 changes: 3 additions & 4 deletions packages/prettier-config/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": ".",
"rootDir": ".",
"sourceMap": false
"outDir": "./lib",
"rootDir": "./src"
},
"include": ["./*.ts"]
"include": ["./src/**/*.ts"]
}
6 changes: 4 additions & 2 deletions packages/prettier-config/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import {defineConfig} from 'tsup'

export default defineConfig({
bundle: false,
clean: true,
dts: true,
entry: ['prettier.config.ts', '120-proof.ts', 'plugins.ts'],
entry: ['./src/*.ts'],
format: ['esm'],
outDir: '.',
outDir: 'lib',
sourcemap: true,
// Splitting can place code using `import.meta` into a separate chunk, which breaks the preset export mappings.
splitting: false,
})
7 changes: 7 additions & 0 deletions packages/prettier-plugins/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @bfra.me/prettier-plugins

## 0.4.0
### Minor Changes



- Refactor and add `languages` to the `package-json` plugin; improve types (by [@marcusrbrown](https://github.com/marcusrbrown) with [#407](https://github.com/bfra-me/works/pull/407))

## 0.3.1
### Patch Changes

Expand Down
2 changes: 1 addition & 1 deletion packages/prettier-plugins/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bfra.me/prettier-plugins",
"version": "0.3.1",
"version": "0.4.0",
"description": "Plugins for Prettier used across bfra.me.",
"keywords": [
"bfra.me",
Expand Down
4 changes: 3 additions & 1 deletion packages/prettier-plugins/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './package-json.js'
import * as PluginPackageJson from './package-json.js'

export {PluginPackageJson}
34 changes: 20 additions & 14 deletions packages/prettier-plugins/src/package-json.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
import type {Parser, ParserOptions, Plugin, SupportOption} from 'prettier'
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 {sortPackageJson} from 'sort-package-json'

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

export type PrettierPackageJsonOptions = {
/** Custom ordering array or comparator function. */
sortPackageJsonSortOrder?: SortPackageJsonOptions['sortOrder']
}

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

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

export type SupportOptions = PrettierSupportOptions & {
[_ in keyof PrettierPackageJsonOptions]: SupportOption
}

const options: SupportOptions = {
sortPackageJsonSortOrder: {
category: 'Format',
category: 'JavaScript',
type: 'string',
description: 'Custom ordering array.',
default: [{value: [] as string[]}],
array: true,
},
} satisfies Record<keyof PrettierPackageJsonOptions, SupportOption>
}

const parser = babelParsers['json-stringify']

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

async parse(text: string, options: PrettierOptions) {
async parse(text: string, options: ParserOptions) {
const {filepath} = options
if (/package.*json$/u.test(filepath)) {
// Format the text with prettier to avoid any parsing errors
Expand All @@ -48,11 +59,6 @@ export const parsers = {
return parser.parse(text, options)
},
},
} satisfies Record<string, Parser>

const PackageJsonPlugin: Plugin<string> = {
parsers,
options,
}

export default PackageJsonPlugin
export {languages, options, parsers}
3 changes: 2 additions & 1 deletion packages/prettier-plugins/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib",
"rootDir": "./src"
"rootDir": "./src",
"typeRoots": ["./types", "./node_modules/@types"]
},
"include": ["./src/**/*.ts"]
}
Loading

0 comments on commit 9b23446

Please sign in to comment.