@meethive/vite 0.0.1 → 0.0.3
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/{src/federation/src/runtime/dynamic-remote.d.ts → dynamic-remote.d.ts} +25 -19
- package/dist/dynamic-remote.js +185 -0
- package/dist/dynamic-remote.mjs +163 -0
- package/dist/index.d.ts +51 -4
- package/dist/index.js +1 -20
- package/dist/index.mjs +1 -20
- package/dist/{src/federation/src/utils/semver/satisfy.d.ts → satisfy.d.ts} +2 -1
- package/dist/satisfy.js +381 -0
- package/dist/satisfy.mjs +381 -0
- package/package.json +20 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/src/federation/src/dev/expose-development.d.ts +0 -5
- package/dist/src/federation/src/dev/expose-development.d.ts.map +0 -1
- package/dist/src/federation/src/dev/remote-development.d.ts +0 -5
- package/dist/src/federation/src/dev/remote-development.d.ts.map +0 -1
- package/dist/src/federation/src/dev/shared-development.d.ts +0 -5
- package/dist/src/federation/src/dev/shared-development.d.ts.map +0 -1
- package/dist/src/federation/src/index.d.ts +0 -7
- package/dist/src/federation/src/index.d.ts.map +0 -1
- package/dist/src/federation/src/prod/expose-production.d.ts +0 -5
- package/dist/src/federation/src/prod/expose-production.d.ts.map +0 -1
- package/dist/src/federation/src/prod/remote-production.d.ts +0 -7
- package/dist/src/federation/src/prod/remote-production.d.ts.map +0 -1
- package/dist/src/federation/src/prod/shared-production.d.ts +0 -5
- package/dist/src/federation/src/prod/shared-production.d.ts.map +0 -1
- package/dist/src/federation/src/public.d.ts +0 -40
- package/dist/src/federation/src/public.d.ts.map +0 -1
- package/dist/src/federation/src/runtime/dynamic-remote.d.ts.map +0 -1
- package/dist/src/federation/src/utils/html.d.ts +0 -12
- package/dist/src/federation/src/utils/html.d.ts.map +0 -1
- package/dist/src/federation/src/utils/index.d.ts +0 -29
- package/dist/src/federation/src/utils/index.d.ts.map +0 -1
- package/dist/src/federation/src/utils/semver/compare.d.ts +0 -10
- package/dist/src/federation/src/utils/semver/compare.d.ts.map +0 -1
- package/dist/src/federation/src/utils/semver/constants.d.ts +0 -11
- package/dist/src/federation/src/utils/semver/constants.d.ts.map +0 -1
- package/dist/src/federation/src/utils/semver/parser.d.ts +0 -10
- package/dist/src/federation/src/utils/semver/parser.d.ts.map +0 -1
- package/dist/src/federation/src/utils/semver/satisfy.d.ts.map +0 -1
- package/dist/src/federation/src/utils/semver/utils.d.ts +0 -12
- package/dist/src/federation/src/utils/semver/utils.d.ts.map +0 -1
- package/dist/src/monaco-editor/index.d.ts +0 -35
- package/dist/src/monaco-editor/index.d.ts.map +0 -1
- package/dist/src/monaco-editor/languageWork.d.ts +0 -10
- package/dist/src/monaco-editor/languageWork.d.ts.map +0 -1
- package/dist/src/monaco-editor/workerMiddleware.d.ts +0 -9
- package/dist/src/monaco-editor/workerMiddleware.d.ts.map +0 -1
- package/dist/src/sharp/index.d.ts +0 -12
- package/dist/src/sharp/index.d.ts.map +0 -1
- package/index.ts +0 -3
- package/src/federation/src/dev/expose-development.ts +0 -29
- package/src/federation/src/dev/remote-development.ts +0 -435
- package/src/federation/src/dev/shared-development.ts +0 -29
- package/src/federation/src/index.ts +0 -242
- package/src/federation/src/prod/expose-production.ts +0 -333
- package/src/federation/src/prod/federation_fn_import.js +0 -75
- package/src/federation/src/prod/remote-production.ts +0 -658
- package/src/federation/src/prod/shared-production.ts +0 -268
- package/src/federation/src/public.ts +0 -54
- package/src/federation/src/runtime/dynamic-remote.ts +0 -247
- package/src/federation/src/utils/html.ts +0 -165
- package/src/federation/src/utils/index.ts +0 -255
- package/src/federation/src/utils/semver/compare.ts +0 -131
- package/src/federation/src/utils/semver/constants.ts +0 -46
- package/src/federation/src/utils/semver/parser.ts +0 -253
- package/src/federation/src/utils/semver/satisfy.ts +0 -151
- package/src/federation/src/utils/semver/utils.ts +0 -93
- package/src/federation/types/dynamic-remote.d.ts +0 -105
- package/src/federation/types/index.d.ts +0 -344
- package/src/federation/types/pluginHooks.d.ts +0 -4
- package/src/federation/types/virtual-modules.d.ts +0 -48
- package/src/federation/types/viteDevServer.d.ts +0 -22
- package/src/monaco-editor/index.ts +0 -205
- package/src/monaco-editor/languageWork.ts +0 -36
- package/src/monaco-editor/workerMiddleware.ts +0 -78
- package/src/sharp/index.ts +0 -93
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Dynamic remote loader for runtime
|
|
3
|
-
* Provides utilities to dynamically load and manage remote components at runtime
|
|
4
|
-
*/
|
|
5
|
-
export interface RemoteOptions {
|
|
6
|
-
url: string | (() => string | Promise<string>);
|
|
7
|
-
format?: 'esm' | 'systemjs' | 'var';
|
|
8
|
-
from?: 'vite' | 'webpack';
|
|
9
|
-
shareScope?: string;
|
|
10
|
-
external?: string | string[];
|
|
11
|
-
externalType?: 'url' | 'promise';
|
|
12
|
-
}
|
|
13
|
-
export interface RemoteComponentConfig {
|
|
14
|
-
name: string;
|
|
15
|
-
component: string;
|
|
16
|
-
url: string | (() => string | Promise<string>);
|
|
17
|
-
options?: RemoteOptions;
|
|
18
|
-
}
|
|
19
1
|
/**
|
|
20
2
|
* Dynamic remote component manager
|
|
21
3
|
*/
|
|
@@ -59,12 +41,35 @@ export declare class DynamicRemoteManager {
|
|
|
59
41
|
*/
|
|
60
42
|
isRemoteComponentCached(remoteName: string, componentName: string): boolean;
|
|
61
43
|
}
|
|
44
|
+
|
|
62
45
|
export declare const dynamicRemoteManager: DynamicRemoteManager;
|
|
46
|
+
|
|
63
47
|
/**
|
|
64
48
|
* Convenience function to dynamically load remote component
|
|
65
49
|
* @param config Remote component configuration
|
|
66
50
|
*/
|
|
67
51
|
export declare function loadDynamicRemoteComponent(config: RemoteComponentConfig): Promise<any>;
|
|
52
|
+
|
|
53
|
+
export declare interface RemoteComponentConfig {
|
|
54
|
+
name: string;
|
|
55
|
+
component: string;
|
|
56
|
+
url: string | (() => string | Promise<string>);
|
|
57
|
+
options?: RemoteOptions;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Dynamic remote loader for runtime
|
|
62
|
+
* Provides utilities to dynamically load and manage remote components at runtime
|
|
63
|
+
*/
|
|
64
|
+
export declare interface RemoteOptions {
|
|
65
|
+
url: string | (() => string | Promise<string>);
|
|
66
|
+
format?: 'esm' | 'systemjs' | 'var';
|
|
67
|
+
from?: 'vite' | 'webpack';
|
|
68
|
+
shareScope?: string;
|
|
69
|
+
external?: string | string[];
|
|
70
|
+
externalType?: 'url' | 'promise';
|
|
71
|
+
}
|
|
72
|
+
|
|
68
73
|
/**
|
|
69
74
|
* Vue 3 composable for dynamic remote loading
|
|
70
75
|
* @param remoteName Remote name
|
|
@@ -76,4 +81,5 @@ export declare function useDynamicRemote(remoteName: string, componentName: stri
|
|
|
76
81
|
error: any;
|
|
77
82
|
reload: () => Promise<void>;
|
|
78
83
|
};
|
|
79
|
-
|
|
84
|
+
|
|
85
|
+
export { }
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
25
|
+
class DynamicRemoteManager {
|
|
26
|
+
remoteCache = /* @__PURE__ */ new Map();
|
|
27
|
+
loadingPromises = /* @__PURE__ */ new Map();
|
|
28
|
+
/**
|
|
29
|
+
* Add a remote dynamically at runtime
|
|
30
|
+
* @param name Remote name
|
|
31
|
+
* @param config Remote configuration
|
|
32
|
+
*/
|
|
33
|
+
async addRemote(name, config) {
|
|
34
|
+
try {
|
|
35
|
+
const federationModule = await import("virtual:__federation__");
|
|
36
|
+
const { __federation_method_add_origin_setRemote } = federationModule;
|
|
37
|
+
await __federation_method_add_origin_setRemote(name, config.url, {
|
|
38
|
+
format: config.format || "esm",
|
|
39
|
+
from: config.from || "vite",
|
|
40
|
+
shareScope: config.shareScope || "default",
|
|
41
|
+
external: config.external,
|
|
42
|
+
externalType: config.externalType || "url"
|
|
43
|
+
});
|
|
44
|
+
} catch (error) {
|
|
45
|
+
throw new Error(`Failed to add dynamic remote '${name}': ${error.message}. Make sure to enable dynamic remotes in your plugin configuration with 'enableDynamicRemotes: true'.`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Load a remote component dynamically
|
|
50
|
+
* @param remoteName Remote name
|
|
51
|
+
* @param componentName Component name to load from remote
|
|
52
|
+
* @returns Promise of the loaded component
|
|
53
|
+
*/
|
|
54
|
+
async loadRemoteComponent(remoteName, componentName) {
|
|
55
|
+
const cacheKey = `${remoteName}/${componentName}`;
|
|
56
|
+
if (this.remoteCache.has(cacheKey)) {
|
|
57
|
+
return this.remoteCache.get(cacheKey);
|
|
58
|
+
}
|
|
59
|
+
if (this.loadingPromises.has(cacheKey)) {
|
|
60
|
+
return this.loadingPromises.get(cacheKey);
|
|
61
|
+
}
|
|
62
|
+
const loadingPromise = this.doLoadRemoteComponent(remoteName, componentName);
|
|
63
|
+
this.loadingPromises.set(cacheKey, loadingPromise);
|
|
64
|
+
try {
|
|
65
|
+
const component = await loadingPromise;
|
|
66
|
+
this.remoteCache.set(cacheKey, component);
|
|
67
|
+
return component;
|
|
68
|
+
} finally {
|
|
69
|
+
this.loadingPromises.delete(cacheKey);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async doLoadRemoteComponent(remoteName, componentName) {
|
|
73
|
+
try {
|
|
74
|
+
const federationModule = await import("virtual:__federation__");
|
|
75
|
+
const { __federation_method_getRemote } = federationModule;
|
|
76
|
+
return __federation_method_getRemote(remoteName, componentName);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
throw new Error(`Failed to load remote component '${remoteName}/${componentName}': ${error.message}. Make sure to enable dynamic remotes in your plugin configuration with 'enableDynamicRemotes: true'.`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Preload a remote component
|
|
83
|
+
* @param remoteName Remote name
|
|
84
|
+
* @param componentName Component name
|
|
85
|
+
*/
|
|
86
|
+
async preloadRemoteComponent(remoteName, componentName) {
|
|
87
|
+
try {
|
|
88
|
+
await this.loadRemoteComponent(remoteName, componentName);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.warn(`Failed to preload remote component ${remoteName}/${componentName}:`, error);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Remove a remote component from cache
|
|
95
|
+
* @param remoteName Remote name
|
|
96
|
+
* @param componentName Component name
|
|
97
|
+
*/
|
|
98
|
+
clearRemoteComponentCache(remoteName, componentName) {
|
|
99
|
+
if (componentName) {
|
|
100
|
+
const cacheKey = `${remoteName}/${componentName}`;
|
|
101
|
+
this.remoteCache.delete(cacheKey);
|
|
102
|
+
} else {
|
|
103
|
+
for (const key of this.remoteCache.keys()) {
|
|
104
|
+
if (key.startsWith(`${remoteName}/`)) {
|
|
105
|
+
this.remoteCache.delete(key);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get all cached remote components
|
|
112
|
+
*/
|
|
113
|
+
getCachedRemotes() {
|
|
114
|
+
return Array.from(this.remoteCache.keys());
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Check if a remote component is cached
|
|
118
|
+
* @param remoteName Remote name
|
|
119
|
+
* @param componentName Component name
|
|
120
|
+
*/
|
|
121
|
+
isRemoteComponentCached(remoteName, componentName) {
|
|
122
|
+
const cacheKey = `${remoteName}/${componentName}`;
|
|
123
|
+
return this.remoteCache.has(cacheKey);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const dynamicRemoteManager = new DynamicRemoteManager();
|
|
127
|
+
async function loadDynamicRemoteComponent(config) {
|
|
128
|
+
if (config.options) {
|
|
129
|
+
await dynamicRemoteManager.addRemote(config.name, {
|
|
130
|
+
url: config.url,
|
|
131
|
+
...config.options
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
return dynamicRemoteManager.loadRemoteComponent(config.name, config.component);
|
|
135
|
+
}
|
|
136
|
+
function useDynamicRemote(remoteName, componentName) {
|
|
137
|
+
const loading = ref(true);
|
|
138
|
+
const error = ref(null);
|
|
139
|
+
const component = ref(null);
|
|
140
|
+
const loadComponent = async () => {
|
|
141
|
+
try {
|
|
142
|
+
loading.value = true;
|
|
143
|
+
error.value = null;
|
|
144
|
+
component.value = await dynamicRemoteManager.loadRemoteComponent(remoteName, componentName);
|
|
145
|
+
} catch (err) {
|
|
146
|
+
error.value = err instanceof Error ? err : new Error("Failed to load remote component");
|
|
147
|
+
console.error(`Failed to load remote component ${remoteName}/${componentName}:`, err);
|
|
148
|
+
} finally {
|
|
149
|
+
loading.value = false;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
onMounted(() => {
|
|
153
|
+
loadComponent();
|
|
154
|
+
});
|
|
155
|
+
return {
|
|
156
|
+
component: readonly(component),
|
|
157
|
+
loading: readonly(loading),
|
|
158
|
+
error: readonly(error),
|
|
159
|
+
reload: loadComponent
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function isVueAvailable() {
|
|
163
|
+
try {
|
|
164
|
+
return typeof ref !== "undefined" && typeof onMounted !== "undefined";
|
|
165
|
+
} catch {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
let ref, onMounted, readonly;
|
|
170
|
+
if (isVueAvailable()) {
|
|
171
|
+
try {
|
|
172
|
+
import("vue").then((vue) => {
|
|
173
|
+
ref = vue.ref;
|
|
174
|
+
onMounted = vue.onMounted;
|
|
175
|
+
readonly = vue.readonly;
|
|
176
|
+
}).catch(() => {
|
|
177
|
+
console.warn("Vue not available for dynamic import");
|
|
178
|
+
});
|
|
179
|
+
} catch {
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
exports.DynamicRemoteManager = DynamicRemoteManager;
|
|
183
|
+
exports.dynamicRemoteManager = dynamicRemoteManager;
|
|
184
|
+
exports.loadDynamicRemoteComponent = loadDynamicRemoteComponent;
|
|
185
|
+
exports.useDynamicRemote = useDynamicRemote;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
class DynamicRemoteManager {
|
|
2
|
+
remoteCache = /* @__PURE__ */ new Map();
|
|
3
|
+
loadingPromises = /* @__PURE__ */ new Map();
|
|
4
|
+
/**
|
|
5
|
+
* Add a remote dynamically at runtime
|
|
6
|
+
* @param name Remote name
|
|
7
|
+
* @param config Remote configuration
|
|
8
|
+
*/
|
|
9
|
+
async addRemote(name, config) {
|
|
10
|
+
try {
|
|
11
|
+
const federationModule = await import("virtual:__federation__");
|
|
12
|
+
const { __federation_method_add_origin_setRemote } = federationModule;
|
|
13
|
+
await __federation_method_add_origin_setRemote(name, config.url, {
|
|
14
|
+
format: config.format || "esm",
|
|
15
|
+
from: config.from || "vite",
|
|
16
|
+
shareScope: config.shareScope || "default",
|
|
17
|
+
external: config.external,
|
|
18
|
+
externalType: config.externalType || "url"
|
|
19
|
+
});
|
|
20
|
+
} catch (error) {
|
|
21
|
+
throw new Error(`Failed to add dynamic remote '${name}': ${error.message}. Make sure to enable dynamic remotes in your plugin configuration with 'enableDynamicRemotes: true'.`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Load a remote component dynamically
|
|
26
|
+
* @param remoteName Remote name
|
|
27
|
+
* @param componentName Component name to load from remote
|
|
28
|
+
* @returns Promise of the loaded component
|
|
29
|
+
*/
|
|
30
|
+
async loadRemoteComponent(remoteName, componentName) {
|
|
31
|
+
const cacheKey = `${remoteName}/${componentName}`;
|
|
32
|
+
if (this.remoteCache.has(cacheKey)) {
|
|
33
|
+
return this.remoteCache.get(cacheKey);
|
|
34
|
+
}
|
|
35
|
+
if (this.loadingPromises.has(cacheKey)) {
|
|
36
|
+
return this.loadingPromises.get(cacheKey);
|
|
37
|
+
}
|
|
38
|
+
const loadingPromise = this.doLoadRemoteComponent(remoteName, componentName);
|
|
39
|
+
this.loadingPromises.set(cacheKey, loadingPromise);
|
|
40
|
+
try {
|
|
41
|
+
const component = await loadingPromise;
|
|
42
|
+
this.remoteCache.set(cacheKey, component);
|
|
43
|
+
return component;
|
|
44
|
+
} finally {
|
|
45
|
+
this.loadingPromises.delete(cacheKey);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async doLoadRemoteComponent(remoteName, componentName) {
|
|
49
|
+
try {
|
|
50
|
+
const federationModule = await import("virtual:__federation__");
|
|
51
|
+
const { __federation_method_getRemote } = federationModule;
|
|
52
|
+
return __federation_method_getRemote(remoteName, componentName);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
throw new Error(`Failed to load remote component '${remoteName}/${componentName}': ${error.message}. Make sure to enable dynamic remotes in your plugin configuration with 'enableDynamicRemotes: true'.`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Preload a remote component
|
|
59
|
+
* @param remoteName Remote name
|
|
60
|
+
* @param componentName Component name
|
|
61
|
+
*/
|
|
62
|
+
async preloadRemoteComponent(remoteName, componentName) {
|
|
63
|
+
try {
|
|
64
|
+
await this.loadRemoteComponent(remoteName, componentName);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.warn(`Failed to preload remote component ${remoteName}/${componentName}:`, error);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Remove a remote component from cache
|
|
71
|
+
* @param remoteName Remote name
|
|
72
|
+
* @param componentName Component name
|
|
73
|
+
*/
|
|
74
|
+
clearRemoteComponentCache(remoteName, componentName) {
|
|
75
|
+
if (componentName) {
|
|
76
|
+
const cacheKey = `${remoteName}/${componentName}`;
|
|
77
|
+
this.remoteCache.delete(cacheKey);
|
|
78
|
+
} else {
|
|
79
|
+
for (const key of this.remoteCache.keys()) {
|
|
80
|
+
if (key.startsWith(`${remoteName}/`)) {
|
|
81
|
+
this.remoteCache.delete(key);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get all cached remote components
|
|
88
|
+
*/
|
|
89
|
+
getCachedRemotes() {
|
|
90
|
+
return Array.from(this.remoteCache.keys());
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Check if a remote component is cached
|
|
94
|
+
* @param remoteName Remote name
|
|
95
|
+
* @param componentName Component name
|
|
96
|
+
*/
|
|
97
|
+
isRemoteComponentCached(remoteName, componentName) {
|
|
98
|
+
const cacheKey = `${remoteName}/${componentName}`;
|
|
99
|
+
return this.remoteCache.has(cacheKey);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const dynamicRemoteManager = new DynamicRemoteManager();
|
|
103
|
+
async function loadDynamicRemoteComponent(config) {
|
|
104
|
+
if (config.options) {
|
|
105
|
+
await dynamicRemoteManager.addRemote(config.name, {
|
|
106
|
+
url: config.url,
|
|
107
|
+
...config.options
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return dynamicRemoteManager.loadRemoteComponent(config.name, config.component);
|
|
111
|
+
}
|
|
112
|
+
function useDynamicRemote(remoteName, componentName) {
|
|
113
|
+
const loading = ref(true);
|
|
114
|
+
const error = ref(null);
|
|
115
|
+
const component = ref(null);
|
|
116
|
+
const loadComponent = async () => {
|
|
117
|
+
try {
|
|
118
|
+
loading.value = true;
|
|
119
|
+
error.value = null;
|
|
120
|
+
component.value = await dynamicRemoteManager.loadRemoteComponent(remoteName, componentName);
|
|
121
|
+
} catch (err) {
|
|
122
|
+
error.value = err instanceof Error ? err : new Error("Failed to load remote component");
|
|
123
|
+
console.error(`Failed to load remote component ${remoteName}/${componentName}:`, err);
|
|
124
|
+
} finally {
|
|
125
|
+
loading.value = false;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
onMounted(() => {
|
|
129
|
+
loadComponent();
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
component: readonly(component),
|
|
133
|
+
loading: readonly(loading),
|
|
134
|
+
error: readonly(error),
|
|
135
|
+
reload: loadComponent
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function isVueAvailable() {
|
|
139
|
+
try {
|
|
140
|
+
return typeof ref !== "undefined" && typeof onMounted !== "undefined";
|
|
141
|
+
} catch {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
let ref, onMounted, readonly;
|
|
146
|
+
if (isVueAvailable()) {
|
|
147
|
+
try {
|
|
148
|
+
import("vue").then((vue) => {
|
|
149
|
+
ref = vue.ref;
|
|
150
|
+
onMounted = vue.onMounted;
|
|
151
|
+
readonly = vue.readonly;
|
|
152
|
+
}).catch(() => {
|
|
153
|
+
console.warn("Vue not available for dynamic import");
|
|
154
|
+
});
|
|
155
|
+
} catch {
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
export {
|
|
159
|
+
DynamicRemoteManager,
|
|
160
|
+
dynamicRemoteManager,
|
|
161
|
+
loadDynamicRemoteComponent,
|
|
162
|
+
useDynamicRemote
|
|
163
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
import { VitePluginFederationOptions } from '../types';
|
|
3
|
+
|
|
4
|
+
declare type EditorLanguageWorks = 'css' | 'html' | 'json' | 'typescript' | 'editorWorkerService';
|
|
5
|
+
|
|
6
|
+
export declare function federation(options: VitePluginFederationOptions): Plugin;
|
|
7
|
+
|
|
8
|
+
declare interface IMonacoEditorOpts {
|
|
9
|
+
/**
|
|
10
|
+
* include only a subset of the languageWorkers supported.
|
|
11
|
+
*/
|
|
12
|
+
languageWorkers?: EditorLanguageWorks[];
|
|
13
|
+
customWorkers?: IWorkerDefinition[];
|
|
14
|
+
/**
|
|
15
|
+
* Override the public path from which files generated by this plugin will be served.
|
|
16
|
+
* This wins out over Webpack's dynamic runtime path and can be useful to avoid attempting to load workers cross-
|
|
17
|
+
* origin when using a CDN for other static resources.
|
|
18
|
+
* Use e.g. '/' if you want to load your resources from the current origin.
|
|
19
|
+
*/
|
|
20
|
+
publicPath?: string;
|
|
21
|
+
customDistPath?: (root: string, buildOutDir: string, base: string) => string;
|
|
22
|
+
forceBuildCDN?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Specify whether the editor API should be exposed through a global `monaco` object or not. This
|
|
25
|
+
* option is applicable to `0.22.0` and newer version of `monaco-editor`. Since `0.22.0`, the ESM
|
|
26
|
+
* version of the monaco editor does no longer define a global `monaco` object unless
|
|
27
|
+
* `global.MonacoEnvironment = { globalAPI: true }` is set ([change
|
|
28
|
+
* log](https://github.com/microsoft/monaco-editor/blob/main/CHANGELOG.md#0220-29012021)).
|
|
29
|
+
*/
|
|
30
|
+
globalAPI?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare interface IWorkerDefinition {
|
|
34
|
+
label: string;
|
|
35
|
+
entry: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export declare function monacoEditorPlugin(options: IMonacoEditorOpts): Plugin;
|
|
39
|
+
|
|
40
|
+
export declare function sharpOptimize(options?: SharpOptimizeOptions): Plugin;
|
|
41
|
+
|
|
42
|
+
declare type SharpOptimizeOptions = {
|
|
43
|
+
include?: (string | RegExp)[];
|
|
44
|
+
exclude?: (string | RegExp)[];
|
|
45
|
+
jpegQuality?: number;
|
|
46
|
+
pngQuality?: number;
|
|
47
|
+
webpQuality?: number;
|
|
48
|
+
avifQuality?: number;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { }
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ const MagicString = require("magic-string");
|
|
|
29
29
|
const path$1 = require("node:path");
|
|
30
30
|
const fs = require("fs");
|
|
31
31
|
require("crypto");
|
|
32
|
+
require("./dynamic-remote.js");
|
|
32
33
|
const esbuild = require("esbuild");
|
|
33
34
|
const EXPOSES_MAP = /* @__PURE__ */ new Map();
|
|
34
35
|
const EXPOSES_KEY_MAP = /* @__PURE__ */ new Map();
|
|
@@ -1652,26 +1653,6 @@ function devExposePlugin(options) {
|
|
|
1652
1653
|
name: "originjs:expose-development"
|
|
1653
1654
|
};
|
|
1654
1655
|
}
|
|
1655
|
-
function isVueAvailable() {
|
|
1656
|
-
try {
|
|
1657
|
-
return typeof ref !== "undefined" && typeof onMounted !== "undefined";
|
|
1658
|
-
} catch {
|
|
1659
|
-
return false;
|
|
1660
|
-
}
|
|
1661
|
-
}
|
|
1662
|
-
let ref, onMounted, readonly;
|
|
1663
|
-
if (isVueAvailable()) {
|
|
1664
|
-
try {
|
|
1665
|
-
import("vue").then((vue) => {
|
|
1666
|
-
ref = vue.ref;
|
|
1667
|
-
onMounted = vue.onMounted;
|
|
1668
|
-
readonly = vue.readonly;
|
|
1669
|
-
}).catch(() => {
|
|
1670
|
-
console.warn("Vue not available for dynamic import");
|
|
1671
|
-
});
|
|
1672
|
-
} catch {
|
|
1673
|
-
}
|
|
1674
|
-
}
|
|
1675
1656
|
const normalizeAssetsDir = (config) => {
|
|
1676
1657
|
const configured = config?.build?.assetsDir ?? "assets";
|
|
1677
1658
|
if (!configured) return "";
|
package/dist/index.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import MagicString from "magic-string";
|
|
|
5
5
|
import path$1 from "node:path";
|
|
6
6
|
import { readFileSync, statSync, readdirSync, existsSync, rmSync } from "fs";
|
|
7
7
|
import "crypto";
|
|
8
|
+
import "./dynamic-remote.mjs";
|
|
8
9
|
import { buildSync } from "esbuild";
|
|
9
10
|
const EXPOSES_MAP = /* @__PURE__ */ new Map();
|
|
10
11
|
const EXPOSES_KEY_MAP = /* @__PURE__ */ new Map();
|
|
@@ -1628,26 +1629,6 @@ function devExposePlugin(options) {
|
|
|
1628
1629
|
name: "originjs:expose-development"
|
|
1629
1630
|
};
|
|
1630
1631
|
}
|
|
1631
|
-
function isVueAvailable() {
|
|
1632
|
-
try {
|
|
1633
|
-
return typeof ref !== "undefined" && typeof onMounted !== "undefined";
|
|
1634
|
-
} catch {
|
|
1635
|
-
return false;
|
|
1636
|
-
}
|
|
1637
|
-
}
|
|
1638
|
-
let ref, onMounted, readonly;
|
|
1639
|
-
if (isVueAvailable()) {
|
|
1640
|
-
try {
|
|
1641
|
-
import("vue").then((vue) => {
|
|
1642
|
-
ref = vue.ref;
|
|
1643
|
-
onMounted = vue.onMounted;
|
|
1644
|
-
readonly = vue.readonly;
|
|
1645
|
-
}).catch(() => {
|
|
1646
|
-
console.warn("Vue not available for dynamic import");
|
|
1647
|
-
});
|
|
1648
|
-
} catch {
|
|
1649
|
-
}
|
|
1650
|
-
}
|
|
1651
1632
|
const normalizeAssetsDir = (config) => {
|
|
1652
1633
|
const configured = config?.build?.assetsDir ?? "assets";
|
|
1653
1634
|
if (!configured) return "";
|