Skip to content

Commit 7bfb780

Browse files
committedApr 18, 2024·
fix(module): use relative path in the generate eslint.config, fix #395
1 parent 17c823e commit 7bfb780

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed
 

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fileURLToPath, pathToFileURL } from 'node:url'
1+
import { fileURLToPath } from 'node:url'
22
import { builtinModules } from 'node:module'
33
import fs from 'node:fs/promises'
44
import { addTemplate, createResolver, logger } from '@nuxt/kit'
@@ -112,6 +112,8 @@ async function generateESLintConfig(options: ModuleOptions, nuxt: Nuxt, addons:
112112
const importLines: Import[] = []
113113
const configItems: string[] = []
114114

115+
const configDir = nuxt.options.buildDir
116+
115117
const config: ConfigGenOptions = {
116118
standalone: true,
117119
...typeof options.config !== 'boolean' ? options.config || {} : {},
@@ -156,12 +158,17 @@ async function generateESLintConfig(options: ModuleOptions, nuxt: Nuxt, addons:
156158
configItems.push(...resolved.configs)
157159
}
158160

161+
function relativeWithDot(path: string) {
162+
const r = relative(configDir, path)
163+
return r.startsWith('.') ? r : './' + r
164+
}
165+
159166
const imports = await Promise.all(importLines.map(async (line): Promise<Import> => {
160167
return {
161168
...line,
162169
from: (line.from.match(/^\w+:/) || builtinModules.includes(line.from))
163170
? line.from
164-
: pathToFileURL(await r.resolvePath(line.from)).toString(),
171+
: relativeWithDot(await r.resolvePath(line.from)),
165172
}
166173
}))
167174

0 commit comments

Comments
 (0)
Please sign in to comment.