Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions app/components/Package/TimelineChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,34 @@ const seriesDependencies = computed(() => {
}
})

const activeTab = shallowRef<TimelineChartMetric>('totalSize')
const timelineChartMetrics = new Set<TimelineChartMetric>([
'totalSize',
'dependencyCount',
'dependencySize',
])

const activeTab = usePermalink<TimelineChartMetric>('metric', 'totalSize', {
permanent: true,
})

watch(
activeTab,
value => {
if (!timelineChartMetrics.has(value)) {
activeTab.value = 'totalSize'
}
},
{ immediate: true },
)

const shouldPauseChartAnimations = shallowRef(true)

const { start: startChartAnimationPauseTimer } = useTimeoutFn(
() => {
shouldPauseChartAnimations.value = false
},
1000,
{ immediate: false },
300,
{ immediate: true },
)

function pauseChartAnimations() {
Expand Down Expand Up @@ -859,7 +877,7 @@ const timelineMetricTabs = computed(() => [
<div
style="width: 100%"
class="font-mono border-b border-border"
:class="{ loaded: shouldPauseChartAnimations }"
:class="{ loading: shouldPauseChartAnimations || loading }"
id="timeline-chart"
>
<div class="mt-4 flex flex-row flex-wrap items-center justify-between gap-4">
Expand Down Expand Up @@ -967,7 +985,7 @@ const timelineMetricTabs = computed(() => [
:markersNegative="getNegativeDatapointPlots(svg.data[0], svg.slicer.start)"
:colors
:gradientColors="E18E_GRADIENT_COLORS"
:pauseAnimations="shouldPauseChartAnimations"
:pauseAnimations="shouldPauseChartAnimations || loading"
/>
</template>

Expand Down Expand Up @@ -1040,6 +1058,10 @@ const timelineMetricTabs = computed(() => [
:dataset="datasets.dependencySize"
:config="stackbarConfig"
:selected-x-index="indexSelection"
:style="{
opacity: shouldPauseChartAnimations || loading ? 0 : 1,
transition: 'opacity 0.15s',
}"
ref="chartRef"
>
<!-- Injecting custom svg elements -->
Expand All @@ -1058,7 +1080,7 @@ const timelineMetricTabs = computed(() => [
"
:activeVersionPlot="getActiveVersionDatapointBar(svg.data, svg.barWidth)"
:colors
:pauseAnimations="shouldPauseChartAnimations"
:pauseAnimations="shouldPauseChartAnimations || loading"
/>
</template>

Expand Down Expand Up @@ -1112,7 +1134,10 @@ const timelineMetricTabs = computed(() => [
</VueUiStackbar>

<template #fallback>
<SkeletonBlock class="flex place-items-center justify-center aspect-[1152/254.59]">
<SkeletonBlock
class="flex place-items-center justify-center"
:class="[activeTab === 'dependencySize' ? 'aspect-[1152/466.4]' : 'aspect-[1152/254.59]']"
>
<span class="i-lucide:chart-line w-10 h-10 text-fg-muted" aria-hidden="true" />
</SkeletonBlock>
</template>
Expand Down Expand Up @@ -1198,9 +1223,9 @@ const timelineMetricTabs = computed(() => [
animation: indeterminate 1.5s ease-in-out infinite;
}

.loaded :deep(.vue-data-ui-component .serie_line_0 path),
.loaded :deep(.vdui-shape-circle),
.loaded :deep(.vue-ui-stackbar rect) {
.loading :deep(.vue-data-ui-component .serie_line_0 path),
.loading :deep(.vdui-shape-circle),
.loading :deep(.vue-ui-stackbar rect) {
transition: none !important;
animation: none !important;
}
Expand Down
6 changes: 3 additions & 3 deletions app/components/Package/Versions.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { compare, validRange } from 'semver'
import { compare, normalizeRange } from 'verkit'
import type { RouteLocationRaw } from 'vue-router'
import type { TrustStatus } from 'packumeta'
import { fetchAllPackageVersions } from '~/utils/npm/api'
Expand Down Expand Up @@ -55,7 +55,7 @@ const semverFilter = ref('')
watch(semverFilter, async newFilter => {
const trimmed = newFilter.trim()
if (trimmed === '' || hasLoadedAll.value) return
if (!validRange(trimmed)) return
if (!normalizeRange(trimmed)) return

try {
const allVersions = await loadAllVersions()
Expand Down Expand Up @@ -86,7 +86,7 @@ const filteredVersionSet = computed(() =>
)
const isFilterActive = computed(() => semverFilter.value.trim() !== '')
const isInvalidRange = computed(
() => isFilterActive.value && validRange(semverFilter.value.trim()) === null,
() => isFilterActive.value && normalizeRange(semverFilter.value.trim()) === null,
)

// All tag rows derived from props (SSR-safe)
Expand Down
2 changes: 1 addition & 1 deletion app/components/VersionSelector.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { onClickOutside } from '@vueuse/core'
import { compare } from 'semver'
import { compare } from 'verkit'
import {
buildVersionToTagsMap,
getPrereleaseChannel,
Expand Down
14 changes: 7 additions & 7 deletions app/composables/npm/useOutdatedDependencies.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PackageVersionsInfo } from 'fast-npm-meta'
import { getVersionsBatch } from 'fast-npm-meta'
import { maxSatisfying, prerelease, major, minor, diff, gt } from 'semver'
import { difference, findMaxSatisfying, getMajor, getMinor, getPrerelease, isGreater } from 'verkit'
import {
type OutdatedDependencyInfo,
isNonSemverConstraint,
Expand All @@ -26,22 +26,22 @@ function resolveOutdated(

let filteredVersions = versions
if (!constraintIncludesPrerelease(constraint)) {
filteredVersions = versions.filter(v => !prerelease(v))
filteredVersions = versions.filter(v => !getPrerelease(v))
}

const resolved = maxSatisfying(filteredVersions, constraint)
const resolved = findMaxSatisfying(filteredVersions, constraint)
if (!resolved) return null

if (resolved === latestTag) return null

// Resolved is newer than latest (e.g. ^2.0.0-rc when latest is 1.x)
if (gt(resolved, latestTag)) {
if (isGreater(resolved, latestTag)) {
return null
}

const diffType = diff(resolved, latestTag)
const majorsBehind = major(latestTag) - major(resolved)
const minorsBehind = majorsBehind === 0 ? minor(latestTag) - minor(resolved) : 0
const diffType = difference(resolved, latestTag)
const majorsBehind = getMajor(latestTag) - getMajor(resolved)
const minorsBehind = majorsBehind === 0 ? getMinor(latestTag) - getMinor(resolved) : 0

return {
resolved,
Expand Down
4 changes: 2 additions & 2 deletions app/composables/useCommandPaletteVersionCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
CommandPaletteContextCommandInput,
CommandPalettePackageContext,
} from '~/types/command-palette'
import { compare, satisfies, validRange } from 'semver'
import { compare, normalizeRange, satisfies } from 'verkit'

type CommandPaletteVersionRoute = (version: string) => RouteLocationRaw

Expand Down Expand Up @@ -54,7 +54,7 @@ export function useCommandPaletteVersionCommands(
const resolvedContext = toValue(context)
if (!resolvedContext?.resolvedVersion || !query) return null

const semverRange = validRange(query)
const semverRange = normalizeRange(query)
if (!semverRange) return null

const matchingVersions = getSortedVersions(resolvedContext).filter(version =>
Expand Down
6 changes: 3 additions & 3 deletions app/composables/useInstallSizeDiff.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { compare, prerelease, valid } from 'semver'
import { compare, getPrerelease, isValid } from 'verkit'

export interface InstallSizeDiff {
direction: 'increase' | 'decrease'
Expand All @@ -20,10 +20,10 @@ const SIZE_DECREASE_THRESHOLD = 0.2
const DEP_DECREASE_THRESHOLD = 3

function getComparisonVersion(pkg: SlimPackument, resolvedVersion: string): string | null {
const isCurrentPrerelease = prerelease(resolvedVersion) !== null
const isCurrentPrerelease = getPrerelease(resolvedVersion) !== null

const stableVersions = Object.keys(pkg.time)
.filter(v => v !== 'modified' && v !== 'created' && valid(v) !== null && prerelease(v) === null)
.filter(v => v !== 'modified' && v !== 'created' && isValid(v) && getPrerelease(v) === null)
.sort((a, b) => compare(a, b))

if (isCurrentPrerelease) {
Expand Down
3 changes: 2 additions & 1 deletion app/pages/package-timeline/[[org]]/[packageName].vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import type { RouteLocationRaw } from 'vue-router'
import { compare } from 'semver'
import { compare } from 'verkit'
import type {
TimelineResponse,
TimelineVersion,
Expand All @@ -12,6 +12,7 @@ import type { TimelineSizeCacheValue } from '~/utils/charts'
definePageMeta({
name: 'timeline',
path: '/package-timeline/:org?/:packageName/v/:version',
preserveScrollOnQuery: true,
})

const { t } = useI18n()
Expand Down
6 changes: 3 additions & 3 deletions app/pages/package/[[org]]/[name]/versions.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { WindowVirtualizer } from 'virtua/vue'
import { getVersions } from 'fast-npm-meta'
import { compare, validRange } from 'semver'
import { compare, normalizeRange } from 'verkit'
import {
buildVersionToTagsMap,
buildTaggedVersionRows,
Expand Down Expand Up @@ -205,14 +205,14 @@ const versionFilterInput = ref('')
const versionFilter = refDebounced(versionFilterInput, 100)
const isFilterActive = computed(() => versionFilter.value.trim() !== '')
const isInvalidRange = computed(
() => isFilterActive.value && validRange(versionFilter.value.trim()) === null,
() => isFilterActive.value && normalizeRange(versionFilter.value.trim()) === null,
)

const filteredVersionSet = computed(() => {
const trimmed = versionFilter.value.trim()
if (!trimmed) return null
// Try semver range first (e.g. "^2.0.0", ">=1 <3")
if (validRange(trimmed)) {
if (normalizeRange(trimmed)) {
return filterVersions(versionStrings.value, trimmed)
}
// Fallback: substring match (e.g. "2.4", "beta")
Expand Down
2 changes: 1 addition & 1 deletion app/utils/npm/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getVersions } from 'fast-npm-meta'
import { compare } from 'semver'
import { compare } from 'verkit'

type NpmDownloadsRangeResponse = {
start: string
Expand Down
4 changes: 2 additions & 2 deletions app/utils/npm/outdated-dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ReleaseType } from 'semver'
import type { VersionDifference } from 'verkit'

/** Information about an outdated dependency */
export interface OutdatedDependencyInfo {
Expand All @@ -11,7 +11,7 @@ export interface OutdatedDependencyInfo {
/** How many minor versions behind (when same major) */
minorsBehind: number
/** The type of version difference */
diffType: ReleaseType | null
diffType: VersionDifference | null
}

/**
Expand Down
34 changes: 32 additions & 2 deletions app/utils/package-content-hints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ const POSSIBLY_UNNECESSARY_FILES: ReadonlySet<string> = new Set([
'.editorconfig',
'.prettierignore',
'.eslintignore',
'.jshintignore',
'.npmignore',
'.gitignore',
'.gitattributes',
'.travis.yml',
'.verb.md',
'Makefile',
'tsconfig.json',
'jsconfig.json',
'.node-version',
'.nvmrc',
'mise.toml',
Expand All @@ -27,6 +33,18 @@ const POSSIBLY_UNNECESSARY_FILES: ReadonlySet<string> = new Set([
'.env.production.local',
'.nycrc',
'nyc.json',
'.DS_Store',
'AUTHORS',
'test.js',
'test.ts',
'tests.js',
'tests.ts',
'bench.js',
'benchmark.js',
'yarn.lock',
'bun.lock',
'bun.lockb',
'package-lock.json',
])

const POSSIBLY_UNNECESSARY_DIRECTORIES: ReadonlySet<string> = new Set([
Expand All @@ -35,11 +53,16 @@ const POSSIBLY_UNNECESSARY_DIRECTORIES: ReadonlySet<string> = new Set([
'.github',
'.idea',
'.zed',
'.yarn',
'.husky',
'.changeset',
'test',
'tests',
'__tests__',
'spec',
'specs',
'example',
'examples',
'benchmark',
])

const POSSIBLY_UNNECESSARY_DIRECTORY_PATTERNS: readonly RegExp[] = [/^__.+__$/]
Expand All @@ -53,11 +76,18 @@ const POSSIBLY_UNNECESSARY_PATTERNS: readonly RegExp[] = [
/^\.oxlintrc(?:\.(?:json|js|cjs|yml|yaml))?$/,
/^oxfmt\.config\.(?:js|cjs|mjs|ts|mts|cts)$/,
/^\.oxfmtrc(?:\.(?:json|js|cjs|yml|yaml))?$/,
/^jest\.config\.(?:js|cjs|mjs|ts|mts|cts)$/,
// Match common dot-prefixed config files without flagging all dotfiles;
// files like .npmrc, .npmignore, and .gitkeep can be intentional artifacts.
// files like .npmrc can be intentional artifacts.
/^\.(?!npmrc$)[a-z][a-z0-9_-]*rc$/,
/^\.(?!npmrc\.)[a-z][a-z0-9_-]*rc\.(?:json|js|cjs|mjs|yml|yaml|toml)$/,
/^\.[a-z][a-z0-9_-]*\.config\.(?:js|cjs|mjs|ts|mts|cts)$/,
// Match files ending in .test.js, .test.ts, .spec.js, .spec.ts, etc.
/\.(?:test|spec)\.(?:j|t)s$/,
// Match CHANGELOG.md, etc
/^(?:changelog|releasenotes|release-notes|history|contributing|contribute|news|collaborators)\.(?:md|markdown|txt)$/i,
// Match example.mjs, examples.js, stc
/^examples?\.(?:js|cjs|mjs|ts|mts|cts)$/,
]

export function isPossiblyUnnecessaryContent(name: string, type: 'file' | 'directory'): boolean {
Expand Down
6 changes: 3 additions & 3 deletions app/utils/publish-security.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getTrustLevel, getTrustLevelName, type TrustLevelName } from 'packumeta'
import { compare, major } from 'semver'
import { compare, getMajor } from 'verkit'

export interface PublishSecurityDowngrade {
downgradedVersion: string
Expand Down Expand Up @@ -72,7 +72,7 @@ export function detectPublishSecurityDowngradeForVersion(
const current = sorted[currentIndex]
if (!current) return null

const currentMajor = major(current.version)
const currentMajor = getMajor(current.version)

// Find the strongest older version across all majors (for detection)
// and the strongest within the same major (for recommendation)
Expand All @@ -84,7 +84,7 @@ export function detectPublishSecurityDowngradeForVersion(
if (!strongestOlderAny || version.trustRank > strongestOlderAny.trustRank) {
strongestOlderAny = version
}
if (major(version.version) === currentMajor) {
if (getMajor(version.version) === currentMajor) {
if (!strongestOlderSameMajor || version.trustRank > strongestOlderSameMajor.trustRank) {
strongestOlderSameMajor = version
}
Expand Down
Loading
Loading