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