fix(nuxt): handle subpaths more correctly

This commit is contained in:
Daniel Roe 2024-06-20 19:57:05 +01:00
parent f2868f8c72
commit b279849631
No known key found for this signature in database
GPG Key ID: CBC814C393D93268

View File

@ -99,12 +99,12 @@ async function initNuxt (nuxt: Nuxt) {
const packageJSON = await readPackageJSON(nuxt.options.rootDir).catch(() => ({}) as PackageJson)
const dependencies = new Set([...Object.keys(packageJSON.dependencies || {}), ...Object.keys(packageJSON.devDependencies || {})])
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 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) {
try {
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
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)
if (path) {
return [[pkg, [path]], [nightly + subpath, [path]]]
}
}
const path = await resolveTypePath(pkg + subpath)
const path = await resolveTypePath(_pkg + subpath)
if (path) {
return [[pkg, [path]]]
}