@@ -38,7 +38,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
3838 }
3939 }
4040
41- const nitroConfig : NitroConfig = defu ( _nitroConfig , < NitroConfig > {
41+ const nitroConfig : NitroConfig = defu ( _nitroConfig , {
4242 static : nuxt . options . _generate ,
4343 debug : nuxt . options . debug ,
4444 rootDir : nuxt . options . rootDir ,
@@ -47,7 +47,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
4747 dev : nuxt . options . dev ,
4848 buildDir : nuxt . options . buildDir ,
4949 imports : {
50- autoImport : nuxt . options . imports . autoImport ,
50+ autoImport : nuxt . options . imports . autoImport as boolean ,
5151 imports : [
5252 {
5353 as : '__buildAssetsURL' ,
@@ -112,7 +112,12 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
112112 typescript : {
113113 strict : true ,
114114 generateTsConfig : true ,
115- tsconfigPath : 'tsconfig.server.json'
115+ tsconfigPath : 'tsconfig.server.json' ,
116+ tsConfig : {
117+ include : [
118+ join ( nuxt . options . buildDir , 'types/nitro-nuxt.d.ts' )
119+ ]
120+ }
116121 } ,
117122 publicAssets : [
118123 nuxt . options . dev
@@ -143,7 +148,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
143148 '@nuxt/' ,
144149 nuxt . options . buildDir
145150 ] ) ,
146- ...nuxt . options . build . transpile . filter ( i => typeof i === 'string' ) ,
151+ ...nuxt . options . build . transpile . filter ( ( i ) : i is string => typeof i === 'string' ) ,
147152 'nuxt/dist' ,
148153 'nuxt3/dist' ,
149154 distDir
@@ -202,7 +207,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
202207 output : { } ,
203208 plugins : [ ]
204209 }
205- } )
210+ } satisfies NitroConfig )
206211
207212 // Resolve user-provided paths
208213 nitroConfig . srcDir = resolve ( nuxt . options . rootDir , nuxt . options . srcDir , nitroConfig . srcDir ! )
@@ -256,6 +261,30 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
256261 // Extend nitro config with hook
257262 await nuxt . callHook ( 'nitro:config' , nitroConfig )
258263
264+ // TODO: extract to shared utility?
265+ const excludedAlias = [ / ^ @ v u e \/ .* $ / , '#imports' , '#vue-router' , 'vue-demi' , / ^ # a p p / ]
266+ const basePath = nitroConfig . typescript ! . tsConfig ! . compilerOptions ?. baseUrl ? resolve ( nuxt . options . buildDir , nitroConfig . typescript ! . tsConfig ! . compilerOptions ?. baseUrl ) : nuxt . options . buildDir
267+ const aliases = nitroConfig . alias !
268+ const tsConfig = nitroConfig . typescript ! . tsConfig !
269+ tsConfig . compilerOptions = tsConfig . compilerOptions || { }
270+ tsConfig . compilerOptions . paths = tsConfig . compilerOptions . paths || { }
271+ for ( const _alias in aliases ) {
272+ const alias = _alias as keyof typeof aliases
273+ if ( excludedAlias . some ( pattern => typeof pattern === 'string' ? alias === pattern : pattern . test ( alias ) ) ) {
274+ continue
275+ }
276+ if ( alias in tsConfig . compilerOptions . paths ) { continue }
277+
278+ const absolutePath = resolve ( basePath , aliases [ alias ] ! )
279+ const stats = await fsp . stat ( absolutePath ) . catch ( ( ) => null /* file does not exist */ )
280+ if ( stats ?. isDirectory ( ) ) {
281+ tsConfig . compilerOptions . paths [ alias ] = [ absolutePath ]
282+ tsConfig . compilerOptions . paths [ `${ alias } /*` ] = [ `${ absolutePath } /*` ]
283+ } else {
284+ tsConfig . compilerOptions . paths [ alias ] = [ absolutePath . replace ( / (?< = \w ) \. \w + $ / g, '' ) ] /* remove extension */
285+ }
286+ }
287+
259288 // Init nitro
260289 const nitro = await createNitro ( nitroConfig )
261290
0 commit comments