From 29970faeea6ee081cd1d8fef37d3cebee3b6bd57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gr=C3=B8ngaard?= Date: Wed, 22 May 2024 17:03:00 +0200 Subject: [PATCH] chore: improve prettier setup (#169) - We now use the shared `@sanity/prettier-config` - All files are formatted - Astro files as well --- .github/workflows/lock.yml | 2 +- .github/workflows/prettier.yml | 4 +- .github/workflows/release-please.yml | 2 +- .prettierer.cjs | 9 + .prettierignore | 1 + apps/example-ssr/astro.config.mjs | 16 +- apps/example-ssr/src/components/NewsBar.jsx | 2 +- apps/example-ssr/tsconfig.json | 2 +- apps/example/astro.config.mjs | 4 +- apps/example/src/components/NewsBar.jsx | 2 +- apps/example/tsconfig.json | 2 +- package-lock.json | 220 +++++++++++++++++++- package.json | 4 +- turbo.json | 9 +- 14 files changed, 256 insertions(+), 23 deletions(-) create mode 100644 .prettierer.cjs diff --git a/.github/workflows/lock.yml b/.github/workflows/lock.yml index 049054e8..ca08914d 100644 --- a/.github/workflows/lock.yml +++ b/.github/workflows/lock.yml @@ -7,7 +7,7 @@ on: pull_request: types: [closed] schedule: - - cron: '0 0 * * *' + - cron: "0 0 * * *" workflow_dispatch: permissions: diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml index 9eb400c1..d74608e3 100644 --- a/.github/workflows/prettier.yml +++ b/.github/workflows/prettier.yml @@ -38,7 +38,7 @@ jobs: author: github-actions <41898282+github-actions[bot]@users.noreply.github.com> body: I ran `npm run format` 🧑‍💻 branch: actions/prettier - commit-message: 'chore(prettier): 🤖 ✨' + commit-message: "chore(prettier): 🤖 ✨" labels: 🤖 bot - title: 'chore(prettier): 🤖 ✨' + title: "chore(prettier): 🤖 ✨" token: ${{ steps.generate-token.outputs.token }} diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 3dd7efe6..6b2b9f48 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -37,7 +37,7 @@ jobs: with: cache: npm node-version: lts/* - registry-url: 'https://registry.npmjs.org' + registry-url: "https://registry.npmjs.org" - run: corepack enable && npm --version && npm ci --ignore-scripts && npm audit signatures if: ${{ steps.release.outputs.releases_created }} # Release Please has already incremented versions and published tags, so we just diff --git a/.prettierer.cjs b/.prettierer.cjs new file mode 100644 index 00000000..2d6197b9 --- /dev/null +++ b/.prettierer.cjs @@ -0,0 +1,9 @@ +const preset = require("@sanity/prettier-config"); + +/** @type {import("prettier").Config} */ +const config = { + ...preset, + plugins: [...preset.plugins, "prettier-plugin-astro"], +}; + +module.exports = config; diff --git a/.prettierignore b/.prettierignore index 1b763b1b..a3414d0f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1 +1,2 @@ +dist CHANGELOG.md diff --git a/apps/example-ssr/astro.config.mjs b/apps/example-ssr/astro.config.mjs index 3ce8bd08..d41a62e9 100644 --- a/apps/example-ssr/astro.config.mjs +++ b/apps/example-ssr/astro.config.mjs @@ -1,22 +1,22 @@ -import sanity from '@sanity/astro' -import { defineConfig } from 'astro/config' -import vercel from '@astrojs/vercel/serverless'; -import react from '@astrojs/react'; +import sanity from "@sanity/astro"; +import { defineConfig } from "astro/config"; +import vercel from "@astrojs/vercel/serverless"; +import react from "@astrojs/react"; // https://astro.build/config export default defineConfig({ integrations: [ sanity({ - projectId: '3do82whm', - dataset: 'next', + projectId: "3do82whm", + dataset: "next", // If you are doing static builds you may want opt out of the CDN useCdn: true, studioBasePath: "/admin", }), react(), ], - output: 'server', + output: "server", adapter: vercel({ edgeMiddleware: true, }), -}) +}); diff --git a/apps/example-ssr/src/components/NewsBar.jsx b/apps/example-ssr/src/components/NewsBar.jsx index c8a190f6..3629fdc9 100644 --- a/apps/example-ssr/src/components/NewsBar.jsx +++ b/apps/example-ssr/src/components/NewsBar.jsx @@ -9,7 +9,7 @@ export function NewsBar() { const [news, setNews] = useState({ message: "Loading news…" }); const getNews = useCallback(async () => { const response = await sanityClient.fetch( - `*[_type == "sanityIoSettings"][0].banner` + `*[_type == "sanityIoSettings"][0].banner`, ); setNews(response || { message: "no news" }); }, [sanityClient]); diff --git a/apps/example-ssr/tsconfig.json b/apps/example-ssr/tsconfig.json index 77da9dd0..bcbf8b50 100644 --- a/apps/example-ssr/tsconfig.json +++ b/apps/example-ssr/tsconfig.json @@ -1,3 +1,3 @@ { "extends": "astro/tsconfigs/strict" -} \ No newline at end of file +} diff --git a/apps/example/astro.config.mjs b/apps/example/astro.config.mjs index 7cdcef5c..09c0082e 100644 --- a/apps/example/astro.config.mjs +++ b/apps/example/astro.config.mjs @@ -1,6 +1,6 @@ import sanity from "@sanity/astro"; import { defineConfig } from "astro/config"; -import react from '@astrojs/react'; +import react from "@astrojs/react"; // https://astro.build/config export default defineConfig({ @@ -12,6 +12,6 @@ export default defineConfig({ useCdn: false, studioBasePath: "/admin", }), - react() + react(), ], }); diff --git a/apps/example/src/components/NewsBar.jsx b/apps/example/src/components/NewsBar.jsx index c8a190f6..3629fdc9 100644 --- a/apps/example/src/components/NewsBar.jsx +++ b/apps/example/src/components/NewsBar.jsx @@ -9,7 +9,7 @@ export function NewsBar() { const [news, setNews] = useState({ message: "Loading news…" }); const getNews = useCallback(async () => { const response = await sanityClient.fetch( - `*[_type == "sanityIoSettings"][0].banner` + `*[_type == "sanityIoSettings"][0].banner`, ); setNews(response || { message: "no news" }); }, [sanityClient]); diff --git a/apps/example/tsconfig.json b/apps/example/tsconfig.json index 77da9dd0..bcbf8b50 100644 --- a/apps/example/tsconfig.json +++ b/apps/example/tsconfig.json @@ -1,3 +1,3 @@ { "extends": "astro/tsconfigs/strict" -} \ No newline at end of file +} diff --git a/package-lock.json b/package-lock.json index 3eed913b..9e40cfc5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,11 +10,13 @@ "apps/*" ], "devDependencies": { + "@sanity/prettier-config": "^1.0.2", "@turbo/gen": "^1.10.16", "eslint": "^8.52.0", "eslint-config-custom": "*", "prettier": "^3.0.3", "rimraf": "^5.0.7", + "prettier-plugin-astro": "^0.13.0", "turbo": "^1.10.16" } }, @@ -4912,6 +4914,18 @@ "node": ">=14" } }, + "node_modules/@pkgr/core": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz", + "integrity": "sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==", + "dev": true, + "engines": { + "node": "^12.20.0 || ^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, "node_modules/@portabletext/toolkit": { "version": "2.0.10", "resolved": "https://registry.npmjs.org/@portabletext/toolkit/-/toolkit-2.0.10.tgz", @@ -5641,6 +5655,18 @@ "ms": "^2.1.1" } }, + "node_modules/@sanity/prettier-config": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@sanity/prettier-config/-/prettier-config-1.0.2.tgz", + "integrity": "sha512-V4HinfhMYxQoyXefJ2B8zJnwlf7A8mVzAzKk24B/iCg4pkVlMGc8bj0buu9Uieh4bNeHvEAHOIQv+Xd7tiLuNA==", + "dev": true, + "dependencies": { + "prettier-plugin-packagejson": "^2.5.0" + }, + "peerDependencies": { + "prettier": "^3.2.5" + } + }, "node_modules/@sanity/schema": { "version": "3.16.7", "resolved": "https://registry.npmjs.org/@sanity/schema/-/schema-3.16.7.tgz", @@ -9230,6 +9256,15 @@ "node": ">=6" } }, + "node_modules/detect-indent": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-7.0.1.tgz", + "integrity": "sha512-Mc7QhQ8s+cLrnUfU/Ji94vG/r8M26m8f++vyres4ZoojaRDpZ1eSIh/EpzLNwlWuvzSZ3UbDFspjFvTDXe6e/g==", + "dev": true, + "engines": { + "node": ">=12.20" + } + }, "node_modules/detect-libc": { "version": "2.0.2", "license": "Apache-2.0", @@ -9237,6 +9272,18 @@ "node": ">=8" } }, + "node_modules/detect-newline": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-4.0.1.tgz", + "integrity": "sha512-qE3Veg1YXzGHQhlA6jzebZN2qVf6NX+A7m7qlhCGG30dJixrAQhYOsJjsnBjJkCSmuOPpCk30145fr8FV0bzog==", + "dev": true, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/detect-node-es": { "version": "1.1.0", "license": "MIT" @@ -10927,6 +10974,18 @@ "get-random-values": "^1.2.2" } }, + "node_modules/get-stdin": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-9.0.0.tgz", + "integrity": "sha512-dVKBjfWisLAicarI2Sf+JuBE/DghV4UzNAVe9yhEJuzeREd3JhOTE9cUaJTeSa77fsbQUK3pcOpJfM59+VKZaA==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/get-stream": { "version": "6.0.1", "dev": true, @@ -10997,6 +11056,15 @@ "node": ">= 4.0.0" } }, + "node_modules/git-hooks-list": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/git-hooks-list/-/git-hooks-list-3.1.0.tgz", + "integrity": "sha512-LF8VeHeR7v+wAbXqfgRlTSX/1BJR9Q1vEMR8JAz1cEg6GX07+zyj3sAdDvYjj/xnlIfVuGgj4qBei1K3hKH+PA==", + "dev": true, + "funding": { + "url": "https://github.com/fisker/git-hooks-list?sponsor=1" + } + }, "node_modules/github-from-package": { "version": "0.0.0", "license": "MIT", @@ -16540,9 +16608,9 @@ } }, "node_modules/prettier": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", - "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz", + "integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==", "dev": true, "bin": { "prettier": "bin/prettier.cjs" @@ -16554,6 +16622,44 @@ "url": "https://github.com/prettier/prettier?sponsor=1" } }, + "node_modules/prettier-plugin-astro": { + "version": "0.13.0", + "resolved": "https://registry.npmjs.org/prettier-plugin-astro/-/prettier-plugin-astro-0.13.0.tgz", + "integrity": "sha512-5HrJNnPmZqTUNoA97zn4gNQv9BgVhv+et03314WpQ9H9N8m2L9OSV798olwmG2YLXPl1iSstlJCR1zB3x5xG4g==", + "dev": true, + "dependencies": { + "@astrojs/compiler": "^1.5.5", + "prettier": "^3.0.0", + "sass-formatter": "^0.7.6" + }, + "engines": { + "node": "^14.15.0 || >=16.0.0" + } + }, + "node_modules/prettier-plugin-astro/node_modules/@astrojs/compiler": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/@astrojs/compiler/-/compiler-1.8.2.tgz", + "integrity": "sha512-o/ObKgtMzl8SlpIdzaxFnt7SATKPxu4oIP/1NL+HDJRzxfJcAkOTAb/ZKMRyULbz4q+1t2/DAebs2Z1QairkZw==", + "dev": true + }, + "node_modules/prettier-plugin-packagejson": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/prettier-plugin-packagejson/-/prettier-plugin-packagejson-2.5.0.tgz", + "integrity": "sha512-6XkH3rpin5QEQodBSVNg+rBo4r91g/1mCaRwS1YGdQJZ6jwqrg2UchBsIG9tpS1yK1kNBvOt84OILsX8uHzBGg==", + "dev": true, + "dependencies": { + "sort-package-json": "2.10.0", + "synckit": "0.9.0" + }, + "peerDependencies": { + "prettier": ">= 1.16.0" + }, + "peerDependenciesMeta": { + "prettier": { + "optional": true + } + } + }, "node_modules/pretty-ms": { "version": "7.0.1", "license": "MIT", @@ -18249,6 +18355,12 @@ "rxjs": "7.x" } }, + "node_modules/s.color": { + "version": "0.0.15", + "resolved": "https://registry.npmjs.org/s.color/-/s.color-0.0.15.tgz", + "integrity": "sha512-AUNrbEUHeKY8XsYr/DYpl+qk5+aM+DChopnWOPEzn8YKzOhv4l2zH6LzZms3tOZP3wwdOyc0RmTciyi46HLIuA==", + "dev": true + }, "node_modules/sade": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/sade/-/sade-1.8.1.tgz", @@ -18621,6 +18733,15 @@ "node": ">=8" } }, + "node_modules/sass-formatter": { + "version": "0.7.9", + "resolved": "https://registry.npmjs.org/sass-formatter/-/sass-formatter-0.7.9.tgz", + "integrity": "sha512-CWZ8XiSim+fJVG0cFLStwDvft1VI7uvXdCNJYXhDvowiv+DsbD1nXLiQ4zrE5UBvj5DWZJ93cwN0NX5PMsr1Pw==", + "dev": true, + "dependencies": { + "suf-log": "^2.5.3" + } + }, "node_modules/sax": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/sax/-/sax-1.3.0.tgz", @@ -19385,6 +19506,74 @@ "dev": true, "license": "MIT" }, + "node_modules/sort-object-keys": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/sort-object-keys/-/sort-object-keys-1.1.3.tgz", + "integrity": "sha512-855pvK+VkU7PaKYPc+Jjnmt4EzejQHyhhF33q31qG8x7maDzkeFhAAThdCYay11CISO+qAMwjOBP+fPZe0IPyg==", + "dev": true + }, + "node_modules/sort-package-json": { + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/sort-package-json/-/sort-package-json-2.10.0.tgz", + "integrity": "sha512-MYecfvObMwJjjJskhxYfuOADkXp1ZMMnCFC8yhp+9HDsk7HhR336hd7eiBs96lTXfiqmUNI+WQCeCMRBhl251g==", + "dev": true, + "dependencies": { + "detect-indent": "^7.0.1", + "detect-newline": "^4.0.0", + "get-stdin": "^9.0.0", + "git-hooks-list": "^3.0.0", + "globby": "^13.1.2", + "is-plain-obj": "^4.1.0", + "semver": "^7.6.0", + "sort-object-keys": "^1.1.3" + }, + "bin": { + "sort-package-json": "cli.js" + } + }, + "node_modules/sort-package-json/node_modules/globby": { + "version": "13.2.2", + "resolved": "https://registry.npmjs.org/globby/-/globby-13.2.2.tgz", + "integrity": "sha512-Y1zNGV+pzQdh7H39l9zgB4PJqjRNqydvdYCDG4HFXM4XuvSaQQlEc91IU1yALL8gUTDomgBAfz3XJdmUS+oo0w==", + "dev": true, + "dependencies": { + "dir-glob": "^3.0.1", + "fast-glob": "^3.3.0", + "ignore": "^5.2.4", + "merge2": "^1.4.1", + "slash": "^4.0.0" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/sort-package-json/node_modules/semver": { + "version": "7.6.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", + "integrity": "sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/sort-package-json/node_modules/slash": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-4.0.0.tgz", + "integrity": "sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/source-map": { "version": "0.6.1", "devOptional": true, @@ -19835,6 +20024,15 @@ "resolved": "https://registry.npmjs.org/stylis/-/stylis-4.3.0.tgz", "integrity": "sha512-E87pIogpwUsUwXw7dNyU4QDjdgVMy52m+XEOPEKUn161cCzWjjhPSQhByfd1CcNvrOLnXQ6OnnZDwnJrz/Z4YQ==" }, + "node_modules/suf-log": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/suf-log/-/suf-log-2.5.3.tgz", + "integrity": "sha512-KvC8OPjzdNOe+xQ4XWJV2whQA0aM1kGVczMQ8+dStAO6KfEB140JEVQ9dE76ONZ0/Ylf67ni4tILPJB41U0eow==", + "dev": true, + "dependencies": { + "s.color": "0.0.15" + } + }, "node_modules/supports-color": { "version": "5.5.0", "license": "MIT", @@ -19868,6 +20066,22 @@ "version": "3.2.4", "license": "MIT" }, + "node_modules/synckit": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.9.0.tgz", + "integrity": "sha512-7RnqIMq572L8PeEzKeBINYEJDDxpcH8JEgLwUqBd3TkofhFRbkq4QLR0u+36avGAhCRbk2nnmjcW9SE531hPDg==", + "dev": true, + "dependencies": { + "@pkgr/core": "^0.1.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, "node_modules/tar": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/tar/-/tar-6.2.0.tgz", diff --git a/package.json b/package.json index b6397f0f..90176c29 100644 --- a/package.json +++ b/package.json @@ -5,14 +5,16 @@ "build": "turbo run build", "dev": "turbo run dev", "lint": "turbo run lint", - "format": "prettier --write \"**/*.{ts,tsx,md}\"" + "format": "prettier --write ." }, "devDependencies": { + "@sanity/prettier-config": "^1.0.2", "@turbo/gen": "^1.10.16", "eslint": "^8.52.0", "eslint-config-custom": "*", "prettier": "^3.0.3", "rimraf": "^5.0.7", + "prettier-plugin-astro": "^0.13.0", "turbo": "^1.10.16" }, "name": "astro", diff --git a/turbo.json b/turbo.json index 067d3f46..9a6d9b47 100644 --- a/turbo.json +++ b/turbo.json @@ -7,7 +7,14 @@ }, "build": { "dependsOn": ["^build"], - "outputs": ["dist/**", ".next/**", "!.next/cache/**", "build/**", "public/**", ".vercel/output/**"] + "outputs": [ + "dist/**", + ".next/**", + "!.next/cache/**", + "build/**", + "public/**", + ".vercel/output/**" + ] }, "lint": {}, "dev": {