diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cb045a0..b55b1a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,9 @@ jobs: - name: Lint Files run: npm run lint + - name: Type Check Files + run: npm run tsc + - name: Check Formatting run: npm run fmt:check diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..4f3c108 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,40 @@ +# Contributing + +Please be sure to read the contribution guidelines before making or requesting a change. + +## Code of Conduct + +This project adheres to the [OpenJS Foundation Code of Conduct](https://eslint.org/conduct). We kindly request that you read over our code of conduct before contributing. + +## Commands + +### Building + +[Rollup](https://rollupjs.org) and [TypeScript](https://www.typescriptlang.org) are used to turn source files in `packages/*/src/` into outputs in `packages/*/dist/`. + +```shell +npm run build +``` + +### Linting + +ESLint is linted using ESLint. +[Building](#building) the project must be done before it can lint itself. + +```shell +npm run lint +``` + +### Type Checking + +This project is written in JavaScript and uses [TypeScript](https://www.typescriptlang.org) to validate types declared in JSDoc comments. + +```shell +npm run tsc +``` + +Add `--watch` to run in a "watch" mode: + +```shell +npm run tsc -- --watch +``` diff --git a/package.json b/package.json index 7e799ef..fd44b8a 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "build": "node scripts/build.js", "build:readme": "node tools/update-readme.js", "lint": "eslint .", + "tsc": "tsc", "lint:fix": "eslint --fix .", "fmt": "prettier --write .", "fmt:check": "prettier --check .", @@ -27,6 +28,7 @@ "!(*.{js,ts})": "prettier --write --ignore-unknown" }, "devDependencies": { + "@types/mocha": "^10.0.7", "common-tags": "^1.8.2", "eslint": "^9.4.0", "eslint-config-eslint": "^11.0.0", diff --git a/packages/compat/tsconfig.json b/packages/compat/tsconfig.json index 3fa504c..5d8149a 100644 --- a/packages/compat/tsconfig.json +++ b/packages/compat/tsconfig.json @@ -1,13 +1,7 @@ { + "extends": "../../tsconfig.base.json", "files": ["src/index.js"], "compilerOptions": { - "declaration": true, - "emitDeclarationOnly": true, - "allowJs": true, - "checkJs": true, - "outDir": "dist/esm", - "target": "ES2022", - "moduleResolution": "NodeNext", - "module": "NodeNext" + "outDir": "dist/esm" } } diff --git a/packages/config-array/tsconfig.json b/packages/config-array/tsconfig.json index 3fa504c..5d8149a 100644 --- a/packages/config-array/tsconfig.json +++ b/packages/config-array/tsconfig.json @@ -1,13 +1,7 @@ { + "extends": "../../tsconfig.base.json", "files": ["src/index.js"], "compilerOptions": { - "declaration": true, - "emitDeclarationOnly": true, - "allowJs": true, - "checkJs": true, - "outDir": "dist/esm", - "target": "ES2022", - "moduleResolution": "NodeNext", - "module": "NodeNext" + "outDir": "dist/esm" } } diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index cbeabd7..67750a2 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -1,13 +1,7 @@ { + "extends": "../../tsconfig.base.json", "files": ["src/types.ts"], "compilerOptions": { - "declaration": true, - "emitDeclarationOnly": true, - "allowJs": true, - "checkJs": true, - "outDir": "dist/esm", - "target": "ES2022", - "moduleResolution": "NodeNext", - "module": "NodeNext" + "outDir": "dist/esm" } } diff --git a/packages/migrate-config/tsconfig.json b/packages/migrate-config/tsconfig.json index 08bc479..4e6f7b3 100644 --- a/packages/migrate-config/tsconfig.json +++ b/packages/migrate-config/tsconfig.json @@ -1,13 +1,7 @@ { + "extends": "../../tsconfig.base.json", "files": ["src/migrate-config-cli.js"], "compilerOptions": { - "declaration": true, - "emitDeclarationOnly": true, - "allowJs": true, - "checkJs": true, - "outDir": "dist/esm", - "target": "ES2022", - "moduleResolution": "NodeNext", - "module": "NodeNext" + "outDir": "dist/esm" } } diff --git a/packages/object-schema/tsconfig.json b/packages/object-schema/tsconfig.json index 3fa504c..5d8149a 100644 --- a/packages/object-schema/tsconfig.json +++ b/packages/object-schema/tsconfig.json @@ -1,13 +1,7 @@ { + "extends": "../../tsconfig.base.json", "files": ["src/index.js"], "compilerOptions": { - "declaration": true, - "emitDeclarationOnly": true, - "allowJs": true, - "checkJs": true, - "outDir": "dist/esm", - "target": "ES2022", - "moduleResolution": "NodeNext", - "module": "NodeNext" + "outDir": "dist/esm" } } diff --git a/packages/plugin-kit/src/@types/levn.d.ts b/packages/plugin-kit/src/@types/levn.d.ts deleted file mode 100644 index 94414cc..0000000 --- a/packages/plugin-kit/src/@types/levn.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -declare module "levn" { - interface ParseOptions { - explicit?: boolean; - customTypes: Record; - } - - function parse(type: string, input: string, options?: ParseOptions): object; -} diff --git a/packages/plugin-kit/src/config-comment-parser.js b/packages/plugin-kit/src/config-comment-parser.js index f22f97a..e4489c0 100644 --- a/packages/plugin-kit/src/config-comment-parser.js +++ b/packages/plugin-kit/src/config-comment-parser.js @@ -9,7 +9,6 @@ // Imports //------------------------------------------------------------------------------ -// @ts-ignore -- don't feel like fighting with TypeScript right now import levn from "levn"; //----------------------------------------------------------------------------- diff --git a/packages/plugin-kit/tsconfig.json b/packages/plugin-kit/tsconfig.json index 960debf..779639c 100644 --- a/packages/plugin-kit/tsconfig.json +++ b/packages/plugin-kit/tsconfig.json @@ -1,15 +1,8 @@ { + "extends": "../../tsconfig.base.json", "files": ["src/index.js"], "compilerOptions": { - "declaration": true, - "emitDeclarationOnly": true, - "allowJs": true, - "checkJs": true, "outDir": "dist/esm", - "target": "ES2022", - "moduleResolution": "NodeNext", - "module": "NodeNext", - "strict": true, - "typeRoots": ["node_modules/@types", "src/@types"] + "strict": true } } diff --git a/scripts/build.js b/scripts/build.js index 2200225..22d4bee 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -67,8 +67,8 @@ async function calculatePackageDependencies(packageDirs) { } /** - * Creates an array of directories to be built in order to sastify dependencies. - * @param {Map}} dependencies The + * Creates an array of directories to be built in order to satisfy dependencies. + * @param {Map}>} dependencies The * dependencies between packages. * @returns {Array} An array of directories to be built in order. */ diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 0000000..c5740a8 --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "allowJs": true, + "checkJs": true, + "declaration": true, + "emitDeclarationOnly": true, + "module": "NodeNext", + "moduleResolution": "NodeNext", + "target": "ES2022" + } +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..f4bf5d8 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.base.json", + "include": ["packages/*/src"], + "compilerOptions": { + "emitDeclarationOnly": false, + "noEmit": true + } +} diff --git a/types/levn.d.ts b/types/levn.d.ts new file mode 100644 index 0000000..61e75b7 --- /dev/null +++ b/types/levn.d.ts @@ -0,0 +1,36 @@ +/** + * @todo This should be contributed up to DefinitelyTyped to make a `@types/levn` package. + */ +declare module "levn" { + export interface ParseOptions { + explicit?: boolean | undefined; + customTypes?: Record; + } + + export interface CustomParseType { + typeOf: string; + validate: (value: unknown) => boolean; + cast: (value: unknown) => CastedValue; + } + + export interface CastedValue { + type: string; + value: Value; + } + + // TODO: This comes from type-check. + export type ParsedType = unknown; + + export function parse( + type: string, + string: string, + options?: unknown, + ): unknown; + + export function parsedTypeParse( + parsedType: string, + options?: unknown, + ): unknown; + + export const VERSION: string; +}