Skip to content

Commit

Permalink
feat: add h3 auto imports preset (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Aug 8, 2022
1 parent 758b046 commit fbadeb7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
24 changes: 0 additions & 24 deletions src/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,5 @@ export const nitroImports: Preset[] = [
'nitroPlugin',
'defineRenderHandler'
]
},
{
from: 'h3',
imports: [
'defineEventHandler',
'defineLazyEventHandler',
'eventHandler',
'lazyEventHandler',
'dynamicEventHandler',
'appendHeader',
'assertMethod',
'createError',
'handleCacheHeaders',
'isMethod',
'sendRedirect',
'useCookies',
'useCookie',
'deleteCookie',
'setCookie',
'useBody',
'useMethod',
'useQuery',
'useRawBody'
]
}
]
11 changes: 10 additions & 1 deletion src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { loadConfig } from 'c12'
import { klona } from 'klona/full'
import { camelCase } from 'scule'
import { defu } from 'defu'
import { resolveModuleExportNames, resolvePath as resovleModule } from 'mlly'
// import escapeRE from 'escape-string-regexp'
import { withLeadingSlash, withoutTrailingSlash, withTrailingSlash } from 'ufo'
import { isTest } from 'std-env'
import { resolvePath as resovleModule } from 'mlly'
import { resolvePath, detectTarget } from './utils'
import type { NitroConfig, NitroOptions } from './types'
import { runtimeDir, pkgDir } from './dirs'
Expand Down Expand Up @@ -152,6 +152,15 @@ export async function loadOptions (userConfig: NitroConfig = {}): Promise<NitroO
options.autoImport.exclude.push(options.buildDir)
}

// Add h3 auto imports preset
if (options.autoImport) {
const h3Exports = await resolveModuleExportNames('h3', { url: import.meta.url })
options.autoImport.presets.push({
from: 'h3',
imports: h3Exports.filter(n => !n.match(/^[A-Z]/) && n !== 'use')
})
}

options.baseURL = withLeadingSlash(withTrailingSlash(options.baseURL))
options.runtimeConfig = defu(options.runtimeConfig, {
app: {
Expand Down

0 comments on commit fbadeb7

Please sign in to comment.