mirror of
https://github.com/zyycn/codex-proxy-rs.git
synced 2026-11-06 08:06:19 +00:00
* chore(deps-dev): bump @antfu/eslint-config in /frontend Bumps [@antfu/eslint-config](https://github.com/antfu/eslint-config) from 9.5.1 to 10.0.0. - [Release notes](https://github.com/antfu/eslint-config/releases) - [Commits](https://github.com/antfu/eslint-config/compare/v9.5.1...v10.0.0) --- updated-dependencies: - dependency-name: "@antfu/eslint-config" dependency-version: 10.0.0 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * chore(frontend): migrate formatting to ESLint v10 Co-authored-by: Codex <noreply@openai.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Zyy <zyycn@users.noreply.github.com> Co-authored-by: Codex <noreply@openai.com>
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import type { Plugin } from 'vite'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { build } from 'vite'
|
|
|
|
// 桥运行在隔离 iframe 中,独立编译以保证注入源码不依赖宿主闭包或分块。
|
|
export function pluginBridge(): Plugin {
|
|
const id = 'virtual:plugin-bridge-source'
|
|
const resolvedId = `\0${id}`
|
|
const entry = fileURLToPath(new URL('../src/views/plugins/management/bridge-runtime.ts', import.meta.url))
|
|
const dependencies = new Set<string>()
|
|
return {
|
|
name: 'plugin-management-bridge',
|
|
resolveId: source => source === id
|
|
? resolvedId
|
|
: undefined,
|
|
async load(source) {
|
|
if (source !== resolvedId)
|
|
return
|
|
const result = await build({
|
|
configFile: false,
|
|
logLevel: 'silent',
|
|
build: {
|
|
write: false,
|
|
minify: true,
|
|
lib: {
|
|
entry,
|
|
name: 'CodexProxyPluginBridge',
|
|
formats: ['iife'],
|
|
},
|
|
},
|
|
})
|
|
const outputs = (Array.isArray(result)
|
|
? result
|
|
: [result])
|
|
.flatMap(output => 'output' in output
|
|
? output.output
|
|
: [])
|
|
const [chunk] = outputs
|
|
if (outputs.length !== 1 || chunk?.type !== 'chunk' || chunk.imports.length || chunk.dynamicImports.length)
|
|
throw new Error('插件管理桥必须构建为单个独立脚本')
|
|
dependencies.clear()
|
|
for (const dependency of Object.keys(chunk.modules)) {
|
|
dependencies.add(dependency)
|
|
this.addWatchFile(dependency)
|
|
}
|
|
return `export default ${JSON.stringify(chunk.code)}`
|
|
},
|
|
handleHotUpdate({ file, server }) {
|
|
if (dependencies.has(file)) {
|
|
const module = server.moduleGraph.getModuleById(resolvedId)
|
|
return module
|
|
? [module]
|
|
: []
|
|
}
|
|
},
|
|
}
|
|
}
|