@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.
- package/dist/check-dep-versions.cjs +201 -96
- package/dist/checkDeps.cjs +163 -92
- package/dist/constants.cjs +32 -30
- package/dist/exports.cjs +15 -13
- package/dist/extractor/accessSafe.cjs +25 -23
- package/dist/extractor/babelParse.cjs +30 -28
- package/dist/extractor/buildClassName.cjs +59 -35
- package/dist/extractor/bundle.cjs +159 -104
- package/dist/extractor/bundleConfig.cjs +463 -263
- package/dist/extractor/concatClassName.cjs +41 -29
- package/dist/extractor/createEvaluator.cjs +54 -41
- package/dist/extractor/createExtractor.cjs +1338 -661
- package/dist/extractor/createLogger.cjs +30 -25
- package/dist/extractor/detectModuleFormat.cjs +22 -16
- package/dist/extractor/ensureImportingConcat.cjs +31 -25
- package/dist/extractor/errors.cjs +12 -10
- package/dist/extractor/esbuildAliasPlugin.cjs +28 -16
- package/dist/extractor/esbuildTsconfigPaths.cjs +58 -36
- package/dist/extractor/evaluateAstNode.cjs +104 -59
- package/dist/extractor/extractHelpers.cjs +130 -67
- package/dist/extractor/extractMediaStyle.cjs +110 -69
- package/dist/extractor/extractToClassNames.cjs +336 -230
- package/dist/extractor/extractToNative.cjs +244 -149
- package/dist/extractor/findTopmostFunction.cjs +22 -13
- package/dist/extractor/generatedUid.cjs +39 -28
- package/dist/extractor/getGuiConfigPathFromOptionsConfig.cjs +20 -14
- package/dist/extractor/getPrefixLogs.cjs +12 -10
- package/dist/extractor/getPropValueFromAttributes.cjs +52 -34
- package/dist/extractor/getSourceModule.cjs +73 -37
- package/dist/extractor/getStaticBindingsForScope.cjs +131 -68
- package/dist/extractor/hoistClassNames.cjs +46 -32
- package/dist/extractor/literalToAst.cjs +67 -42
- package/dist/extractor/loadFile.cjs +9 -3
- package/dist/extractor/loadGui.cjs +198 -109
- package/dist/extractor/logLines.cjs +27 -19
- package/dist/extractor/normalizeTernaries.cjs +66 -44
- package/dist/extractor/propsToFontFamilyCache.cjs +15 -11
- package/dist/extractor/regenerateConfig.cjs +109 -81
- package/dist/extractor/removeUnusedHooks.cjs +73 -41
- package/dist/extractor/timer.cjs +23 -14
- package/dist/extractor/validHTMLAttributes.cjs +61 -59
- package/dist/extractor/watchGuiConfig.cjs +35 -23
- package/dist/getPragmaOptions.cjs +34 -19
- package/dist/helpers/memoize.cjs +24 -16
- package/dist/helpers/requireGuiCore.cjs +22 -15
- package/dist/index.cjs +26 -24
- package/dist/registerRequire.cjs +132 -77
- package/dist/server.cjs +35 -28
- package/dist/types.cjs +7 -5
- package/dist/worker.cjs +62 -40
- package/package.json +2 -2
- package/src/checkDeps.ts +1 -1
- package/src/extractor/bundle.ts +1 -1
- package/src/extractor/bundleConfig.ts +5 -5
- package/src/extractor/createExtractor.ts +28 -13
- package/src/extractor/createLogger.ts +1 -3
- package/src/extractor/extractToNative.ts +35 -9
- package/src/extractor/loadGui.ts +4 -4
- package/src/extractor/regenerateConfig.ts +2 -2
- package/src/getPragmaOptions.ts +2 -2
- package/src/helpers/requireGuiCore.ts +6 -6
- package/src/registerRequire.ts +4 -4
- package/src/worker.ts +1 -1
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/createLogger.d.ts.map +1 -1
- package/types/extractor/extractToNative.d.ts.map +1 -1
- 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
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
32
34
|
var 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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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")
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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)
|
|
84
|
-
|
|
85
|
-
|
|
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()
|
|
102
|
+
cleanupTempFiles();
|
|
103
|
+
process.exit();
|
|
91
104
|
});
|
|
92
105
|
process.on("SIGTERM", () => {
|
|
93
|
-
cleanupTempFiles()
|
|
106
|
+
cleanupTempFiles();
|
|
107
|
+
process.exit();
|
|
94
108
|
});
|
|
95
|
-
const external = ["@hanzogui/core", "@hanzogui/web", "react", "react-dom", "react-native-svg"]
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
}
|
|
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
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
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 =
|
|
146
|
-
if (isBundling)
|
|
147
|
-
|
|
148
|
-
|
|
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()
|
|
201
|
+
global.guiLastLoaded = Date.now();
|
|
202
|
+
global.guiLastBundledConfig = config;
|
|
154
203
|
}
|
|
155
|
-
let hasBundledOnce =
|
|
156
|
-
|
|
204
|
+
let hasBundledOnce = false;
|
|
205
|
+
let hasLoggedBuild = false;
|
|
157
206
|
async function bundleConfig(props) {
|
|
158
|
-
if (global.guiLastBundledConfig && Date.now() - global.guiLastLoaded < 3e3)
|
|
207
|
+
if (global.guiLastBundledConfig && Date.now() - global.guiLastLoaded < 3e3) {
|
|
208
|
+
return global.guiLastBundledConfig;
|
|
209
|
+
}
|
|
159
210
|
try {
|
|
160
|
-
isBundling =
|
|
161
|
-
const configEntry = props.config ? (0, import_getGuiConfigPathFromOptionsConfig.getGuiConfigPathFromOptionsConfig)(props.config) : ""
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
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) =>
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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)
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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"
|
|
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
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
|
|
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)
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
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)`)
|
|
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 =
|
|
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
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
|
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 =
|
|
265
|
-
const coreComponents = getCoreComponentsSync(props)
|
|
266
|
-
|
|
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 =
|
|
270
|
-
const coreComponents = getCoreComponentsSync(props)
|
|
271
|
-
|
|
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)
|
|
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 =
|
|
286
|
-
const componentsModules = props.components || []
|
|
287
|
-
|
|
288
|
-
if (!forceExports && 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
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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:
|
|
440
|
+
bundle: true,
|
|
323
441
|
packages: "external",
|
|
324
|
-
allowOverwrite:
|
|
325
|
-
sourcemap:
|
|
442
|
+
allowOverwrite: true,
|
|
443
|
+
sourcemap: false,
|
|
326
444
|
loader: import_bundle.esbuildLoaderConfig
|
|
327
|
-
})
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
|
|
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:
|
|
343
|
-
})
|
|
474
|
+
forceExports: true
|
|
475
|
+
});
|
|
476
|
+
didBabel = true;
|
|
344
477
|
} catch (err) {
|
|
345
|
-
console.info("babel err", err, writtenContents)
|
|
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:
|
|
485
|
+
forceExports: false
|
|
349
486
|
});
|
|
350
487
|
} catch (err2) {
|
|
351
|
-
process.env.
|
|
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
|
-
`)
|
|
492
|
+
`);
|
|
493
|
+
console.info(err2);
|
|
494
|
+
console.info(`At: ${loadModule}`, `
|
|
355
495
|
didBabel: ${didBabel}`, `
|
|
356
496
|
In:`, writtenContents, `
|
|
357
|
-
isDynamic: `, isDynamic)
|
|
497
|
+
isDynamic: `, isDynamic);
|
|
498
|
+
}
|
|
499
|
+
loaded = [];
|
|
358
500
|
}
|
|
359
501
|
} finally {
|
|
360
502
|
dispose();
|
|
361
503
|
}
|
|
362
|
-
Array.isArray(loaded)
|
|
504
|
+
if (Array.isArray(loaded)) {
|
|
505
|
+
results.push(...loaded);
|
|
506
|
+
} else if (loaded) {
|
|
507
|
+
results.push(loaded);
|
|
508
|
+
}
|
|
363
509
|
}
|
|
364
|
-
|
|
510
|
+
cacheComponents[key] = results;
|
|
511
|
+
return results;
|
|
365
512
|
} catch (err) {
|
|
366
|
-
|
|
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 =
|
|
372
|
-
const componentsModules = props.components || []
|
|
373
|
-
|
|
374
|
-
if (!forceExports && 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
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
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 =
|
|
540
|
+
forceExports: forceExports2 = false
|
|
389
541
|
} = {}) {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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
|
-
|
|
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
|
-
|
|
582
|
+
if (isDynamic) {
|
|
583
|
+
FS.removeSync(loadModule);
|
|
584
|
+
activeTempFiles.delete(loadModule);
|
|
585
|
+
}
|
|
420
586
|
};
|
|
421
587
|
try {
|
|
422
588
|
const res = attemptLoad({
|
|
423
|
-
forceExports:
|
|
589
|
+
forceExports: true
|
|
424
590
|
});
|
|
425
|
-
|
|
591
|
+
didBabel = true;
|
|
592
|
+
return res;
|
|
426
593
|
} catch (err) {
|
|
427
|
-
console.info("babel err", err, writtenContents)
|
|
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:
|
|
604
|
+
forceExports: false
|
|
434
605
|
});
|
|
435
606
|
} catch (err) {
|
|
436
|
-
|
|
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
|
-
`)
|
|
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
|
-
|
|
623
|
+
cacheComponents[key] = info;
|
|
624
|
+
return info;
|
|
448
625
|
} catch (err) {
|
|
449
|
-
|
|
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) =>
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
target
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
})
|
|
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
|
|
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.
|
|
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])
|
|
487
|
-
|
|
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
|
-
|
|
685
|
+
(0, import_traverse.default)(ast, {
|
|
496
686
|
ExportNamedDeclaration(nodePath) {
|
|
497
|
-
if (nodePath.node.specifiers)
|
|
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
|
-
})
|
|
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)
|
|
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
|
-
})
|
|
508
|
-
|
|
706
|
+
});
|
|
707
|
+
return (0, import_generator.default)(ast, {
|
|
708
|
+
concise: false,
|
|
509
709
|
filename: "test.tsx",
|
|
510
|
-
retainLines:
|
|
511
|
-
sourceMaps:
|
|
710
|
+
retainLines: false,
|
|
711
|
+
sourceMaps: false
|
|
512
712
|
}).code;
|
|
513
713
|
}
|