Skip to content

Commit

Permalink
fix: windows path resolution (#369)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Mar 29, 2024
1 parent e6dd7b2 commit 2efd732
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions packages/module/src/modules/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addTemplate, tryResolveModule } from '@nuxt/kit'
import { addTemplate, createResolver } from '@nuxt/kit'
import { stringifyImports } from 'unimport'
import type { Import } from 'unimport'
import type { Nuxt } from '@nuxt/schema'
Expand All @@ -8,9 +8,10 @@ import type { ESLintConfigGenAddon } from '../types'
import type { NuxtESLintConfigOptions } from '@nuxt/eslint-config/flat'
import type { ConfigGenOptions, ModuleOptions } from '../module'
import { createAddonGlobals } from '../config-addons/globals'
import { isAbsolute } from 'path'
import { pathToFileURL } from 'url'

const r = createResolver(import.meta.url)

export async function setupConfigGen(options: ModuleOptions, nuxt: Nuxt) {
const defaultAddons = [
createAddonGlobals(nuxt),
Expand Down Expand Up @@ -97,16 +98,10 @@ async function generateESLintConfig(options: ModuleOptions, nuxt: Nuxt, addons:
configItems.push(...resolved.configs)
}

async function resolveModule(id: string) {
if (id && (id.includes('://') || isAbsolute(id)))
return id
return await tryResolveModule(id, import.meta.url) || id
}

const imports = await Promise.all(importLines.map(async (line): Promise<Import> => {
return {
...line,
from: pathToFileURL(await resolveModule(line.from)).toString(),
from: pathToFileURL(await r.resolvePath(line.from)).toString(),
}
}))

Expand Down

0 comments on commit 2efd732

Please sign in to comment.