Skip to content
Merged
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
70 changes: 70 additions & 0 deletions .github/workflows/download-packages-popularity.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Download and save packages popularity

env:
CI: "true"

on:
push:
branches:
- master
paths:
- .github/workflows/*.yml
- "cases/*.ts"
- "*.ts"
- package.json
- package-lock.json
- bun.lockb

jobs:
build:
name: "Node ${{ matrix.node-version }}"

runs-on: ubuntu-latest

strategy:
max-parallel: 1
matrix:
node-version:
- 23.x

steps:
- uses: actions/checkout@v4

- name: Cache node modules
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: npm install
run: npm ci

- name: download-packages-popularity
run: npm run download-packages-popularity

## FIX: https://github.com/github-actions-x/commit/issues/16
- name: Expose git commit data
uses: rlespinasse/git-commit-data-action@v1 ## https://github.com/rlespinasse/git-commit-data-action

- name: push
uses: github-actions-x/commit@v2.9
## prevents forked repos from comitting results in PRs
if: github.repository == 'moltar/typescript-runtime-type-benchmarks'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
push-branch: master
commit-message: 'feat: adds popularity of packages'
rebase: 'true'
name: ${{ env.GIT_COMMIT_AUTHOR_NAME }} ## FIX: https://github.com/github-actions-x/commit/issues/16
email: ${{ env.GIT_COMMIT_AUTHOR_EMAIL }} ## FIX: https://github.com/github-actions-x/commit/issues/16
Binary file modified bun.lockb
Binary file not shown.
33 changes: 30 additions & 3 deletions docs/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ BENCHMARKS.forEach(b => {
BENCHMARKS_ORDER[b.name] = b.order;
});

const PACKAGES_POPULARITY: { [k: string]: number } = {};

type PackagePopularity = {
name: string;
weeklyDownloads: number;
};

async function loadPackagesPopularity() {
await fetch('packagesPopularity.json')
.then(res => res.json() as Promise<PackagePopularity[]>)
.then(data => {
data.forEach(p => {
PACKAGES_POPULARITY[p.name] = p.weeklyDownloads;
});
});
}

function normalizePartialValues(values: BenchmarkResult[]): BenchmarkResult[] {
if (!values.length) {
return [];
Expand Down Expand Up @@ -147,7 +164,7 @@ async function graph({
selectedBunVersions: string[];
benchmarkResultsNodejs: BenchmarkResult[];
benchmarkResultsBun: BenchmarkResult[];
sort?: 'alphabetically' | 'fastest';
sort?: 'alphabetically' | 'fastest' | 'popularity';
}) {
if (
!selectedBenchmarks.length ||
Expand Down Expand Up @@ -230,6 +247,13 @@ async function graph({
sortedValues = [...valuesNodejs, ...valuesBun].sort((a, b) =>
a.name < b.name ? -1 : 1,
);
} else if (sort === 'popularity') {
sortedValues = [...valuesNodejs, ...valuesBun].sort((a, b) => {
const aPopularity = PACKAGES_POPULARITY[a.name] || 0;
const bPopularity = PACKAGES_POPULARITY[b.name] || 0;

return bPopularity - aPopularity;
});
}

// remove duplicates not sure whether vega-lite can handle that
Expand Down Expand Up @@ -427,7 +451,7 @@ class App extends Component<
selectedBunVersions: { [key: string]: boolean };
valuesNodeJs: BenchmarkResult[];
valuesBun: BenchmarkResult[];
sortBy: 'fastest' | 'alphabetically';
sortBy: 'fastest' | 'alphabetically' | 'popularity';
}
> {
state = {
Expand Down Expand Up @@ -470,7 +494,9 @@ class App extends Component<
return res;
}

componentDidMount() {
async componentDidMount() {
await loadPackagesPopularity();

NODE_VERSIONS.forEach((v, i) => {
fetch(`results/node-${v}.json`)
.then(response => response.json() as Promise<BenchmarkResponse>)
Expand Down Expand Up @@ -649,6 +675,7 @@ class App extends Component<
>
<option value="fastest">Fastest</option>
<option value="alphabetically">Alphabetically</option>
<option value="popularity">Popularity</option>
</select>
</label>
</div>
Expand Down
93 changes: 65 additions & 28 deletions docs/dist/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/packagesPopularity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"name":"aeria","weeklyDownloads":925},{"name":"ajv","weeklyDownloads":108193774},{"name":"arktype","weeklyDownloads":60942},{"name":"banditypes","weeklyDownloads":250},{"name":"bueno","weeklyDownloads":70},{"name":"caketype","weeklyDownloads":70},{"name":"class-transformer-validator-sync","weeklyDownloads":3167945},{"name":"computed-types","weeklyDownloads":1778},{"name":"decoders","weeklyDownloads":13809},{"name":"io-ts","weeklyDownloads":1333952},{"name":"jointz","weeklyDownloads":107},{"name":"json-decoder","weeklyDownloads":127},{"name":"$mol_data","weeklyDownloads":85},{"name":"@mojotech/json-type-validation","weeklyDownloads":15090},{"name":"mondrian-framework","weeklyDownloads":77},{"name":"myzod","weeklyDownloads":25398},{"name":"ok-computer","weeklyDownloads":70},{"name":"parse-dont-validate (chained function)","weeklyDownloads":195},{"name":"parse-dont-validate (named parameters)","weeklyDownloads":195},{"name":"purify-ts","weeklyDownloads":16508},{"name":"r-assign","weeklyDownloads":1684},{"name":"rescript-schema","weeklyDownloads":888},{"name":"rulr","weeklyDownloads":1227},{"name":"runtypes","weeklyDownloads":224592},{"name":"@sapphire/shapeshift","weeklyDownloads":241466},{"name":"simple-runtypes","weeklyDownloads":794},{"name":"@sinclair/typebox-(ahead-of-time)","weeklyDownloads":30679213},{"name":"@sinclair/typebox-(dynamic)","weeklyDownloads":30679213},{"name":"@sinclair/typebox-(just-in-time)","weeklyDownloads":30679213},{"name":"spectypes","weeklyDownloads":77},{"name":"succulent","weeklyDownloads":87},{"name":"superstruct","weeklyDownloads":1626205},{"name":"suretype","weeklyDownloads":30307},{"name":"tiny-schema-validator","weeklyDownloads":15},{"name":"to-typed","weeklyDownloads":74},{"name":"toi","weeklyDownloads":695},{"name":"ts-interface-checker","weeklyDownloads":9449654},{"name":"ts-json-validator","weeklyDownloads":32701},{"name":"ts-runtime-checks","weeklyDownloads":567},{"name":"ts-utils","weeklyDownloads":71},{"name":"tson","weeklyDownloads":70},{"name":"@typeofweb/schema","weeklyDownloads":152},{"name":"typia","weeklyDownloads":152527},{"name":"unknownutil","weeklyDownloads":882},{"name":"valibot","weeklyDownloads":412391},{"name":"valita","weeklyDownloads":13451},{"name":"vality","weeklyDownloads":122},{"name":"yup","weeklyDownloads":6542575},{"name":"zod","weeklyDownloads":12787921},{"name":"deepkit","weeklyDownloads":8114},{"name":"effect-schema","weeklyDownloads":811506},{"name":"ts-auto-guard","weeklyDownloads":7029}]
Loading