@tamagui/static 1.0.0-beta.153 → 1.0.0-beta.181

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/cjs/constants.js +8 -0
  2. package/dist/cjs/extractor/accessSafe.js +4 -0
  3. package/dist/cjs/extractor/babelParse.js +5 -0
  4. package/dist/cjs/extractor/babelParse.js.map +2 -2
  5. package/dist/cjs/extractor/buildClassName.js +4 -0
  6. package/dist/cjs/extractor/createEvaluator.js +5 -0
  7. package/dist/cjs/extractor/createExtractor.js +120 -72
  8. package/dist/cjs/extractor/createExtractor.js.map +2 -2
  9. package/dist/cjs/extractor/ensureImportingConcat.js +4 -0
  10. package/dist/cjs/extractor/evaluateAstNode.js +4 -0
  11. package/dist/cjs/extractor/extractHelpers.js +11 -0
  12. package/dist/cjs/extractor/extractMediaStyle.js +5 -0
  13. package/dist/cjs/extractor/extractMediaStyle.js.map +2 -2
  14. package/dist/cjs/extractor/extractToClassNames.js +12 -4
  15. package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
  16. package/dist/cjs/extractor/findTopmostFunction.js +4 -0
  17. package/dist/cjs/extractor/generatedUid.js +4 -0
  18. package/dist/cjs/extractor/getPrefixLogs.js +4 -0
  19. package/dist/cjs/extractor/getPropValueFromAttributes.js +4 -0
  20. package/dist/cjs/extractor/getSourceModule.js +4 -0
  21. package/dist/cjs/extractor/getStaticBindingsForScope.js +4 -0
  22. package/dist/cjs/extractor/hoistClassNames.js +4 -0
  23. package/dist/cjs/extractor/literalToAst.js +5 -0
  24. package/dist/cjs/extractor/loadTamagui.js +67 -47
  25. package/dist/cjs/extractor/loadTamagui.js.map +2 -2
  26. package/dist/cjs/extractor/logLines.js +4 -0
  27. package/dist/cjs/extractor/normalizeTernaries.js +4 -0
  28. package/dist/cjs/extractor/removeUnusedHooks.js +4 -0
  29. package/dist/cjs/extractor/timer.js +46 -0
  30. package/dist/cjs/extractor/timer.js.map +7 -0
  31. package/dist/cjs/extractor/validHTMLAttributes.js +4 -0
  32. package/dist/cjs/index.js +6 -0
  33. package/dist/cjs/patchReactNativeWeb.js +23 -7
  34. package/dist/cjs/patchReactNativeWeb.js.map +2 -2
  35. package/dist/esm/extractor/babelParse.js.map +2 -2
  36. package/dist/esm/extractor/createExtractor.js +123 -79
  37. package/dist/esm/extractor/createExtractor.js.map +2 -2
  38. package/dist/esm/extractor/extractMediaStyle.js.map +2 -2
  39. package/dist/esm/extractor/extractToClassNames.js +8 -4
  40. package/dist/esm/extractor/extractToClassNames.js.map +2 -2
  41. package/dist/esm/extractor/loadTamagui.js +63 -47
  42. package/dist/esm/extractor/loadTamagui.js.map +2 -2
  43. package/dist/esm/extractor/timer.js +24 -0
  44. package/dist/esm/extractor/timer.js.map +7 -0
  45. package/dist/esm/patchReactNativeWeb.js +19 -7
  46. package/dist/esm/patchReactNativeWeb.js.map +2 -2
  47. package/dist/jsx/extractor/createExtractor.js +123 -79
  48. package/dist/jsx/extractor/extractToClassNames.js +8 -4
  49. package/dist/jsx/extractor/loadTamagui.js +63 -47
  50. package/dist/jsx/extractor/timer.js +23 -0
  51. package/dist/jsx/patchReactNativeWeb.js +19 -7
  52. package/package.json +9 -9
  53. package/types/extractor/babelParse.d.ts.map +1 -1
  54. package/types/extractor/createExtractor.d.ts.map +1 -1
  55. package/types/extractor/extractMediaStyle.d.ts +1 -1
  56. package/types/extractor/extractMediaStyle.d.ts.map +1 -1
  57. package/types/extractor/extractToClassNames.d.ts +2 -1
  58. package/types/extractor/extractToClassNames.d.ts.map +1 -1
  59. package/types/extractor/loadTamagui.d.ts.map +1 -1
  60. package/types/extractor/timer.d.ts +5 -0
  61. package/types/extractor/timer.d.ts.map +1 -0
  62. package/types/patchReactNativeWeb.d.ts.map +1 -1
@@ -5,6 +5,7 @@ import * as t from "@babel/types";
5
5
  import {
6
6
  getSplitStyles,
7
7
  mediaQueryConfig,
8
+ normalizeStyleObject,
8
9
  pseudos,
9
10
  rnw
10
11
  } from "@tamagui/core-node";
@@ -20,6 +21,7 @@ import { loadTamagui } from "./loadTamagui";
20
21
  import { logLines } from "./logLines";
21
22
  import { normalizeTernaries } from "./normalizeTernaries";
22
23
  import { removeUnusedHooks } from "./removeUnusedHooks";
24
+ import { timer } from "./timer";
23
25
  import { validHTMLAttributes } from "./validHTMLAttributes";
24
26
  const UNTOUCHED_PROPS = {
25
27
  key: true,
@@ -47,10 +49,6 @@ function createExtractor() {
47
49
  process.exit(1);
48
50
  }
49
51
  const shouldAddDebugProp = !process.env.npm_package_dependencies_next && process.env.TAMAGUI_TARGET !== "native" && process.env.IDENTIFY_TAGS !== "false" && (process.env.NODE_ENV === "development" || process.env.DEBUG || process.env.IDENTIFY_TAGS);
50
- require("esbuild-register/dist/node").register({
51
- target: "es2019",
52
- format: "cjs"
53
- });
54
52
  let loadedTamaguiConfig;
55
53
  let hasLogged = false;
56
54
  return {
@@ -83,10 +81,15 @@ function createExtractor() {
83
81
  if (!Array.isArray(props.components)) {
84
82
  throw new Error(`Must provide components array with list of Tamagui component modules`);
85
83
  }
84
+ const tm = timer();
86
85
  const { components, tamaguiConfig } = loadTamagui({
87
86
  config,
88
87
  components: props.components || ["tamagui"]
89
88
  });
89
+ if (shouldPrintDebug === "verbose") {
90
+ console.log("tamagui.config.ts:", { components, config });
91
+ }
92
+ tm.mark("load-tamagui", shouldPrintDebug === "verbose");
90
93
  loadedTamaguiConfig = tamaguiConfig;
91
94
  const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]];
92
95
  const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
@@ -100,6 +103,9 @@ function createExtractor() {
100
103
  obj[name] = components[name];
101
104
  return obj;
102
105
  }, {});
106
+ if (shouldPrintDebug === "verbose") {
107
+ console.log("validComponents", Object.keys(validComponents));
108
+ }
103
109
  let doesUseValidImport = false;
104
110
  let hasImportedTheme = false;
105
111
  for (const bodyPath of body) {
@@ -107,11 +113,16 @@ function createExtractor() {
107
113
  continue;
108
114
  const node = "node" in bodyPath ? bodyPath.node : bodyPath;
109
115
  const from = node.source.value;
110
- if (props.components.includes(from) || isInternalImport(from)) {
111
- if (node.specifiers.some((specifier) => {
116
+ const isValidImport = props.components.includes(from) || isInternalImport(from);
117
+ if (isValidImport) {
118
+ const isValidComponent = node.specifiers.some((specifier) => {
112
119
  const name = specifier.local.name;
113
120
  return validComponents[name] || validHooks[name];
114
- })) {
121
+ });
122
+ if (shouldPrintDebug === "verbose") {
123
+ console.log("import from", from, { isValidComponent });
124
+ }
125
+ if (isValidComponent) {
115
126
  doesUseValidImport = true;
116
127
  break;
117
128
  }
@@ -123,6 +134,7 @@ function createExtractor() {
123
134
  if (!doesUseValidImport) {
124
135
  return null;
125
136
  }
137
+ tm.mark("import-check", shouldPrintDebug === "verbose");
126
138
  let couldntParse = false;
127
139
  const modifiedComponents = /* @__PURE__ */ new Set();
128
140
  const bindingCache = {};
@@ -144,6 +156,7 @@ function createExtractor() {
144
156
  },
145
157
  JSXElement(traversePath) {
146
158
  var _a, _b, _c, _d, _e;
159
+ tm.mark("jsx-element", shouldPrintDebug === "verbose");
147
160
  const node = traversePath.node.openingElement;
148
161
  const ogAttributes = node.attributes;
149
162
  const componentName = findComponentName(traversePath.scope);
@@ -571,6 +584,11 @@ function createExtractor() {
571
584
  for (const key in next) {
572
585
  if (pseudos[key]) {
573
586
  prev2[key] = prev2[key] || {};
587
+ if (shouldPrintDebug) {
588
+ if (!next[key] || !prev2[key]) {
589
+ console.log("warn: missing", key, prev2, next);
590
+ }
591
+ }
574
592
  Object.assign(prev2[key], next[key]);
575
593
  } else {
576
594
  prev2[key] = next[key];
@@ -680,6 +698,7 @@ function createExtractor() {
680
698
  if (couldntParse) {
681
699
  return;
682
700
  }
701
+ tm.mark("jsx-element-flattened", shouldPrintDebug === "verbose");
683
702
  node.attributes = flattenedAttrs;
684
703
  if (staticConfig.defaultProps) {
685
704
  for (const key in staticConfig.defaultProps) {
@@ -705,6 +724,7 @@ function createExtractor() {
705
724
  attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
706
725
  try {
707
726
  const res2 = evaluateAttribute(path);
727
+ tm.mark("jsx-element-evaluate-attr", shouldPrintDebug === "verbose");
708
728
  if (!res2) {
709
729
  path.remove();
710
730
  }
@@ -767,45 +787,25 @@ function createExtractor() {
767
787
  out.push(cur);
768
788
  return out;
769
789
  }, []).flat();
770
- const completeStaticProps = {
771
- ...Object.keys(attrs).reduce((acc, index) => {
772
- const cur = attrs[index];
773
- if (cur.type === "style") {
774
- Object.assign(acc, cur.value);
775
- }
776
- if (cur.type === "attr") {
777
- if (t.isJSXSpreadAttribute(cur.value)) {
778
- return acc;
779
- }
780
- if (!t.isJSXIdentifier(cur.value.name)) {
781
- return acc;
782
- }
783
- const key = cur.value.name.name;
784
- const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
785
- if (value === FAILED_EVAL) {
786
- return acc;
787
- }
788
- acc[key] = value;
789
- }
790
- return acc;
791
- }, {})
792
- };
793
790
  const hasSpread = node.attributes.some((x) => t.isJSXSpreadAttribute(x));
794
791
  const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
795
792
  const themeVal = inlined.get("theme");
796
793
  inlined.delete("theme");
797
794
  const allOtherPropsExtractable = [...inlined].every(([k, v]) => INLINE_EXTRACTABLE[k]);
798
- const shouldWrapInnerTheme = allOtherPropsExtractable && !!(hasOnlyStringChildren && themeVal);
799
- const canFlattenProps = inlined.size === 0 || shouldWrapInnerTheme || allOtherPropsExtractable;
795
+ const shouldWrapThme = allOtherPropsExtractable && !!themeVal;
796
+ const canFlattenProps = inlined.size === 0 || shouldWrapThme || allOtherPropsExtractable;
800
797
  let shouldFlatten = !shouldDeopt && canFlattenProps && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
801
- if (shouldFlatten && shouldWrapInnerTheme) {
798
+ if (shouldPrintDebug) {
799
+ console.log(" >>", { hasSpread, shouldDeopt, shouldFlatten, canFlattenProps, shouldWrapThme, allOtherPropsExtractable, hasOnlyStringChildren });
800
+ }
801
+ if (shouldFlatten && shouldWrapThme) {
802
802
  if (typeof themeVal !== "string") {
803
- console.warn("??");
804
803
  return;
805
804
  }
806
805
  if (shouldPrintDebug) {
807
806
  console.log(" - wrapping theme", allOtherPropsExtractable, themeVal);
808
807
  }
808
+ attrs = attrs.filter((x) => x.type === "attr" && t.isJSXAttribute(x.value) && x.value.name.name === "theme" ? false : true);
809
809
  if (!hasImportedTheme) {
810
810
  hasImportedTheme = true;
811
811
  programPath.node.body.push(t.importDeclaration([t.importSpecifier(t.identifier("_TamaguiTheme"), t.identifier("Theme"))], t.stringLiteral("@tamagui/core")));
@@ -817,23 +817,21 @@ function createExtractor() {
817
817
  if (shouldFlatten && staticConfig.defaultProps) {
818
818
  const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap((key) => {
819
819
  if (!isValidStyleKey(key)) {
820
- return;
820
+ return [];
821
821
  }
822
- try {
823
- const serialize = require("babel-literal-to-ast");
824
- const val = staticConfig.defaultProps[key];
825
- const value = serialize(val);
826
- const name = tamaguiConfig.shorthands[key] || key;
827
- return {
828
- type: "style",
829
- name,
830
- value
831
- };
832
- } catch (err) {
833
- console.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${key}
834
- error: ${err}`);
822
+ const value = staticConfig.defaultProps[key];
823
+ const name = tamaguiConfig.shorthands[key] || key;
824
+ if (value === void 0) {
825
+ console.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${key} ${value}`);
835
826
  shouldDeopt = true;
827
+ return;
836
828
  }
829
+ const attr = {
830
+ type: "style",
831
+ name,
832
+ value: { [name]: value }
833
+ };
834
+ return attr;
837
835
  });
838
836
  if (defaultStyleAttrs.length) {
839
837
  attrs = [...defaultStyleAttrs, ...attrs];
@@ -901,6 +899,7 @@ function createExtractor() {
901
899
  acc.push(cur);
902
900
  return acc;
903
901
  }, []);
902
+ tm.mark("jsx-element-expanded", shouldPrintDebug === "verbose");
904
903
  if (shouldPrintDebug) {
905
904
  console.log(" - attrs (expanded): \n", logLines(attrs.map(attrStr).join(", ")));
906
905
  }
@@ -937,54 +936,91 @@ function createExtractor() {
937
936
  acc.push(cur);
938
937
  return acc;
939
938
  }, []);
940
- if (shouldPrintDebug) {
941
- console.log(" - attrs (combined \u{1F500}): \n", logLines(attrs.map(attrStr).join(", ")));
942
- }
939
+ const state = {
940
+ noClassNames: true,
941
+ focus: false,
942
+ hover: false,
943
+ mounted: true,
944
+ press: false,
945
+ pressIn: false
946
+ };
947
+ const completeStaticProps = Object.keys(attrs).reduce((acc, index) => {
948
+ const cur = attrs[index];
949
+ if (cur.type === "style") {
950
+ normalizeStyleObject(cur.value);
951
+ Object.assign(acc, cur.value);
952
+ }
953
+ if (cur.type === "attr") {
954
+ if (t.isJSXSpreadAttribute(cur.value)) {
955
+ return acc;
956
+ }
957
+ if (!t.isJSXIdentifier(cur.value.name)) {
958
+ return acc;
959
+ }
960
+ const key = cur.value.name.name;
961
+ const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
962
+ if (value === FAILED_EVAL) {
963
+ return acc;
964
+ }
965
+ acc[key] = value;
966
+ }
967
+ return acc;
968
+ }, {});
943
969
  const completeProps = {
944
970
  ...staticConfig.defaultProps,
945
971
  ...completeStaticProps
946
972
  };
973
+ if (shouldPrintDebug) {
974
+ console.log(" - attrs (combined \u{1F500}): \n", logLines(attrs.map(attrStr).join(", ")));
975
+ console.log(" - defaultProps: \n", logLines(objToStr(staticConfig.defaultProps)));
976
+ console.log(" - completeStaticProps: \n", logLines(objToStr(completeStaticProps)));
977
+ }
947
978
  const getStyles = /* @__PURE__ */ __name((props2, debugName = "") => {
948
- if (!props2)
949
- return;
950
- if (!Object.keys(props2).length)
951
- return;
979
+ if (!props2 || !Object.keys(props2).length) {
980
+ if (shouldPrintDebug)
981
+ console.log(" getStyles() no props");
982
+ return {};
983
+ }
952
984
  if (excludeProps && !!excludeProps.size) {
953
985
  for (const key in props2) {
954
986
  if (excludeProps.has(key)) {
987
+ if (shouldPrintDebug)
988
+ console.log(" delete excluded", key);
955
989
  delete props2[key];
956
990
  }
957
991
  }
958
992
  }
959
- const out = getSplitStyles(props2, staticConfig, defaultTheme, {
960
- noClassNames: true,
961
- fallbackProps: completeProps,
962
- focus: false,
963
- hover: false,
964
- mounted: true,
965
- press: false,
966
- pressIn: false
967
- });
968
- const outStyle = {
969
- ...out.style,
970
- ...out.pseudos
971
- };
972
- for (const key in outStyle) {
993
+ try {
994
+ const out = getSplitStyles(props2, staticConfig, defaultTheme, {
995
+ ...state,
996
+ fallbackProps: completeProps
997
+ });
998
+ const outStyle = {
999
+ ...out.style,
1000
+ ...out.pseudos
1001
+ };
973
1002
  if (staticConfig.validStyles) {
974
- if (!staticConfig.validStyles[key] && !pseudos[key]) {
975
- delete outStyle[key];
1003
+ for (const key in outStyle) {
1004
+ if (!staticConfig.validStyles[key] && !pseudos[key] && !/(hover|focus|press)Style$/.test(key)) {
1005
+ if (shouldPrintDebug)
1006
+ console.log(" delete invalid style", key);
1007
+ delete outStyle[key];
1008
+ }
976
1009
  }
977
1010
  }
978
- }
979
- if (shouldPrintDebug === "verbose") {
980
- console.log(` getStyles ${debugName} (props):
1011
+ if (shouldPrintDebug) {
1012
+ console.log(` getStyles ${debugName} (props):
981
1013
  `, logLines(objToStr(props2)));
982
- console.log(` getStyles ${debugName} (out.viewProps):
1014
+ console.log(` getStyles ${debugName} (out.viewProps):
983
1015
  `, logLines(objToStr(out.viewProps)));
984
- console.log(` getStyles ${debugName} (out.style):
1016
+ console.log(` getStyles ${debugName} (out.style):
985
1017
  `, logLines(objToStr(outStyle || {}), true));
1018
+ }
1019
+ return outStyle;
1020
+ } catch (err) {
1021
+ console.log("error", err.message, err.stack);
1022
+ return {};
986
1023
  }
987
- return outStyle;
988
1024
  }, "getStyles");
989
1025
  const completeStylesProcessed = getStyles(completeProps, "completeStylesProcessed");
990
1026
  if (!completeStylesProcessed) {
@@ -1025,11 +1061,13 @@ function createExtractor() {
1025
1061
  console.log(" => tern ", attrStr(attr));
1026
1062
  continue;
1027
1063
  case "style":
1064
+ if (shouldPrintDebug)
1065
+ console.log(" * styles in", logLines(objToStr(attr.value)));
1028
1066
  const styles = getStyles(attr.value, "style");
1067
+ if (shouldPrintDebug)
1068
+ console.log(" * styles out", logLines(objToStr(styles)));
1029
1069
  if (styles) {
1030
1070
  attr.value = Object.fromEntries(Object.keys(styles).map((k) => [k, completeStylesProcessed[k]]));
1031
- } else {
1032
- console.warn("?????????");
1033
1071
  }
1034
1072
  continue;
1035
1073
  }
@@ -1037,6 +1075,7 @@ function createExtractor() {
1037
1075
  getStyleError = err;
1038
1076
  }
1039
1077
  }
1078
+ tm.mark("jsx-element-styles", shouldPrintDebug === "verbose");
1040
1079
  if (getStyleError) {
1041
1080
  console.log(" \u26A0\uFE0F postprocessing error, deopt", getStyleError);
1042
1081
  node.attributes = ogAttributes;
@@ -1060,6 +1099,9 @@ function createExtractor() {
1060
1099
  if (attr.type === "style") {
1061
1100
  for (const key in attr.value) {
1062
1101
  if (existingStyleKeys.has(key)) {
1102
+ if (shouldPrintDebug) {
1103
+ console.log(" >> delete existing", key);
1104
+ }
1063
1105
  delete attr.value[key];
1064
1106
  } else {
1065
1107
  existingStyleKeys.add(key);
@@ -1101,6 +1143,7 @@ function createExtractor() {
1101
1143
  }
1102
1144
  }
1103
1145
  });
1146
+ tm.mark("jsx-done", shouldPrintDebug === "verbose");
1104
1147
  if (modifiedComponents.size) {
1105
1148
  const all = Array.from(modifiedComponents);
1106
1149
  if (shouldPrintDebug) {
@@ -1110,6 +1153,7 @@ function createExtractor() {
1110
1153
  removeUnusedHooks(comp, shouldPrintDebug);
1111
1154
  }
1112
1155
  }
1156
+ tm.done(shouldPrintDebug === "verbose");
1113
1157
  return res;
1114
1158
  }
1115
1159
  };
@@ -18,6 +18,7 @@ import { getPrefixLogs } from "./getPrefixLogs";
18
18
  import { hoistClassNames } from "./hoistClassNames";
19
19
  import { literalToAst } from "./literalToAst";
20
20
  import { logLines } from "./logLines";
21
+ import { timer } from "./timer";
21
22
  const mergeStyleGroups = {
22
23
  shadowOpacity: true,
23
24
  shadowRadius: true,
@@ -31,10 +32,12 @@ function extractToClassNames({
31
32
  sourcePath,
32
33
  options,
33
34
  shouldPrintDebug,
35
+ cssLoaderPath,
34
36
  threaded,
35
37
  cssPath
36
38
  }) {
37
39
  var _a;
40
+ const tm = timer();
38
41
  if (typeof source !== "string") {
39
42
  throw new Error("`source` must be a string of javascript");
40
43
  }
@@ -49,6 +52,7 @@ function extractToClassNames({
49
52
  console.error("babel parse error:", sourcePath);
50
53
  throw err;
51
54
  }
55
+ tm.mark(`babel-parse`, shouldPrintDebug === "verbose");
52
56
  const cssMap = /* @__PURE__ */ new Map();
53
57
  const existingHoists = {};
54
58
  let hasFlattened = false;
@@ -246,7 +250,7 @@ function extractToClassNames({
246
250
  if (styles) {
247
251
  const cssQuery = threaded ? `cssData=${Buffer.from(styles).toString("base64")}` : `cssPath=${cssPath}`;
248
252
  const remReq = loader.remainingRequest;
249
- const importPath = `${cssPath}!=!tamagui-loader?${cssQuery}!${remReq}`;
253
+ const importPath = `${cssPath}!=!${cssLoaderPath}?${cssQuery}!${remReq}`;
250
254
  ast.program.body.unshift(t.importDeclaration([], t.stringLiteral(importPath)));
251
255
  }
252
256
  const result = generate(ast, {
@@ -260,16 +264,16 @@ function extractToClassNames({
260
264
  console.log("\n -------- output code ------- \n\n", result.code.split("\n").filter((x) => !x.startsWith("//")).join("\n"));
261
265
  console.log("\n -------- output style -------- \n\n", styles);
262
266
  }
263
- console.log(sourcePath, styles);
264
267
  if (shouldLogTiming) {
265
268
  const memUsed = mem ? Math.round((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204 * 10) / 10 : 0;
266
- const timing = `${Date.now() - start}`.padStart(3);
267
269
  const path2 = basename(sourcePath).replace(/\.[jt]sx?$/, "").slice(0, 22).trim().padStart(24);
268
270
  const numOptimized = `${res.optimized}`.padStart(3);
269
271
  const numFound = `${res.found}`.padStart(3);
270
272
  const numFlattened = `${res.flattened}`.padStart(3);
271
273
  const memory = process.env.DEBUG && memUsed > 10 ? ` ${memUsed}MB` : "";
272
- const timingStr = `${timing}ms`.padStart(6);
274
+ const timing = Date.now() - start;
275
+ const timingWarning = timing > 50 ? "\u26A0\uFE0F" : timing > 150 ? "\u2622\uFE0F" : "";
276
+ const timingStr = `${timing}ms${timingWarning}`.padStart(6);
273
277
  console.log(`${getPrefixLogs(options)} ${path2} ${numFound} \xB7 ${numOptimized} \xB7 ${numFlattened} ${timingStr} ${memory ? `(${memory})` : ""}`);
274
278
  }
275
279
  return {
@@ -7,56 +7,72 @@ function loadTamagui(props) {
7
7
  if (loadedTamagui) {
8
8
  return loadedTamagui;
9
9
  }
10
- process.env.IS_STATIC = "is_static";
11
- const proxyWorm = require("@tamagui/proxy-worm");
12
- const rnw = require("react-native-web");
13
- const Mod = require("module");
14
- const og = Mod.prototype.require;
15
- Mod.prototype.require = function(path) {
16
- if (path.endsWith(".css")) {
17
- return {};
18
- }
19
- if (path === "@gorhom/bottom-sheet" || path.startsWith("react-native-reanimated")) {
20
- return proxyWorm;
21
- }
22
- if (path.startsWith("react-native") && !path.startsWith("react-native-web/dist/cjs/exports")) {
23
- return rnw;
24
- }
25
- try {
26
- return og.apply(this, arguments);
27
- } catch (err) {
28
- console.error("Tamagui error loading file:\n");
29
- console.log(" ", path, "\n");
30
- console.log(err.message);
31
- console.log(err.stack);
32
- process.exit(1);
33
- }
34
- };
35
10
  const configPath = join(process.cwd(), props.config);
36
- const tamaguiConfigExport = require(configPath);
37
- const tamaguiConfig = tamaguiConfigExport["default"] || tamaguiConfigExport;
38
- if (!tamaguiConfig || !tamaguiConfig.parsed) {
39
- try {
40
- const confPath = require.resolve(configPath);
41
- console.log(`Received:`, tamaguiConfigExport);
42
- throw new Error(`Can't find valid config in ${confPath}`);
43
- } catch (err) {
44
- throw err;
11
+ const { unregister } = require("esbuild-register/dist/node").register({
12
+ target: "es2019",
13
+ format: "cjs"
14
+ });
15
+ try {
16
+ process.env.IS_STATIC = "is_static";
17
+ const proxyWorm = require("@tamagui/proxy-worm");
18
+ const rnw = require("react-native-web");
19
+ const Mod = require("module");
20
+ const og = Mod.prototype.require;
21
+ Mod.prototype.require = function(path) {
22
+ if (path.endsWith(".css")) {
23
+ return {};
24
+ }
25
+ if (path === "@gorhom/bottom-sheet" || path.startsWith("react-native-reanimated")) {
26
+ return proxyWorm;
27
+ }
28
+ if (path.startsWith("react-native") && !path.startsWith("react-native-web/dist/cjs/exports")) {
29
+ return rnw;
30
+ }
31
+ try {
32
+ return og.apply(this, arguments);
33
+ } catch (err) {
34
+ console.error("Tamagui error loading file:\n");
35
+ console.log(" ", path, "\n");
36
+ console.log(err.message);
37
+ console.log(err.stack);
38
+ process.exit(1);
39
+ }
40
+ };
41
+ const exp = require(configPath);
42
+ const tamaguiConfig = exp["default"] || exp;
43
+ if (!tamaguiConfig || !tamaguiConfig.parsed) {
44
+ try {
45
+ const confPath = require.resolve(configPath);
46
+ console.log(`Received:`, tamaguiConfig);
47
+ throw new Error(`Can't find valid config in ${confPath}`);
48
+ } catch (err) {
49
+ throw err;
50
+ }
45
51
  }
52
+ const components = {};
53
+ for (const moduleName of props.components) {
54
+ const exported = require(moduleName);
55
+ for (const Name in exported) {
56
+ const val = exported[Name];
57
+ const staticConfig = val == null ? void 0 : val.staticConfig;
58
+ if (staticConfig) {
59
+ Object.assign(components, { [Name]: { staticConfig } });
60
+ }
61
+ }
62
+ }
63
+ process.env.IS_STATIC = void 0;
64
+ Mod.prototype.require = og;
65
+ createTamagui(tamaguiConfig);
66
+ loadedTamagui = {
67
+ components,
68
+ tamaguiConfig
69
+ };
70
+ return loadedTamagui;
71
+ } catch (err) {
72
+ throw err;
73
+ } finally {
74
+ unregister();
46
75
  }
47
- const components = {};
48
- for (const module of props.components) {
49
- const exported = require(module);
50
- Object.assign(components, exported);
51
- }
52
- process.env.IS_STATIC = void 0;
53
- Mod.prototype.require = og;
54
- createTamagui(tamaguiConfig);
55
- loadedTamagui = {
56
- components,
57
- tamaguiConfig
58
- };
59
- return loadedTamagui;
60
76
  }
61
77
  __name(loadTamagui, "loadTamagui");
62
78
  export {
@@ -0,0 +1,23 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ const timer = /* @__PURE__ */ __name(() => {
4
+ const start = Date.now();
5
+ let last = start;
6
+ return {
7
+ mark: (name, print = false) => {
8
+ if (print) {
9
+ const took = Date.now() - last;
10
+ last = Date.now();
11
+ console.log(`Time ${name}: ${took}ms`);
12
+ }
13
+ },
14
+ done: (print = false) => {
15
+ if (print) {
16
+ console.log(`Total time: ${Date.now() - start}ms`);
17
+ }
18
+ }
19
+ };
20
+ }, "timer");
21
+ export {
22
+ timer
23
+ };
@@ -15,6 +15,8 @@ function patchReactNativeWeb() {
15
15
  }
16
16
  const patches = [
17
17
  {
18
+ id: "dom-props",
19
+ filePath: ["modules", "createDOMProps", "index.js"],
18
20
  replacee: ` if (dataSet != null) {`,
19
21
  replacer: `
20
22
  if (props.dataSet && props.dataSet.className) {
@@ -22,15 +24,25 @@ function patchReactNativeWeb() {
22
24
  classList = className
23
25
  dataSet = dataSetRest
24
26
  }
27
+ if (props.dataSet && props.dataSet.id) {
28
+ domProps['id'] = props.dataSet.id
29
+ }
25
30
  if (dataSet != null) {`
31
+ },
32
+ {
33
+ id: "forward-props",
34
+ filePath: ["modules", "forwardedProps", "index.js"],
35
+ replacee: `dataSet: true,`,
36
+ replacer: `id: true, dataSet: true,`
26
37
  }
27
38
  ];
28
- const dataSetPath = ["modules", "createDOMProps", "index.js"];
29
- const dataSetModulePath = path.join(rootDir, "dist", ...dataSetPath);
30
- const dataSetCjsPath = path.join(rootDir, "dist", "cjs", ...dataSetPath);
31
- for (const file of [dataSetModulePath, dataSetCjsPath]) {
32
- const contents = fs.readFileSync(file, "utf-8");
33
- for (const { replacee, replacer } of patches) {
39
+ for (const { filePath, replacee, replacer } of patches) {
40
+ const files = [
41
+ path.join(rootDir, "dist", ...filePath),
42
+ path.join(rootDir, "dist", "cjs", ...filePath)
43
+ ];
44
+ for (const file of files) {
45
+ const contents = fs.readFileSync(file, "utf-8");
34
46
  if (contents.includes(replacer)) {
35
47
  continue;
36
48
  }
@@ -42,7 +54,7 @@ function patchReactNativeWeb() {
42
54
  continue;
43
55
  }
44
56
  console.log(" | patch " + path.relative(rootDir, file));
45
- fs.writeFileSync(file, contents.replaceAll(replacee, replacer));
57
+ fs.writeFileSync(file, contents.replace(replacee, replacer));
46
58
  }
47
59
  }
48
60
  const moduleEntry = path.join(rootDir, "dist", "index.js");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/static",
3
- "version": "1.0.0-beta.153+a49c2588",
3
+ "version": "1.0.0-beta.181+fff2a5b2",
4
4
  "source": "src/index.ts",
5
5
  "typings": "types",
6
6
  "main": "dist/cjs",
@@ -34,19 +34,19 @@
34
34
  "@babel/parser": "^7.15.7",
35
35
  "@babel/traverse": "^7.15.4",
36
36
  "@expo/match-media": "^0.1.0",
37
- "@tamagui/build": "^1.0.0-beta.153+a49c2588",
38
- "@tamagui/core-node": "^1.0.0-beta.153+a49c2588",
39
- "@tamagui/fake-react-native": "^1.0.0-beta.153+a49c2588",
40
- "@tamagui/helpers": "^1.0.0-beta.153+a49c2588",
41
- "@tamagui/proxy-worm": "^1.0.0-beta.153+a49c2588",
37
+ "@tamagui/build": "^1.0.0-beta.181+fff2a5b2",
38
+ "@tamagui/core-node": "^1.0.0-beta.181+fff2a5b2",
39
+ "@tamagui/fake-react-native": "^1.0.0-beta.181+fff2a5b2",
40
+ "@tamagui/helpers": "^1.0.0-beta.181+fff2a5b2",
41
+ "@tamagui/proxy-worm": "^1.0.0-beta.181+fff2a5b2",
42
42
  "babel-literal-to-ast": "^2.1.0",
43
43
  "esbuild": "^0.14.36",
44
- "esbuild-register": "^3.1.2",
44
+ "esbuild-register": "^3.3.2",
45
45
  "find-cache-dir": "^3.3.2",
46
46
  "fs-extra": "^9.1.0",
47
47
  "invariant": "^2.2.4",
48
48
  "lodash": "^4.17.21",
49
- "tamagui": "^1.0.0-beta.153+a49c2588"
49
+ "tamagui": "^1.0.0-beta.181+fff2a5b2"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@babel/plugin-syntax-typescript": "^7.14.5",
@@ -73,5 +73,5 @@
73
73
  "peerDependencies": {
74
74
  "react-native-web": "*"
75
75
  },
76
- "gitHead": "a49c2588898b6db5660f9b3346078cd87f585dcf"
76
+ "gitHead": "fff2a5b25ea3881d499e5376cd166f58556acaba"
77
77
  }