Skip to content

Commit

Permalink
refactor: make @kksh/ui dependent only on @kksh/api
Browse files Browse the repository at this point in the history
Reason: @kksh/ui may be published later for building website, all its dependency packages must be also published. To avoid trouble it should be standalone, depend only on packages already published
  • Loading branch information
HuakunShen committed Nov 3, 2024
1 parent 71506fb commit 97499e8
Show file tree
Hide file tree
Showing 38 changed files with 155 additions and 169 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.svelte-kit/
target/
vendors
12 changes: 6 additions & 6 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@
},
"devDependencies": {
"@kksh/types": "workspace:*",
"@sveltejs/adapter-static": "^3.0.5",
"@sveltejs/kit": "^2.7.0",
"@sveltejs/adapter-static": "^3.0.6",
"@sveltejs/kit": "^2.7.4",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"@tailwindcss/aspect-ratio": "^0.4.2",
"@tailwindcss/container-queries": "^0.1.1",
"@tailwindcss/forms": "^0.5.9",
"@tailwindcss/typography": "^0.5.15",
"@tauri-apps/cli": "^2",
"@tauri-apps/cli": "^2.0.4",
"autoprefixer": "^10.4.20",
"clsx": "^2.1.1",
"embla-carousel-svelte": "^8.3.1",
"formsnap": "^1.0.1",
"tailwind-merge": "^2.5.4",
"tailwind-variants": "^0.2.1",
"tailwindcss": "^3.4.9",
"tailwindcss": "^3.4.14",
"tailwindcss-animate": "^1.0.7",
"tslib": "^2.8.0",
"typescript": "^5.5.0",
"tslib": "^2.8.1",
"typescript": "^5.6.3",
"vaul-svelte": "^0.3.2",
"vite": "^5.4.10"
}
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/cmds/builtin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { appState } from "@/stores"
import type { BuiltinCmd } from "@kksh/types"
import type { BuiltinCmd } from "@kksh/ui/types"
import { dev } from "$app/environment"
import { goto } from "$app/navigation"

Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/cmds/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CmdTypeEnum, CustomUiCmd, ExtPackageJsonExtra, TemplateUiCmd } from "@kksh/api/models"
import type { CommandLaunchers, OnExtCmdSelect } from "@kksh/types"
import type { CommandLaunchers, OnExtCmdSelect } from "@kksh/ui/types"
import * as v from "valibot"
import { onCustomUiCmdSelect, onTemplateUiCmdSelect } from "./ext"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import type { ExtPackageJsonExtra } from "@kksh/api/models"
import { isExtPathInDev } from "@kksh/extension/utils"
import { Command } from "@kksh/svelte5"
import type { AppConfig, AppState, BuiltinCmd, CommandLaunchers } from "@kksh/types"
import type { AppConfig, AppState } from "@kksh/types"
import {
BuiltinCmds,
CustomCommandInput,
ExtCmdsGroup,
GlobalCommandPaletteFooter
} from "@kksh/ui/main"
import type { BuiltinCmd, CommandLaunchers } from "@kksh/ui/types"
import { cn } from "@kksh/ui/utils"
import type { Writable } from "svelte/store"
Expand Down
6 changes: 1 addition & 5 deletions apps/desktop/src/lib/supabase.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { Icon } from "@kksh/api/models"
import { createSB, ExtItem, SupabaseAPI, type Tables } from "@kksh/supabase"
import { createClient, type PostgrestSingleResponse } from "@supabase/supabase-js"
import * as v from "valibot"
import { number, object, optional, pipe, string, transform, type InferOutput } from "valibot"
import { createSB, SupabaseAPI } from "@kksh/supabase"
import { SUPABASE_ANON_KEY, SUPABASE_URL } from "./constants"

export const supabase = createSB(SUPABASE_URL, SUPABASE_ANON_KEY)
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script lang="ts">
import { commandLaunchers } from "@/cmds"
import { builtinCmds } from "@/cmds/builtin"
import CommandPalette from "@/components/main/CommandPalette.svelte"
import { appState } from "@/stores"
import { appConfig } from "@/stores/appConfig"
import { extensions } from "@/stores/extensions"
import { CommandPalette } from "@kksh/ui/main"
import "@kksh/ui"
</script>

Expand Down
8 changes: 4 additions & 4 deletions apps/desktop/src/routes/extension/store/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import { goBackOnEscape, goBackOnEscapeClearSearchTerm } from "@/utils/key"
import { goBack } from "@/utils/route"
import { isCompatible } from "@kksh/api"
import { SBExt } from "@kksh/api/supabase"
import { isUpgradable } from "@kksh/extension"
import { ExtItem } from "@kksh/supabase"
import { Command } from "@kksh/svelte5"
import { StoreListing } from "@kksh/ui/extension"
import { greaterThan, parse as parseSemver } from "@std/semver"
Expand All @@ -29,11 +29,11 @@
// )
// }
function onExtItemSelected(ext: ExtItem) {
function onExtItemSelected(ext: SBExt) {
goto(`./store/${ext.identifier}`)
}
async function onExtItemUpgrade(ext: ExtItem) {
async function onExtItemUpgrade(ext: SBExt) {
const res = await supabaseAPI.getLatestExtPublish(ext.identifier)
if (res.error)
return toast.error("Fail to get latest extension", { description: res.error.message })
Expand All @@ -43,7 +43,7 @@
})
}
async function onExtItemInstall(ext: ExtItem) {
async function onExtItemInstall(ext: SBExt) {
console.log("onExtItemInstall", ext)
const res = await supabaseAPI.getLatestExtPublish(ext.identifier)
if (res.error)
Expand Down
6 changes: 3 additions & 3 deletions apps/desktop/src/routes/extension/store/+page.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { appConfig, extensions, installedStoreExts } from "@/stores"
import { supabaseAPI } from "@/supabase"
import type { ExtPackageJsonExtra } from "@kksh/api/models"
import { SBExt } from "@kksh/api/supabase"
import { isExtPathInDev, isUpgradable } from "@kksh/extension"
import { ExtItem, type Tables } from "@kksh/supabase"
import { error } from "@sveltejs/kit"
import { derived, get, type Readable } from "svelte/store"
import type { PageLoad } from "./$types"

export const load: PageLoad = async (): Promise<{
storeExtList: ExtItem[]
storeExtList: SBExt[]
installedStoreExts: Readable<ExtPackageJsonExtra[]>
installedExtsMap: Readable<Record<string, string>>
upgradableExpsMap: Readable<Record<string, boolean>>
Expand All @@ -28,7 +28,7 @@ export const load: PageLoad = async (): Promise<{
const upgradableExpsMap = derived(installedStoreExts, ($exts) =>
Object.fromEntries(
$exts.map((ext) => {
const dbExt: ExtItem | undefined = storeExtsMap[ext.kunkun.identifier]
const dbExt: SBExt | undefined = storeExtsMap[ext.kunkun.identifier]
return [ext.kunkun.identifier, dbExt ? isUpgradable(dbExt, ext.version) : false]
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
delayedImageDialogOpen = imageDialogOpen
}, 500)
})
const demoImages = $derived(
ext.demo_images.map((src) => supabaseAPI.translateExtensionFilePathToUrl(src))
)
Expand Down Expand Up @@ -73,7 +74,7 @@
function onUninstallSelected() {
btnLoading = true
extensions
return extensions
.uninstallStoreExtensionByIdentifier(ext.identifier)
.then((uninstalledExt) => {
toast.success(`${uninstalledExt.name} Uninstalled`)
Expand All @@ -88,7 +89,7 @@
}
function onEnterPressed() {
console.log("onEnterPressed")
return onInstallSelected()
}
function handleKeydown(e: KeyboardEvent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { extensions } from "@/stores"
import { supabaseAPI } from "@/supabase"
import { KunkunExtManifest, type ExtPackageJsonExtra } from "@kksh/api/models"
import type { Tables } from "@kksh/supabase/types"
import type { Tables } from "@kksh/api/supabase/types"
import { error } from "@sveltejs/kit"
import { toast } from "svelte-sonner"
import { get } from "svelte/store"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dependencies": {
"@changesets/cli": "^2.27.9",
"@iconify/svelte": "^4.0.2",
"@supabase/supabase-js": "^2.43.4",
"@supabase/supabase-js": "^2.46.1",
"@tauri-apps/api": "^2.0.3",
"@tauri-apps/cli": "^2.0.4",
"@tauri-apps/plugin-deep-link": "^2.0.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/api/jsr.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"./commands": "./src/commands/index.ts",
"./runtime/deno": "./src/runtime/deno.ts",
"./permissions": "./src/permissions/index.ts",
"./supabase": "./src/supabase/index.ts",
"./supabase/types": "./src/supabase/database.types.ts",
"./dev": "./src/dev/index.ts",
"./events": "./src/events.ts"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"./permissions": "./src/permissions/index.ts",
"./dev": "./src/dev/index.ts",
"./events": "./src/events.ts",
"./supabase": "./src/supabase/index.ts",
"./supabase/types": "./src/supabase/database.types.ts",
"./package.json": "./package.json"
},
"license": "MIT",
Expand Down Expand Up @@ -45,7 +47,6 @@
"dependencies": {
"@hk/comlink-stdio": "npm:comlink-stdio@^0.1.7",
"@huakunshen/comlink": "^4.4.1",
"@rollup/plugin-typescript": "^11.1.6",
"@tauri-apps/api": "^2.0.3",
"@tauri-apps/cli": "^2.0.4",
"@tauri-apps/plugin-deep-link": "^2.0.0",
Expand All @@ -64,12 +65,11 @@
"comlink": "^4.4.1",
"lodash": "^4.17.21",
"minimatch": "^10.0.1",
"rollup": "^4.24.0",
"semver": "^7.6.3",
"svelte-sonner": "^0.3.28",
"tauri-api-adapter": "0.3.8",
"tauri-plugin-network-api": "2.0.3",
"tauri-plugin-shellx-api": "^2.0.10",
"tauri-plugin-network-api": "2.0.4",
"tauri-plugin-shellx-api": "^2.0.11",
"tauri-plugin-system-info-api": "2.0.6",
"valibot": "^0.40.0"
},
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions packages/api/src/supabase/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./model"
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Icon } from "@kksh/api/models"
import * as v from "valibot"

export const ExtItem = v.object({
/***
* Correspond to `extensions` table in supabase
*/
export const SBExt = v.object({
identifier: v.string(),
name: v.string(),
created_at: v.string(),
Expand All @@ -13,4 +16,4 @@ export const ExtItem = v.object({
icon: Icon
})

export type ExtItem = v.InferOutput<typeof ExtItem>
export type SBExt = v.InferOutput<typeof SBExt>
4 changes: 2 additions & 2 deletions packages/extension/src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { isCompatible } from "@kksh/api"
import { db, decompressTarball } from "@kksh/api/commands"
import type { ExtPackageJsonExtra } from "@kksh/api/models"
import { ExtItem } from "@kksh/supabase"
import { SBExt } from "@kksh/supabase"
import { greaterThan, parse as parseSemver } from "@std/semver"
import * as path from "@tauri-apps/api/path"
import * as dialog from "@tauri-apps/plugin-dialog"
Expand Down Expand Up @@ -145,7 +145,7 @@ export async function uninstallExtensionByPath(extPath: string) {
return fs.remove(extPath, { recursive: true }).then(() => db.deleteExtensionByPath(extPath))
}

export function isUpgradable(dbExt: ExtItem, installedExtVersion: string) {
export function isUpgradable(dbExt: SBExt, installedExtVersion: string) {
const upgradable =
greaterThan(parseSemver(dbExt.version), parseSemver(installedExtVersion)) && dbExt.api_version
? isCompatible(dbExt.api_version)
Expand Down
3 changes: 1 addition & 2 deletions packages/supabase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"setup": "bun setup.ts"
},
"exports": {
".": "./src/index.ts",
"./types": "./src/types/database.types.ts"
".": "./src/index.ts"
},
"dependencies": {
"@kksh/api": "workspace:*"
Expand Down
10 changes: 5 additions & 5 deletions packages/supabase/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { SBExt } from "@kksh/api/supabase"
import type { Database, Tables } from "@kksh/api/supabase/types"
import type { PostgrestSingleResponse, SupabaseClient } from "@supabase/supabase-js"
import * as v from "valibot"
import { ExtItem } from "./model"
import type { Database, Tables } from "./types/database.types"

export class SupabaseAPI {
constructor(private supabase: SupabaseClient<Database>) {}
async getExtList(): Promise<ExtItem[]> {
async getExtList(): Promise<SBExt[]> {
const res = await this.supabase
.from("extensions")
.select(
Expand All @@ -16,13 +16,13 @@ export class SupabaseAPI {
const dbExts: Tables<"extensions">[] = res.data ?? []
return dbExts
.map((x) => {
const parsedNode = v.safeParse(ExtItem, x)
const parsedNode = v.safeParse(SBExt, x)
if (!parsedNode.success) {
console.error(`Fail to parse extension`, x)
console.warn(parsedNode.issues)
console.error(v.flatten(parsedNode.issues))
}
return parsedNode.success ? v.parse(ExtItem, parsedNode.output) : null
return parsedNode.success ? v.parse(SBExt, parsedNode.output) : null
})
.filter((x) => x !== null)
}
Expand Down
6 changes: 3 additions & 3 deletions packages/supabase/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Database } from "@kksh/api/supabase/types"
import { createClient } from "@supabase/supabase-js"
import { type Database } from "./types/database.types"

export function createSB(supabaseUrl: string, supabaseAnonKey: string) {
return createClient<Database>(supabaseUrl, supabaseAnonKey)
}
export { SupabaseAPI } from "./api"

export type { Database, Tables } from "./types/database.types"
export { ExtItem } from "./model"
export type { Database, Tables } from "@kksh/api/supabase/types"
export { SBExt } from "@kksh/api/supabase"
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

## Permission Table

<table>
Expand All @@ -7,7 +6,6 @@
<th>Description</th>
</tr>


<tr>
<td>

Expand Down
1 change: 0 additions & 1 deletion packages/types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from "./appConfig"
export * from "./appState"
export * from "./command"
11 changes: 5 additions & 6 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"types": "./src/index.ts",
"svelte": "./src/index.ts"
},
"./types": {
"types": "./src/types.ts",
"svelte": "./src/types.ts"
},
"./custom": {
"types": "./src/components/custom/index.ts",
"svelte": "./src/components/custom/index.ts"
Expand All @@ -30,12 +34,7 @@
"lint": "eslint ."
},
"devDependencies": {
"@kksh/eslint-config": "workspace:*",
"@kksh/extension": "workspace:*",
"@kksh/supabase": "workspace:*",
"@kksh/types": "workspace:*",
"@kksh/typescript-config": "workspace:*",
"@kksh/utils": "workspace:*",
"@kksh/api": "workspace:*",
"bits-ui": "1.0.0-next.36",
"clsx": "^2.1.1",
"lucide-svelte": "^0.454.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/common/IconMultiplexer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Icon from "@iconify/svelte"
import { IconEnum, IconType, Icon as TIcon } from "@kksh/api/models"
import { Button } from "@kksh/svelte5"
import { cn } from "$lib/utils"
import { cn } from "@kksh/ui/utils"
const { icon, class: className }: { icon: TIcon; class?: string } = $props()
</script>
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/src/components/extension/ExtListItem.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script lang="ts">
import Icon from "@iconify/svelte"
import { Icon as TIcon } from "@kksh/api/models"
import { ExtItem } from "@kksh/supabase"
import { SBExt } from "@kksh/api/supabase"
import { Button, Command } from "@kksh/svelte5"
import { IconMultiplexer } from "@kksh/ui"
import { humanReadableNumber } from "@kksh/utils"
import { humanReadableNumber } from "@kksh/ui/utils"
import { greaterThan, parse as parseSemver } from "@std/semver"
import { CircleCheckBigIcon, MoveRightIcon } from "lucide-svelte"
import { parse } from "valibot"
Expand All @@ -17,7 +17,7 @@
onInstall,
isUpgradable
}: {
ext: ExtItem
ext: SBExt
installedVersion?: string
onSelect: () => void
onUpgrade: () => void
Expand Down
Loading

0 comments on commit 97499e8

Please sign in to comment.