Skip to content

Commit

Permalink
fix: load eslint module from config file dir, close #53
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jun 1, 2024
1 parent aa2a227 commit 770aded
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"get-port-please": "^3.1.2",
"h3": "^1.11.1",
"minimatch": "^9.0.4",
"mlly": "^1.7.0",
"mrmime": "^2.0.0",
"open": "^10.1.0",
"picocolors": "^1.0.1",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

8 changes: 7 additions & 1 deletion src/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { bundleRequire } from 'bundle-require'
import fg from 'fast-glob'
import { findUp } from 'find-up'
import c from 'picocolors'
import { resolve as resolveModule } from 'mlly'
import type { FlatConfigItem, MatchedFile, Payload, RuleInfo } from '../shared/types'
import { isIgnoreOnlyConfig, matchFile } from '../shared/configs'
import { MARK_CHECK, MARK_INFO, configFilenames } from './constants'
Expand Down Expand Up @@ -104,7 +105,12 @@ export async function readConfig(
rawConfigs = [rawConfigs]

const rulesMap = new Map<string, RuleInfo>()
const eslintRules = await import(['eslint', 'use-at-your-own-risk'].join('/')).then(r => r.default.builtinRules)

// Try resolve `eslint` module from the same directory as the config file
// Otherwise fallback to bare import
const eslintPath = await resolveModule('eslint/use-at-your-own-risk', { url: basePath })
.catch(() => null) || 'eslint/use-at-your-own-risk'
const eslintRules = await import(eslintPath).then(r => r.default.builtinRules)

for (const [name, rule] of eslintRules.entries()) {
rulesMap.set(name, {
Expand Down

0 comments on commit 770aded

Please sign in to comment.