Skip to content
Draft
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
12 changes: 4 additions & 8 deletions app/composables/npm/useAlgoliaSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ function hitToSearchResult(hit: AlgoliaHit): NpmSearchResult {
interface AlgoliaSearchOptions {
size?: number
from?: number
filters?: string
}

/** Extra checks bundled into a single multi-search request. */
Expand Down Expand Up @@ -145,7 +144,7 @@ export function useAlgoliaSearch() {
query,
offset: options.from,
length: options.size,
filters: options.filters || '',
filters: '',
analyticsTags: ['npmx.dev'],
attributesToRetrieve: ATTRIBUTES_TO_RETRIEVE,
attributesToHighlight: [],
Expand All @@ -167,11 +166,8 @@ export function useAlgoliaSearch() {
}

/** Fetch all packages for a maintainer using `owners.name` filter with pagination. */
async function searchByMaintainer(
ownerName: string,
options: { maxResults?: number } = {},
): Promise<NpmSearchResponse> {
const max = options.maxResults ?? 1000
async function searchByMaintainer(ownerName: string): Promise<NpmSearchResponse> {
const max = 1000

const allHits: AlgoliaHit[] = []
let offset = 0
Expand Down Expand Up @@ -295,7 +291,7 @@ export function useAlgoliaSearch() {
query,
offset: options.from,
length: options.size,
filters: options.filters || '',
filters: '',
analyticsTags: ['npmx.dev'],
attributesToRetrieve: ATTRIBUTES_TO_RETRIEVE,
attributesToHighlight: [],
Expand Down
6 changes: 2 additions & 4 deletions app/composables/useFacetSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ function getFacetsInCategory(category: string): ComparisonFacet[] {

/**
* Composable for managing comparison facet selection with URL sync.
*
* @param queryParam - The URL query parameter name to use (default: 'facets')
*/
export function useFacetSelection(queryParam = 'facets') {
export function useFacetSelection() {
const { t } = useI18n()
const compactNumberFormatter = useCompactNumberFormatter()
const bytesFormatter = useBytesFormatter()
Expand Down Expand Up @@ -166,7 +164,7 @@ export function useFacetSelection(queryParam = 'facets') {
}

// Sync with URL query param (stable ref - doesn't change on other query changes)
const facetsParam = useRouteQuery<string>(queryParam, '', { mode: 'replace' })
const facetsParam = useRouteQuery<string>('facets', '', { mode: 'replace' })

// Parse facet IDs from URL or use defaults
const selectedFacetIds = computed<ComparisonFacet[]>({
Expand Down
4 changes: 1 addition & 3 deletions app/composables/useStructuredFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ export function removeKeywordFromQuery(query: string, keyword: string): string {
interface UseStructuredFiltersOptions {
packages: Ref<NpmSearchResult[]>
searchQueryModel?: Ref<string>
initialFilters?: Partial<StructuredFilters>
initialSort?: SortOption
}

Expand All @@ -153,15 +152,14 @@ function matchesSecurity(pkg: NpmSearchResult, security: SecurityFilter): boolea
export function useStructuredFilters(options: UseStructuredFiltersOptions) {
const route = useRoute()
const router = useRouter()
const { packages, initialFilters, initialSort, searchQueryModel } = options
const { packages, initialSort, searchQueryModel } = options
const { t } = useI18n()

const searchQuery = shallowRef(normalizeSearchParam(route.query.q))

// Filter state - must be declared before the watcher that uses it
const filters = ref<StructuredFilters>({
...DEFAULT_FILTERS,
...initialFilters,
})

// Watch route query changes and sync filter state
Expand Down
4 changes: 2 additions & 2 deletions app/utils/compare-scatter-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function isFiniteNumber(value: unknown): value is number {
return typeof value === 'number' && Number.isFinite(value)
}

function toFreshnessScore(value: unknown, maximumAgeInDays = 365): number | null {
function toFreshnessScore(value: unknown): number | null {
if (!value) {
return null
}
Expand All @@ -21,7 +21,7 @@ function toFreshnessScore(value: unknown, maximumAgeInDays = 365): number | null

const ageInMilliseconds = Date.now() - date.getTime()
const ageInDays = ageInMilliseconds / MILLISECONDS_IN_A_DAY
const normalizedFreshness = 1 - ageInDays / maximumAgeInDays
const normalizedFreshness = 1 - ageInDays / 365

if (normalizedFreshness < 0) {
return 0
Expand Down
3 changes: 1 addition & 2 deletions cli/src/npm-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import { resolveNpmProcessCommand } from './npm-process.ts'
const execFileAsync = promisify(execFile)
export const NPM_REGISTRY_URL = 'https://registry.npmjs.org/'

function createNpmEnv(overrides: Record<string, string> = {}): Record<string, string> {
function createNpmEnv(): Record<string, string> {
return {
...process.env,
...overrides,
FORCE_COLOR: '0',
npm_config_registry: NPM_REGISTRY_URL,
}
Expand Down
10 changes: 3 additions & 7 deletions cli/src/npm-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ interface NpmProcessCommand {
args: string[]
}

export function resolveNpmProcessCommand(
npmArgs: string[],
platform = process.platform,
comSpec = process.env.ComSpec,
): NpmProcessCommand {
if (platform === 'win32') {
export function resolveNpmProcessCommand(npmArgs: string[]): NpmProcessCommand {
if (process.platform === 'win32') {
return {
command: comSpec || 'cmd.exe',
command: process.env.ComSpec || 'cmd.exe',
args: ['/d', '/s', '/c', 'npm', ...npmArgs],
}
}
Expand Down
4 changes: 2 additions & 2 deletions server/api/auth/atproto.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ function encodeOAuthState(event: H3Event, data: OAuthStateData): string {
return JSON.stringify({ data, id })
}

function generateRandomHexString(byteLength: number = 16): string {
return Array.from(crypto.getRandomValues(new Uint8Array(byteLength)), byte =>
function generateRandomHexString(): string {
return Array.from(crypto.getRandomValues(new Uint8Array(16)), byte =>
byte.toString(16).padStart(2, '0'),
).join('')
}
Expand Down
4 changes: 1 addition & 3 deletions shared/utils/constellation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,11 @@ export class Constellation {
/**
* Gets all links from constellation and their counts
* @param target - A uri encoded link. did, url, or at-uri
* @param ttl - The ttl to use for the cache
*/
async getAllLinks(target: string, ttl: number | undefined = undefined) {
async getAllLinks(target: string) {
return await this.cachedFetch<AllLinksResponse>(
`https://${CONSTELLATION_HOST}/links/all?target=${target}`,
{ headers: HEADERS },
ttl,
)
}
}
70 changes: 28 additions & 42 deletions shared/utils/git-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ interface ProviderConfig {
/** Parse URL path into owner/repo, returns null if invalid */
parsePath(parts: string[]): { owner: string; repo: string } | null
/** Get raw file URL base for resolving relative paths */
getRawBaseUrl(ref: RepoRef, branch?: string): string
getRawBaseUrl(ref: RepoRef): string
/** Get blob/rendered URL base for markdown files */
getBlobBaseUrl(ref: RepoRef, branch?: string): string
getBlobBaseUrl(ref: RepoRef): string
/** Convert file URLs to blob URLs (for images) */
fileToRaw?(url: string): string
/** Convert blob URLs to raw URLs (for images) */
Expand All @@ -79,10 +79,8 @@ const providers: ProviderConfig[] = [
if (!owner || !repo) return null
return { owner, repo }
},
getRawBaseUrl: (ref, branch = 'HEAD') =>
`https://raw.githubusercontent.com/${ref.owner}/${ref.repo}/${branch}`,
getBlobBaseUrl: (ref, branch = 'HEAD') =>
`https://github.com/${ref.owner}/${ref.repo}/blob/${branch}`,
getRawBaseUrl: ref => `https://raw.githubusercontent.com/${ref.owner}/${ref.repo}/HEAD`,
getBlobBaseUrl: ref => `https://github.com/${ref.owner}/${ref.repo}/blob/HEAD`,
fileToRaw: url => url.replace('/tree/', '/raw/'),
blobToRaw: url => url.replace('/blob/', '/raw/'),
},
Expand All @@ -102,13 +100,13 @@ const providers: ProviderConfig[] = [
if (!owner || !repo) return null
return { owner, repo }
},
getRawBaseUrl: (ref, branch = 'HEAD') => {
getRawBaseUrl: ref => {
const host = ref.host ?? 'gitlab.com'
return `https://${host}/${ref.owner}/${ref.repo}/-/raw/${branch}`
return `https://${host}/${ref.owner}/${ref.repo}/-/raw/HEAD`
},
getBlobBaseUrl: (ref, branch = 'HEAD') => {
getBlobBaseUrl: ref => {
const host = ref.host ?? 'gitlab.com'
return `https://${host}/${ref.owner}/${ref.repo}/-/blob/${branch}`
return `https://${host}/${ref.owner}/${ref.repo}/-/blob/HEAD`
},
blobToRaw: url => url.replace('/-/blob/', '/-/raw/'),
},
Expand All @@ -124,10 +122,8 @@ const providers: ProviderConfig[] = [
if (!owner || !repo) return null
return { owner, repo }
},
getRawBaseUrl: (ref, branch = 'HEAD') =>
`https://bitbucket.org/${ref.owner}/${ref.repo}/raw/${branch}`,
getBlobBaseUrl: (ref, branch = 'HEAD') =>
`https://bitbucket.org/${ref.owner}/${ref.repo}/src/${branch}`,
getRawBaseUrl: ref => `https://bitbucket.org/${ref.owner}/${ref.repo}/raw/HEAD`,
getBlobBaseUrl: ref => `https://bitbucket.org/${ref.owner}/${ref.repo}/src/HEAD`,
blobToRaw: url => url.replace('/src/', '/raw/'),
},
{
Expand All @@ -142,10 +138,8 @@ const providers: ProviderConfig[] = [
if (!owner || !repo) return null
return { owner, repo }
},
getRawBaseUrl: (ref, branch = 'HEAD') =>
`https://codeberg.org/${ref.owner}/${ref.repo}/raw/branch/${branch === 'HEAD' ? 'main' : branch}`,
getBlobBaseUrl: (ref, branch = 'HEAD') =>
`https://codeberg.org/${ref.owner}/${ref.repo}/src/branch/${branch === 'HEAD' ? 'main' : branch}`,
getRawBaseUrl: ref => `https://codeberg.org/${ref.owner}/${ref.repo}/raw/branch/main`,
getBlobBaseUrl: ref => `https://codeberg.org/${ref.owner}/${ref.repo}/src/branch/main`,
blobToRaw: url => url.replace('/src/', '/raw/'),
},
{
Expand All @@ -160,10 +154,8 @@ const providers: ProviderConfig[] = [
if (!owner || !repo) return null
return { owner, repo }
},
getRawBaseUrl: (ref, branch = 'master') =>
`https://gitee.com/${ref.owner}/${ref.repo}/raw/${branch}`,
getBlobBaseUrl: (ref, branch = 'master') =>
`https://gitee.com/${ref.owner}/${ref.repo}/blob/${branch}`,
getRawBaseUrl: ref => `https://gitee.com/${ref.owner}/${ref.repo}/raw/master`,
getBlobBaseUrl: ref => `https://gitee.com/${ref.owner}/${ref.repo}/blob/master`,
blobToRaw: url => url.replace('/blob/', '/raw/'),
},
{
Expand All @@ -179,10 +171,8 @@ const providers: ProviderConfig[] = [
if (!owner || !repo) return null
return { owner, repo }
},
getRawBaseUrl: (ref, branch = 'HEAD') =>
`https://git.sr.ht/${ref.owner}/${ref.repo}/blob/${branch}`,
getBlobBaseUrl: (ref, branch = 'HEAD') =>
`https://git.sr.ht/${ref.owner}/${ref.repo}/tree/${branch}/item`,
getRawBaseUrl: ref => `https://git.sr.ht/${ref.owner}/${ref.repo}/blob/HEAD`,
getBlobBaseUrl: ref => `https://git.sr.ht/${ref.owner}/${ref.repo}/tree/HEAD/item`,
},
{
id: 'tangled',
Expand All @@ -201,10 +191,8 @@ const providers: ProviderConfig[] = [
if (!owner || !repo) return null
return { owner, repo }
},
getRawBaseUrl: (ref, branch = 'main') =>
`https://tangled.sh/${ref.owner}/${ref.repo}/raw/branch/${branch}`,
getBlobBaseUrl: (ref, branch = 'main') =>
`https://tangled.sh/${ref.owner}/${ref.repo}/src/branch/${branch}`,
getRawBaseUrl: ref => `https://tangled.sh/${ref.owner}/${ref.repo}/raw/branch/main`,
getBlobBaseUrl: ref => `https://tangled.sh/${ref.owner}/${ref.repo}/src/branch/main`,
blobToRaw: url => url.replace('/blob/', '/raw/branch/'),
},
{
Expand All @@ -220,10 +208,8 @@ const providers: ProviderConfig[] = [
// Use empty owner, store full rad: ID as repo
return { owner: '', repo: radMatch[0] }
},
getRawBaseUrl: (ref, branch = 'HEAD') =>
`https://seed.radicle.at/api/v1/projects/${ref.repo}/blob/${branch}`,
getBlobBaseUrl: (ref, branch = 'HEAD') =>
`https://app.radicle.at/nodes/seed.radicle.at/${ref.repo}/tree/${branch}`,
getRawBaseUrl: ref => `https://seed.radicle.at/api/v1/projects/${ref.repo}/blob/HEAD`,
getBlobBaseUrl: ref => `https://app.radicle.at/nodes/seed.radicle.at/${ref.repo}/tree/HEAD`,
},
{
id: 'forgejo',
Expand All @@ -237,13 +223,13 @@ const providers: ProviderConfig[] = [
if (!owner || !repo) return null
return { owner, repo }
},
getRawBaseUrl: (ref, branch = 'HEAD') => {
getRawBaseUrl: ref => {
const host = ref.host ?? 'codeberg.org'
return `https://${host}/${ref.owner}/${ref.repo}/raw/branch/${branch === 'HEAD' ? 'main' : branch}`
return `https://${host}/${ref.owner}/${ref.repo}/raw/branch/main`
},
getBlobBaseUrl: (ref, branch = 'HEAD') => {
getBlobBaseUrl: ref => {
const host = ref.host ?? 'codeberg.org'
return `https://${host}/${ref.owner}/${ref.repo}/src/branch/${branch === 'HEAD' ? 'main' : branch}`
return `https://${host}/${ref.owner}/${ref.repo}/src/branch/main`
},
blobToRaw: url => url.replace('/src/', '/raw/'),
},
Expand All @@ -259,13 +245,13 @@ const providers: ProviderConfig[] = [
if (!owner || !repo) return null
return { owner, repo }
},
getRawBaseUrl: (ref, branch = 'HEAD') => {
getRawBaseUrl: ref => {
const host = ref.host ?? 'gitea.io'
return `https://${host}/${ref.owner}/${ref.repo}/raw/branch/${branch === 'HEAD' ? 'main' : branch}`
return `https://${host}/${ref.owner}/${ref.repo}/raw/branch/main`
},
getBlobBaseUrl: (ref, branch = 'HEAD') => {
getBlobBaseUrl: ref => {
const host = ref.host ?? 'gitea.io'
return `https://${host}/${ref.owner}/${ref.repo}/src/branch/${branch === 'HEAD' ? 'main' : branch}`
return `https://${host}/${ref.owner}/${ref.repo}/src/branch/main`
},
blobToRaw: url => url.replace('/src/', '/raw/'),
},
Expand Down
3 changes: 1 addition & 2 deletions shared/utils/repository-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,7 @@ export async function getRepoMeta(
export async function getRepositoryStars(
cachedFetch: CachedFetchFunction,
ref: RepoRef,
options: Parameters<typeof $fetch>[1] = {},
): Promise<number | null> {
const meta = await getRepoMeta(cachedFetch, ref, options)
const meta = await getRepoMeta(cachedFetch, ref)
return meta?.stars ?? null
}
Loading