Skip to content

Commit 9afe21d

Browse files
committed
fix:added TR language support for warning text and changed logic for sorting versions to date of release
1 parent bd4ebe5 commit 9afe21d

File tree

5 files changed

+39
-36
lines changed

5 files changed

+39
-36
lines changed

app/components/LicenseDisplay.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ const hasAnyValidLicense = computed(() => tokens.value.some(t => t.type === 'lic
5757
v-if="changes.length > 0"
5858
class="border border-amber-600/40 bg-amber-500/10 rounded-lg inline-flex justify-start items-center mt-1 gap-x-1 py-[2px] px-[3px]"
5959
>
60-
<p class="text-md text-amber-800 dark:text-amber-400">changed</p>
60+
<p class="text-md text-amber-800 dark:text-amber-400">
61+
{{ $t("package.versions.license_change_warning") }}
62+
</p>
6163
<TooltipApp interactive position="top">
6264
<span
6365
tabindex="0"
Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,76 @@
1-
import type { MaybeRefOrGetter } from 'vue'
2-
import { toValue } from 'vue'
1+
import type { MaybeRefOrGetter } from "vue";
2+
import { toValue } from "vue";
33

44
export interface LicenseChange {
5-
from: string
6-
to: string
7-
version: string
5+
from: string;
6+
to: string;
7+
version: string;
88
}
99

1010
export interface LicenseChangesResult {
11-
changes: LicenseChange[]
11+
changes: LicenseChange[];
1212
}
1313

1414
// Type definitions for npm registry response
1515
interface NpmRegistryVersion {
16-
version: string
17-
license?: string
16+
version: string;
17+
license?: string;
1818
}
1919

2020
// for registry responses of $fetch function, the type includes the key versions as well as many others too.
2121
interface NpmRegistryResponse {
22-
versions: Record<
23-
string,
24-
{
25-
version: string
26-
license?: string
27-
}
28-
>
22+
time: Record<string, string>;
23+
versions: Record<string, NpmRegistryVersion>;
2924
}
3025

3126
/**
3227
* Composable to detect license changes across all versions of a package
3328
*/
34-
export function useLicenseChanges(packageName: MaybeRefOrGetter<string | null | undefined>) {
29+
export function useLicenseChanges(
30+
packageName: MaybeRefOrGetter<string | null | undefined>,
31+
) {
3532
return useAsyncData<LicenseChangesResult>(
3633
() => `license-changes:${toValue(packageName)}`,
3734
async () => {
38-
const name = toValue(packageName)
39-
if (!name) return { changes: [] }
35+
const name = toValue(packageName);
36+
if (!name) return { changes: [] };
4037

4138
// Fetch full package metadata from npm registry
42-
const url = `https://registry.npmjs.org/${name}`
43-
const data = await $fetch<NpmRegistryResponse>(url)
39+
const url = `https://registry.npmjs.org/${name}`;
40+
const data = await $fetch<NpmRegistryResponse>(url);
4441

45-
const changes: LicenseChange[] = []
46-
let prevLicense: string | undefined = undefined
42+
const changes: LicenseChange[] = [];
43+
let prevLicense: string | undefined = undefined;
4744

4845
// `data.versions` is an object with version keys
49-
const versions = Object.values(data.versions) as NpmRegistryVersion[]
46+
const versions = Object.values(data.versions) as NpmRegistryVersion[];
5047

5148
// Sort versions ascending to compare chronologically
5249
versions.sort((a, b) => {
53-
const parse = (v: string) => v.split('.').map(Number)
54-
const [aMajor, aMinor, aPatch] = parse(a.version as string)
55-
const [bMajor, bMinor, bPatch] = parse(b.version as string)
56-
if (aMajor !== bMajor) return aMajor! - bMajor!
57-
if (aMinor !== bMinor) return aMinor! - bMinor!
58-
return aPatch! - bPatch!
59-
})
50+
const dateA = new Date(data.time[a.version] as string).getTime();
51+
const dateB = new Date(data.time[b.version] as string).getTime();
52+
53+
// Ascending order (oldest to newest)
54+
return dateA - dateB;
55+
});
6056

6157
// Detect license changes
6258
for (const version of versions) {
63-
const license = (version.license as string) ?? 'UNKNOWN'
59+
const license = (version.license as string) ?? "UNKNOWN";
6460
if (prevLicense && license !== prevLicense) {
6561
changes.push({
6662
from: prevLicense,
6763
to: license,
6864
version: version.version as string,
69-
})
65+
});
7066
}
71-
prevLicense = license
67+
prevLicense = license;
7268
}
73-
return { changes }
69+
return { changes };
7470
},
7571
{
7672
default: () => ({ changes: [] }),
7773
watch: [() => toValue(packageName)],
7874
},
79-
)
75+
);
8076
}

i18n/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@
435435
"license_change_item": "from {from} to {to} at version {version}",
436436
"filter_tooltip": "Filter versions using a {link}. For example, ^3.0.0 shows all 3.x versions.",
437437
"changed_license": "The license was changed: {license_change}",
438+
"license_change_warning": "change!",
438439
"filter_tooltip_link": "semver range",
439440
"no_matches": "No versions match this range",
440441
"copy_alt": {

i18n/locales/tr-TR.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@
390390
"license_change_item": "{version} sürümünde {from}'den {to}'ya",
391391
"filter_tooltip": "Sürümleri {link} kullanarak filtreleyin. Örneğin, ^3.0.0 tüm 3.x sürümlerini gösterir.",
392392
"changed_license": "Lisans değişikliği gerçekleşti: {license_change}",
393+
"license_change_warning": "değişiklik!",
393394
"filter_tooltip_link": "semver aralığı",
394395
"no_matches": "Bu aralığa uygun sürüm yok",
395396
"copy_alt": {

i18n/schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,9 @@
13091309
"changed_license": {
13101310
"type": "string"
13111311
},
1312+
"license_change_warning": {
1313+
"type": "string"
1314+
},
13121315
"filter_tooltip_link": {
13131316
"type": "string"
13141317
},

0 commit comments

Comments
 (0)