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