web-extend-plugin-vue2 0.3.4 → 0.3.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 +40 -1
- package/dist/index.cjs +78 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +78 -21
- package/dist/index.mjs.map +1 -1
- package/index.d.ts +11 -0
- package/package.json +13 -9
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Vue 2 host runtime for web plugin bootstrap, route registration, host API inject
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm i web-extend-plugin-vue2
|
|
8
|
+
npm i web-extend-plugin-vue2@0.3.5
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
Peer dependencies:
|
|
@@ -13,6 +13,10 @@ Peer dependencies:
|
|
|
13
13
|
- `vue >= 2.6.0 < 3`
|
|
14
14
|
- `vue-router >= 3.5.0 < 4`
|
|
15
15
|
|
|
16
|
+
Published package:
|
|
17
|
+
|
|
18
|
+
- `web-extend-plugin-vue2@0.3.5`
|
|
19
|
+
|
|
16
20
|
## Public API
|
|
17
21
|
|
|
18
22
|
The package now exposes named exports only.
|
|
@@ -33,6 +37,9 @@ Utilities:
|
|
|
33
37
|
|
|
34
38
|
- `createRequestBridge`
|
|
35
39
|
- `createVueCliAxiosInstallOptions`
|
|
40
|
+
- `registerHostComponents`
|
|
41
|
+
- `registerVueGlobalComponents`
|
|
42
|
+
- `registerHostModules`
|
|
36
43
|
- `composeManifestFetch`
|
|
37
44
|
- `manifestFetchCacheMiddleware`
|
|
38
45
|
- `wrapManifestFetchWithCache`
|
|
@@ -90,6 +97,37 @@ installWebExtendPluginVue2(
|
|
|
90
97
|
).catch(console.warn)
|
|
91
98
|
```
|
|
92
99
|
|
|
100
|
+
## Host exposes
|
|
101
|
+
|
|
102
|
+
Preferred host integration uses concrete component/module exposes instead of relying on `hostCapabilities`.
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
import {
|
|
106
|
+
installWebExtendPluginVue2,
|
|
107
|
+
createVueCliAxiosInstallOptions,
|
|
108
|
+
registerHostComponents,
|
|
109
|
+
registerVueGlobalComponents,
|
|
110
|
+
registerHostModules
|
|
111
|
+
} from 'web-extend-plugin-vue2'
|
|
112
|
+
|
|
113
|
+
registerVueGlobalComponents(Vue, {
|
|
114
|
+
include: (name) => /^El[A-Z]/.test(name),
|
|
115
|
+
mapName: (name) => name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase()
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
registerHostComponents({
|
|
119
|
+
'app.pagination': Pagination,
|
|
120
|
+
'app.dict-tag': DictTag
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
registerHostModules({
|
|
124
|
+
request,
|
|
125
|
+
download
|
|
126
|
+
})
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Plugins should depend on stable expose names such as `el-button`, `app.pagination`, or `request`.
|
|
130
|
+
|
|
93
131
|
## Important runtime options
|
|
94
132
|
|
|
95
133
|
- `manifestBase`: API prefix, default `/fp-api`
|
|
@@ -105,6 +143,7 @@ installWebExtendPluginVue2(
|
|
|
105
143
|
- `pluginRoutesParentName`: explicit parent route name for child plugin routes
|
|
106
144
|
- `ensurePluginHostRoute`: when `true`, auto-registers the shell route
|
|
107
145
|
- `hostContext`: readonly host dependencies injected into `hostApi.hostContext`
|
|
146
|
+
- `hostCapabilities`: optional legacy metadata; prefer `registerHostComponents` and `registerHostModules`
|
|
108
147
|
|
|
109
148
|
## Notes
|
|
110
149
|
|
package/dist/index.cjs
CHANGED
|
@@ -81,7 +81,7 @@ function getEnvObject() {
|
|
|
81
81
|
return raw.__WEP_ENV__;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
catch {
|
|
84
|
+
catch (_a) {
|
|
85
85
|
/* ignore */
|
|
86
86
|
}
|
|
87
87
|
return null;
|
|
@@ -117,7 +117,7 @@ function readProcessEnv(key) {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
catch {
|
|
120
|
+
catch (_a) {
|
|
121
121
|
/* ignore */
|
|
122
122
|
}
|
|
123
123
|
return undefined;
|
|
@@ -143,7 +143,7 @@ function resolveBundledIsDev() {
|
|
|
143
143
|
return true;
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
|
-
catch {
|
|
146
|
+
catch (_a) {
|
|
147
147
|
/* ignore */
|
|
148
148
|
}
|
|
149
149
|
try {
|
|
@@ -151,7 +151,7 @@ function resolveBundledIsDev() {
|
|
|
151
151
|
return true;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
catch {
|
|
154
|
+
catch (_b) {
|
|
155
155
|
/* ignore */
|
|
156
156
|
}
|
|
157
157
|
return false;
|
|
@@ -226,7 +226,7 @@ function isScriptHostAllowed(url, hostSet) {
|
|
|
226
226
|
const h = normalizeHost(u.hostname);
|
|
227
227
|
return hostSet.has(h);
|
|
228
228
|
}
|
|
229
|
-
catch {
|
|
229
|
+
catch (_a) {
|
|
230
230
|
return false;
|
|
231
231
|
}
|
|
232
232
|
}
|
|
@@ -3438,7 +3438,7 @@ function parseWebPluginDevMapExplicit(opts) {
|
|
|
3438
3438
|
const map = JSON.parse(String(raw));
|
|
3439
3439
|
return map && typeof map === 'object' ? map : null;
|
|
3440
3440
|
}
|
|
3441
|
-
catch {
|
|
3441
|
+
catch (_a) {
|
|
3442
3442
|
console.warn('[wep] invalid webPluginDevMapJson / VITE_WEB_PLUGIN_DEV_MAP');
|
|
3443
3443
|
return null;
|
|
3444
3444
|
}
|
|
@@ -3490,7 +3490,7 @@ async function buildImplicitWebPluginDevMap(opts, hostSet) {
|
|
|
3490
3490
|
return {};
|
|
3491
3491
|
}
|
|
3492
3492
|
}
|
|
3493
|
-
catch {
|
|
3493
|
+
catch (_a) {
|
|
3494
3494
|
return {};
|
|
3495
3495
|
}
|
|
3496
3496
|
const pathPart = opts.webPluginDevEntryPath;
|
|
@@ -3514,7 +3514,7 @@ function closeAllPluginDevEventSources() {
|
|
|
3514
3514
|
try {
|
|
3515
3515
|
es.close();
|
|
3516
3516
|
}
|
|
3517
|
-
catch {
|
|
3517
|
+
catch (_a) {
|
|
3518
3518
|
/* ignore */
|
|
3519
3519
|
}
|
|
3520
3520
|
}
|
|
@@ -3532,7 +3532,7 @@ function isDevOriginAllowedForSse(origin, hostSet) {
|
|
|
3532
3532
|
const u = new URL(origin);
|
|
3533
3533
|
return hostSet.has(normalizeHost(u.hostname));
|
|
3534
3534
|
}
|
|
3535
|
-
catch {
|
|
3535
|
+
catch (_a) {
|
|
3536
3536
|
return false;
|
|
3537
3537
|
}
|
|
3538
3538
|
}
|
|
@@ -3576,7 +3576,7 @@ function startPluginDevSseForMap(devMap, isDev, hostSet, ssePath) {
|
|
|
3576
3576
|
try {
|
|
3577
3577
|
origins.add(new URL(t, window.location.href).origin);
|
|
3578
3578
|
}
|
|
3579
|
-
catch {
|
|
3579
|
+
catch (_a) {
|
|
3580
3580
|
/* skip */
|
|
3581
3581
|
}
|
|
3582
3582
|
}
|
|
@@ -3771,6 +3771,25 @@ function cloneMetaMap(registry) {
|
|
|
3771
3771
|
}
|
|
3772
3772
|
return out;
|
|
3773
3773
|
}
|
|
3774
|
+
function resolveVueGlobalComponentSource(VueRuntime) {
|
|
3775
|
+
if (!VueRuntime || typeof VueRuntime !== 'object' || Array.isArray(VueRuntime)) {
|
|
3776
|
+
return undefined;
|
|
3777
|
+
}
|
|
3778
|
+
const maybeOptions = VueRuntime.options;
|
|
3779
|
+
if (!maybeOptions || typeof maybeOptions !== 'object' || Array.isArray(maybeOptions)) {
|
|
3780
|
+
return undefined;
|
|
3781
|
+
}
|
|
3782
|
+
const maybeComponents = maybeOptions.components;
|
|
3783
|
+
return maybeComponents && typeof maybeComponents === 'object' && !Array.isArray(maybeComponents)
|
|
3784
|
+
? maybeComponents
|
|
3785
|
+
: undefined;
|
|
3786
|
+
}
|
|
3787
|
+
function resolveHostComponentMeta(metaInput, name, component) {
|
|
3788
|
+
const raw = typeof metaInput === 'function' ? metaInput(name, component) : metaInput;
|
|
3789
|
+
return raw && typeof raw === 'object' && !Array.isArray(raw)
|
|
3790
|
+
? normalizeExposeMeta(raw)
|
|
3791
|
+
: {};
|
|
3792
|
+
}
|
|
3774
3793
|
function registerHostComponents(input) {
|
|
3775
3794
|
const entries = normalizeNamedEntries(input, normalizeHostComponentEntry);
|
|
3776
3795
|
for (const { name, entry } of entries) {
|
|
@@ -3791,22 +3810,60 @@ function registerHostModules(input) {
|
|
|
3791
3810
|
}
|
|
3792
3811
|
return getAllHostModuleMeta();
|
|
3793
3812
|
}
|
|
3813
|
+
function registerVueGlobalComponents(VueRuntime, options = {}) {
|
|
3814
|
+
const source = options.source && typeof options.source === 'object' && !Array.isArray(options.source)
|
|
3815
|
+
? options.source
|
|
3816
|
+
: resolveVueGlobalComponentSource(VueRuntime);
|
|
3817
|
+
if (!source) {
|
|
3818
|
+
return getAllHostComponentMeta();
|
|
3819
|
+
}
|
|
3820
|
+
const registry = {};
|
|
3821
|
+
for (const [rawName, component] of Object.entries(source)) {
|
|
3822
|
+
const sourceName = String(rawName).trim();
|
|
3823
|
+
if (!sourceName || component == null) {
|
|
3824
|
+
continue;
|
|
3825
|
+
}
|
|
3826
|
+
if (typeof options.include === 'function' && !options.include(sourceName, component)) {
|
|
3827
|
+
continue;
|
|
3828
|
+
}
|
|
3829
|
+
const mappedName = typeof options.mapName === 'function' ? options.mapName(sourceName, component) : sourceName;
|
|
3830
|
+
const exposeName = typeof mappedName === 'string' ? mappedName.trim() : '';
|
|
3831
|
+
if (!exposeName) {
|
|
3832
|
+
continue;
|
|
3833
|
+
}
|
|
3834
|
+
registry[exposeName] = {
|
|
3835
|
+
component,
|
|
3836
|
+
...resolveHostComponentMeta(options.meta, sourceName, component)
|
|
3837
|
+
};
|
|
3838
|
+
}
|
|
3839
|
+
return registerHostComponents(registry);
|
|
3840
|
+
}
|
|
3794
3841
|
function getHostComponent(name) {
|
|
3795
3842
|
const key = typeof name === 'string' ? name.trim() : '';
|
|
3796
|
-
|
|
3843
|
+
if (!key) {
|
|
3844
|
+
return undefined;
|
|
3845
|
+
}
|
|
3846
|
+
const record = hostComponentsRegistry[key];
|
|
3847
|
+
return record ? record.value : undefined;
|
|
3797
3848
|
}
|
|
3798
3849
|
function getHostModule(name) {
|
|
3799
3850
|
const key = typeof name === 'string' ? name.trim() : '';
|
|
3800
|
-
|
|
3851
|
+
if (!key) {
|
|
3852
|
+
return undefined;
|
|
3853
|
+
}
|
|
3854
|
+
const record = hostModulesRegistry[key];
|
|
3855
|
+
return record ? record.value : undefined;
|
|
3801
3856
|
}
|
|
3802
3857
|
function getHostComponentMeta(name) {
|
|
3803
3858
|
const key = typeof name === 'string' ? name.trim() : '';
|
|
3804
|
-
const
|
|
3859
|
+
const record = key ? hostComponentsRegistry[key] : undefined;
|
|
3860
|
+
const meta = record ? record.meta : undefined;
|
|
3805
3861
|
return meta ? { ...meta } : undefined;
|
|
3806
3862
|
}
|
|
3807
3863
|
function getHostModuleMeta(name) {
|
|
3808
3864
|
const key = typeof name === 'string' ? name.trim() : '';
|
|
3809
|
-
const
|
|
3865
|
+
const record = key ? hostModulesRegistry[key] : undefined;
|
|
3866
|
+
const meta = record ? record.meta : undefined;
|
|
3810
3867
|
return meta ? { ...meta } : undefined;
|
|
3811
3868
|
}
|
|
3812
3869
|
function getAllHostComponentMeta() {
|
|
@@ -3910,7 +3967,7 @@ function resolveStaticManifestUrlForFetch(url, origin) {
|
|
|
3910
3967
|
const pathPart = u.startsWith('/') ? u : `/${u}`;
|
|
3911
3968
|
return new URL(pathPart, o).href;
|
|
3912
3969
|
}
|
|
3913
|
-
catch {
|
|
3970
|
+
catch (_a) {
|
|
3914
3971
|
return u;
|
|
3915
3972
|
}
|
|
3916
3973
|
}
|
|
@@ -4296,13 +4353,13 @@ function manifestFetchCacheMiddleware$1(options = {}) {
|
|
|
4296
4353
|
return structuredClone(r);
|
|
4297
4354
|
}
|
|
4298
4355
|
}
|
|
4299
|
-
catch {
|
|
4356
|
+
catch (_a) {
|
|
4300
4357
|
/* ignore */
|
|
4301
4358
|
}
|
|
4302
4359
|
try {
|
|
4303
4360
|
return JSON.parse(JSON.stringify(r));
|
|
4304
4361
|
}
|
|
4305
|
-
catch {
|
|
4362
|
+
catch (_b) {
|
|
4306
4363
|
return { ...r, data: r.data };
|
|
4307
4364
|
}
|
|
4308
4365
|
}
|
|
@@ -4340,7 +4397,7 @@ function manifestFetchCacheMiddleware$1(options = {}) {
|
|
|
4340
4397
|
}
|
|
4341
4398
|
return res;
|
|
4342
4399
|
}
|
|
4343
|
-
catch {
|
|
4400
|
+
catch (_a) {
|
|
4344
4401
|
return null;
|
|
4345
4402
|
}
|
|
4346
4403
|
}
|
|
@@ -4348,7 +4405,7 @@ function manifestFetchCacheMiddleware$1(options = {}) {
|
|
|
4348
4405
|
try {
|
|
4349
4406
|
store.setItem(key, JSON.stringify({ expiresAt, result }));
|
|
4350
4407
|
}
|
|
4351
|
-
catch {
|
|
4408
|
+
catch (_a) {
|
|
4352
4409
|
/* Quota / 不可序列化 */
|
|
4353
4410
|
}
|
|
4354
4411
|
}
|
|
@@ -4441,7 +4498,7 @@ function normalizeBridgePath(input) {
|
|
|
4441
4498
|
try {
|
|
4442
4499
|
return decodeURIComponent(normalized);
|
|
4443
4500
|
}
|
|
4444
|
-
catch {
|
|
4501
|
+
catch (_a) {
|
|
4445
4502
|
return normalized;
|
|
4446
4503
|
}
|
|
4447
4504
|
})();
|
|
@@ -4955,6 +5012,7 @@ exports.manifestFetchCacheMiddleware = manifestFetchCacheMiddleware;
|
|
|
4955
5012
|
exports.peerMinimumVersions = peerMinimumVersions;
|
|
4956
5013
|
exports.registerHostComponents = registerHostComponents;
|
|
4957
5014
|
exports.registerHostModules = registerHostModules;
|
|
5015
|
+
exports.registerVueGlobalComponents = registerVueGlobalComponents;
|
|
4958
5016
|
exports.registries = registries;
|
|
4959
5017
|
exports.resolveRuntimeOptions = resolveRuntimeOptions;
|
|
4960
5018
|
exports.routeSynthNamePrefix = routeSynthNamePrefix;
|