@tamagui/static 1.0.0-alpha.3 → 1.0.0-alpha.7
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/extractor/createExtractor.js +43 -28
- package/dist/extractor/createExtractor.js.map +2 -2
- package/dist/extractor/extractToClassNames.js +8 -16
- package/dist/extractor/extractToClassNames.js.map +2 -2
- package/dist/index.cjs +72 -48
- package/dist/index.cjs.map +2 -2
- package/dist/patchReactNativeWeb.js +18 -3
- package/dist/patchReactNativeWeb.js.map +2 -2
- package/package.json +7 -6
- package/src/extractor/createExtractor.ts +59 -36
- package/src/extractor/extractToClassNames.ts +4 -15
- package/src/patchReactNativeWeb.ts +21 -5
- package/src/types.ts +6 -2
- package/types.d.ts +217 -0
package/dist/index.cjs
CHANGED
|
@@ -717,6 +717,7 @@ function createExtractor() {
|
|
|
717
717
|
format: "cjs"
|
|
718
718
|
});
|
|
719
719
|
let loadedTamaguiConfig;
|
|
720
|
+
let hasLogged = false;
|
|
720
721
|
return {
|
|
721
722
|
getTamaguiConfig() {
|
|
722
723
|
return loadedTamaguiConfig;
|
|
@@ -730,7 +731,9 @@ function createExtractor() {
|
|
|
730
731
|
sourcePath = "",
|
|
731
732
|
onExtractTag,
|
|
732
733
|
getFlattenedNode,
|
|
733
|
-
|
|
734
|
+
disableExtraction,
|
|
735
|
+
disableExtractInlineMedia,
|
|
736
|
+
disableDebugAttr
|
|
734
737
|
} = _b, props = __objRest(_b, [
|
|
735
738
|
"config",
|
|
736
739
|
"importsWhitelist",
|
|
@@ -739,7 +742,9 @@ function createExtractor() {
|
|
|
739
742
|
"sourcePath",
|
|
740
743
|
"onExtractTag",
|
|
741
744
|
"getFlattenedNode",
|
|
742
|
-
"
|
|
745
|
+
"disableExtraction",
|
|
746
|
+
"disableExtractInlineMedia",
|
|
747
|
+
"disableDebugAttr"
|
|
743
748
|
]);
|
|
744
749
|
if (sourcePath === "") {
|
|
745
750
|
throw new Error(`Must provide a source file name`);
|
|
@@ -753,16 +758,16 @@ function createExtractor() {
|
|
|
753
758
|
});
|
|
754
759
|
loadedTamaguiConfig = tamaguiConfig;
|
|
755
760
|
const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]];
|
|
756
|
-
let doesUseValidImport = false;
|
|
757
761
|
const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
|
|
758
762
|
const isInternalImport = /* @__PURE__ */ __name((importStr) => isInsideTamagui(sourcePath) && importStr[0] === ".", "isInternalImport");
|
|
759
763
|
const validComponents = Object.keys(components).filter((key) => {
|
|
760
764
|
var _a2;
|
|
761
|
-
return !!((_a2 = components[key]) == null ? void 0 : _a2.staticConfig);
|
|
765
|
+
return key[0].toUpperCase() === key[0] && !!((_a2 = components[key]) == null ? void 0 : _a2.staticConfig);
|
|
762
766
|
}).reduce((obj, name) => {
|
|
763
767
|
obj[name] = components[name];
|
|
764
768
|
return obj;
|
|
765
769
|
}, {});
|
|
770
|
+
let doesUseValidImport = false;
|
|
766
771
|
for (const bodyPath of body) {
|
|
767
772
|
if (bodyPath.type !== "ImportDeclaration")
|
|
768
773
|
continue;
|
|
@@ -791,6 +796,11 @@ function createExtractor() {
|
|
|
791
796
|
return fileOrPath.type === "File" ? (0, import_traverse.default)(fileOrPath, a) : fileOrPath.traverse(a);
|
|
792
797
|
}, "callTraverse");
|
|
793
798
|
let programPath;
|
|
799
|
+
const res = {
|
|
800
|
+
flattened: 0,
|
|
801
|
+
optimized: 0,
|
|
802
|
+
modified: 0
|
|
803
|
+
};
|
|
794
804
|
callTraverse({
|
|
795
805
|
Program: {
|
|
796
806
|
enter(path3) {
|
|
@@ -823,8 +833,26 @@ function createExtractor() {
|
|
|
823
833
|
if (!component || !component.staticConfig) {
|
|
824
834
|
return;
|
|
825
835
|
}
|
|
826
|
-
const { staticConfig } = component;
|
|
827
836
|
const originalNodeName = node.name.name;
|
|
837
|
+
if (shouldPrintDebug) {
|
|
838
|
+
console.log(`
|
|
839
|
+
<${originalNodeName} />`);
|
|
840
|
+
}
|
|
841
|
+
const filePath = sourcePath.replace(process.cwd(), ".");
|
|
842
|
+
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
843
|
+
if (shouldAddDebugProp && !disableDebugAttr) {
|
|
844
|
+
const preName = componentName ? `${componentName}:` : "";
|
|
845
|
+
res.modified++;
|
|
846
|
+
node.attributes.unshift(t9.jsxAttribute(t9.jsxIdentifier("data-is"), t9.stringLiteral(` ${preName}${node.name.name} ${filePath.replace("./", "")}:${lineNumbers} `)));
|
|
847
|
+
}
|
|
848
|
+
if (disableExtraction) {
|
|
849
|
+
if (!hasLogged) {
|
|
850
|
+
console.log("\u{1F95A} Tamagui disableExtraction set: no CSS or optimizations will be run");
|
|
851
|
+
hasLogged = true;
|
|
852
|
+
}
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
const { staticConfig } = component;
|
|
828
856
|
const isTextView = staticConfig.isText || false;
|
|
829
857
|
const validStyles = (staticConfig == null ? void 0 : staticConfig.validStyles) ?? {};
|
|
830
858
|
let tagName = ((_a2 = staticConfig.defaultProps) == null ? void 0 : _a2.tag) ?? (isTextView ? "span" : "div");
|
|
@@ -846,21 +874,17 @@ function createExtractor() {
|
|
|
846
874
|
]);
|
|
847
875
|
const excludeProps = new Set(props.excludeProps ?? []);
|
|
848
876
|
const isExcludedProp = /* @__PURE__ */ __name((name) => {
|
|
849
|
-
const
|
|
850
|
-
if (
|
|
877
|
+
const res2 = excludeProps.has(name);
|
|
878
|
+
if (res2 && shouldPrintDebug)
|
|
851
879
|
console.log(` excluding ${name}`);
|
|
852
|
-
return
|
|
880
|
+
return res2;
|
|
853
881
|
}, "isExcludedProp");
|
|
854
882
|
const isDeoptedProp = /* @__PURE__ */ __name((name) => {
|
|
855
|
-
const
|
|
856
|
-
if (
|
|
883
|
+
const res2 = deoptProps.has(name);
|
|
884
|
+
if (res2 && shouldPrintDebug)
|
|
857
885
|
console.log(` deopting ${name}`);
|
|
858
|
-
return
|
|
886
|
+
return res2;
|
|
859
887
|
}, "isDeoptedProp");
|
|
860
|
-
if (shouldPrintDebug) {
|
|
861
|
-
console.log(`
|
|
862
|
-
<${originalNodeName} />`);
|
|
863
|
-
}
|
|
864
888
|
const staticNamespace = getStaticBindingsForScope(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
865
889
|
const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
|
|
866
890
|
tamaguiConfig,
|
|
@@ -933,11 +957,11 @@ function createExtractor() {
|
|
|
933
957
|
let isFlattened = false;
|
|
934
958
|
attrs = traversePath.get("openingElement").get("attributes").flatMap((path3) => {
|
|
935
959
|
try {
|
|
936
|
-
const
|
|
937
|
-
if (!
|
|
960
|
+
const res2 = evaluateAttribute(path3);
|
|
961
|
+
if (!res2) {
|
|
938
962
|
path3.remove();
|
|
939
963
|
}
|
|
940
|
-
return
|
|
964
|
+
return res2;
|
|
941
965
|
} catch (err) {
|
|
942
966
|
console.log("Error extracting attribute", err.message, err.stack);
|
|
943
967
|
console.log("node", path3.node);
|
|
@@ -1059,7 +1083,7 @@ function createExtractor() {
|
|
|
1059
1083
|
if (UNTOUCHED_PROPS[name]) {
|
|
1060
1084
|
return attr;
|
|
1061
1085
|
}
|
|
1062
|
-
if (name[0] === "$" && t9.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
1086
|
+
if (name[0] === "$" && t9.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value) && !disableExtractInlineMedia) {
|
|
1063
1087
|
const shortname = name.slice(1);
|
|
1064
1088
|
if (mediaQueryConfig[shortname]) {
|
|
1065
1089
|
const expression = attribute.value.expression;
|
|
@@ -1246,8 +1270,6 @@ function createExtractor() {
|
|
|
1246
1270
|
if (parentFn) {
|
|
1247
1271
|
modifiedComponents.add(parentFn);
|
|
1248
1272
|
}
|
|
1249
|
-
const filePath = sourcePath.replace(process.cwd(), ".");
|
|
1250
|
-
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
1251
1273
|
let ternaries = [];
|
|
1252
1274
|
attrs = attrs.reduce((out, cur) => {
|
|
1253
1275
|
const next = attrs[attrs.indexOf(cur) + 1];
|
|
@@ -1442,20 +1464,13 @@ function createExtractor() {
|
|
|
1442
1464
|
if (shouldPrintDebug) {
|
|
1443
1465
|
console.log(" - attrs (after): ", attrs.map(attrStr).join(", "));
|
|
1444
1466
|
}
|
|
1445
|
-
if (shouldAddDebugProp) {
|
|
1446
|
-
const preName = componentName ? `${componentName}:` : "";
|
|
1447
|
-
attrs.unshift({
|
|
1448
|
-
type: "attr",
|
|
1449
|
-
value: t9.jsxAttribute(t9.jsxIdentifier("data-is"), t9.stringLiteral(` ${preName}${node.name.name} ${filePath.replace("./", "")}:${lineNumbers} `))
|
|
1450
|
-
});
|
|
1451
|
-
}
|
|
1452
1467
|
if (shouldFlatten) {
|
|
1453
1468
|
if (shouldPrintDebug) {
|
|
1454
1469
|
console.log(" [\u2705] flattening", originalNodeName, flatNode);
|
|
1455
1470
|
}
|
|
1456
1471
|
isFlattened = true;
|
|
1457
1472
|
node.name.name = flatNode;
|
|
1458
|
-
|
|
1473
|
+
res.flattened++;
|
|
1459
1474
|
if (closingElement) {
|
|
1460
1475
|
closingElement.name.name = flatNode;
|
|
1461
1476
|
}
|
|
@@ -1464,6 +1479,7 @@ function createExtractor() {
|
|
|
1464
1479
|
console.log(" [\u274A] inline props ", inlinePropCount, shouldDeopt ? " deopted" : "", hasSpread ? " spread" : "", "!flatten", staticConfig.neverFlatten);
|
|
1465
1480
|
console.log(" - attrs (end): ", attrs.map(attrStr).join(", "));
|
|
1466
1481
|
}
|
|
1482
|
+
res.optimized++;
|
|
1467
1483
|
onExtractTag({
|
|
1468
1484
|
attrs,
|
|
1469
1485
|
node,
|
|
@@ -1486,6 +1502,7 @@ function createExtractor() {
|
|
|
1486
1502
|
removeUnusedHooks(comp, shouldPrintDebug);
|
|
1487
1503
|
}
|
|
1488
1504
|
}
|
|
1505
|
+
return res;
|
|
1489
1506
|
}
|
|
1490
1507
|
};
|
|
1491
1508
|
}
|
|
@@ -1803,16 +1820,11 @@ function extractToClassNames({
|
|
|
1803
1820
|
}
|
|
1804
1821
|
const cssMap = new Map();
|
|
1805
1822
|
const existingHoists = {};
|
|
1806
|
-
|
|
1807
|
-
let optimized = 0;
|
|
1808
|
-
extractor.parse(ast, __spreadProps(__spreadValues({
|
|
1823
|
+
const res = extractor.parse(ast, __spreadProps(__spreadValues({
|
|
1809
1824
|
sourcePath,
|
|
1810
1825
|
shouldPrintDebug
|
|
1811
1826
|
}, options), {
|
|
1812
1827
|
getFlattenedNode: ({ tag }) => tag,
|
|
1813
|
-
onDidFlatten() {
|
|
1814
|
-
flattened++;
|
|
1815
|
-
},
|
|
1816
1828
|
onExtractTag: ({
|
|
1817
1829
|
attrs,
|
|
1818
1830
|
node,
|
|
@@ -1823,7 +1835,6 @@ function extractToClassNames({
|
|
|
1823
1835
|
lineNumbers,
|
|
1824
1836
|
programPath
|
|
1825
1837
|
}) => {
|
|
1826
|
-
optimized++;
|
|
1827
1838
|
let finalClassNames = [];
|
|
1828
1839
|
let finalAttrs = [];
|
|
1829
1840
|
let finalStyles = [];
|
|
@@ -1849,11 +1860,11 @@ function extractToClassNames({
|
|
|
1849
1860
|
if (!style)
|
|
1850
1861
|
return [];
|
|
1851
1862
|
const styleWithPrev = ensureNeededPrevStyle(style);
|
|
1852
|
-
const
|
|
1853
|
-
if (
|
|
1854
|
-
finalStyles = [...finalStyles, ...
|
|
1863
|
+
const res2 = (0, import_core_node3.getStylesAtomic)(styleWithPrev);
|
|
1864
|
+
if (res2.length) {
|
|
1865
|
+
finalStyles = [...finalStyles, ...res2];
|
|
1855
1866
|
}
|
|
1856
|
-
return
|
|
1867
|
+
return res2;
|
|
1857
1868
|
}, "addStyles");
|
|
1858
1869
|
let lastMediaImportance = 1;
|
|
1859
1870
|
for (const attr of attrs) {
|
|
@@ -1956,12 +1967,10 @@ function extractToClassNames({
|
|
|
1956
1967
|
}
|
|
1957
1968
|
}
|
|
1958
1969
|
}));
|
|
1959
|
-
if (!
|
|
1970
|
+
if (!res || !res.modified) {
|
|
1960
1971
|
return null;
|
|
1961
1972
|
}
|
|
1962
|
-
const styles = Array.from(cssMap.values()).map((x) =>
|
|
1963
|
-
return x.css;
|
|
1964
|
-
}).join("\n").trim();
|
|
1973
|
+
const styles = Array.from(cssMap.values()).map((x) => x.css).join("\n").trim();
|
|
1965
1974
|
if (styles) {
|
|
1966
1975
|
const cssQuery = threaded ? `cssData=${Buffer.from(styles).toString("base64")}` : `cssPath=${cssPath}`;
|
|
1967
1976
|
const remReq = (0, import_loader_utils.getRemainingRequest)(loader);
|
|
@@ -1981,7 +1990,7 @@ function extractToClassNames({
|
|
|
1981
1990
|
}
|
|
1982
1991
|
if (shouldLogTiming && mem) {
|
|
1983
1992
|
const memUsed = Math.round((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204 * 10) / 10;
|
|
1984
|
-
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` : ""}`);
|
|
1993
|
+
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` : ""}`);
|
|
1985
1994
|
}
|
|
1986
1995
|
return {
|
|
1987
1996
|
ast,
|
|
@@ -1997,8 +2006,24 @@ var fs = __toModule(require("fs"));
|
|
|
1997
2006
|
var import_path4 = __toModule(require("path"));
|
|
1998
2007
|
function patchReactNativeWeb() {
|
|
1999
2008
|
const rootDir = require.resolve("react-native-web").replace(/\/dist.*/, "");
|
|
2000
|
-
|
|
2001
|
-
|
|
2009
|
+
const modulePath = import_path4.default.join(rootDir, "dist", "tamagui-exports.js");
|
|
2010
|
+
const cjsPath = import_path4.default.join(rootDir, "dist", "cjs", "tamagui-exports.js");
|
|
2011
|
+
const isEqual = (() => {
|
|
2012
|
+
let res = false;
|
|
2013
|
+
try {
|
|
2014
|
+
res = fs.readFileSync(modulePath, "utf-8") === moduleExports && fs.readFileSync(cjsPath, "utf-8") == cjsExports;
|
|
2015
|
+
} catch {
|
|
2016
|
+
res = false;
|
|
2017
|
+
}
|
|
2018
|
+
return res;
|
|
2019
|
+
})();
|
|
2020
|
+
if (!isEqual) {
|
|
2021
|
+
console.log("\u{1F95A} Tamagui patching react-native-web to share atomic styling primitives");
|
|
2022
|
+
console.log(" > adding", modulePath);
|
|
2023
|
+
console.log(" > adding", cjsPath);
|
|
2024
|
+
fs.writeFileSync(modulePath, moduleExports);
|
|
2025
|
+
fs.writeFileSync(cjsPath, cjsExports);
|
|
2026
|
+
}
|
|
2002
2027
|
const moduleEntry = import_path4.default.join(rootDir, "dist", "index.js");
|
|
2003
2028
|
const moduleEntrySrc = fs.readFileSync(moduleEntry, "utf-8");
|
|
2004
2029
|
if (!moduleEntrySrc.includes("// tamagui-patch-v4")) {
|
|
@@ -2019,7 +2044,6 @@ export const TamaguiExports = TExports
|
|
|
2019
2044
|
exports.TamaguiExports = _interopRequireDefault(require("./tamagui-exports"));
|
|
2020
2045
|
// tamagui-patch-end
|
|
2021
2046
|
`);
|
|
2022
|
-
console.log(`Tamagui patched react-native-web`);
|
|
2023
2047
|
}
|
|
2024
2048
|
}
|
|
2025
2049
|
__name(patchReactNativeWeb, "patchReactNativeWeb");
|