Skip to content

Commit

Permalink
feat: use TypeScript for source config files (#46)
Browse files Browse the repository at this point in the history
Resolves #33

Switch to TypeScript to have a better code base for the future.
  • Loading branch information
mheob authored Sep 17, 2022
1 parent c4e3768 commit 6f731ee
Show file tree
Hide file tree
Showing 24 changed files with 187 additions and 85 deletions.
6 changes: 6 additions & 0 deletions .changeset/hungry-cups-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@mheob/eslint-config': patch
'@mheob/prettier-config': patch
---

Switch to typescript as source files
37 changes: 37 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ node_modules
# testing
coverage

# next.js
# builds
.next/
out/
out
build
dist

# misc
.DS_Store
Expand Down
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ coverage

# turbo
.turbo

# builds
.next/
out
build
dist
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
4 changes: 0 additions & 4 deletions packages/eslint-config/index.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/eslint-config/index.js

This file was deleted.

7 changes: 0 additions & 7 deletions packages/eslint-config/next.js

This file was deleted.

15 changes: 7 additions & 8 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tools@boehm.work>",
"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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down Expand Up @@ -50,3 +48,5 @@ module.exports = {
},
],
};

export = config;
1 change: 1 addition & 0 deletions packages/eslint-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export = require('./base');
7 changes: 7 additions & 0 deletions packages/eslint-config/src/next.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Linter } from 'eslint';

const config: Linter.Config = {
extends: ['./react', 'next/core-web-vitals'],
};

export = config;
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -23,3 +21,5 @@ module.exports = {
},
],
};

export = config;
9 changes: 9 additions & 0 deletions packages/eslint-config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "@mheob/tsconfig/commonjs.json",
"compilerOptions": {
"declaration": true,
"outDir": "dist",
"rootDir": "src"
},
"include": ["src/**/*"]
}
34 changes: 0 additions & 34 deletions packages/prettier-config/index.cjs

This file was deleted.

4 changes: 0 additions & 4 deletions packages/prettier-config/index.d.ts

This file was deleted.

13 changes: 7 additions & 6 deletions packages/prettier-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tools@boehm.work>",
"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": {
Expand All @@ -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"
},
Expand Down
46 changes: 46 additions & 0 deletions packages/prettier-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -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:', '<THIRD_PARTY_MODULES>', '^[./]'],
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;
9 changes: 9 additions & 0 deletions packages/prettier-config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "@mheob/tsconfig/commonjs.json",
"compilerOptions": {
"declaration": true,
"outDir": "dist",
"rootDir": "src"
},
"include": ["src/**/*"]
}
2 changes: 1 addition & 1 deletion packages/tsconfig/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tools@boehm.work>",
Expand Down
Loading

0 comments on commit 6f731ee

Please sign in to comment.