@hanzogui/static 3.0.6 → 4.4.0

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