mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fix(nuxt): handle subpaths more correctly
This commit is contained in:
parent
f2868f8c72
commit
b279849631
@ -99,12 +99,12 @@ async function initNuxt (nuxt: Nuxt) {
|
|||||||
const packageJSON = await readPackageJSON(nuxt.options.rootDir).catch(() => ({}) as PackageJson)
|
const packageJSON = await readPackageJSON(nuxt.options.rootDir).catch(() => ({}) as PackageJson)
|
||||||
const dependencies = new Set([...Object.keys(packageJSON.dependencies || {}), ...Object.keys(packageJSON.devDependencies || {})])
|
const dependencies = new Set([...Object.keys(packageJSON.dependencies || {}), ...Object.keys(packageJSON.devDependencies || {})])
|
||||||
const paths = Object.fromEntries(await Promise.all(coreTypePackages.map(async (pkg) => {
|
const paths = Object.fromEntries(await Promise.all(coreTypePackages.map(async (pkg) => {
|
||||||
// ignore packages that exist in `package.json` as these can be resolved by TypeScript
|
|
||||||
if (dependencies.has(pkg) && !(pkg in nightlies)) { return [] }
|
|
||||||
|
|
||||||
const [_pkg = pkg, _subpath] = /^[^@]+\//.test(pkg) ? pkg.split('/') : [pkg]
|
const [_pkg = pkg, _subpath] = /^[^@]+\//.test(pkg) ? pkg.split('/') : [pkg]
|
||||||
const subpath = _subpath ? '/' + _subpath : ''
|
const subpath = _subpath ? '/' + _subpath : ''
|
||||||
|
|
||||||
|
// ignore packages that exist in `package.json` as these can be resolved by TypeScript
|
||||||
|
if (dependencies.has(_pkg) && !(_pkg in nightlies)) { return [] }
|
||||||
|
|
||||||
async function resolveTypePath (path: string) {
|
async function resolveTypePath (path: string) {
|
||||||
try {
|
try {
|
||||||
const r = await _resolvePath(path, { url: nuxt.options.modulesDir, conditions: ['types', 'import', 'require'] })
|
const r = await _resolvePath(path, { url: nuxt.options.modulesDir, conditions: ['types', 'import', 'require'] })
|
||||||
@ -120,14 +120,14 @@ async function initNuxt (nuxt: Nuxt) {
|
|||||||
|
|
||||||
// deduplicate types for nightly releases
|
// deduplicate types for nightly releases
|
||||||
if (_pkg in nightlies) {
|
if (_pkg in nightlies) {
|
||||||
const nightly = nightlies[pkg as keyof typeof nightlies]
|
const nightly = nightlies[_pkg as keyof typeof nightlies]
|
||||||
const path = await resolveTypePath(nightly + subpath)
|
const path = await resolveTypePath(nightly + subpath)
|
||||||
if (path) {
|
if (path) {
|
||||||
return [[pkg, [path]], [nightly + subpath, [path]]]
|
return [[pkg, [path]], [nightly + subpath, [path]]]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = await resolveTypePath(pkg + subpath)
|
const path = await resolveTypePath(_pkg + subpath)
|
||||||
if (path) {
|
if (path) {
|
||||||
return [[pkg, [path]]]
|
return [[pkg, [path]]]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user