From 4afc2f5c964f2d2e906396669e61052d9cce9488 Mon Sep 17 00:00:00 2001 From: Refringe Date: Mon, 30 Dec 2024 04:13:15 -0500 Subject: [PATCH] Development Strict Mode (#1006) - Enables TS strict mode - Adds script to check types - Adds workflow to run check-type script - Updates the code-checking workflows to share the same set-up job This updates the `tsconfig.json` option to enable strict mode. *However*, we use TSX for development and SWC for release, which do not type-check, so this option only gives additional linting/visual-feedback in VSCode. Additionally, I've added a NPM script `npm run lint:types` and a GitHub workflow that runs it. **This depends on #1005.** --------- Co-authored-by: Chomp <27521899+chompDev@users.noreply.github.com> --- .github/workflows/run-lint.yaml | 10 +++++++ .github/workflows/run-test.yaml | 10 +++++++ .github/workflows/run-types.yaml | 42 +++++++++++++++++++++++++++++ README.md | 45 +++++++++++++++++--------------- project/package.json | 9 ++++--- project/tsconfig.json | 2 +- project/tsconfig.types.json | 1 + 7 files changed, 93 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/run-types.yaml diff --git a/.github/workflows/run-lint.yaml b/.github/workflows/run-lint.yaml index c78064b4..28878311 100644 --- a/.github/workflows/run-lint.yaml +++ b/.github/workflows/run-lint.yaml @@ -23,7 +23,17 @@ jobs: cache: "npm" cache-dependency-path: "project/package.json" + - name: Check NPM Cache + id: cache-check + uses: actions/cache@v4 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('./project/package.json') }} + restore-keys: | + ${{ runner.os }}-node- + - name: Install NPM Dependencies + if: steps.cache-check.outputs.cache-hit != 'true' run: npm install working-directory: ./project diff --git a/.github/workflows/run-test.yaml b/.github/workflows/run-test.yaml index bb8de899..8cf3aebc 100644 --- a/.github/workflows/run-test.yaml +++ b/.github/workflows/run-test.yaml @@ -23,7 +23,17 @@ jobs: cache: "npm" cache-dependency-path: "project/package.json" + - name: Check NPM Cache + id: cache-check + uses: actions/cache@v4 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('./project/package.json') }} + restore-keys: | + ${{ runner.os }}-node- + - name: Install NPM Dependencies + if: steps.cache-check.outputs.cache-hit != 'true' run: npm install working-directory: ./project diff --git a/.github/workflows/run-types.yaml b/.github/workflows/run-types.yaml new file mode 100644 index 00000000..9027b435 --- /dev/null +++ b/.github/workflows/run-types.yaml @@ -0,0 +1,42 @@ +name: Run Type Check + +on: + push: + branches: ["*"] + pull_request: + branches: ["*"] + +jobs: + types: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + lfs: false + + - name: Checkout LFS + run: git lfs pull + + - uses: actions/setup-node@v4 + with: + node-version-file: "./project/.nvmrc" + cache: "npm" + cache-dependency-path: "./project/package.json" + + - name: Check NPM Cache + id: cache-check + uses: actions/cache@v4 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('./project/package.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - name: Install NPM Dependencies + if: steps.cache-check.outputs.cache-hit != 'true' + run: npm install + working-directory: ./project + + - name: Run Type Check + run: npm run lint:types + working-directory: ./project diff --git a/README.md b/README.md index 6a71cf06..ec3f7141 100644 --- a/README.md +++ b/README.md @@ -51,27 +51,30 @@ To prepare the project for development you will need to: The following commands are available after the initial setup. Run them with `npm run `. -| Command | Description | -|-----------------------|---------------------------------------------------------------------------| -| `check:circular` | Check for circular dependencies in the project. | -| `lint` | Check the project for coding standards issues using Biome. | -| `lint:fix` | Automatically fix coding standards issues using Biome. | -| `style` | Check the project for formatting issues using Biome. | -| `style:fix` | Automatically fix formatting issues using Biome. | -| `format` | Automatically fix all coding standards and formatting issues using Biome. | -| `test` | Run all tests. | -| `test:watch` | Run tests in watch mode. Tests will re-run when files are changed. | -| `test:coverage` | Run tests and generate a coverage report. | -| `test:ui` | Run tests in UI mode. This will open a browser window to view tests. | -| `build:release` | Build the project for release. | -| `build:debug` | Build the project for debugging. | -| `build:bleeding` | Build the project on the bleeding edge. | -| `build:bleedingmods` | Build the project on the bleeding edge with mods. | -| `run:build` | Run the project in build mode. | -| `run:debug` | Run the project in debug mode. | -| `run:profiler` | Run the project in profiler mode. | -| `gen:types` | Generate types for the project. | -| `gen:docs` | Generate documentation for the project. | +| Command | Description | +|------------------------|---------------------------------------------------------------------------| +| `check:circular` | Check for circular dependencies in the project. | +| `lint` | Check the project for coding standards issues using Biome. | +| `lint:fix` | Automatically fix coding standards issues using Biome. | +| `lint:types` | Check for TypeScript compile errors using TSC. | +| `style` | Check the project for formatting issues using Biome. | +| `style:fix` | Automatically fix formatting issues using Biome. | +| `format` | Automatically fix all coding standards and formatting issues using Biome. | +| `test` | Run all tests. | +| `test:watch` | Run tests in watch mode. Tests will re-run when files are changed. | +| `test:coverage` | Run tests and generate a coverage report. | +| `test:ui` | Run tests in UI mode. This will open a browser window to view tests. | +| `build:release` | Build the project for release. | +| `build:debug` | Build the project for debugging. | +| `build:bleeding` | Build the project on the bleeding edge. | +| `build:bleedingmods` | Build the project on the bleeding edge with mods. | +| `run:build` | Run the project in build mode. | +| `run:debug` | Run the project in debug mode. | +| `run:profiler` | Run the project in profiler mode. | +| `gen:types` | Generate types for the project. | +| `gen:docs` | Generate documentation for the project. | +| `gen:items` | Dynamically generate ItemTpl and Weapons enums. | +| `gen:productionquests` | Automatically update properties for production requirements. | ### Debugging diff --git a/project/package.json b/project/package.json index 91d7e855..24f408fe 100644 --- a/project/package.json +++ b/project/package.json @@ -14,13 +14,14 @@ "check:circular": "madge --circular --ts-config tsconfig.json --extensions ts ./src/", "lint": "npx @biomejs/biome lint ./", "lint:fix": "npx @biomejs/biome lint --write ./", + "lint:types": "tsc --noEmit", "style": "npx @biomejs/biome format ./", "style:fix": "npx @biomejs/biome format --write ./", "format": "npx @biomejs/biome check --write ./", - "test": "vitest run", - "test:watch": "vitest", - "test:coverage": "vitest run --coverage", - "test:ui": "vitest --ui --coverage", + "test": "npx vitest run", + "test:watch": "npx vitest", + "test:coverage": "npx vitest run --coverage", + "test:ui": "npx vitest --ui --coverage", "build:release": "cross-env PKG_CACHE_PATH=\"./.pkg-cache\" gulp build:release", "build:debug": "cross-env PKG_CACHE_PATH=\"./.pkg-cache\" gulp build:debug", "build:bleeding": "cross-env PKG_CACHE_PATH=\"./.pkg-cache\" gulp build:bleeding", diff --git a/project/tsconfig.json b/project/tsconfig.json index ac0cbc7b..ae82d0b7 100644 --- a/project/tsconfig.json +++ b/project/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "strict": false, + "strict": true, "moduleDetection": "force", "module": "Preserve", "resolveJsonModule": true, diff --git a/project/tsconfig.types.json b/project/tsconfig.types.json index 4f2cb246..c96fe95a 100644 --- a/project/tsconfig.types.json +++ b/project/tsconfig.types.json @@ -1,6 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { + "strict": false, "noEmit": false, "emitDeclarationOnly": true, "declaration": true,