@meethive/vite 0.0.1 → 0.0.2
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/dynamic-remote.d.ts +2 -0
- package/dist/dynamic-remote.js +185 -0
- package/dist/dynamic-remote.mjs +163 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +9 -325
- package/dist/index.mjs +9 -303
- package/dist/satisfy.d.ts +2 -0
- 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 +0 -79
- 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 +0 -2
- 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
package/dist/index.js
CHANGED
|
@@ -1,27 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
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" });
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
25
3
|
const virtual = require("@rollup/plugin-virtual");
|
|
26
4
|
const path = require("path");
|
|
27
5
|
const estreeWalker = require("estree-walker");
|
|
@@ -29,13 +7,14 @@ const MagicString = require("magic-string");
|
|
|
29
7
|
const path$1 = require("node:path");
|
|
30
8
|
const fs = require("fs");
|
|
31
9
|
require("crypto");
|
|
32
|
-
const
|
|
10
|
+
const dynamicRemote = require("./dynamic-remote.js");
|
|
33
11
|
const EXPOSES_MAP = /* @__PURE__ */ new Map();
|
|
34
12
|
const EXPOSES_KEY_MAP = /* @__PURE__ */ new Map();
|
|
35
13
|
const SHARED = "shared";
|
|
36
14
|
const DYNAMIC_LOADING_CSS = "dynamicLoadingCss";
|
|
37
15
|
const DYNAMIC_LOADING_CSS_PREFIX = "__v__css__";
|
|
38
16
|
const DEFAULT_ENTRY_FILENAME = "remoteEntry.js";
|
|
17
|
+
const VitePluginFederationVersion = "1.5.0";
|
|
39
18
|
const builderInfo = {
|
|
40
19
|
builder: "rollup",
|
|
41
20
|
assetsDir: "",
|
|
@@ -1652,26 +1631,6 @@ function devExposePlugin(options) {
|
|
|
1652
1631
|
name: "originjs:expose-development"
|
|
1653
1632
|
};
|
|
1654
1633
|
}
|
|
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
1634
|
const normalizeAssetsDir = (config) => {
|
|
1676
1635
|
const configured = config?.build?.assetsDir ?? "assets";
|
|
1677
1636
|
if (!configured) return "";
|
|
@@ -1835,284 +1794,9 @@ function federation(options) {
|
|
|
1835
1794
|
}
|
|
1836
1795
|
};
|
|
1837
1796
|
}
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
label: "css",
|
|
1845
|
-
entry: "monaco-editor/esm/vs/language/css/css.worker"
|
|
1846
|
-
},
|
|
1847
|
-
{
|
|
1848
|
-
label: "html",
|
|
1849
|
-
entry: "monaco-editor/esm/vs/language/html/html.worker"
|
|
1850
|
-
},
|
|
1851
|
-
{
|
|
1852
|
-
label: "json",
|
|
1853
|
-
entry: "monaco-editor/esm/vs/language/json/json.worker"
|
|
1854
|
-
},
|
|
1855
|
-
{
|
|
1856
|
-
label: "typescript",
|
|
1857
|
-
entry: "monaco-editor/esm/vs/language/typescript/ts.worker"
|
|
1858
|
-
}
|
|
1859
|
-
];
|
|
1860
|
-
const languageWorksByLabel = {};
|
|
1861
|
-
languageWorkAttr.forEach(
|
|
1862
|
-
(languageWork) => languageWorksByLabel[languageWork.label] = languageWork
|
|
1863
|
-
);
|
|
1864
|
-
function getFilenameByEntry(entry) {
|
|
1865
|
-
entry = path.basename(entry, "js");
|
|
1866
|
-
return entry + ".bundle.js";
|
|
1867
|
-
}
|
|
1868
|
-
const cacheDir = "node_modules/.monaco/";
|
|
1869
|
-
function getWorkPath(works, options, config) {
|
|
1870
|
-
const workerPaths = {};
|
|
1871
|
-
for (const work of works) {
|
|
1872
|
-
if (isCDN(options.publicPath)) {
|
|
1873
|
-
workerPaths[work.label] = options.publicPath + "/" + getFilenameByEntry(work.entry);
|
|
1874
|
-
} else {
|
|
1875
|
-
workerPaths[work.label] = config.base + options.publicPath + "/" + getFilenameByEntry(work.entry);
|
|
1876
|
-
}
|
|
1877
|
-
}
|
|
1878
|
-
if (workerPaths["typescript"]) {
|
|
1879
|
-
workerPaths["javascript"] = workerPaths["typescript"];
|
|
1880
|
-
}
|
|
1881
|
-
if (workerPaths["css"]) {
|
|
1882
|
-
workerPaths["less"] = workerPaths["css"];
|
|
1883
|
-
workerPaths["scss"] = workerPaths["css"];
|
|
1884
|
-
}
|
|
1885
|
-
if (workerPaths["html"]) {
|
|
1886
|
-
workerPaths["handlebars"] = workerPaths["html"];
|
|
1887
|
-
workerPaths["razor"] = workerPaths["html"];
|
|
1888
|
-
}
|
|
1889
|
-
return workerPaths;
|
|
1890
|
-
}
|
|
1891
|
-
function workerMiddleware(middlewares, config, options) {
|
|
1892
|
-
const works = getWorks(options);
|
|
1893
|
-
if (fs.existsSync(cacheDir)) {
|
|
1894
|
-
fs.rmSync(cacheDir, { recursive: true, force: true });
|
|
1895
|
-
}
|
|
1896
|
-
for (const work of works) {
|
|
1897
|
-
middlewares.use(
|
|
1898
|
-
config.base + options.publicPath + "/" + getFilenameByEntry(work.entry),
|
|
1899
|
-
function(req, res, next) {
|
|
1900
|
-
if (!fs.existsSync(cacheDir + getFilenameByEntry(work.entry))) {
|
|
1901
|
-
esbuild.buildSync({
|
|
1902
|
-
entryPoints: [resolveMonacoPath(work.entry)],
|
|
1903
|
-
bundle: true,
|
|
1904
|
-
outfile: cacheDir + getFilenameByEntry(work.entry)
|
|
1905
|
-
});
|
|
1906
|
-
}
|
|
1907
|
-
const contentBuffer = fs.readFileSync(cacheDir + getFilenameByEntry(work.entry));
|
|
1908
|
-
res.setHeader("Content-Type", "text/javascript");
|
|
1909
|
-
res.end(contentBuffer);
|
|
1910
|
-
}
|
|
1911
|
-
);
|
|
1912
|
-
}
|
|
1913
|
-
}
|
|
1914
|
-
function resolveMonacoPath(filePath) {
|
|
1915
|
-
try {
|
|
1916
|
-
return path.resolve(path.join(process.cwd(), "node_modules", filePath));
|
|
1917
|
-
} catch (err) {
|
|
1918
|
-
return path.resolve(filePath);
|
|
1919
|
-
}
|
|
1920
|
-
}
|
|
1921
|
-
function getWorks(options) {
|
|
1922
|
-
let works = options.languageWorkers.map(
|
|
1923
|
-
(work) => languageWorksByLabel[work]
|
|
1924
|
-
);
|
|
1925
|
-
works.push(...options.customWorkers);
|
|
1926
|
-
return works;
|
|
1927
|
-
}
|
|
1928
|
-
const getFS = async () => {
|
|
1929
|
-
if (typeof process !== "undefined" && process.versions?.node) {
|
|
1930
|
-
const fs2 = await import("fs");
|
|
1931
|
-
return {
|
|
1932
|
-
existsSync: fs2.existsSync,
|
|
1933
|
-
mkdirSync: fs2.mkdirSync,
|
|
1934
|
-
readFileSync: fs2.readFileSync,
|
|
1935
|
-
writeFileSync: fs2.writeFileSync
|
|
1936
|
-
};
|
|
1937
|
-
}
|
|
1938
|
-
return null;
|
|
1939
|
-
};
|
|
1940
|
-
function monacoEditorPlugin(options) {
|
|
1941
|
-
const languageWorkers = options.languageWorkers || Object.keys(languageWorksByLabel);
|
|
1942
|
-
const publicPath = options.publicPath || "monacoeditorwork";
|
|
1943
|
-
const globalAPI = options.globalAPI || false;
|
|
1944
|
-
const customWorkers = options.customWorkers || [];
|
|
1945
|
-
const forceBuildCDN = options.forceBuildCDN || false;
|
|
1946
|
-
options = {
|
|
1947
|
-
...options,
|
|
1948
|
-
languageWorkers,
|
|
1949
|
-
publicPath,
|
|
1950
|
-
globalAPI,
|
|
1951
|
-
customWorkers,
|
|
1952
|
-
forceBuildCDN
|
|
1953
|
-
};
|
|
1954
|
-
let resolvedConfig;
|
|
1955
|
-
return {
|
|
1956
|
-
name: "vite-plugin-monaco-editor",
|
|
1957
|
-
configResolved(getResolvedConfig) {
|
|
1958
|
-
resolvedConfig = getResolvedConfig;
|
|
1959
|
-
},
|
|
1960
|
-
configureServer(server) {
|
|
1961
|
-
if (isCDN(publicPath)) {
|
|
1962
|
-
return;
|
|
1963
|
-
}
|
|
1964
|
-
workerMiddleware(server.middlewares, resolvedConfig, options);
|
|
1965
|
-
},
|
|
1966
|
-
transformIndexHtml(html) {
|
|
1967
|
-
const works = getWorks(options);
|
|
1968
|
-
const workerPaths = getWorkPath(works, options, resolvedConfig);
|
|
1969
|
-
const globals = {
|
|
1970
|
-
MonacoEnvironment: `(function (paths) {
|
|
1971
|
-
return {
|
|
1972
|
-
globalAPI: ${globalAPI},
|
|
1973
|
-
getWorkerUrl : function (moduleId, label) {
|
|
1974
|
-
var result = paths[label];
|
|
1975
|
-
var _location = window.__MICRO_APP_ENVIRONMENT__ ? window.rawWindow.location : window.location;
|
|
1976
|
-
var currentUrl = String(_location);
|
|
1977
|
-
var currentOrigin = currentUrl.substr(0, currentUrl.length - _location.hash.length - _location.search.length - _location.pathname.length);
|
|
1978
|
-
|
|
1979
|
-
if (window.__MICRO_APP_ENVIRONMENT__) {
|
|
1980
|
-
result = currentOrigin + result.replace('./', '/')
|
|
1981
|
-
}
|
|
1982
|
-
|
|
1983
|
-
if (/^((http:)|(https:)|(file:)|(\\/\\/))/.test(result)) {
|
|
1984
|
-
if (result.substring(0, currentOrigin.length) !== currentOrigin) {
|
|
1985
|
-
var js = '/*' + label + '*/importScripts("' + result + '");';
|
|
1986
|
-
var blob = new Blob([js], { type: 'application/javascript' });
|
|
1987
|
-
return URL.createObjectURL(blob);
|
|
1988
|
-
}
|
|
1989
|
-
}
|
|
1990
|
-
console.log('result',result);
|
|
1991
|
-
return result;
|
|
1992
|
-
}
|
|
1993
|
-
};
|
|
1994
|
-
})(${JSON.stringify(workerPaths, null, 2)})`
|
|
1995
|
-
};
|
|
1996
|
-
const descriptor = [
|
|
1997
|
-
{
|
|
1998
|
-
tag: "script",
|
|
1999
|
-
children: Object.keys(globals).map((key) => `self[${JSON.stringify(key)}] = ${globals[key]};`).join("\n"),
|
|
2000
|
-
injectTo: "head-prepend"
|
|
2001
|
-
}
|
|
2002
|
-
];
|
|
2003
|
-
return descriptor;
|
|
2004
|
-
},
|
|
2005
|
-
async writeBundle() {
|
|
2006
|
-
if (isCDN(publicPath) && !forceBuildCDN) {
|
|
2007
|
-
return;
|
|
2008
|
-
}
|
|
2009
|
-
const fs2 = await getFS();
|
|
2010
|
-
if (!fs2) {
|
|
2011
|
-
this.warn("File system operations not available in this environment");
|
|
2012
|
-
return;
|
|
2013
|
-
}
|
|
2014
|
-
const works = getWorks(options);
|
|
2015
|
-
const distPath = options.customDistPath ? options.customDistPath(
|
|
2016
|
-
resolvedConfig.root,
|
|
2017
|
-
resolvedConfig.build.outDir,
|
|
2018
|
-
resolvedConfig.base
|
|
2019
|
-
) : path.join(
|
|
2020
|
-
resolvedConfig.root,
|
|
2021
|
-
resolvedConfig.build.outDir,
|
|
2022
|
-
resolvedConfig.base,
|
|
2023
|
-
options.publicPath
|
|
2024
|
-
);
|
|
2025
|
-
if (!fs2.existsSync(distPath)) {
|
|
2026
|
-
fs2.mkdirSync(distPath, {
|
|
2027
|
-
recursive: true
|
|
2028
|
-
});
|
|
2029
|
-
}
|
|
2030
|
-
for (const work of works) {
|
|
2031
|
-
if (!fs2.existsSync(cacheDir + getFilenameByEntry(work.entry))) {
|
|
2032
|
-
esbuild.buildSync({
|
|
2033
|
-
entryPoints: [resolveMonacoPath(work.entry)],
|
|
2034
|
-
bundle: true,
|
|
2035
|
-
outfile: cacheDir + getFilenameByEntry(work.entry)
|
|
2036
|
-
});
|
|
2037
|
-
}
|
|
2038
|
-
const contentBuffer = fs2.readFileSync(cacheDir + getFilenameByEntry(work.entry));
|
|
2039
|
-
const workDistPath = path.resolve(distPath, getFilenameByEntry(work.entry));
|
|
2040
|
-
fs2.writeFileSync(workDistPath, contentBuffer);
|
|
2041
|
-
}
|
|
2042
|
-
}
|
|
2043
|
-
};
|
|
2044
|
-
}
|
|
2045
|
-
function isCDN(publicPath) {
|
|
2046
|
-
if (/^((http:)|(https:)|(file:)|(\/\/))/.test(publicPath)) {
|
|
2047
|
-
return true;
|
|
2048
|
-
}
|
|
2049
|
-
return false;
|
|
2050
|
-
}
|
|
2051
|
-
function matches(filename, patterns) {
|
|
2052
|
-
if (!patterns || patterns.length === 0) return true;
|
|
2053
|
-
return patterns.some(
|
|
2054
|
-
(p) => typeof p === "string" ? filename.includes(p) : p.test(filename)
|
|
2055
|
-
);
|
|
2056
|
-
}
|
|
2057
|
-
function sharpOptimize(options = {}) {
|
|
2058
|
-
const {
|
|
2059
|
-
include,
|
|
2060
|
-
exclude,
|
|
2061
|
-
jpegQuality = 75,
|
|
2062
|
-
pngQuality = 75,
|
|
2063
|
-
webpQuality = 75,
|
|
2064
|
-
avifQuality = 50
|
|
2065
|
-
} = options;
|
|
2066
|
-
let _sharp = null;
|
|
2067
|
-
const getSharp = async () => {
|
|
2068
|
-
if (!_sharp) {
|
|
2069
|
-
const sharpModule = await import("sharp");
|
|
2070
|
-
_sharp = sharpModule.default ?? sharpModule;
|
|
2071
|
-
}
|
|
2072
|
-
return _sharp;
|
|
2073
|
-
};
|
|
2074
|
-
const imageExts = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp", ".avif"]);
|
|
2075
|
-
return {
|
|
2076
|
-
name: "jetlinks-sharp-optimize",
|
|
2077
|
-
apply: "build",
|
|
2078
|
-
enforce: "post",
|
|
2079
|
-
async generateBundle(_opts, bundle) {
|
|
2080
|
-
for (const [fileName, asset] of Object.entries(bundle)) {
|
|
2081
|
-
if (asset.type !== "asset") continue;
|
|
2082
|
-
const ext = path$1.extname(fileName).toLowerCase();
|
|
2083
|
-
if (!imageExts.has(ext)) continue;
|
|
2084
|
-
if (exclude && matches(fileName, exclude)) continue;
|
|
2085
|
-
if (include && !matches(fileName, include)) continue;
|
|
2086
|
-
try {
|
|
2087
|
-
const sourceBuffer = Buffer.isBuffer(asset.source) ? asset.source : Buffer.from(String(asset.source));
|
|
2088
|
-
const sharp = await getSharp();
|
|
2089
|
-
let instance = sharp(sourceBuffer);
|
|
2090
|
-
switch (ext) {
|
|
2091
|
-
case ".jpg":
|
|
2092
|
-
case ".jpeg":
|
|
2093
|
-
instance = instance.jpeg({ quality: jpegQuality, mozjpeg: true });
|
|
2094
|
-
break;
|
|
2095
|
-
case ".png":
|
|
2096
|
-
instance = instance.png({ quality: pngQuality, compressionLevel: 9 });
|
|
2097
|
-
break;
|
|
2098
|
-
case ".webp":
|
|
2099
|
-
instance = instance.webp({ quality: webpQuality });
|
|
2100
|
-
break;
|
|
2101
|
-
case ".avif":
|
|
2102
|
-
instance = instance.avif({ quality: avifQuality });
|
|
2103
|
-
break;
|
|
2104
|
-
default:
|
|
2105
|
-
break;
|
|
2106
|
-
}
|
|
2107
|
-
const optimized = await instance.toBuffer();
|
|
2108
|
-
asset.source = optimized;
|
|
2109
|
-
} catch (err) {
|
|
2110
|
-
this.warn(`sharp optimize failed for ${fileName}: ${String(err)}`);
|
|
2111
|
-
}
|
|
2112
|
-
}
|
|
2113
|
-
}
|
|
2114
|
-
};
|
|
2115
|
-
}
|
|
2116
|
-
exports.federation = federation;
|
|
2117
|
-
exports.monacoEditorPlugin = monacoEditorPlugin;
|
|
2118
|
-
exports.sharpOptimize = sharpOptimize;
|
|
1797
|
+
exports.DynamicRemoteManager = dynamicRemote.DynamicRemoteManager;
|
|
1798
|
+
exports.dynamicRemoteManager = dynamicRemote.dynamicRemoteManager;
|
|
1799
|
+
exports.loadDynamicRemoteComponent = dynamicRemote.loadDynamicRemoteComponent;
|
|
1800
|
+
exports.useDynamicRemote = dynamicRemote.useDynamicRemote;
|
|
1801
|
+
exports.VitePluginFederationVersion = VitePluginFederationVersion;
|
|
1802
|
+
exports.default = federation;
|
package/dist/index.mjs
CHANGED
|
@@ -3,15 +3,16 @@ import path, { posix, resolve, basename, join, extname, parse, relative, dirname
|
|
|
3
3
|
import { walk } from "estree-walker";
|
|
4
4
|
import MagicString from "magic-string";
|
|
5
5
|
import path$1 from "node:path";
|
|
6
|
-
import { readFileSync, statSync, readdirSync
|
|
6
|
+
import { readFileSync, statSync, readdirSync } from "fs";
|
|
7
7
|
import "crypto";
|
|
8
|
-
import {
|
|
8
|
+
import { DynamicRemoteManager, dynamicRemoteManager, loadDynamicRemoteComponent, useDynamicRemote } from "./dynamic-remote.mjs";
|
|
9
9
|
const EXPOSES_MAP = /* @__PURE__ */ new Map();
|
|
10
10
|
const EXPOSES_KEY_MAP = /* @__PURE__ */ new Map();
|
|
11
11
|
const SHARED = "shared";
|
|
12
12
|
const DYNAMIC_LOADING_CSS = "dynamicLoadingCss";
|
|
13
13
|
const DYNAMIC_LOADING_CSS_PREFIX = "__v__css__";
|
|
14
14
|
const DEFAULT_ENTRY_FILENAME = "remoteEntry.js";
|
|
15
|
+
const VitePluginFederationVersion = "1.5.0";
|
|
15
16
|
const builderInfo = {
|
|
16
17
|
builder: "rollup",
|
|
17
18
|
assetsDir: "",
|
|
@@ -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 "";
|
|
@@ -1811,286 +1792,11 @@ function federation(options) {
|
|
|
1811
1792
|
}
|
|
1812
1793
|
};
|
|
1813
1794
|
}
|
|
1814
|
-
const languageWorkAttr = [
|
|
1815
|
-
{
|
|
1816
|
-
label: "editorWorkerService",
|
|
1817
|
-
entry: "monaco-editor/esm/vs/editor/editor.worker"
|
|
1818
|
-
},
|
|
1819
|
-
{
|
|
1820
|
-
label: "css",
|
|
1821
|
-
entry: "monaco-editor/esm/vs/language/css/css.worker"
|
|
1822
|
-
},
|
|
1823
|
-
{
|
|
1824
|
-
label: "html",
|
|
1825
|
-
entry: "monaco-editor/esm/vs/language/html/html.worker"
|
|
1826
|
-
},
|
|
1827
|
-
{
|
|
1828
|
-
label: "json",
|
|
1829
|
-
entry: "monaco-editor/esm/vs/language/json/json.worker"
|
|
1830
|
-
},
|
|
1831
|
-
{
|
|
1832
|
-
label: "typescript",
|
|
1833
|
-
entry: "monaco-editor/esm/vs/language/typescript/ts.worker"
|
|
1834
|
-
}
|
|
1835
|
-
];
|
|
1836
|
-
const languageWorksByLabel = {};
|
|
1837
|
-
languageWorkAttr.forEach(
|
|
1838
|
-
(languageWork) => languageWorksByLabel[languageWork.label] = languageWork
|
|
1839
|
-
);
|
|
1840
|
-
function getFilenameByEntry(entry) {
|
|
1841
|
-
entry = basename(entry, "js");
|
|
1842
|
-
return entry + ".bundle.js";
|
|
1843
|
-
}
|
|
1844
|
-
const cacheDir = "node_modules/.monaco/";
|
|
1845
|
-
function getWorkPath(works, options, config) {
|
|
1846
|
-
const workerPaths = {};
|
|
1847
|
-
for (const work of works) {
|
|
1848
|
-
if (isCDN(options.publicPath)) {
|
|
1849
|
-
workerPaths[work.label] = options.publicPath + "/" + getFilenameByEntry(work.entry);
|
|
1850
|
-
} else {
|
|
1851
|
-
workerPaths[work.label] = config.base + options.publicPath + "/" + getFilenameByEntry(work.entry);
|
|
1852
|
-
}
|
|
1853
|
-
}
|
|
1854
|
-
if (workerPaths["typescript"]) {
|
|
1855
|
-
workerPaths["javascript"] = workerPaths["typescript"];
|
|
1856
|
-
}
|
|
1857
|
-
if (workerPaths["css"]) {
|
|
1858
|
-
workerPaths["less"] = workerPaths["css"];
|
|
1859
|
-
workerPaths["scss"] = workerPaths["css"];
|
|
1860
|
-
}
|
|
1861
|
-
if (workerPaths["html"]) {
|
|
1862
|
-
workerPaths["handlebars"] = workerPaths["html"];
|
|
1863
|
-
workerPaths["razor"] = workerPaths["html"];
|
|
1864
|
-
}
|
|
1865
|
-
return workerPaths;
|
|
1866
|
-
}
|
|
1867
|
-
function workerMiddleware(middlewares, config, options) {
|
|
1868
|
-
const works = getWorks(options);
|
|
1869
|
-
if (existsSync(cacheDir)) {
|
|
1870
|
-
rmSync(cacheDir, { recursive: true, force: true });
|
|
1871
|
-
}
|
|
1872
|
-
for (const work of works) {
|
|
1873
|
-
middlewares.use(
|
|
1874
|
-
config.base + options.publicPath + "/" + getFilenameByEntry(work.entry),
|
|
1875
|
-
function(req, res, next) {
|
|
1876
|
-
if (!existsSync(cacheDir + getFilenameByEntry(work.entry))) {
|
|
1877
|
-
buildSync({
|
|
1878
|
-
entryPoints: [resolveMonacoPath(work.entry)],
|
|
1879
|
-
bundle: true,
|
|
1880
|
-
outfile: cacheDir + getFilenameByEntry(work.entry)
|
|
1881
|
-
});
|
|
1882
|
-
}
|
|
1883
|
-
const contentBuffer = readFileSync(cacheDir + getFilenameByEntry(work.entry));
|
|
1884
|
-
res.setHeader("Content-Type", "text/javascript");
|
|
1885
|
-
res.end(contentBuffer);
|
|
1886
|
-
}
|
|
1887
|
-
);
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
function resolveMonacoPath(filePath) {
|
|
1891
|
-
try {
|
|
1892
|
-
return resolve(join(process.cwd(), "node_modules", filePath));
|
|
1893
|
-
} catch (err) {
|
|
1894
|
-
return resolve(filePath);
|
|
1895
|
-
}
|
|
1896
|
-
}
|
|
1897
|
-
function getWorks(options) {
|
|
1898
|
-
let works = options.languageWorkers.map(
|
|
1899
|
-
(work) => languageWorksByLabel[work]
|
|
1900
|
-
);
|
|
1901
|
-
works.push(...options.customWorkers);
|
|
1902
|
-
return works;
|
|
1903
|
-
}
|
|
1904
|
-
const getFS = async () => {
|
|
1905
|
-
if (typeof process !== "undefined" && process.versions?.node) {
|
|
1906
|
-
const fs = await import("fs");
|
|
1907
|
-
return {
|
|
1908
|
-
existsSync: fs.existsSync,
|
|
1909
|
-
mkdirSync: fs.mkdirSync,
|
|
1910
|
-
readFileSync: fs.readFileSync,
|
|
1911
|
-
writeFileSync: fs.writeFileSync
|
|
1912
|
-
};
|
|
1913
|
-
}
|
|
1914
|
-
return null;
|
|
1915
|
-
};
|
|
1916
|
-
function monacoEditorPlugin(options) {
|
|
1917
|
-
const languageWorkers = options.languageWorkers || Object.keys(languageWorksByLabel);
|
|
1918
|
-
const publicPath = options.publicPath || "monacoeditorwork";
|
|
1919
|
-
const globalAPI = options.globalAPI || false;
|
|
1920
|
-
const customWorkers = options.customWorkers || [];
|
|
1921
|
-
const forceBuildCDN = options.forceBuildCDN || false;
|
|
1922
|
-
options = {
|
|
1923
|
-
...options,
|
|
1924
|
-
languageWorkers,
|
|
1925
|
-
publicPath,
|
|
1926
|
-
globalAPI,
|
|
1927
|
-
customWorkers,
|
|
1928
|
-
forceBuildCDN
|
|
1929
|
-
};
|
|
1930
|
-
let resolvedConfig;
|
|
1931
|
-
return {
|
|
1932
|
-
name: "vite-plugin-monaco-editor",
|
|
1933
|
-
configResolved(getResolvedConfig) {
|
|
1934
|
-
resolvedConfig = getResolvedConfig;
|
|
1935
|
-
},
|
|
1936
|
-
configureServer(server) {
|
|
1937
|
-
if (isCDN(publicPath)) {
|
|
1938
|
-
return;
|
|
1939
|
-
}
|
|
1940
|
-
workerMiddleware(server.middlewares, resolvedConfig, options);
|
|
1941
|
-
},
|
|
1942
|
-
transformIndexHtml(html) {
|
|
1943
|
-
const works = getWorks(options);
|
|
1944
|
-
const workerPaths = getWorkPath(works, options, resolvedConfig);
|
|
1945
|
-
const globals = {
|
|
1946
|
-
MonacoEnvironment: `(function (paths) {
|
|
1947
|
-
return {
|
|
1948
|
-
globalAPI: ${globalAPI},
|
|
1949
|
-
getWorkerUrl : function (moduleId, label) {
|
|
1950
|
-
var result = paths[label];
|
|
1951
|
-
var _location = window.__MICRO_APP_ENVIRONMENT__ ? window.rawWindow.location : window.location;
|
|
1952
|
-
var currentUrl = String(_location);
|
|
1953
|
-
var currentOrigin = currentUrl.substr(0, currentUrl.length - _location.hash.length - _location.search.length - _location.pathname.length);
|
|
1954
|
-
|
|
1955
|
-
if (window.__MICRO_APP_ENVIRONMENT__) {
|
|
1956
|
-
result = currentOrigin + result.replace('./', '/')
|
|
1957
|
-
}
|
|
1958
|
-
|
|
1959
|
-
if (/^((http:)|(https:)|(file:)|(\\/\\/))/.test(result)) {
|
|
1960
|
-
if (result.substring(0, currentOrigin.length) !== currentOrigin) {
|
|
1961
|
-
var js = '/*' + label + '*/importScripts("' + result + '");';
|
|
1962
|
-
var blob = new Blob([js], { type: 'application/javascript' });
|
|
1963
|
-
return URL.createObjectURL(blob);
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
console.log('result',result);
|
|
1967
|
-
return result;
|
|
1968
|
-
}
|
|
1969
|
-
};
|
|
1970
|
-
})(${JSON.stringify(workerPaths, null, 2)})`
|
|
1971
|
-
};
|
|
1972
|
-
const descriptor = [
|
|
1973
|
-
{
|
|
1974
|
-
tag: "script",
|
|
1975
|
-
children: Object.keys(globals).map((key) => `self[${JSON.stringify(key)}] = ${globals[key]};`).join("\n"),
|
|
1976
|
-
injectTo: "head-prepend"
|
|
1977
|
-
}
|
|
1978
|
-
];
|
|
1979
|
-
return descriptor;
|
|
1980
|
-
},
|
|
1981
|
-
async writeBundle() {
|
|
1982
|
-
if (isCDN(publicPath) && !forceBuildCDN) {
|
|
1983
|
-
return;
|
|
1984
|
-
}
|
|
1985
|
-
const fs = await getFS();
|
|
1986
|
-
if (!fs) {
|
|
1987
|
-
this.warn("File system operations not available in this environment");
|
|
1988
|
-
return;
|
|
1989
|
-
}
|
|
1990
|
-
const works = getWorks(options);
|
|
1991
|
-
const distPath = options.customDistPath ? options.customDistPath(
|
|
1992
|
-
resolvedConfig.root,
|
|
1993
|
-
resolvedConfig.build.outDir,
|
|
1994
|
-
resolvedConfig.base
|
|
1995
|
-
) : join(
|
|
1996
|
-
resolvedConfig.root,
|
|
1997
|
-
resolvedConfig.build.outDir,
|
|
1998
|
-
resolvedConfig.base,
|
|
1999
|
-
options.publicPath
|
|
2000
|
-
);
|
|
2001
|
-
if (!fs.existsSync(distPath)) {
|
|
2002
|
-
fs.mkdirSync(distPath, {
|
|
2003
|
-
recursive: true
|
|
2004
|
-
});
|
|
2005
|
-
}
|
|
2006
|
-
for (const work of works) {
|
|
2007
|
-
if (!fs.existsSync(cacheDir + getFilenameByEntry(work.entry))) {
|
|
2008
|
-
buildSync({
|
|
2009
|
-
entryPoints: [resolveMonacoPath(work.entry)],
|
|
2010
|
-
bundle: true,
|
|
2011
|
-
outfile: cacheDir + getFilenameByEntry(work.entry)
|
|
2012
|
-
});
|
|
2013
|
-
}
|
|
2014
|
-
const contentBuffer = fs.readFileSync(cacheDir + getFilenameByEntry(work.entry));
|
|
2015
|
-
const workDistPath = resolve(distPath, getFilenameByEntry(work.entry));
|
|
2016
|
-
fs.writeFileSync(workDistPath, contentBuffer);
|
|
2017
|
-
}
|
|
2018
|
-
}
|
|
2019
|
-
};
|
|
2020
|
-
}
|
|
2021
|
-
function isCDN(publicPath) {
|
|
2022
|
-
if (/^((http:)|(https:)|(file:)|(\/\/))/.test(publicPath)) {
|
|
2023
|
-
return true;
|
|
2024
|
-
}
|
|
2025
|
-
return false;
|
|
2026
|
-
}
|
|
2027
|
-
function matches(filename, patterns) {
|
|
2028
|
-
if (!patterns || patterns.length === 0) return true;
|
|
2029
|
-
return patterns.some(
|
|
2030
|
-
(p) => typeof p === "string" ? filename.includes(p) : p.test(filename)
|
|
2031
|
-
);
|
|
2032
|
-
}
|
|
2033
|
-
function sharpOptimize(options = {}) {
|
|
2034
|
-
const {
|
|
2035
|
-
include,
|
|
2036
|
-
exclude,
|
|
2037
|
-
jpegQuality = 75,
|
|
2038
|
-
pngQuality = 75,
|
|
2039
|
-
webpQuality = 75,
|
|
2040
|
-
avifQuality = 50
|
|
2041
|
-
} = options;
|
|
2042
|
-
let _sharp = null;
|
|
2043
|
-
const getSharp = async () => {
|
|
2044
|
-
if (!_sharp) {
|
|
2045
|
-
const sharpModule = await import("sharp");
|
|
2046
|
-
_sharp = sharpModule.default ?? sharpModule;
|
|
2047
|
-
}
|
|
2048
|
-
return _sharp;
|
|
2049
|
-
};
|
|
2050
|
-
const imageExts = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp", ".avif"]);
|
|
2051
|
-
return {
|
|
2052
|
-
name: "jetlinks-sharp-optimize",
|
|
2053
|
-
apply: "build",
|
|
2054
|
-
enforce: "post",
|
|
2055
|
-
async generateBundle(_opts, bundle) {
|
|
2056
|
-
for (const [fileName, asset] of Object.entries(bundle)) {
|
|
2057
|
-
if (asset.type !== "asset") continue;
|
|
2058
|
-
const ext = path$1.extname(fileName).toLowerCase();
|
|
2059
|
-
if (!imageExts.has(ext)) continue;
|
|
2060
|
-
if (exclude && matches(fileName, exclude)) continue;
|
|
2061
|
-
if (include && !matches(fileName, include)) continue;
|
|
2062
|
-
try {
|
|
2063
|
-
const sourceBuffer = Buffer.isBuffer(asset.source) ? asset.source : Buffer.from(String(asset.source));
|
|
2064
|
-
const sharp = await getSharp();
|
|
2065
|
-
let instance = sharp(sourceBuffer);
|
|
2066
|
-
switch (ext) {
|
|
2067
|
-
case ".jpg":
|
|
2068
|
-
case ".jpeg":
|
|
2069
|
-
instance = instance.jpeg({ quality: jpegQuality, mozjpeg: true });
|
|
2070
|
-
break;
|
|
2071
|
-
case ".png":
|
|
2072
|
-
instance = instance.png({ quality: pngQuality, compressionLevel: 9 });
|
|
2073
|
-
break;
|
|
2074
|
-
case ".webp":
|
|
2075
|
-
instance = instance.webp({ quality: webpQuality });
|
|
2076
|
-
break;
|
|
2077
|
-
case ".avif":
|
|
2078
|
-
instance = instance.avif({ quality: avifQuality });
|
|
2079
|
-
break;
|
|
2080
|
-
default:
|
|
2081
|
-
break;
|
|
2082
|
-
}
|
|
2083
|
-
const optimized = await instance.toBuffer();
|
|
2084
|
-
asset.source = optimized;
|
|
2085
|
-
} catch (err) {
|
|
2086
|
-
this.warn(`sharp optimize failed for ${fileName}: ${String(err)}`);
|
|
2087
|
-
}
|
|
2088
|
-
}
|
|
2089
|
-
}
|
|
2090
|
-
};
|
|
2091
|
-
}
|
|
2092
1795
|
export {
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
1796
|
+
DynamicRemoteManager,
|
|
1797
|
+
VitePluginFederationVersion,
|
|
1798
|
+
federation as default,
|
|
1799
|
+
dynamicRemoteManager,
|
|
1800
|
+
loadDynamicRemoteComponent,
|
|
1801
|
+
useDynamicRemote
|
|
2096
1802
|
};
|