Skip to content

Commit 8dfefa1

Browse files
committed
chore: use top level await for something
closes #1817
1 parent 9c696c1 commit 8dfefa1

File tree

4 files changed

+25
-44
lines changed

4 files changed

+25
-44
lines changed

Diff for: src/test/_util.ts

+15-33
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,25 @@ import exported from '../index.js'
22
import { plugin as tseslintPlugin } from 'typescript-eslint'
33
import { TSESLint } from '@typescript-eslint/utils'
44
import semver from 'semver'
5-
import type { PackageJson } from 'type-fest'
65
import { readPackageUp } from 'read-package-up'
76

8-
interface PkgDetails {
9-
pkgPath: string
10-
pkgJson: PackageJson
11-
ourDeps: NonNullable<PackageJson['dependencies']>
12-
ourPeerDeps: NonNullable<PackageJson['peerDependencies']>
13-
ourDevDeps: NonNullable<PackageJson['devDependencies']>
7+
const readResult = await readPackageUp()
8+
if (readResult === undefined) {
9+
throw new Error()
1410
}
15-
16-
export const getPkgDetails = async (): Promise<PkgDetails> => {
17-
const readResult = await readPackageUp()
18-
if (readResult === undefined) {
19-
throw new Error()
20-
}
21-
const ourPkg = readResult.packageJson
22-
if (ourPkg.dependencies === undefined) {
23-
throw new Error()
24-
}
25-
const ourDeps = ourPkg.dependencies
26-
if (ourPkg.peerDependencies === undefined) {
27-
throw new Error()
28-
}
29-
const ourPeerDeps = ourPkg.peerDependencies
30-
if (ourPkg.devDependencies === undefined) {
31-
throw new Error()
32-
}
33-
const ourDevDeps = ourPkg.devDependencies
34-
return {
35-
pkgJson: ourPkg,
36-
pkgPath: readResult.path,
37-
ourDeps,
38-
ourPeerDeps,
39-
ourDevDeps,
40-
}
11+
const ourPkg = readResult.packageJson
12+
if (ourPkg.dependencies === undefined) {
13+
throw new Error()
14+
}
15+
export const ourDeps = ourPkg.dependencies
16+
if (ourPkg.peerDependencies === undefined) {
17+
throw new Error()
18+
}
19+
export const ourPeerDeps = ourPkg.peerDependencies
20+
if (ourPkg.devDependencies === undefined) {
21+
throw new Error()
4122
}
23+
export const ourDevDeps = ourPkg.devDependencies
4224

4325
export const isSingleCaretRange = (rangeStr: string): boolean => {
4426
const range = new semver.Range(rangeStr)

Diff for: src/test/compatibility.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import type { TSESLint } from '@typescript-eslint/utils'
33
import { ESLint } from 'eslint_bottom'
44
import exported from '../index.js'
55
import semver from 'semver'
6-
import { extractVersionRange, getPkgDetails } from './_util.js'
6+
import {
7+
extractVersionRange,
8+
ourDeps,
9+
ourDevDeps,
10+
ourPeerDeps,
11+
} from './_util.js'
712
import {
813
parser as tseslintBottomParser,
914
plugin as tseslintBottomPlugin,
@@ -13,8 +18,6 @@ import nBottomPlugin from 'eslint-plugin-n_bottom'
1318
import promiseBottomPlugin from 'eslint-plugin-promise_bottom'
1419

1520
test('bottom dep version is minimum of dep range', async (t) => {
16-
const { ourDeps, ourDevDeps, ourPeerDeps } = await getPkgDetails()
17-
1821
const bottomDepsThatAreNotMinOfDepRange = [
1922
['typescript-eslint', ourDeps] as const,
2023
['eslint', ourPeerDeps] as const,
@@ -24,7 +27,6 @@ test('bottom dep version is minimum of dep range', async (t) => {
2427
]
2528
.map(([depName, depCategory]) => {
2629
const bottomRange = ourDevDeps[`${depName}_bottom`]
27-
if (bottomRange === undefined) throw new Error()
2830
const bottomVersion = extractVersionRange(bottomRange)
2931

3032
const depRange = depCategory[depName]

Diff for: src/test/dependencies.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import test from 'ava'
22
import {
33
extractVersionRange,
4-
getPkgDetails,
54
isPinnedRange,
65
isSingleCaretRange,
6+
ourDeps,
7+
ourDevDeps,
8+
ourPeerDeps,
79
} from './_util.js'
810

911
test('range types', async (t) => {
10-
const { ourDeps, ourPeerDeps, ourDevDeps } = await getPkgDetails()
11-
1212
const nonCompliantDepRanges = Object.entries({
1313
dep: ourDeps,
1414
peer: ourPeerDeps,

Diff for: src/test/misc.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'ava'
22
import exported from '../index.js'
3-
import { getPkgDetails } from './_util.js'
3+
import { ourDeps } from './_util.js'
44

55
test('rule configs are arrays', (t) => {
66
if (exported.rules === undefined) throw new Error()
@@ -11,10 +11,7 @@ test('rule configs are arrays', (t) => {
1111
})
1212

1313
test('tseslint dep group same version', async (t) => {
14-
const { ourDeps } = await getPkgDetails()
1514
const tseslint = ourDeps['typescript-eslint']
16-
if (tseslint === undefined) throw new Error()
1715
const tseslintUtils = ourDeps['@typescript-eslint/utils']
18-
if (tseslintUtils === undefined) throw new Error()
1916
t.is(tseslint, tseslintUtils)
2017
})

0 commit comments

Comments
 (0)