Skip to content

Commit

Permalink
refactor: clean up project setup (#51)
Browse files Browse the repository at this point in the history
* build: lock pnpm version via package.json#packageManager

* deps: update SDK dependencies

* build: update gitignore

* build: add clean, typecheck npm scripts

* build: simplify tsconfig and typecheck all files

* refactor: fix typechecking errors

* refactor: remove unused type

* refactor: add eslint setup

* refactor: fix lint issues

This is a mix of stylistic fixes and fixes for some real issues (e.g.
missing `await`s), so I guess it's not really a refactor, but whatever.

* refactor: fix unnecessary `* as` imports

* ci: add CI workflow

* refactor: suppress deprecated warnings
  • Loading branch information
ndhoule authored Oct 11, 2024
1 parent 9cb2744 commit 34d03a2
Show file tree
Hide file tree
Showing 15 changed files with 1,902 additions and 405 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: Build and test

on:
pull_request:

jobs:
build_and_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
if: "${{ steps.extract_branch.outputs.branch != 'release-please--branches--main' }}"
with:
node-version: 18.19.0

- uses: pnpm/action-setup@v3

- name: Install dependencies
run: pnpm install

- name: Lint
run: pnpm run lint

- name: Typecheck
run: pnpm run typecheck

- name: Run tests
run: pnpm run test

- name: Build
run: pnpm run build
13 changes: 9 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Local Netlify folder
.netlify
node_modules
.ntli
*.tsbuildinfo
.DS_Store
.cache/
.eslintcache
.netlify/
.ntli/
.vscode/
dev-model.gql
node_modules/
75 changes: 75 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// @ts-check
import js from "@eslint/js";
import gitignore from "eslint-config-flat-gitignore";
import prettierRecommended from "eslint-plugin-prettier/recommended";
import vitest from "@vitest/eslint-plugin";
import globals from "globals";
import path from "node:path";
import { fileURLToPath } from "node:url";
import ts from "typescript-eslint";
import tailwind from "eslint-plugin-tailwindcss";

export default ts.config(
gitignore(),
js.configs.recommended,
...ts.configs.strictTypeChecked,
...ts.configs.stylisticTypeChecked,
...tailwind.configs["flat/recommended"],

{
languageOptions: {
globals: globals.node,
parserOptions: {
project: "tsconfig.*.json",
tsconfigRootDir: path.dirname(fileURLToPath(import.meta.url)),
projectService: true,
},
},
linterOptions: {
reportUnusedDisableDirectives: true,
},
},
{
files: ["**/*.?(c|m)[j]s?(x)"],
...ts.configs.disableTypeChecked,
},

// Global overrides
{
files: ["**/*.?(c|m)[t]s?(x)"],
rules: {
// Both interface and type are useful in different ways
"@typescript-eslint/consistent-type-definitions": "off",
// Empty functions are often useful and shouldn't require adding a comment
"@typescript-eslint/no-empty-function": "off",
// Default settings interfere with react-hook-form's form `onSubmit` handler
// https://github.com/orgs/react-hook-form/discussions/8622
"@typescript-eslint/no-misused-promises": [
"error",
{ checksVoidReturn: { attributes: false } },
],
// Allow TypeScript/tsc-style underscore-prefixed unused variables
"@typescript-eslint/no-unused-vars": [
"error",
{
args: "all",
argsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
ignoreRestSiblings: true,
},
],
"@typescript-eslint/switch-exhaustiveness-check": "error",
},
},

// Tests
{
files: [`src/**/*.test.?(c|m)[jt]s?(x)`],
plugins: { vitest },
rules: vitest.configs.recommended.rules,
},

// Must be last
prettierRecommended,
);
29 changes: 24 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,54 @@
"version": "0.0.1",
"main": "src/index.ts",
"type": "module",
"packageManager": "[email protected]+sha512.e5a7e52a4183a02d5931057f7a0dbff9d5e9ce3161e33fa68ae392125b79282a8a8a470a51dfc8a0ed86221442eb2fb57019b0990ed24fab519bf0e1bc5ccfc4",
"scripts": {
"build": "netlify-extension build",
"dev": "netlify-extension dev --open"
"clean": "rm -rf .netlify/ .ntli/ node_modules/.vite *.tsbuildinfo",
"dev": "netlify-extension dev",
"lint": "eslint --cache",
"lint:fix": "eslint --cache --fix",
"test": "echo 'No tests, exiting.'",
"typecheck": "tsc --build",
"typecheck:watch": "tsc --build --watch"
},
"dependencies": {
"@netlify/build": "^29.54.2",
"@netlify/functions": "^2.8.1",
"@netlify/plugin-csp-nonce": "^1.2.9",
"@netlify/sdk": "^2.3.0",
"@netlify/sdk": "^2.4.4",
"@tanstack/react-query": "^5.55.4",
"@trpc/client": "11.0.0-rc.477",
"@trpc/react-query": "11.0.0-rc.477",
"@trpc/server": "11.0.0-rc.477",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"typescript": "^5.1.6",
"zod": "^3.23.8"
},
"devDependencies": {
"@netlify/netlify-plugin-netlify-extension": "^1.0.0",
"@netlify/netlify-plugin-netlify-extension": "^1.0.3",
"@tsconfig/node18": "^18.2.4",
"@tsconfig/recommended": "^1.0.7",
"@tsconfig/strictest": "^2.0.5",
"@tsconfig/vite-react": "^3.0.2",
"@types/eslint-plugin-tailwindcss": "^3.17.0",
"@types/eslint__js": "^8.42.3",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"@vitest/eslint-plugin": "^1.1.7",
"autoprefixer": "^10.4.20",
"netlify-cli": "^17.35.0",
"eslint": "^9.11.0",
"eslint-config-flat-gitignore": "^0.3.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-tailwindcss": "^3.17.4",
"globals": "^15.11.0",
"netlify-cli": "^17.36.2",
"prettier": "3.3.3",
"tailwindcss": "^3.4.10",
"typescript": "^5.5.4",
"typescript-eslint": "^8.7.0",
"vite": "^5.4.3"
}
}
Loading

0 comments on commit 34d03a2

Please sign in to comment.