From 980728275a7bfab0fef40d6d8ba045ebc1c0b1a6 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sat, 20 May 2023 23:29:32 +0100 Subject: [PATCH] fix(nuxt): use `resolvePath` to handle edge cases for modules (#20975) --- packages/kit/src/module/install.ts | 10 +++------- test/fixtures/basic/nuxt.config.ts | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/kit/src/module/install.ts b/packages/kit/src/module/install.ts index 44da958f74..81750194d9 100644 --- a/packages/kit/src/module/install.ts +++ b/packages/kit/src/module/install.ts @@ -1,11 +1,11 @@ import { lstatSync } from 'node:fs' import type { Nuxt, NuxtModule } from '@nuxt/schema' -import { dirname, isAbsolute, normalize, resolve } from 'pathe' +import { dirname, isAbsolute } from 'pathe' import { isNuxt2 } from '../compatibility' import { useNuxt } from '../context' import { requireModule } from '../internal/cjs' import { importModule } from '../internal/esm' -import { resolveAlias } from '../resolve' +import { resolveAlias, resolvePath } from '../resolve' /** Installs a module on a Nuxt instance. */ export async function installModule (moduleToInstall: string | NuxtModule, _inlineOptions?: any, _nuxt?: Nuxt) { @@ -53,11 +53,7 @@ async function normalizeModule (nuxtModule: string | NuxtModule, inlineOptions?: // Import if input is string if (typeof nuxtModule === 'string') { - let src = resolveAlias(nuxtModule) - if (src.match(/^\.{1,2}\//)) { - src = resolve(nuxt.options.rootDir, src) - } - src = normalize(src) + const src = await resolvePath(nuxtModule) try { // Prefer ESM resolution if possible nuxtModule = await importModule(src, nuxt.options.modulesDir).catch(() => null) ?? requireModule(src, { paths: nuxt.options.modulesDir }) diff --git a/test/fixtures/basic/nuxt.config.ts b/test/fixtures/basic/nuxt.config.ts index 0e588c0361..c4b074af61 100644 --- a/test/fixtures/basic/nuxt.config.ts +++ b/test/fixtures/basic/nuxt.config.ts @@ -80,7 +80,7 @@ export default defineNuxtConfig({ } }, modules: [ - './modules/test/index', + './modules/test', [ '~/modules/example', {