Skip to content

Commit

Permalink
build: moduleResolution: nodenext
Browse files Browse the repository at this point in the history
Co-authored-by: Rostislav Simonik <rostislav.simonik@technologystudio.sk>
  • Loading branch information
mightyiam and rostislav-simonik committed Aug 20, 2023
1 parent 2401e22 commit 1f31e2b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 59 deletions.
52 changes: 17 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
"eslint-plugin-import": "2.28.1",
"eslint-plugin-n": "16.0.1",
"eslint-plugin-promise": "6.1.1",
"inclusion": "1.0.1",
"js-yaml": "4.1.0",
"just-diff": "6.0.2",
"npm-package-arg": "11.0.0",
Expand All @@ -97,6 +96,7 @@
"semver": "7.5.4",
"standard-version": "9.5.0",
"tsconfigs": "5.0.0",
"type-fest": "4.2.0",
"typescript": "5.1.6"
},
"files": [
Expand Down
47 changes: 25 additions & 22 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import test from 'ava'
import { type PackageJson } from 'type-fest'
import exported from '.'
import configStandard from './eslint-config-standard'
import { rules as typescriptEslintRules } from '@typescript-eslint/eslint-plugin'
import standardPkg from 'eslint-config-standard/package.json'
import type { NormalizedPackageJson, readPackageUp } from 'read-pkg-up'
import { Linter, ESLint } from 'eslint'
import { readFile } from 'fs/promises'
import { resolve } from 'path'
import npmPkgArg from 'npm-package-arg'
import semver from 'semver'
import inclusion from 'inclusion'
import { diff as justDiff } from 'just-diff'
import structuredClone from '@ungap/structured-clone'

interface PkgDetails {
pkgPath: string
pkgJson: NormalizedPackageJson
ourDeps: NonNullable<NormalizedPackageJson['dependencies']>
ourPeerDeps: NonNullable<NormalizedPackageJson['peerDependencies']>
ourDevDeps: NonNullable<NormalizedPackageJson['devDependencies']>
pkgJson: PackageJson
ourDeps: NonNullable<PackageJson['dependencies']>
ourPeerDeps: NonNullable<PackageJson['peerDependencies']>
ourDevDeps: NonNullable<PackageJson['devDependencies']>
}

const getPkgDetails = async (): Promise<PkgDetails> => {
const readPkgUp: typeof readPackageUp = (await inclusion('read-pkg-up')).readPackageUp
const readResult = await readPkgUp()
const { readPackageUp } = await import('read-pkg-up')
const readResult = await readPackageUp()
if (readResult === undefined) { throw new Error() }
const ourPkg = readResult.packageJson
if (ourPkg.dependencies === undefined) { throw new Error() }
Expand Down Expand Up @@ -303,8 +301,12 @@ test('Dependencies range types', async (t) => {
const { ourDeps, ourPeerDeps, ourDevDeps } = await getPkgDetails()

t.deepEqual(Object.keys(ourDeps).sort(), ['@typescript-eslint/parser', 'eslint-config-standard'])
t.true(isPinnedRange(ourDeps['eslint-config-standard']), 'eslint-config-standard is pinned')
t.true(isSingleCaretRange(ourDeps['@typescript-eslint/parser']), '@typescript-eslint/parser is a single `^` range.')
const eslintConfigStandard = ourDeps['eslint-config-standard']
if (eslintConfigStandard === undefined) throw new Error()
t.true(isPinnedRange(eslintConfigStandard), 'eslint-config-standard is pinned')
const parser = ourDeps['@typescript-eslint/parser']
if (parser === undefined) throw new Error()
t.true(isSingleCaretRange(parser), '@typescript-eslint/parser is a single `^` range.')
const typescriptValue = ourPeerDeps.typescript
t.is(typescriptValue, '*', 'Peer dependency typescript is `*`')
const typescriptEslintPluginValue = ourPeerDeps['@typescript-eslint/eslint-plugin']
Expand All @@ -314,6 +316,7 @@ test('Dependencies range types', async (t) => {
`Peer dependency \`@typescript-eslint/eslint-plugin: ${typescriptEslintPluginValue}\` is a single \`^\` range.`
)
for (const [name, spec] of Object.entries(ourDevDeps)) {
if (spec === undefined) throw new Error()
if (spec.startsWith('github:')) continue
const range = name.startsWith(`${typescriptEslintBottom}/`) ? extractVersionSpec(spec) : spec
t.true(isPinnedRange(range), `Dev dependency \`${name}: ${spec}\` is pinned`)
Expand All @@ -340,13 +343,16 @@ test('@typescript-eslint/eslint-plugin, dev dep subset of peer dep', async (t) =
return
}
const devDepPluginRange = ourDevDeps['@typescript-eslint/eslint-plugin']
if (devDepPluginRange === undefined) throw new Error()
t.true(semver.subset(devDepPluginRange, peerDepPluginRange))
})

test('devDep plugin range subset of dep parser range', async (t) => {
const { ourDeps, ourDevDeps } = await getPkgDetails()
const depParserRange = ourDeps['@typescript-eslint/parser']
const devPluginRange = ourDevDeps['@typescript-eslint/eslint-plugin']
if (devPluginRange === undefined) throw new Error()
if (depParserRange === undefined) throw new Error()
t.true(semver.subset(devPluginRange, depParserRange))
})

Expand Down Expand Up @@ -393,21 +399,14 @@ test('npm install args in readme satisfy peerDeps', async (t) => {
t.false(ourPeerDepsLength > installArgsLength, 'more peer deps than install args')
})

test('not using the `inclusion` package when package is ES modules', async (t) => {
const { pkgJson, ourDevDeps } = await getPkgDetails()
const isUsingInclusion = Object.keys(ourDevDeps).includes('inclusion') // haha
const isModulesPackage = pkgJson.type === 'module'
t.true(isUsingInclusion, 'happy to see it gone')
t.false(isModulesPackage, 'time to drop usage of `inclusion` package')
})

test('all direct equivalents are used', (t) => {
const unusedDirectEquivalents = equivalents
.filter((rule) => Object.prototype.hasOwnProperty.call(standardRules, rule) && !Object.prototype.hasOwnProperty.call(ourRules, `@typescript-eslint/${rule}`))
t.deepEqual(unusedDirectEquivalents, [])
})

test('configs of equivalents are supersets of upstream', (t) => {
test('configs of equivalents are supersets of upstream', async (t) => {
const { diff: justDiff } = await import('just-diff')
equivalents.forEach((ruleName) => {
const standardRuleConfig = standardRules[ruleName]
const ourRuleConfig = ourRules[`@typescript-eslint/${ruleName}`]
Expand Down Expand Up @@ -502,8 +501,12 @@ test('our configuration is compatible with the plugin and parser at bottom of pe
const peerDepRange = ourPeerDeps['@typescript-eslint/eslint-plugin']
if (peerDepRange === undefined) throw new Error()

const bottomPluginVersion = extractVersionSpec(ourDevDeps[typescriptEslintBottomPlugin])
const bottomParserVersion = extractVersionSpec(ourDevDeps[typescriptEslintBottomParser])
const bottomPluginRange = ourDevDeps[typescriptEslintBottomPlugin]
if (bottomPluginRange === undefined) throw new Error()
const bottomPluginVersion = extractVersionSpec(bottomPluginRange)
const bottomParserRange = ourDevDeps[typescriptEslintBottomParser]
if (bottomParserRange === undefined) throw new Error()
const bottomParserVersion = extractVersionSpec(bottomParserRange)

const minPeerDepVersion = semver.minVersion(peerDepRange)
if (minPeerDepVersion === null) throw new Error()
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "tsconfigs/nodejs-module",
"compilerOptions": {
"outDir": "lib"
"outDir": "lib",
"moduleResolution": "nodenext"
},
"include": [
"src/**/*.ts",
Expand Down

0 comments on commit 1f31e2b

Please sign in to comment.