Files
wehub-resource-sync 9b395f5cc3
Build Chrome Extension / build (push) Waiting to run
Trigger Website Rebuild (Docs Updated) / dispatch (push) Waiting to run
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:48 +08:00

50 lines
2.6 KiB
JavaScript

// packagist package — fetch a single Packagist package's metadata.
//
// Hits `https://packagist.org/packages/<vendor>/<package>.json`. Returns
// one row: latest stable version + release time, license, repository,
// description, lifetime / monthly / daily downloads, github stars, favers.
import { cli, Strategy } from '@jackwener/opencli/registry';
import { CommandExecutionError } from '@jackwener/opencli/errors';
import { PACKAGIST_BASE, packagistFetch, pickStableVersion, requirePackageName, trimDate } from './utils.js';
cli({
site: 'packagist',
name: 'package',
access: 'read',
description: 'Fetch a Packagist package\'s metadata (version, downloads, license, repo, GitHub stars)',
domain: 'packagist.org',
strategy: Strategy.PUBLIC,
browser: false,
args: [
{ name: 'name', positional: true, required: true, help: 'Composer package "<vendor>/<package>" (e.g. "symfony/console", "monolog/monolog")' },
],
columns: ['package', 'version', 'releasedAt', 'license', 'description', 'repository', 'githubStars', 'favers', 'downloads', 'monthlyDownloads', 'dailyDownloads', 'url'],
func: async (args) => {
const { full } = requirePackageName(args.name);
const url = `${PACKAGIST_BASE}/packages/${full}.json`;
const body = await packagistFetch(url, 'packagist package');
const pkg = body?.package;
if (!pkg || typeof pkg !== 'object') {
throw new CommandExecutionError(`packagist package returned no "package" object for ${full}.`);
}
const versionKey = pickStableVersion(pkg.versions);
const versionEntry = versionKey ? pkg.versions?.[versionKey] : null;
const license = Array.isArray(versionEntry?.license) ? versionEntry.license.filter(Boolean).join(', ') : '';
const downloads = pkg.downloads ?? {};
return [{
package: String(pkg.name ?? full).trim(),
version: versionKey ? String(versionKey) : '',
releasedAt: trimDate(versionEntry?.time),
license,
description: String(pkg.description ?? '').trim(),
repository: String(pkg.repository ?? '').trim(),
githubStars: pkg.github_stars != null ? Number(pkg.github_stars) : null,
favers: pkg.favers != null ? Number(pkg.favers) : null,
downloads: downloads.total != null ? Number(downloads.total) : null,
monthlyDownloads: downloads.monthly != null ? Number(downloads.monthly) : null,
dailyDownloads: downloads.daily != null ? Number(downloads.daily) : null,
url: `https://packagist.org/packages/${full}`,
}];
},
});