@hanzogui/vite-plugin 8.3.0 → 8.3.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/cjs/extensions.js +16 -0
- package/dist/cjs/extensions.js.map +1 -0
- package/dist/cjs/here.js +6 -0
- package/dist/cjs/here.js.map +1 -0
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/loadGui.js +84 -0
- package/dist/cjs/loadGui.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/plugin.js +523 -0
- package/dist/cjs/plugin.js.map +1 -0
- package/dist/esm/extensions.js +13 -0
- package/dist/esm/extensions.js.map +1 -0
- package/dist/esm/here.js +3 -0
- package/dist/esm/here.js.map +1 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/loadGui.js +76 -0
- package/dist/esm/loadGui.js.map +1 -0
- package/dist/esm/plugin.js +518 -0
- package/dist/esm/plugin.js.map +1 -0
- package/package.json +20 -19
- package/src/here.cjs.ts +3 -0
- package/src/here.ts +2 -0
- package/src/index.ts +1 -1
- package/src/plugin.ts +7 -9
- package/types/here.d.ts +2 -0
- package/types/here.d.ts.map +1 -0
- package/types/index.d.ts +1 -1
- package/types/index.d.ts.map +1 -1
- package/types/plugin.d.ts.map +1 -1
- package/dist/cjs/extensions.cjs +0 -28
- package/dist/cjs/index.cjs +0 -20
- package/dist/cjs/loadGui.cjs +0 -101
- package/dist/cjs/plugin.cjs +0 -473
- package/dist/esm/extensions.mjs +0 -3
- package/dist/esm/extensions.mjs.map +0 -1
- package/dist/esm/index.mjs +0 -2
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/loadGui.mjs +0 -61
- package/dist/esm/loadGui.mjs.map +0 -1
- package/dist/esm/plugin.mjs +0 -435
- package/dist/esm/plugin.mjs.map +0 -1
package/dist/cjs/plugin.cjs
DELETED
|
@@ -1,473 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all) __defProp(target, name, {
|
|
9
|
-
get: all[name],
|
|
10
|
-
enumerable: true
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
-
get: () => from[key],
|
|
17
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
-
value: mod,
|
|
29
|
-
enumerable: true
|
|
30
|
-
}) : target, mod));
|
|
31
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
-
value: true
|
|
33
|
-
}), mod);
|
|
34
|
-
var plugin_exports = {};
|
|
35
|
-
__export(plugin_exports, {
|
|
36
|
-
hanzoguiAliases: () => hanzoguiAliases,
|
|
37
|
-
hanzoguiPlugin: () => hanzoguiPlugin
|
|
38
|
-
});
|
|
39
|
-
module.exports = __toCommonJS(plugin_exports);
|
|
40
|
-
var Static = __toESM(require("@hanzogui/static-worker"), 1);
|
|
41
|
-
var import_static_worker = require("@hanzogui/static-worker");
|
|
42
|
-
var import_node_crypto = require("node:crypto");
|
|
43
|
-
var import_node_module = require("node:module");
|
|
44
|
-
var import_node_path = __toESM(require("node:path"), 1);
|
|
45
|
-
var import_node_url = require("node:url");
|
|
46
|
-
var import_loadGui = require("./loadGui.cjs");
|
|
47
|
-
const import_meta = {};
|
|
48
|
-
const _pluginRequire = (0, import_node_module.createRequire)(typeof __filename === "string" ? __filename : (0, import_node_url.fileURLToPath)(import_meta.url));
|
|
49
|
-
const resolve = name => _pluginRequire.resolve(name);
|
|
50
|
-
const normalizePath = value => value.replace(/\\/g, "/");
|
|
51
|
-
const PACKAGE_EXTENSIONS = /\.(mjs|js|jsx|tsx)$/;
|
|
52
|
-
const CACHE_KEY = "__hanzogui_vite_cache__";
|
|
53
|
-
const CACHE_SIZE_KEY = "__hanzogui_vite_cache_size__";
|
|
54
|
-
const PENDING_KEY = "__hanzogui_vite_pending__";
|
|
55
|
-
function getSharedCache() {
|
|
56
|
-
if (!globalThis[CACHE_KEY]) {
|
|
57
|
-
;
|
|
58
|
-
globalThis[CACHE_KEY] = {};
|
|
59
|
-
}
|
|
60
|
-
return globalThis[CACHE_KEY];
|
|
61
|
-
}
|
|
62
|
-
function getSharedCacheSize() {
|
|
63
|
-
return globalThis[CACHE_SIZE_KEY] || 0;
|
|
64
|
-
}
|
|
65
|
-
function setSharedCacheSize(size) {
|
|
66
|
-
;
|
|
67
|
-
globalThis[CACHE_SIZE_KEY] = size;
|
|
68
|
-
}
|
|
69
|
-
function clearSharedCache() {
|
|
70
|
-
;
|
|
71
|
-
globalThis[CACHE_KEY] = {};
|
|
72
|
-
globalThis[CACHE_SIZE_KEY] = 0;
|
|
73
|
-
}
|
|
74
|
-
function isInstalled(projectRoot, id) {
|
|
75
|
-
try {
|
|
76
|
-
const req = (0, import_node_module.createRequire)(import_node_path.default.join(projectRoot, "package.json"));
|
|
77
|
-
req.resolve(id);
|
|
78
|
-
return true;
|
|
79
|
-
} catch {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function addIfInstalled(userConf, projectRoot, ids) {
|
|
84
|
-
const root = projectRoot || process.cwd();
|
|
85
|
-
userConf.optimizeDeps ||= {};
|
|
86
|
-
userConf.optimizeDeps.include ||= [];
|
|
87
|
-
for (const id of ids) {
|
|
88
|
-
if (!userConf.optimizeDeps.include.includes(id) && isInstalled(root, id)) {
|
|
89
|
-
userConf.optimizeDeps.include.push(id);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function getPendingExtractions() {
|
|
94
|
-
if (!globalThis[PENDING_KEY]) {
|
|
95
|
-
;
|
|
96
|
-
globalThis[PENDING_KEY] = /* @__PURE__ */new Map();
|
|
97
|
-
}
|
|
98
|
-
return globalThis[PENDING_KEY];
|
|
99
|
-
}
|
|
100
|
-
function hanzoguiAliases(options = {}) {
|
|
101
|
-
const aliases = [];
|
|
102
|
-
if (options.svg) {
|
|
103
|
-
aliases.push({
|
|
104
|
-
find: "react-native-svg",
|
|
105
|
-
replacement: resolve("@hanzogui/react-native-svg")
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
if (options.rnwLite) {
|
|
109
|
-
const rnwlBase = import_node_path.default.dirname(resolve("@hanzogui/react-native-web-lite/package.json"));
|
|
110
|
-
const rnwl = normalizePath(import_node_path.default.join(rnwlBase, options.rnwLite === "without-animated" ? "dist/esm/without-animated.mjs" : "dist/esm/index.mjs"));
|
|
111
|
-
aliases.push({
|
|
112
|
-
// map deep RNW paths like dist/exports/StyleSheet/preprocess to rnw-lite's flat structure
|
|
113
|
-
// extracts the final path segment (e.g. "preprocess" or "createReactDOMStyle")
|
|
114
|
-
find: /^react-native(?:-web)?\/dist\/(?:exports|modules)\/.*\/([^/]+)$/,
|
|
115
|
-
replacement: `${normalizePath(rnwlBase)}/dist/esm/$1.mjs`
|
|
116
|
-
}, {
|
|
117
|
-
find: /^react-native$/,
|
|
118
|
-
replacement: rnwl
|
|
119
|
-
}, {
|
|
120
|
-
find: /^react-native\/(Libraries\/Utilities\/codegenNativeComponent|Libraries\/Utilities\/codegenNativeCommand)$/,
|
|
121
|
-
replacement: `${rnwlBase}/$1`
|
|
122
|
-
}, {
|
|
123
|
-
find: "react-native/package.json",
|
|
124
|
-
replacement: resolve("@hanzogui/react-native-web-lite/package.json")
|
|
125
|
-
}, {
|
|
126
|
-
find: /^react-native-web$/,
|
|
127
|
-
replacement: rnwl
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
return aliases;
|
|
131
|
-
}
|
|
132
|
-
function hanzoguiPlugin({
|
|
133
|
-
disableResolveConfig,
|
|
134
|
-
...hanzoguiOptionsIn
|
|
135
|
-
} = {}) {
|
|
136
|
-
let shouldExtract = !hanzoguiOptionsIn.disableExtraction;
|
|
137
|
-
let watcher;
|
|
138
|
-
const enableNativeEnv = !!globalThis.__vxrnEnableNativeEnv;
|
|
139
|
-
const extensions = [`.web.mjs`, `.web.js`, `.web.jsx`, `.web.ts`, `.web.tsx`, ".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json"];
|
|
140
|
-
(0, import_loadGui.loadGuiBuildConfig)(hanzoguiOptionsIn);
|
|
141
|
-
const ensureLoaded = async () => {
|
|
142
|
-
const promise = (0, import_loadGui.getLoadPromise)();
|
|
143
|
-
if (promise) await promise;
|
|
144
|
-
const options = (0, import_loadGui.getGuiOptions)();
|
|
145
|
-
if (options) {
|
|
146
|
-
shouldExtract = !options.disableExtraction;
|
|
147
|
-
}
|
|
148
|
-
return options;
|
|
149
|
-
};
|
|
150
|
-
const getHash = input => (0, import_node_crypto.createHash)("sha1").update(input).digest("base64");
|
|
151
|
-
const memoryCache = getSharedCache();
|
|
152
|
-
const cssMap = /* @__PURE__ */new Map();
|
|
153
|
-
let config;
|
|
154
|
-
let server;
|
|
155
|
-
const virtualExt = `.hanzogui.css`;
|
|
156
|
-
const getAbsoluteVirtualFileId = filePath => {
|
|
157
|
-
if (filePath.startsWith(config.root)) {
|
|
158
|
-
return filePath;
|
|
159
|
-
}
|
|
160
|
-
return normalizePath(import_node_path.default.join(config.root, filePath));
|
|
161
|
-
};
|
|
162
|
-
function isNotClient(environment) {
|
|
163
|
-
return environment?.name && environment.name !== "client";
|
|
164
|
-
}
|
|
165
|
-
function isNative(environment) {
|
|
166
|
-
return environment?.name && (environment.name === "ios" || environment.name === "android");
|
|
167
|
-
}
|
|
168
|
-
function invalidateModule(absoluteId) {
|
|
169
|
-
if (!server) return;
|
|
170
|
-
const {
|
|
171
|
-
moduleGraph
|
|
172
|
-
} = server;
|
|
173
|
-
const modules = moduleGraph.getModulesByFile(absoluteId);
|
|
174
|
-
if (modules) {
|
|
175
|
-
for (const module2 of modules) {
|
|
176
|
-
moduleGraph.invalidateModule(module2);
|
|
177
|
-
module2.lastHMRTimestamp = module2.lastInvalidationTimestamp || Date.now();
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
const basePlugin = {
|
|
182
|
-
name: "hanzogui",
|
|
183
|
-
enforce: "pre",
|
|
184
|
-
configureServer(_server) {
|
|
185
|
-
server = _server;
|
|
186
|
-
},
|
|
187
|
-
async buildEnd() {
|
|
188
|
-
await watcher?.then(res => {
|
|
189
|
-
res?.dispose();
|
|
190
|
-
});
|
|
191
|
-
},
|
|
192
|
-
async config(_, env) {
|
|
193
|
-
const options = await ensureLoaded();
|
|
194
|
-
if (!options) {
|
|
195
|
-
throw new Error(`No hanzogui options loaded`);
|
|
196
|
-
}
|
|
197
|
-
if (!options.disableWatchGuiConfig) {
|
|
198
|
-
watcher = Static.watchGuiConfig({
|
|
199
|
-
components: ["@hanzo/gui"],
|
|
200
|
-
config: "./src/hanzogui.config.ts",
|
|
201
|
-
...options
|
|
202
|
-
}).catch(err => {
|
|
203
|
-
console.error(` [Gui] Error watching config: ${err}`);
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
return {
|
|
207
|
-
envPrefix: ["GUI_"],
|
|
208
|
-
// A dependency that RENDERS is bundled, not externalised.
|
|
209
|
-
//
|
|
210
|
-
// An externalised package resolves react itself, and under SSR that is a
|
|
211
|
-
// second module instance of the one react in the tree — its dispatcher is
|
|
212
|
-
// null while the app renders, so the package's first hook throws and the
|
|
213
|
-
// whole page fails, not just the subtree. GuiProvider mounts a telemetry
|
|
214
|
-
// client for every app, so these two arrive in apps that never named them.
|
|
215
|
-
//
|
|
216
|
-
// It belongs here rather than in each app's config because every gui app
|
|
217
|
-
// already mounts this plugin, and a list repeated per app is a list the
|
|
218
|
-
// next app forgets.
|
|
219
|
-
ssr: {
|
|
220
|
-
noExternal: ["@hanzo/event", "@hanzo/observe"]
|
|
221
|
-
},
|
|
222
|
-
environments: {
|
|
223
|
-
client: {
|
|
224
|
-
define: {
|
|
225
|
-
"process.env.GUI_IS_CLIENT": JSON.stringify(true),
|
|
226
|
-
"process.env.GUI_ENVIRONMENT": '"client"'
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
},
|
|
230
|
-
define: {
|
|
231
|
-
// reanimated support
|
|
232
|
-
_frameTimestamp: void 0,
|
|
233
|
-
_WORKLET: false,
|
|
234
|
-
__DEV__: `${env.mode === "development"}`,
|
|
235
|
-
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || env.mode),
|
|
236
|
-
"process.env.ENABLE_RSC": JSON.stringify(process.env.ENABLE_RSC || ""),
|
|
237
|
-
"process.env.ENABLE_STEPS": JSON.stringify(process.env.ENABLE_STEPS || ""),
|
|
238
|
-
"process.env.IS_STATIC": JSON.stringify(false),
|
|
239
|
-
...(env.mode === "production" && {
|
|
240
|
-
"process.env.GUI_OPTIMIZE_THEMES": JSON.stringify(true)
|
|
241
|
-
})
|
|
242
|
-
},
|
|
243
|
-
resolve: disableResolveConfig || enableNativeEnv ? {} : {
|
|
244
|
-
extensions,
|
|
245
|
-
alias: {
|
|
246
|
-
...(options.platform !== "native" && {
|
|
247
|
-
"react-native/Libraries/Renderer/shims/ReactFabric": resolve("@hanzogui/proxy-worm"),
|
|
248
|
-
"react-native/Libraries/Utilities/codegenNativeComponent": resolve("@hanzogui/proxy-worm"),
|
|
249
|
-
"react-native-svg": resolve("@hanzogui/react-native-svg"),
|
|
250
|
-
...(!options?.useReactNativeWebLite && {
|
|
251
|
-
"react-native": resolve("react-native-web")
|
|
252
|
-
})
|
|
253
|
-
})
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
const rnwLitePlugin = {
|
|
260
|
-
name: "hanzogui-rnw-lite",
|
|
261
|
-
config() {
|
|
262
|
-
if (enableNativeEnv) {
|
|
263
|
-
return {};
|
|
264
|
-
}
|
|
265
|
-
const options = (0, import_loadGui.getGuiOptions)();
|
|
266
|
-
if (!options?.useReactNativeWebLite) {
|
|
267
|
-
return {};
|
|
268
|
-
}
|
|
269
|
-
const include = [];
|
|
270
|
-
if (isInstalled(process.cwd(), "memoize-one")) {
|
|
271
|
-
include.push("memoize-one");
|
|
272
|
-
}
|
|
273
|
-
return {
|
|
274
|
-
resolve: {
|
|
275
|
-
alias: hanzoguiAliases({
|
|
276
|
-
rnwLite: options.useReactNativeWebLite
|
|
277
|
-
})
|
|
278
|
-
},
|
|
279
|
-
optimizeDeps: {
|
|
280
|
-
// upstream react-native-web must not be pre-bundled when aliased to lite
|
|
281
|
-
exclude: ["react-native-web"],
|
|
282
|
-
include
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
const extractPlugin = {
|
|
288
|
-
name: "hanzogui-extract",
|
|
289
|
-
enforce: "pre",
|
|
290
|
-
async config(userConf) {
|
|
291
|
-
const options = await ensureLoaded();
|
|
292
|
-
userConf.optimizeDeps ||= {};
|
|
293
|
-
userConf.optimizeDeps.include ||= [];
|
|
294
|
-
userConf.optimizeDeps.include.push("inline-style-prefixer");
|
|
295
|
-
addIfInstalled(userConf, userConf.root, ["@hanzogui/toast", "@hanzogui/toast/v2", "@hanzogui/sheet", "@hanzogui/sheet/controller"]);
|
|
296
|
-
userConf.resolve ||= {};
|
|
297
|
-
userConf.resolve.dedupe ||= [];
|
|
298
|
-
for (const id of ["hanzogui", "@hanzogui/core", "@hanzogui/web", "@hanzogui/toast", "@hanzogui/sheet"]) {
|
|
299
|
-
if (!userConf.resolve.dedupe.includes(id) && isInstalled(userConf.root || process.cwd(), id)) {
|
|
300
|
-
userConf.resolve.dedupe.push(id);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
if (!shouldExtract) return;
|
|
304
|
-
userConf.optimizeDeps.include.push("@hanzogui/core/inject-styles");
|
|
305
|
-
},
|
|
306
|
-
async configResolved(resolvedConfig) {
|
|
307
|
-
config = resolvedConfig;
|
|
308
|
-
},
|
|
309
|
-
async resolveId(source) {
|
|
310
|
-
if (!shouldExtract) return;
|
|
311
|
-
if (isNative(this.environment)) {
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
if (isNotClient(this.environment)) {
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
const [validId, query] = source.split("?");
|
|
318
|
-
if (!validId.endsWith(virtualExt)) {
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId);
|
|
322
|
-
if (cssMap.has(absoluteId)) {
|
|
323
|
-
return absoluteId + (query ? `?${query}` : "");
|
|
324
|
-
}
|
|
325
|
-
},
|
|
326
|
-
async load(id) {
|
|
327
|
-
if (!shouldExtract) return;
|
|
328
|
-
const options = (0, import_loadGui.getGuiOptions)();
|
|
329
|
-
if (options?.disable) {
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
if (isNative(this.environment)) {
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
if (isNotClient(this.environment)) {
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
const [validId] = id.split("?");
|
|
339
|
-
return cssMap.get(validId);
|
|
340
|
-
},
|
|
341
|
-
transform: {
|
|
342
|
-
order: "pre",
|
|
343
|
-
async handler(code, id) {
|
|
344
|
-
const options = await ensureLoaded();
|
|
345
|
-
await (0, import_loadGui.ensureFullConfigLoaded)();
|
|
346
|
-
if (options?.disable) {
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
if (isNative(this.environment)) {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
const [validId] = id.split("?");
|
|
353
|
-
const pkg = (0, import_static_worker.installedPackageOf)(validId);
|
|
354
|
-
if (pkg ? !(0, import_static_worker.isExtractable)(validId, options?.extractPackages) || !PACKAGE_EXTENSIONS.test(validId) : !validId.endsWith(".tsx")) {
|
|
355
|
-
return;
|
|
356
|
-
}
|
|
357
|
-
const {
|
|
358
|
-
shouldDisable,
|
|
359
|
-
shouldPrintDebug
|
|
360
|
-
} = await (0, import_static_worker.getPragmaOptions)({
|
|
361
|
-
source: code,
|
|
362
|
-
path: validId
|
|
363
|
-
});
|
|
364
|
-
if (shouldPrintDebug) {
|
|
365
|
-
console.trace(`Current file: ${id} in environment: ${this.environment?.name}, shouldDisable: ${shouldDisable}`);
|
|
366
|
-
console.info(`
|
|
367
|
-
|
|
368
|
-
Original source:
|
|
369
|
-
${code}
|
|
370
|
-
|
|
371
|
-
`);
|
|
372
|
-
}
|
|
373
|
-
if (shouldDisable) {
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
const isSSR = isNotClient(this.environment);
|
|
377
|
-
const cacheKey = getHash(`${code}${id}`);
|
|
378
|
-
const pending = getPendingExtractions();
|
|
379
|
-
const formatResult = entry => {
|
|
380
|
-
const finalCode = !isSSR && entry.cssImport ? `${entry.js}
|
|
381
|
-
${entry.cssImport}` : entry.js;
|
|
382
|
-
return {
|
|
383
|
-
code: finalCode,
|
|
384
|
-
map: entry.map
|
|
385
|
-
};
|
|
386
|
-
};
|
|
387
|
-
const cached = memoryCache[cacheKey];
|
|
388
|
-
if (cached) {
|
|
389
|
-
if (process.env.DEBUG_GUI_CACHE) {
|
|
390
|
-
console.info(`[hanzogui-cache] HIT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
|
|
391
|
-
}
|
|
392
|
-
return formatResult(cached);
|
|
393
|
-
}
|
|
394
|
-
const pendingExtraction = pending.get(cacheKey);
|
|
395
|
-
if (pendingExtraction) {
|
|
396
|
-
if (process.env.DEBUG_GUI_CACHE) {
|
|
397
|
-
console.info(`[hanzogui-cache] WAIT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
|
|
398
|
-
}
|
|
399
|
-
const result = await pendingExtraction;
|
|
400
|
-
if (result) {
|
|
401
|
-
return formatResult(result);
|
|
402
|
-
}
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
if (process.env.DEBUG_GUI_CACHE) {
|
|
406
|
-
console.info(`[hanzogui-cache] EXTRACT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
|
|
407
|
-
}
|
|
408
|
-
const extractionPromise = (async () => {
|
|
409
|
-
let extracted;
|
|
410
|
-
try {
|
|
411
|
-
extracted = await Static.extractToClassNames({
|
|
412
|
-
source: code,
|
|
413
|
-
sourcePath: validId,
|
|
414
|
-
options,
|
|
415
|
-
shouldPrintDebug
|
|
416
|
-
});
|
|
417
|
-
} catch (err) {
|
|
418
|
-
if (process.env.DEBUG_GUI_CACHE) {
|
|
419
|
-
console.info(`[hanzogui-cache] ERROR extracting ${id.split("/").pop()}:`, err);
|
|
420
|
-
}
|
|
421
|
-
console.error(err instanceof Error ? err.message : String(err));
|
|
422
|
-
return null;
|
|
423
|
-
}
|
|
424
|
-
if (!extracted) {
|
|
425
|
-
if (process.env.DEBUG_GUI_CACHE) {
|
|
426
|
-
console.info(`[hanzogui-cache] no extraction result for ${id.split("/").pop()}`);
|
|
427
|
-
}
|
|
428
|
-
return null;
|
|
429
|
-
}
|
|
430
|
-
const rootRelativeId = `${validId}${virtualExt}`;
|
|
431
|
-
const absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
|
|
432
|
-
let cssImport = null;
|
|
433
|
-
if (extracted.styles) {
|
|
434
|
-
this.addWatchFile(rootRelativeId);
|
|
435
|
-
if (server && cssMap.has(absoluteId)) {
|
|
436
|
-
invalidateModule(rootRelativeId);
|
|
437
|
-
}
|
|
438
|
-
cssImport = `import "${rootRelativeId}";`;
|
|
439
|
-
cssMap.set(absoluteId, extracted.styles);
|
|
440
|
-
}
|
|
441
|
-
const jsCode = extracted.js.toString();
|
|
442
|
-
const cacheEntry = {
|
|
443
|
-
js: jsCode,
|
|
444
|
-
map: extracted.map,
|
|
445
|
-
cssImport
|
|
446
|
-
};
|
|
447
|
-
const newSize = getSharedCacheSize() + jsCode.length;
|
|
448
|
-
if (newSize > 67108864) {
|
|
449
|
-
clearSharedCache();
|
|
450
|
-
} else {
|
|
451
|
-
setSharedCacheSize(newSize);
|
|
452
|
-
}
|
|
453
|
-
memoryCache[cacheKey] = cacheEntry;
|
|
454
|
-
if (process.env.DEBUG_GUI_CACHE) {
|
|
455
|
-
console.info(`[hanzogui-cache] WRITE key=${cacheKey.slice(0, 8)} cacheSize=${Object.keys(memoryCache).length}`);
|
|
456
|
-
}
|
|
457
|
-
return cacheEntry;
|
|
458
|
-
})();
|
|
459
|
-
pending.set(cacheKey, extractionPromise);
|
|
460
|
-
try {
|
|
461
|
-
const result = await extractionPromise;
|
|
462
|
-
if (result) {
|
|
463
|
-
return formatResult(result);
|
|
464
|
-
}
|
|
465
|
-
return;
|
|
466
|
-
} finally {
|
|
467
|
-
pending.delete(cacheKey);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
};
|
|
472
|
-
return [basePlugin, rnwLitePlugin, extractPlugin];
|
|
473
|
-
}
|
package/dist/esm/extensions.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["extensions"],"sources":["../../src/extensions.ts"],"sourcesContent":[null],"mappings":"AAAO,MAAMA,UAAA,GAAa,CACxB,WACA,cACA,cACA,eACA,OACA,QACA,SACA,OACA,QACA,OACF","ignoreList":[]}
|
package/dist/esm/index.mjs
DELETED
package/dist/esm/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|
package/dist/esm/loadGui.mjs
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import * as StaticWorker from "@hanzogui/static-worker";
|
|
2
|
-
const LOAD_STATE_KEY = "__hanzogui_load_state__";
|
|
3
|
-
function getLoadState() {
|
|
4
|
-
if (!globalThis[LOAD_STATE_KEY]) {
|
|
5
|
-
;
|
|
6
|
-
globalThis[LOAD_STATE_KEY] = {
|
|
7
|
-
loadPromise: null,
|
|
8
|
-
loadedOptions: null,
|
|
9
|
-
fullConfigLoaded: false,
|
|
10
|
-
fullConfigLoadPromise: null
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
return globalThis[LOAD_STATE_KEY];
|
|
14
|
-
}
|
|
15
|
-
function getGuiOptions() {
|
|
16
|
-
return getLoadState().loadedOptions;
|
|
17
|
-
}
|
|
18
|
-
function getLoadPromise() {
|
|
19
|
-
return getLoadState().loadPromise;
|
|
20
|
-
}
|
|
21
|
-
async function loadGuiBuildConfig(optionsIn) {
|
|
22
|
-
const state = getLoadState();
|
|
23
|
-
if (state.loadedOptions) return state.loadedOptions;
|
|
24
|
-
if (state.loadPromise) return state.loadPromise;
|
|
25
|
-
state.loadPromise = (async () => {
|
|
26
|
-
const options = await StaticWorker.loadGuiBuildConfig({
|
|
27
|
-
...optionsIn,
|
|
28
|
-
platform: "web"
|
|
29
|
-
});
|
|
30
|
-
state.loadedOptions = options;
|
|
31
|
-
return options;
|
|
32
|
-
})();
|
|
33
|
-
return state.loadPromise;
|
|
34
|
-
}
|
|
35
|
-
async function ensureFullConfigLoaded() {
|
|
36
|
-
const state = getLoadState();
|
|
37
|
-
if (state.fullConfigLoaded) return;
|
|
38
|
-
if (state.fullConfigLoadPromise) return state.fullConfigLoadPromise;
|
|
39
|
-
state.fullConfigLoadPromise = (async () => {
|
|
40
|
-
const options = await loadGuiBuildConfig();
|
|
41
|
-
if (!options.disableWatchGuiConfig && !options.disable) {
|
|
42
|
-
await StaticWorker.loadGui({
|
|
43
|
-
components: ["@hanzo/gui"],
|
|
44
|
-
platform: "web",
|
|
45
|
-
...options
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
state.fullConfigLoaded = true;
|
|
49
|
-
})();
|
|
50
|
-
return state.fullConfigLoadPromise;
|
|
51
|
-
}
|
|
52
|
-
async function cleanup() {
|
|
53
|
-
await StaticWorker.destroyPool();
|
|
54
|
-
const state = getLoadState();
|
|
55
|
-
state.loadPromise = null;
|
|
56
|
-
state.loadedOptions = null;
|
|
57
|
-
state.fullConfigLoaded = false;
|
|
58
|
-
state.fullConfigLoadPromise = null;
|
|
59
|
-
}
|
|
60
|
-
export { cleanup, ensureFullConfigLoaded, getGuiOptions, getLoadPromise, loadGuiBuildConfig };
|
|
61
|
-
//# sourceMappingURL=loadGui.mjs.map
|
package/dist/esm/loadGui.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["StaticWorker","LOAD_STATE_KEY","getLoadState","globalThis","loadPromise","loadedOptions","fullConfigLoaded","fullConfigLoadPromise","getGuiOptions","getLoadPromise","loadGuiBuildConfig","optionsIn","state","options","platform","ensureFullConfigLoaded","disableWatchGuiConfig","disable","loadGui","components","cleanup","destroyPool"],"sources":["../../src/loadGui.ts"],"sourcesContent":[null],"mappings":"AAAA,YAAYA,YAAA,MAAkB;AAI9B,MAAMC,cAAA,GAAiB;AASvB,SAASC,aAAA,EAA0B;EACjC,IAAI,CAAEC,UAAA,CAAmBF,cAAc,GAAG;IACxC;IAAEE,UAAA,CAAmBF,cAAc,IAAI;MACrCG,WAAA,EAAa;MACbC,aAAA,EAAe;MACfC,gBAAA,EAAkB;MAClBC,qBAAA,EAAuB;IACzB;EACF;EACA,OAAQJ,UAAA,CAAmBF,cAAc;AAC3C;AAEO,SAASO,cAAA,EAAmC;EACjD,OAAON,YAAA,CAAa,EAAEG,aAAA;AACxB;AAEO,SAASI,eAAA,EAA6C;EAC3D,OAAOP,YAAA,CAAa,EAAEE,WAAA;AACxB;AAMA,eAAsBM,mBACpBC,SAAA,EACqB;EACrB,MAAMC,KAAA,GAAQV,YAAA,CAAa;EAC3B,IAAIU,KAAA,CAAMP,aAAA,EAAe,OAAOO,KAAA,CAAMP,aAAA;EACtC,IAAIO,KAAA,CAAMR,WAAA,EAAa,OAAOQ,KAAA,CAAMR,WAAA;EAEpCQ,KAAA,CAAMR,WAAA,IAAe,YAAY;IAC/B,MAAMS,OAAA,GAAU,MAAMb,YAAA,CAAaU,kBAAA,CAAmB;MACpD,GAAGC,SAAA;MACHG,QAAA,EAAU;IACZ,CAAC;IAEDF,KAAA,CAAMP,aAAA,GAAgBQ,OAAA;IACtB,OAAOA,OAAA;EACT,GAAG;EAEH,OAAOD,KAAA,CAAMR,WAAA;AACf;AAMA,eAAsBW,uBAAA,EAAwC;EAC5D,MAAMH,KAAA,GAAQV,YAAA,CAAa;EAE3B,IAAIU,KAAA,CAAMN,gBAAA,EAAkB;EAC5B,IAAIM,KAAA,CAAML,qBAAA,EAAuB,OAAOK,KAAA,CAAML,qBAAA;EAI9CK,KAAA,CAAML,qBAAA,IAAyB,YAAY;IACzC,MAAMM,OAAA,GAAU,MAAMH,kBAAA,CAAmB;IAGzC,IAAI,CAACG,OAAA,CAAQG,qBAAA,IAAyB,CAACH,OAAA,CAAQI,OAAA,EAAS;MACtD,MAAMjB,YAAA,CAAakB,OAAA,CAAQ;QACzBC,UAAA,EAAY,CAAC,YAAY;QACzBL,QAAA,EAAU;QACV,GAAGD;MACL,CAAC;IACH;IACAD,KAAA,CAAMN,gBAAA,GAAmB;EAC3B,GAAG;EAEH,OAAOM,KAAA,CAAML,qBAAA;AACf;AAEA,eAAsBa,QAAA,EAAU;EAC9B,MAAMpB,YAAA,CAAaqB,WAAA,CAAY;EAC/B,MAAMT,KAAA,GAAQV,YAAA,CAAa;EAC3BU,KAAA,CAAMR,WAAA,GAAc;EACpBQ,KAAA,CAAMP,aAAA,GAAgB;EACtBO,KAAA,CAAMN,gBAAA,GAAmB;EACzBM,KAAA,CAAML,qBAAA,GAAwB;AAChC","ignoreList":[]}
|