web-extend-plugin-vue2 0.3.6 → 0.3.7

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/dist/index.mjs CHANGED
@@ -225,21 +225,35 @@ function isScriptHostAllowed(url, hostSet) {
225
225
  }
226
226
  }
227
227
 
228
- /**
229
- * 合并用户、环境与默认配置得到运行时选项。
230
- */
231
228
  const DEF = defaultWebExtendPluginRuntime;
232
229
  const EK = webExtendPluginEnvKeys;
230
+ function asRecord$1(value) {
231
+ return value && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
232
+ }
233
+ function normalizeHostBridge(userVal) {
234
+ const raw = asRecord$1(userVal);
235
+ if (!raw) {
236
+ return undefined;
237
+ }
238
+ const normalized = {};
239
+ if (raw.modules && typeof raw.modules === 'object' && !Array.isArray(raw.modules)) {
240
+ normalized.modules = { ...raw.modules };
241
+ }
242
+ if (raw.components && typeof raw.components === 'object' && !Array.isArray(raw.components)) {
243
+ normalized.components = { ...raw.components };
244
+ }
245
+ return normalized.modules || normalized.components ? normalized : undefined;
246
+ }
233
247
  function resolveManifestCredentials(userVal, envKey, fallback) {
234
248
  if (userVal !== undefined) {
235
- const s = String(userVal);
236
- if (s === 'include' || s === 'omit' || s === 'same-origin') {
237
- return s;
249
+ const normalized = String(userVal);
250
+ if (normalized === 'include' || normalized === 'omit' || normalized === 'same-origin') {
251
+ return normalized;
238
252
  }
239
253
  }
240
- const e = resolveBundledEnv(envKey, '');
241
- if (e === 'include' || e === 'omit' || e === 'same-origin') {
242
- return e;
254
+ const envValue = resolveBundledEnv(envKey, '');
255
+ if (envValue === 'include' || envValue === 'omit' || envValue === 'same-origin') {
256
+ return envValue;
243
257
  }
244
258
  return fallback;
245
259
  }
@@ -248,167 +262,184 @@ function resolvePositiveInt(userVal, envKey, fallback) {
248
262
  return Math.floor(userVal);
249
263
  }
250
264
  const raw = resolveBundledEnv(envKey, '');
251
- const n = raw ? parseInt(raw, 10) : NaN;
252
- if (Number.isFinite(n) && n > 0) {
253
- return n;
265
+ const parsed = raw ? parseInt(raw, 10) : NaN;
266
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
267
+ }
268
+ function normalizeStringList$1(value) {
269
+ if (Array.isArray(value)) {
270
+ return value.map(String).map((item) => item.trim()).filter(Boolean);
254
271
  }
255
- return fallback;
272
+ if (typeof value === 'string' && value.trim()) {
273
+ return value
274
+ .split(',')
275
+ .map((item) => item.trim())
276
+ .filter(Boolean);
277
+ }
278
+ return [];
279
+ }
280
+ function resolveAllowedScriptHosts(value) {
281
+ const raw = normalizeStringList$1(value);
282
+ return raw.length > 0 ? raw.map(normalizeHost).filter(Boolean) : [];
283
+ }
284
+ function resolvePathPrefixes(value) {
285
+ const raw = normalizeStringList$1(value);
286
+ return raw.length > 0 ? raw.map((item) => ensureLeadingPath(item)).filter(Boolean) : [];
287
+ }
288
+ function resolveBoolean(value) {
289
+ if (value === true || value === false) {
290
+ return value;
291
+ }
292
+ return undefined;
293
+ }
294
+ function resolveManifestInput(user) {
295
+ return asRecord$1(user.manifest) || {};
296
+ }
297
+ function resolveHostInput(user) {
298
+ return asRecord$1(user.host) || {};
299
+ }
300
+ function resolveDevInput(user) {
301
+ return asRecord$1(user.dev) || {};
302
+ }
303
+ function resolveHooksInput(user) {
304
+ return asRecord$1(user.hooks) || {};
305
+ }
306
+ function resolveDevPluginIds(dev) {
307
+ const explicit = normalizeStringList$1(dev.pluginIds);
308
+ if (explicit.length > 0) {
309
+ return explicit;
310
+ }
311
+ const fromEnv = normalizeStringList$1(resolveBundledEnv(EK.webPluginDevIds, ''));
312
+ if (fromEnv.length > 0) {
313
+ return fromEnv;
314
+ }
315
+ const implicit = normalizeStringList$1(resolveBundledEnv(EK.implicitDevIds, ''));
316
+ return implicit.length > 0 ? implicit : [...DEF.defaultImplicitDevPluginIds];
317
+ }
318
+ function resolveDevManifestFallback(dev, manifestMode, isDev) {
319
+ if (manifestMode === 'static') {
320
+ return false;
321
+ }
322
+ const direct = resolveBoolean(dev.manifestFallback && dev.manifestFallback.enabled);
323
+ if (direct !== undefined) {
324
+ return direct;
325
+ }
326
+ const envFlag = resolveBundledEnv(EK.devManifestFallback, '');
327
+ if (envFlag === '0' || envFlag === 'false') {
328
+ return false;
329
+ }
330
+ if (envFlag === '1' || envFlag === 'true') {
331
+ return true;
332
+ }
333
+ return isDev;
256
334
  }
257
- /** 合并用户、环境变量与 `defaultWebExtendPluginRuntime`,得到完整运行时选项(宿主可只传需要覆盖的字段)。 */
258
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
259
335
  function resolveRuntimeOptions$1(user = {}) {
260
- const manifestBaseRaw = user.manifestBase !== undefined && user.manifestBase !== ''
261
- ? String(user.manifestBase)
336
+ const manifest = resolveManifestInput(user);
337
+ const host = resolveHostInput(user);
338
+ const hostRoute = asRecord$1(host.route) || {};
339
+ const dev = resolveDevInput(user);
340
+ const devFallback = asRecord$1(dev.manifestFallback) || {};
341
+ const hooks = resolveHooksInput(user);
342
+ const normalizedHostBridge = normalizeHostBridge(host.bridge);
343
+ const manifestBaseRaw = manifest.baseUrl !== undefined && String(manifest.baseUrl).trim() !== ''
344
+ ? String(manifest.baseUrl)
262
345
  : resolveBundledEnv(EK.manifestBase, DEF.manifestBase) || DEF.manifestBase;
263
- const manifestListPath = ensureLeadingPath(user.manifestListPath !== undefined && user.manifestListPath !== ''
264
- ? user.manifestListPath
346
+ const manifestListPath = ensureLeadingPath(manifest.listPath !== undefined && String(manifest.listPath).trim() !== ''
347
+ ? manifest.listPath
265
348
  : resolveBundledEnv(EK.manifestListPath, DEF.manifestListPath));
266
- const defaultImplicitDevPluginIds = Array.isArray(user.defaultImplicitDevPluginIds)
267
- ? user.defaultImplicitDevPluginIds.map(String).filter(Boolean)
268
- : (() => {
269
- const e = resolveBundledEnv(EK.implicitDevIds, '');
270
- if (e) {
271
- return e
272
- .split(',')
273
- .map((s) => s.trim())
274
- .filter(Boolean);
275
- }
276
- return [...DEF.defaultImplicitDevPluginIds];
277
- })();
278
- const allowedScriptHosts = Array.isArray(user.allowedScriptHosts) && user.allowedScriptHosts.length > 0
279
- ? user.allowedScriptHosts.map((h) => normalizeHost(String(h))).filter(Boolean)
280
- : (() => {
281
- const e = resolveBundledEnv(EK.allowedScriptHosts, '');
282
- if (e) {
283
- return e
284
- .split(',')
285
- .map((s) => normalizeHost(s.trim()))
286
- .filter(Boolean);
287
- }
288
- return [...DEF.allowedScriptHosts];
289
- })();
290
- const bridgeAllowedPathPrefixes = Array.isArray(user.bridgeAllowedPathPrefixes) && user.bridgeAllowedPathPrefixes.length > 0
291
- ? user.bridgeAllowedPathPrefixes.map((p) => ensureLeadingPath(p)).filter(Boolean)
292
- : (() => {
293
- const e = resolveBundledEnv(EK.bridgePrefixes, '');
294
- if (e) {
295
- return e
296
- .split(',')
297
- .map((s) => ensureLeadingPath(s.trim()))
298
- .filter(Boolean);
299
- }
300
- return [...DEF.bridgeAllowedPathPrefixes];
301
- })();
302
- const manifestMode = resolveManifestModeFromInputs(user.manifestMode);
303
- const staticManifestUrl = resolveStaticManifestUrlFromInputs(user.staticManifestUrl);
304
- const isDevResolved = user.isDev !== undefined ? user.isDev : resolveBundledIsDev();
305
- const devFallbackStaticManifestUrl = (() => {
306
- if (user.devFallbackStaticManifestUrl !== undefined && String(user.devFallbackStaticManifestUrl).trim() !== '') {
307
- return String(user.devFallbackStaticManifestUrl).trim();
349
+ const allowedScriptHosts = (() => {
350
+ const explicit = resolveAllowedScriptHosts(host.scriptHosts);
351
+ if (explicit.length > 0) {
352
+ return explicit;
308
353
  }
309
- const e = resolveBundledEnv(EK.devFallbackManifestUrl, '');
310
- if (e) {
311
- return e.trim();
354
+ const fromEnv = resolveAllowedScriptHosts(resolveBundledEnv(EK.allowedScriptHosts, ''));
355
+ return fromEnv.length > 0 ? fromEnv : [...DEF.allowedScriptHosts];
356
+ })();
357
+ const bridgeAllowedPathPrefixes = (() => {
358
+ const explicit = resolvePathPrefixes(host.requestPathPrefixes);
359
+ if (explicit.length > 0) {
360
+ return explicit;
361
+ }
362
+ const fromEnv = resolvePathPrefixes(resolveBundledEnv(EK.bridgePrefixes, ''));
363
+ return fromEnv.length > 0 ? fromEnv : [...DEF.bridgeAllowedPathPrefixes];
364
+ })();
365
+ const manifestMode = resolveManifestModeFromInputs(manifest.source);
366
+ const staticManifestUrl = resolveStaticManifestUrlFromInputs(manifest.staticUrl);
367
+ const isDev = resolveBoolean(dev.enabled) !== undefined ? Boolean(dev.enabled) : resolveBundledIsDev();
368
+ const devFallbackStaticManifestUrl = (() => {
369
+ if (devFallback.staticUrl !== undefined && String(devFallback.staticUrl).trim() !== '') {
370
+ return String(devFallback.staticUrl).trim();
312
371
  }
313
- return String(DEF.devFallbackStaticManifestUrl).trim();
372
+ const envValue = resolveBundledEnv(EK.devFallbackManifestUrl, '');
373
+ return envValue ? envValue.trim() : String(DEF.devFallbackStaticManifestUrl).trim();
314
374
  })();
315
- const hostLayoutComponent = user.hostLayoutComponent;
316
- const pluginRoutesParentName = user.pluginRoutesParentName !== undefined && String(user.pluginRoutesParentName).trim() !== ''
317
- ? String(user.pluginRoutesParentName).trim()
375
+ const pluginRoutesParentName = hostRoute.parentName !== undefined && String(hostRoute.parentName).trim() !== ''
376
+ ? String(hostRoute.parentName).trim()
318
377
  : '';
319
- const pluginMountRaw = user.pluginMountPath !== undefined && String(user.pluginMountPath).trim() !== ''
320
- ? String(user.pluginMountPath).trim()
378
+ const pluginMountRaw = hostRoute.mountPath !== undefined && String(hostRoute.mountPath).trim() !== ''
379
+ ? String(hostRoute.mountPath).trim()
321
380
  : String(resolveBundledEnv(EK.mountPath, '') || DEF.pluginMountPath).trim();
322
381
  const pluginMountPath = ensureLeadingPath(pluginMountRaw || DEF.pluginMountPath);
323
- const pluginHostRouteMeta = user.pluginHostRouteMeta !== undefined && user.pluginHostRouteMeta !== null
324
- ? user.pluginHostRouteMeta
325
- : undefined;
326
- const ensurePluginHostRoute = user.ensurePluginHostRoute === true;
327
- const devManifestFallback = (() => {
328
- if (manifestMode === 'static') {
329
- return false;
330
- }
331
- if (user.devManifestFallback === false) {
332
- return false;
333
- }
334
- if (user.devManifestFallback === true) {
335
- return true;
336
- }
337
- const envFlag = resolveBundledEnv(EK.devManifestFallback, '');
338
- if (envFlag === '0' || envFlag === 'false') {
339
- return false;
382
+ const pluginHostRouteMeta = asRecord$1(hostRoute.meta);
383
+ const ensurePluginHostRoute = resolveBoolean(hostRoute.enabled) === true;
384
+ const webPluginDevMapJson = (() => {
385
+ if (dev.pluginMap && typeof dev.pluginMap === 'object' && !Array.isArray(dev.pluginMap)) {
386
+ return JSON.stringify(dev.pluginMap);
340
387
  }
341
- if (envFlag === '1' || envFlag === 'true') {
342
- return true;
343
- }
344
- return !!isDevResolved;
388
+ return dev.pluginMap !== undefined ? String(dev.pluginMap || '') : resolveBundledEnv(EK.webPluginDevMap, '');
345
389
  })();
346
390
  return {
347
391
  manifestBase: manifestBaseRaw.replace(/\/$/, '') || DEF.manifestBase.replace(/\/$/, ''),
348
392
  manifestListPath,
349
393
  manifestMode,
350
394
  staticManifestUrl,
351
- devManifestFallback,
395
+ devManifestFallback: resolveDevManifestFallback(dev, manifestMode, isDev),
352
396
  devFallbackStaticManifestUrl,
353
- manifestFetchCredentials: resolveManifestCredentials(user.manifestFetchCredentials, EK.manifestCredentials, DEF.manifestFetchCredentials),
354
- isDev: isDevResolved,
355
- webPluginDevOrigin: user.webPluginDevOrigin !== undefined
356
- ? user.webPluginDevOrigin
357
- : resolveBundledEnv(EK.webPluginDevOrigin, ''),
358
- webPluginDevIds: user.webPluginDevIds !== undefined ? user.webPluginDevIds : resolveBundledEnv(EK.webPluginDevIds, ''),
359
- webPluginDevMapJson: user.webPluginDevMapJson !== undefined
360
- ? user.webPluginDevMapJson
361
- : resolveBundledEnv(EK.webPluginDevMap, ''),
362
- webPluginDevEntryPath: ensureLeadingPath(user.webPluginDevEntryPath !== undefined && user.webPluginDevEntryPath !== ''
363
- ? user.webPluginDevEntryPath
397
+ manifestFetchCredentials: resolveManifestCredentials(manifest.credentials, EK.manifestCredentials, DEF.manifestFetchCredentials),
398
+ isDev,
399
+ webPluginDevOrigin: dev.origin !== undefined ? String(dev.origin || '').trim() : resolveBundledEnv(EK.webPluginDevOrigin, ''),
400
+ webPluginDevIds: resolveDevPluginIds(dev),
401
+ webPluginDevMapJson,
402
+ webPluginDevEntryPath: ensureLeadingPath(dev.entryPath !== undefined && String(dev.entryPath).trim() !== ''
403
+ ? String(dev.entryPath)
364
404
  : resolveBundledEnv(EK.devEntry, DEF.webPluginDevEntryPath)),
365
- devPingPath: ensureLeadingPath(user.devPingPath !== undefined && user.devPingPath !== ''
366
- ? user.devPingPath
405
+ devPingPath: ensureLeadingPath(dev.pingPath !== undefined && String(dev.pingPath).trim() !== ''
406
+ ? String(dev.pingPath)
367
407
  : resolveBundledEnv(EK.devPing, DEF.devPingPath)),
368
- devReloadSsePath: ensureLeadingPath(user.devReloadSsePath !== undefined && user.devReloadSsePath !== ''
369
- ? user.devReloadSsePath
408
+ devReloadSsePath: ensureLeadingPath(dev.reloadSsePath !== undefined && String(dev.reloadSsePath).trim() !== ''
409
+ ? String(dev.reloadSsePath)
370
410
  : resolveBundledEnv(EK.devSse, DEF.devReloadSsePath)),
371
- devPingTimeoutMs: resolvePositiveInt(user.devPingTimeoutMs, EK.devPingTimeout, DEF.devPingTimeoutMs),
372
- defaultImplicitDevPluginIds,
411
+ devPingTimeoutMs: resolvePositiveInt(dev.pingTimeoutMs, EK.devPingTimeout, DEF.devPingTimeoutMs),
412
+ defaultImplicitDevPluginIds: [...DEF.defaultImplicitDevPluginIds],
373
413
  allowedScriptHosts,
374
414
  bridgeAllowedPathPrefixes,
375
- bootstrapSummary: user.bootstrapSummary,
376
- hostLayoutComponent,
415
+ bootstrapSummary: resolveBoolean(dev.bootstrapSummary),
416
+ hostLayoutComponent: hostRoute.layout,
377
417
  pluginMountPath,
378
418
  pluginHostRouteMeta,
379
419
  ensurePluginHostRoute,
380
420
  pluginRoutesParentName,
381
- ...(typeof user.fetchManifest === 'function' ? { fetchManifest: user.fetchManifest } : {}),
382
- ...(typeof user.transformRoutes === 'function' ? { transformRoutes: user.transformRoutes } : {}),
383
- ...(typeof user.interceptRegisterRoutes === 'function'
384
- ? { interceptRegisterRoutes: user.interceptRegisterRoutes }
385
- : {}),
386
- ...(typeof user.adaptRouteDeclarations === 'function'
387
- ? { adaptRouteDeclarations: user.adaptRouteDeclarations }
388
- : {}),
389
- ...(typeof user.onPluginRoutesContributed === 'function'
390
- ? { onPluginRoutesContributed: user.onPluginRoutesContributed }
421
+ ...(typeof manifest.fetch === 'function' ? { fetchManifest: manifest.fetch } : {}),
422
+ ...(typeof hooks.transformRoutes === 'function' ? { transformRoutes: hooks.transformRoutes } : {}),
423
+ ...(typeof hooks.interceptRegisterRoutes === 'function'
424
+ ? { interceptRegisterRoutes: hooks.interceptRegisterRoutes }
391
425
  : {}),
392
- ...(user.hostContext !== undefined &&
393
- user.hostContext !== null &&
394
- typeof user.hostContext === 'object' &&
395
- !Array.isArray(user.hostContext)
396
- ? { hostContext: user.hostContext }
426
+ ...(typeof hooks.adaptRouteDeclarations === 'function'
427
+ ? { adaptRouteDeclarations: hooks.adaptRouteDeclarations }
397
428
  : {}),
398
- ...(user.hostCapabilities !== undefined &&
399
- user.hostCapabilities !== null &&
400
- typeof user.hostCapabilities === 'object' &&
401
- !Array.isArray(user.hostCapabilities)
402
- ? { hostCapabilities: user.hostCapabilities }
429
+ ...(typeof hooks.onRoutesContributed === 'function'
430
+ ? { onPluginRoutesContributed: hooks.onRoutesContributed }
403
431
  : {}),
404
- ...(typeof user.onBeforePluginActivate === 'function'
405
- ? { onBeforePluginActivate: user.onBeforePluginActivate }
432
+ ...(asRecord$1(host.context) ? { hostContext: asRecord$1(host.context) } : {}),
433
+ ...(asRecord$1(host.capabilities) ? { hostCapabilities: asRecord$1(host.capabilities) } : {}),
434
+ ...(normalizedHostBridge ? { hostBridge: normalizedHostBridge } : {}),
435
+ ...(typeof hooks.beforeActivate === 'function'
436
+ ? { onBeforePluginActivate: hooks.beforeActivate }
406
437
  : {}),
407
- ...(typeof user.onAfterPluginActivate === 'function'
408
- ? { onAfterPluginActivate: user.onAfterPluginActivate }
438
+ ...(typeof hooks.afterActivate === 'function'
439
+ ? { onAfterPluginActivate: hooks.afterActivate }
409
440
  : {}),
410
- ...(typeof user.onPluginActivateError === 'function'
411
- ? { onPluginActivateError: user.onPluginActivateError }
441
+ ...(typeof hooks.onActivateError === 'function'
442
+ ? { onPluginActivateError: hooks.onActivateError }
412
443
  : {})
413
444
  };
414
445
  }
@@ -3418,18 +3449,31 @@ function disposeWebPlugin(pluginId) {
3418
3449
  }
3419
3450
 
3420
3451
  /**
3421
- * 开发模式插件 URL 映射(显式 JSON + 隐式 dev 探测)。
3452
+ * 开发模式插件 URL 映射。
3422
3453
  */
3454
+ function normalizeStringValue(value) {
3455
+ return value == null ? '' : String(value).trim();
3456
+ }
3457
+ function normalizeStringList(value, fallback = []) {
3458
+ const raw = normalizeStringValue(value);
3459
+ if (!raw) {
3460
+ return [...fallback];
3461
+ }
3462
+ return raw
3463
+ .split(',')
3464
+ .map((item) => item.trim())
3465
+ .filter(Boolean);
3466
+ }
3423
3467
  function parseWebPluginDevMapExplicit(opts) {
3424
3468
  if (!opts.isDev) {
3425
3469
  return null;
3426
3470
  }
3427
- const raw = opts.webPluginDevMapJson;
3428
- if (raw === undefined || raw === null || String(raw).trim() === '') {
3471
+ const raw = normalizeStringValue(opts.webPluginDevMapJson);
3472
+ if (!raw) {
3429
3473
  return null;
3430
3474
  }
3431
3475
  try {
3432
- const map = JSON.parse(String(raw));
3476
+ const map = JSON.parse(raw);
3433
3477
  return map && typeof map === 'object' ? map : null;
3434
3478
  }
3435
3479
  catch (_a) {
@@ -3446,22 +3490,11 @@ async function buildImplicitWebPluginDevMap(opts, hostSet) {
3446
3490
  if (!opts.isDev) {
3447
3491
  return {};
3448
3492
  }
3449
- const origin = opts.webPluginDevOrigin === undefined || opts.webPluginDevOrigin === null
3450
- ? ''
3451
- : String(opts.webPluginDevOrigin).trim();
3452
- if (!origin) {
3493
+ const origin = normalizeStringValue(opts.webPluginDevOrigin);
3494
+ if (!origin || !isScriptHostAllowed(`${origin}/`, hostSet)) {
3453
3495
  return {};
3454
3496
  }
3455
- if (!isScriptHostAllowed(`${origin}/`, hostSet)) {
3456
- return {};
3457
- }
3458
- const idsRaw = opts.webPluginDevIds;
3459
- const ids = idsRaw !== undefined && idsRaw !== null && String(idsRaw).trim() !== ''
3460
- ? String(idsRaw)
3461
- .split(',')
3462
- .map((s) => s.trim())
3463
- .filter(Boolean)
3464
- : [...opts.defaultImplicitDevPluginIds];
3497
+ const ids = normalizeStringList(opts.webPluginDevIds, opts.defaultImplicitDevPluginIds);
3465
3498
  if (ids.length === 0) {
3466
3499
  return {};
3467
3500
  }
@@ -3470,31 +3503,28 @@ async function buildImplicitWebPluginDevMap(opts, hostSet) {
3470
3503
  try {
3471
3504
  const ctrl = new AbortController();
3472
3505
  const timer = setTimeout(() => ctrl.abort(), opts.devPingTimeoutMs);
3473
- const r = await fetch(pingUrl, {
3506
+ const response = await fetch(pingUrl, {
3474
3507
  mode: 'cors',
3475
3508
  cache: 'no-store',
3476
3509
  signal: ctrl.signal
3477
3510
  });
3478
3511
  clearTimeout(timer);
3479
- if (!r.ok) {
3512
+ if (!response.ok) {
3480
3513
  return {};
3481
3514
  }
3482
- const body = (await r.text()).trim();
3483
- if (body !== 'ok') {
3515
+ if ((await response.text()).trim() !== 'ok') {
3484
3516
  return {};
3485
3517
  }
3486
3518
  }
3487
3519
  catch (_a) {
3488
3520
  return {};
3489
3521
  }
3490
- const pathPart = opts.webPluginDevEntryPath;
3522
+ const entryUrl = `${base}${opts.webPluginDevEntryPath}`;
3491
3523
  const map = {};
3492
3524
  for (const id of ids) {
3493
- map[id] = `${base}${pathPart}`;
3494
- }
3495
- if (ids.length) {
3496
- console.info('[wep] plugin dev server', base, '→ implicit entries', pathPart, ids.join(', '));
3525
+ map[id] = entryUrl;
3497
3526
  }
3527
+ console.info('[wep] plugin dev server', base, '-> implicit entries', opts.webPluginDevEntryPath, ids.join(', '));
3498
3528
  return map;
3499
3529
  }
3500
3530
 
@@ -3628,15 +3658,14 @@ async function fetchStaticManifestViaHttp(ctx) {
3628
3658
  }
3629
3659
 
3630
3660
  /**
3631
- * 当 `ensurePluginHostRoute === true` 且提供 `pluginRoutesParentName` + `hostLayoutComponent` 时,
3632
- * 注册 `pluginMountPath` + Layout 的命名父路由,供 `router.addRoute(parentName, child)` 挂载插件页。
3661
+ * 在需要时补注册插件宿主父路由。
3633
3662
  */
3634
3663
  function routeNameExists(router, name) {
3635
3664
  if (!name) {
3636
3665
  return false;
3637
3666
  }
3638
3667
  if (typeof router.getRoutes === 'function') {
3639
- return router.getRoutes().some((r) => r.name === name);
3668
+ return router.getRoutes().some((route) => route.name === name);
3640
3669
  }
3641
3670
  return walkRouteNames(router.options && router.options.routes, name);
3642
3671
  }
@@ -3644,50 +3673,49 @@ function walkRouteNames(routes, name) {
3644
3673
  if (!Array.isArray(routes)) {
3645
3674
  return false;
3646
3675
  }
3647
- for (const r of routes) {
3648
- if (r && typeof r === 'object' && r.name === name) {
3676
+ for (const route of routes) {
3677
+ if (route && typeof route === 'object' && route.name === name) {
3649
3678
  return true;
3650
3679
  }
3651
- const ch = r && typeof r === 'object' ? r.children : null;
3652
- if (walkRouteNames(ch, name)) {
3680
+ const children = route && typeof route === 'object' ? route.children : undefined;
3681
+ if (walkRouteNames(children, name)) {
3653
3682
  return true;
3654
3683
  }
3655
3684
  }
3656
3685
  return false;
3657
3686
  }
3658
- function ensurePluginHostRoute$1(router, opts) {
3659
- if (opts.ensurePluginHostRoute !== true) {
3660
- return;
3661
- }
3662
- if (!router || typeof router.addRoute !== 'function') {
3687
+ function normalizeMountPath(value) {
3688
+ const mountDefault = defaultWebExtendPluginRuntime.pluginMountPath;
3689
+ const raw = String(value || mountDefault).trim().replace(/\/$/, '') || mountDefault;
3690
+ return raw.startsWith('/') ? raw : `/${raw}`;
3691
+ }
3692
+ function resolveRouteMeta(value) {
3693
+ return value && typeof value === 'object' && !Array.isArray(value)
3694
+ ? { ...value }
3695
+ : { requiresConfig: true, hidden: true };
3696
+ }
3697
+ function ensurePluginHostRoute$1(router, options) {
3698
+ const opts = options && typeof options === 'object' && ('manifestBase' in options || 'ensurePluginHostRoute' in options)
3699
+ ? options
3700
+ : resolveRuntimeOptions$1(options);
3701
+ if (opts.ensurePluginHostRoute !== true || !router || typeof router.addRoute !== 'function') {
3663
3702
  return;
3664
3703
  }
3665
3704
  const parentName = String(opts.pluginRoutesParentName || '').trim();
3666
- if (!parentName) {
3667
- return;
3668
- }
3669
- if (routeNameExists(router, parentName)) {
3705
+ if (!parentName || routeNameExists(router, parentName)) {
3670
3706
  return;
3671
3707
  }
3672
3708
  const Layout = opts.hostLayoutComponent;
3673
3709
  if (!Layout) {
3674
- console.warn('[wep] 缺少 hostLayoutComponent,未自动注册插件壳路由;请传入宿主 Layout,或在路由表中自行配置与 pluginRoutesParentName 一致的父路由');
3710
+ console.warn('[wep] missing hostLayoutComponent; plugin host route was not auto-registered');
3675
3711
  return;
3676
3712
  }
3677
- const mountDefault = defaultWebExtendPluginRuntime.pluginMountPath;
3678
- let pathRaw = String(opts.pluginMountPath || mountDefault).trim().replace(/\/$/, '') || mountDefault;
3679
- if (!pathRaw.startsWith('/')) {
3680
- pathRaw = `/${pathRaw}`;
3681
- }
3682
- const meta = opts.pluginHostRouteMeta && typeof opts.pluginHostRouteMeta === 'object'
3683
- ? { ...opts.pluginHostRouteMeta }
3684
- : { requiresConfig: true, hidden: true };
3685
3713
  router.addRoute({
3686
- path: pathRaw,
3714
+ path: normalizeMountPath(opts.pluginMountPath),
3687
3715
  name: parentName,
3688
3716
  component: Layout,
3689
3717
  redirect: 'noredirect',
3690
- meta,
3718
+ meta: resolveRouteMeta(opts.pluginHostRouteMeta),
3691
3719
  children: []
3692
3720
  });
3693
3721
  }
@@ -4069,6 +4097,65 @@ function sortByPriority(plugins) {
4069
4097
  })
4070
4098
  .map((decorated) => decorated.entry);
4071
4099
  }
4100
+ function logBootstrapSummary(enabled, payload) {
4101
+ if (enabled) {
4102
+ console.info('[wep] bootstrap_summary', payload);
4103
+ }
4104
+ }
4105
+ function getManifestBody(result) {
4106
+ return result.ok && result.data && typeof result.data === 'object' ? result.data : null;
4107
+ }
4108
+ function getManifestPluginCount(result) {
4109
+ const body = getManifestBody(result);
4110
+ return body && Array.isArray(body.plugins) ? body.plugins.length : 0;
4111
+ }
4112
+ async function fetchManifestSafely(fetchManifest, manifestCtx) {
4113
+ try {
4114
+ if (typeof fetchManifest === 'function') {
4115
+ return await fetchManifest(manifestCtx);
4116
+ }
4117
+ return await defaultFetchWebPluginManifest$1(manifestCtx);
4118
+ }
4119
+ catch (error) {
4120
+ return { ok: false, error, data: null };
4121
+ }
4122
+ }
4123
+ function buildHostKit(opts) {
4124
+ const frozenHostContext = freezeShallowHostContext(opts.hostContext !== undefined ? opts.hostContext : undefined, opts.hostCapabilities && typeof opts.hostCapabilities === 'object' ? opts.hostCapabilities : undefined);
4125
+ return {
4126
+ hostContext: frozenHostContext,
4127
+ bridgeAllowedPathPrefixes: opts.bridgeAllowedPathPrefixes,
4128
+ ...(opts.pluginRoutesParentName ? { pluginRoutesParentName: opts.pluginRoutesParentName } : {}),
4129
+ ...(typeof opts.transformRoutes === 'function' ? { transformRoutes: opts.transformRoutes } : {}),
4130
+ ...(typeof opts.interceptRegisterRoutes === 'function'
4131
+ ? { interceptRegisterRoutes: opts.interceptRegisterRoutes }
4132
+ : {}),
4133
+ ...(typeof opts.adaptRouteDeclarations === 'function'
4134
+ ? { adaptRouteDeclarations: opts.adaptRouteDeclarations }
4135
+ : {}),
4136
+ ...(typeof opts.onPluginRoutesContributed === 'function'
4137
+ ? { onPluginRoutesContributed: opts.onPluginRoutesContributed }
4138
+ : {})
4139
+ };
4140
+ }
4141
+ function resolveManifestRequest(opts) {
4142
+ const isStatic = opts.manifestMode === 'static';
4143
+ if (isStatic) {
4144
+ const raw = String(opts.staticManifestUrl || '').trim();
4145
+ if (!raw) {
4146
+ return null;
4147
+ }
4148
+ return {
4149
+ isStatic,
4150
+ manifestUrl: resolveStaticManifestUrlForFetch(raw, window.location.origin)
4151
+ };
4152
+ }
4153
+ const base = String(opts.manifestBase).replace(/\/$/, '');
4154
+ return {
4155
+ isStatic,
4156
+ manifestUrl: `${base}${opts.manifestListPath}`
4157
+ };
4158
+ }
4072
4159
  async function bootstrapPlugins$1(
4073
4160
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4074
4161
  router,
@@ -4080,26 +4167,17 @@ createHostApiFactory, runtimeOptions) {
4080
4167
  }
4081
4168
  printRuntimeBannerOnce();
4082
4169
  clearActivatedPluginIds();
4083
- const opts = resolveRuntimeOptions$1(runtimeOptions || {});
4170
+ const opts = resolveRuntimeOptions$1(runtimeOptions);
4171
+ const showBootstrapSummary = shouldShowBootstrapSummary(opts);
4084
4172
  setPluginBootstrapRouter(router);
4085
4173
  ensurePluginHostRoute$1(router, opts);
4086
- const base = String(opts.manifestBase).replace(/\/$/, '');
4087
- const isStatic = opts.manifestMode === 'static';
4088
- let manifestUrl;
4089
- if (isStatic) {
4090
- const raw = String(opts.staticManifestUrl || '').trim();
4091
- if (!raw) {
4092
- console.warn('[wep] manifestMode=static requires non-empty staticManifestUrl (or env VITE_WEB_PLUGIN_STATIC_MANIFEST_URL)');
4093
- if (shouldShowBootstrapSummary(opts)) {
4094
- console.info('[wep] bootstrap_summary', { ok: false, reason: 'static_manifest_url_missing' });
4095
- }
4096
- return;
4097
- }
4098
- manifestUrl = resolveStaticManifestUrlForFetch(raw, window.location.origin);
4099
- }
4100
- else {
4101
- manifestUrl = `${base}${opts.manifestListPath}`;
4174
+ const manifestRequest = resolveManifestRequest(opts);
4175
+ if (!manifestRequest) {
4176
+ console.warn('[wep] manifestMode=static requires non-empty staticManifestUrl (or env VITE_WEB_PLUGIN_STATIC_MANIFEST_URL)');
4177
+ logBootstrapSummary(showBootstrapSummary, { ok: false, reason: 'static_manifest_url_missing' });
4178
+ return;
4102
4179
  }
4180
+ const { isStatic, manifestUrl } = manifestRequest;
4103
4181
  const hostSet = buildAllowedScriptHostsSet(opts.allowedScriptHosts);
4104
4182
  const explicit = parseWebPluginDevMapExplicit(opts);
4105
4183
  const manifestCtx = {
@@ -4107,27 +4185,15 @@ createHostApiFactory, runtimeOptions) {
4107
4185
  credentials: opts.manifestFetchCredentials
4108
4186
  };
4109
4187
  const [primaryResult, implicit] = await Promise.all([
4110
- (async () => {
4111
- try {
4112
- if (typeof opts.fetchManifest === 'function') {
4113
- return await opts.fetchManifest(manifestCtx);
4114
- }
4115
- return await defaultFetchWebPluginManifest$1(manifestCtx);
4116
- }
4117
- catch (e) {
4118
- return { ok: false, error: e, data: null };
4119
- }
4120
- })(),
4188
+ fetchManifestSafely(typeof opts.fetchManifest === 'function'
4189
+ ? opts.fetchManifest
4190
+ : undefined, manifestCtx),
4121
4191
  buildImplicitWebPluginDevMap(opts, hostSet)
4122
4192
  ]);
4123
4193
  let manifestResult = primaryResult;
4124
4194
  let manifestUrlUsed = manifestUrl;
4125
4195
  if (!isStatic && opts.devManifestFallback && opts.isDev) {
4126
- const dataObj = primaryResult.ok && primaryResult.data && typeof primaryResult.data === 'object'
4127
- ? primaryResult.data
4128
- : null;
4129
- const plen = dataObj && Array.isArray(dataObj.plugins) ? dataObj.plugins.length : 0;
4130
- const needFallback = !primaryResult.ok || plen === 0;
4196
+ const needFallback = !primaryResult.ok || getManifestPluginCount(primaryResult) === 0;
4131
4197
  const fallbackRaw = String(opts.devFallbackStaticManifestUrl || '').trim();
4132
4198
  if (needFallback && fallbackRaw) {
4133
4199
  const fallbackUrl = resolveStaticManifestUrlForFetch(fallbackRaw, window.location.origin);
@@ -4136,8 +4202,7 @@ createHostApiFactory, runtimeOptions) {
4136
4202
  credentials: opts.manifestFetchCredentials
4137
4203
  };
4138
4204
  const fr = await fetchStaticManifestViaHttp(fallbackCtx);
4139
- const fdata = fr.ok && fr.data && typeof fr.data === 'object' ? fr.data : null;
4140
- const flen = fdata && Array.isArray(fdata.plugins) ? fdata.plugins.length : 0;
4205
+ const flen = getManifestPluginCount(fr);
4141
4206
  if (fr.ok && flen > 0) {
4142
4207
  manifestResult = fr;
4143
4208
  manifestUrlUsed = fallbackUrl;
@@ -4147,22 +4212,7 @@ createHostApiFactory, runtimeOptions) {
4147
4212
  }
4148
4213
  const devMap = mergeDevMaps(implicit, explicit);
4149
4214
  startPluginDevSseForMap(devMap, opts.isDev, hostSet, opts.devReloadSsePath);
4150
- const frozenHostContext = freezeShallowHostContext(opts.hostContext !== undefined ? opts.hostContext : undefined, opts.hostCapabilities && typeof opts.hostCapabilities === 'object' ? opts.hostCapabilities : undefined);
4151
- const hostKit = {
4152
- hostContext: frozenHostContext,
4153
- bridgeAllowedPathPrefixes: opts.bridgeAllowedPathPrefixes,
4154
- ...(opts.pluginRoutesParentName ? { pluginRoutesParentName: opts.pluginRoutesParentName } : {}),
4155
- ...(typeof opts.transformRoutes === 'function' ? { transformRoutes: opts.transformRoutes } : {}),
4156
- ...(typeof opts.interceptRegisterRoutes === 'function'
4157
- ? { interceptRegisterRoutes: opts.interceptRegisterRoutes }
4158
- : {}),
4159
- ...(typeof opts.adaptRouteDeclarations === 'function'
4160
- ? { adaptRouteDeclarations: opts.adaptRouteDeclarations }
4161
- : {}),
4162
- ...(typeof opts.onPluginRoutesContributed === 'function'
4163
- ? { onPluginRoutesContributed: opts.onPluginRoutesContributed }
4164
- : {})
4165
- };
4215
+ const hostKit = buildHostKit(opts);
4166
4216
  if (!manifestResult.ok) {
4167
4217
  if (manifestResult.error) {
4168
4218
  console.warn('[wep] fetch manifest failed', manifestResult.error);
@@ -4171,16 +4221,12 @@ createHostApiFactory, runtimeOptions) {
4171
4221
  const label = isStatic ? 'static manifest' : 'manifest HTTP';
4172
4222
  console.warn(`[wep] ${label}`, manifestResult.status, manifestUrlUsed);
4173
4223
  }
4174
- if (shouldShowBootstrapSummary(opts)) {
4175
- console.info('[wep] bootstrap_summary', { ok: false, reason: 'manifest_fetch' });
4176
- }
4224
+ logBootstrapSummary(showBootstrapSummary, { ok: false, reason: 'manifest_fetch' });
4177
4225
  return;
4178
4226
  }
4179
- const data = manifestResult.data;
4227
+ const data = getManifestBody(manifestResult);
4180
4228
  if (!data) {
4181
- if (shouldShowBootstrapSummary(opts)) {
4182
- console.info('[wep] bootstrap_summary', { ok: false, reason: 'manifest_empty_body' });
4183
- }
4229
+ logBootstrapSummary(showBootstrapSummary, { ok: false, reason: 'manifest_empty_body' });
4184
4230
  return;
4185
4231
  }
4186
4232
  const apiVer = data.hostPluginApiVersion;
@@ -4193,12 +4239,10 @@ createHostApiFactory, runtimeOptions) {
4193
4239
  host: HOST_PLUGIN_API_VERSION,
4194
4240
  manifest: apiVer
4195
4241
  });
4196
- if (shouldShowBootstrapSummary(opts)) {
4197
- console.info('[wep] bootstrap_summary', {
4198
- ok: false,
4199
- reason: 'manifest_host_api_version_mismatch'
4200
- });
4201
- }
4242
+ logBootstrapSummary(showBootstrapSummary, {
4243
+ ok: false,
4244
+ reason: 'manifest_host_api_version_mismatch'
4245
+ });
4202
4246
  return;
4203
4247
  }
4204
4248
  }
@@ -4298,9 +4342,7 @@ createHostApiFactory, runtimeOptions) {
4298
4342
  }
4299
4343
  }
4300
4344
  }
4301
- if (shouldShowBootstrapSummary(opts)) {
4302
- console.info('[wep] bootstrap_summary', { ok: true, ...summary });
4303
- }
4345
+ logBootstrapSummary(showBootstrapSummary, { ok: true, ...summary });
4304
4346
  }
4305
4347
 
4306
4348
  /**
@@ -4578,10 +4620,39 @@ function clearContributedRoutesForPlugin(pluginId) {
4578
4620
  }
4579
4621
 
4580
4622
  /**
4581
- * 构造插件 `activator(hostApi)` 使用的宿主 API:路由、扩展点、资源与受控请求桥。
4623
+ * 构造插件 `activator(hostApi)` 使用的宿主 API
4582
4624
  */
4583
4625
  let slotItemKeySeq = 0;
4584
4626
  let routeSynthSeq = 0;
4627
+ function getBridgePrefixes(hostKitOptions) {
4628
+ return Array.isArray(hostKitOptions.bridgeAllowedPathPrefixes) &&
4629
+ hostKitOptions.bridgeAllowedPathPrefixes.length > 0
4630
+ ? hostKitOptions.bridgeAllowedPathPrefixes
4631
+ : defaultWebExtendPluginRuntime.bridgeAllowedPathPrefixes;
4632
+ }
4633
+ function resolveHostRuntime(hostKitOptions) {
4634
+ const hostContext = hostKitOptions.hostContext != null && typeof hostKitOptions.hostContext === 'object'
4635
+ ? hostKitOptions.hostContext
4636
+ : Object.freeze({});
4637
+ const hostVue = hostContext.Vue;
4638
+ return {
4639
+ hostContext,
4640
+ VueRuntime: hostVue || Vue
4641
+ };
4642
+ }
4643
+ function normalizeParentRouteName(hostKitOptions) {
4644
+ return typeof hostKitOptions.pluginRoutesParentName === 'string'
4645
+ ? hostKitOptions.pluginRoutesParentName.trim()
4646
+ : '';
4647
+ }
4648
+ function normalizeUrls(urls) {
4649
+ return Array.isArray(urls)
4650
+ ? urls
4651
+ .filter((url) => typeof url === 'string')
4652
+ .map((url) => url.trim())
4653
+ .filter(Boolean)
4654
+ : [];
4655
+ }
4585
4656
  function decorateRouteTreeWithPluginMeta(pluginId, route) {
4586
4657
  const meta = route.meta && typeof route.meta === 'object' && !Array.isArray(route.meta)
4587
4658
  ? route.meta
@@ -4607,97 +4678,81 @@ function decorateRouteTreeWithPluginMeta(pluginId, route) {
4607
4678
  function analyzeRouteInputTree(nodes) {
4608
4679
  let hasDecl = false;
4609
4680
  let hasCfg = false;
4610
- function walk(r) {
4611
- if (!r || typeof r !== 'object') {
4681
+ function walk(node) {
4682
+ if (!node || typeof node !== 'object') {
4612
4683
  return;
4613
4684
  }
4614
- const o = r;
4615
- const cfg = o.component != null || o.components != null;
4616
- const decl = typeof o.componentRef === 'string';
4617
- if (cfg) {
4685
+ const record = node;
4686
+ const hasRouteConfig = record.component != null || record.components != null;
4687
+ const hasRouteDecl = typeof record.componentRef === 'string';
4688
+ if (hasRouteConfig) {
4618
4689
  hasCfg = true;
4619
4690
  }
4620
- else if (decl) {
4691
+ else if (hasRouteDecl) {
4621
4692
  hasDecl = true;
4622
4693
  }
4623
- const ch = o.children;
4624
- if (Array.isArray(ch)) {
4625
- for (const c of ch) {
4626
- walk(c);
4694
+ if (Array.isArray(record.children)) {
4695
+ for (const child of record.children) {
4696
+ walk(child);
4627
4697
  }
4628
4698
  }
4629
4699
  }
4630
- for (const n of nodes) {
4631
- walk(n);
4700
+ for (const node of nodes) {
4701
+ walk(node);
4632
4702
  }
4633
4703
  return { hasDecl, hasCfg };
4634
4704
  }
4635
- /**
4636
- * 单插件在宿主侧的 API 句柄。工厂请传 `(id, router, kit) => createHostApi(id, r, kit)` 以便 bridge 白名单等到位。
4637
- */
4705
+ function rollbackRegisteredTopRoutes(
4638
4706
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4639
- function createHostApi(pluginId, router, hostKitOptions = {}) {
4640
- const bridgePrefixes = Array.isArray(hostKitOptions.bridgeAllowedPathPrefixes) &&
4641
- hostKitOptions.bridgeAllowedPathPrefixes.length > 0
4642
- ? hostKitOptions.bridgeAllowedPathPrefixes
4643
- : defaultWebExtendPluginRuntime.bridgeAllowedPathPrefixes;
4644
- const bridge = createRequestBridge({ allowedPathPrefixes: bridgePrefixes });
4645
- const parentName = typeof hostKitOptions.pluginRoutesParentName === 'string'
4646
- ? hostKitOptions.pluginRoutesParentName.trim()
4647
- : '';
4648
- function rollbackRegisteredTopRoutes(routes) {
4649
- for (let i = routes.length - 1; i >= 0; i--) {
4650
- const route = routes[i];
4651
- if (typeof route.dispose === 'function') {
4652
- try {
4653
- route.dispose();
4654
- continue;
4655
- }
4656
- catch (e) {
4657
- console.warn('[wep] rollback route disposer failed', route.name, e);
4658
- }
4707
+ router, routes) {
4708
+ for (let i = routes.length - 1; i >= 0; i--) {
4709
+ const route = routes[i];
4710
+ if (typeof route.dispose === 'function') {
4711
+ try {
4712
+ route.dispose();
4713
+ continue;
4659
4714
  }
4660
- if (typeof router.removeRoute === 'function') {
4661
- try {
4662
- router.removeRoute(route.name);
4663
- }
4664
- catch (e) {
4665
- console.warn('[wep] rollback removeRoute failed', route.name, e);
4666
- }
4715
+ catch (e) {
4716
+ console.warn('[wep] rollback route disposer failed', route.name, e);
4717
+ }
4718
+ }
4719
+ if (typeof router.removeRoute === 'function') {
4720
+ try {
4721
+ router.removeRoute(route.name);
4722
+ }
4723
+ catch (e) {
4724
+ console.warn('[wep] rollback removeRoute failed', route.name, e);
4667
4725
  }
4668
4726
  }
4669
4727
  }
4670
- function applyInternalRegister(rawRouteConfigs) {
4671
- const wrapped = rawRouteConfigs.map((r) => ({
4672
- ...decorateRouteTreeWithPluginMeta(pluginId, r),
4673
- name: r.name || `${routeSynthNamePrefix}${pluginId}_${routeSynthSeq++}`
4674
- }));
4728
+ }
4729
+ function decorateTopRoutes(pluginId, rawRouteConfigs) {
4730
+ return rawRouteConfigs.map((route) => ({
4731
+ ...decorateRouteTreeWithPluginMeta(pluginId, route),
4732
+ name: route.name || `${routeSynthNamePrefix}${pluginId}_${routeSynthSeq++}`
4733
+ }));
4734
+ }
4735
+ function createRouteRegistrar({ pluginId, router, parentName, hostKitOptions }) {
4736
+ function addTopRoute(route) {
4737
+ const dispose = parentName ? router.addRoute(parentName, route) : router.addRoute(route);
4738
+ return {
4739
+ name: String(route.name),
4740
+ dispose: typeof dispose === 'function' ? dispose : undefined
4741
+ };
4742
+ }
4743
+ return function applyInternalRegister(rawRouteConfigs) {
4675
4744
  if (typeof router.addRoute !== 'function') {
4676
- throw new Error('[wep] vue-router 3.5+ 必需:请使用 router.addRoute(不再支持 addRoutes)');
4745
+ throw new Error('[wep] vue-router 3.5+ required: please use router.addRoute');
4677
4746
  }
4747
+ const wrapped = decorateTopRoutes(pluginId, rawRouteConfigs);
4678
4748
  const registeredTopRoutes = [];
4679
4749
  try {
4680
- if (parentName) {
4681
- for (const r of wrapped) {
4682
- const dispose = router.addRoute(parentName, r);
4683
- registeredTopRoutes.push({
4684
- name: String(r.name),
4685
- dispose: typeof dispose === 'function' ? dispose : undefined
4686
- });
4687
- }
4688
- }
4689
- else {
4690
- for (const r of wrapped) {
4691
- const dispose = router.addRoute(r);
4692
- registeredTopRoutes.push({
4693
- name: String(r.name),
4694
- dispose: typeof dispose === 'function' ? dispose : undefined
4695
- });
4696
- }
4750
+ for (const route of wrapped) {
4751
+ registeredTopRoutes.push(addTopRoute(route));
4697
4752
  }
4698
4753
  }
4699
4754
  catch (e) {
4700
- rollbackRegisteredTopRoutes(registeredTopRoutes);
4755
+ rollbackRegisteredTopRoutes(router, registeredTopRoutes);
4701
4756
  throw e;
4702
4757
  }
4703
4758
  recordPluginTopRoutes(pluginId, registeredTopRoutes);
@@ -4710,69 +4765,80 @@ function createHostApi(pluginId, router, hostKitOptions = {}) {
4710
4765
  contributedRoutes
4711
4766
  });
4712
4767
  }
4713
- }
4714
- function injectStylesheet(href) {
4715
- const link = document.createElement('link');
4716
- link.rel = 'stylesheet';
4717
- link.href = href;
4718
- link.setAttribute('data-plugin-asset', pluginId);
4719
- document.head.appendChild(link);
4720
- }
4721
- function injectScript(src) {
4722
- return new Promise((resolve, reject) => {
4723
- const s = document.createElement('script');
4724
- s.async = true;
4725
- s.src = src;
4726
- s.setAttribute('data-plugin-asset', pluginId);
4727
- s.onload = () => resolve();
4728
- s.onerror = () => reject(new Error('script failed: ' + src));
4729
- document.head.appendChild(s);
4768
+ };
4769
+ }
4770
+ function injectStylesheet(pluginId, href) {
4771
+ const link = document.createElement('link');
4772
+ link.rel = 'stylesheet';
4773
+ link.href = href;
4774
+ link.setAttribute('data-plugin-asset', pluginId);
4775
+ document.head.appendChild(link);
4776
+ }
4777
+ function injectScript(pluginId, src) {
4778
+ return new Promise((resolve, reject) => {
4779
+ const script = document.createElement('script');
4780
+ script.async = true;
4781
+ script.src = src;
4782
+ script.setAttribute('data-plugin-asset', pluginId);
4783
+ script.onload = () => resolve();
4784
+ script.onerror = () => reject(new Error('script failed: ' + src));
4785
+ document.head.appendChild(script);
4786
+ });
4787
+ }
4788
+ function resolveRouteConfigs(pluginId,
4789
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4790
+ router, hostKitOptions, routes) {
4791
+ const { hasDecl, hasCfg } = analyzeRouteInputTree(routes);
4792
+ if (hasDecl && hasCfg) {
4793
+ throw new Error('[wep] registerRoutes: cannot mix RouteDeclaration (componentRef) with RouteConfig (component)');
4794
+ }
4795
+ let configs;
4796
+ if (hasDecl) {
4797
+ const adapt = hostKitOptions.adaptRouteDeclarations;
4798
+ if (typeof adapt !== 'function') {
4799
+ throw new Error('[wep] registerRoutes: RouteDeclaration (componentRef) requires adaptRouteDeclarations on the host');
4800
+ }
4801
+ configs = adapt({
4802
+ pluginId,
4803
+ router,
4804
+ declarations: routes
4730
4805
  });
4731
4806
  }
4732
- const hostContext = hostKitOptions.hostContext != null && typeof hostKitOptions.hostContext === 'object'
4733
- ? hostKitOptions.hostContext
4734
- : Object.freeze({});
4735
- const hostVue = hostContext && hostContext.Vue;
4736
- const VueRuntime = hostVue || Vue;
4807
+ else {
4808
+ configs = routes;
4809
+ }
4810
+ return typeof hostKitOptions.transformRoutes === 'function'
4811
+ ? hostKitOptions.transformRoutes({
4812
+ pluginId,
4813
+ router,
4814
+ routes: configs
4815
+ })
4816
+ : configs;
4817
+ }
4818
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4819
+ function createHostApi(pluginId, router, hostKitOptions = {}) {
4820
+ const bridge = createRequestBridge({ allowedPathPrefixes: getBridgePrefixes(hostKitOptions) });
4821
+ const parentName = normalizeParentRouteName(hostKitOptions);
4822
+ const applyInternalRegister = createRouteRegistrar({
4823
+ pluginId,
4824
+ router,
4825
+ parentName,
4826
+ hostKitOptions
4827
+ });
4828
+ const { hostContext, VueRuntime } = resolveHostRuntime(hostKitOptions);
4737
4829
  ensureRegistriesReactive(VueRuntime);
4738
4830
  registerPluginTeardown(pluginId, () => {
4739
4831
  clearContributedRoutesForPlugin(pluginId);
4740
4832
  });
4741
4833
  return {
4742
4834
  hostPluginApiVersion: HOST_PLUGIN_API_VERSION,
4743
- /** 宿主注入的只读依赖(store、router、开放能力等),见 `resolveRuntimeOptions.hostContext` */
4744
4835
  hostContext,
4745
4836
  registerRoutes(routes) {
4746
4837
  const list = Array.isArray(routes) ? routes : [];
4747
4838
  if (list.length === 0) {
4748
4839
  return;
4749
4840
  }
4750
- const { hasDecl, hasCfg } = analyzeRouteInputTree(list);
4751
- if (hasDecl && hasCfg) {
4752
- throw new Error('[wep] registerRoutes: cannot mix RouteDeclaration (componentRef) with RouteConfig (component)');
4753
- }
4754
- let configs;
4755
- if (hasDecl) {
4756
- const adapt = hostKitOptions.adaptRouteDeclarations;
4757
- if (typeof adapt !== 'function') {
4758
- throw new Error('[wep] registerRoutes: RouteDeclaration (componentRef) requires adaptRouteDeclarations on the host');
4759
- }
4760
- configs = adapt({
4761
- pluginId,
4762
- router,
4763
- declarations: list
4764
- });
4765
- }
4766
- else {
4767
- configs = list;
4768
- }
4769
- if (typeof hostKitOptions.transformRoutes === 'function') {
4770
- configs = hostKitOptions.transformRoutes({
4771
- pluginId,
4772
- router,
4773
- routes: configs
4774
- });
4775
- }
4841
+ const configs = resolveRouteConfigs(pluginId, router, hostKitOptions, list);
4776
4842
  if (typeof hostKitOptions.interceptRegisterRoutes === 'function') {
4777
4843
  hostKitOptions.interceptRegisterRoutes({
4778
4844
  pluginId,
@@ -4793,11 +4859,11 @@ function createHostApi(pluginId, router, hostKitOptions = {}) {
4793
4859
  VueRuntime.set(registries.slots, pointId, []);
4794
4860
  }
4795
4861
  const list = registries.slots[pointId];
4796
- for (const c of components) {
4862
+ for (const componentEntry of components) {
4797
4863
  list.push({
4798
4864
  pluginId,
4799
- component: c.component,
4800
- priority: c.priority != null ? c.priority : 0,
4865
+ component: componentEntry.component,
4866
+ priority: componentEntry.priority != null ? componentEntry.priority : 0,
4801
4867
  key: `${pluginId}-${pointId}-${++slotItemKeySeq}`
4802
4868
  });
4803
4869
  }
@@ -4805,14 +4871,12 @@ function createHostApi(pluginId, router, hostKitOptions = {}) {
4805
4871
  registries.slotRevision++;
4806
4872
  },
4807
4873
  registerStylesheetUrls(urls) {
4808
- for (const u of urls || []) {
4809
- if (typeof u === 'string' && u) {
4810
- injectStylesheet(u);
4811
- }
4874
+ for (const url of normalizeUrls(urls)) {
4875
+ injectStylesheet(pluginId, url);
4812
4876
  }
4813
4877
  },
4814
4878
  registerScriptUrls(urls) {
4815
- const chain = (urls || []).filter((u) => typeof u === 'string' && u).reduce((p, u) => p.then(() => injectScript(u)), Promise.resolve());
4879
+ const chain = normalizeUrls(urls).reduce((promise, url) => promise.then(() => injectScript(pluginId, url)), Promise.resolve());
4816
4880
  chain.catch((e) => console.warn('[wep] registerScriptUrls', pluginId, e));
4817
4881
  },
4818
4882
  registerSanitizedHtmlSnippet() {
@@ -4885,16 +4949,6 @@ function createExtensionPointComponent(VueLike = Vue) {
4885
4949
  }
4886
4950
  var ExtensionPoint = createExtensionPointComponent();
4887
4951
 
4888
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4889
- function installWebExtendPluginVue2(Vue, router, options) {
4890
- if (Vue) {
4891
- ensureRegistriesReactive(Vue);
4892
- Vue.component('ExtensionPoint', createExtensionPointComponent(Vue));
4893
- }
4894
- const runtime = resolveRuntimeOptions$1(options || {});
4895
- return bootstrapPlugins$1(router, (id, r, kit) => createHostApi(id, r, kit || {}), runtime);
4896
- }
4897
-
4898
4952
  function isRecord(input) {
4899
4953
  return !!input && typeof input === 'object' && !Array.isArray(input);
4900
4954
  }
@@ -4932,6 +4986,19 @@ VueRuntime, options = {}) {
4932
4986
  return modules;
4933
4987
  }
4934
4988
 
4989
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4990
+ function installWebExtendPluginVue2(Vue, router, options) {
4991
+ const runtime = resolveRuntimeOptions$1(options);
4992
+ if (Vue) {
4993
+ ensureRegistriesReactive(Vue);
4994
+ Vue.component('ExtensionPoint', createExtensionPointComponent(Vue));
4995
+ if (runtime.hostBridge && typeof runtime.hostBridge === 'object') {
4996
+ installHostBridge(Vue, runtime.hostBridge);
4997
+ }
4998
+ }
4999
+ return bootstrapPlugins$1(router, createHostApi, runtime);
5000
+ }
5001
+
4935
5002
  function resolveManifestPathUnderApiBase(manifestUrl, apiBase) {
4936
5003
  const base = String(apiBase !== undefined
4937
5004
  ? apiBase
@@ -4955,17 +5022,22 @@ function bridgePrefixesFromVueCliEnv() {
4955
5022
  const raw = [base ? `${base}/` : '', '/api/', '/dev-api/'].filter(Boolean);
4956
5023
  return [...new Set(raw)];
4957
5024
  }
5025
+ function asRecord(value) {
5026
+ return value && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
5027
+ }
4958
5028
  function createVueCliAxiosInstallOptions(deps, extra = {}) {
4959
5029
  const { request } = deps;
4960
5030
  if (typeof request !== 'function') {
4961
5031
  throw new Error('[wep] createVueCliAxiosInstallOptions requires deps.request');
4962
5032
  }
4963
- const { fetchManifest: userFetchManifest, manifestMode: extraManifestMode, staticManifestUrl: extraStaticManifestUrl, ...restExtra } = extra;
5033
+ const manifest = asRecord(extra.manifest) || {};
5034
+ const host = asRecord(extra.host) || {};
5035
+ const mergedHost = { ...host };
4964
5036
  const envBase = (typeof process !== 'undefined' && process.env && process.env.VUE_APP_BASE_API
4965
5037
  ? String(process.env.VUE_APP_BASE_API)
4966
5038
  : '').replace(/\/$/, '');
4967
- const userBase = extra.manifestBase !== undefined && String(extra.manifestBase).trim() !== ''
4968
- ? String(extra.manifestBase).replace(/\/$/, '')
5039
+ const userBase = manifest.baseUrl !== undefined && String(manifest.baseUrl).trim() !== ''
5040
+ ? String(manifest.baseUrl).replace(/\/$/, '')
4969
5041
  : '';
4970
5042
  const stripBase = userBase || envBase;
4971
5043
  const fetchManifestApi = async (ctx) => {
@@ -4976,11 +5048,7 @@ function createVueCliAxiosInstallOptions(deps, extra = {}) {
4976
5048
  });
4977
5049
  const data = unwrapNestedManifestBody(body);
4978
5050
  if (!data || typeof data !== 'object') {
4979
- return {
4980
- ok: false,
4981
- error: new Error('[wep] invalid manifest response'),
4982
- data: null
4983
- };
5051
+ return { ok: false, error: new Error('[wep] invalid manifest response'), data: null };
4984
5052
  }
4985
5053
  return { ok: true, data };
4986
5054
  }
@@ -4988,28 +5056,33 @@ function createVueCliAxiosInstallOptions(deps, extra = {}) {
4988
5056
  return { ok: false, error, data: null };
4989
5057
  }
4990
5058
  };
4991
- const manifestMode = resolveManifestModeFromInputs(extraManifestMode);
4992
- const staticManifestUrl = resolveStaticManifestUrlFromInputs(extraStaticManifestUrl);
4993
- const fetchManifest = typeof userFetchManifest === 'function'
4994
- ? userFetchManifest
4995
- : manifestMode === 'static'
5059
+ const manifestSource = resolveManifestModeFromInputs(manifest.source);
5060
+ const staticUrl = resolveStaticManifestUrlFromInputs(manifest.staticUrl);
5061
+ const fetchManifest = typeof manifest.fetch === 'function'
5062
+ ? manifest.fetch
5063
+ : manifestSource === 'static'
4996
5064
  ? fetchStaticManifestViaHttp
4997
5065
  : fetchManifestApi;
4998
- const options = {
4999
- manifestBase: stripBase || undefined,
5000
- bridgeAllowedPathPrefixes: bridgePrefixesFromVueCliEnv(),
5001
- manifestMode,
5002
- staticManifestUrl,
5003
- ...restExtra,
5004
- fetchManifest
5005
- };
5006
5066
  const listPath = typeof process !== 'undefined' &&
5007
5067
  process.env &&
5008
- process.env[webExtendPluginEnvKeys.manifestPathAlt];
5009
- if (listPath && options.manifestListPath === undefined && extra.manifestListPath === undefined) {
5010
- options.manifestListPath = String(process.env[webExtendPluginEnvKeys.manifestPathAlt]);
5068
+ process.env[webExtendPluginEnvKeys.manifestPathAlt]
5069
+ ? String(process.env[webExtendPluginEnvKeys.manifestPathAlt])
5070
+ : undefined;
5071
+ if (mergedHost.requestPathPrefixes === undefined) {
5072
+ mergedHost.requestPathPrefixes = bridgePrefixesFromVueCliEnv();
5011
5073
  }
5012
- return options;
5074
+ return {
5075
+ ...extra,
5076
+ manifest: {
5077
+ ...manifest,
5078
+ baseUrl: stripBase || undefined,
5079
+ listPath: manifest.listPath !== undefined ? manifest.listPath : listPath,
5080
+ source: manifestSource,
5081
+ staticUrl,
5082
+ fetch: fetchManifest
5083
+ },
5084
+ host: mergedHost
5085
+ };
5013
5086
  }
5014
5087
 
5015
5088
  const { bootstrapPlugins, defaultFetchWebPluginManifest, resolveRuntimeOptions, ensurePluginHostRoute, getActivatedPluginIds } = pluginRuntime;