Skip to content

Commit c6d381c

Browse files
committed
Update npm stats
1 parent 14a818a commit c6d381c

File tree

1,697 files changed

+1695
-1661
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,697 files changed

+1695
-1661
lines changed

apps/svelte.dev/scripts/registry/npm.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,11 @@ function format(date: Date, format_str: string): string {
314314
return format_str.replace('yyyy', year.toString()).replace('MM', month).replace('dd', day);
315315
}
316316

317-
const API_BASE_URL = 'https://api.npmjs.org/downloads';
317+
const API_BASE_URL = 'https://api.npmjs.org/';
318318
const REGISTRY_BASE_URL = 'https://registry.npmjs.org/';
319319

320320
const END_DATE = format(new Date(), 'yyyy-MM-dd');
321-
const START_DATE = format(sub_days(new Date(), 30), 'yyyy-MM-dd');
321+
const START_DATE = format(sub_days(new Date(), 7), 'yyyy-MM-dd');
322322

323323
const PAGE_SIZE = 100;
324324

@@ -337,7 +337,7 @@ export async function fetch_downloads_for_package(pkg: string): Promise<number>
337337
/**
338338
* Gets details for a package from the npm registry
339339
*/
340-
export async function fetch_details_for_package(pkg: string) {
340+
export async function fetch_details_for_package(pkg: string): Promise<any> {
341341
const registry_data = await superfetch(`${REGISTRY_BASE_URL}${pkg}`, { headers: HEADERS }).then(
342342
(r) => r.json()
343343
);

apps/svelte.dev/scripts/registry/update-registry.ts

Lines changed: 93 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
// Credit for original: Astro team
22
import { createOpenRouter } from '@openrouter/ai-sdk-provider';
3-
import { extract_frontmatter, transform } from '@sveltejs/site-kit/markdown';
43
import { generateText } from 'ai';
54
import dotenv from 'dotenv';
65
import fs, { mkdirSync } from 'node:fs';
76
import path from 'node:path';
87
import { fileURLToPath } from 'node:url';
98
import glob from 'tiny-glob/sync.js';
109
import registry from '../../src/lib/registry.json' with { type: 'json' };
11-
import type { Package } from '../../src/lib/server/content.js';
1210
import {
1311
fetch_details_for_package,
12+
fetch_downloads_for_package,
1413
HEADERS,
1514
PackageCache,
1615
request_queue,
@@ -20,6 +19,7 @@ import {
2019
superfetch,
2120
type StructuredInterimPackage
2221
} from './npm.js';
22+
import type { Package } from '../../src/lib/server/content.js';
2323

2424
dotenv.config({ path: '.env.local' });
2525

@@ -452,17 +452,98 @@ async function update_all_github_stars(ignore_if_exists = false) {
452452
}
453453
}
454454

455-
// Gets the cached files, goes through npm for each, and udpate
456-
// all relevant npm information from that
455+
/**
456+
* Updates package cache with latest npm data
457+
* Uses existing request_queue from superfetch for concurrency control
458+
*/
457459
async function update_cache_from_npm() {
458-
// for (const [pkg_file_name, data] of PackageCache.entries()) {
459-
// console.log(await fetch_details_for_package(data.name));
460-
// }
461-
const detail = await fetch_details_for_package('svelte-drag');
460+
// Track progress
461+
let processedCount = 0;
462+
const updatedPackages: {
463+
pkg_name: string;
464+
data: Package;
465+
}[] = [];
466+
467+
// Collect all package entries to count total
468+
const packages = [];
469+
for await (const [pkg_name, data] of PackageCache.entries()) {
470+
packages.push({ pkg_name, data });
471+
}
472+
473+
const totalPackages = packages.length;
474+
console.log(`Starting update for ${totalPackages} packages`);
475+
476+
// Create array of promises for package updates
477+
const promises = packages.map(({ pkg_name, data }) => {
478+
// These fetch functions already use request_queue internally via superfetch
479+
return Promise.all([
480+
fetch_details_for_package(data.name),
481+
fetch_downloads_for_package(data.name)
482+
])
483+
.then(([details, downloads]) => {
484+
try {
485+
if (!details) {
486+
console.warn(`No details found for package: ${data.name}`);
487+
return null;
488+
}
489+
490+
const latest_version = details['dist-tags']?.latest;
491+
if (!latest_version) {
492+
console.warn(`No latest version found for package: ${data.name}`);
493+
return null;
494+
}
495+
496+
// Get last update date and deprecation status
497+
const updated = details.time?.[latest_version]
498+
? new Date(details.time[latest_version])
499+
: undefined;
500+
const deprecated = details.versions?.[latest_version]?.deprecated || false;
501+
502+
// Update the package data
503+
const updatedData = {
504+
...data,
505+
downloads,
506+
updated: updated?.toISOString(),
507+
deprecated: deprecated || undefined // Only include if true
508+
};
509+
510+
// Save updated data back to cache
511+
PackageCache.set(data.name, updatedData);
512+
513+
// Track progress
514+
processedCount++;
515+
if (processedCount % 10 === 0 || processedCount === totalPackages) {
516+
console.log(
517+
`Progress: ${processedCount}/${totalPackages} (${Math.round((processedCount / totalPackages) * 100)}%)`
518+
);
519+
}
520+
521+
// Store updated package info
522+
const packageInfo: Package = {
523+
...data,
524+
downloads,
525+
updated: updated?.toISOString(),
526+
deprecated
527+
};
528+
529+
updatedPackages.push({ data: packageInfo as any, pkg_name: data.name });
530+
return packageInfo;
531+
} catch (error) {
532+
console.error(`Error processing package ${data.name}:`, error);
533+
return null;
534+
}
535+
})
536+
.catch((error) => {
537+
console.error(`Error fetching package ${data.name}:`, error);
538+
return null;
539+
});
540+
});
462541

463-
const latestVersion = detail['dist-tags']?.latest;
542+
// Wait for all updates to complete
543+
await Promise.all(promises);
464544

465-
console.log(detail.versions[latestVersion]);
545+
console.log(`Update completed for ${processedCount} packages`);
546+
return updatedPackages.filter(Boolean);
466547
}
467548

468549
async function delete_untagged() {
@@ -491,6 +572,6 @@ async function* create_map_batch_generator(
491572

492573
// const svelte_packages = await process_batches_through_llm();
493574

494-
// update_cache_from_npm();
495-
update_all_github_stars();
575+
update_cache_from_npm();
576+
// update_all_github_stars();
496577
// delete_untagged();

apps/svelte.dev/src/lib/server/generated/registry/0xclearview-svelte-tiny-virtual-table.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "A tiny but mighty list virtualization component for svelte, with z
44
repo_url: "https://github.com/0xclearview/svelte-tiny-virtual-table"
55
author: "Marcos Gutiérrez"
66
homepage: "https://github.com/0xclearview/svelte-tiny-virtual-table#readme"
7-
downloads: 6
7+
downloads: 9
88
updated: "2024-11-16T13:11:37.125Z"
99
tags:
1010
- ui

apps/svelte.dev/src/lib/server/generated/registry/3--svelte-preprocess.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "A Svelte preprocessor wrapper with baked-in support for commonly u
44
repo_url: "https://github.com/i18n-fork/svelte-preprocess"
55
author: "Christian Kaisermann"
66
homepage: "https://github.com/i18n-fork/svelte-preprocess#readme"
7-
downloads: 2
7+
downloads: 16
88
updated: "2024-10-21T06:10:48.516Z"
99
tags:
1010
- preprocessor

apps/svelte.dev/src/lib/server/generated/registry/3xpo-svelte-colour-picker.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "A highly customizable color picker component library"
44
repo_url: "https://github.com/Exponential-Workload/svelte-colour-picker"
55
author: "Maxime Dupont"
66
homepage: "https://gh.expo.moe/svelte-colour-picker/"
7-
downloads: 2
7+
downloads: 8
88
updated: "2024-03-01T19:10:08.365Z"
99
tags:
1010
- ui

apps/svelte.dev/src/lib/server/generated/registry/3xpo-svelte-slider.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "A highly customizable slider component library"
44
repo_url: "https://github.com/Exponential-Workload/svelte-colour-picker"
55
author: "Expo"
66
homepage: "https://gh.expo.moe/svelte-slider/"
7-
downloads: 2
7+
downloads: 4
88
dependents: 1
99
updated: "2024-01-04T08:25:23.273Z"
1010
tags:

apps/svelte.dev/src/lib/server/generated/registry/6edesign-svelte-sortablejs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: "@6edesign/svelte-sortablejs"
3-
description: "<p align="center"> <img src="https://github.com/solidsnail/svelte-sortablejs/raw/master/docs/logo.png"> </p>"
3+
description: """<p align="center"> <img src="https://github.com/solidsnail/svelte-sortablejs/raw/master/docs/logo.png"> </p>"""
44
author: "6edesign"
55
downloads: 2
66
updated: "2020-10-26T21:07:23.556Z"

apps/svelte.dev/src/lib/server/generated/registry/6edesign-svelte-three.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: "@6edesign/svelte-three"
33
description: "Demo"
44
author: "6edesign"
5-
downloads: 4
5+
downloads: 23
66
updated: "2021-01-20T04:40:39.253Z"
77
tags:
88
- ui

apps/svelte.dev/src/lib/server/generated/registry/a-luna-svelte-simple-tables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "Accessible, sortable, paginated table component"
44
repo_url: "https://github.com/a-luna/svelte-simple-tables"
55
author: "Aaron Luna"
66
homepage: "https://github.com/a-luna/svelte-simple-tables"
7-
downloads: 27
7+
downloads: 47
88
updated: "2022-07-19T09:27:18.684Z"
99
github_stars: 6
1010
tags:

apps/svelte.dev/src/lib/server/generated/registry/abineo-svelte-forms.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "Well tested form validation for svelte & sveltekit (js/ts)"
44
repo_url: "https://github.com/abineo-ag/svelte-forms"
55
author: "christoph-jeanluc-schneider"
66
homepage: "https://github.com/abineo-ag/svelte-forms#readme"
7-
downloads: 1
7+
downloads: 14
88
updated: "2023-06-27T14:48:12.451Z"
99
tags:
1010
- utility

0 commit comments

Comments
 (0)