Skip to content

Commit

Permalink
feat: Improve TS configs and add library types
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnns committed Dec 9, 2024
1 parent 0c6662f commit 760a898
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

# Generated by TypeScript
types
13 changes: 13 additions & 0 deletions docs/prettier.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Peerigon's Prettier config

## Install

```sh
npm install prettier@3 --save-dev
```

Add a `prettier.config.js` to your project:

```
```
15 changes: 15 additions & 0 deletions docs/typescript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Reasoning

### `noUncheckedIndexedAccess`

- Mention tiny-invariant

### `noPropertyAccessFromIndexSignature`

### `exactOptionalPropertyTypes`

### `verbatimModuleSyntax`

### `allowImportingTsExtensions`

### `rewriteRelativeImportExtensions`
84 changes: 68 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,74 @@
"author": "Peerigon GmbH <[email protected]>",
"type": "module",
"exports": {
"./eslint/presets/javascript-browser": "./eslint/presets/javascript-browser.js",
"./eslint/presets/javascript-node": "./eslint/presets/javascript-node.js",
"./eslint/presets/javascript": "./eslint/presets/javascript.js",
"./eslint/presets/typescript-node": "./eslint/presets/typescript-node.js",
"./eslint/presets/typescript-react": "./eslint/presets/typescript-react.js",
"./eslint/presets/typescript": "./eslint/presets/typescript.js",
"./eslint/styles/jsx-no-literals": "./eslint/styles/jsx-no-literals.js",
"./eslint/styles/no-default-export": "./eslint/styles/no-default-export.js",
"./eslint/styles/no-null": "./eslint/styles/no-null.js",
"./eslint/styles/prefer-array-shorthand": "./eslint/styles/prefer-array-shorthand.js",
"./eslint/styles/prefer-interface": "./eslint/styles/prefer-interface.js",
"./prettier": "./prettier/base.js",
"./semantic-release": "./semantic-release/base.js",
"./typescript": "./typescript/base.json",
"./typescript/lib": "./typescript/lib.json"
"./eslint/presets/javascript-browser": {
"types": "./types/eslint/presets/javascript-browser.d.ts",
"default": "./eslint/presets/javascript-browser.js"
},
"./eslint/presets/javascript-node": {
"types": "./types/eslint/presets/javascript-node.d.ts",
"default": "./eslint/presets/javascript-node.js"
},
"./eslint/presets/javascript": {
"types": "./types/eslint/presets/javascript.d.ts",
"default": "./eslint/presets/javascript.js"
},
"./eslint/presets/typescript-node": {
"types": "./types/eslint/presets/typescript-node.d.ts",
"default": "./eslint/presets/typescript-node.js"
},
"./eslint/presets/typescript-react": {
"types": "./types/eslint/presets/typescript-react.d.ts",
"default": "./eslint/presets/typescript-react.js"
},
"./eslint/presets/typescript": {
"types": "./types/eslint/presets/typescript.d.ts",
"default": "./eslint/presets/typescript.js"
},
"./eslint/styles/jsx-no-literals": {
"types": "./types/eslint/styles/jsx-no-literals.d.ts",
"default": "./eslint/styles/jsx-no-literals.js"
},
"./eslint/styles/no-default-export": {
"types": "./types/eslint/styles/no-default-export.d.ts",
"default": "./eslint/styles/no-default-export.js"
},
"./eslint/styles/no-null": {
"types": "./types/eslint/styles/no-null.d.ts",
"default": "./eslint/styles/no-null.js"
},
"./eslint/styles/prefer-array-shorthand": {
"types": "./types/eslint/styles/prefer-array-shorthand.d.ts",
"default": "./eslint/styles/prefer-array-shorthand.js"
},
"./eslint/styles/prefer-interface": {
"types": "./types/eslint/styles/prefer-interface.d.ts",
"default": "./eslint/styles/prefer-interface.js"
},
"./prettier": {
"types": "./types/prettier/base.d.ts",
"default": "./prettier/base.js"
},
"./semantic-release": {
"types": "./types/semantic-release/base.d.ts",
"default": "./semantic-release/base.js"
},
"./typescript": {
"default": "./typescript/base.json"
},
"./typescript/lib": {
"default": "./typescript/lib.json"
},
"./typescript/js-lib": {
"default": "./typescript/js-lib.json"
}
},
"files": [
"docs",
"eslint",
"prettier",
"semantic-release",
"types",
"typescript",
"CHANGELOG.md",
"README.md"
Expand All @@ -55,8 +103,11 @@
"test:styles:no-null": "cd eslint/styles/no-null.test; eslint --max-warnings 0 .",
"test:styles:prefer-array-shorthand": "cd eslint/styles/prefer-array-shorthand.test; eslint --max-warnings 0 .",
"test:styles:prefer-interface": "cd eslint/styles/prefer-interface.test; eslint --max-warnings 0 .",
"test:types": "tsc",
"test:types": "tsc --noEmit",
"test:prettier": "prettier --check .",
"build": "run-s build:*",
"build:types": "tsc",
"prepublishOnly": "npm run build",
"prepare": "husky",
"release": "semantic-release"
},
Expand Down Expand Up @@ -107,6 +158,7 @@
},
"peerDependencies": {
"eslint": "^9.0.0",
"prettier": "^3.3.3",
"typescript": "^5.6.3"
},
"publishConfig": {
Expand Down
5 changes: 4 additions & 1 deletion prettier/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const plugins = await Promise.all([
safeResolve("prettier-plugin-tailwindcss"),
]);

export default {
/** @type {import("prettier").Config} */
export const config = {
plugins,
importOrderParserPlugins: [
"typescript",
Expand All @@ -28,3 +29,5 @@ export default {
],
importOrderTypeScriptVersion: "5.0.0",
};

export default config;
5 changes: 4 additions & 1 deletion semantic-release/base.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default {
/** @type {import("semantic-release").Options} */
export const config = {
branches: ["main", { name: "beta", prerelease: true }],
plugins: [
"@semantic-release/commit-analyzer",
Expand Down Expand Up @@ -36,3 +37,5 @@ export default {
],
],
};

export default config;
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "./typescript/base.json",
"extends": "./typescript/js-lib.json",
"include": ["eslint", "prettier", "typescript", "semantic-release"],
"exclude": [
"eslint/presets/typescript.test",
Expand Down
5 changes: 4 additions & 1 deletion typescript/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"isolatedModules": true,
"lib": ["DOM", "ESNext"],
"module": "NodeNext",
"noEmit": true, // If code should be emitted, it's recommended to create a separate tsconfig.build.json file
"noImplicitOverride": true,
"noImplicitReturns": true,
"noPropertyAccessFromIndexSignature": true,
Expand All @@ -16,6 +15,10 @@
"skipLibCheck": true,
"strict": true,
"target": "ESNext"
// TODO: Turn on the following settings once TS 5.7 is released, see also https://nodejs.org/docs/latest/api/typescript.html#typescript-features
// "allowImportingTsExtensions": true,
// "rewriteRelativeImportExtensions": true,
// "verbatimModuleSyntax": true
},
"$schema": "https://json.schemastore.org/tsconfig"
}
9 changes: 9 additions & 0 deletions typescript/js-lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./lib.json",
"compilerOptions": {
"allowJs": true,
"emitDeclarationOnly": true,
"outDir": "${configDir}/types"
},
"$schema": "https://json.schemastore.org/tsconfig"
}
11 changes: 7 additions & 4 deletions typescript/lib.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"extends": "./typescript.json",
"extends": "./base.json",
"compilerOptions": {
"sourceMap": true,
"declaration": true
}
"declaration": true,
"declarationMap": true,
"outDir": "${configDir}/dist",
"sourceMap": true
},
"$schema": "https://json.schemastore.org/tsconfig"
}

0 comments on commit 760a898

Please sign in to comment.