@hanzogui/static 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.
Files changed (67) hide show
  1. package/dist/check-dep-versions.cjs +201 -96
  2. package/dist/checkDeps.cjs +163 -92
  3. package/dist/constants.cjs +32 -30
  4. package/dist/exports.cjs +15 -13
  5. package/dist/extractor/accessSafe.cjs +25 -23
  6. package/dist/extractor/babelParse.cjs +30 -28
  7. package/dist/extractor/buildClassName.cjs +59 -35
  8. package/dist/extractor/bundle.cjs +159 -104
  9. package/dist/extractor/bundleConfig.cjs +463 -263
  10. package/dist/extractor/concatClassName.cjs +41 -29
  11. package/dist/extractor/createEvaluator.cjs +54 -41
  12. package/dist/extractor/createExtractor.cjs +1338 -661
  13. package/dist/extractor/createLogger.cjs +30 -25
  14. package/dist/extractor/detectModuleFormat.cjs +22 -16
  15. package/dist/extractor/ensureImportingConcat.cjs +31 -25
  16. package/dist/extractor/errors.cjs +12 -10
  17. package/dist/extractor/esbuildAliasPlugin.cjs +28 -16
  18. package/dist/extractor/esbuildTsconfigPaths.cjs +58 -36
  19. package/dist/extractor/evaluateAstNode.cjs +104 -59
  20. package/dist/extractor/extractHelpers.cjs +130 -67
  21. package/dist/extractor/extractMediaStyle.cjs +110 -69
  22. package/dist/extractor/extractToClassNames.cjs +336 -230
  23. package/dist/extractor/extractToNative.cjs +244 -149
  24. package/dist/extractor/findTopmostFunction.cjs +22 -13
  25. package/dist/extractor/generatedUid.cjs +39 -28
  26. package/dist/extractor/getGuiConfigPathFromOptionsConfig.cjs +20 -14
  27. package/dist/extractor/getPrefixLogs.cjs +12 -10
  28. package/dist/extractor/getPropValueFromAttributes.cjs +52 -34
  29. package/dist/extractor/getSourceModule.cjs +73 -37
  30. package/dist/extractor/getStaticBindingsForScope.cjs +131 -68
  31. package/dist/extractor/hoistClassNames.cjs +46 -32
  32. package/dist/extractor/literalToAst.cjs +67 -42
  33. package/dist/extractor/loadFile.cjs +9 -3
  34. package/dist/extractor/loadGui.cjs +198 -109
  35. package/dist/extractor/logLines.cjs +27 -19
  36. package/dist/extractor/normalizeTernaries.cjs +66 -44
  37. package/dist/extractor/propsToFontFamilyCache.cjs +15 -11
  38. package/dist/extractor/regenerateConfig.cjs +109 -81
  39. package/dist/extractor/removeUnusedHooks.cjs +73 -41
  40. package/dist/extractor/timer.cjs +23 -14
  41. package/dist/extractor/validHTMLAttributes.cjs +61 -59
  42. package/dist/extractor/watchGuiConfig.cjs +35 -23
  43. package/dist/getPragmaOptions.cjs +34 -19
  44. package/dist/helpers/memoize.cjs +24 -16
  45. package/dist/helpers/requireGuiCore.cjs +22 -15
  46. package/dist/index.cjs +26 -24
  47. package/dist/registerRequire.cjs +132 -77
  48. package/dist/server.cjs +35 -28
  49. package/dist/types.cjs +7 -5
  50. package/dist/worker.cjs +62 -40
  51. package/package.json +2 -2
  52. package/src/checkDeps.ts +1 -1
  53. package/src/extractor/bundle.ts +1 -1
  54. package/src/extractor/bundleConfig.ts +5 -5
  55. package/src/extractor/createExtractor.ts +28 -13
  56. package/src/extractor/createLogger.ts +1 -3
  57. package/src/extractor/extractToNative.ts +35 -9
  58. package/src/extractor/loadGui.ts +4 -4
  59. package/src/extractor/regenerateConfig.ts +2 -2
  60. package/src/getPragmaOptions.ts +2 -2
  61. package/src/helpers/requireGuiCore.ts +6 -6
  62. package/src/registerRequire.ts +4 -4
  63. package/src/worker.ts +1 -1
  64. package/types/extractor/createExtractor.d.ts.map +1 -1
  65. package/types/extractor/createLogger.d.ts.map +1 -1
  66. package/types/extractor/extractToNative.d.ts.map +1 -1
  67. package/types/worker.d.ts +1 -1
@@ -2,33 +2,35 @@ 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
- __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: !0
11
- });
12
- },
13
- __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
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
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
- value: mod,
27
- enumerable: !0
28
- }) : target, mod)),
29
- __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
- value: !0
31
- }), mod);
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 bundleConfig_exports = {};
33
35
  __export(bundleConfig_exports, {
34
36
  bundleConfig: () => bundleConfig,
@@ -44,143 +46,200 @@ __export(bundleConfig_exports, {
44
46
  writeGuiCSS: () => writeGuiCSS
45
47
  });
46
48
  module.exports = __toCommonJS(bundleConfig_exports);
47
- var import_generator = __toESM(require("@babel/generator")),
48
- import_traverse = __toESM(require("@babel/traverse")),
49
- t = __toESM(require("@babel/types")),
50
- import_node_crypto = require("node:crypto"),
51
- import_node_fs = require("node:fs"),
52
- import_node_path = require("node:path"),
53
- import_node_url = require("node:url"),
54
- import_cli_color = require("@hanzogui/cli-color"),
55
- import_esbuild = __toESM(require("esbuild")),
56
- FS = __toESM(require("fs-extra")),
57
- import_promises = require("node:fs/promises"),
58
- import_registerRequire = require("../registerRequire.cjs"),
59
- import_babelParse = require("./babelParse.cjs"),
60
- import_bundle = require("./bundle.cjs"),
61
- import_getGuiConfigPathFromOptionsConfig = require("./getGuiConfigPathFromOptionsConfig.cjs"),
62
- import_requireGuiCore = require("../helpers/requireGuiCore.cjs"),
63
- import_detectModuleFormat = require("./detectModuleFormat.cjs");
49
+ var import_generator = __toESM(require("@babel/generator"));
50
+ var import_traverse = __toESM(require("@babel/traverse"));
51
+ var t = __toESM(require("@babel/types"));
52
+ var import_node_crypto = require("node:crypto");
53
+ var import_node_fs = require("node:fs");
54
+ var import_node_path = require("node:path");
55
+ var import_node_url = require("node:url");
56
+ var import_cli_color = require("@hanzogui/cli-color");
57
+ var import_esbuild = __toESM(require("esbuild"));
58
+ var FS = __toESM(require("fs-extra"));
59
+ var import_promises = require("node:fs/promises");
60
+ var import_registerRequire = require("../registerRequire.cjs");
61
+ var import_babelParse = require("./babelParse.cjs");
62
+ var import_bundle = require("./bundle.cjs");
63
+ var import_getGuiConfigPathFromOptionsConfig = require("./getGuiConfigPathFromOptionsConfig.cjs");
64
+ var import_requireGuiCore = require("../helpers/requireGuiCore.cjs");
65
+ var import_detectModuleFormat = require("./detectModuleFormat.cjs");
64
66
  const activeTempFiles = /* @__PURE__ */new Set();
65
67
  function getDynamicEvalOutfile(name, format, contents) {
66
- const ext = format === "esm" ? "mjs" : "cjs",
67
- hash = (0, import_node_crypto.createHash)("sha1").update(name).update("\0").update(format).update("\0").update(contents).digest("hex").slice(0, 10);
68
+ const ext = format === "esm" ? "mjs" : "cjs";
69
+ const hash = (0, import_node_crypto.createHash)("sha1").update(name).update("\0").update(format).update("\0").update(contents).digest("hex").slice(0, 10);
68
70
  return (0, import_node_path.join)(process.cwd(), ".gui", `dynamic-eval-${hash}-${(0, import_node_path.basename)(name)}.${ext}`);
69
71
  }
70
72
  function getEsbuildStdinLoader(filePath) {
71
- return filePath.endsWith(".tsx") ? "tsx" : filePath.endsWith(".ts") ? "ts" : filePath.endsWith(".jsx") ? "jsx" : "js";
73
+ if (filePath.endsWith(".tsx")) return "tsx";
74
+ if (filePath.endsWith(".ts")) return "ts";
75
+ if (filePath.endsWith(".jsx")) return "jsx";
76
+ return "js";
72
77
  }
73
78
  function resolvePackageEntry(packageName, format) {
74
- if (format === "cjs") return require.resolve(packageName);
75
- const packageJsonPath = require.resolve(`${packageName}/package.json`),
76
- packageJson = JSON.parse((0, import_node_fs.readFileSync)(packageJsonPath, "utf-8")),
77
- packageRoot = (0, import_node_path.dirname)(packageJsonPath),
78
- exportEntry = packageJson.exports?.["."],
79
- esmEntry = exportEntry?.import || exportEntry?.module || exportEntry?.browser || packageJson.module;
80
- return typeof esmEntry == "string" ? (0, import_node_path.join)(packageRoot, esmEntry) : require.resolve(packageName);
79
+ if (format === "cjs") {
80
+ return require.resolve(packageName);
81
+ }
82
+ const packageJsonPath = require.resolve(`${packageName}/package.json`);
83
+ const packageJson = JSON.parse((0, import_node_fs.readFileSync)(packageJsonPath, "utf-8"));
84
+ const packageRoot = (0, import_node_path.dirname)(packageJsonPath);
85
+ const exportEntry = packageJson.exports?.["."];
86
+ const esmEntry = exportEntry?.import || exportEntry?.module || exportEntry?.browser || packageJson.module;
87
+ if (typeof esmEntry === "string") {
88
+ return (0, import_node_path.join)(packageRoot, esmEntry);
89
+ }
90
+ return require.resolve(packageName);
81
91
  }
82
92
  function cleanupTempFiles() {
83
- for (const f of activeTempFiles) try {
84
- (0, import_node_fs.unlinkSync)(f);
85
- } catch {}
93
+ for (const f of activeTempFiles) {
94
+ try {
95
+ (0, import_node_fs.unlinkSync)(f);
96
+ } catch {}
97
+ }
86
98
  activeTempFiles.clear();
87
99
  }
88
100
  process.on("exit", cleanupTempFiles);
89
101
  process.on("SIGINT", () => {
90
- cleanupTempFiles(), process.exit();
102
+ cleanupTempFiles();
103
+ process.exit();
91
104
  });
92
105
  process.on("SIGTERM", () => {
93
- cleanupTempFiles(), process.exit();
106
+ cleanupTempFiles();
107
+ process.exit();
94
108
  });
95
- const external = ["@hanzogui/core", "@hanzogui/web", "react", "react-dom", "react-native-svg"],
96
- esbuildExtraOptions = {
97
- define: {
98
- __DEV__: `${process.env.NODE_ENV === "development"}`
99
- }
100
- },
101
- handleEsmFeaturesPlugin = {
102
- name: "handle-esm-features",
103
- setup(build) {
104
- const isCjs = build.initialOptions.format === "cjs" || !build.initialOptions.format;
105
- build.onLoad({
106
- filter: /\.(ts|tsx|js|jsx|mjs)$/
107
- }, args => {
108
- if (!isCjs || args.path.includes("node_modules") && !args.path.includes("@gui")) return null;
109
- let contents = (0, import_node_fs.readFileSync)(args.path, "utf8"),
110
- modified = !1;
111
- return contents.includes("import.meta.env") && (contents = contents.replace(/import\.meta\.env/g, "process.env"), modified = !0), contents.includes("import.meta.url") && (contents = contents.replace(/import\.meta\.url/g, '""'), modified = !0), contents.includes("import.meta.main") && (contents = contents.replace(/import\.meta\.main/g, "false"), modified = !0), /^\s*(?:const|let|var|export)\s+[^=]*=\s*await\b/m.test(contents) || /^await\s/m.test(contents) ? (process.env.DEBUG?.startsWith("@hanzo/gui") && console.info(`[hanzo-gui] stubbing file with top-level await: ${args.path}`), {
109
+ const external = ["@hanzogui/core", "@hanzogui/web", "react", "react-dom", "react-native-svg"];
110
+ const esbuildExtraOptions = {
111
+ define: {
112
+ __DEV__: `${process.env.NODE_ENV === "development"}`
113
+ }
114
+ };
115
+ const handleEsmFeaturesPlugin = {
116
+ name: "handle-esm-features",
117
+ setup(build) {
118
+ const isCjs = build.initialOptions.format === "cjs" || !build.initialOptions.format;
119
+ build.onLoad({
120
+ filter: /\.(ts|tsx|js|jsx|mjs)$/
121
+ }, args => {
122
+ if (!isCjs) {
123
+ return null;
124
+ }
125
+ if (args.path.includes("node_modules") && !args.path.includes("@gui")) {
126
+ return null;
127
+ }
128
+ let contents = (0, import_node_fs.readFileSync)(args.path, "utf8");
129
+ let modified = false;
130
+ if (contents.includes("import.meta.env")) {
131
+ contents = contents.replace(/import\.meta\.env/g, "process.env");
132
+ modified = true;
133
+ }
134
+ if (contents.includes("import.meta.url")) {
135
+ contents = contents.replace(/import\.meta\.url/g, '""');
136
+ modified = true;
137
+ }
138
+ if (contents.includes("import.meta.main")) {
139
+ contents = contents.replace(/import\.meta\.main/g, "false");
140
+ modified = true;
141
+ }
142
+ if (/^\s*(?:const|let|var|export)\s+[^=]*=\s*await\b/m.test(contents) || /^await\s/m.test(contents)) {
143
+ if (process.env.DEBUG?.startsWith("@hanzo/gui")) {
144
+ console.info(`[hanzo-gui] stubbing file with top-level await: ${args.path}`);
145
+ }
146
+ return {
112
147
  contents: `// stubbed - contains top-level await
113
148
  module.exports = {}`,
114
149
  loader: "js"
115
- }) : modified ? {
150
+ };
151
+ }
152
+ if (modified) {
153
+ return {
116
154
  contents,
117
155
  loader: args.path.endsWith(".tsx") ? "tsx" : args.path.endsWith(".ts") ? "ts" : args.path.endsWith(".jsx") ? "jsx" : "js"
118
- } : null;
119
- });
120
- }
121
- },
122
- esbuildTransformOptions = {
123
- target: "es2022",
124
- format: "cjs",
125
- jsx: "automatic",
126
- platform: "node",
127
- ...esbuildExtraOptions
128
- },
129
- esbuildOptions = {
130
- ...esbuildTransformOptions
131
- },
132
- esbuildOptionsWithPlugins = {
133
- ...esbuildTransformOptions,
134
- plugins: [handleEsmFeaturesPlugin]
135
- };
136
- let currentBundle = null,
137
- isBundling = !1,
138
- lastBundle = null;
156
+ };
157
+ }
158
+ return null;
159
+ });
160
+ }
161
+ };
162
+ const esbuildTransformOptions = {
163
+ target: "es2022",
164
+ format: "cjs",
165
+ jsx: "automatic",
166
+ platform: "node",
167
+ ...esbuildExtraOptions
168
+ };
169
+ const esbuildOptions = {
170
+ ...esbuildTransformOptions
171
+ };
172
+ const esbuildOptionsWithPlugins = {
173
+ ...esbuildTransformOptions,
174
+ plugins: [handleEsmFeaturesPlugin]
175
+ };
176
+ let currentBundle = null;
177
+ let isBundling = false;
178
+ let lastBundle = null;
139
179
  const waitForBundle = /* @__PURE__ */new Set();
140
180
  function hasBundledConfigChanged() {
141
- return lastBundle === currentBundle ? !1 : (lastBundle = currentBundle, !0);
181
+ if (lastBundle === currentBundle) {
182
+ return false;
183
+ }
184
+ lastBundle = currentBundle;
185
+ return true;
142
186
  }
143
187
  let loadedConfig = null;
144
188
  const getLoadedConfig = () => loadedConfig;
145
- async function getBundledConfig(props, rebuild = !1) {
146
- if (isBundling) await new Promise(res => {
147
- waitForBundle.add(res);
148
- });else if (!currentBundle || rebuild) return await bundleConfig(props);
189
+ async function getBundledConfig(props, rebuild = false) {
190
+ if (isBundling) {
191
+ await new Promise(res => {
192
+ waitForBundle.add(res);
193
+ });
194
+ } else if (!currentBundle || rebuild) {
195
+ return await bundleConfig(props);
196
+ }
149
197
  return currentBundle;
150
198
  }
151
199
  global.guiLastLoaded ||= 0;
152
200
  function updateLastLoaded(config) {
153
- global.guiLastLoaded = Date.now(), global.guiLastBundledConfig = config;
201
+ global.guiLastLoaded = Date.now();
202
+ global.guiLastBundledConfig = config;
154
203
  }
155
- let hasBundledOnce = !1,
156
- hasLoggedBuild = !1;
204
+ let hasBundledOnce = false;
205
+ let hasLoggedBuild = false;
157
206
  async function bundleConfig(props) {
158
- if (global.guiLastBundledConfig && Date.now() - global.guiLastLoaded < 3e3) return global.guiLastBundledConfig;
207
+ if (global.guiLastBundledConfig && Date.now() - global.guiLastLoaded < 3e3) {
208
+ return global.guiLastBundledConfig;
209
+ }
159
210
  try {
160
- isBundling = !0;
161
- const configEntry = props.config ? (0, import_getGuiConfigPathFromOptionsConfig.getGuiConfigPathFromOptionsConfig)(props.config) : "",
162
- tmpDir = (0, import_node_path.join)(process.cwd(), ".gui"),
163
- configFormat = configEntry ? (0, import_detectModuleFormat.detectModuleFormat)(configEntry) : "cjs",
164
- configOutPath = (0, import_node_path.join)(tmpDir, `gui.config${configFormat === "esm" ? ".mjs" : ".cjs"}`),
165
- baseComponents = (props.components || []).filter(x => x !== "@hanzogui/core"),
166
- componentFormats = baseComponents.map(mod => {
167
- try {
168
- const pkgJson = require.resolve(mod + "/package.json");
169
- return JSON.parse((0, import_node_fs.readFileSync)(pkgJson, "utf-8")).type === "module" ? "esm" : "cjs";
170
- } catch {
171
- return "cjs";
172
- }
173
- }),
174
- componentOutPaths = baseComponents.map((componentModule, i) => {
175
- const ext = componentFormats[i] === "esm" ? ".mjs" : ".cjs";
176
- return (0, import_node_path.join)(tmpDir, `${componentModule.split(import_node_path.sep).join("-").replace(/[^a-z0-9]+/gi, "")}-components.config${ext}`);
177
- });
178
- process.env.NODE_ENV === "development" && process.env.DEBUG?.startsWith("@hanzo/gui") && console.info("Building config entry", configEntry);
211
+ isBundling = true;
212
+ const configEntry = props.config ? (0, import_getGuiConfigPathFromOptionsConfig.getGuiConfigPathFromOptionsConfig)(props.config) : "";
213
+ const tmpDir = (0, import_node_path.join)(process.cwd(), ".gui");
214
+ const configFormat = configEntry ? (0, import_detectModuleFormat.detectModuleFormat)(configEntry) : "cjs";
215
+ const configExt = configFormat === "esm" ? ".mjs" : ".cjs";
216
+ const configOutPath = (0, import_node_path.join)(tmpDir, `gui.config${configExt}`);
217
+ const baseComponents = (props.components || []).filter(x => x !== "@hanzogui/core");
218
+ const componentFormats = baseComponents.map(mod => {
219
+ try {
220
+ const pkgJson = require.resolve(mod + "/package.json");
221
+ const pkg = JSON.parse((0, import_node_fs.readFileSync)(pkgJson, "utf-8"));
222
+ return pkg.type === "module" ? "esm" : "cjs";
223
+ } catch {
224
+ return "cjs";
225
+ }
226
+ });
227
+ const componentOutPaths = baseComponents.map((componentModule, i) => {
228
+ const ext = componentFormats[i] === "esm" ? ".mjs" : ".cjs";
229
+ return (0, import_node_path.join)(tmpDir, `${componentModule.split(import_node_path.sep).join("-").replace(/[^a-z0-9]+/gi, "")}-components.config${ext}`);
230
+ });
231
+ if (process.env.NODE_ENV === "development" && process.env.DEBUG?.startsWith("@hanzo/gui")) {
232
+ console.info(`Building config entry`, configEntry);
233
+ }
179
234
  let shouldBuild = !props.disableInitialBuild;
180
235
  if (shouldBuild && props.config) {
181
236
  const allOutFiles = [configOutPath, ...componentOutPaths];
182
237
  try {
183
- (await Promise.all(allOutFiles.map(f => FS.stat(f).catch(() => null)))).every(s => s !== null && Date.now() - s.mtimeMs < 3e3) && (shouldBuild = !1);
238
+ const stats = await Promise.all(allOutFiles.map(f => FS.stat(f).catch(() => null)));
239
+ const allExistAndRecent = stats.every(s => s !== null && Date.now() - s.mtimeMs < 3e3);
240
+ if (allExistAndRecent) {
241
+ shouldBuild = false;
242
+ }
184
243
  } catch {}
185
244
  }
186
245
  if (shouldBuild) {
@@ -195,80 +254,129 @@ async function bundleConfig(props) {
195
254
  target: "node24",
196
255
  format: configFormat,
197
256
  ...esbuildExtraOptions
198
- }, props.platform || "web") : null, ...baseComponents.map((componentModule, i) => (0, import_bundle.esbundleGuiConfig)({
199
- entryPoints: [componentModule],
200
- resolvePlatformSpecificEntries: !0,
201
- external,
202
- outfile: componentOutPaths[i],
203
- target: "node24",
204
- format: componentFormats[i],
205
- ...esbuildExtraOptions
206
- }, props.platform || "web"))]), !hasLoggedBuild && !props._skipBuildLog && (hasLoggedBuild = !0, (0, import_cli_color.colorLog)(import_cli_color.Color.FgYellow, `
207
- \u27A1 [hanzo-gui] built config, components, prompt (${Date.now() - start}ms)`), process.env.DEBUG?.startsWith("@hanzo/gui") && (0, import_cli_color.colorLog)(import_cli_color.Color.Dim, `
257
+ }, props.platform || "web") : null, ...baseComponents.map((componentModule, i) => {
258
+ return (0, import_bundle.esbundleGuiConfig)({
259
+ entryPoints: [componentModule],
260
+ resolvePlatformSpecificEntries: true,
261
+ external,
262
+ outfile: componentOutPaths[i],
263
+ target: "node24",
264
+ format: componentFormats[i],
265
+ ...esbuildExtraOptions
266
+ }, props.platform || "web");
267
+ })]);
268
+ if (!hasLoggedBuild && !props["_skipBuildLog"]) {
269
+ hasLoggedBuild = true;
270
+ (0, import_cli_color.colorLog)(import_cli_color.Color.FgYellow, `
271
+ \u27A1 [hanzo-gui] built config, components, prompt (${Date.now() - start}ms)`);
272
+ if (process.env.DEBUG?.startsWith("@hanzo/gui")) {
273
+ (0, import_cli_color.colorLog)(import_cli_color.Color.Dim, `
208
274
  Config .${import_node_path.sep}${(0, import_node_path.relative)(process.cwd(), configOutPath)}
209
- Components ${componentOutPaths.map(p => `.${import_node_path.sep}${(0, import_node_path.relative)(process.cwd(), p)}`).join(`
210
- `)}
211
- `));
275
+ Components ${componentOutPaths.map(p => `.${import_node_path.sep}${(0, import_node_path.relative)(process.cwd(), p)}`).join("\n ")}
276
+ `);
277
+ }
278
+ }
212
279
  }
213
280
  if (hasBundledOnce) {
214
281
  try {
215
282
  delete require.cache[require.resolve(configOutPath)];
216
283
  } catch {}
217
- for (const p of componentOutPaths) try {
218
- delete require.cache[require.resolve(p)];
219
- } catch {}
220
- } else hasBundledOnce = !0;
284
+ for (const p of componentOutPaths) {
285
+ try {
286
+ delete require.cache[require.resolve(p)];
287
+ } catch {}
288
+ }
289
+ } else {
290
+ hasBundledOnce = true;
291
+ }
221
292
  let out;
222
- configFormat === "esm" ? out = await import((0, import_node_url.pathToFileURL)(configOutPath).href) : out = require(configOutPath);
293
+ if (configFormat === "esm") {
294
+ out = await import((0, import_node_url.pathToFileURL)(configOutPath).href);
295
+ } else {
296
+ out = require(configOutPath);
297
+ }
223
298
  let config = out.default || out || out.config;
224
- if (config && config.config && !config.tokens && (config = config.config), !config) throw new Error(`No config: ${config}`);
225
- if (config._isProxyWorm) throw new Error("Got a proxied config - likely a module loading error. Set DEBUG=hanzo-gui for details.");
226
- if (loadedConfig = config, !config.parsed) {
299
+ if (config && config.config && !config.tokens) {
300
+ config = config.config;
301
+ }
302
+ if (!config) {
303
+ throw new Error(`No config: ${config}`);
304
+ }
305
+ if (config._isProxyWorm) {
306
+ throw new Error(`Got a proxied config - likely a module loading error. Set DEBUG=hanzo-gui for details.`);
307
+ }
308
+ loadedConfig = config;
309
+ if (!config.parsed) {
227
310
  const {
228
311
  createGui
229
312
  } = (0, import_requireGuiCore.requireGuiCore)(props.platform || "web");
230
313
  config = createGui(config);
231
314
  }
232
- props.outputCSS && (await writeGuiCSS(props.outputCSS, config));
315
+ if (props.outputCSS) {
316
+ await writeGuiCSS(props.outputCSS, config);
317
+ }
233
318
  let components = await loadComponents({
234
319
  ...props,
235
320
  components: componentOutPaths
236
321
  });
237
- if (!components) throw new Error(`No components found: ${componentOutPaths.join(", ")}`);
238
- for (const component of components) component.moduleName = baseComponents[componentOutPaths.indexOf(component.moduleName)] || component.moduleName, component.moduleName || (process.env.DEBUG?.includes("@hanzo/gui") || process.env.IS_HANZO_GUI_DEV) && console.warn(`\u26A0\uFE0F no module name found: ${component.moduleName} ${JSON.stringify(baseComponents)} in ${JSON.stringify(componentOutPaths)}`);
239
- process.env.NODE_ENV === "development" && process.env.DEBUG?.startsWith("@hanzo/gui") && console.info("Loaded components", components);
322
+ if (!components) {
323
+ throw new Error(`No components found: ${componentOutPaths.join(", ")}`);
324
+ }
325
+ for (const component of components) {
326
+ component.moduleName = baseComponents[componentOutPaths.indexOf(component.moduleName)] || component.moduleName;
327
+ if (!component.moduleName) {
328
+ if (process.env.DEBUG?.includes("@hanzo/gui") || process.env.IS_GUI_DEV) {
329
+ console.warn(`\u26A0\uFE0F no module name found: ${component.moduleName} ${JSON.stringify(baseComponents)} in ${JSON.stringify(componentOutPaths)}`);
330
+ }
331
+ }
332
+ }
333
+ if (process.env.NODE_ENV === "development" && process.env.DEBUG?.startsWith("@hanzo/gui")) {
334
+ console.info("Loaded components", components);
335
+ }
240
336
  const res = {
241
337
  components,
242
338
  nameToPaths: {},
243
339
  guiConfig: config
244
340
  };
245
- return currentBundle = res, updateLastLoaded(res), res;
341
+ currentBundle = res;
342
+ updateLastLoaded(res);
343
+ return res;
246
344
  } catch (err) {
247
- console.error(`Error bundling gui config: ${err?.message} (run with DEBUG=hanzo-gui to see stack)`), process.env.DEBUG?.includes("@hanzo/gui") && console.error(err.stack);
345
+ console.error(`Error bundling gui config: ${err?.message} (run with DEBUG=hanzo-gui to see stack)`);
346
+ if (process.env.DEBUG?.includes("@hanzo/gui")) {
347
+ console.error(err.stack);
348
+ }
248
349
  } finally {
249
- isBundling = !1, waitForBundle.forEach(cb => cb()), waitForBundle.clear();
350
+ isBundling = false;
351
+ waitForBundle.forEach(cb => cb());
352
+ waitForBundle.clear();
250
353
  }
251
354
  }
252
355
  async function writeGuiCSS(outputCSS, config) {
253
356
  const flush = async () => {
254
- (0, import_cli_color.colorLog)(import_cli_color.Color.FgYellow, ` \u27A1 [hanzo-gui] output css: ${outputCSS}`), await FS.writeFile(outputCSS, css);
255
- },
256
- css = config.getCSS();
257
- if (typeof css != "string") throw new Error(`Invalid CSS: ${typeof css} ${css}`);
357
+ (0, import_cli_color.colorLog)(import_cli_color.Color.FgYellow, ` \u27A1 [hanzo-gui] output css: ${outputCSS}`);
358
+ await FS.writeFile(outputCSS, css);
359
+ };
360
+ const css = config.getCSS();
361
+ if (typeof css !== "string") {
362
+ throw new Error(`Invalid CSS: ${typeof css} ${css}`);
363
+ }
258
364
  try {
259
- (0, import_node_fs.existsSync)(outputCSS) && (await (0, import_promises.readFile)(outputCSS, "utf8")) === css || (await flush());
365
+ if ((0, import_node_fs.existsSync)(outputCSS) && (await (0, import_promises.readFile)(outputCSS, "utf8")) === css) {} else {
366
+ await flush();
367
+ }
260
368
  } catch (err) {
261
369
  console.info("Error writing themes", err);
262
370
  }
263
371
  }
264
- async function loadComponents(props, forceExports = !1) {
265
- const coreComponents = getCoreComponentsSync(props),
266
- otherComponents = await loadComponentsInner(props, forceExports);
372
+ async function loadComponents(props, forceExports = false) {
373
+ const coreComponents = getCoreComponentsSync(props);
374
+ const otherComponents = await loadComponentsInner(props, forceExports);
267
375
  return [...coreComponents, ...(otherComponents || [])];
268
376
  }
269
- function loadComponentsSync(props, forceExports = !1) {
270
- const coreComponents = getCoreComponentsSync(props),
271
- otherComponents = loadComponentsInnerSync(props, forceExports);
377
+ function loadComponentsSync(props, forceExports = false) {
378
+ const coreComponents = getCoreComponentsSync(props);
379
+ const otherComponents = loadComponentsInnerSync(props, forceExports);
272
380
  return [...coreComponents, ...(otherComponents || [])];
273
381
  }
274
382
  function getCoreComponentsSync(props) {
@@ -276,16 +384,20 @@ function getCoreComponentsSync(props) {
276
384
  ...props,
277
385
  components: ["@hanzogui/core"]
278
386
  });
279
- if (!loaded) throw new Error("Core should always load");
387
+ if (!loaded) {
388
+ throw new Error(`Core should always load`);
389
+ }
280
390
  return [{
281
391
  ...loaded[0],
282
392
  moduleName: "@hanzogui/core"
283
393
  }];
284
394
  }
285
- async function loadComponentsInner(props, forceExports = !1) {
286
- const componentsModules = props.components || [],
287
- key = componentsModules.join("\0");
288
- if (!forceExports && cacheComponents[key]) return cacheComponents[key];
395
+ async function loadComponentsInner(props, forceExports = false) {
396
+ const componentsModules = props.components || [];
397
+ const key = componentsModules.join("\0");
398
+ if (!forceExports && cacheComponents[key]) {
399
+ return cacheComponents[key];
400
+ }
289
401
  const {
290
402
  unregister
291
403
  } = (0, import_registerRequire.registerRequire)(props.platform || "web", {
@@ -294,17 +406,23 @@ async function loadComponentsInner(props, forceExports = !1) {
294
406
  try {
295
407
  const results = [];
296
408
  for (const name of componentsModules) {
297
- const isLocal = !!(0, import_node_path.extname)(name),
298
- isDynamic = isLocal && forceExports,
299
- format = isLocal ? (0, import_detectModuleFormat.detectModuleFormat)(name) : "cjs",
300
- fileContents = isDynamic ? (0, import_node_fs.readFileSync)(name, "utf-8") : "";
301
- let loadModule = name,
302
- writtenContents = fileContents,
303
- didBabel = !1;
409
+ const extension = (0, import_node_path.extname)(name);
410
+ const isLocal = Boolean(extension);
411
+ const isDynamic = isLocal && forceExports;
412
+ const format = isLocal ? (0, import_detectModuleFormat.detectModuleFormat)(name) : "cjs";
413
+ const fileContents = isDynamic ? (0, import_node_fs.readFileSync)(name, "utf-8") : "";
414
+ let loadModule = name;
415
+ let writtenContents = fileContents;
416
+ let didBabel = false;
304
417
  const attemptLoad = async ({
305
- forceExports: forceExports2 = !1
306
- } = {}) => {
307
- isDynamic && (writtenContents = forceExports2 ? transformAddExports((0, import_babelParse.babelParse)(esbuildit(fileContents, "modern"), name)) : fileContents, loadModule = getDynamicEvalOutfile(name, format, writtenContents), FS.ensureDirSync((0, import_node_path.dirname)(loadModule)), activeTempFiles.add(loadModule), await import_esbuild.default.build({
418
+ forceExports: forceExports2 = false
419
+ } = {}) => {
420
+ if (isDynamic) {
421
+ writtenContents = forceExports2 ? transformAddExports((0, import_babelParse.babelParse)(esbuildit(fileContents, "modern"), name)) : fileContents;
422
+ loadModule = getDynamicEvalOutfile(name, format, writtenContents);
423
+ FS.ensureDirSync((0, import_node_path.dirname)(loadModule));
424
+ activeTempFiles.add(loadModule);
425
+ await import_esbuild.default.build({
308
426
  ...esbuildOptionsWithPlugins,
309
427
  format,
310
428
  outfile: loadModule,
@@ -319,59 +437,91 @@ async function loadComponentsInner(props, forceExports = !1) {
319
437
  "@hanzogui/react-native-web-lite": resolvePackageEntry("@hanzogui/react-native-web-lite", format),
320
438
  "@hanzogui/react-native-web-internals": resolvePackageEntry("@hanzogui/react-native-web-internals", format)
321
439
  },
322
- bundle: !0,
440
+ bundle: true,
323
441
  packages: "external",
324
- allowOverwrite: !0,
325
- sourcemap: !1,
442
+ allowOverwrite: true,
443
+ sourcemap: false,
326
444
  loader: import_bundle.esbuildLoaderConfig
327
- })), process.env.DEBUG === "@hanzo/gui" && console.info("loadModule", loadModule, format);
328
- let moduleResult;
329
- format === "esm" ? moduleResult = await import((0, import_node_url.pathToFileURL)(loadModule).href) : moduleResult = require(loadModule), forceExports2 || (0, import_registerRequire.setRequireResult)(name, moduleResult);
330
- const nameToInfo = getComponentStaticConfigByName(name, interopDefaultExport(moduleResult));
331
- return {
332
- moduleName: name,
333
- nameToInfo
334
- };
335
- },
336
- dispose = () => {
337
- isDynamic && (FS.removeSync(loadModule), activeTempFiles.delete(loadModule));
445
+ });
446
+ }
447
+ if (process.env.DEBUG === "@hanzo/gui") {
448
+ console.info(`loadModule`, loadModule, format);
449
+ }
450
+ let moduleResult;
451
+ if (format === "esm") {
452
+ moduleResult = await import((0, import_node_url.pathToFileURL)(loadModule).href);
453
+ } else {
454
+ moduleResult = require(loadModule);
455
+ }
456
+ if (!forceExports2) {
457
+ (0, import_registerRequire.setRequireResult)(name, moduleResult);
458
+ }
459
+ const nameToInfo = getComponentStaticConfigByName(name, interopDefaultExport(moduleResult));
460
+ return {
461
+ moduleName: name,
462
+ nameToInfo
338
463
  };
464
+ };
465
+ const dispose = () => {
466
+ if (isDynamic) {
467
+ FS.removeSync(loadModule);
468
+ activeTempFiles.delete(loadModule);
469
+ }
470
+ };
339
471
  let loaded;
340
472
  try {
341
473
  loaded = await attemptLoad({
342
- forceExports: !0
343
- }), didBabel = !0;
474
+ forceExports: true
475
+ });
476
+ didBabel = true;
344
477
  } catch (err) {
345
- console.info("babel err", err, writtenContents), writtenContents = fileContents, process.env.DEBUG?.startsWith("@hanzo/gui") && console.info("Error parsing babel likely", err);
478
+ console.info("babel err", err, writtenContents);
479
+ writtenContents = fileContents;
480
+ if (process.env.DEBUG?.startsWith("@hanzo/gui")) {
481
+ console.info(`Error parsing babel likely`, err);
482
+ }
346
483
  try {
347
484
  loaded = await attemptLoad({
348
- forceExports: !1
485
+ forceExports: false
349
486
  });
350
487
  } catch (err2) {
351
- process.env.HANZO_GUI_ENABLE_WARN_DYNAMIC_LOAD && (console.info(`
488
+ if (process.env.GUI_ENABLE_WARN_DYNAMIC_LOAD) {
489
+ console.info(`
352
490
  Gui attempted but failed to dynamically optimize components in:
353
491
  ${name}
354
- `), console.info(err2), console.info(`At: ${loadModule}`, `
492
+ `);
493
+ console.info(err2);
494
+ console.info(`At: ${loadModule}`, `
355
495
  didBabel: ${didBabel}`, `
356
496
  In:`, writtenContents, `
357
- isDynamic: `, isDynamic)), loaded = [];
497
+ isDynamic: `, isDynamic);
498
+ }
499
+ loaded = [];
358
500
  }
359
501
  } finally {
360
502
  dispose();
361
503
  }
362
- Array.isArray(loaded) ? results.push(...loaded) : loaded && results.push(loaded);
504
+ if (Array.isArray(loaded)) {
505
+ results.push(...loaded);
506
+ } else if (loaded) {
507
+ results.push(loaded);
508
+ }
363
509
  }
364
- return cacheComponents[key] = results, results;
510
+ cacheComponents[key] = results;
511
+ return results;
365
512
  } catch (err) {
366
- return console.info("Gui error bundling components", err.message, err.stack), null;
513
+ console.info(`Gui error bundling components`, err.message, err.stack);
514
+ return null;
367
515
  } finally {
368
516
  unregister();
369
517
  }
370
518
  }
371
- function loadComponentsInnerSync(props, forceExports = !1) {
372
- const componentsModules = props.components || [],
373
- key = componentsModules.join("\0");
374
- if (!forceExports && cacheComponents[key]) return cacheComponents[key];
519
+ function loadComponentsInnerSync(props, forceExports = false) {
520
+ const componentsModules = props.components || [];
521
+ const key = componentsModules.join("\0");
522
+ if (!forceExports && cacheComponents[key]) {
523
+ return cacheComponents[key];
524
+ }
375
525
  const {
376
526
  unregister
377
527
  } = (0, import_registerRequire.registerRequire)(props.platform || "web", {
@@ -379,36 +529,49 @@ function loadComponentsInnerSync(props, forceExports = !1) {
379
529
  });
380
530
  try {
381
531
  const info = componentsModules.flatMap(name => {
382
- const isDynamic = !!(0, import_node_path.extname)(name) && forceExports,
383
- fileContents = isDynamic ? (0, import_node_fs.readFileSync)(name, "utf-8") : "";
384
- let loadModule = name,
385
- writtenContents = fileContents,
386
- didBabel = !1;
532
+ const extension = (0, import_node_path.extname)(name);
533
+ const isLocal = Boolean(extension);
534
+ const isDynamic = isLocal && forceExports;
535
+ const fileContents = isDynamic ? (0, import_node_fs.readFileSync)(name, "utf-8") : "";
536
+ let loadModule = name;
537
+ let writtenContents = fileContents;
538
+ let didBabel = false;
387
539
  function attemptLoad({
388
- forceExports: forceExports2 = !1
540
+ forceExports: forceExports2 = false
389
541
  } = {}) {
390
- isDynamic && (writtenContents = forceExports2 ? transformAddExports((0, import_babelParse.babelParse)(esbuildit(fileContents, "modern"), name)) : fileContents, loadModule = getDynamicEvalOutfile(name, "cjs", writtenContents), FS.ensureDirSync((0, import_node_path.dirname)(loadModule)), activeTempFiles.add(loadModule), import_esbuild.default.buildSync({
391
- ...esbuildOptions,
392
- outfile: loadModule,
393
- stdin: {
394
- contents: writtenContents,
395
- resolveDir: (0, import_node_path.dirname)(name),
396
- sourcefile: name,
397
- loader: getEsbuildStdinLoader(name)
398
- },
399
- alias: {
400
- "react-native": resolvePackageEntry("@hanzogui/react-native-web-lite", "esm"),
401
- "@hanzogui/react-native-web-lite": resolvePackageEntry("@hanzogui/react-native-web-lite", "esm"),
402
- "@hanzogui/react-native-web-internals": resolvePackageEntry("@hanzogui/react-native-web-internals", "esm")
403
- },
404
- bundle: !0,
405
- packages: "external",
406
- allowOverwrite: !0,
407
- sourcemap: !1,
408
- loader: import_bundle.esbuildLoaderConfig
409
- })), process.env.DEBUG === "@hanzo/gui" && console.info("loadModule", loadModule, require.resolve(loadModule));
542
+ if (isDynamic) {
543
+ writtenContents = forceExports2 ? transformAddExports((0, import_babelParse.babelParse)(esbuildit(fileContents, "modern"), name)) : fileContents;
544
+ loadModule = getDynamicEvalOutfile(name, "cjs", writtenContents);
545
+ FS.ensureDirSync((0, import_node_path.dirname)(loadModule));
546
+ activeTempFiles.add(loadModule);
547
+ import_esbuild.default.buildSync({
548
+ ...esbuildOptions,
549
+ outfile: loadModule,
550
+ stdin: {
551
+ contents: writtenContents,
552
+ resolveDir: (0, import_node_path.dirname)(name),
553
+ sourcefile: name,
554
+ loader: getEsbuildStdinLoader(name)
555
+ },
556
+ alias: {
557
+ "react-native": resolvePackageEntry("@hanzogui/react-native-web-lite", "esm"),
558
+ "@hanzogui/react-native-web-lite": resolvePackageEntry("@hanzogui/react-native-web-lite", "esm"),
559
+ "@hanzogui/react-native-web-internals": resolvePackageEntry("@hanzogui/react-native-web-internals", "esm")
560
+ },
561
+ bundle: true,
562
+ packages: "external",
563
+ allowOverwrite: true,
564
+ sourcemap: false,
565
+ loader: import_bundle.esbuildLoaderConfig
566
+ });
567
+ }
568
+ if (process.env.DEBUG === "@hanzo/gui") {
569
+ console.info(`loadModule`, loadModule, require.resolve(loadModule));
570
+ }
410
571
  const moduleResult = require(loadModule);
411
- forceExports2 || (0, import_registerRequire.setRequireResult)(name, moduleResult);
572
+ if (!forceExports2) {
573
+ (0, import_registerRequire.setRequireResult)(name, moduleResult);
574
+ }
412
575
  const nameToInfo = getComponentStaticConfigByName(name, interopDefaultExport(moduleResult));
413
576
  return {
414
577
  moduleName: name,
@@ -416,55 +579,74 @@ function loadComponentsInnerSync(props, forceExports = !1) {
416
579
  };
417
580
  }
418
581
  const dispose = () => {
419
- isDynamic && (FS.removeSync(loadModule), activeTempFiles.delete(loadModule));
582
+ if (isDynamic) {
583
+ FS.removeSync(loadModule);
584
+ activeTempFiles.delete(loadModule);
585
+ }
420
586
  };
421
587
  try {
422
588
  const res = attemptLoad({
423
- forceExports: !0
589
+ forceExports: true
424
590
  });
425
- return didBabel = !0, res;
591
+ didBabel = true;
592
+ return res;
426
593
  } catch (err) {
427
- console.info("babel err", err, writtenContents), writtenContents = fileContents, process.env.DEBUG?.startsWith("@hanzo/gui") && console.info("Error parsing babel likely", err);
594
+ console.info("babel err", err, writtenContents);
595
+ writtenContents = fileContents;
596
+ if (process.env.DEBUG?.startsWith("@hanzo/gui")) {
597
+ console.info(`Error parsing babel likely`, err);
598
+ }
428
599
  } finally {
429
600
  dispose();
430
601
  }
431
602
  try {
432
603
  return attemptLoad({
433
- forceExports: !1
604
+ forceExports: false
434
605
  });
435
606
  } catch (err) {
436
- return process.env.HANZO_GUI_ENABLE_WARN_DYNAMIC_LOAD && (console.info(`
607
+ if (process.env.GUI_ENABLE_WARN_DYNAMIC_LOAD) {
608
+ console.info(`
437
609
  Gui attempted but failed to dynamically optimize components in:
438
610
  ${name}
439
- `), console.info(err), console.info(`At: ${loadModule}`, `
611
+ `);
612
+ console.info(err);
613
+ console.info(`At: ${loadModule}`, `
440
614
  didBabel: ${didBabel}`, `
441
615
  In:`, writtenContents, `
442
- isDynamic: `, isDynamic)), [];
616
+ isDynamic: `, isDynamic);
617
+ }
618
+ return [];
443
619
  } finally {
444
620
  dispose();
445
621
  }
446
622
  });
447
- return cacheComponents[key] = info, info;
623
+ cacheComponents[key] = info;
624
+ return info;
448
625
  } catch (err) {
449
- return console.info("Gui error bundling components", err.message, err.stack), null;
626
+ console.info(`Gui error bundling components`, err.message, err.stack);
627
+ return null;
450
628
  } finally {
451
629
  unregister();
452
630
  }
453
631
  }
454
- const esbuildit = (src, target) => import_esbuild.default.transformSync(src, {
455
- ...esbuildTransformOptions,
456
- ...(target === "modern" && {
457
- target: "es2022",
458
- jsx: "automatic",
459
- loader: "tsx",
460
- platform: "neutral",
461
- format: "esm"
462
- })
463
- }).code;
632
+ const esbuildit = (src, target) => {
633
+ return import_esbuild.default.transformSync(src, {
634
+ ...esbuildTransformOptions,
635
+ ...(target === "modern" && {
636
+ target: "es2022",
637
+ jsx: "automatic",
638
+ loader: "tsx",
639
+ platform: "neutral",
640
+ format: "esm"
641
+ })
642
+ }).code;
643
+ };
464
644
  function getComponentStaticConfigByName(name, exported) {
465
645
  const components = {};
466
646
  try {
467
- if (!exported || typeof exported != "object" || Array.isArray(exported)) throw new Error(`Invalid export from package ${name}: ${typeof exported}`);
647
+ if (!exported || typeof exported !== "object" || Array.isArray(exported)) {
648
+ throw new Error(`Invalid export from package ${name}: ${typeof exported}`);
649
+ }
468
650
  for (const key in exported) {
469
651
  const found = getGuiComponent(key, exported[key]);
470
652
  if (found) {
@@ -478,13 +660,21 @@ function getComponentStaticConfigByName(name, exported) {
478
660
  }
479
661
  }
480
662
  } catch (err) {
481
- process.env.HANZO_GUI_ENABLE_WARN_DYNAMIC_LOAD && (console.error(`Gui failed getting components from ${name} (Disable error by setting environment variable HANZO_GUI_ENABLE_WARN_DYNAMIC_LOAD=1)`), console.error(err));
663
+ if (process.env.GUI_ENABLE_WARN_DYNAMIC_LOAD) {
664
+ console.error(`Gui failed getting components from ${name} (Disable error by setting environment variable GUI_ENABLE_WARN_DYNAMIC_LOAD=1)`);
665
+ console.error(err);
666
+ }
482
667
  }
483
668
  return components;
484
669
  }
485
670
  function getGuiComponent(name, Component) {
486
- if (name[0].toUpperCase() !== name[0]) return;
487
- if (Component?.staticConfig) return Component;
671
+ if (name[0].toUpperCase() !== name[0]) {
672
+ return;
673
+ }
674
+ const staticConfig = Component?.staticConfig;
675
+ if (staticConfig) {
676
+ return Component;
677
+ }
488
678
  }
489
679
  function interopDefaultExport(mod) {
490
680
  return mod?.default ?? mod;
@@ -492,22 +682,32 @@ function interopDefaultExport(mod) {
492
682
  const cacheComponents = {};
493
683
  function transformAddExports(ast) {
494
684
  const usedNames = /* @__PURE__ */new Set();
495
- return (0, import_traverse.default)(ast, {
685
+ (0, import_traverse.default)(ast, {
496
686
  ExportNamedDeclaration(nodePath) {
497
- if (nodePath.node.specifiers) for (const spec of nodePath.node.specifiers) usedNames.add(t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value);
687
+ if (nodePath.node.specifiers) {
688
+ for (const spec of nodePath.node.specifiers) {
689
+ usedNames.add(t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value);
690
+ }
691
+ }
498
692
  }
499
- }), (0, import_traverse.default)(ast, {
693
+ });
694
+ (0, import_traverse.default)(ast, {
500
695
  VariableDeclaration(nodePath) {
501
696
  if (!t.isProgram(nodePath.parent)) return;
502
697
  const decs = nodePath.node.declarations;
503
698
  if (decs.length > 1) return;
504
699
  const [dec] = decs;
505
- t.isIdentifier(dec.id) && dec.init && (usedNames.has(dec.id.name) || (usedNames.add(dec.id.name), nodePath.replaceWith(t.exportNamedDeclaration(t.variableDeclaration("let", [dec]), [t.exportSpecifier(t.identifier(dec.id.name), t.identifier(dec.id.name))]))));
700
+ if (!t.isIdentifier(dec.id)) return;
701
+ if (!dec.init) return;
702
+ if (usedNames.has(dec.id.name)) return;
703
+ usedNames.add(dec.id.name);
704
+ nodePath.replaceWith(t.exportNamedDeclaration(t.variableDeclaration("let", [dec]), [t.exportSpecifier(t.identifier(dec.id.name), t.identifier(dec.id.name))]));
506
705
  }
507
- }), (0, import_generator.default)(ast, {
508
- concise: !1,
706
+ });
707
+ return (0, import_generator.default)(ast, {
708
+ concise: false,
509
709
  filename: "test.tsx",
510
- retainLines: !1,
511
- sourceMaps: !1
710
+ retainLines: false,
711
+ sourceMaps: false
512
712
  }).code;
513
713
  }