Skip to content

Commit

Permalink
feat: allow override rootdir for generated configs
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Nov 26, 2024
1 parent 52e50a5 commit 86f7940
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/module/src/modules/config/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function generateESLintConfig(
},
)

const dirs = getDirs(nuxt) || {}
const dirs = getDirs(nuxt, options) || {}

for (const addon of addons) {
const resolved = await addon.getConfigs()
Expand Down
9 changes: 6 additions & 3 deletions packages/module/src/modules/config/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import type { Nuxt } from '@nuxt/schema'
import { relative, resolve } from 'pathe'
import type { NuxtESLintConfigOptions } from '@nuxt/eslint-config/flat'
import type { ModuleOptions } from '../../types'

export function getDirs(nuxt: Nuxt, options: ModuleOptions): NuxtESLintConfigOptions['dirs'] {
const rootDir = (typeof options.config === 'object' && options.config.rootDir) || nuxt.options.rootDir

export function getDirs(nuxt: Nuxt): NuxtESLintConfigOptions['dirs'] {
const dirs: Required<NuxtESLintConfigOptions['dirs']> = {
pages: [],
composables: [],
Expand All @@ -13,12 +16,12 @@ export function getDirs(nuxt: Nuxt): NuxtESLintConfigOptions['dirs'] {
middleware: [],
modules: [],
servers: [],
root: [nuxt.options.rootDir],
root: [],
src: [],
}

for (const layer of nuxt.options._layers) {
const r = (t: string) => relative(nuxt.options.rootDir, resolve(layer.config.srcDir, t.replace(/^~[/\\]/, '')))
const r = (t: string) => relative(rootDir, resolve(layer.config.srcDir, t.replace(/^~[/\\]/, '')))

dirs.src.push(r(''))
dirs.pages.push(r(nuxt.options.dir.pages || 'pages'))
Expand Down
8 changes: 8 additions & 0 deletions packages/module/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export interface ConfigGenOptions extends NuxtESLintFeaturesOptions {
* @default true
*/
autoInit?: boolean

/**
* Override rootDir for the generated ESLint config
* If you generate ESLint config from a different directory, you can set this option
*
* @default nuxt.options.rootDir
*/
rootDir?: string
}

export interface CheckerOptions {
Expand Down

0 comments on commit 86f7940

Please sign in to comment.