From 3a0543fae60a5f56ba38a8468be6c66853ed3bed Mon Sep 17 00:00:00 2001 From: alptekin isiklar Date: Sat, 21 Mar 2026 22:52:08 +0000 Subject: [PATCH 1/2] 1826-add a warning and info for license changes. Added support for TR language too. --- app/components/LicenseDisplay.vue | 64 ++- app/composables/useLicenseChanges.ts | 80 +++ app/pages/package/[[org]]/[name].vue | 697 ++++++++++++++++----------- i18n/locales/en.json | 3 + i18n/locales/tr-TR.json | 3 + i18n/schema.json | 9 + 6 files changed, 571 insertions(+), 285 deletions(-) create mode 100644 app/composables/useLicenseChanges.ts diff --git a/app/components/LicenseDisplay.vue b/app/components/LicenseDisplay.vue index c83cb46d35..2d9dec3847 100644 --- a/app/components/LicenseDisplay.vue +++ b/app/components/LicenseDisplay.vue @@ -1,13 +1,36 @@ tokens.value.some(t => t.type === 'lic aria-hidden="true" /> +
+

change!

+ + + + + + +
diff --git a/app/composables/useLicenseChanges.ts b/app/composables/useLicenseChanges.ts new file mode 100644 index 0000000000..74b0f0deab --- /dev/null +++ b/app/composables/useLicenseChanges.ts @@ -0,0 +1,80 @@ +import type { MaybeRefOrGetter } from 'vue' +import { toValue } from 'vue' + +export interface LicenseChange { + from: string + to: string + version: string +} + +export interface LicenseChangesResult { + changes: LicenseChange[] +} + +// Type definitions for npm registry response +interface NpmRegistryVersion { + version: string + license?: string +} + +// for registry responses of $fetch function, the type includes the key versions as well as many others too. +interface NpmRegistryResponse { + versions: Record< + string, + { + version: string + license?: string + } + > +} + +/** + * Composable to detect license changes across all versions of a package + */ +export function useLicenseChanges(packageName: MaybeRefOrGetter) { + return useAsyncData( + () => `license-changes:${toValue(packageName)}`, + async () => { + const name = toValue(packageName) + if (!name) return { changes: [] } + + // Fetch full package metadata from npm registry + const url = `https://registry.npmjs.org/${name}` + const data = await $fetch(url) + + const changes: LicenseChange[] = [] + let prevLicense: string | undefined = undefined + + // `data.versions` is an object with version keys + const versions = Object.values(data.versions) as NpmRegistryVersion[] + + // Sort versions ascending to compare chronologically + versions.sort((a, b) => { + const parse = (v: string) => v.split('.').map(Number) + const [aMajor, aMinor, aPatch] = parse(a.version as string) + const [bMajor, bMinor, bPatch] = parse(b.version as string) + if (aMajor !== bMajor) return aMajor! - bMajor! + if (aMinor !== bMinor) return aMinor! - bMinor! + return aPatch! - bPatch! + }) + + // Detect license changes + for (const version of versions) { + const license = (version.license as string) ?? 'UNKNOWN' + if (prevLicense && license !== prevLicense) { + changes.push({ + from: prevLicense, + to: license, + version: version.version as string, + }) + } + prevLicense = license + } + return { changes } + }, + { + default: () => ({ changes: [] }), + watch: [() => toValue(packageName)], + }, + ) +} diff --git a/app/pages/package/[[org]]/[name].vue b/app/pages/package/[[org]]/[name].vue index a83a101243..a6d1449a10 100644 --- a/app/pages/package/[[org]]/[name].vue +++ b/app/pages/package/[[org]]/[name].vue @@ -1,67 +1,67 @@