@@ -4,7 +4,8 @@ import type { LoadNuxtOptions } from '@nuxt/kit'
4
4
import { addBuildPlugin , addComponent , addPlugin , addRouteMiddleware , addServerPlugin , addVitePlugin , addWebpackPlugin , installModule , loadNuxtConfig , logger , nuxtCtx , resolveAlias , resolveFiles , resolvePath , tryResolveModule , useNitro } from '@nuxt/kit'
5
5
import { resolvePath as _resolvePath } from 'mlly'
6
6
import type { Nuxt , NuxtHooks , NuxtOptions } from 'nuxt/schema'
7
- import { resolvePackageJSON } from 'pkg-types'
7
+ import type { PackageJson } from 'pkg-types'
8
+ import { readPackageJSON , resolvePackageJSON } from 'pkg-types'
8
9
9
10
import escapeRE from 'escape-string-regexp'
10
11
import fse from 'fs-extra'
@@ -51,6 +52,14 @@ export function createNuxt (options: NuxtOptions): Nuxt {
51
52
return nuxt
52
53
}
53
54
55
+ const nightlies = {
56
+ nitropack : 'nitropack-nightly' ,
57
+ h3 : 'h3-nightly' ,
58
+ nuxt : 'nuxt-nightly' ,
59
+ '@nuxt/schema' : '@nuxt/schema-nightly' ,
60
+ '@nuxt/kit' : '@nuxt/kit-nightly'
61
+ }
62
+
54
63
async function initNuxt ( nuxt : Nuxt ) {
55
64
// Register user hooks
56
65
for ( const config of nuxt . options . _layers . map ( layer => layer . config ) . reverse ( ) ) {
@@ -64,11 +73,28 @@ async function initNuxt (nuxt: Nuxt) {
64
73
nuxt . hook ( 'close' , ( ) => nuxtCtx . unset ( ) )
65
74
66
75
const coreTypePackages = nuxt . options . typescript . hoist || [ ]
76
+ const packageJSON = await readPackageJSON ( nuxt . options . rootDir ) . catch ( ( ) => ( { } ) as PackageJson )
77
+ const dependencies = new Set ( [ ...Object . keys ( packageJSON . dependencies || { } ) , ...Object . keys ( packageJSON . devDependencies || { } ) ] )
67
78
const paths = Object . fromEntries ( await Promise . all ( coreTypePackages . map ( async ( pkg ) => {
79
+ // ignore packages that exist in `package.json` as these can be resolved by TypeScript
80
+ if ( dependencies . has ( pkg ) && ! ( pkg in nightlies ) ) { return [ ] }
81
+
82
+ // deduplicate types for nightly releases
83
+ if ( pkg in nightlies ) {
84
+ const nightly = nightlies [ pkg as keyof typeof nightlies ]
85
+ const path = await _resolvePath ( nightly , { url : nuxt . options . modulesDir } ) . then ( r => resolvePackageJSON ( r ) ) . catch ( ( ) => null )
86
+ if ( path ) {
87
+ return [ [ pkg , [ dirname ( path ) ] ] , [ nightly , [ dirname ( path ) ] ] ]
88
+ }
89
+ }
90
+
68
91
const path = await _resolvePath ( pkg , { url : nuxt . options . modulesDir } ) . then ( r => resolvePackageJSON ( r ) ) . catch ( ( ) => null )
69
- if ( ! path ) { return }
70
- return [ pkg , [ dirname ( path ) ] ]
71
- } ) ) . then ( r => r . filter ( Boolean ) as [ string , [ string ] ] [ ] ) )
92
+ if ( path ) {
93
+ return [ [ pkg , [ dirname ( path ) ] ] ]
94
+ }
95
+
96
+ return [ ]
97
+ } ) ) . then ( r => r . flat ( ) ) )
72
98
73
99
// Set nitro resolutions for types that might be obscured with shamefully-hoist=false
74
100
nuxt . options . nitro . typescript = defu ( nuxt . options . nitro . typescript , {
0 commit comments