Skip to content

Commit

Permalink
fix(module): use relative path in the generate eslint.config, fix #395
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Apr 18, 2024
1 parent 17c823e commit 7bfb780
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/module/src/modules/config.ts
@@ -1,4 +1,4 @@
import { fileURLToPath, pathToFileURL } from 'node:url'
import { fileURLToPath } from 'node:url'
import { builtinModules } from 'node:module'
import fs from 'node:fs/promises'
import { addTemplate, createResolver, logger } from '@nuxt/kit'
Expand Down Expand Up @@ -112,6 +112,8 @@ async function generateESLintConfig(options: ModuleOptions, nuxt: Nuxt, addons:
const importLines: Import[] = []
const configItems: string[] = []

const configDir = nuxt.options.buildDir

const config: ConfigGenOptions = {
standalone: true,
...typeof options.config !== 'boolean' ? options.config || {} : {},
Expand Down Expand Up @@ -156,12 +158,17 @@ async function generateESLintConfig(options: ModuleOptions, nuxt: Nuxt, addons:
configItems.push(...resolved.configs)
}

function relativeWithDot(path: string) {
const r = relative(configDir, path)
return r.startsWith('.') ? r : './' + r
}

const imports = await Promise.all(importLines.map(async (line): Promise<Import> => {
return {
...line,
from: (line.from.match(/^\w+:/) || builtinModules.includes(line.from))
? line.from
: pathToFileURL(await r.resolvePath(line.from)).toString(),
: relativeWithDot(await r.resolvePath(line.from)),
}
}))

Expand Down

0 comments on commit 7bfb780

Please sign in to comment.