Skip to content

Commit

Permalink
fix: use build aliases and set declaration as ts file
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Huang committed Mar 15, 2024
1 parent 123253b commit 31595da
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default defineNuxtModule<ModuleOptions>({
})

addImportsSources({
from: resolve(nuxt.options.buildDir, `${moduleName}.d.ts`),
from: resolve(nuxt.options.buildDir, `${moduleName}.ts`),
imports: schemas.flatMap(({ fetchName }) => Object.values(fetchName)),
})

Expand Down Expand Up @@ -152,12 +152,12 @@ export default defineNuxtModule<ModuleOptions>({
}])

addTemplate({
filename: `${moduleName}.d.ts`,
filename: `${moduleName}.ts`,
getContents() {
return `
import { createUseOpenFetch } from './imports.d.ts'
import { createUseOpenFetch } from '#imports'
${schemas.map(({ name }) => `
import type { paths as ${pascalCase(name)}Paths } from './types/${moduleName}/schemas/${kebabCase(name)}.d.ts'
import type { paths as ${pascalCase(name)}Paths } from '#build/types/${moduleName}/schemas/${kebabCase(name)}.d.ts'
`.trimStart()).join('').trimEnd()}
${schemas.length ? `export type OpenFetchClientName = ${schemas.map(({ name }) => `'${name}'`).join(' | ')}` : ''}
Expand Down Expand Up @@ -186,9 +186,9 @@ export const ${fetchName.lazyComposable} = createUseOpenFetch<${pascalCase(name)
addTypeTemplate({
filename: `types/${moduleName}/nuxt.d.ts`,
getContents: () => `
import type { OpenFetchClient } from '../../imports.d.ts'
import type { OpenFetchClient } from '#imports'
${schemas.map(({ name }) => `
import type { paths as ${pascalCase(name)}Paths } from './schemas/${kebabCase(name)}.d.ts'
import type { paths as ${pascalCase(name)}Paths } from '#build/types/${moduleName}/schemas/${kebabCase(name)}.d.ts'
`.trimStart()).join('').trimEnd()}
declare module '#app' {
Expand All @@ -211,9 +211,9 @@ export {}
addTemplate({
filename: `types/${moduleName}/nitro.d.ts`,
getContents: () => `
import type { OpenFetchClient } from '../../imports.d.ts'
import type { OpenFetchClient } from '#imports'
${schemas.map(({ name }) => `
import type { paths as ${pascalCase(name)}Paths } from './schemas/${kebabCase(name)}.d.ts'
import type { paths as ${pascalCase(name)}Paths } from '#build/types/${moduleName}/schemas/${kebabCase(name)}.d.ts'
`.trimStart()).join('').trimEnd()}
declare module 'nitropack' {
Expand Down

0 comments on commit 31595da

Please sign in to comment.