Huakun Shen e21bef154e
Feature: install extension from JSR (#53)
* chore: upgrade many dependencies

* fix: @kksh/svelte, migrate 5

* refactor: move dialog plugin code out of ui package

* chore: disable check-types in api build.ts

Causing build error in kunkun-services

* feat: add jsr package

* feat: implement jsr package with API and parsers for jsr

* feat: modify API, add function to extract linked github repo from html

* perf: improve jsr package API with @hk/jsr-client

* feat: add jsr package version table for publishing extension

* fix: dependency and type incompatibility in ui package

* feat: add validateJsrPackageAsKunkunExtension function in jsr package

* feat: improve jsr table

* feat: add a ElementAlert component

* feat: update ElementAlert UI

* chore: update deno.lock

* chore: enable submodule support in jsr-publish workflow

* chore: bump version to 0.0.48 in jsr.json

* feat: regenerate supabase types, add author_id

* Move @kksh/jsr package to @kksh/api

* update deno.lock

* chore: change @tauri-plugin/plugin-upload version from git url to version

* feat: add rounded corner for ElementAlert

* chore: update deno.lock

* chore: bump version to 0.0.51 in jsr.json and update import paths for ExtPackageJson

* feat: add publishExtJSR API to SupabaseAPI

* refactor: replace "@hk/jsr-client" from jsr with @huakunshen/jsr-client from npm

* chore: update  deno.lock

* feat: update validateJsrPackageAsKunkunExtension return type

* refactor: improve error message

* feat: add metadata to ext_publish, update database.types.ts

* feat: add models module for Supabase with ExtPublishMetadata and source type enumeration

* feat: support installing JSR package as extension

Since JSR overwrites package.json with its own code to be compatible with npm, causing manifest parsing to be impossible. I add metadata field to ext_publish.
When extension comes from jsr, kunkun app will fetch the original package.json from jsr and overwrite the one modified by jsr.

* fix: add missing dep @tauri-apps/plugin-upload to @kksh/extension

* chore: update version to 0.0.52 in version.ts
2025-01-10 08:23:18 -05:00

134 lines
3.7 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import * as v from "valibot";
import { ExtPackageJson } from "../../../models/manifest";
import {
getAllVersionsOfJsrPackage,
getJsrNpmPackageVersionMetadata,
getJsrNpmPkgMetadata,
getJsrPackageGitHubRepo,
getJsrPackageHtml,
getJsrPackageMetadata,
getJsrPackageSrcFile,
getNpmPackageTarballUrl,
isSignedByGitHubAction,
jsrPackageExists,
splitRawJsrPkgName,
translateJsrToNpmPkgName,
} from "../index";
import { JsrPackageMetadata, NpmPkgMetadata } from "../models";
describe("Test the helper functions", () => {
test("Get Package Html", async () => {
const html = await getJsrPackageHtml("kunkun", "kkrpc");
expect(html).toBeDefined();
});
test("Signed By GitHub Action", async () => {
const kkrpcSigned = await isSignedByGitHubAction(
"kunkun",
"kkrpc",
"0.0.14",
);
expect(kkrpcSigned).toBe(true);
const kkrpcSignedVersion = await isSignedByGitHubAction(
"kunkun",
"kkrpc",
"0.0.14",
);
expect(kkrpcSignedVersion).toBe(true);
expect(kkrpcSignedVersion).toBe(true);
const kunkunApiSigned = await isSignedByGitHubAction(
"kunkun",
"api",
"0.0.47",
);
expect(kunkunApiSigned).toBe(false);
});
test("Get Linked GitHub Repo", async () => {
const repo = await getJsrPackageGitHubRepo("kunkun", "kkrpc");
expect(repo).toBeDefined();
expect(repo?.owner).toBe("kunkunsh");
expect(repo?.name).toBe("kkrpc");
});
test("Get Package Metadata", async () => {
const metadata = await getJsrPackageMetadata("kunkun", "api");
const parsed = v.parse(JsrPackageMetadata, metadata);
expect(parsed).toBeDefined();
});
test("Get Package's package.json", async () => {
const packageJson = await getJsrPackageSrcFile(
"kunkun",
"ext-image-processing",
"0.0.6",
"package.json",
);
expect(packageJson).toBeDefined();
const parsed = v.parse(ExtPackageJson, JSON.parse(packageJson!));
expect(parsed).toBeDefined();
});
test("Get Package's README.md", async () => {
const readme = await getJsrPackageSrcFile(
"kunkun",
"api",
"0.0.47",
"README.md",
);
expect(readme).toBeDefined();
});
test("Translate Jsr Package Name to Npm Package Name", () => {
const npmPkgName = translateJsrToNpmPkgName("kunkun", "api");
expect(npmPkgName).toBe("kunkun__api");
});
test("Split Jsr Package Name", async () => {
const { scope, name } = await splitRawJsrPkgName("@kunkun/api");
expect(scope).toBe("kunkun");
expect(name).toBe("api");
expect(splitRawJsrPkgName("kunkun/api")).rejects.toThrow();
});
test("Get Npm Package Metadata", async () => {
const metadata = await getJsrNpmPkgMetadata("kunkun", "api");
const parsed = v.parse(NpmPkgMetadata, metadata);
expect(parsed).toBeDefined();
});
test("Get Npm Package Version Metadata", async () => {
const metadata = await getJsrNpmPackageVersionMetadata(
"kunkun",
"api",
"0.0.47",
);
expect(metadata).toBeDefined();
});
test("Get Npm Package Tarball Url", async () => {
const url = await getNpmPackageTarballUrl("kunkun", "api", "0.0.47");
expect(url).toBeDefined();
});
test("Get All Versions Of Jsr Package", async () => {
const versions = await getAllVersionsOfJsrPackage("kunkun", "api");
expect(versions).toBeDefined();
// verify: versions should match npm api
const npmPkgMetadata = await getJsrNpmPkgMetadata("kunkun", "api");
expect(versions).toEqual(Object.keys(npmPkgMetadata.versions));
});
test("Jsr Package Exists", async () => {
expect(await jsrPackageExists("kunkun", "api")).toBe(true);
expect(await jsrPackageExists("hk", "non-existent-package")).toBe(
false,
);
expect(await jsrPackageExists("hk", "jsr-client", "0.1.2")).toBe(true);
expect(await jsrPackageExists("hk", "jsr-client", "0.1.500")).toBe(
false,
);
});
});