Skip to content

Commit 533fa40

Browse files
committedJul 27, 2024··
feat: include nitro unimport to globals as well, close #461
1 parent 77bc797 commit 533fa40

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed
 

‎packages/module/src/modules/config/addons/globals.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,32 @@ import type { Linter } from 'eslint'
44
import type { ESLintConfigGenAddon } from '../../../types'
55

66
export function createAddonGlobals(nuxt: Nuxt): ESLintConfigGenAddon {
7-
let unimport: Unimport
7+
let unimport: Unimport | undefined
8+
let nitroUnimport: Unimport | undefined
89

910
nuxt.hook('imports:context', (context) => {
1011
unimport = context
1112
})
1213

14+
nuxt.hook('nitro:init', (nitro) => {
15+
nitroUnimport = nitro.unimport
16+
})
17+
1318
return {
1419
name: 'nuxt:eslint:import-globals',
1520
async getConfigs() {
21+
const imports = [
22+
...await unimport?.getImports() || [],
23+
...await nitroUnimport?.getImports() || [],
24+
]
25+
1626
return {
1727
configs: [
18-
'// Set globals from imports registry\n'
19-
+ JSON.stringify(<Linter.Config>{
28+
'// Set globals from imports registry',
29+
JSON.stringify(<Linter.Config>{
2030
name: 'nuxt/import-globals',
2131
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'])),
2333
},
2434
}),
2535
],

‎packages/module/src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export interface ESLintConfigGenAddonResult {
123123
*/
124124
imports?: Import[]
125125
/**
126-
* Flat config items, should be stringified
126+
* Flat config items, should be stringified lines
127127
*/
128128
configs?: string[]
129129
}

0 commit comments

Comments
 (0)
Please sign in to comment.