From 3a4cd2c361923dd56845349edcc40c77eab0a7f7 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Mon, 29 Jun 2026 05:15:50 +0800 Subject: [PATCH] Revert "fix: update js-yaml imports for v5" This reverts commit 250198d547af692fe6ccb36b9929b2f55785b8d1. Revert "chore(deps): update dependency js-yaml to v5 (#7331)" This reverts commit b44f671fc2c3dba9842994f6d4bc1cd85d699068. --- package.json | 2 +- pnpm-lock.yaml | 12 ++------- .../profile/groups-editor-viewer.tsx | 22 ++++++++-------- .../profile/proxies-editor-viewer.tsx | 10 +++---- .../profile/rules-editor-viewer.tsx | 26 +++++++++---------- src/components/proxy/proxy-chain.tsx | 4 +-- src/components/setting/mods/dns-viewer.tsx | 12 ++++----- 7 files changed, 40 insertions(+), 48 deletions(-) diff --git a/package.json b/package.json index 4830d9a86..6c41482a1 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "foxact": "^0.3.4", "foxts": "^5.4.2", "i18next": "^26.2.0", - "js-yaml": "^5.0.0", + "js-yaml": "^4.1.1", "lodash-es": "^4.18.1", "meta-json-schema": "^1.19.25", "monaco-editor": "^0.55.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9062d9f84..46dc49210 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -81,8 +81,8 @@ importers: specifier: ^26.2.0 version: 26.2.0(typescript@6.0.3) js-yaml: - specifier: ^5.0.0 - version: 5.1.0 + specifier: ^4.1.1 + version: 4.1.1 lodash-es: specifier: ^4.18.1 version: 4.18.1 @@ -2659,10 +2659,6 @@ packages: resolution: {integrity: sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA==} hasBin: true - js-yaml@5.1.0: - resolution: {integrity: sha512-s8VA5jkR8f22S3NAXmhKPFqGUduqZGlsufabVOgN14iTdw/RXcym7bKkbwjxLK9Yw2lEvvmJjFp119+KPeo8Kg==} - hasBin: true - jsesc@3.1.0: resolution: {integrity: sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==} engines: {node: '>=6'} @@ -6229,10 +6225,6 @@ snapshots: dependencies: argparse: 2.0.1 - js-yaml@5.1.0: - dependencies: - argparse: 2.0.1 - jsesc@3.1.0: {} json-buffer@3.0.1: {} diff --git a/src/components/profile/groups-editor-viewer.tsx b/src/components/profile/groups-editor-viewer.tsx index 527db086f..666ee0e97 100644 --- a/src/components/profile/groups-editor-viewer.tsx +++ b/src/components/profile/groups-editor-viewer.tsx @@ -32,7 +32,7 @@ import { cancelIdleCallback, requestIdleCallback, } from 'foxact/request-idle-callback' -import { dump, load } from 'js-yaml' +import yaml from 'js-yaml' import { startTransition, useCallback, @@ -126,7 +126,7 @@ const buildGroupsYaml = ( append: IProxyGroupConfig[], deleteList: string[], ) => { - return dump( + return yaml.dump( { prepend, append, @@ -334,7 +334,7 @@ export const GroupsEditorViewer = (props: Props) => { } const fetchContent = useCallback(async () => { const data = await readProfileFile(property) - const obj = load(data) as ISeqProfileConfig | null + const obj = yaml.load(data) as ISeqProfileConfig | null setPrependSeq(obj?.prepend || []) setAppendSeq(obj?.append || []) @@ -358,7 +358,7 @@ export const GroupsEditorViewer = (props: Props) => { return } - const obj = load(currData) as ISeqProfileConfig | null + const obj = yaml.load(currData) as ISeqProfileConfig | null startTransition(() => { setPrependSeq(obj?.prepend ?? []) setAppendSeq(obj?.append ?? []) @@ -397,13 +397,13 @@ export const GroupsEditorViewer = (props: Props) => { const fetchProxyPolicy = useCallback(async () => { const data = await readProfileFile(profileUid) const proxiesData = await readProfileFile(proxiesUid) - const originGroupsObj = load(data) as { + const originGroupsObj = yaml.load(data) as { 'proxy-groups': IProxyGroupConfig[] } | null - const originProxiesObj = load(data) as { proxies: [] } | null + const originProxiesObj = yaml.load(data) as { proxies: [] } | null const originProxies = originProxiesObj?.proxies || [] - const moreProxiesObj = load(proxiesData) as ISeqProfileConfig | null + const moreProxiesObj = yaml.load(proxiesData) as ISeqProfileConfig | null const morePrependProxies = moreProxiesObj?.prepend || [] const moreAppendProxies = moreProxiesObj?.append || [] const moreDeleteProxies = normalizeDeleteSeq(moreProxiesObj?.delete) @@ -443,21 +443,21 @@ export const GroupsEditorViewer = (props: Props) => { const mergeData = await readProfileFile(mergeUid) const globalMergeData = await readProfileFile('Merge') - const originGroupsObj = load(data) as { + const originGroupsObj = yaml.load(data) as { 'proxy-groups': IProxyGroupConfig[] } | null - const originProviderObj = load(data) as { + const originProviderObj = yaml.load(data) as { 'proxy-providers': Record } | null const originProvider = originProviderObj?.['proxy-providers'] || {} - const moreProviderObj = load(mergeData) as { + const moreProviderObj = yaml.load(mergeData) as { 'proxy-providers': Record } | null const moreProvider = moreProviderObj?.['proxy-providers'] || {} - const globalProviderObj = load(globalMergeData) as { + const globalProviderObj = yaml.load(globalMergeData) as { 'proxy-providers': Record } | null const globalProvider = globalProviderObj?.['proxy-providers'] || {} diff --git a/src/components/profile/proxies-editor-viewer.tsx b/src/components/profile/proxies-editor-viewer.tsx index ab7efe201..27b5380e3 100644 --- a/src/components/profile/proxies-editor-viewer.tsx +++ b/src/components/profile/proxies-editor-viewer.tsx @@ -25,7 +25,7 @@ import { styled, } from '@mui/material' import { useLockFn } from 'ahooks' -import { dump, load } from 'js-yaml' +import yaml from 'js-yaml' import { startTransition, useCallback, @@ -272,7 +272,7 @@ export const ProxiesEditorViewer = (props: Props) => { const fetchProfile = useCallback(async () => { const data = await readProfileFile(profileUid) - const originProxiesObj = load(data) as { + const originProxiesObj = yaml.load(data) as { proxies: IProxyConfig[] } | null @@ -281,7 +281,7 @@ export const ProxiesEditorViewer = (props: Props) => { const fetchContent = useCallback(async () => { const data = await readProfileFile(property) - const obj = load(data) as ISeqProfileConfig | null + const obj = yaml.load(data) as ISeqProfileConfig | null setPrependSeq(obj?.prepend || []) setAppendSeq(obj?.append || []) @@ -296,7 +296,7 @@ export const ProxiesEditorViewer = (props: Props) => { return } - const obj = load(currData) as ISeqProfileConfig | null + const obj = yaml.load(currData) as ISeqProfileConfig | null startTransition(() => { setPrependSeq(obj?.prepend ?? []) setAppendSeq(obj?.append ?? []) @@ -312,7 +312,7 @@ export const ProxiesEditorViewer = (props: Props) => { const serialize = () => { try { setCurrData( - dump( + yaml.dump( { prepend: prependSeq, append: appendSeq, delete: deleteSeq }, { forceQuotes: true }, ), diff --git a/src/components/profile/rules-editor-viewer.tsx b/src/components/profile/rules-editor-viewer.tsx index 179cfc662..fac32b481 100644 --- a/src/components/profile/rules-editor-viewer.tsx +++ b/src/components/profile/rules-editor-viewer.tsx @@ -27,7 +27,7 @@ import { styled, } from '@mui/material' import { useLockFn } from 'ahooks' -import { dump, load } from 'js-yaml' +import yaml from 'js-yaml' import { startTransition, useCallback, @@ -407,7 +407,7 @@ export const RulesEditorViewer = (props: Props) => { } const fetchContent = useCallback(async () => { const data = await readProfileFile(property) - const obj = load(data) as ISeqProfileConfig | null + const obj = yaml.load(data) as ISeqProfileConfig | null setPrependSeq(obj?.prepend || []) setAppendSeq(obj?.append || []) @@ -422,7 +422,7 @@ export const RulesEditorViewer = (props: Props) => { return } - const obj = load(currData) as ISeqProfileConfig | null + const obj = yaml.load(currData) as ISeqProfileConfig | null startTransition(() => { setPrependSeq(obj?.prepend ?? []) setAppendSeq(obj?.append ?? []) @@ -439,7 +439,7 @@ export const RulesEditorViewer = (props: Props) => { const serialize = () => { try { setCurrData( - dump( + yaml.dump( { prepend: prependSeq, append: appendSeq, delete: deleteSeq }, { forceQuotes: true }, ), @@ -471,13 +471,13 @@ export const RulesEditorViewer = (props: Props) => { const mergeData = await readProfileFile(mergeUid) // merge配置文件 const globalMergeData = await readProfileFile('Merge') // global merge配置文件 - const rulesObj = load(data) as { rules: [] } | null + const rulesObj = yaml.load(data) as { rules: [] } | null - const originGroupsObj = load(data) as { + const originGroupsObj = yaml.load(data) as { 'proxy-groups': IProxyGroupConfig[] } | null const originGroups = originGroupsObj?.['proxy-groups'] || [] - const moreGroupsObj = load(groupsData) as ISeqProfileConfig | null + const moreGroupsObj = yaml.load(groupsData) as ISeqProfileConfig | null const rawPrependGroups = moreGroupsObj?.['prepend'] const morePrependGroups = Array.isArray(rawPrependGroups) ? (rawPrependGroups as IProxyGroupConfig[]) @@ -503,29 +503,29 @@ export const RulesEditorViewer = (props: Props) => { moreAppendGroups, ) - const originRuleSetObj = load(data) as { + const originRuleSetObj = yaml.load(data) as { 'rule-providers': Record } | null const originRuleSet = originRuleSetObj?.['rule-providers'] || {} - const moreRuleSetObj = load(mergeData) as { + const moreRuleSetObj = yaml.load(mergeData) as { 'rule-providers': Record } | null const moreRuleSet = moreRuleSetObj?.['rule-providers'] || {} - const globalRuleSetObj = load(globalMergeData) as { + const globalRuleSetObj = yaml.load(globalMergeData) as { 'rule-providers': Record } | null const globalRuleSet = globalRuleSetObj?.['rule-providers'] || {} const ruleSet = Object.assign({}, originRuleSet, moreRuleSet, globalRuleSet) - const originSubRuleObj = load(data) as { + const originSubRuleObj = yaml.load(data) as { 'sub-rules': Record } | null const originSubRule = originSubRuleObj?.['sub-rules'] || {} - const moreSubRuleObj = load(mergeData) as { + const moreSubRuleObj = yaml.load(mergeData) as { 'sub-rules': Record } | null const moreSubRule = moreSubRuleObj?.['sub-rules'] || {} - const globalSubRuleObj = load(globalMergeData) as { + const globalSubRuleObj = yaml.load(globalMergeData) as { 'sub-rules': Record } | null const globalSubRule = globalSubRuleObj?.['sub-rules'] || {} diff --git a/src/components/proxy/proxy-chain.tsx b/src/components/proxy/proxy-chain.tsx index 2da1bd609..68bd78385 100644 --- a/src/components/proxy/proxy-chain.tsx +++ b/src/components/proxy/proxy-chain.tsx @@ -33,7 +33,7 @@ import { Typography, useTheme, } from '@mui/material' -import { load } from 'js-yaml' +import yaml from 'js-yaml' import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { @@ -431,7 +431,7 @@ export const ProxyChain = ({ if (chainConfigData) { try { // JSON is valid YAML, so one parser covers both persisted formats. - const parsedConfig = load(chainConfigData) as ParsedChainConfig + const parsedConfig = yaml.load(chainConfigData) as ParsedChainConfig const chainItems = toChainItems(parsedConfig) if (chainItems.length > 0) { diff --git a/src/components/setting/mods/dns-viewer.tsx b/src/components/setting/mods/dns-viewer.tsx index 959ead96c..5d081f895 100644 --- a/src/components/setting/mods/dns-viewer.tsx +++ b/src/components/setting/mods/dns-viewer.tsx @@ -14,7 +14,7 @@ import { } from '@mui/material' import { invoke } from '@tauri-apps/api/core' import { useLockFn } from 'ahooks' -import { dump, load } from 'js-yaml' +import yaml from 'js-yaml' import type { Ref } from 'react' import { useCallback, @@ -385,7 +385,7 @@ export function DnsViewer({ ref }: { ref?: Ref }) { config.hosts = hosts } - setYamlContent(dump(config, { forceQuotes: true })) + setYamlContent(yaml.dump(config, { forceQuotes: true })) }, [generateDnsConfig, setYamlContent, values.hosts]) // 重置为默认值 @@ -428,7 +428,7 @@ export function DnsViewer({ ref }: { ref?: Ref }) { // 从YAML更新表单值 const updateValuesFromYaml = useCallback(() => { try { - const parsedYaml = load(yamlContent) as any + const parsedYaml = yaml.load(yamlContent) as any if (!parsedYaml) return skipYamlSyncRef.current = true @@ -478,7 +478,7 @@ export function DnsViewer({ ref }: { ref?: Ref }) { if (dnsConfigExists) { const dnsConfig = await invoke('get_dns_config_content', {}) - const config = load(dnsConfig) as any + const config = yaml.load(dnsConfig) as any updateValuesFromConfig(config) setYamlContent(dnsConfig) @@ -524,7 +524,7 @@ export function DnsViewer({ ref }: { ref?: Ref }) { } } else { // 使用YAML编辑器的值 - const parsedConfig = load(yamlContent) + const parsedConfig = yaml.load(yamlContent) if (typeof parsedConfig !== 'object' || parsedConfig === null) { throw new Error(t('settings.modals.dns.errors.invalid')) } @@ -594,7 +594,7 @@ export function DnsViewer({ ref }: { ref?: Ref }) { // 允许YAML编辑后立即分析和更新表单值 try { - const config = load(value || '') as any + const config = yaml.load(value || '') as any if (config && typeof config === 'object') { setTimeout(() => { updateValuesFromConfig(config)