mirror of
https://github.com/kunkunsh/kunkun.git
synced 2025-04-04 14:46:42 +00:00
fix: install and upgrade in store for jsr packages
This commit is contained in:
parent
130608cd92
commit
7e811440b8
@ -22,7 +22,11 @@ function createExtensionsStore(): Writable<ExtPackageJsonExtra[]> & {
|
||||
registerNewExtensionByPath: (extPath: string) => Promise<ExtPackageJsonExtra>
|
||||
uninstallStoreExtensionByIdentifier: (identifier: string) => Promise<ExtPackageJsonExtra>
|
||||
uninstallDevExtensionByIdentifier: (identifier: string) => Promise<ExtPackageJsonExtra>
|
||||
upgradeStoreExtension: (identifier: string, tarballUrl: string) => Promise<ExtPackageJsonExtra>
|
||||
upgradeStoreExtension: (
|
||||
identifier: string,
|
||||
tarballUrl: string,
|
||||
extras?: { overwritePackageJson?: string }
|
||||
) => Promise<ExtPackageJsonExtra>
|
||||
} {
|
||||
const store = writable<ExtPackageJsonExtra[]>([])
|
||||
|
||||
@ -176,12 +180,13 @@ function createExtensionsStore(): Writable<ExtPackageJsonExtra[]> & {
|
||||
|
||||
async function upgradeStoreExtension(
|
||||
identifier: string,
|
||||
tarballUrl: string
|
||||
tarballUrl: string,
|
||||
extras?: { overwritePackageJson?: string }
|
||||
): Promise<ExtPackageJsonExtra> {
|
||||
const extsDir = get(appConfig).extensionsInstallDir
|
||||
if (!extsDir) throw new Error("Extension path not set")
|
||||
return uninstallStoreExtensionByIdentifier(identifier).then(() =>
|
||||
installFromTarballUrl(tarballUrl, extsDir)
|
||||
installFromTarballUrl(tarballUrl, extsDir, extras)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,9 @@
|
||||
import { supabaseAPI } from "@/supabase"
|
||||
import { goBackOnEscapeClearSearchTerm, goHomeOnEscapeClearSearchTerm } from "@/utils/key"
|
||||
import { goBack, goHome } from "@/utils/route"
|
||||
import { SBExt } from "@kksh/api/supabase"
|
||||
import { SBExt, type Tables } from "@kksh/api/supabase"
|
||||
import { isUpgradable } from "@kksh/extension"
|
||||
import type { ExtPublishMetadata } from "@kksh/supabase/models"
|
||||
import { Button, Command } from "@kksh/svelte5"
|
||||
import { Constants } from "@kksh/ui"
|
||||
import { ExtListItem } from "@kksh/ui/extension"
|
||||
@ -14,6 +15,7 @@
|
||||
import { ArrowLeft } from "lucide-svelte"
|
||||
import type { Snippet } from "svelte"
|
||||
import { toast } from "svelte-sonner"
|
||||
import { getInstallExtras } from "./[identifier]/helper.js"
|
||||
|
||||
let { data } = $props()
|
||||
const { storeExtList, installedStoreExts, installedExtsMap, upgradableExpsMap } = data
|
||||
@ -38,10 +40,17 @@
|
||||
return toast.error("Fail to get latest extension", {
|
||||
description: res.error.message
|
||||
})
|
||||
const tarballUrl = supabaseAPI.translateExtensionFilePathToUrl(res.data.tarball_path)
|
||||
return extensions.upgradeStoreExtension(ext.identifier, tarballUrl).then((newExt) => {
|
||||
toast.success(`${ext.name} Upgraded to ${newExt.version}`)
|
||||
})
|
||||
const tarballUrl = res.data.tarball_path.startsWith("http")
|
||||
? res.data.tarball_path
|
||||
: supabaseAPI.translateExtensionFilePathToUrl(res.data.tarball_path)
|
||||
const installExtras = await getInstallExtras(
|
||||
res.data as Tables<"ext_publish"> & { metadata: ExtPublishMetadata }
|
||||
)
|
||||
return extensions
|
||||
.upgradeStoreExtension(ext.identifier, tarballUrl, installExtras)
|
||||
.then((newExt) => {
|
||||
toast.success(`${ext.name} Upgraded to ${newExt.version}`)
|
||||
})
|
||||
}
|
||||
|
||||
async function onExtItemInstall(ext: SBExt) {
|
||||
@ -51,10 +60,15 @@
|
||||
description: res.error.message
|
||||
})
|
||||
|
||||
const tarballUrl = supabaseAPI.translateExtensionFilePathToUrl(res.data.tarball_path)
|
||||
const tarballUrl = res.data.tarball_path.startsWith("http")
|
||||
? res.data.tarball_path
|
||||
: supabaseAPI.translateExtensionFilePathToUrl(res.data.tarball_path)
|
||||
const installExtras = await getInstallExtras(
|
||||
res.data as Tables<"ext_publish"> & { metadata: ExtPublishMetadata }
|
||||
)
|
||||
const installDir = await getExtensionsFolder()
|
||||
return extensions
|
||||
.installFromTarballUrl(tarballUrl, installDir)
|
||||
.installFromTarballUrl(tarballUrl, installDir, installExtras)
|
||||
.then(() => toast.success(`Plugin ${ext.name} Installed`))
|
||||
.then(() =>
|
||||
supabaseAPI.incrementDownloads({
|
||||
|
@ -8,7 +8,7 @@ export async function getInstallExtras(
|
||||
if (ext.metadata.sourceType) {
|
||||
if (ext.metadata.sourceType === "jsr") {
|
||||
if (ext.metadata.source) {
|
||||
try {
|
||||
try {
|
||||
const res = await fetch(`${ext.metadata.source}/package.json`)
|
||||
const pkgJsonContent = await res.text()
|
||||
extras.overwritePackageJson = pkgJsonContent
|
||||
|
Loading…
x
Reference in New Issue
Block a user