@@ -4,14 +4,21 @@ import type { Import } from 'unimport'
4
4
import type { Nuxt } from '@nuxt/schema'
5
5
import { relative , resolve } from 'pathe'
6
6
import { getPort } from 'get-port-please'
7
- import type { ESLintPluginAddon } from '../types'
7
+ import type { ESLintConfigGenAddon } from '../types'
8
8
import type { NuxtESLintConfigOptions } from '@nuxt/eslint-config/flat'
9
9
import { ConfigGenOptions , ModuleOptions } from '../module'
10
+ import { createAddonGlobals } from '../config-addons/globals'
10
11
11
- export function setupConfigGen ( options : ModuleOptions , nuxt : Nuxt ) {
12
- const addons : ESLintPluginAddon [ ] = [ ]
12
+ export async function setupConfigGen ( options : ModuleOptions , nuxt : Nuxt ) {
13
+ const addons : ESLintConfigGenAddon [ ] = [
14
+ createAddonGlobals ( nuxt ) ,
15
+ ]
13
16
14
17
// TODO: hook to add more addons
18
+ // nuxt.hook('app:resolve', async () => {
19
+ // await nuxt.callHook('eslint:config:addons', addons)
20
+ // })
21
+
15
22
addTemplate ( {
16
23
filename : 'eslint.config.mjs' ,
17
24
write : true ,
@@ -23,9 +30,9 @@ export function setupConfigGen(options: ModuleOptions, nuxt: Nuxt) {
23
30
setupDevToolsIntegration ( nuxt )
24
31
}
25
32
26
- function generateESLintConfig ( options : ModuleOptions , nuxt : Nuxt , addons : ESLintPluginAddon [ ] ) {
33
+ async function generateESLintConfig ( options : ModuleOptions , nuxt : Nuxt , addons : ESLintConfigGenAddon [ ] ) {
27
34
const importLines : Import [ ] = [ ]
28
- const configLines : string [ ] = [ ]
35
+ const configItems : string [ ] = [ ]
29
36
30
37
const config : ConfigGenOptions = {
31
38
standalone : true ,
@@ -46,22 +53,27 @@ function generateESLintConfig(options: ModuleOptions, nuxt: Nuxt, addons: ESLint
46
53
dirs : getDirs ( nuxt ) ,
47
54
}
48
55
49
- configLines . push ( `...createConfigForNuxt(\n ${ JSON . stringify ( basicOptions , null , 2 ) } \n), ` )
56
+ configItems . push ( `// Nuxt Configs\n ...createConfigForNuxt(${ JSON . stringify ( basicOptions , null , 2 ) } ) ` )
50
57
51
- for ( const mod of addons ) {
52
- importLines . push ( ...mod . imports )
53
- configLines . push ( ...mod . configs )
58
+ for ( const addon of addons ) {
59
+ const resolved = await addon ( )
60
+ if ( resolved ?. imports )
61
+ importLines . push ( ...resolved . imports )
62
+ if ( resolved ?. configs )
63
+ configItems . push ( ...resolved . configs )
54
64
}
55
65
56
66
return [
57
67
'// ESLint config generated by Nuxt' ,
58
68
stringifyImports ( importLines , false ) ,
69
+ '' ,
59
70
`export default [` ,
60
- ... configLines ,
71
+ configItems . join ( ',\n\n' ) ,
61
72
`]` ,
62
73
'' ,
63
74
] . join ( '\n' )
64
75
}
76
+
65
77
function setupDevToolsIntegration ( nuxt : Nuxt ) {
66
78
let viewerProcess : ReturnType < typeof import ( '@nuxt/devtools-kit' ) [ 'startSubprocess' ] > | undefined
67
79
let viewerPort : number | undefined
@@ -124,6 +136,7 @@ function setupDevToolsIntegration(nuxt: Nuxt) {
124
136
} )
125
137
} )
126
138
}
139
+
127
140
function getDirs ( nuxt : Nuxt ) : NuxtESLintConfigOptions [ 'dirs' ] {
128
141
const dirs : Required < NuxtESLintConfigOptions [ 'dirs' ] > = {
129
142
pages : [ ] ,
0 commit comments