mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
fix(nuxt): support hoisting types of subpath imports (#27720)
This commit is contained in:
parent
bbcab053bc
commit
18f0724402
@ -102,18 +102,34 @@ async function initNuxt (nuxt: Nuxt) {
|
|||||||
// ignore packages that exist in `package.json` as these can be resolved by TypeScript
|
// ignore packages that exist in `package.json` as these can be resolved by TypeScript
|
||||||
if (dependencies.has(pkg) && !(pkg in nightlies)) { return [] }
|
if (dependencies.has(pkg) && !(pkg in nightlies)) { return [] }
|
||||||
|
|
||||||
// deduplicate types for nightly releases
|
const [_pkg = pkg, _subpath] = /^[^@]+\//.test(pkg) ? pkg.split('/') : [pkg]
|
||||||
if (pkg in nightlies) {
|
const subpath = _subpath ? '/' + _subpath : ''
|
||||||
const nightly = nightlies[pkg as keyof typeof nightlies]
|
|
||||||
const path = await _resolvePath(nightly, { url: nuxt.options.modulesDir }).then(r => resolvePackageJSON(r)).catch(() => null)
|
async function resolveTypePath (path: string) {
|
||||||
if (path) {
|
try {
|
||||||
return [[pkg, [dirname(path)]], [nightly, [dirname(path)]]]
|
const r = await _resolvePath(path, { url: nuxt.options.modulesDir, conditions: ['types', 'import', 'require'] })
|
||||||
|
if (subpath) {
|
||||||
|
return r.replace(/(?:\.d)?\.[mc]?[jt]s$/, '')
|
||||||
|
}
|
||||||
|
const rootPath = await resolvePackageJSON(r)
|
||||||
|
return dirname(rootPath)
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = await _resolvePath(pkg, { url: nuxt.options.modulesDir }).then(r => resolvePackageJSON(r)).catch(() => null)
|
// deduplicate types for nightly releases
|
||||||
|
if (_pkg in nightlies) {
|
||||||
|
const nightly = nightlies[pkg as keyof typeof nightlies]
|
||||||
|
const path = await resolveTypePath(nightly + subpath)
|
||||||
if (path) {
|
if (path) {
|
||||||
return [[pkg, [dirname(path)]]]
|
return [[pkg, [path]], [nightly + subpath, [path]]]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const path = await resolveTypePath(pkg + subpath)
|
||||||
|
if (path) {
|
||||||
|
return [[pkg, [path]]]
|
||||||
}
|
}
|
||||||
|
|
||||||
return []
|
return []
|
||||||
|
@ -47,6 +47,7 @@ export default defineUntypedSchema({
|
|||||||
'@vue/compiler-sfc',
|
'@vue/compiler-sfc',
|
||||||
'@vue/runtime-dom',
|
'@vue/runtime-dom',
|
||||||
'vue-router',
|
'vue-router',
|
||||||
|
'vue-router/auto',
|
||||||
'@nuxt/schema',
|
'@nuxt/schema',
|
||||||
'nuxt',
|
'nuxt',
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user