@tamagui/static 1.88.12 → 1.89.0-1706308641099
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +21 -0
- package/dist/esm/constants.mjs +10 -0
- package/dist/esm/extractor/accessSafe.mjs +11 -0
- package/dist/esm/extractor/babelParse.mjs +18 -0
- package/dist/esm/extractor/buildClassName.mjs +26 -0
- package/dist/esm/extractor/bundle.mjs +94 -0
- package/dist/esm/extractor/bundleConfig.mjs +263 -0
- package/dist/esm/extractor/createEvaluator.mjs +34 -0
- package/dist/esm/extractor/createExtractor.mjs +952 -0
- package/dist/esm/extractor/ensureImportingConcat.mjs +13 -0
- package/dist/esm/extractor/esbuildAliasPlugin.mjs +20 -0
- package/dist/esm/extractor/evaluateAstNode.mjs +48 -0
- package/dist/esm/extractor/extractHelpers.mjs +72 -0
- package/dist/esm/extractor/extractMediaStyle.mjs +93 -0
- package/dist/esm/extractor/extractToClassNames.mjs +237 -0
- package/dist/esm/extractor/findTopmostFunction.mjs +10 -0
- package/dist/esm/extractor/generateTamaguiStudioConfig.mjs +108 -0
- package/dist/esm/extractor/generatedUid.mjs +12 -0
- package/dist/esm/extractor/getPrefixLogs.mjs +4 -0
- package/dist/esm/extractor/getPropValueFromAttributes.mjs +31 -0
- package/dist/esm/extractor/getSourceModule.mjs +33 -0
- package/dist/esm/extractor/getStaticBindingsForScope.mjs +112 -0
- package/dist/esm/extractor/getTamaguiConfigPathFromOptionsConfig.mjs +5 -0
- package/dist/esm/extractor/hoistClassNames.mjs +24 -0
- package/dist/esm/extractor/literalToAst.mjs +48 -0
- package/dist/esm/extractor/loadFile.mjs +11 -0
- package/dist/esm/extractor/loadTamagui.mjs +233 -0
- package/dist/esm/extractor/logLines.mjs +11 -0
- package/dist/esm/extractor/normalizeTernaries.mjs +33 -0
- package/dist/esm/extractor/propsToFontFamilyCache.mjs +12 -0
- package/dist/esm/extractor/removeUnusedHooks.mjs +41 -0
- package/dist/esm/extractor/timer.mjs +19 -0
- package/dist/esm/extractor/validHTMLAttributes.mjs +49 -0
- package/dist/esm/getPragmaOptions.mjs +19 -0
- package/dist/esm/helpers/memoize.mjs +13 -0
- package/dist/esm/helpers/requireTamaguiCore.mjs +5 -0
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/minifyCSS.mjs +12 -0
- package/dist/esm/registerRequire.mjs +74 -0
- package/dist/esm/server.mjs +40 -0
- package/dist/esm/setup.mjs +1 -0
- package/dist/esm/static.mjs +10 -0
- package/dist/esm/types.mjs +0 -0
- package/dist/esm/webpackPlugin.mjs +7 -0
- package/package.json +15 -15
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Nate Wienert
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import findCacheDir from "find-cache-dir";
|
2
|
+
const CSS_FILE_NAME = "__snack.css",
|
3
|
+
MEDIA_SEP = "_",
|
4
|
+
cacheDir = findCacheDir({
|
5
|
+
name: "tamagui",
|
6
|
+
create: !0
|
7
|
+
}),
|
8
|
+
FAILED_EVAL = Symbol("failed_style_eval"),
|
9
|
+
SHOULD_DEBUG = process.env.DEBUG === "*" || process.env.DEBUG?.startsWith("tamagui");
|
10
|
+
export { CSS_FILE_NAME, FAILED_EVAL, MEDIA_SEP, SHOULD_DEBUG, cacheDir };
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import * as t from "@babel/types";
|
2
|
+
function accessSafe(obj, member) {
|
3
|
+
return t.logicalExpression("&&", t.logicalExpression("&&",
|
4
|
+
// typeof obj === 'object
|
5
|
+
t.binaryExpression("===", t.unaryExpression("typeof", obj), t.stringLiteral("object")),
|
6
|
+
// obj !== null
|
7
|
+
t.binaryExpression("!==", obj, t.nullLiteral())),
|
8
|
+
// obj.member
|
9
|
+
t.memberExpression(obj, t.identifier(member), !1));
|
10
|
+
}
|
11
|
+
export { accessSafe };
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import * as babelParser from "@babel/parser";
|
2
|
+
const plugins = ["asyncGenerators", "classProperties", "dynamicImport", "functionBind", "jsx", "numericSeparator", "objectRestSpread", "optionalCatchBinding", "decorators-legacy", "typescript", "optionalChaining", "nullishCoalescingOperator"],
|
3
|
+
parserOptions = Object.freeze({
|
4
|
+
plugins,
|
5
|
+
sourceType: "module"
|
6
|
+
}),
|
7
|
+
parser = babelParser.parse.bind(babelParser);
|
8
|
+
function babelParse(code, fileName) {
|
9
|
+
const codeString = code.toString();
|
10
|
+
try {
|
11
|
+
return parser(codeString, parserOptions);
|
12
|
+
} catch (err) {
|
13
|
+
throw new Error(`Error parsing babel: ${err} in ${fileName}, code:
|
14
|
+
${codeString}
|
15
|
+
${err.stack}`);
|
16
|
+
}
|
17
|
+
}
|
18
|
+
export { babelParse, parserOptions };
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import * as t from "@babel/types";
|
2
|
+
const buildClassName = (objectsIn, extras = "") => {
|
3
|
+
let objects = buildClassNameLogic(objectsIn);
|
4
|
+
return objects ? (t.isStringLiteral(objects) ? objects.value = `${extras} ${objects.value}` : objects = t.binaryExpression("+", t.stringLiteral(extras), objects), objects) : null;
|
5
|
+
},
|
6
|
+
buildClassNameLogic = objects => objects.reduce((acc, val) => {
|
7
|
+
if (acc == null) return (
|
8
|
+
// pass conditional expressions through
|
9
|
+
t.isConditionalExpression(val) ||
|
10
|
+
// pass non-null literals through
|
11
|
+
t.isStringLiteral(val) || t.isNumericLiteral(val) ? val : t.logicalExpression("||", val, t.stringLiteral(""))
|
12
|
+
);
|
13
|
+
let inner;
|
14
|
+
if (t.isStringLiteral(val)) {
|
15
|
+
if (t.isStringLiteral(acc)) return t.stringLiteral(`${acc.value} ${val.value}`);
|
16
|
+
inner = t.stringLiteral(` ${val.value}`);
|
17
|
+
} else if (t.isLiteral(val)) inner = t.binaryExpression("+", t.stringLiteral(" "), val);else if (t.isConditionalExpression(val) || t.isBinaryExpression(val)) {
|
18
|
+
if (t.isStringLiteral(acc)) return t.binaryExpression("+", t.stringLiteral(`${acc.value} `), val);
|
19
|
+
inner = t.binaryExpression("+", t.stringLiteral(" "), val);
|
20
|
+
} else if (t.isIdentifier(val) || t.isMemberExpression(val)) inner = t.conditionalExpression(val, t.binaryExpression("+", t.stringLiteral(" "), val), t.stringLiteral(""));else {
|
21
|
+
if (t.isStringLiteral(acc)) return t.binaryExpression("+", t.stringLiteral(`${acc.value} `), t.logicalExpression("||", val, t.stringLiteral("")));
|
22
|
+
inner = t.binaryExpression("+", t.stringLiteral(" "), t.logicalExpression("||", val, t.stringLiteral("")));
|
23
|
+
}
|
24
|
+
return t.binaryExpression("+", acc, inner);
|
25
|
+
}, null);
|
26
|
+
export { buildClassName, buildClassNameLogic };
|
@@ -0,0 +1,94 @@
|
|
1
|
+
import { basename, dirname, join } from "path";
|
2
|
+
import esbuild from "esbuild";
|
3
|
+
import { pathExists, stat, writeFile } from "fs-extra";
|
4
|
+
import { esbuildAliasPlugin } from "./esbuildAliasPlugin.mjs";
|
5
|
+
import { resolveWebOrNativeSpecificEntry } from "./loadTamagui.mjs";
|
6
|
+
function getESBuildConfig({
|
7
|
+
entryPoints,
|
8
|
+
resolvePlatformSpecificEntries,
|
9
|
+
...options
|
10
|
+
}, platform, aliases) {
|
11
|
+
process.env.DEBUG?.startsWith("tamagui") && console.info("Building", entryPoints);
|
12
|
+
const tsconfig = join(__dirname, "..", "..", "..", "tamagui.tsconfig.json");
|
13
|
+
return {
|
14
|
+
bundle: !0,
|
15
|
+
entryPoints: resolvePlatformSpecificEntries ? entryPoints.map(resolveWebOrNativeSpecificEntry) : entryPoints,
|
16
|
+
format: "cjs",
|
17
|
+
target: "node16",
|
18
|
+
jsx: "transform",
|
19
|
+
jsxFactory: "react",
|
20
|
+
allowOverwrite: !0,
|
21
|
+
keepNames: !0,
|
22
|
+
resolveExtensions: [".web.tsx", ".web.ts", ".web.jsx", ".web.js", ".tsx", ".ts", ".jsx", ".js"],
|
23
|
+
platform: "node",
|
24
|
+
tsconfig,
|
25
|
+
loader: {
|
26
|
+
".js": "jsx",
|
27
|
+
".png": "dataurl",
|
28
|
+
".jpg": "dataurl",
|
29
|
+
".jpeg": "dataurl",
|
30
|
+
".svg": "dataurl",
|
31
|
+
".gif": "dataurl",
|
32
|
+
".webp": "dataurl",
|
33
|
+
".woff2": "dataurl",
|
34
|
+
".woff": "dataurl",
|
35
|
+
".eot": "dataurl",
|
36
|
+
".otf": "dataurl",
|
37
|
+
".ttf": "dataurl"
|
38
|
+
},
|
39
|
+
logLevel: "warning",
|
40
|
+
plugins: [{
|
41
|
+
name: "external",
|
42
|
+
setup(build) {
|
43
|
+
build.onResolve({
|
44
|
+
filter: /@tamagui\/core/
|
45
|
+
}, args => ({
|
46
|
+
path: platform === "native" ? "@tamagui/core/native" : "@tamagui/core",
|
47
|
+
external: !0
|
48
|
+
})), build.onResolve({
|
49
|
+
filter: /react-native\/package.json$/
|
50
|
+
}, args => ({
|
51
|
+
path: "react-native/package.json",
|
52
|
+
external: !0
|
53
|
+
})), build.onResolve({
|
54
|
+
filter: /@tamagui\/web/
|
55
|
+
}, args => ({
|
56
|
+
path: platform === "native" ? "@tamagui/core/native" : "@tamagui/core",
|
57
|
+
external: !0
|
58
|
+
})), build.onResolve({
|
59
|
+
filter: /^(react-native|react-native\/.*)$/
|
60
|
+
}, args => ({
|
61
|
+
path: "react-native-web-lite",
|
62
|
+
external: !0
|
63
|
+
})), build.onResolve({
|
64
|
+
filter: /react-native-reanimated/
|
65
|
+
}, args => ({
|
66
|
+
path: "react-native-reanimated",
|
67
|
+
external: !0
|
68
|
+
}));
|
69
|
+
}
|
70
|
+
}, esbuildAliasPlugin({
|
71
|
+
...aliases
|
72
|
+
})],
|
73
|
+
...options
|
74
|
+
};
|
75
|
+
}
|
76
|
+
async function bundle(props, platform, aliases) {
|
77
|
+
await asyncLock(props);
|
78
|
+
const config = getESBuildConfig(props, platform, aliases);
|
79
|
+
return esbuild.build(config);
|
80
|
+
}
|
81
|
+
async function asyncLock(props) {
|
82
|
+
const lockFile = join(dirname(props.outfile), basename(props.outfile, ".lock")),
|
83
|
+
lockStat = await stat(lockFile).catch(() => {});
|
84
|
+
if ((lockStat ? /* @__PURE__ */new Date().getTime() - new Date(lockStat.mtime).getTime() : 1 / 0) < 500) {
|
85
|
+
process.env.DEBUG?.startsWith("tamagui") && console.info("Waiting for existing build", props.entryPoints);
|
86
|
+
let tries = 5;
|
87
|
+
for (; tries--;) {
|
88
|
+
if (await pathExists(props.outfile)) return;
|
89
|
+
await new Promise(res => setTimeout(res, 50));
|
90
|
+
}
|
91
|
+
}
|
92
|
+
writeFile(lockFile, "");
|
93
|
+
}
|
94
|
+
export { bundle };
|
@@ -0,0 +1,263 @@
|
|
1
|
+
import { readFileSync } from "fs";
|
2
|
+
import { basename, dirname, extname, join, relative, sep } from "path";
|
3
|
+
import generate from "@babel/generator";
|
4
|
+
import traverse from "@babel/traverse";
|
5
|
+
import * as t from "@babel/types";
|
6
|
+
import { Color, colorLog } from "@tamagui/cli-color";
|
7
|
+
import esbuild from "esbuild";
|
8
|
+
import { ensureDir, removeSync, writeFileSync } from "fs-extra";
|
9
|
+
import { registerRequire, setRequireResult } from "../registerRequire.mjs";
|
10
|
+
import { babelParse } from "./babelParse.mjs";
|
11
|
+
import { bundle } from "./bundle.mjs";
|
12
|
+
import { getTamaguiConfigPathFromOptionsConfig } from "./getTamaguiConfigPathFromOptionsConfig.mjs";
|
13
|
+
const external = ["@tamagui/core", "@tamagui/web", "react", "react-dom", "react-native-svg"],
|
14
|
+
esbuildExtraOptions = {
|
15
|
+
define: {
|
16
|
+
__DEV__: `${process.env.NODE_ENV === "development"}`
|
17
|
+
}
|
18
|
+
},
|
19
|
+
esbuildOptions = {
|
20
|
+
target: "es2018",
|
21
|
+
format: "cjs",
|
22
|
+
jsx: "automatic",
|
23
|
+
platform: "node",
|
24
|
+
...esbuildExtraOptions
|
25
|
+
};
|
26
|
+
let currentBundle = null,
|
27
|
+
isBundling = !1,
|
28
|
+
lastBundle = null;
|
29
|
+
const waitForBundle = /* @__PURE__ */new Set();
|
30
|
+
function hasBundledConfigChanged() {
|
31
|
+
return lastBundle === currentBundle ? !1 : (lastBundle = currentBundle, !0);
|
32
|
+
}
|
33
|
+
async function getBundledConfig(props, rebuild = !1) {
|
34
|
+
if (isBundling) await new Promise(res => {
|
35
|
+
waitForBundle.add(res);
|
36
|
+
});else if (!currentBundle || rebuild) return await bundleConfig(props);
|
37
|
+
return currentBundle;
|
38
|
+
}
|
39
|
+
async function bundleConfig(props) {
|
40
|
+
try {
|
41
|
+
isBundling = !0;
|
42
|
+
const configEntry = props.config ? getTamaguiConfigPathFromOptionsConfig(props.config) : "",
|
43
|
+
tmpDir = join(process.cwd(), ".tamagui"),
|
44
|
+
configOutPath = join(tmpDir, "tamagui.config.cjs"),
|
45
|
+
baseComponents = props.components.filter(x => x !== "@tamagui/core"),
|
46
|
+
componentOutPaths = baseComponents.map(componentModule => join(tmpDir, `${componentModule.split(sep).join("-").replace(/[^a-z0-9]+/gi, "")}-components.config.cjs`));
|
47
|
+
if (process.env.NODE_ENV === "development" && process.env.DEBUG?.startsWith("tamagui") && console.info("Building config entry", configEntry), !props.disableInitialBuild) {
|
48
|
+
try {
|
49
|
+
await ensureDir(tmpDir);
|
50
|
+
} catch {}
|
51
|
+
const start = Date.now();
|
52
|
+
await Promise.all([props.config ? bundle({
|
53
|
+
entryPoints: [configEntry],
|
54
|
+
external,
|
55
|
+
outfile: configOutPath,
|
56
|
+
target: "node16",
|
57
|
+
...esbuildExtraOptions
|
58
|
+
}, props.platform) : null, ...baseComponents.map((componentModule, i) => bundle({
|
59
|
+
entryPoints: [componentModule],
|
60
|
+
resolvePlatformSpecificEntries: !0,
|
61
|
+
external,
|
62
|
+
outfile: componentOutPaths[i],
|
63
|
+
target: "node16",
|
64
|
+
...esbuildExtraOptions
|
65
|
+
}, props.platform))]), colorLog(Color.FgYellow, `
|
66
|
+
\u27A1 [tamagui] built config and components (${Date.now() - start}ms):`), colorLog(Color.Dim, `
|
67
|
+
Config .${sep}${relative(process.cwd(), configOutPath)}
|
68
|
+
Components ${[...componentOutPaths.map(p => `.${sep}${relative(process.cwd(), p)}`)].join(`
|
69
|
+
`)}
|
70
|
+
`);
|
71
|
+
}
|
72
|
+
let out;
|
73
|
+
const {
|
74
|
+
unregister
|
75
|
+
} = registerRequire(props.platform);
|
76
|
+
try {
|
77
|
+
out = require(configOutPath);
|
78
|
+
} catch (err) {
|
79
|
+
throw err;
|
80
|
+
} finally {
|
81
|
+
unregister();
|
82
|
+
}
|
83
|
+
let config = out.default || out || out.config;
|
84
|
+
if (config && config.config && !config.tokens && (config = config.config), !config) throw new Error(`No config: ${config}`);
|
85
|
+
let components = loadComponents({
|
86
|
+
...props,
|
87
|
+
components: componentOutPaths
|
88
|
+
});
|
89
|
+
if (!components) throw new Error(`No components found: ${componentOutPaths.join(", ")}`);
|
90
|
+
for (const component of components) component.moduleName = baseComponents[componentOutPaths.indexOf(component.moduleName)] || component.moduleName, component.moduleName || (process.env.DEBUG?.includes("tamagui") || process.env.IS_TAMAGUI_DEV) && console.warn(`\u26A0\uFE0F no module name found: ${component.moduleName} ${JSON.stringify(baseComponents)} in ${JSON.stringify(componentOutPaths)}`);
|
91
|
+
process.env.NODE_ENV === "development" && process.env.DEBUG?.startsWith("tamagui") && console.info("Loaded components", components);
|
92
|
+
const res = {
|
93
|
+
components,
|
94
|
+
nameToPaths: {},
|
95
|
+
tamaguiConfig: config
|
96
|
+
};
|
97
|
+
return currentBundle = res, res;
|
98
|
+
} catch (err) {
|
99
|
+
console.error(`Error bundling tamagui config: ${err?.message} (run with DEBUG=tamagui to see stack)`), process.env.DEBUG?.includes("tamagui") && console.error(err.stack);
|
100
|
+
} finally {
|
101
|
+
isBundling = !1, waitForBundle.forEach(cb => cb()), waitForBundle.clear();
|
102
|
+
}
|
103
|
+
}
|
104
|
+
function loadComponents(props, forceExports = !1) {
|
105
|
+
const coreComponents = getCoreComponents(props),
|
106
|
+
otherComponents = loadComponentsInner(props, forceExports);
|
107
|
+
return [...coreComponents, ...(otherComponents || [])];
|
108
|
+
}
|
109
|
+
function getCoreComponents(props) {
|
110
|
+
const loaded = loadComponentsInner({
|
111
|
+
...props,
|
112
|
+
components: ["@tamagui/core"]
|
113
|
+
});
|
114
|
+
if (!loaded) throw new Error("Core should always load");
|
115
|
+
return [{
|
116
|
+
...loaded[0],
|
117
|
+
moduleName: "@tamagui/core"
|
118
|
+
}];
|
119
|
+
}
|
120
|
+
function loadComponentsInner(props, forceExports = !1) {
|
121
|
+
const componentsModules = props.components,
|
122
|
+
key = componentsModules.join("");
|
123
|
+
if (!forceExports && cacheComponents[key]) return cacheComponents[key];
|
124
|
+
const {
|
125
|
+
unregister
|
126
|
+
} = registerRequire(props.platform, {
|
127
|
+
proxyWormImports: forceExports
|
128
|
+
});
|
129
|
+
try {
|
130
|
+
const info = componentsModules.flatMap(name => {
|
131
|
+
const isDynamic = !!extname(name) && forceExports,
|
132
|
+
fileContents = isDynamic ? readFileSync(name, "utf-8") : "",
|
133
|
+
loadModule = isDynamic ? join(dirname(name), `.tamagui-dynamic-eval-${basename(name)}.tsx`) : name;
|
134
|
+
let writtenContents = fileContents,
|
135
|
+
didBabel = !1;
|
136
|
+
function attemptLoad({
|
137
|
+
forceExports: forceExports2 = !1
|
138
|
+
} = {}) {
|
139
|
+
isDynamic && (writtenContents = forceExports2 ? transformAddExports(babelParse(esbuildit(fileContents, "modern"), name)) : fileContents, writeFileSync(loadModule, writtenContents), esbuild.buildSync({
|
140
|
+
...esbuildOptions,
|
141
|
+
entryPoints: [loadModule],
|
142
|
+
outfile: loadModule,
|
143
|
+
alias: {
|
144
|
+
"react-native": require.resolve("react-native-web-lite")
|
145
|
+
},
|
146
|
+
bundle: !0,
|
147
|
+
packages: "external",
|
148
|
+
allowOverwrite: !0,
|
149
|
+
// logLevel: 'silent',
|
150
|
+
sourcemap: !1,
|
151
|
+
loader: {
|
152
|
+
".png": "dataurl",
|
153
|
+
".jpg": "dataurl",
|
154
|
+
".jpeg": "dataurl",
|
155
|
+
".gif": "dataurl"
|
156
|
+
}
|
157
|
+
})), process.env.DEBUG === "tamagui" && console.info("loadModule", loadModule, require.resolve(loadModule));
|
158
|
+
const moduleResult = require(loadModule);
|
159
|
+
forceExports2 || setRequireResult(name, moduleResult);
|
160
|
+
const nameToInfo = getComponentStaticConfigByName(name, interopDefaultExport(moduleResult));
|
161
|
+
return {
|
162
|
+
moduleName: name,
|
163
|
+
nameToInfo
|
164
|
+
};
|
165
|
+
}
|
166
|
+
const dispose = () => {
|
167
|
+
isDynamic && removeSync(loadModule);
|
168
|
+
};
|
169
|
+
try {
|
170
|
+
const res = attemptLoad({
|
171
|
+
forceExports: !0
|
172
|
+
});
|
173
|
+
return didBabel = !0, res;
|
174
|
+
} catch (err) {
|
175
|
+
console.info("babel err", err, writtenContents), writtenContents = fileContents, process.env.DEBUG?.startsWith("tamagui") && console.info("Error parsing babel likely", err);
|
176
|
+
} finally {
|
177
|
+
dispose();
|
178
|
+
}
|
179
|
+
try {
|
180
|
+
return attemptLoad({
|
181
|
+
forceExports: !1
|
182
|
+
});
|
183
|
+
} catch (err) {
|
184
|
+
return process.env.TAMAGUI_ENABLE_WARN_DYNAMIC_LOAD && (console.info(`
|
185
|
+
|
186
|
+
Tamagui attempted but failed to dynamically optimize components in:
|
187
|
+
${name}
|
188
|
+
`), console.info(err), console.info(`At: ${loadModule}`, `
|
189
|
+
didBabel: ${didBabel}`, `
|
190
|
+
In:`, writtenContents, `
|
191
|
+
isDynamic: `, isDynamic)), [];
|
192
|
+
} finally {
|
193
|
+
dispose();
|
194
|
+
}
|
195
|
+
});
|
196
|
+
return cacheComponents[key] = info, info;
|
197
|
+
} catch (err) {
|
198
|
+
return console.info("Tamagui error bundling components", err.message, err.stack), null;
|
199
|
+
} finally {
|
200
|
+
unregister();
|
201
|
+
}
|
202
|
+
}
|
203
|
+
const esbuildit = (src, target) => esbuild.transformSync(src, {
|
204
|
+
...esbuildOptions,
|
205
|
+
...(target === "modern" && {
|
206
|
+
target: "es2022",
|
207
|
+
jsx: "automatic",
|
208
|
+
loader: "tsx",
|
209
|
+
platform: "neutral",
|
210
|
+
format: "esm"
|
211
|
+
})
|
212
|
+
}).code;
|
213
|
+
function getComponentStaticConfigByName(name, exported) {
|
214
|
+
const components = {};
|
215
|
+
try {
|
216
|
+
if (!exported || typeof exported != "object" || Array.isArray(exported)) throw new Error(`Invalid export from package ${name}: ${typeof exported}`);
|
217
|
+
for (const key in exported) {
|
218
|
+
const found = getTamaguiComponent(key, exported[key]);
|
219
|
+
if (found) {
|
220
|
+
const {
|
221
|
+
Component,
|
222
|
+
...sc
|
223
|
+
} = found.staticConfig;
|
224
|
+
components[key] = {
|
225
|
+
staticConfig: sc
|
226
|
+
};
|
227
|
+
}
|
228
|
+
}
|
229
|
+
} catch (err) {
|
230
|
+
process.env.TAMAGUI_ENABLE_WARN_DYNAMIC_LOAD && (console.error(`Tamagui failed getting components from ${name} (Disable error by setting environment variable TAMAGUI_ENABLE_WARN_DYNAMIC_LOAD=1)`), console.error(err));
|
231
|
+
}
|
232
|
+
return components;
|
233
|
+
}
|
234
|
+
function getTamaguiComponent(name, Component) {
|
235
|
+
if (name[0].toUpperCase() !== name[0]) return;
|
236
|
+
if (Component?.staticConfig) return Component;
|
237
|
+
}
|
238
|
+
function interopDefaultExport(mod) {
|
239
|
+
return mod?.default ?? mod;
|
240
|
+
}
|
241
|
+
const cacheComponents = {};
|
242
|
+
function transformAddExports(ast) {
|
243
|
+
const usedNames = /* @__PURE__ */new Set();
|
244
|
+
return traverse(ast, {
|
245
|
+
ExportNamedDeclaration(nodePath) {
|
246
|
+
if (nodePath.node.specifiers) for (const spec of nodePath.node.specifiers) usedNames.add(t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value);
|
247
|
+
}
|
248
|
+
}), traverse(ast, {
|
249
|
+
VariableDeclaration(nodePath) {
|
250
|
+
if (!t.isProgram(nodePath.parent)) return;
|
251
|
+
const decs = nodePath.node.declarations;
|
252
|
+
if (decs.length > 1) return;
|
253
|
+
const [dec] = decs;
|
254
|
+
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))]))));
|
255
|
+
}
|
256
|
+
}), generate(ast, {
|
257
|
+
concise: !1,
|
258
|
+
filename: "test.tsx",
|
259
|
+
retainLines: !1,
|
260
|
+
sourceMaps: !1
|
261
|
+
}).code;
|
262
|
+
}
|
263
|
+
export { bundleConfig, esbuildOptions, getBundledConfig, hasBundledConfigChanged, loadComponents, loadComponentsInner };
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import vm from "vm";
|
2
|
+
import generate from "@babel/generator";
|
3
|
+
import * as t from "@babel/types";
|
4
|
+
import esbuild from "esbuild";
|
5
|
+
import { FAILED_EVAL } from "../constants.mjs";
|
6
|
+
import { evaluateAstNode } from "./evaluateAstNode.mjs";
|
7
|
+
function createEvaluator({
|
8
|
+
props,
|
9
|
+
staticNamespace,
|
10
|
+
sourcePath,
|
11
|
+
traversePath,
|
12
|
+
shouldPrintDebug
|
13
|
+
}) {
|
14
|
+
const evalFn = n => {
|
15
|
+
if (t.isIdentifier(n) && typeof staticNamespace[n.name] < "u") return staticNamespace[n.name];
|
16
|
+
const evalContext = vm.createContext(staticNamespace),
|
17
|
+
codeWithTypescriptAnnotations = `(${generate(n).code})`,
|
18
|
+
code = esbuild.transformSync(codeWithTypescriptAnnotations, {
|
19
|
+
loader: "tsx"
|
20
|
+
}).code.replace(/;\n$/, "");
|
21
|
+
return shouldPrintDebug && console.info("evaluating", code), vm.runInContext(code, evalContext);
|
22
|
+
};
|
23
|
+
return n => evaluateAstNode(n, evalFn);
|
24
|
+
}
|
25
|
+
function createSafeEvaluator(attemptEval) {
|
26
|
+
return n => {
|
27
|
+
try {
|
28
|
+
return attemptEval(n);
|
29
|
+
} catch {
|
30
|
+
return FAILED_EVAL;
|
31
|
+
}
|
32
|
+
};
|
33
|
+
}
|
34
|
+
export { createEvaluator, createSafeEvaluator };
|