Skip to content

Commit

Permalink
refactor(nuxi): extract nitro types to corresponding modules (nuxt#668)
Browse files Browse the repository at this point in the history
Co-authored-by: Pooya Parsa <pyapar@gmail.com>
  • Loading branch information
danielroe and pi0 authored Oct 7, 2021
1 parent accbe64 commit cc2279b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/bridge/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {} from '@nuxt/nitro'
import type { NuxtConfig as _NuxtConfig } from '@nuxt/kit'

export interface BridgeConfig {
Expand Down
8 changes: 1 addition & 7 deletions packages/nuxi/src/commands/prepare.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { promises as fsp } from 'fs'
import { relative, resolve } from 'pathe'
import { cyan } from 'colorette'
import { isNuxt3, TSReference } from '@nuxt/kit'
import { TSReference } from '@nuxt/kit'
import { importModule, getModulePaths, getNearestPackage } from '../utils/cjs'
import { success } from '../utils/log'
import { defineNuxtCommand } from './index'
Expand All @@ -19,15 +19,9 @@ export default defineNuxtCommand({
const { loadNuxt } = await importModule('@nuxt/kit', rootDir) as typeof import('@nuxt/kit')
const nuxt = await loadNuxt({ rootDir })

const adHocModules = isNuxt3()
? ['@nuxt/kit', '@nuxt/nitro']
: ['@nuxt/kit']

const modulePaths = getModulePaths(nuxt.options.modulesDir)

const references: TSReference[] = [
...isNuxt3() ? ['nuxt3'] : [],
...adHocModules,
...nuxt.options.buildModules,
...nuxt.options.modules,
...nuxt.options._modules
Expand Down
5 changes: 5 additions & 0 deletions packages/nuxt3/src/core/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ async function initNuxt (nuxt: Nuxt) {
// Init nitro
await initNitro(nuxt)

// Add nuxt3 types
nuxt.hook('prepare:types', (opts) => {
opts.references.push({ types: 'nuxt3' })
})

// Init user modules
await nuxt.callHook('modules:before', { nuxt } as ModuleContainer)
const modulesToInstall = [
Expand Down
1 change: 1 addition & 0 deletions packages/nuxt3/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import type { } from '@nuxt/nitro'
export * from './dist/index'
export * from './dist/app/types/index'
2 changes: 0 additions & 2 deletions playground/nuxt.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Please do not manually modify this file.

/// <reference types="nuxt3" />
/// <reference types="@nuxt/kit" />
/// <reference types="@nuxt/nitro" />
/// <reference path=".nuxt/components.d.ts" />
/// <reference path=".nuxt/global-imports.d.ts" />
export {}

0 comments on commit cc2279b

Please sign in to comment.