mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
fix: strip file extensions in imports.d.ts
(#3540)
This commit is contained in:
parent
d404484c61
commit
02e683d33f
@ -107,6 +107,9 @@ export default defineNuxtModule<AutoImportsOptions>({
|
|||||||
function addDeclarationTemplates (ctx: AutoImportContext) {
|
function addDeclarationTemplates (ctx: AutoImportContext) {
|
||||||
const nuxt = useNuxt()
|
const nuxt = useNuxt()
|
||||||
|
|
||||||
|
// Remove file extension for benefit of TypeScript
|
||||||
|
const stripExtension = (path: string) => path.replace(/\.[a-z]+$/, '')
|
||||||
|
|
||||||
const resolved = {}
|
const resolved = {}
|
||||||
const r = (id: string) => {
|
const r = (id: string) => {
|
||||||
if (resolved[id]) { return resolved[id] }
|
if (resolved[id]) { return resolved[id] }
|
||||||
@ -114,15 +117,14 @@ function addDeclarationTemplates (ctx: AutoImportContext) {
|
|||||||
if (isAbsolute(path)) {
|
if (isAbsolute(path)) {
|
||||||
path = relative(join(nuxt.options.buildDir, 'types'), path)
|
path = relative(join(nuxt.options.buildDir, 'types'), path)
|
||||||
}
|
}
|
||||||
// Remove file extension for benefit of TypeScript
|
path = stripExtension(path)
|
||||||
path = path.replace(/\.[a-z]+$/, '')
|
|
||||||
resolved[id] = path
|
resolved[id] = path
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
addTemplate({
|
addTemplate({
|
||||||
filename: 'imports.d.ts',
|
filename: 'imports.d.ts',
|
||||||
getContents: () => toExports(ctx.autoImports)
|
getContents: () => toExports(ctx.autoImports.map(i => ({ ...i, from: stripExtension(i.from) })))
|
||||||
})
|
})
|
||||||
|
|
||||||
addTemplate({
|
addTemplate({
|
||||||
|
Loading…
Reference in New Issue
Block a user