File tree 2 files changed +15
-5
lines changed
2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -4,22 +4,32 @@ import type { Linter } from 'eslint'
4
4
import type { ESLintConfigGenAddon } from '../../../types'
5
5
6
6
export function createAddonGlobals ( nuxt : Nuxt ) : ESLintConfigGenAddon {
7
- let unimport : Unimport
7
+ let unimport : Unimport | undefined
8
+ let nitroUnimport : Unimport | undefined
8
9
9
10
nuxt . hook ( 'imports:context' , ( context ) => {
10
11
unimport = context
11
12
} )
12
13
14
+ nuxt . hook ( 'nitro:init' , ( nitro ) => {
15
+ nitroUnimport = nitro . unimport
16
+ } )
17
+
13
18
return {
14
19
name : 'nuxt:eslint:import-globals' ,
15
20
async getConfigs ( ) {
21
+ const imports = [
22
+ ...await unimport ?. getImports ( ) || [ ] ,
23
+ ...await nitroUnimport ?. getImports ( ) || [ ] ,
24
+ ]
25
+
16
26
return {
17
27
configs : [
18
- '// Set globals from imports registry\n'
19
- + JSON . stringify ( < Linter . Config > {
28
+ '// Set globals from imports registry' ,
29
+ JSON . stringify ( < Linter . Config > {
20
30
name : 'nuxt/import-globals' ,
21
31
languageOptions : {
22
- globals : Object . fromEntries ( ( await unimport . getImports ( ) ) . map ( i => [ i . as || i . name , 'readonly' ] ) ) ,
32
+ globals : Object . fromEntries ( imports . map ( i => [ i . as || i . name , 'readonly' ] ) ) ,
23
33
} ,
24
34
} ) ,
25
35
] ,
Original file line number Diff line number Diff line change @@ -123,7 +123,7 @@ export interface ESLintConfigGenAddonResult {
123
123
*/
124
124
imports ?: Import [ ]
125
125
/**
126
- * Flat config items, should be stringified
126
+ * Flat config items, should be stringified lines
127
127
*/
128
128
configs ?: string [ ]
129
129
}
You can’t perform that action at this time.
0 commit comments