Skip to content

Commit 40482d0

Browse files
committed
feat: exclude optional packages in the filters by default
1 parent 411b9bf commit 40482d0

File tree

6 files changed

+20
-3
lines changed

6 files changed

+20
-3
lines changed

packages/node-modules-inspector/src/app/components/display/ModuleType.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { PropType } from 'vue'
33
import { Tooltip as FloatingTooltip } from 'floating-vue'
44
import { computed, defineComponent, h } from 'vue'
55
import { settings } from '../../state/settings'
6-
import { getModuleType, MODULE_TYPES_COLOR_BADGE } from '../../utils/module-type'
6+
import { getModuleType, MODULE_TYPES_COLOR_BADGE, MODULE_TYPES_NAME } from '../../utils/module-type'
77

88
// @unocss-include
99

@@ -64,7 +64,7 @@ export default defineComponent({
6464
MODULE_TYPES_COLOR_BADGE[type.value],
6565
props.badge ? 'w-11 flex-none text-center px1 rounded text-sm' : 'bg-transparent! w-auto!',
6666
],
67-
}, type.value.toUpperCase()),
67+
}, MODULE_TYPES_NAME[type.value]),
6868
popper: () => h('div', { class: 'text-sm' }, description.value),
6969
})
7070
}

packages/node-modules-inspector/src/app/components/panel/FiltersOptionExcludes.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ import { filters } from '../../state/filters'
4343
<OptionItem title="Exclude Types Packages" description="Exclude TypeScript declaration packages">
4444
<OptionCheckbox v-model="filters.state.excludeDts" />
4545
</OptionItem>
46+
<OptionItem title="Exclude Optional Packages" description="Exclude optional packages">
47+
<OptionCheckbox v-model="filters.state.excludeOptional" />
48+
</OptionItem>
4649
<OptionItem title="Exclude Private Packages" description="Exclude private workspace packages and their dependencies">
4750
<OptionCheckbox v-model="filters.state.excludePrivate" />
4851
</OptionItem>

packages/node-modules-inspector/src/app/pages/grid/[...grid].vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useRoute } from '#app/composables/router'
44
import SafeImage from '@/components/display/SafeImage.vue'
55
import { computed } from 'vue'
66
import { payloads } from '../../state/payload'
7+
import { getModuleType } from '../../utils/module-type'
78
import { getAuthors, getPackageData, getRepository } from '../../utils/package-json'
89
910
const params = useRoute().params as Record<string, string>
@@ -24,7 +25,7 @@ const groups = computed<Group[]>(() => {
2425
if (tab.value === 'module-type') {
2526
const map = new Map<string, PackageNode[]>()
2627
for (const pkg of payloads.filtered.packages) {
27-
const type = pkg.resolved.module
28+
const type = getModuleType(pkg)
2829
if (!map.has(type))
2930
map.set(type, [])
3031
map.get(type)?.push(pkg)

packages/node-modules-inspector/src/app/state/filters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export function filtersExcludePredicate(pkg: PackageNode) {
4545
return true
4646
if (state.excludeDts && pkg.resolved.module === 'dts')
4747
return true
48+
if (state.excludeOptional && !pkg.filepath)
49+
return true
4850
if (state.excludePrivate && pkg.private)
4951
return true
5052
if (state.excludes?.length) {

packages/node-modules-inspector/src/app/utils/module-type.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ export const MODULE_TYPES_COLOR_BADGE = {
1515
unknown: 'badge-color-gray',
1616
}
1717

18+
export const MODULE_TYPES_NAME = {
19+
esm: 'ESM',
20+
dual: 'DUAL',
21+
cjs: 'CJS',
22+
faux: 'FAUX',
23+
dts: 'DTS',
24+
unknown: '?',
25+
}
26+
1827
export function getModuleType(node: PackageNode | PackageModuleType) {
1928
const type = typeof node === 'string' ? node : node.resolved.module
2029

packages/node-modules-inspector/src/shared/filters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface FilterOptions {
1212

1313
excludes: null | string[]
1414
excludeDts: boolean
15+
excludeOptional: boolean
1516
excludePrivate: boolean
1617
excludeWorkspace: boolean
1718

@@ -45,6 +46,7 @@ export const FILTERS_SCHEMA: {
4546
// Excludes
4647
excludes: { type: Array, default: null, category: 'exclude' },
4748
excludeDts: { type: Boolean, default: true, category: 'exclude' },
49+
excludeOptional: { type: Boolean, default: true, category: 'exclude' },
4850
excludePrivate: { type: Boolean, default: false, category: 'exclude' },
4951
excludeWorkspace: { type: Boolean, default: import.meta.env.BACKEND === 'webcontainer', category: 'exclude' },
5052
}

0 commit comments

Comments
 (0)