Skip to content

Commit 9a1527f

Browse files
committed
fix: strip _ui suffix from frontend plugin directory name on git clone
Frontend plugins with _ui suffix (e.g. api_key_ui) now clone into directories without the suffix (e.g. api_key), matching the expected local plugin naming convention. Made-with: Cursor
1 parent 7bc6726 commit 9a1527f

3 files changed

Lines changed: 21 additions & 11 deletions

File tree

src/commands/plugin/add.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { requireProjectDir, fatal } from '../../lib/errors.js'
77
import { fetchPluginMarketData, filterByType, getMarketPluginType } from '../../lib/plugin-market.js'
88
import { installFromMarket, installFrontendPlugin, installBackendPlugin, runPnpmInstall } from '../../lib/plugin-install.js'
99
import type { PluginData } from '../../types/plugin.js'
10-
import { inferPluginType } from '../../types/plugin.js'
10+
import { inferPluginType, stripWebPluginSuffix } from '../../types/plugin.js'
1111

1212
/**
1313
* fba plugin add — 添加插件
@@ -32,11 +32,12 @@ export async function pluginAddAction(options: {
3232

3333
if (options.f) {
3434
// 前端插件安装
35-
const name = options.repoUrl?.split('/').pop()?.replace('.git', '') ?? 'plugin'
35+
const rawName = options.repoUrl?.split('/').pop()?.replace('.git', '') ?? 'plugin'
36+
const name = stripWebPluginSuffix(rawName)
3637
const ok = await installFrontendPlugin(
3738
projectDir,
3839
options.repoUrl ?? '',
39-
name,
40+
rawName,
4041
)
4142
if (ok) {
4243
clack.log.success(chalk.green(`${t('pluginInstallSuccess')}: ${name}`))

src/lib/plugin-install.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { run } from './process.js'
66
import { gitClone, removeGitDir } from './git.js'
77
import { getFrontendPluginDir, getBackendPluginDir, getBackendDir, getFrontendDir } from './config.js'
88
import type { InstalledPlugin, PluginInfo, PluginData } from '../types/plugin.js'
9-
import { inferPluginType } from '../types/plugin.js'
9+
import { inferPluginType, stripWebPluginSuffix } from '../types/plugin.js'
1010

1111
/**
1212
* 扫描已安装的插件(通过名称后缀 _ui 判断类型)
@@ -77,11 +77,12 @@ export async function installFrontendPlugin(
7777
pluginName: string,
7878
branch?: string,
7979
): Promise<boolean> {
80-
const pluginDir = join(getFrontendPluginDir(projectDir), pluginName)
80+
const localName = stripWebPluginSuffix(pluginName)
81+
const pluginDir = join(getFrontendPluginDir(projectDir), localName)
8182
if (existsSync(pluginDir)) {
8283
return false // 已存在
8384
}
84-
return gitClone(repoUrl, pluginDir, { branch, label: `Installing ${pluginName}` })
85+
return gitClone(repoUrl, pluginDir, { branch, label: `Installing ${localName}` })
8586
}
8687

8788
/**
@@ -125,18 +126,19 @@ export async function installFromMarket(
125126
const failed: string[] = []
126127

127128
for (const p of plugins) {
128-
const name = basename(p.git.path) || p.plugin.summary
129-
const type = inferPluginType(name)
129+
const rawName = basename(p.git.path) || p.plugin.summary
130+
const type = inferPluginType(rawName)
131+
const displayName = type === 'web' ? stripWebPluginSuffix(rawName) : rawName
130132

131133
let ok: boolean
132134
if (type === 'web') {
133-
ok = await installFrontendPlugin(projectDir, p.git.url, name, p.git.branch)
135+
ok = await installFrontendPlugin(projectDir, p.git.url, rawName, p.git.branch)
134136
} else {
135137
ok = await installBackendPlugin(projectDir, { repoUrl: p.git.url })
136138
}
137139

138-
if (ok) success.push(name)
139-
else failed.push(name)
140+
if (ok) success.push(displayName)
141+
else failed.push(displayName)
140142
}
141143

142144
return { success, failed }

src/types/plugin.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ export function ensureWebPluginName(name: string): { name: string; appended: boo
7676
return { name: `${name}${PLUGIN_WEB_SUFFIX}`, appended: true }
7777
}
7878

79+
/** 去掉 web 插件名称的 _ui 后缀,用于 git clone 目标目录名 */
80+
export function stripWebPluginSuffix(name: string): string {
81+
return name.endsWith(PLUGIN_WEB_SUFFIX)
82+
? name.slice(0, -PLUGIN_WEB_SUFFIX.length)
83+
: name
84+
}
85+
7986
/** 已安装的本地插件信息 */
8087
export interface InstalledPlugin {
8188
name: string

0 commit comments

Comments
 (0)