@hanzogui/vite-plugin 3.0.6 → 4.3.1
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.cjs +12 -10
- package/dist/cjs/index.cjs +7 -5
- package/dist/cjs/loadGui.cjs +58 -39
- package/dist/cjs/plugin.cjs +252 -122
- package/dist/esm/loadGui.mjs +34 -17
- package/dist/esm/loadGui.mjs.map +1 -1
- package/dist/esm/plugin.mjs +220 -92
- package/dist/esm/plugin.mjs.map +1 -1
- package/package.json +2 -2
- package/src/plugin.ts +15 -11
- package/types/plugin.d.ts.map +1 -1
package/dist/cjs/plugin.cjs
CHANGED
|
@@ -2,74 +2,90 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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);
|
|
32
34
|
var plugin_exports = {};
|
|
33
35
|
__export(plugin_exports, {
|
|
34
36
|
guiAliases: () => guiAliases,
|
|
35
37
|
guiPlugin: () => guiPlugin
|
|
36
38
|
});
|
|
37
39
|
module.exports = __toCommonJS(plugin_exports);
|
|
38
|
-
var Static = __toESM(require("@hanzogui/static-worker"), 1)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const import_meta = {}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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_path = __toESM(require("node:path"), 1);
|
|
44
|
+
var import_node_url = require("node:url");
|
|
45
|
+
var import_vite = require("vite");
|
|
46
|
+
var import_loadGui = require("./loadGui.cjs");
|
|
47
|
+
const import_meta = {};
|
|
48
|
+
const resolve = name => (0, import_node_url.fileURLToPath)(import_meta.resolve(name));
|
|
49
|
+
const CACHE_KEY = "__gui_vite_cache__";
|
|
50
|
+
const CACHE_SIZE_KEY = "__gui_vite_cache_size__";
|
|
51
|
+
const PENDING_KEY = "__gui_vite_pending__";
|
|
50
52
|
function getSharedCache() {
|
|
51
|
-
|
|
53
|
+
if (!globalThis[CACHE_KEY]) {
|
|
54
|
+
;
|
|
55
|
+
globalThis[CACHE_KEY] = {};
|
|
56
|
+
}
|
|
57
|
+
return globalThis[CACHE_KEY];
|
|
52
58
|
}
|
|
53
59
|
function getSharedCacheSize() {
|
|
54
60
|
return globalThis[CACHE_SIZE_KEY] || 0;
|
|
55
61
|
}
|
|
56
62
|
function setSharedCacheSize(size) {
|
|
63
|
+
;
|
|
57
64
|
globalThis[CACHE_SIZE_KEY] = size;
|
|
58
65
|
}
|
|
59
66
|
function clearSharedCache() {
|
|
60
|
-
|
|
67
|
+
;
|
|
68
|
+
globalThis[CACHE_KEY] = {};
|
|
69
|
+
globalThis[CACHE_SIZE_KEY] = 0;
|
|
61
70
|
}
|
|
62
71
|
function getPendingExtractions() {
|
|
63
|
-
|
|
72
|
+
if (!globalThis[PENDING_KEY]) {
|
|
73
|
+
;
|
|
74
|
+
globalThis[PENDING_KEY] = /* @__PURE__ */new Map();
|
|
75
|
+
}
|
|
76
|
+
return globalThis[PENDING_KEY];
|
|
64
77
|
}
|
|
65
78
|
function guiAliases(options = {}) {
|
|
66
79
|
const aliases = [];
|
|
67
|
-
if (options.svg
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
80
|
+
if (options.svg) {
|
|
81
|
+
aliases.push({
|
|
82
|
+
find: "react-native-svg",
|
|
83
|
+
replacement: resolve("@hanzogui/react-native-svg")
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (options.rnwLite) {
|
|
87
|
+
const rnwl = resolve(options.rnwLite === "without-animated" ? "@hanzogui/react-native-web-lite/without-animated" : "@hanzogui/react-native-web-lite");
|
|
88
|
+
const rnwlBase = import_node_path.default.dirname(resolve("@hanzogui/react-native-web-lite/package.json"));
|
|
73
89
|
aliases.push({
|
|
74
90
|
// map deep RNW paths like dist/exports/StyleSheet/preprocess to rnw-lite's flat structure
|
|
75
91
|
// extracts the final path segment (e.g. "preprocess" or "createReactDOMStyle")
|
|
@@ -95,23 +111,32 @@ function guiPlugin({
|
|
|
95
111
|
disableResolveConfig,
|
|
96
112
|
...guiOptionsIn
|
|
97
113
|
} = {}) {
|
|
98
|
-
let shouldExtract = !guiOptionsIn.disableExtraction
|
|
99
|
-
|
|
100
|
-
const enableNativeEnv = !!globalThis.__vxrnEnableNativeEnv
|
|
101
|
-
|
|
114
|
+
let shouldExtract = !guiOptionsIn.disableExtraction;
|
|
115
|
+
let watcher;
|
|
116
|
+
const enableNativeEnv = !!globalThis.__vxrnEnableNativeEnv;
|
|
117
|
+
const extensions = [`.web.mjs`, `.web.js`, `.web.jsx`, `.web.ts`, `.web.tsx`, ".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json"];
|
|
102
118
|
(0, import_loadGui.loadGuiBuildConfig)(guiOptionsIn);
|
|
103
119
|
const ensureLoaded = async () => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
|
|
120
|
+
const promise = (0, import_loadGui.getLoadPromise)();
|
|
121
|
+
if (promise) await promise;
|
|
122
|
+
const options = (0, import_loadGui.getGuiOptions)();
|
|
123
|
+
if (options) {
|
|
124
|
+
shouldExtract = !options.disableExtraction;
|
|
125
|
+
}
|
|
126
|
+
return options;
|
|
127
|
+
};
|
|
128
|
+
const getHash = input => (0, import_node_crypto.createHash)("sha1").update(input).digest("base64");
|
|
129
|
+
const memoryCache = getSharedCache();
|
|
130
|
+
const cssMap = /* @__PURE__ */new Map();
|
|
131
|
+
let config;
|
|
132
|
+
let server;
|
|
133
|
+
const virtualExt = `.gui.css`;
|
|
134
|
+
const getAbsoluteVirtualFileId = filePath => {
|
|
135
|
+
if (filePath.startsWith(config.root)) {
|
|
136
|
+
return filePath;
|
|
137
|
+
}
|
|
138
|
+
return (0, import_vite.normalizePath)(import_node_path.default.join(config.root, filePath));
|
|
139
|
+
};
|
|
115
140
|
function isNotClient(environment) {
|
|
116
141
|
return environment?.name && environment.name !== "client";
|
|
117
142
|
}
|
|
@@ -121,12 +146,17 @@ function guiPlugin({
|
|
|
121
146
|
function invalidateModule(absoluteId) {
|
|
122
147
|
if (!server) return;
|
|
123
148
|
const {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (modules)
|
|
149
|
+
moduleGraph
|
|
150
|
+
} = server;
|
|
151
|
+
const modules = moduleGraph.getModulesByFile(absoluteId);
|
|
152
|
+
if (modules) {
|
|
153
|
+
for (const module2 of modules) {
|
|
154
|
+
moduleGraph.invalidateModule(module2);
|
|
155
|
+
module2.lastHMRTimestamp = module2.lastInvalidationTimestamp || Date.now();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
128
158
|
}
|
|
129
|
-
|
|
159
|
+
const basePlugin = {
|
|
130
160
|
name: "hanzo-gui",
|
|
131
161
|
enforce: "pre",
|
|
132
162
|
configureServer(_server) {
|
|
@@ -138,41 +168,48 @@ function guiPlugin({
|
|
|
138
168
|
});
|
|
139
169
|
},
|
|
140
170
|
async transform(code, id) {
|
|
141
|
-
if (id.includes("expo-linear-gradient"))
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
171
|
+
if (id.includes("expo-linear-gradient")) {
|
|
172
|
+
return (0, import_vite.transformWithEsbuild)(code, id, {
|
|
173
|
+
loader: "jsx",
|
|
174
|
+
jsx: "automatic"
|
|
175
|
+
});
|
|
176
|
+
}
|
|
145
177
|
},
|
|
146
178
|
async config(_, env) {
|
|
147
179
|
const options = await ensureLoaded();
|
|
148
|
-
if (!options)
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
180
|
+
if (!options) {
|
|
181
|
+
throw new Error(`No hanzo-gui options loaded`);
|
|
182
|
+
}
|
|
183
|
+
if (!options.disableWatchGuiConfig) {
|
|
184
|
+
watcher = Static.watchGuiConfig({
|
|
185
|
+
components: ["@hanzo/gui"],
|
|
186
|
+
config: "./src/gui.config.ts",
|
|
187
|
+
...options
|
|
188
|
+
}).catch(err => {
|
|
189
|
+
console.error(` [GUI] Error watching config: ${err}`);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
envPrefix: ["GUI_"],
|
|
157
194
|
environments: {
|
|
158
195
|
client: {
|
|
159
196
|
define: {
|
|
160
|
-
"process.env.
|
|
161
|
-
"process.env.
|
|
197
|
+
"process.env.GUI_IS_CLIENT": JSON.stringify(true),
|
|
198
|
+
"process.env.GUI_ENVIRONMENT": '"client"'
|
|
162
199
|
}
|
|
163
200
|
}
|
|
164
201
|
},
|
|
165
202
|
define: {
|
|
166
203
|
// reanimated support
|
|
167
204
|
_frameTimestamp: void 0,
|
|
168
|
-
_WORKLET:
|
|
205
|
+
_WORKLET: false,
|
|
169
206
|
__DEV__: `${env.mode === "development"}`,
|
|
170
207
|
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || env.mode),
|
|
171
208
|
"process.env.ENABLE_RSC": JSON.stringify(process.env.ENABLE_RSC || ""),
|
|
172
209
|
"process.env.ENABLE_STEPS": JSON.stringify(process.env.ENABLE_STEPS || ""),
|
|
173
|
-
"process.env.IS_STATIC": JSON.stringify(
|
|
210
|
+
"process.env.IS_STATIC": JSON.stringify(false),
|
|
174
211
|
...(env.mode === "production" && {
|
|
175
|
-
"process.env.
|
|
212
|
+
"process.env.GUI_OPTIMIZE_THEMES": JSON.stringify(true)
|
|
176
213
|
})
|
|
177
214
|
},
|
|
178
215
|
resolve: disableResolveConfig || enableNativeEnv ? {} : {
|
|
@@ -190,38 +227,73 @@ function guiPlugin({
|
|
|
190
227
|
}
|
|
191
228
|
};
|
|
192
229
|
}
|
|
193
|
-
}
|
|
230
|
+
};
|
|
231
|
+
const rnwLitePlugin = {
|
|
194
232
|
name: "gui-rnw-lite",
|
|
195
233
|
config() {
|
|
196
|
-
if (enableNativeEnv)
|
|
234
|
+
if (enableNativeEnv) {
|
|
235
|
+
return {};
|
|
236
|
+
}
|
|
197
237
|
const options = (0, import_loadGui.getGuiOptions)();
|
|
198
|
-
|
|
238
|
+
if (!options?.useReactNativeWebLite) {
|
|
239
|
+
return {};
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
199
242
|
resolve: {
|
|
200
243
|
alias: guiAliases({
|
|
201
244
|
rnwLite: options.useReactNativeWebLite
|
|
202
245
|
})
|
|
246
|
+
},
|
|
247
|
+
optimizeDeps: {
|
|
248
|
+
// upstream react-native-web must not be pre-bundled when aliased to lite
|
|
249
|
+
exclude: ["react-native-web"]
|
|
203
250
|
}
|
|
204
|
-
}
|
|
251
|
+
};
|
|
205
252
|
}
|
|
206
|
-
}
|
|
253
|
+
};
|
|
254
|
+
const extractPlugin = {
|
|
207
255
|
name: "gui-extract",
|
|
208
256
|
enforce: "pre",
|
|
209
257
|
async config(userConf) {
|
|
210
258
|
const options = await ensureLoaded();
|
|
211
|
-
userConf.optimizeDeps ||= {}
|
|
259
|
+
userConf.optimizeDeps ||= {};
|
|
260
|
+
userConf.optimizeDeps.include ||= [];
|
|
261
|
+
userConf.optimizeDeps.include.push("inline-style-prefixer");
|
|
262
|
+
if (!shouldExtract) return;
|
|
263
|
+
userConf.optimizeDeps.include.push("@hanzogui/core/inject-styles");
|
|
212
264
|
},
|
|
213
265
|
async configResolved(resolvedConfig) {
|
|
214
266
|
config = resolvedConfig;
|
|
215
267
|
},
|
|
216
268
|
async resolveId(source) {
|
|
217
|
-
if (!shouldExtract
|
|
269
|
+
if (!shouldExtract) return;
|
|
270
|
+
if (isNative(this.environment)) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (isNotClient(this.environment)) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
218
276
|
const [validId, query] = source.split("?");
|
|
219
|
-
if (!validId.endsWith(virtualExt))
|
|
277
|
+
if (!validId.endsWith(virtualExt)) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
220
280
|
const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId);
|
|
221
|
-
if (cssMap.has(absoluteId))
|
|
281
|
+
if (cssMap.has(absoluteId)) {
|
|
282
|
+
return absoluteId + (query ? `?${query}` : "");
|
|
283
|
+
}
|
|
222
284
|
},
|
|
223
285
|
async load(id) {
|
|
224
|
-
if (!shouldExtract
|
|
286
|
+
if (!shouldExtract) return;
|
|
287
|
+
const options = (0, import_loadGui.getGuiOptions)();
|
|
288
|
+
if (options?.disable) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
if (isNative(this.environment)) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
if (isNotClient(this.environment)) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
225
297
|
const [validId] = id.split("?");
|
|
226
298
|
return cssMap.get(validId);
|
|
227
299
|
},
|
|
@@ -229,9 +301,17 @@ function guiPlugin({
|
|
|
229
301
|
order: "pre",
|
|
230
302
|
async handler(code, id) {
|
|
231
303
|
const options = await ensureLoaded();
|
|
232
|
-
|
|
304
|
+
await (0, import_loadGui.ensureFullConfigLoaded)();
|
|
305
|
+
if (options?.disable) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (isNative(this.environment)) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
233
311
|
const [validId] = id.split("?");
|
|
234
|
-
if (!validId.endsWith(".tsx"))
|
|
312
|
+
if (!validId.endsWith(".tsx")) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
235
315
|
const {
|
|
236
316
|
shouldDisable,
|
|
237
317
|
shouldPrintDebug
|
|
@@ -239,29 +319,50 @@ function guiPlugin({
|
|
|
239
319
|
source: code,
|
|
240
320
|
path: validId
|
|
241
321
|
});
|
|
242
|
-
if (shouldPrintDebug
|
|
322
|
+
if (shouldPrintDebug) {
|
|
323
|
+
console.trace(`Current file: ${id} in environment: ${this.environment?.name}, shouldDisable: ${shouldDisable}`);
|
|
324
|
+
console.info(`
|
|
243
325
|
|
|
244
326
|
Original source:
|
|
245
327
|
${code}
|
|
246
328
|
|
|
247
|
-
`)
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
${
|
|
329
|
+
`);
|
|
330
|
+
}
|
|
331
|
+
if (shouldDisable) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const isSSR = isNotClient(this.environment);
|
|
335
|
+
const cacheKey = getHash(`${code}${id}`);
|
|
336
|
+
const pending = getPendingExtractions();
|
|
337
|
+
const formatResult = entry => {
|
|
338
|
+
const finalCode = !isSSR && entry.cssImport ? `${entry.js}
|
|
339
|
+
${entry.cssImport}` : entry.js;
|
|
340
|
+
return {
|
|
341
|
+
code: finalCode,
|
|
254
342
|
map: entry.map
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
const cached = memoryCache[cacheKey];
|
|
346
|
+
if (cached) {
|
|
347
|
+
if (process.env.DEBUG_GUI_CACHE) {
|
|
348
|
+
console.info(`[gui-cache] HIT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
|
|
349
|
+
}
|
|
350
|
+
return formatResult(cached);
|
|
351
|
+
}
|
|
258
352
|
const pendingExtraction = pending.get(cacheKey);
|
|
259
353
|
if (pendingExtraction) {
|
|
260
|
-
process.env.
|
|
354
|
+
if (process.env.DEBUG_GUI_CACHE) {
|
|
355
|
+
console.info(`[gui-cache] WAIT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
|
|
356
|
+
}
|
|
261
357
|
const result = await pendingExtraction;
|
|
262
|
-
|
|
358
|
+
if (result) {
|
|
359
|
+
return formatResult(result);
|
|
360
|
+
}
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
if (process.env.DEBUG_GUI_CACHE) {
|
|
364
|
+
console.info(`[gui-cache] EXTRACT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
|
|
263
365
|
}
|
|
264
|
-
process.env.DEBUG_HANZO_GUI_CACHE && console.info(`[gui-cache] EXTRACT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
|
|
265
366
|
const extractionPromise = (async () => {
|
|
266
367
|
let extracted;
|
|
267
368
|
try {
|
|
@@ -272,30 +373,59 @@ ${entry.cssImport}` : entry.js,
|
|
|
272
373
|
shouldPrintDebug
|
|
273
374
|
});
|
|
274
375
|
} catch (err) {
|
|
275
|
-
|
|
376
|
+
if (process.env.DEBUG_GUI_CACHE) {
|
|
377
|
+
console.info(`[gui-cache] ERROR extracting ${id.split("/").pop()}:`, err);
|
|
378
|
+
}
|
|
379
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
if (!extracted) {
|
|
383
|
+
if (process.env.DEBUG_GUI_CACHE) {
|
|
384
|
+
console.info(`[gui-cache] no extraction result for ${id.split("/").pop()}`);
|
|
385
|
+
}
|
|
386
|
+
return null;
|
|
276
387
|
}
|
|
277
|
-
|
|
278
|
-
const
|
|
279
|
-
absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
|
|
388
|
+
const rootRelativeId = `${validId}${virtualExt}`;
|
|
389
|
+
const absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
|
|
280
390
|
let cssImport = null;
|
|
281
|
-
extracted.styles
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
391
|
+
if (extracted.styles) {
|
|
392
|
+
this.addWatchFile(rootRelativeId);
|
|
393
|
+
if (server && cssMap.has(absoluteId)) {
|
|
394
|
+
invalidateModule(rootRelativeId);
|
|
395
|
+
}
|
|
396
|
+
cssImport = `import "${rootRelativeId}";`;
|
|
397
|
+
cssMap.set(absoluteId, extracted.styles);
|
|
398
|
+
}
|
|
399
|
+
const jsCode = extracted.js.toString();
|
|
400
|
+
const cacheEntry = {
|
|
401
|
+
js: jsCode,
|
|
402
|
+
map: extracted.map,
|
|
403
|
+
cssImport
|
|
404
|
+
};
|
|
405
|
+
const newSize = getSharedCacheSize() + jsCode.length;
|
|
406
|
+
if (newSize > 67108864) {
|
|
407
|
+
clearSharedCache();
|
|
408
|
+
} else {
|
|
409
|
+
setSharedCacheSize(newSize);
|
|
410
|
+
}
|
|
411
|
+
memoryCache[cacheKey] = cacheEntry;
|
|
412
|
+
if (process.env.DEBUG_GUI_CACHE) {
|
|
413
|
+
console.info(`[gui-cache] WRITE key=${cacheKey.slice(0, 8)} cacheSize=${Object.keys(memoryCache).length}`);
|
|
414
|
+
}
|
|
415
|
+
return cacheEntry;
|
|
290
416
|
})();
|
|
291
417
|
pending.set(cacheKey, extractionPromise);
|
|
292
418
|
try {
|
|
293
419
|
const result = await extractionPromise;
|
|
294
|
-
|
|
420
|
+
if (result) {
|
|
421
|
+
return formatResult(result);
|
|
422
|
+
}
|
|
423
|
+
return;
|
|
295
424
|
} finally {
|
|
296
425
|
pending.delete(cacheKey);
|
|
297
426
|
}
|
|
298
427
|
}
|
|
299
428
|
}
|
|
300
|
-
}
|
|
429
|
+
};
|
|
430
|
+
return [basePlugin, rnwLitePlugin, extractPlugin];
|
|
301
431
|
}
|
package/dist/esm/loadGui.mjs
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import * as StaticWorker from "@hanzogui/static-worker";
|
|
2
2
|
const LOAD_STATE_KEY = "__gui_load_state__";
|
|
3
3
|
function getLoadState() {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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];
|
|
10
14
|
}
|
|
11
15
|
function getGuiOptions() {
|
|
12
16
|
return getLoadState().loadedOptions;
|
|
@@ -16,29 +20,42 @@ function getLoadPromise() {
|
|
|
16
20
|
}
|
|
17
21
|
async function loadGuiBuildConfig(optionsIn) {
|
|
18
22
|
const state = getLoadState();
|
|
19
|
-
|
|
23
|
+
if (state.loadedOptions) return state.loadedOptions;
|
|
24
|
+
if (state.loadPromise) return state.loadPromise;
|
|
25
|
+
state.loadPromise = (async () => {
|
|
20
26
|
const options = await StaticWorker.loadGuiBuildConfig({
|
|
21
27
|
...optionsIn,
|
|
22
28
|
platform: "web"
|
|
23
29
|
});
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
state.loadedOptions = options;
|
|
31
|
+
return options;
|
|
32
|
+
})();
|
|
33
|
+
return state.loadPromise;
|
|
26
34
|
}
|
|
27
35
|
async function ensureFullConfigLoaded() {
|
|
28
36
|
const state = getLoadState();
|
|
29
|
-
if (
|
|
37
|
+
if (state.fullConfigLoaded) return;
|
|
38
|
+
if (state.fullConfigLoadPromise) return state.fullConfigLoadPromise;
|
|
39
|
+
state.fullConfigLoadPromise = (async () => {
|
|
30
40
|
const options = await loadGuiBuildConfig();
|
|
31
|
-
!options.disableWatchGuiConfig && !options.disable
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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;
|
|
37
51
|
}
|
|
38
52
|
async function cleanup() {
|
|
39
53
|
await StaticWorker.destroyPool();
|
|
40
54
|
const state = getLoadState();
|
|
41
|
-
state.loadPromise = null
|
|
55
|
+
state.loadPromise = null;
|
|
56
|
+
state.loadedOptions = null;
|
|
57
|
+
state.fullConfigLoaded = false;
|
|
58
|
+
state.fullConfigLoadPromise = null;
|
|
42
59
|
}
|
|
43
60
|
export { cleanup, ensureFullConfigLoaded, getGuiOptions, getLoadPromise, loadGuiBuildConfig };
|
|
44
61
|
//# sourceMappingURL=loadGui.mjs.map
|
package/dist/esm/loadGui.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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":[]}
|