@tamagui/static 1.0.0-alpha.1 → 1.0.0-alpha.10

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/index.cjs CHANGED
@@ -255,7 +255,9 @@ function isValidThemeHook(jsxPath, n, sourcePath) {
255
255
  return true;
256
256
  }
257
257
  __name(isValidThemeHook, "isValidThemeHook");
258
- var isInsideTamagui = /* @__PURE__ */ __name((srcName) => srcName.includes("/tamagui/"), "isInsideTamagui");
258
+ var isInsideTamagui = /* @__PURE__ */ __name((srcName) => {
259
+ return srcName.includes("/tamagui/_jsx") || srcName.includes("/core/src");
260
+ }, "isInsideTamagui");
259
261
 
260
262
  // src/extractor/createEvaluator.ts
261
263
  function createEvaluator({
@@ -572,6 +574,19 @@ function loadTamagui(props) {
572
574
  }
573
575
  __name(loadTamagui, "loadTamagui");
574
576
 
577
+ // src/extractor/logLines.ts
578
+ var logLines = /* @__PURE__ */ __name((str) => {
579
+ let lines = [""];
580
+ const items = str.split(" ");
581
+ for (const item of items) {
582
+ if (item.length + lines[lines.length - 1].length > 100) {
583
+ lines.push("");
584
+ }
585
+ lines[lines.length - 1] += item + " ";
586
+ }
587
+ return lines.map((line, i) => " " + (i == 0 ? "" : " ") + line.trim()).join("\n");
588
+ }, "logLines");
589
+
575
590
  // src/extractor/normalizeTernaries.ts
576
591
  var import_generator2 = __toModule(require("@babel/generator"));
577
592
  var t7 = __toModule(require("@babel/types"));
@@ -715,8 +730,9 @@ function createExtractor() {
715
730
  format: "cjs"
716
731
  });
717
732
  let loadedTamaguiConfig;
733
+ let hasLogged = false;
718
734
  return {
719
- getTamaguiConfig() {
735
+ getTamagui() {
720
736
  return loadedTamaguiConfig;
721
737
  },
722
738
  parse: (fileOrPath, _a) => {
@@ -728,7 +744,9 @@ function createExtractor() {
728
744
  sourcePath = "",
729
745
  onExtractTag,
730
746
  getFlattenedNode,
731
- onDidFlatten
747
+ disableExtraction,
748
+ disableExtractInlineMedia,
749
+ disableDebugAttr
732
750
  } = _b, props = __objRest(_b, [
733
751
  "config",
734
752
  "importsWhitelist",
@@ -737,7 +755,9 @@ function createExtractor() {
737
755
  "sourcePath",
738
756
  "onExtractTag",
739
757
  "getFlattenedNode",
740
- "onDidFlatten"
758
+ "disableExtraction",
759
+ "disableExtractInlineMedia",
760
+ "disableDebugAttr"
741
761
  ]);
742
762
  if (sourcePath === "") {
743
763
  throw new Error(`Must provide a source file name`);
@@ -751,16 +771,18 @@ function createExtractor() {
751
771
  });
752
772
  loadedTamaguiConfig = tamaguiConfig;
753
773
  const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]];
754
- let doesUseValidImport = false;
755
774
  const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
756
- const isInternalImport = /* @__PURE__ */ __name((importStr) => isInsideTamagui(sourcePath) && importStr[0] === ".", "isInternalImport");
775
+ const isInternalImport = /* @__PURE__ */ __name((importStr) => {
776
+ return isInsideTamagui(sourcePath) && importStr[0] === ".";
777
+ }, "isInternalImport");
757
778
  const validComponents = Object.keys(components).filter((key) => {
758
779
  var _a2;
759
- return !!((_a2 = components[key]) == null ? void 0 : _a2.staticConfig);
780
+ return key[0].toUpperCase() === key[0] && !!((_a2 = components[key]) == null ? void 0 : _a2.staticConfig);
760
781
  }).reduce((obj, name) => {
761
782
  obj[name] = components[name];
762
783
  return obj;
763
784
  }, {});
785
+ let doesUseValidImport = false;
764
786
  for (const bodyPath of body) {
765
787
  if (bodyPath.type !== "ImportDeclaration")
766
788
  continue;
@@ -789,6 +811,11 @@ function createExtractor() {
789
811
  return fileOrPath.type === "File" ? (0, import_traverse.default)(fileOrPath, a) : fileOrPath.traverse(a);
790
812
  }, "callTraverse");
791
813
  let programPath;
814
+ const res = {
815
+ flattened: 0,
816
+ optimized: 0,
817
+ modified: 0
818
+ };
792
819
  callTraverse({
793
820
  Program: {
794
821
  enter(path3) {
@@ -821,8 +848,26 @@ function createExtractor() {
821
848
  if (!component || !component.staticConfig) {
822
849
  return;
823
850
  }
824
- const { staticConfig } = component;
825
851
  const originalNodeName = node.name.name;
852
+ if (shouldPrintDebug) {
853
+ console.log(`
854
+ <${originalNodeName} />`);
855
+ }
856
+ const filePath = sourcePath.replace(process.cwd(), ".");
857
+ const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
858
+ if (shouldAddDebugProp && !disableDebugAttr) {
859
+ const preName = componentName ? `${componentName}:` : "";
860
+ res.modified++;
861
+ node.attributes.unshift(t9.jsxAttribute(t9.jsxIdentifier("data-is"), t9.stringLiteral(` ${preName}${node.name.name} ${filePath.replace("./", "")}:${lineNumbers} `)));
862
+ }
863
+ if (disableExtraction) {
864
+ if (!hasLogged) {
865
+ console.log("\u{1F95A} Tamagui disableExtraction set: no CSS or optimizations will be run");
866
+ hasLogged = true;
867
+ }
868
+ return;
869
+ }
870
+ const { staticConfig } = component;
826
871
  const isTextView = staticConfig.isText || false;
827
872
  const validStyles = (staticConfig == null ? void 0 : staticConfig.validStyles) ?? {};
828
873
  let tagName = ((_a2 = staticConfig.defaultProps) == null ? void 0 : _a2.tag) ?? (isTextView ? "span" : "div");
@@ -844,21 +889,17 @@ function createExtractor() {
844
889
  ]);
845
890
  const excludeProps = new Set(props.excludeProps ?? []);
846
891
  const isExcludedProp = /* @__PURE__ */ __name((name) => {
847
- const res = excludeProps.has(name);
848
- if (res && shouldPrintDebug)
892
+ const res2 = excludeProps.has(name);
893
+ if (res2 && shouldPrintDebug)
849
894
  console.log(` excluding ${name}`);
850
- return res;
895
+ return res2;
851
896
  }, "isExcludedProp");
852
897
  const isDeoptedProp = /* @__PURE__ */ __name((name) => {
853
- const res = deoptProps.has(name);
854
- if (res && shouldPrintDebug)
898
+ const res2 = deoptProps.has(name);
899
+ if (res2 && shouldPrintDebug)
855
900
  console.log(` deopting ${name}`);
856
- return res;
901
+ return res2;
857
902
  }, "isDeoptedProp");
858
- if (shouldPrintDebug) {
859
- console.log(`
860
- <${originalNodeName} />`);
861
- }
862
903
  const staticNamespace = getStaticBindingsForScope(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
863
904
  const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
864
905
  tamaguiConfig,
@@ -931,11 +972,11 @@ function createExtractor() {
931
972
  let isFlattened = false;
932
973
  attrs = traversePath.get("openingElement").get("attributes").flatMap((path3) => {
933
974
  try {
934
- const res = evaluateAttribute(path3);
935
- if (!res) {
975
+ const res2 = evaluateAttribute(path3);
976
+ if (!res2) {
936
977
  path3.remove();
937
978
  }
938
- return res;
979
+ return res2;
939
980
  } catch (err) {
940
981
  console.log("Error extracting attribute", err.message, err.stack);
941
982
  console.log("node", path3.node);
@@ -958,7 +999,9 @@ function createExtractor() {
958
999
  }
959
1000
  const propName = prop.key["name"];
960
1001
  if (!isStaticAttributeName(propName) && propName !== "tag") {
961
- console.log(" not a valid style prop!", propName);
1002
+ if (shouldPrintDebug) {
1003
+ console.log(" not a valid style prop!", propName);
1004
+ }
962
1005
  return false;
963
1006
  }
964
1007
  return true;
@@ -1023,7 +1066,9 @@ function createExtractor() {
1023
1066
  if (!test)
1024
1067
  throw new Error(`no test`);
1025
1068
  if ([alt, cons].some((side) => side && !isExtractable(side))) {
1026
- console.log("not extractable", alt, cons);
1069
+ if (shouldPrintDebug) {
1070
+ console.log("not extractable", alt, cons);
1071
+ }
1027
1072
  return attr;
1028
1073
  }
1029
1074
  return [
@@ -1054,6 +1099,9 @@ function createExtractor() {
1054
1099
  return attr;
1055
1100
  }
1056
1101
  if (name[0] === "$" && t9.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
1102
+ if (disableExtractInlineMedia) {
1103
+ return attr;
1104
+ }
1057
1105
  const shortname = name.slice(1);
1058
1106
  if (mediaQueryConfig[shortname]) {
1059
1107
  const expression = attribute.value.expression;
@@ -1113,7 +1161,9 @@ function createExtractor() {
1113
1161
  if (styleValue !== FAILED_EVAL) {
1114
1162
  return {
1115
1163
  type: "style",
1116
- value: { [name]: styleValue }
1164
+ value: { [name]: styleValue },
1165
+ name,
1166
+ attr: path3.node
1117
1167
  };
1118
1168
  }
1119
1169
  if (t9.isBinaryExpression(value)) {
@@ -1226,7 +1276,7 @@ function createExtractor() {
1226
1276
  }
1227
1277
  __name(evaluateAttribute, "evaluateAttribute");
1228
1278
  if (shouldPrintDebug) {
1229
- console.log(" - attrs (before): ", attrs.map(attrStr).join(", "));
1279
+ console.log(" - attrs (before):\n", logLines(attrs.map(attrStr).join(", ")));
1230
1280
  }
1231
1281
  node.attributes = attrs.filter(isAttr).map((x) => x.value);
1232
1282
  if (couldntParse) {
@@ -1240,8 +1290,6 @@ function createExtractor() {
1240
1290
  if (parentFn) {
1241
1291
  modifiedComponents.add(parentFn);
1242
1292
  }
1243
- const filePath = sourcePath.replace(process.cwd(), ".");
1244
- const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
1245
1293
  let ternaries = [];
1246
1294
  attrs = attrs.reduce((out, cur) => {
1247
1295
  const next = attrs[attrs.indexOf(cur) + 1];
@@ -1300,17 +1348,19 @@ function createExtractor() {
1300
1348
  const shouldFlatten = !shouldDeopt && inlinePropCount === 0 && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
1301
1349
  if (!shouldFlatten) {
1302
1350
  attrs = attrs.reduce((acc, cur) => {
1303
- var _a3;
1351
+ var _a3, _b2;
1304
1352
  if (cur.type === "style") {
1305
1353
  for (const key in cur.value) {
1306
- const shouldInsertNull = !!((_a3 = staticConfig.ensureOverriddenProp) == null ? void 0 : _a3[key]);
1354
+ const shouldEnsureOverridden = !!((_a3 = staticConfig.ensureOverriddenProp) == null ? void 0 : _a3[key]);
1307
1355
  const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
1308
- const shouldInsertNullOverride = shouldInsertNull && !isSetInAttrsAlready;
1309
- if (shouldInsertNullOverride) {
1310
- acc.push({
1311
- type: "attr",
1312
- value: t9.jsxAttribute(t9.jsxIdentifier(key), t9.jsxExpressionContainer(t9.nullLiteral()))
1313
- });
1356
+ if (!isSetInAttrsAlready) {
1357
+ const isVariant = !!((_b2 = staticConfig.variants) == null ? void 0 : _b2[cur.name || ""]);
1358
+ if (isVariant || shouldEnsureOverridden) {
1359
+ acc.push({
1360
+ type: "attr",
1361
+ value: cur.attr || t9.jsxAttribute(t9.jsxIdentifier(key), t9.jsxExpressionContainer(t9.nullLiteral()))
1362
+ });
1363
+ }
1314
1364
  }
1315
1365
  }
1316
1366
  }
@@ -1319,7 +1369,7 @@ function createExtractor() {
1319
1369
  }, []);
1320
1370
  }
1321
1371
  if (shouldPrintDebug) {
1322
- console.log(" - attrs (flattened): ", attrs.map(attrStr).join(", "));
1372
+ console.log(" - attrs (flattened): \n", logLines(attrs.map(attrStr).join(", ")));
1323
1373
  }
1324
1374
  attrs = attrs.reduce((acc, cur) => {
1325
1375
  if (cur.type !== "attr" || !t9.isJSXAttribute(cur.value) || typeof cur.value.name.name !== "string") {
@@ -1337,7 +1387,7 @@ function createExtractor() {
1337
1387
  return acc;
1338
1388
  }, []);
1339
1389
  if (shouldPrintDebug) {
1340
- console.log(" - attrs (evaluated styles): ", attrs.map(attrStr).join(", "));
1390
+ console.log(" - attrs (evaluated styles): \n", logLines(attrs.map(attrStr).join(", ")));
1341
1391
  }
1342
1392
  let prev = null;
1343
1393
  attrs = attrs.reduce((acc, cur) => {
@@ -1352,7 +1402,7 @@ function createExtractor() {
1352
1402
  return acc;
1353
1403
  }, []);
1354
1404
  if (shouldPrintDebug) {
1355
- console.log(" - attrs (combined \u{1F500}): ", attrs.map(attrStr).join(", "));
1405
+ console.log(" - attrs (combined \u{1F500}): \n", logLines(attrs.map(attrStr).join(", ")));
1356
1406
  }
1357
1407
  const getStyles = /* @__PURE__ */ __name((props2) => {
1358
1408
  if (!props2)
@@ -1366,9 +1416,10 @@ function createExtractor() {
1366
1416
  const out = postProcessStyles(props2, staticConfig, defaultTheme);
1367
1417
  const next = (out == null ? void 0 : out.style) ?? props2;
1368
1418
  if (shouldPrintDebug) {
1369
- console.log(" >> getStyles: ", objToStr(props2), "==>>", objToStr(next));
1370
- console.log(" >> style: ", objToStr(out.style));
1371
- console.log(" >> viewp: ", objToStr(out.viewProps));
1419
+ console.log(" getStyles props >>\n", logLines(objToStr(props2)));
1420
+ console.log(" getStyles next >>\n", logLines(objToStr(next)));
1421
+ console.log(" getStyles style >>\n", logLines(objToStr(out.style)));
1422
+ console.log(" getStyles viewp >>\n", logLines(objToStr(out.viewProps)));
1372
1423
  }
1373
1424
  if (staticConfig.validStyles) {
1374
1425
  for (const key in next) {
@@ -1379,9 +1430,6 @@ function createExtractor() {
1379
1430
  }
1380
1431
  return next;
1381
1432
  }, "getStyles");
1382
- if (shouldPrintDebug) {
1383
- console.log(" staticConfig.defaultProps", staticConfig.defaultProps);
1384
- }
1385
1433
  const completeStylesProcessed = getStyles(__spreadValues(__spreadValues({}, staticConfig.defaultProps), completeStaticProps));
1386
1434
  const stylesToAddToInitialGroup = (0, import_lodash.difference)(Object.keys(completeStylesProcessed), Object.keys(completeStaticProps));
1387
1435
  if (stylesToAddToInitialGroup.length) {
@@ -1398,8 +1446,8 @@ function createExtractor() {
1398
1446
  }
1399
1447
  }
1400
1448
  if (shouldPrintDebug) {
1401
- console.log(" completeStaticProps", objToStr(completeStaticProps));
1402
- console.log(" completeStylesProcessed", objToStr(completeStylesProcessed));
1449
+ console.log(" completeStaticProps\n", logLines(objToStr(completeStaticProps)));
1450
+ console.log(" completeStylesProcessed\n", logLines(objToStr(completeStylesProcessed)));
1403
1451
  }
1404
1452
  for (const attr of attrs) {
1405
1453
  try {
@@ -1434,14 +1482,7 @@ function createExtractor() {
1434
1482
  }
1435
1483
  }
1436
1484
  if (shouldPrintDebug) {
1437
- console.log(" - attrs (after): ", attrs.map(attrStr).join(", "));
1438
- }
1439
- if (shouldAddDebugProp) {
1440
- const preName = componentName ? `${componentName}:` : "";
1441
- attrs.unshift({
1442
- type: "attr",
1443
- value: t9.jsxAttribute(t9.jsxIdentifier("data-is"), t9.stringLiteral(` ${preName}${node.name.name} ${filePath.replace("./", "")}:${lineNumbers} `))
1444
- });
1485
+ console.log(" - attrs (after):\n", logLines(attrs.map(attrStr).join(", ")));
1445
1486
  }
1446
1487
  if (shouldFlatten) {
1447
1488
  if (shouldPrintDebug) {
@@ -1449,15 +1490,16 @@ function createExtractor() {
1449
1490
  }
1450
1491
  isFlattened = true;
1451
1492
  node.name.name = flatNode;
1452
- onDidFlatten == null ? void 0 : onDidFlatten();
1493
+ res.flattened++;
1453
1494
  if (closingElement) {
1454
1495
  closingElement.name.name = flatNode;
1455
1496
  }
1456
1497
  }
1457
1498
  if (shouldPrintDebug) {
1458
1499
  console.log(" [\u274A] inline props ", inlinePropCount, shouldDeopt ? " deopted" : "", hasSpread ? " spread" : "", "!flatten", staticConfig.neverFlatten);
1459
- console.log(" - attrs (end): ", attrs.map(attrStr).join(", "));
1500
+ console.log(" - attrs (end):\n", logLines(attrs.map(attrStr).join(", ")));
1460
1501
  }
1502
+ res.optimized++;
1461
1503
  onExtractTag({
1462
1504
  attrs,
1463
1505
  node,
@@ -1480,6 +1522,7 @@ function createExtractor() {
1480
1522
  removeUnusedHooks(comp, shouldPrintDebug);
1481
1523
  }
1482
1524
  }
1525
+ return res;
1483
1526
  }
1484
1527
  };
1485
1528
  }
@@ -1797,16 +1840,11 @@ function extractToClassNames({
1797
1840
  }
1798
1841
  const cssMap = new Map();
1799
1842
  const existingHoists = {};
1800
- let flattened = 0;
1801
- let optimized = 0;
1802
- extractor.parse(ast, __spreadProps(__spreadValues({
1843
+ const res = extractor.parse(ast, __spreadProps(__spreadValues({
1803
1844
  sourcePath,
1804
1845
  shouldPrintDebug
1805
1846
  }, options), {
1806
1847
  getFlattenedNode: ({ tag }) => tag,
1807
- onDidFlatten() {
1808
- flattened++;
1809
- },
1810
1848
  onExtractTag: ({
1811
1849
  attrs,
1812
1850
  node,
@@ -1817,7 +1855,6 @@ function extractToClassNames({
1817
1855
  lineNumbers,
1818
1856
  programPath
1819
1857
  }) => {
1820
- optimized++;
1821
1858
  let finalClassNames = [];
1822
1859
  let finalAttrs = [];
1823
1860
  let finalStyles = [];
@@ -1843,11 +1880,11 @@ function extractToClassNames({
1843
1880
  if (!style)
1844
1881
  return [];
1845
1882
  const styleWithPrev = ensureNeededPrevStyle(style);
1846
- const res = (0, import_core_node3.getStylesAtomic)(styleWithPrev);
1847
- if (res.length) {
1848
- finalStyles = [...finalStyles, ...res];
1883
+ const res2 = (0, import_core_node3.getStylesAtomic)(styleWithPrev);
1884
+ if (res2.length) {
1885
+ finalStyles = [...finalStyles, ...res2];
1849
1886
  }
1850
- return res;
1887
+ return res2;
1851
1888
  }, "addStyles");
1852
1889
  let lastMediaImportance = 1;
1853
1890
  for (const attr of attrs) {
@@ -1855,9 +1892,6 @@ function extractToClassNames({
1855
1892
  case "style":
1856
1893
  const styles2 = addStyles(attr.value);
1857
1894
  const newClassNames = (0, import_helpers2.concatClassName)(styles2.map((x) => x.identifier).join(" "));
1858
- if (shouldPrintDebug) {
1859
- console.log(" classnames", newClassNames, finalClassNames);
1860
- }
1861
1895
  const existing = finalClassNames.find((x) => x.type == "StringLiteral");
1862
1896
  if (existing) {
1863
1897
  existing.value = `${existing.value} ${newClassNames}`;
@@ -1865,7 +1899,7 @@ function extractToClassNames({
1865
1899
  finalClassNames = [...finalClassNames, t14.stringLiteral(newClassNames)];
1866
1900
  }
1867
1901
  if (shouldPrintDebug) {
1868
- console.log(" classnames (after)", finalClassNames.map((x) => x["value"]).join(" "));
1902
+ console.log(" classnames (after)\n", logLines(finalClassNames.map((x) => x["value"]).join(" ")));
1869
1903
  }
1870
1904
  break;
1871
1905
  case "attr":
@@ -1889,7 +1923,7 @@ function extractToClassNames({
1889
1923
  finalAttrs.push(val);
1890
1924
  break;
1891
1925
  case "ternary":
1892
- const mediaExtraction = extractMediaStyle(attr.value, jsxPath, extractor.getTamaguiConfig(), sourcePath, lastMediaImportance, shouldPrintDebug);
1926
+ const mediaExtraction = extractMediaStyle(attr.value, jsxPath, extractor.getTamagui(), sourcePath, lastMediaImportance, shouldPrintDebug);
1893
1927
  if (mediaExtraction) {
1894
1928
  lastMediaImportance++;
1895
1929
  finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles];
@@ -1950,12 +1984,10 @@ function extractToClassNames({
1950
1984
  }
1951
1985
  }
1952
1986
  }));
1953
- if (!optimized) {
1987
+ if (!res || !res.modified) {
1954
1988
  return null;
1955
1989
  }
1956
- const styles = Array.from(cssMap.values()).map((x) => {
1957
- return x.css;
1958
- }).join("\n").trim();
1990
+ const styles = Array.from(cssMap.values()).map((x) => x.css).join("\n").trim();
1959
1991
  if (styles) {
1960
1992
  const cssQuery = threaded ? `cssData=${Buffer.from(styles).toString("base64")}` : `cssPath=${cssPath}`;
1961
1993
  const remReq = (0, import_loader_utils.getRemainingRequest)(loader);
@@ -1975,7 +2007,7 @@ function extractToClassNames({
1975
2007
  }
1976
2008
  if (shouldLogTiming && mem) {
1977
2009
  const memUsed = Math.round((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204 * 10) / 10;
1978
- console.log(` \u{1F95A} ${(0, import_path3.basename)(sourcePath).padStart(40)} ${`${Date.now() - start}`.padStart(3)}ms \u05C1\xB7 ${`${optimized}`.padStart(4)} optimized \xB7 ${flattened} flattened ${memUsed > 10 ? `used ${memUsed}MB` : ""}`);
2010
+ console.log(` \u{1F95A} ${(0, import_path3.basename)(sourcePath).padStart(40)} ${`${Date.now() - start}`.padStart(3)}ms \u05C1\xB7 ${`${res.optimized}`.padStart(4)} optimized \xB7 ${res.flattened} flattened ${memUsed > 10 ? `used ${memUsed}MB` : ""}`);
1979
2011
  }
1980
2012
  return {
1981
2013
  ast,
@@ -1991,8 +2023,24 @@ var fs = __toModule(require("fs"));
1991
2023
  var import_path4 = __toModule(require("path"));
1992
2024
  function patchReactNativeWeb() {
1993
2025
  const rootDir = require.resolve("react-native-web").replace(/\/dist.*/, "");
1994
- fs.writeFileSync(import_path4.default.join(rootDir, "dist", "tamagui-exports.js"), moduleExports);
1995
- fs.writeFileSync(import_path4.default.join(rootDir, "dist", "cjs", "tamagui-exports.js"), cjsExports);
2026
+ const modulePath = import_path4.default.join(rootDir, "dist", "tamagui-exports.js");
2027
+ const cjsPath = import_path4.default.join(rootDir, "dist", "cjs", "tamagui-exports.js");
2028
+ const isEqual = (() => {
2029
+ let res = false;
2030
+ try {
2031
+ res = fs.readFileSync(modulePath, "utf-8") === moduleExports && fs.readFileSync(cjsPath, "utf-8") == cjsExports;
2032
+ } catch {
2033
+ res = false;
2034
+ }
2035
+ return res;
2036
+ })();
2037
+ if (!isEqual) {
2038
+ console.log("\u{1F95A} Tamagui patching react-native-web to share atomic styling primitives");
2039
+ console.log(" > adding", modulePath);
2040
+ console.log(" > adding", cjsPath);
2041
+ fs.writeFileSync(modulePath, moduleExports);
2042
+ fs.writeFileSync(cjsPath, cjsExports);
2043
+ }
1996
2044
  const moduleEntry = import_path4.default.join(rootDir, "dist", "index.js");
1997
2045
  const moduleEntrySrc = fs.readFileSync(moduleEntry, "utf-8");
1998
2046
  if (!moduleEntrySrc.includes("// tamagui-patch-v4")) {
@@ -2013,7 +2061,6 @@ export const TamaguiExports = TExports
2013
2061
  exports.TamaguiExports = _interopRequireDefault(require("./tamagui-exports"));
2014
2062
  // tamagui-patch-end
2015
2063
  `);
2016
- console.log(`Tamagui patched react-native-web`);
2017
2064
  }
2018
2065
  }
2019
2066
  __name(patchReactNativeWeb, "patchReactNativeWeb");