Skip to content

Commit 78243a9

Browse files
fix(vite): gracefully handle missing package manifest (#151)
1 parent 5afeb27 commit 78243a9

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

packages/vite/src/app/components/packages/Table.vue

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type { PackageInfo, SessionContext } from '~~/shared/types'
33
import { useRoute } from '#app/composables/router'
44
import { useCycleList } from '@vueuse/core'
5-
import { Menu as VMenu } from 'floating-vue'
5+
import { Tooltip, Menu as VMenu } from 'floating-vue'
66
import { settings } from '~~/app/state/settings'
77
88
withDefaults(defineProps<{
@@ -69,9 +69,23 @@ function toggleSizeSortType() {
6969
:class="[index === packages.length - 1 ? 'border-b-0' : '']"
7070
:to="{ path: route.path, query: { package: `${item.name}@${item.version}` } }"
7171
>
72-
<div v-if="!groupView" role="cell" font-mono flex-none min-w80 py1.5 px2 ws-nowrap text-sm>
73-
<DisplayHighlightedPackageName :name="item.name" />
74-
</div>
72+
<Tooltip
73+
:triggers="['hover']"
74+
:delay="1200"
75+
:disabled="item.name.length < 30"
76+
>
77+
<div
78+
v-if="!groupView" role="cell" font-mono flex-none w80 py1.5 px2 ws-nowrap text-sm overflow-hidden
79+
truncate
80+
>
81+
<DisplayHighlightedPackageName :name="item.name" />
82+
</div>
83+
<template #popper>
84+
<span font-mono text-sm>
85+
{{ item.name }}
86+
</span>
87+
</template>
88+
</Tooltip>
7589
<div role="cell" flex="~ items-center" text-left flex-none font-mono py1.5 px2 text-sm min-w40 op80 :class="{ 'text-primary': item.duplicated }">
7690
{{ item.version }}
7791
</div>

packages/vite/src/node/rpc/functions/rolldown-get-packages.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,21 @@ export async function getPackagesManifest(reader: RolldownEventsReader) {
4242
}
4343
})
4444
await Promise.all(packages.map(async (p) => {
45-
const manifest = await readProjectManifestOnly(p.dir)
46-
const packageKey = `${manifest.name!}@${manifest.version!}`
45+
let packageKey = ''
46+
let manifest = null
47+
48+
try {
49+
manifest = await readProjectManifestOnly(p.dir)
50+
packageKey = `${manifest.name!}@${manifest.version!}`
51+
}
52+
catch (err: any) {
53+
if (err?.code === 'ERR_PNPM_NO_IMPORTER_MANIFEST_FOUND') {
54+
packageKey = `${p.dir}`
55+
}
56+
else {
57+
throw err
58+
}
59+
}
4760
const packageInfo = packagesManifest.get(packageKey)
4861
const importers = getImporters(p.path, p.dir).map(i => ({ path: i, version: '' }))
4962
if (packageInfo) {
@@ -59,8 +72,8 @@ export async function getPackagesManifest(reader: RolldownEventsReader) {
5972
}
6073
else {
6174
packagesManifest.set(packageKey, {
62-
name: manifest.name!,
63-
version: manifest.version!,
75+
name: manifest?.name || p.dir,
76+
version: manifest?.version || '(unknown)',
6477
dir: p.dir,
6578
files: [{
6679
path: p.path,
@@ -101,7 +114,17 @@ export const rolldownGetPackages = defineRpcFunction({
101114
if (duplicated) {
102115
files = await Promise.all(files.map(async (f) => {
103116
const importers = await Promise.all(f.importers.map(async (i) => {
104-
const manifest = isNodeModulePath(i.path) ? await readProjectManifestOnly(getPackageDirPath(i.path)) : null
117+
let manifest = null
118+
try {
119+
if (isNodeModulePath(i.path)) {
120+
manifest = await readProjectManifestOnly(getPackageDirPath(i.path))
121+
}
122+
}
123+
catch (err: any) {
124+
if (err?.code !== 'ERR_PNPM_NO_IMPORTER_MANIFEST_FOUND') {
125+
throw err
126+
}
127+
}
105128
return { ...i, version: manifest?.version ?? '' }
106129
}))
107130
return { ...f, importers }

0 commit comments

Comments
 (0)