Skip to content

Commit fa74d38

Browse files
committed
feat: add types and library config
1 parent 7fb26cb commit fa74d38

File tree

10 files changed

+98
-7
lines changed

10 files changed

+98
-7
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ Create a `reset.d.ts` file:
4646
import "@aha-co/config/reset.d.ts"
4747
```
4848

49+
#### TS for Libraries
50+
51+
The configuration above assumes you're using a bundler to create an application.
52+
If you're creating a library, you'll want the configuration to be more strict to
53+
be consumable in as many setups as possible. You can extend a different config
54+
instead:
55+
56+
```json
57+
extends: ["@aha-co/config/typescript.lib"],
58+
```
59+
4960
### ESLint
5061

5162
Create a `eslint.config.js` file in the project root and

eslint.config.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { type Linter } from "eslint"
2+
3+
/**
4+
* Check if a package is installed by attempting to resolve it
5+
* @param pkg - The package name to check
6+
* @returns True if the package is installed, false otherwise
7+
*/
8+
export declare const has: (pkg: string) => boolean
9+
10+
/**
11+
* ESLint configuration for Aha projects
12+
*/
13+
export declare const config: Linter.Config[]
14+
15+
export default config

index.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @aha-co/config main entry point
3+
*
4+
* This package provides standardized configurations for Aha JS projects.
5+
* The main entry point intentionally throws an error as there is no default export.
6+
* Import specific configurations using the named exports instead:
7+
*
8+
* @example
9+
* ```ts
10+
* import { config as prettierConfig } from '@aha-co/config/prettier'
11+
* import { config as eslintConfig } from '@aha-co/config/eslint'
12+
* ```
13+
*/
14+
15+
declare const _default: never
16+
export default _default

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,28 @@
44
"version": "1.0.1",
55
"description": "Standardized configs for Aha JS projects",
66
"main": "index.js",
7+
"types": "index.d.ts",
78
"type": "module",
89
"imports": {
910
"#/*": "./*"
1011
},
1112
"exports": {
12-
".": "./index.js",
13-
"./prettier": "./prettier.js",
14-
"./typescript": "./typescript.json",
13+
".": {
14+
"types": "./index.d.ts",
15+
"import": "./index.js"
16+
},
17+
"./prettier": {
18+
"types": "./prettier.d.ts",
19+
"import": "./prettier.js"
20+
},
21+
"./typescript": "./typescript.app.json",
22+
"./typescript.app": "./typescript.app.json",
23+
"./typescript.lib": "./typescript.lib.json",
1524
"./reset.d.ts": "./reset.d.ts",
16-
"./eslint": "./eslint.config.js"
25+
"./eslint": {
26+
"types": "./eslint.config.d.ts",
27+
"import": "./eslint.config.js"
28+
}
1729
},
1830
"prettier": "./prettier.js",
1931
"scripts": {
@@ -56,6 +68,7 @@
5668
},
5769
"devDependencies": {
5870
"@playwright/test": "^1.54.1",
71+
"@types/eslint": "^9.6.1",
5972
"@types/react": "^19.1.8",
6073
"eslint": "^9.32.0",
6174
"npm-run-all": "^4.1.5",

prettier.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { type Options } from "prettier"
2+
3+
/**
4+
* Prettier configuration for Aha projects
5+
*/
6+
export declare const config: Options
7+
8+
export default config

prettier.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @type {import("prettier").Options} */
1+
/** @type {import("prettier").Config} */
22
export const config = {
33
arrowParens: "always",
44
bracketSameLine: false,

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"extends": "./typescript.json",
2+
"extends": "./typescript.lib.json",
33
"include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx"]
44
}

typescript.json renamed to typescript.app.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"allowImportingTsExtensions": true,
1111
"noUncheckedIndexedAccess": true,
1212
"forceConsistentCasingInFileNames": true,
13-
"noEmit": true
13+
"noEmit": true,
14+
"moduleResolution": "bundler",
15+
"allowSyntheticDefaultImports": true,
16+
"esModuleInterop": true
1417
}
1518
}

typescript.lib.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
3+
"compilerOptions": {
4+
"module": "node18",
5+
"target": "es2020",
6+
"strict": true,
7+
"verbatimModuleSyntax": true,
8+
"declaration": true,
9+
"sourceMap": true,
10+
"declarationMap": true,
11+
"outDir": "dist"
12+
}
13+
}

0 commit comments

Comments
 (0)