optimize deps

This commit is contained in:
Stephen Zhou
2026-03-18 19:50:58 +08:00
parent 63eed30e78
commit af9c577bf6
5 changed files with 20 additions and 92 deletions

View File

@ -5,12 +5,12 @@ import { RiLoader2Line } from '@remixicon/react'
import * as React from 'react'
import { useEffect, useMemo } from 'react'
import { Trans, useTranslation } from 'react-i18next'
import { gte } from 'semver'
import Button from '@/app/components/base/button'
import useCheckInstalled from '@/app/components/plugins/install-plugin/hooks/use-check-installed'
import { useAppContext } from '@/context/app-context'
import { uninstallPlugin } from '@/service/plugins'
import { useInstallPackageFromLocal, usePluginTaskList } from '@/service/use-plugins'
import { gte } from '@/utils/semver'
import Card from '../../../card'
import { TaskStatus } from '../../../types'
import checkTaskStatus from '../../base/check-task-status'
@ -117,7 +117,7 @@ const Installed: FC<Props> = ({
return (
<>
<div className="flex flex-col items-start justify-center gap-4 self-stretch px-6 py-3">
<div className="text-text-secondary system-md-regular">
<div className="system-md-regular text-text-secondary">
<p>{t(`${i18nPrefix}.readyToInstall`, { ns: 'plugin' })}</p>
<p>
<Trans
@ -127,7 +127,7 @@ const Installed: FC<Props> = ({
/>
</p>
{!isDifyVersionCompatible && (
<p className="flex items-center gap-1 text-text-warning system-md-regular">
<p className="system-md-regular flex items-center gap-1 text-text-warning">
{t('difyVersionNotCompatible', { ns: 'plugin', minimalDifyVersion: payload.meta.minimum_dify_version })}
</p>
)}

View File

@ -5,11 +5,11 @@ import { RiLoader2Line } from '@remixicon/react'
import * as React from 'react'
import { useEffect, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import { gte } from 'semver'
import Button from '@/app/components/base/button'
import useCheckInstalled from '@/app/components/plugins/install-plugin/hooks/use-check-installed'
import { useAppContext } from '@/context/app-context'
import { useInstallPackageFromMarketPlace, usePluginDeclarationFromMarketPlace, usePluginTaskList, useUpdatePackageFromMarketPlace } from '@/service/use-plugins'
import { gte } from '@/utils/semver'
import Card from '../../../card'
// import { RiInformation2Line } from '@remixicon/react'
import { TaskStatus } from '../../../types'
@ -133,10 +133,10 @@ const Installed: FC<Props> = ({
return (
<>
<div className="flex flex-col items-start justify-center gap-4 self-stretch px-6 py-3">
<div className="text-text-secondary system-md-regular">
<div className="system-md-regular text-text-secondary">
<p>{t(`${i18nPrefix}.readyToInstall`, { ns: 'plugin' })}</p>
{!isDifyVersionCompatible && (
<p className="text-text-warning system-md-regular">
<p className="system-md-regular text-text-warning">
{t('difyVersionNotCompatible', { ns: 'plugin', minimalDifyVersion: pluginDeclaration?.manifest.meta.minimum_dify_version })}
</p>
)}

View File

@ -4,6 +4,7 @@ import type { Placement } from '@/app/components/base/ui/placement'
import * as React from 'react'
import { useCallback } from 'react'
import { useTranslation } from 'react-i18next'
import { lt } from 'semver'
import Badge from '@/app/components/base/badge'
import {
Popover,
@ -13,7 +14,6 @@ import {
import useTimestamp from '@/hooks/use-timestamp'
import { useVersionListOfPlugin } from '@/service/use-plugins'
import { cn } from '@/utils/classnames'
import { lt } from '@/utils/semver'
type Props = {
disabled?: boolean

View File

@ -1,93 +1,13 @@
type SemverIdentifier = number | string
import semver from 'semver'
type ParsedSemver = {
core: number[]
prerelease: SemverIdentifier[]
}
const parseIdentifier = (value: string): SemverIdentifier => {
if (/^\d+$/.test(value))
return Number(value)
return value
}
const parseSemver = (version: string): ParsedSemver => {
const normalized = version.trim().replace(/^v/i, '').split('+')[0]
const [corePart, prereleasePart] = normalized.split('-', 2)
return {
core: corePart.split('.').map(part => Number(part) || 0),
prerelease: prereleasePart
? prereleasePart.split('.').filter(Boolean).map(parseIdentifier)
: [],
}
}
const compareIdentifier = (left: SemverIdentifier, right: SemverIdentifier) => {
if (typeof left === 'number' && typeof right === 'number')
return Math.sign(left - right)
if (typeof left === 'number')
return -1
if (typeof right === 'number')
return 1
return left.localeCompare(right)
}
const comparePrerelease = (left: SemverIdentifier[], right: SemverIdentifier[]) => {
if (!left.length && !right.length)
return 0
if (!left.length)
return 1
if (!right.length)
return -1
const maxLength = Math.max(left.length, right.length)
for (let i = 0; i < maxLength; i += 1) {
const leftId = left[i]
const rightId = right[i]
if (leftId === undefined)
return -1
if (rightId === undefined)
return 1
const result = compareIdentifier(leftId, rightId)
if (result !== 0)
return result
}
return 0
export const getLatestVersion = (versionList: string[]) => {
return semver.rsort(versionList)[0]
}
export const compareVersion = (v1: string, v2: string) => {
const left = parseSemver(v1)
const right = parseSemver(v2)
const maxCoreLength = Math.max(left.core.length, right.core.length)
for (let i = 0; i < maxCoreLength; i += 1) {
const diff = (left.core[i] || 0) - (right.core[i] || 0)
if (diff !== 0)
return Math.sign(diff)
}
return comparePrerelease(left.prerelease, right.prerelease)
}
export const gte = (v1: string, v2: string) => compareVersion(v1, v2) >= 0
export const lt = (v1: string, v2: string) => compareVersion(v1, v2) < 0
export const getLatestVersion = (versionList: string[]) => {
return [...versionList].sort((left, right) => compareVersion(right, left))[0]
return semver.compare(v1, v2)
}
export const isEqualOrLaterThanVersion = (baseVersion: string, targetVersion: string) => {
return gte(baseVersion, targetVersion)
return semver.gte(baseVersion, targetVersion)
}

View File

@ -79,6 +79,14 @@ export default defineConfig(({ mode }) => {
// SyntaxError: Named export not found. The requested module is a CommonJS module, which may not support all module.exports as named exports
noExternal: ['emoji-mart'],
},
environments: {
rsc: {
optimizeDeps: { include: ['semver'] },
},
ssr: {
optimizeDeps: { include: ['semver'] },
},
},
}
: {}),