mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(core,kit): ensure module transpilation paths are dirs (#20396)
This commit is contained in:
parent
526852c1f1
commit
5febd46d23
@ -1,4 +1,6 @@
|
||||
import { lstatSync } from 'node:fs'
|
||||
import type { Nuxt, NuxtModule } from '@nuxt/schema'
|
||||
import { dirname, isAbsolute } from 'pathe'
|
||||
import { isNuxt2 } from '../compatibility'
|
||||
import { useNuxt } from '../context'
|
||||
import { requireModule, resolveModule } from '../internal/cjs'
|
||||
@ -22,7 +24,7 @@ export async function installModule (moduleToInstall: string | NuxtModule, _inli
|
||||
}
|
||||
|
||||
if (typeof moduleToInstall === 'string') {
|
||||
nuxt.options.build.transpile.push(moduleToInstall)
|
||||
nuxt.options.build.transpile.push(normalizeModuleTranspilePath(moduleToInstall))
|
||||
}
|
||||
|
||||
nuxt.options._installedModules = nuxt.options._installedModules || []
|
||||
@ -35,6 +37,17 @@ export async function installModule (moduleToInstall: string | NuxtModule, _inli
|
||||
|
||||
// --- Internal ---
|
||||
|
||||
export const normalizeModuleTranspilePath = (p: string) => {
|
||||
try {
|
||||
// we need to target directories instead of module file paths themselves
|
||||
// /home/user/project/node_modules/module/index.js -> /home/user/project/node_modules/module
|
||||
p = isAbsolute(p) && lstatSync(p).isFile() ? dirname(p) : p
|
||||
} catch (e) {
|
||||
// maybe the path is absolute but does not exist, allow this to bubble up
|
||||
}
|
||||
return p.split('node_modules/').pop() as string
|
||||
}
|
||||
|
||||
async function normalizeModule (nuxtModule: string | NuxtModule, inlineOptions?: any) {
|
||||
const nuxt = useNuxt()
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { useNuxt } from '@nuxt/kit'
|
||||
import { normalizeModuleTranspilePath, useNuxt } from '@nuxt/kit'
|
||||
|
||||
export interface AddModuleTranspilesOptions {
|
||||
additionalModules?: string[]
|
||||
@ -14,7 +14,7 @@ export const addModuleTranspiles = (opts: AddModuleTranspilesOptions = {}) => {
|
||||
]
|
||||
.map(m => typeof m === 'string' ? m : Array.isArray(m) ? m[0] : m.src)
|
||||
.filter(m => typeof m === 'string')
|
||||
.map(m => m.split('node_modules/').pop())
|
||||
.map(normalizeModuleTranspilePath)
|
||||
|
||||
// Try to sanitize modules to better match imports
|
||||
nuxt.options.build.transpile =
|
||||
|
Loading…
Reference in New Issue
Block a user