From 901882d7b84c8181d58c4940ce6f02c9501ebf66 Mon Sep 17 00:00:00 2001 From: Zephyr Lykos Date: Wed, 17 Jan 2024 01:09:53 +0800 Subject: [PATCH] fix: Defer the assignment of matchSorter.rankings (#148) --- .github/workflows/validate.yml | 17 ++++++++--------- package.json | 6 +++--- src/__tests__/index.ts | 1 + src/index.ts | 8 ++++---- tsconfig.json | 5 ++++- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index e9e5be5..8d7616c 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -21,14 +21,14 @@ jobs: if: ${{ !contains(github.head_ref, 'all-contributors') }} strategy: matrix: - node: [10.13, 12, 14, 15] + node: [lts/-1, lts/*, latest] runs-on: ubuntu-latest steps: - name: ⬇️ Checkout repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: ⎔ Setup node - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} @@ -43,7 +43,7 @@ jobs: run: npm run validate - name: ⬆️ Upload coverage report - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v3 release: needs: main @@ -54,12 +54,12 @@ jobs: github.ref) && github.event_name == 'push' }} steps: - name: ⬇️ Checkout repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: ⎔ Setup node - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: - node-version: 14 + node-version: lts/* - name: 📥 Download deps uses: bahmutov/npm-install@v1 @@ -72,9 +72,8 @@ jobs: run: npm run build - name: 🚀 Release - uses: cycjimmy/semantic-release-action@v2 + uses: cycjimmy/semantic-release-action@v4 with: - semantic_version: 17 branches: | [ '+([0-9])?(.{+([0-9]),x}).x', diff --git a/package.json b/package.json index 3b4f8b0..85d1630 100644 --- a/package.json +++ b/package.json @@ -27,13 +27,13 @@ "author": "Kent C. Dodds (https://kentcdodds.com)", "license": "MIT", "dependencies": { - "@babel/runtime": "^7.12.5", + "@babel/runtime": "^7.23.8", "remove-accents": "0.5.0" }, "devDependencies": { "@types/jest": "^26.0.15", - "kcd-scripts": "^7.2.0", - "typescript": "^4.1.2" + "kcd-scripts": "^15", + "typescript": "^5.3" }, "eslintConfig": { "extends": [ diff --git a/src/__tests__/index.ts b/src/__tests__/index.ts index dd795dd..bcb380e 100644 --- a/src/__tests__/index.ts +++ b/src/__tests__/index.ts @@ -526,6 +526,7 @@ for (const [ /* eslint + jest/prefer-each: "off", jest/valid-title: "off", jest/no-disabled-tests: "off", jest/no-focused-tests: "off", diff --git a/src/index.ts b/src/index.ts index 7a20218..1989088 100644 --- a/src/index.ts +++ b/src/index.ts @@ -69,8 +69,6 @@ const rankings = { type Ranking = typeof rankings[keyof typeof rankings] -matchSorter.rankings = rankings - const defaultBaseSortFn: BaseSorter = (a, b) => String(a.rankedValue).localeCompare(String(b.rankedValue)) @@ -110,6 +108,8 @@ function matchSorter( } } +matchSorter.rankings = rankings + /** * Gets the highest ranking for value for the given item based on its values for the given keys * @param {*} item - the item to rank @@ -368,7 +368,7 @@ function getItemValues( value = key(item) } else if (item == null) { value = null - } else if (Object.hasOwnProperty.call(item, key)) { + } else if (Object.hasOwn(item, key)) { value = (item as IndexableByString)[key] } else if (key.includes('.')) { // eslint-disable-next-line @typescript-eslint/no-unsafe-call @@ -412,7 +412,7 @@ function getNestedValues( if (nestedItem == null) continue - if (Object.hasOwnProperty.call(nestedItem, nestedKey)) { + if (Object.hasOwn(nestedItem as object, nestedKey)) { const nestedValue = (nestedItem as IndexableByString)[nestedKey] if (nestedValue != null) { nestedValues.push(nestedValue as IndexableByString | string) diff --git a/tsconfig.json b/tsconfig.json index b41b885..cdf6437 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,3 +1,6 @@ { - "extends": "./node_modules/kcd-scripts/shared-tsconfig.json" + "extends": "./node_modules/kcd-scripts/shared-tsconfig.json", + "compilerOptions": { + "lib": ["ESNext"] + } }