web-extend-plugin-vue2 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +223 -105
- package/dist/index.cjs +1580 -1446
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1572 -1447
- package/dist/index.mjs.map +1 -1
- package/index.d.ts +126 -2
- package/package.json +10 -3
package/index.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export type InterceptRegisterRoutesFn = (ctx: {
|
|
|
37
37
|
pluginId: string
|
|
38
38
|
router: unknown
|
|
39
39
|
routes: ReadonlyArray<VueRouteConfig>
|
|
40
|
-
/** 与默认 `registerRoutes` 相同的包装 + `addRoute`
|
|
40
|
+
/** 与默认 `registerRoutes` 相同的包装 + `router.addRoute` */
|
|
41
41
|
applyInternalRegister: (routes: VueRouteConfig[]) => void
|
|
42
42
|
}) => void
|
|
43
43
|
|
|
@@ -48,7 +48,50 @@ export type AdaptRouteDeclarationsFn = (ctx: {
|
|
|
48
48
|
declarations: ReadonlyArray<RouteDeclaration>
|
|
49
49
|
}) => VueRouteConfig[]
|
|
50
50
|
|
|
51
|
+
/** 将插件 `registerMenuItems` 提交的数据并入宿主用于渲染侧栏/目录的 state(映射规则由宿主实现) */
|
|
52
|
+
export type ApplyPluginMenuItemsFn = (ctx: {
|
|
53
|
+
pluginId: string
|
|
54
|
+
/** 已在各条上附带 `pluginId`,并按 `order` 升序 */
|
|
55
|
+
items: Array<Record<string, unknown>>
|
|
56
|
+
}) => void
|
|
57
|
+
|
|
58
|
+
/** 卸载插件时移除该插件贡献的菜单数据 */
|
|
59
|
+
export type RevokePluginMenuItemsFn = (pluginId: string) => void
|
|
60
|
+
|
|
61
|
+
/** 宿主在 `resolveRuntimeOptions({ hostContext })` 中注入;经浅冻结后由 `hostApi.hostContext` 只读暴露 */
|
|
62
|
+
export type HostContext = Readonly<Record<string, unknown>>
|
|
63
|
+
|
|
64
|
+
export type OnBeforePluginActivateFn = (ctx: {
|
|
65
|
+
pluginId: string
|
|
66
|
+
router: unknown
|
|
67
|
+
pluginRecord: Readonly<Record<string, unknown>>
|
|
68
|
+
}) => void | Promise<void>
|
|
69
|
+
|
|
70
|
+
export type OnAfterPluginActivateFn = (ctx: {
|
|
71
|
+
pluginId: string
|
|
72
|
+
router: unknown
|
|
73
|
+
pluginRecord: Readonly<Record<string, unknown>>
|
|
74
|
+
hostApi: unknown
|
|
75
|
+
}) => void | Promise<void>
|
|
76
|
+
|
|
77
|
+
export type OnPluginActivateErrorFn = (ctx: {
|
|
78
|
+
pluginId: string
|
|
79
|
+
error: unknown
|
|
80
|
+
pluginRecord: Readonly<Record<string, unknown>>
|
|
81
|
+
hostApi: unknown
|
|
82
|
+
}) => void | Promise<void>
|
|
83
|
+
|
|
51
84
|
/** 宿主传入 `createHostApi` 的 `hostKit`(及 `resolveRuntimeOptions` 中同类字段) */
|
|
85
|
+
/** {@link createVueCliAxiosQuickInstallOptions} / {@link installVueCliAxiosWebPlugins} 的宿主侧依赖 */
|
|
86
|
+
export type VueCliAxiosQuickDeps = {
|
|
87
|
+
request: (config: Record<string, unknown>) => Promise<unknown>
|
|
88
|
+
hostLayoutComponent: unknown
|
|
89
|
+
store?: unknown
|
|
90
|
+
hostContext?: Record<string, unknown>
|
|
91
|
+
applyPluginMenuItems?: (ctx: { pluginId: string; items: Array<Record<string, unknown>> }) => void
|
|
92
|
+
revokePluginMenuItems?: (pluginId: string) => void
|
|
93
|
+
}
|
|
94
|
+
|
|
52
95
|
export type HostKitOptions = {
|
|
53
96
|
/** `getBridge().request` 允许的URL路径前缀,须以 `/` 开头 */
|
|
54
97
|
bridgeAllowedPathPrefixes?: string[]
|
|
@@ -57,6 +100,12 @@ export type HostKitOptions = {
|
|
|
57
100
|
transformRoutes?: TransformRoutesFn
|
|
58
101
|
interceptRegisterRoutes?: InterceptRegisterRoutesFn
|
|
59
102
|
adaptRouteDeclarations?: AdaptRouteDeclarationsFn
|
|
103
|
+
/** 必填:插件调用 `registerMenuItems` 时由此写入宿主菜单/路由树等数据结构 */
|
|
104
|
+
applyPluginMenuItems?: ApplyPluginMenuItemsFn
|
|
105
|
+
/** 建议与 `applyPluginMenuItems` 成对配置;`disposeWebPlugin` 会调用以撤销该插件菜单 */
|
|
106
|
+
revokePluginMenuItems?: RevokePluginMenuItemsFn
|
|
107
|
+
/** 由引导流程浅冻结后传入各插件的 `hostApi.hostContext` */
|
|
108
|
+
hostContext?: HostContext
|
|
60
109
|
}
|
|
61
110
|
|
|
62
111
|
/** `resolveRuntimeOptions` 全量运行时选项(在默认字段基础上的扩展;未列字段见 README) */
|
|
@@ -64,7 +113,23 @@ export type WebExtendPluginRuntimeOptions = HostKitOptions &
|
|
|
64
113
|
Record<string, unknown> & {
|
|
65
114
|
manifestBase?: string
|
|
66
115
|
manifestListPath?: string
|
|
116
|
+
/** 默认 `api`;`static` 时用 `staticManifestUrl` 拉取聚合 JSON,不请求 Java 清单接口 */
|
|
117
|
+
manifestMode?: 'api' | 'static'
|
|
118
|
+
/** 静态清单 URL(绝对或站点内路径),`manifestMode: 'static'` 时必填(或配置环境变量) */
|
|
119
|
+
staticManifestUrl?: string
|
|
120
|
+
/** `manifestMode=api` 且开发环境:API 失败或 `plugins` 为空时是否尝试 `devFallbackStaticManifestUrl`(默认 true) */
|
|
121
|
+
devManifestFallback?: boolean
|
|
122
|
+
/** 开发回退静态清单路径,默认 `/web-plugins/plugins.manifest.json` */
|
|
123
|
+
devFallbackStaticManifestUrl?: string
|
|
67
124
|
manifestFetchCredentials?: RequestCredentials
|
|
125
|
+
/** 宿主 Layout,传入后自动注册 `pluginMountPath` 壳路由 */
|
|
126
|
+
hostLayoutComponent?: unknown
|
|
127
|
+
/** 插件 URL 前缀,默认 `/plugin` */
|
|
128
|
+
pluginMountPath?: string
|
|
129
|
+
/** 壳路由 meta */
|
|
130
|
+
pluginHostRouteMeta?: Record<string, unknown>
|
|
131
|
+
/** 是否执行自动壳路由注册,默认 true */
|
|
132
|
+
ensurePluginHostRoute?: boolean
|
|
68
133
|
isDev?: boolean
|
|
69
134
|
webPluginDevOrigin?: string
|
|
70
135
|
webPluginDevIds?: string
|
|
@@ -77,18 +142,31 @@ export type WebExtendPluginRuntimeOptions = HostKitOptions &
|
|
|
77
142
|
allowedScriptHosts?: string[]
|
|
78
143
|
bootstrapSummary?: boolean
|
|
79
144
|
fetchManifest?: ManifestFetchFn
|
|
145
|
+
/** 插件通过 `hostApi.hostContext` 只读访问(浅冻结拷贝);如 `{ store, i18n }` */
|
|
146
|
+
hostContext?: Record<string, unknown>
|
|
147
|
+
/** 调用 `activator` 之前;抛出异常将跳过该插件并计入失败 */
|
|
148
|
+
onBeforePluginActivate?: OnBeforePluginActivateFn
|
|
149
|
+
/** `activator` 成功返回后 */
|
|
150
|
+
onAfterPluginActivate?: OnAfterPluginActivateFn
|
|
151
|
+
/** `activator` 抛错后;用于埋点/降级,不应再抛错(再抛仅记录 warn) */
|
|
152
|
+
onPluginActivateError?: OnPluginActivateErrorFn
|
|
80
153
|
}
|
|
81
154
|
|
|
82
155
|
/** 插件 `activator` 收到的宿主 API */
|
|
83
156
|
export interface HostApi {
|
|
84
157
|
/** 宿主实现的 Host API 协议版本,与清单 `hostPluginApiVersion` 对齐 */
|
|
85
158
|
readonly hostPluginApiVersion: string
|
|
159
|
+
/** 宿主注入上下文(`resolveRuntimeOptions.hostContext` 的浅冻结快照);无则 `{}` */
|
|
160
|
+
readonly hostContext: HostContext
|
|
86
161
|
/**
|
|
87
162
|
* 动态注册路由。含 PRD 时使用 `componentRef` 树;否则传入 `RouteConfig` 数组。
|
|
88
163
|
* 流水线:`adaptRouteDeclarations` → `transformRoutes` → `interceptRegisterRoutes` 或默认注册。
|
|
89
164
|
*/
|
|
90
165
|
registerRoutes(routes: VueRouteConfig[] | RouteDeclaration[]): void
|
|
91
|
-
/**
|
|
166
|
+
/**
|
|
167
|
+
* 向宿主登记侧栏/目录菜单意图;由 `applyPluginMenuItems` 写入宿主 state。
|
|
168
|
+
* 未配置 `applyPluginMenuItems` 时调用会抛错。
|
|
169
|
+
*/
|
|
92
170
|
registerMenuItems(items: Record<string, unknown>[]): void
|
|
93
171
|
registerSlotComponents(
|
|
94
172
|
pointId: string,
|
|
@@ -135,6 +213,7 @@ export const WebExtendPluginVue2: Readonly<{
|
|
|
135
213
|
runtimeOptions?: WebExtendPluginRuntimeOptions
|
|
136
214
|
) => Promise<void>
|
|
137
215
|
resolveRuntimeOptions: (user?: WebExtendPluginRuntimeOptions) => WebExtendPluginRuntimeOptions
|
|
216
|
+
ensurePluginHostRoute: (router: unknown, opts: WebExtendPluginRuntimeOptions) => void
|
|
138
217
|
defaultFetchWebPluginManifest: (ctx: {
|
|
139
218
|
manifestUrl: string
|
|
140
219
|
credentials: RequestCredentials
|
|
@@ -157,6 +236,11 @@ export const WebExtendPluginVue2: Readonly<{
|
|
|
157
236
|
config: Readonly<{
|
|
158
237
|
defaultWebExtendPluginRuntime: Record<string, unknown>
|
|
159
238
|
setWebExtendPluginEnv: (env: Record<string, unknown> | null | undefined) => void
|
|
239
|
+
webExtendPluginEnvKeys: Readonly<Record<string, string>>
|
|
240
|
+
defaultManifestFetchCache: Readonly<{ storageKeyPrefix: string; maxEntries: number }>
|
|
241
|
+
defaultManifestMode: string
|
|
242
|
+
routeSynthNamePrefix: string
|
|
243
|
+
peerMinimumVersions: Readonly<{ vue: string; vueRouter: string }>
|
|
160
244
|
}>
|
|
161
245
|
constants: Readonly<{ HOST_PLUGIN_API_VERSION: string; RUNTIME_CONSOLE_LABEL: string }>
|
|
162
246
|
components: Readonly<{ ExtensionPoint: unknown }>
|
|
@@ -168,6 +252,12 @@ export const WebExtendPluginVue2: Readonly<{
|
|
|
168
252
|
deps: { request: (config: Record<string, unknown>) => Promise<unknown> },
|
|
169
253
|
extra?: Record<string, unknown>
|
|
170
254
|
) => Record<string, unknown>
|
|
255
|
+
createQuickInstallOptions: (
|
|
256
|
+
router: unknown,
|
|
257
|
+
deps: VueCliAxiosQuickDeps,
|
|
258
|
+
extra?: Record<string, unknown>
|
|
259
|
+
) => Record<string, unknown>
|
|
260
|
+
defaultJavaManifestListPath: string
|
|
171
261
|
manifestPathForApiBase: (manifestUrl: string, apiBase?: string) => string
|
|
172
262
|
unwrapManifestBody: (body: unknown) => object | null
|
|
173
263
|
}>
|
|
@@ -176,6 +266,19 @@ export const WebExtendPluginVue2: Readonly<{
|
|
|
176
266
|
|
|
177
267
|
export const defaultWebExtendPluginRuntime: Record<string, unknown>
|
|
178
268
|
|
|
269
|
+
/** 与 `resolveRuntimeOptions` / `build-env` 读取逻辑一致的环境变量键(文档与宿主检索用) */
|
|
270
|
+
export const webExtendPluginEnvKeys: Readonly<Record<string, string>>
|
|
271
|
+
|
|
272
|
+
export const defaultManifestFetchCache: Readonly<{ storageKeyPrefix: string; maxEntries: number }>
|
|
273
|
+
|
|
274
|
+
export const defaultManifestMode: 'api'
|
|
275
|
+
|
|
276
|
+
/** 无 name 的路由由 `createHostApi` 合成的名称前缀 */
|
|
277
|
+
export const routeSynthNamePrefix: string
|
|
278
|
+
|
|
279
|
+
/** 与 package.json peer 下限一致,供 CI / `test:peer-min` 对齐 */
|
|
280
|
+
export const peerMinimumVersions: Readonly<{ vue: string; vueRouter: string }>
|
|
281
|
+
|
|
179
282
|
/** 拉取清单并依次激活插件;浏览器环境执行 */
|
|
180
283
|
export function bootstrapPlugins(
|
|
181
284
|
router: unknown,
|
|
@@ -186,6 +289,8 @@ export function bootstrapPlugins(
|
|
|
186
289
|
/** 合并默认配置、环境变量与显式传入字段 */
|
|
187
290
|
export function resolveRuntimeOptions(user?: WebExtendPluginRuntimeOptions): WebExtendPluginRuntimeOptions
|
|
188
291
|
|
|
292
|
+
export function ensurePluginHostRoute(router: unknown, opts: WebExtendPluginRuntimeOptions): void
|
|
293
|
+
|
|
189
294
|
export function defaultFetchWebPluginManifest(ctx: {
|
|
190
295
|
manifestUrl: string
|
|
191
296
|
credentials: RequestCredentials
|
|
@@ -213,8 +318,25 @@ export function installWebExtendPluginVue2(
|
|
|
213
318
|
options?: WebExtendPluginRuntimeOptions
|
|
214
319
|
): Promise<void>
|
|
215
320
|
|
|
321
|
+
/** Vue CLI + axios 一键安装;默认 `exposeGlobalVue: true` 写入 `window.Vue` */
|
|
322
|
+
export function installVueCliAxiosWebPlugins(
|
|
323
|
+
Vue: unknown,
|
|
324
|
+
router: unknown,
|
|
325
|
+
deps: VueCliAxiosQuickDeps,
|
|
326
|
+
extra?: WebExtendPluginRuntimeOptions & { exposeGlobalVue?: boolean }
|
|
327
|
+
): Promise<void>
|
|
328
|
+
|
|
216
329
|
export const ExtensionPoint: unknown
|
|
217
330
|
|
|
331
|
+
/** 常见 Java 清单路径段,与 `manifestBase` 拼接 */
|
|
332
|
+
export const defaultVueCliJavaManifestListPath: string
|
|
333
|
+
|
|
334
|
+
export function createVueCliAxiosQuickInstallOptions(
|
|
335
|
+
router: unknown,
|
|
336
|
+
deps: VueCliAxiosQuickDeps,
|
|
337
|
+
extra?: Record<string, unknown>
|
|
338
|
+
): Record<string, unknown>
|
|
339
|
+
|
|
218
340
|
export function createVueCliAxiosInstallOptions(
|
|
219
341
|
deps: { request: (config: Record<string, unknown>) => Promise<unknown> },
|
|
220
342
|
extra?: Record<string, unknown>
|
|
@@ -227,6 +349,8 @@ export const presetVueCliAxios: Readonly<{
|
|
|
227
349
|
id: string
|
|
228
350
|
description: string
|
|
229
351
|
createInstallOptions: typeof createVueCliAxiosInstallOptions
|
|
352
|
+
createQuickInstallOptions: typeof createVueCliAxiosQuickInstallOptions
|
|
353
|
+
defaultJavaManifestListPath: typeof defaultVueCliJavaManifestListPath
|
|
230
354
|
manifestPathForApiBase: typeof resolveManifestPathUnderApiBase
|
|
231
355
|
unwrapManifestBody: typeof unwrapNestedManifestBody
|
|
232
356
|
}>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "web-extend-plugin-vue2",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
],
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"vue": ">=2.6.14 <3.0.0",
|
|
25
|
-
"vue-router": ">=3.
|
|
25
|
+
"vue-router": ">=3.5.0 <4.0.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"semver": "^7.6.3"
|
|
@@ -30,12 +30,19 @@
|
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@rollup/plugin-commonjs": "^29.0.2",
|
|
32
32
|
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
33
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
34
|
+
"@types/node": "^22.10.2",
|
|
33
35
|
"rollup": "^4.28.0",
|
|
34
|
-
"
|
|
36
|
+
"tslib": "^2.8.1",
|
|
37
|
+
"typescript": "^5.7.2",
|
|
38
|
+
"vitest": "^2.1.9",
|
|
39
|
+
"vue": "^2.7.16",
|
|
40
|
+
"vue-router": "^3.6.5"
|
|
35
41
|
},
|
|
36
42
|
"scripts": {
|
|
37
43
|
"build": "rollup -c rollup.config.mjs",
|
|
38
44
|
"test": "vitest run",
|
|
45
|
+
"test:peer-min": "npm install --no-save vue@2.6.14 vue-router@3.5.4 && npm run build && npm test && npm install",
|
|
39
46
|
"prepublishOnly": "npm run build && npm run test"
|
|
40
47
|
},
|
|
41
48
|
"license": "Apache-2.0",
|