From 6f731eeba2c6cf3f8e8ce896e19069bc88d45557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20B=C3=B6hm?= Date: Sat, 17 Sep 2022 06:42:25 +0200 Subject: [PATCH] feat: use TypeScript for source config files (#46) Resolves #33 Switch to TypeScript to have a better code base for the future. --- .changeset/hungry-cups-relate.md | 6 +++ .github/workflows/check.yml | 37 +++++++++++++++ .github/workflows/release.yml | 3 ++ .gitignore | 5 +- .prettierignore | 6 +++ package.json | 5 +- packages/eslint-config/.eslintrc.cjs | 2 +- packages/eslint-config/index.d.ts | 4 -- packages/eslint-config/index.js | 1 - packages/eslint-config/next.js | 7 --- packages/eslint-config/package.json | 15 +++--- .../eslint-config/{base.js => src/base.ts} | 10 ++-- packages/eslint-config/src/index.ts | 1 + packages/eslint-config/src/next.ts | 7 +++ .../eslint-config/{react.js => src/react.ts} | 10 ++-- packages/eslint-config/tsconfig.json | 9 ++++ packages/prettier-config/index.cjs | 34 -------------- packages/prettier-config/index.d.ts | 4 -- packages/prettier-config/package.json | 13 +++--- packages/prettier-config/src/index.ts | 46 +++++++++++++++++++ packages/prettier-config/tsconfig.json | 9 ++++ packages/tsconfig/package.json | 2 +- pnpm-lock.yaml | 32 +++++++++++-- turbo.json | 4 ++ 24 files changed, 187 insertions(+), 85 deletions(-) create mode 100644 .changeset/hungry-cups-relate.md create mode 100644 .github/workflows/check.yml delete mode 100644 packages/eslint-config/index.d.ts delete mode 100644 packages/eslint-config/index.js delete mode 100644 packages/eslint-config/next.js rename packages/eslint-config/{base.js => src/base.ts} (93%) create mode 100644 packages/eslint-config/src/index.ts create mode 100644 packages/eslint-config/src/next.ts rename packages/eslint-config/{react.js => src/react.ts} (83%) create mode 100644 packages/eslint-config/tsconfig.json delete mode 100644 packages/prettier-config/index.cjs delete mode 100644 packages/prettier-config/index.d.ts create mode 100644 packages/prettier-config/src/index.ts create mode 100644 packages/prettier-config/tsconfig.json diff --git a/.changeset/hungry-cups-relate.md b/.changeset/hungry-cups-relate.md new file mode 100644 index 0000000..11b8472 --- /dev/null +++ b/.changeset/hungry-cups-relate.md @@ -0,0 +1,6 @@ +--- +'@mheob/eslint-config': patch +'@mheob/prettier-config': patch +--- + +Switch to typescript as source files diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..71dbbde --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,37 @@ +name: Check + +on: + pull_request: + paths: ["packages/**"] + branches: [main] + push: + paths: ["packages/**"] + branches: [main] + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v3 + + - name: Setup PNPM + uses: pnpm/action-setup@v2 + with: + version: 7 + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version-file: ".nvmrc" + cache: "pnpm" + + - name: Install Dependencies + run: pnpm install --frozen-lockfile + + - name: Build files + run: pnpm run build + + - name: Lint files + run: pnpm run lint diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d79d126..4b30d0f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,6 +32,9 @@ jobs: - name: Install Dependencies run: pnpm install --frozen-lockfile + - name: Build files + run: pnpm run build + - name: Create Release Pull Request or Publish to npm id: changesets uses: changesets/action@v1 diff --git a/.gitignore b/.gitignore index 849425f..f140a9d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,10 +8,11 @@ node_modules # testing coverage -# next.js +# builds .next/ -out/ +out build +dist # misc .DS_Store diff --git a/.prettierignore b/.prettierignore index 7c0ec99..566dfc8 100644 --- a/.prettierignore +++ b/.prettierignore @@ -9,3 +9,9 @@ coverage # turbo .turbo + +# builds +.next/ +out +build +dist diff --git a/package.json b/package.json index ad3a5df..99273f1 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "packages/*" ], "scripts": { + "build": "turbo run build", "changeset": "changeset", "clean": "turbo run clean", "clean:root": "rm -rf .turbo && rm -rf node_modules", @@ -25,7 +26,7 @@ "lint-staged": { "*.{cjs,js,jsx,ts,tsx}": "eslint --fix", "!(pnpm-)*.{cjs,js,jsx,ts,tsx,json,md,mdx,yml,yaml}": "pnpm exec prettier --write", - "**/package.json": "pnpm dlx sort-package-json" + "package.json": "pnpm dlx sort-package-json" }, "devDependencies": { "@changesets/cli": "^2.24.4", @@ -35,7 +36,7 @@ "@mheob/prettier-config": "workspace:*", "@types/node": "^18.7.18", "eslint": "^8.23.1", - "husky": "^8.0.0", + "husky": "^8.0.1", "lint-staged": "^13.0.3", "prettier": "^2.7.1", "ts-node": "^10.9.1", diff --git a/packages/eslint-config/.eslintrc.cjs b/packages/eslint-config/.eslintrc.cjs index f73db8f..5ad0310 100644 --- a/packages/eslint-config/.eslintrc.cjs +++ b/packages/eslint-config/.eslintrc.cjs @@ -1,6 +1,6 @@ /** @type {import('eslint').ESLint.ConfigData} */ module.exports = { - extends: ['./base.js'], + extends: ['./dist/base.js'], env: { node: true }, rules: { 'unicorn/prefer-module': 'off', diff --git a/packages/eslint-config/index.d.ts b/packages/eslint-config/index.d.ts deleted file mode 100644 index fa71c61..0000000 --- a/packages/eslint-config/index.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import type { ESLint } from 'ESLint'; - -declare const config: ESLint.ConfigData; -export default config; diff --git a/packages/eslint-config/index.js b/packages/eslint-config/index.js deleted file mode 100644 index 5931c88..0000000 --- a/packages/eslint-config/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./base'); diff --git a/packages/eslint-config/next.js b/packages/eslint-config/next.js deleted file mode 100644 index 2825edd..0000000 --- a/packages/eslint-config/next.js +++ /dev/null @@ -1,7 +0,0 @@ -/** - * NextJS specific ESLint rules - * @type {import('eslint').ESLint.ConfigData} - */ -module.exports = { - extends: ['./react', 'next/core-web-vitals'], -}; diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json index 490faee..6a4f744 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -10,22 +10,19 @@ "bugs": "https://github.com/mheob/config/issues", "repository": { "type": "git", - "url": "https://github.com/mheob/config.git" + "url": "https://github.com/mheob/config" }, "license": "MIT", "author": "Alexander Böhm ", - "main": "index.js", - "types": "index.d.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "files": [ - "index.js", - "index.d.ts", - "base.js", - "next.js", - "react.js", + "dist", "LICENSE", "README.md" ], "scripts": { + "build": "tsc", "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist", "lint": "eslint **/*.cjs --fix", "sort-package-json": "pnpm dlx sort-package-json" @@ -40,6 +37,8 @@ "eslint-plugin-unicorn": "^43.0.2" }, "devDependencies": { + "@mheob/tsconfig": "workspace:*", + "@types/eslint": "^8.4.6", "eslint": "^8.23.1", "prettier": "^2.7.1", "typescript": "^4.8.3" diff --git a/packages/eslint-config/base.js b/packages/eslint-config/src/base.ts similarity index 93% rename from packages/eslint-config/base.js rename to packages/eslint-config/src/base.ts index 50e25df..91a2d7e 100644 --- a/packages/eslint-config/base.js +++ b/packages/eslint-config/src/base.ts @@ -1,8 +1,6 @@ -/** - * Base ESLint rules - * @type {import('eslint').ESLint.ConfigData} - */ -module.exports = { +import type { Linter } from 'eslint'; + +const config: Linter.Config = { plugins: ['@typescript-eslint'], extends: ['eslint:recommended', 'plugin:unicorn/recommended', 'plugin:prettier/recommended'], rules: { @@ -50,3 +48,5 @@ module.exports = { }, ], }; + +export = config; diff --git a/packages/eslint-config/src/index.ts b/packages/eslint-config/src/index.ts new file mode 100644 index 0000000..6e71d9f --- /dev/null +++ b/packages/eslint-config/src/index.ts @@ -0,0 +1 @@ +export = require('./base'); diff --git a/packages/eslint-config/src/next.ts b/packages/eslint-config/src/next.ts new file mode 100644 index 0000000..07a95ee --- /dev/null +++ b/packages/eslint-config/src/next.ts @@ -0,0 +1,7 @@ +import type { Linter } from 'eslint'; + +const config: Linter.Config = { + extends: ['./react', 'next/core-web-vitals'], +}; + +export = config; diff --git a/packages/eslint-config/react.js b/packages/eslint-config/src/react.ts similarity index 83% rename from packages/eslint-config/react.js rename to packages/eslint-config/src/react.ts index 489be4a..0cd6bba 100644 --- a/packages/eslint-config/react.js +++ b/packages/eslint-config/src/react.ts @@ -1,8 +1,6 @@ -/** - * React specific ESLint rules - * @type {import('eslint').ESLint.ConfigData} - */ -module.exports = { +import type { Linter } from 'eslint'; + +const config: Linter.Config = { extends: ['./base', 'plugin:eslint-plugin-react/recommended'], settings: { react: { @@ -23,3 +21,5 @@ module.exports = { }, ], }; + +export = config; diff --git a/packages/eslint-config/tsconfig.json b/packages/eslint-config/tsconfig.json new file mode 100644 index 0000000..fac4eb9 --- /dev/null +++ b/packages/eslint-config/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "@mheob/tsconfig/commonjs.json", + "compilerOptions": { + "declaration": true, + "outDir": "dist", + "rootDir": "src" + }, + "include": ["src/**/*"] +} diff --git a/packages/prettier-config/index.cjs b/packages/prettier-config/index.cjs deleted file mode 100644 index 4264e05..0000000 --- a/packages/prettier-config/index.cjs +++ /dev/null @@ -1,34 +0,0 @@ -const jsDocPlugin = require('prettier-plugin-jsdoc'); -const sortImports = require('@trivago/prettier-plugin-sort-imports'); - -/** @type {import('prettier').Config} */ -module.exports = { - plugins: [jsDocPlugin, sortImports], - arrowParens: 'always', - endOfLine: 'lf', - printWidth: 100, - proseWrap: 'always', - importOrder: ['^node:', '', '^[./]'], - importOrderSeparation: true, - importOrderSortSpecifiers: true, - singleQuote: true, - semi: true, - trailingComma: 'all', - useTabs: true, - - overrides: [ - { - files: '*.{yaml,yml}', - options: { - printWidth: 130, - singleQuote: false, - }, - }, - { - files: '*.md', - options: { - printWidth: 130, - }, - }, - ], -}; diff --git a/packages/prettier-config/index.d.ts b/packages/prettier-config/index.d.ts deleted file mode 100644 index 4dfb6a4..0000000 --- a/packages/prettier-config/index.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import type { Config } from 'prettier'; - -declare const config: Config; -export default config; diff --git a/packages/prettier-config/package.json b/packages/prettier-config/package.json index 438a95f..30ea7e4 100644 --- a/packages/prettier-config/package.json +++ b/packages/prettier-config/package.json @@ -10,21 +10,20 @@ "bugs": "https://github.com/mheob/config/issues", "repository": { "type": "git", - "url": "https://github.com/mheob/config.git" + "url": "https://github.com/mheob/config" }, "license": "MIT", "author": "Alexander Böhm ", - "main": "index.cjs", - "types": "index.d.ts", + "main": "dist/index.js", "files": [ - "index.cjs", - "index.d.ts", + "dist", "LICENSE", "README.md" ], "scripts": { + "build": "tsc", "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist", - "lint": "eslint **/*.cjs --fix", + "lint": "eslint **/*.ts --fix", "sort-package-json": "pnpm dlx sort-package-json" }, "dependencies": { @@ -33,6 +32,8 @@ }, "devDependencies": { "@mheob/eslint-config": "workspace:*", + "@mheob/tsconfig": "workspace:*", + "@types/prettier": "^2.7.0", "eslint": "^8.23.1", "prettier": "^2.7.1" }, diff --git a/packages/prettier-config/src/index.ts b/packages/prettier-config/src/index.ts new file mode 100644 index 0000000..59f8279 --- /dev/null +++ b/packages/prettier-config/src/index.ts @@ -0,0 +1,46 @@ +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore +import sortImports from '@trivago/prettier-plugin-sort-imports'; +import type { Config as DefaultConfig } from 'prettier'; + +interface Config extends DefaultConfig { + importOrder?: string[]; + importOrderCaseInsensitive?: boolean; + importOrderParserPlugins?: string[]; + importOrderSeparation?: boolean; + importOrderGroupNamespaceSpecifiers?: boolean; + importOrderSortSpecifiers?: boolean; +} + +const options: Config = { + plugins: [sortImports], + arrowParens: 'always', + endOfLine: 'lf', + printWidth: 100, + proseWrap: 'always', + importOrder: ['^node:', '', '^[./]'], + importOrderSeparation: true, + importOrderSortSpecifiers: true, + singleQuote: true, + semi: true, + trailingComma: 'all', + useTabs: true, + + overrides: [ + { + files: '*.{yaml,yml}', + options: { + printWidth: 130, + singleQuote: false, + }, + }, + { + files: '*.md', + options: { + printWidth: 130, + }, + }, + ], +}; + +export = options; diff --git a/packages/prettier-config/tsconfig.json b/packages/prettier-config/tsconfig.json new file mode 100644 index 0000000..fac4eb9 --- /dev/null +++ b/packages/prettier-config/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "@mheob/tsconfig/commonjs.json", + "compilerOptions": { + "declaration": true, + "outDir": "dist", + "rootDir": "src" + }, + "include": ["src/**/*"] +} diff --git a/packages/tsconfig/package.json b/packages/tsconfig/package.json index 8f472d4..65c8300 100644 --- a/packages/tsconfig/package.json +++ b/packages/tsconfig/package.json @@ -13,7 +13,7 @@ "bugs": "https://github.com/mheob/config/issues", "repository": { "type": "git", - "url": "https://github.com/mheob/config.git" + "url": "https://github.com/mheob/config" }, "license": "MIT", "author": "Alexander Böhm ", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e6265f3..dab7493 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,7 +11,7 @@ importers: '@mheob/prettier-config': workspace:* '@types/node': ^18.7.18 eslint: ^8.23.1 - husky: ^8.0.0 + husky: ^8.0.1 lint-staged: ^13.0.3 prettier: ^2.7.1 ts-node: ^10.9.1 @@ -34,6 +34,8 @@ importers: packages/eslint-config: specifiers: + '@mheob/tsconfig': workspace:* + '@types/eslint': ^8.4.6 '@typescript-eslint/eslint-plugin': ^5.37.0 '@typescript-eslint/parser': ^5.37.0 eslint: ^8.23.1 @@ -53,6 +55,8 @@ importers: eslint-plugin-react: 7.31.8_eslint@8.23.1 eslint-plugin-unicorn: 43.0.2_eslint@8.23.1 devDependencies: + '@mheob/tsconfig': link:../tsconfig + '@types/eslint': 8.4.6 eslint: 8.23.1 prettier: 2.7.1 typescript: 4.8.3 @@ -60,7 +64,9 @@ importers: packages/prettier-config: specifiers: '@mheob/eslint-config': workspace:* + '@mheob/tsconfig': workspace:* '@trivago/prettier-plugin-sort-imports': ^3.3.0 + '@types/prettier': ^2.7.0 eslint: ^8.23.1 prettier: ^2.7.1 prettier-plugin-jsdoc: ^0.4.2 @@ -69,6 +75,8 @@ importers: prettier-plugin-jsdoc: 0.4.2_prettier@2.7.1 devDependencies: '@mheob/eslint-config': link:../eslint-config + '@mheob/tsconfig': link:../tsconfig + '@types/prettier': 2.7.0 eslint: 8.23.1 prettier: 2.7.1 @@ -613,7 +621,7 @@ packages: '@types/node': 14.18.29 chalk: 4.1.2 cosmiconfig: 7.0.1 - cosmiconfig-typescript-loader: 4.0.0_3owiowz3ujipd4k6pbqn3n7oui + cosmiconfig-typescript-loader: 4.1.0_3owiowz3ujipd4k6pbqn3n7oui lodash: 4.17.21 resolve-from: 5.0.0 ts-node: 10.9.1_ck2axrxkiif44rdbzjywaqjysa @@ -863,6 +871,17 @@ packages: '@types/ms': 0.7.31 dev: false + /@types/eslint/8.4.6: + resolution: {integrity: sha512-/fqTbjxyFUaYNO7VcW5g+4npmqVACz1bB7RTHYuLj+PRjw9hrCwrUXVQFpChUS0JsyEFvMZ7U/PfmvWgxJhI9g==} + dependencies: + '@types/estree': 1.0.0 + '@types/json-schema': 7.0.11 + dev: true + + /@types/estree/1.0.0: + resolution: {integrity: sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==} + dev: true + /@types/is-ci/3.0.0: resolution: {integrity: sha512-Q0Op0hdWbYd1iahB+IFNQcWXFq4O0Q5MwQP7uN0souuQ4rPg1vEYcnIOfr1gY+M+6rc8FGoRaBO1mOOvL29sEQ==} dependencies: @@ -871,7 +890,6 @@ packages: /@types/json-schema/7.0.11: resolution: {integrity: sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==} - dev: false /@types/json5/0.0.29: resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==} @@ -910,6 +928,10 @@ packages: resolution: {integrity: sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==} dev: true + /@types/prettier/2.7.0: + resolution: {integrity: sha512-RI1L7N4JnW5gQw2spvL7Sllfuf1SaHdrZpCHiBlCXjIlufi1SMNnbu2teze3/QE67Fg2tBlH7W+mi4hVNk4p0A==} + dev: true + /@types/semver/6.2.3: resolution: {integrity: sha512-KQf+QAMWKMrtBMsB8/24w53tEsxllMj6TuA80TT/5igJalLI/zm0L3oXRbIAl4Ohfc85gyHX/jhMwsVkmhLU4A==} dev: true @@ -1460,8 +1482,8 @@ packages: requiresBuild: true dev: false - /cosmiconfig-typescript-loader/4.0.0_3owiowz3ujipd4k6pbqn3n7oui: - resolution: {integrity: sha512-cVpucSc2Tf+VPwCCR7SZzmQTQkPbkk4O01yXsYqXBIbjE1bhwqSyAgYQkRK1un4i0OPziTleqFhdkmOc4RQ/9g==} + /cosmiconfig-typescript-loader/4.1.0_3owiowz3ujipd4k6pbqn3n7oui: + resolution: {integrity: sha512-HbWIuR5O+XO5Oj9SZ5bzgrD4nN+rfhrm2PMb0FVx+t+XIvC45n8F0oTNnztXtspWGw0i2IzHaUWFD5LzV1JB4A==} engines: {node: '>=12', npm: '>=6'} peerDependencies: '@types/node': '*' diff --git a/turbo.json b/turbo.json index 1f1d80d..2256db0 100644 --- a/turbo.json +++ b/turbo.json @@ -1,6 +1,10 @@ { "$schema": "https://turborepo.org/schema.json", "pipeline": { + "build": { + "dependsOn": ["^build"], + "outputs": [] + }, "clean": { "outputs": [] },