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

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 (189) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/constants.js +33 -0
  3. package/dist/cjs/constants.js.map +7 -0
  4. package/dist/cjs/extractor/accessSafe.js +33 -0
  5. package/dist/cjs/extractor/accessSafe.js.map +7 -0
  6. package/dist/cjs/extractor/babelParse.js +52 -0
  7. package/dist/cjs/extractor/babelParse.js.map +7 -0
  8. package/dist/cjs/extractor/buildClassName.js +62 -0
  9. package/dist/cjs/extractor/buildClassName.js.map +7 -0
  10. package/dist/cjs/extractor/createEvaluator.js +73 -0
  11. package/dist/cjs/extractor/createEvaluator.js.map +7 -0
  12. package/dist/cjs/extractor/createExtractor.js +903 -0
  13. package/dist/cjs/extractor/createExtractor.js.map +7 -0
  14. package/dist/cjs/extractor/ensureImportingConcat.js +46 -0
  15. package/dist/cjs/extractor/ensureImportingConcat.js.map +7 -0
  16. package/dist/cjs/extractor/evaluateAstNode.js +116 -0
  17. package/dist/cjs/extractor/evaluateAstNode.js.map +7 -0
  18. package/dist/cjs/extractor/extractHelpers.js +118 -0
  19. package/dist/cjs/extractor/extractHelpers.js.map +7 -0
  20. package/dist/cjs/extractor/extractMediaStyle.js +187 -0
  21. package/dist/cjs/extractor/extractMediaStyle.js.map +7 -0
  22. package/dist/cjs/extractor/extractToClassNames.js +279 -0
  23. package/dist/cjs/extractor/extractToClassNames.js.map +7 -0
  24. package/dist/cjs/extractor/findTopmostFunction.js +29 -0
  25. package/dist/cjs/extractor/findTopmostFunction.js.map +7 -0
  26. package/dist/cjs/extractor/generatedUid.js +50 -0
  27. package/dist/cjs/extractor/generatedUid.js.map +7 -0
  28. package/dist/cjs/extractor/getPropValueFromAttributes.js +71 -0
  29. package/dist/cjs/extractor/getPropValueFromAttributes.js.map +7 -0
  30. package/dist/cjs/extractor/getSourceModule.js +91 -0
  31. package/dist/cjs/extractor/getSourceModule.js.map +7 -0
  32. package/dist/cjs/extractor/getStaticBindingsForScope.js +150 -0
  33. package/dist/cjs/extractor/getStaticBindingsForScope.js.map +7 -0
  34. package/dist/cjs/extractor/hoistClassNames.js +66 -0
  35. package/dist/cjs/extractor/hoistClassNames.js.map +7 -0
  36. package/dist/cjs/extractor/literalToAst.js +56 -0
  37. package/dist/cjs/extractor/literalToAst.js.map +7 -0
  38. package/dist/cjs/extractor/loadTamagui.js +63 -0
  39. package/dist/cjs/extractor/loadTamagui.js.map +7 -0
  40. package/dist/cjs/extractor/logLines.js +23 -0
  41. package/dist/cjs/extractor/logLines.js.map +7 -0
  42. package/dist/cjs/extractor/normalizeTernaries.js +102 -0
  43. package/dist/cjs/extractor/normalizeTernaries.js.map +7 -0
  44. package/dist/cjs/extractor/removeUnusedHooks.js +101 -0
  45. package/dist/cjs/extractor/removeUnusedHooks.js.map +7 -0
  46. package/dist/cjs/index.js +37 -0
  47. package/dist/cjs/index.js.map +7 -0
  48. package/dist/cjs/patchReactNativeWeb.js +129 -0
  49. package/dist/cjs/patchReactNativeWeb.js.map +7 -0
  50. package/dist/cjs/types.js +4 -0
  51. package/dist/cjs/types.js.map +7 -0
  52. package/dist/{constants.js → esm/constants.js} +0 -0
  53. package/dist/{constants.js.map → esm/constants.js.map} +1 -1
  54. package/dist/{extractor → esm/extractor}/accessSafe.js +0 -0
  55. package/dist/{extractor → esm/extractor}/accessSafe.js.map +1 -1
  56. package/dist/{extractor → esm/extractor}/babelParse.js +0 -0
  57. package/dist/{extractor → esm/extractor}/babelParse.js.map +1 -1
  58. package/dist/{extractor → esm/extractor}/buildClassName.js +0 -0
  59. package/dist/{extractor → esm/extractor}/buildClassName.js.map +1 -1
  60. package/dist/{extractor → esm/extractor}/createEvaluator.js +0 -0
  61. package/dist/{extractor → esm/extractor}/createEvaluator.js.map +1 -1
  62. package/dist/{extractor → esm/extractor}/createExtractor.js +92 -53
  63. package/dist/esm/extractor/createExtractor.js.map +7 -0
  64. package/dist/{extractor → esm/extractor}/ensureImportingConcat.js +0 -0
  65. package/dist/{extractor → esm/extractor}/ensureImportingConcat.js.map +1 -1
  66. package/dist/{extractor → esm/extractor}/evaluateAstNode.js +0 -0
  67. package/dist/{extractor → esm/extractor}/evaluateAstNode.js.map +1 -1
  68. package/dist/{extractor → esm/extractor}/extractHelpers.js +3 -1
  69. package/dist/esm/extractor/extractHelpers.js.map +7 -0
  70. package/dist/{extractor → esm/extractor}/extractMediaStyle.js +0 -0
  71. package/dist/{extractor → esm/extractor}/extractMediaStyle.js.map +1 -1
  72. package/dist/{extractor → esm/extractor}/extractToClassNames.js +21 -24
  73. package/dist/esm/extractor/extractToClassNames.js.map +7 -0
  74. package/dist/{extractor → esm/extractor}/findTopmostFunction.js +0 -0
  75. package/dist/{extractor → esm/extractor}/findTopmostFunction.js.map +1 -1
  76. package/dist/{extractor → esm/extractor}/generatedUid.js +0 -0
  77. package/dist/{extractor → esm/extractor}/generatedUid.js.map +1 -1
  78. package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js +0 -0
  79. package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js.map +1 -1
  80. package/dist/{extractor → esm/extractor}/getSourceModule.js +0 -0
  81. package/dist/{extractor → esm/extractor}/getSourceModule.js.map +1 -1
  82. package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js +0 -0
  83. package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js.map +1 -1
  84. package/dist/{extractor → esm/extractor}/hoistClassNames.js +0 -0
  85. package/dist/{extractor → esm/extractor}/hoistClassNames.js.map +1 -1
  86. package/dist/{extractor → esm/extractor}/literalToAst.js +0 -0
  87. package/dist/{extractor → esm/extractor}/literalToAst.js.map +1 -1
  88. package/dist/{extractor → esm/extractor}/loadTamagui.js +0 -0
  89. package/dist/{extractor → esm/extractor}/loadTamagui.js.map +1 -1
  90. package/dist/esm/extractor/logLines.js +17 -0
  91. package/dist/esm/extractor/logLines.js.map +7 -0
  92. package/dist/{extractor → esm/extractor}/normalizeTernaries.js +0 -0
  93. package/dist/{extractor → esm/extractor}/normalizeTernaries.js.map +1 -1
  94. package/dist/{extractor → esm/extractor}/removeUnusedHooks.js +0 -0
  95. package/dist/{extractor → esm/extractor}/removeUnusedHooks.js.map +1 -1
  96. package/dist/{index.js → esm/index.js} +0 -0
  97. package/dist/{index.js.map → esm/index.js.map} +1 -1
  98. package/dist/{patchReactNativeWeb.js → esm/patchReactNativeWeb.js} +18 -3
  99. package/dist/esm/patchReactNativeWeb.js.map +7 -0
  100. package/dist/{types.js → esm/types.js} +0 -0
  101. package/dist/{types.js.map → esm/types.js.map} +0 -0
  102. package/dist/jsx/constants.js +9 -0
  103. package/dist/jsx/extractor/accessSafe.js +10 -0
  104. package/dist/jsx/extractor/babelParse.js +29 -0
  105. package/dist/jsx/extractor/buildClassName.js +39 -0
  106. package/dist/jsx/extractor/createEvaluator.js +50 -0
  107. package/dist/jsx/extractor/createExtractor.js +839 -0
  108. package/dist/jsx/extractor/ensureImportingConcat.js +23 -0
  109. package/dist/jsx/extractor/evaluateAstNode.js +93 -0
  110. package/dist/jsx/extractor/extractHelpers.js +93 -0
  111. package/dist/jsx/extractor/extractMediaStyle.js +150 -0
  112. package/dist/jsx/extractor/extractToClassNames.js +239 -0
  113. package/dist/jsx/extractor/findTopmostFunction.js +22 -0
  114. package/dist/jsx/extractor/generatedUid.js +27 -0
  115. package/dist/jsx/extractor/getPropValueFromAttributes.js +48 -0
  116. package/dist/jsx/extractor/getSourceModule.js +68 -0
  117. package/dist/jsx/extractor/getStaticBindingsForScope.js +127 -0
  118. package/dist/jsx/extractor/hoistClassNames.js +43 -0
  119. package/dist/jsx/extractor/literalToAst.js +33 -0
  120. package/dist/jsx/extractor/loadTamagui.js +40 -0
  121. package/dist/jsx/extractor/logLines.js +16 -0
  122. package/dist/jsx/extractor/normalizeTernaries.js +51 -0
  123. package/dist/jsx/extractor/removeUnusedHooks.js +77 -0
  124. package/dist/jsx/index.js +13 -0
  125. package/dist/jsx/patchReactNativeWeb.js +106 -0
  126. package/dist/jsx/types.js +0 -0
  127. package/package.json +30 -27
  128. package/src/extractor/createExtractor.ts +115 -76
  129. package/src/extractor/extractHelpers.ts +12 -3
  130. package/src/extractor/extractToClassNames.ts +21 -27
  131. package/src/extractor/logLines.ts +11 -0
  132. package/src/patchReactNativeWeb.ts +21 -5
  133. package/src/types.ts +13 -3
  134. package/types/constants.d.ts +4 -0
  135. package/types/constants.d.ts.map +1 -0
  136. package/types/extractor/accessSafe.d.ts +3 -0
  137. package/types/extractor/accessSafe.d.ts.map +1 -0
  138. package/types/extractor/babelParse.d.ts +5 -0
  139. package/types/extractor/babelParse.d.ts.map +1 -0
  140. package/types/extractor/buildClassName.d.ts +4 -0
  141. package/types/extractor/buildClassName.d.ts.map +1 -0
  142. package/types/extractor/createEvaluator.d.ts +12 -0
  143. package/types/extractor/createEvaluator.d.ts.map +1 -0
  144. package/types/extractor/createExtractor.d.ts +14 -0
  145. package/types/extractor/createExtractor.d.ts.map +1 -0
  146. package/types/extractor/ensureImportingConcat.d.ts +4 -0
  147. package/types/extractor/ensureImportingConcat.d.ts.map +1 -0
  148. package/types/extractor/evaluateAstNode.d.ts +3 -0
  149. package/types/extractor/evaluateAstNode.d.ts.map +1 -0
  150. package/types/extractor/extractHelpers.d.ts +12 -0
  151. package/types/extractor/extractHelpers.d.ts.map +1 -0
  152. package/types/extractor/extractMediaStyle.d.ts +10 -0
  153. package/types/extractor/extractMediaStyle.d.ts.map +1 -0
  154. package/types/extractor/extractToClassNames.d.ts +22 -0
  155. package/types/extractor/extractToClassNames.d.ts.map +1 -0
  156. package/types/extractor/findTopmostFunction.d.ts +4 -0
  157. package/types/extractor/findTopmostFunction.d.ts.map +1 -0
  158. package/types/extractor/generatedUid.d.ts +5 -0
  159. package/types/extractor/generatedUid.d.ts.map +1 -0
  160. package/types/extractor/getPropValueFromAttributes.d.ts +3 -0
  161. package/types/extractor/getPropValueFromAttributes.d.ts.map +1 -0
  162. package/types/extractor/getSourceModule.d.ts +16 -0
  163. package/types/extractor/getSourceModule.d.ts.map +1 -0
  164. package/types/extractor/getStaticBindingsForScope.d.ts +4 -0
  165. package/types/extractor/getStaticBindingsForScope.d.ts.map +1 -0
  166. package/types/extractor/hoistClassNames.d.ts +6 -0
  167. package/types/extractor/hoistClassNames.d.ts.map +1 -0
  168. package/types/extractor/literalToAst.d.ts +3 -0
  169. package/types/extractor/literalToAst.d.ts.map +1 -0
  170. package/types/extractor/loadTamagui.d.ts +9 -0
  171. package/types/extractor/loadTamagui.d.ts.map +1 -0
  172. package/types/extractor/logLines.d.ts +2 -0
  173. package/types/extractor/logLines.d.ts.map +1 -0
  174. package/types/extractor/normalizeTernaries.d.ts +3 -0
  175. package/types/extractor/normalizeTernaries.d.ts.map +1 -0
  176. package/types/extractor/removeUnusedHooks.d.ts +3 -0
  177. package/types/extractor/removeUnusedHooks.d.ts.map +1 -0
  178. package/types/index.d.ts +8 -0
  179. package/types/index.d.ts.map +1 -0
  180. package/types/patchReactNativeWeb.d.ts +2 -0
  181. package/types/patchReactNativeWeb.d.ts.map +1 -0
  182. package/types/types.d.ts +79 -0
  183. package/types/types.d.ts.map +1 -0
  184. package/dist/extractor/createExtractor.js.map +0 -7
  185. package/dist/extractor/extractHelpers.js.map +0 -7
  186. package/dist/extractor/extractToClassNames.js.map +0 -7
  187. package/dist/index.cjs +0 -2079
  188. package/dist/index.cjs.map +0 -7
  189. package/dist/patchReactNativeWeb.js.map +0 -7
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@tamagui/static",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.13",
4
4
  "source": "src/index.ts",
5
- "main": "dist/index.cjs",
6
- "module": "dist/index.js",
7
- "typings": "types.d.ts",
5
+ "typings": "types",
6
+ "main": "dist/cjs",
7
+ "module": "dist/esm",
8
+ "module:jsx": "dist/_jsx",
8
9
  "files": [
9
- "dist",
10
- "src"
10
+ "types",
11
+ "src",
12
+ "dist"
11
13
  ],
12
14
  "scripts": {
13
15
  "build": "tamagui-build",
@@ -25,48 +27,49 @@
25
27
  },
26
28
  "license": "MIT",
27
29
  "devDependencies": {
28
- "@babel/core": "^7.15.5",
29
- "@babel/generator": "^7.15.4",
30
- "@babel/helper-plugin-utils": "^7.14.5",
31
- "@babel/parser": "^7.15.7",
32
30
  "@babel/plugin-syntax-typescript": "^7.14.5",
33
- "@babel/traverse": "^7.15.4",
34
31
  "@babel/types": "^7.15.6",
35
- "@dish/babel-preset": "^0.0.6",
36
- "@expo/match-media": "^0.1.0",
37
- "@tamagui/build": "^1.0.0-alpha.1",
38
- "@tamagui/core": "^1.0.0-alpha.1",
39
32
  "@testing-library/react": "13.0.0-alpha.4",
40
33
  "@types/jest": "*",
41
34
  "@types/node": "^16.11.9",
42
35
  "@types/react-native": "^0.64.2",
43
36
  "@types/webpack": "^4.41.26",
44
- "babel-literal-to-ast": "^2.1.0",
45
37
  "babel-loader": "^8.2.2",
46
38
  "css-loader": "^5.2.4",
47
- "esbuild": "^0.13.12",
48
- "find-cache-dir": "^3.3.1",
49
- "fs-extra": "^9.0.0",
50
- "invariant": "^2.2.4",
39
+ "esbuild-loader": "^2.16.0",
51
40
  "jest": "^27.3.1",
52
41
  "loader-utils": "^2.0.0",
53
- "lodash": "^4.17.20",
54
42
  "react": "*",
55
43
  "react-dom": "*",
56
44
  "react-test-renderer": "18.0.0-beta-149b420f6-20211119",
57
45
  "style-loader": "^3.3.0",
58
- "tamagui": "^1.0.0-alpha.1",
59
46
  "typescript": "^4.4.4",
60
47
  "webpack": "^5.58.1"
61
48
  },
62
49
  "dependencies": {
63
- "@tamagui/core-node": "^1.0.0-alpha.1",
64
- "@tamagui/fake-react-native": "^1.0.0-alpha.1",
65
- "@tamagui/helpers": "^1.0.0-alpha.1",
66
- "esbuild-register": "^3.1.2"
50
+ "@babel/core": "^7.15.5",
51
+ "@babel/generator": "^7.15.4",
52
+ "@babel/helper-plugin-utils": "^7.14.5",
53
+ "@babel/parser": "^7.15.7",
54
+ "@babel/traverse": "^7.15.4",
55
+ "@dish/babel-preset": "^0.0.6",
56
+ "@expo/match-media": "^0.1.0",
57
+ "@tamagui/build": "^1.0.0-alpha.12",
58
+ "@tamagui/core": "^1.0.0-alpha.13",
59
+ "@tamagui/core-node": "^1.0.0-alpha.13",
60
+ "@tamagui/fake-react-native": "^1.0.0-alpha.2",
61
+ "@tamagui/helpers": "^1.0.0-alpha.13",
62
+ "babel-literal-to-ast": "^2.1.0",
63
+ "esbuild": "^0.13.12",
64
+ "esbuild-register": "^3.1.2",
65
+ "find-cache-dir": "^3.3.1",
66
+ "fs-extra": "^9.0.0",
67
+ "invariant": "^2.2.4",
68
+ "lodash": "^4.17.20",
69
+ "tamagui": "^1.0.0-alpha.13"
67
70
  },
68
71
  "peerDependencies": {
69
72
  "react-native-web": "*"
70
73
  },
71
- "gitHead": "a41c5a5b08be5518d138515137122c248e3f7c71"
74
+ "gitHead": "5fa09073ac2c6bf529f0e81dd65db8b31682f360"
72
75
  }
@@ -13,6 +13,7 @@ import { findTopmostFunction } from './findTopmostFunction'
13
13
  import { getStaticBindingsForScope } from './getStaticBindingsForScope'
14
14
  import { literalToAst } from './literalToAst'
15
15
  import { loadTamagui } from './loadTamagui'
16
+ import { logLines } from './logLines'
16
17
  import { normalizeTernaries } from './normalizeTernaries'
17
18
  import { removeUnusedHooks } from './removeUnusedHooks'
18
19
 
@@ -51,9 +52,10 @@ export function createExtractor() {
51
52
  })
52
53
 
53
54
  let loadedTamaguiConfig: TamaguiInternalConfig
55
+ let hasLogged = false
54
56
 
55
57
  return {
56
- getTamaguiConfig() {
58
+ getTamagui() {
57
59
  return loadedTamaguiConfig
58
60
  },
59
61
  parse: (
@@ -66,7 +68,10 @@ export function createExtractor() {
66
68
  sourcePath = '',
67
69
  onExtractTag,
68
70
  getFlattenedNode,
69
- onDidFlatten,
71
+ disableExtraction,
72
+ disableExtractInlineMedia,
73
+ disableExtractVariables,
74
+ disableDebugAttr,
70
75
  ...props
71
76
  }: ExtractorParseProps
72
77
  ) => {
@@ -87,26 +92,25 @@ export function createExtractor() {
87
92
  loadedTamaguiConfig = tamaguiConfig
88
93
 
89
94
  const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]]
90
-
91
- // TODO this can be passed in / set based on if source changed
92
- // const shouldReCheckTheme = false //Date.now() - hasParsedFileLast > 600
93
- // hasParsedFileLast = Date.now()
94
-
95
- let doesUseValidImport = false
96
95
  const body = fileOrPath.type === 'Program' ? fileOrPath.get('body') : fileOrPath.program.body
97
96
 
98
97
  /**
99
98
  * Step 1: Determine if importing any statically extractable components
100
99
  */
101
- const isInternalImport = (importStr: string) =>
102
- isInsideTamagui(sourcePath) && importStr[0] === '.'
100
+ const isInternalImport = (importStr: string) => {
101
+ return isInsideTamagui(sourcePath) && importStr[0] === '.'
102
+ }
103
+
103
104
  const validComponents: { [key: string]: any } = Object.keys(components)
104
- .filter((key) => !!components[key]?.staticConfig)
105
+ // check if uppercase to avoid hitting media query proxy before init
106
+ .filter((key) => key[0].toUpperCase() === key[0] && !!components[key]?.staticConfig)
105
107
  .reduce((obj, name) => {
106
108
  obj[name] = components[name]
107
109
  return obj
108
110
  }, {})
109
111
 
112
+ let doesUseValidImport = false
113
+
110
114
  for (const bodyPath of body) {
111
115
  if (bodyPath.type !== 'ImportDeclaration') continue
112
116
  const node = ('node' in bodyPath ? bodyPath.node : bodyPath) as any
@@ -147,6 +151,12 @@ export function createExtractor() {
147
151
  */
148
152
  let programPath: NodePath<t.Program>
149
153
 
154
+ const res = {
155
+ flattened: 0,
156
+ optimized: 0,
157
+ modified: 0,
158
+ }
159
+
150
160
  callTraverse({
151
161
  Program: {
152
162
  enter(path) {
@@ -185,8 +195,41 @@ export function createExtractor() {
185
195
  return
186
196
  }
187
197
 
188
- const { staticConfig } = component
189
198
  const originalNodeName = node.name.name
199
+
200
+ if (shouldPrintDebug) {
201
+ console.log(`\n<${originalNodeName} />`)
202
+ }
203
+
204
+ const filePath = sourcePath.replace(process.cwd(), '.')
205
+ const lineNumbers = node.loc
206
+ ? node.loc.start.line +
207
+ (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : '')
208
+ : ''
209
+
210
+ // add data-is
211
+ if (shouldAddDebugProp && !disableDebugAttr) {
212
+ const preName = componentName ? `${componentName}:` : ''
213
+ res.modified++
214
+ node.attributes.unshift(
215
+ t.jsxAttribute(
216
+ t.jsxIdentifier('data-is'),
217
+ t.stringLiteral(
218
+ ` ${preName}${node.name.name} ${filePath.replace('./', '')}:${lineNumbers} `
219
+ )
220
+ )
221
+ )
222
+ }
223
+
224
+ if (disableExtraction) {
225
+ if (!hasLogged) {
226
+ console.log('🥚 Tamagui disableExtraction set: no CSS or optimizations will be run')
227
+ hasLogged = true
228
+ }
229
+ return
230
+ }
231
+
232
+ const { staticConfig } = component
190
233
  const isTextView = staticConfig.isText || false
191
234
  const validStyles = staticConfig?.validStyles ?? {}
192
235
 
@@ -223,10 +266,6 @@ export function createExtractor() {
223
266
  return res
224
267
  }
225
268
 
226
- if (shouldPrintDebug) {
227
- console.log(`\n<${originalNodeName} />`)
228
- }
229
-
230
269
  // Generate scope object at this level
231
270
  const staticNamespace = getStaticBindingsForScope(
232
271
  traversePath.scope,
@@ -399,9 +438,9 @@ export function createExtractor() {
399
438
  }
400
439
  const propName = prop.key['name']
401
440
  if (!isStaticAttributeName(propName) && propName !== 'tag') {
402
- // if (shouldPrintDebug) {
403
- console.log(' not a valid style prop!', propName)
404
- // }
441
+ if (shouldPrintDebug) {
442
+ console.log(' not a valid style prop!', propName)
443
+ }
405
444
  return false
406
445
  }
407
446
  return true
@@ -489,7 +528,9 @@ export function createExtractor() {
489
528
  const [test, alt, cons] = conditional
490
529
  if (!test) throw new Error(`no test`)
491
530
  if ([alt, cons].some((side) => side && !isExtractable(side))) {
492
- console.log('not extractable', alt, cons)
531
+ if (shouldPrintDebug) {
532
+ console.log('not extractable', alt, cons)
533
+ }
493
534
  return attr
494
535
  }
495
536
  // split into individual ternaries per object property
@@ -539,6 +580,11 @@ export function createExtractor() {
539
580
 
540
581
  // shorthand media queries
541
582
  if (name[0] === '$' && t.isJSXExpressionContainer(attribute?.value)) {
583
+ // allow disabling this extraction
584
+ if (disableExtractInlineMedia) {
585
+ return attr
586
+ }
587
+
542
588
  const shortname = name.slice(1)
543
589
  if (mediaQueryConfig[shortname]) {
544
590
  const expression = attribute.value.expression
@@ -587,11 +633,24 @@ export function createExtractor() {
587
633
  }
588
634
  }
589
635
 
636
+ // native shouldn't extract variables
637
+ if (disableExtractVariables) {
638
+ if (value) {
639
+ if (value.type === 'StringLiteral' && value.value[0] === '$') {
640
+ if (shouldPrintDebug) {
641
+ console.log(' native, disable extract var', value.value)
642
+ }
643
+ inlinePropCount++
644
+ return attr
645
+ }
646
+ }
647
+ }
648
+
590
649
  // if value can be evaluated, extract it and filter it out
591
650
  const styleValue = attemptEvalSafe(value)
592
651
 
593
- // we never flatten if a prop isn't a valid static attribute
594
- // but we need to make sure its post-prop mapping
652
+ // never flatten if a prop isn't a valid static attribute
653
+ // only post prop-mapping
595
654
  if (!isStaticAttributeName(name)) {
596
655
  let keys = [name]
597
656
  if (staticConfig.propMapper) {
@@ -621,6 +680,8 @@ export function createExtractor() {
621
680
  return {
622
681
  type: 'style',
623
682
  value: { [name]: styleValue },
683
+ name,
684
+ attr: path.node,
624
685
  }
625
686
  }
626
687
 
@@ -752,7 +813,7 @@ export function createExtractor() {
752
813
 
753
814
  // see if we can filter them
754
815
  if (shouldPrintDebug) {
755
- console.log(' - attrs (before): ', attrs.map(attrStr).join(', '))
816
+ console.log(' - attrs (before):\n', logLines(attrs.map(attrStr).join(', ')))
756
817
  }
757
818
 
758
819
  // now update to new values
@@ -772,12 +833,6 @@ export function createExtractor() {
772
833
  modifiedComponents.add(parentFn)
773
834
  }
774
835
 
775
- const filePath = sourcePath.replace(process.cwd(), '.')
776
- const lineNumbers = node.loc
777
- ? node.loc.start.line +
778
- (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : '')
779
- : ''
780
-
781
836
  // combine ternaries
782
837
  let ternaries: Ternary[] = []
783
838
  attrs = attrs
@@ -867,29 +922,27 @@ export function createExtractor() {
867
922
  if (cur.type === 'style') {
868
923
  // TODO need to loop over initial props not just style props
869
924
  for (const key in cur.value) {
870
- const shouldInsertNull =
871
- !!(
872
- staticConfig.ensureOverriddenProp?.[key] // || staticConfig.defaultProps?.[key]
873
- )
925
+ const shouldEnsureOverridden = !!staticConfig.ensureOverriddenProp?.[key]
874
926
  const isSetInAttrsAlready = attrs.some(
875
927
  (x) =>
876
928
  x.type === 'attr' &&
877
929
  x.value.type === 'JSXAttribute' &&
878
930
  x.value.name.name === key
879
931
  )
880
- const shouldInsertNullOverride = shouldInsertNull && !isSetInAttrsAlready
881
- // if (shouldPrintDebug) {
882
- // // prettier-ignore
883
- // console.log('what is', key, { shouldInsertNullOverride, shouldInsertNull, isSetInAttrsAlready })
884
- // }
885
- if (shouldInsertNullOverride) {
886
- acc.push({
887
- type: 'attr',
888
- value: t.jsxAttribute(
889
- t.jsxIdentifier(key),
890
- t.jsxExpressionContainer(t.nullLiteral())
891
- ),
892
- })
932
+
933
+ if (!isSetInAttrsAlready) {
934
+ const isVariant = !!staticConfig.variants?.[cur.name || '']
935
+ if (isVariant || shouldEnsureOverridden) {
936
+ acc.push({
937
+ type: 'attr',
938
+ value:
939
+ cur.attr ||
940
+ t.jsxAttribute(
941
+ t.jsxIdentifier(key),
942
+ t.jsxExpressionContainer(t.nullLiteral())
943
+ ),
944
+ })
945
+ }
893
946
  }
894
947
  }
895
948
  }
@@ -899,7 +952,7 @@ export function createExtractor() {
899
952
  }
900
953
 
901
954
  if (shouldPrintDebug) {
902
- console.log(' - attrs (flattened): ', attrs.map(attrStr).join(', '))
955
+ console.log(' - attrs (flattened): \n', logLines(attrs.map(attrStr).join(', ')))
903
956
  }
904
957
 
905
958
  // evaluate away purely style props
@@ -925,7 +978,7 @@ export function createExtractor() {
925
978
  }, [])
926
979
 
927
980
  if (shouldPrintDebug) {
928
- console.log(' - attrs (evaluated styles): ', attrs.map(attrStr).join(', '))
981
+ console.log(' - attrs (evaluated styles): \n', logLines(attrs.map(attrStr).join(', ')))
929
982
  }
930
983
 
931
984
  // combine styles, leave undefined values
@@ -943,7 +996,7 @@ export function createExtractor() {
943
996
  }, [])
944
997
 
945
998
  if (shouldPrintDebug) {
946
- console.log(' - attrs (combined 🔀): ', attrs.map(attrStr).join(', '))
999
+ console.log(' - attrs (combined 🔀): \n', logLines(attrs.map(attrStr).join(', ')))
947
1000
  }
948
1001
 
949
1002
  // post process
@@ -958,9 +1011,10 @@ export function createExtractor() {
958
1011
  const out = postProcessStyles(props, staticConfig, defaultTheme)
959
1012
  const next = out?.style ?? props
960
1013
  if (shouldPrintDebug) {
961
- console.log(' >> getStyles: ', objToStr(props), '==>>', objToStr(next))
962
- console.log(' >> style: ', objToStr(out.style))
963
- console.log(' >> viewp: ', objToStr(out.viewProps))
1014
+ console.log(' getStyles props >>\n', logLines(objToStr(props)))
1015
+ console.log(' getStyles next >>\n', logLines(objToStr(next)))
1016
+ console.log(' getStyles style >>\n', logLines(objToStr(out.style)))
1017
+ console.log(' getStyles viewp >>\n', logLines(objToStr(out.viewProps)))
964
1018
  }
965
1019
  if (staticConfig.validStyles) {
966
1020
  for (const key in next) {
@@ -972,10 +1026,6 @@ export function createExtractor() {
972
1026
  return next
973
1027
  }
974
1028
 
975
- if (shouldPrintDebug) {
976
- console.log(' staticConfig.defaultProps', staticConfig.defaultProps)
977
- }
978
-
979
1029
  // used to ensure we pass the entire prop bundle to getStyles
980
1030
  const completeStylesProcessed = getStyles({
981
1031
  ...staticConfig.defaultProps,
@@ -1004,9 +1054,9 @@ export function createExtractor() {
1004
1054
 
1005
1055
  if (shouldPrintDebug) {
1006
1056
  // prettier-ignore
1007
- console.log(' completeStaticProps', objToStr(completeStaticProps))
1057
+ console.log(' completeStaticProps\n', logLines(objToStr(completeStaticProps)))
1008
1058
  // prettier-ignore
1009
- console.log(' completeStylesProcessed', objToStr(completeStylesProcessed))
1059
+ console.log(' completeStylesProcessed\n', logLines(objToStr(completeStylesProcessed)))
1010
1060
  }
1011
1061
 
1012
1062
  for (const attr of attrs) {
@@ -1045,22 +1095,7 @@ export function createExtractor() {
1045
1095
  }
1046
1096
 
1047
1097
  if (shouldPrintDebug) {
1048
- console.log(' - attrs (after): ', attrs.map(attrStr).join(', '))
1049
- }
1050
-
1051
- // add data-is
1052
- if (shouldAddDebugProp) {
1053
- const preName = componentName ? `${componentName}:` : ''
1054
- // unshift so spreads/nesting overwrite
1055
- attrs.unshift({
1056
- type: 'attr',
1057
- value: t.jsxAttribute(
1058
- t.jsxIdentifier('data-is'),
1059
- t.stringLiteral(
1060
- ` ${preName}${node.name.name} ${filePath.replace('./', '')}:${lineNumbers} `
1061
- )
1062
- ),
1063
- })
1098
+ console.log(' - attrs (after):\n', logLines(attrs.map(attrStr).join(', ')))
1064
1099
  }
1065
1100
 
1066
1101
  if (shouldFlatten) {
@@ -1070,7 +1105,7 @@ export function createExtractor() {
1070
1105
  }
1071
1106
  isFlattened = true
1072
1107
  node.name.name = flatNode
1073
- onDidFlatten?.()
1108
+ res.flattened++
1074
1109
  if (closingElement) {
1075
1110
  closingElement.name.name = flatNode
1076
1111
  }
@@ -1079,9 +1114,11 @@ export function createExtractor() {
1079
1114
  if (shouldPrintDebug) {
1080
1115
  // prettier-ignore
1081
1116
  console.log(' [❊] inline props ', inlinePropCount, shouldDeopt ? ' deopted' : '', hasSpread ? ' spread' : '', '!flatten', staticConfig.neverFlatten)
1082
- console.log(' - attrs (end): ', attrs.map(attrStr).join(', '))
1117
+ console.log(' - attrs (end):\n', logLines(attrs.map(attrStr).join(', ')))
1083
1118
  }
1084
1119
 
1120
+ res.optimized++
1121
+
1085
1122
  onExtractTag({
1086
1123
  attrs,
1087
1124
  node,
@@ -1108,6 +1145,8 @@ export function createExtractor() {
1108
1145
  removeUnusedHooks(comp, shouldPrintDebug)
1109
1146
  }
1110
1147
  }
1148
+
1149
+ return res
1111
1150
  },
1112
1151
  }
1113
1152
  }
@@ -21,7 +21,10 @@ export const attrStr = (attr: ExtractedAttr) => {
21
21
 
22
22
  export const objToStr = (obj: any) => {
23
23
  return Object.entries(obj)
24
- .map(([k, v]) => `${k}:${Array.isArray(v) ? `[...]` : v && typeof v === 'object' ? `{${objToStr(v)}}` : v}`)
24
+ .map(
25
+ ([k, v]) =>
26
+ `${k}:${Array.isArray(v) ? `[...]` : v && typeof v === 'object' ? `{${objToStr(v)}}` : v}`
27
+ )
25
28
  .join(', ')
26
29
  }
27
30
 
@@ -69,7 +72,11 @@ export function findComponentName(scope) {
69
72
  return componentName
70
73
  }
71
74
 
72
- export function isValidThemeHook(jsxPath: NodePath<t.JSXElement>, n: t.MemberExpression, sourcePath: string) {
75
+ export function isValidThemeHook(
76
+ jsxPath: NodePath<t.JSXElement>,
77
+ n: t.MemberExpression,
78
+ sourcePath: string
79
+ ) {
73
80
  if (!t.isIdentifier(n.object) || !t.isIdentifier(n.property)) return false
74
81
  const bindings = jsxPath.scope.getAllBindings()
75
82
  const binding = bindings[n.object.name]
@@ -90,4 +97,6 @@ export function isValidThemeHook(jsxPath: NodePath<t.JSXElement>, n: t.MemberExp
90
97
  return true
91
98
  }
92
99
 
93
- export const isInsideTamagui = (srcName: string) => srcName.includes('/tamagui/')
100
+ export const isInsideTamagui = (srcName: string) => {
101
+ return srcName.includes('/tamagui/_jsx') || srcName.includes('/core/src')
102
+ }
@@ -18,6 +18,7 @@ import { ensureImportingConcat } from './ensureImportingConcat'
18
18
  import { isSimpleSpread } from './extractHelpers'
19
19
  import { extractMediaStyle } from './extractMediaStyle'
20
20
  import { hoistClassNames } from './hoistClassNames'
21
+ import { logLines } from './logLines'
21
22
 
22
23
  export const CONCAT_CLASSNAME_IMPORT = 'concatClassName'
23
24
 
@@ -61,7 +62,7 @@ export function extractToClassNames({
61
62
  '`sourcePath` must be an absolute path to a .js file'
62
63
  )
63
64
 
64
- const shouldLogTiming = shouldPrintDebug || options.logTimings
65
+ const shouldLogTiming = options.logTimings ?? true
65
66
  const start = Date.now()
66
67
  const mem = shouldLogTiming ? process.memoryUsage() : null
67
68
 
@@ -79,17 +80,11 @@ export function extractToClassNames({
79
80
  const cssMap = new Map<string, { css: string; commentTexts: string[] }>()
80
81
  const existingHoists: { [key: string]: t.Identifier } = {}
81
82
 
82
- let flattened = 0
83
- let optimized = 0
84
-
85
- extractor.parse(ast, {
83
+ const res = extractor.parse(ast, {
86
84
  sourcePath,
87
85
  shouldPrintDebug,
88
86
  ...options,
89
87
  getFlattenedNode: ({ tag }) => tag,
90
- onDidFlatten() {
91
- flattened++
92
- },
93
88
  onExtractTag: ({
94
89
  attrs,
95
90
  node,
@@ -100,8 +95,6 @@ export function extractToClassNames({
100
95
  lineNumbers,
101
96
  programPath,
102
97
  }) => {
103
- optimized++
104
-
105
98
  let finalClassNames: ClassNameObject[] = []
106
99
  let finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []
107
100
  let finalStyles: StyleObject[] = []
@@ -144,10 +137,6 @@ export function extractToClassNames({
144
137
  case 'style':
145
138
  const styles = addStyles(attr.value)
146
139
  const newClassNames = concatClassName(styles.map((x) => x.identifier).join(' '))
147
- if (shouldPrintDebug) {
148
- // console.log(' style', attr.value)
149
- console.log(' classnames', newClassNames, finalClassNames)
150
- }
151
140
  // prettier-ignore
152
141
  const existing = finalClassNames.find((x) => x.type == 'StringLiteral') as t.StringLiteral | null
153
142
  if (existing) {
@@ -157,7 +146,7 @@ export function extractToClassNames({
157
146
  }
158
147
  if (shouldPrintDebug) {
159
148
  // prettier-ignore
160
- console.log(' classnames (after)', finalClassNames.map(x => x['value']).join(' '))
149
+ console.log(' classnames (after)\n', logLines(finalClassNames.map(x => x['value']).join(' ')))
161
150
  }
162
151
  break
163
152
  case 'attr':
@@ -190,7 +179,7 @@ export function extractToClassNames({
190
179
  const mediaExtraction = extractMediaStyle(
191
180
  attr.value,
192
181
  jsxPath,
193
- extractor.getTamaguiConfig(),
182
+ extractor.getTamagui(),
194
183
  sourcePath,
195
184
  lastMediaImportance,
196
185
  shouldPrintDebug
@@ -276,15 +265,15 @@ export function extractToClassNames({
276
265
  },
277
266
  })
278
267
 
279
- if (!optimized) {
268
+ if (!res || (!res.modified && !res.optimized && !res.flattened)) {
269
+ if (shouldPrintDebug) {
270
+ console.log('no res or none modified', res)
271
+ }
280
272
  return null
281
273
  }
282
274
 
283
275
  const styles = Array.from(cssMap.values())
284
- .map((x) => {
285
- // remove comments
286
- return x.css //shouldInternalDedupe ? x.css : `${x.commentTexts.join('\n')}\n${x.css}`
287
- })
276
+ .map((x) => x.css)
288
277
  .join('\n')
289
278
  .trim()
290
279
 
@@ -320,12 +309,17 @@ export function extractToClassNames({
320
309
  console.log('\n -------- output style -------- \n\n', styles)
321
310
  }
322
311
 
323
- if (shouldLogTiming && mem) {
324
- // console.log(`${parseTime} / ${traverseTime} / ${generateTime}`)
325
- const memUsed =
326
- Math.round(((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204) * 10) / 10
327
- // prettier-ignore
328
- console.log(` 🥚 ${basename(sourcePath).padStart(40)} ${`${Date.now() - start}`.padStart(3)}ms ׁ· ${`${optimized}`.padStart(4)} optimized · ${flattened} flattened ${memUsed > 10 ? `used ${memUsed}MB` : ''}`)
312
+ if (shouldLogTiming) {
313
+ const memUsed = mem
314
+ ? Math.round(((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204) * 10) / 10
315
+ : 0
316
+ const timing = `${Date.now() - start}`.padStart(3)
317
+ const path = basename(sourcePath).padStart(40)
318
+ const numOptimized = `${res.optimized}`.padStart(4)
319
+ const memory = memUsed > 10 ? `used ${memUsed}MB` : ''
320
+ console.log(
321
+ ` 🥚 ${path} ${timing}ms ׁ· ${numOptimized} optimized · ${res.flattened} flattened ${memory}`
322
+ )
329
323
  }
330
324
 
331
325
  return {
@@ -0,0 +1,11 @@
1
+ export const logLines = (str: string) => {
2
+ let lines: string[] = ['']
3
+ const items = str.split(' ')
4
+ for (const item of items) {
5
+ if (item.length + lines[lines.length - 1].length > 100) {
6
+ lines.push('')
7
+ }
8
+ lines[lines.length - 1] += item + ' '
9
+ }
10
+ return lines.map((line, i) => ' ' + (i == 0 ? '' : ' ') + line.trim()).join('\n')
11
+ }
@@ -9,10 +9,28 @@ import path from 'path'
9
9
  // keep it sync
10
10
  export function patchReactNativeWeb() {
11
11
  const rootDir = require.resolve('react-native-web').replace(/\/dist.*/, '')
12
+ const modulePath = path.join(rootDir, 'dist', 'tamagui-exports.js')
13
+ const cjsPath = path.join(rootDir, 'dist', 'cjs', 'tamagui-exports.js')
12
14
 
13
- // write our export files
14
- fs.writeFileSync(path.join(rootDir, 'dist', 'tamagui-exports.js'), moduleExports)
15
- fs.writeFileSync(path.join(rootDir, 'dist', 'cjs', 'tamagui-exports.js'), cjsExports)
15
+ const isEqual = (() => {
16
+ let res = false
17
+ try {
18
+ res =
19
+ fs.readFileSync(modulePath, 'utf-8') === moduleExports &&
20
+ fs.readFileSync(cjsPath, 'utf-8') == cjsExports
21
+ } catch {
22
+ res = false
23
+ }
24
+ return res
25
+ })()
26
+
27
+ if (!isEqual) {
28
+ console.log('🥚 Tamagui patching react-native-web to share atomic styling primitives')
29
+ console.log(' > adding', modulePath)
30
+ console.log(' > adding', cjsPath)
31
+ fs.writeFileSync(modulePath, moduleExports)
32
+ fs.writeFileSync(cjsPath, cjsExports)
33
+ }
16
34
 
17
35
  // if entry files not patched, patch them:
18
36
  const moduleEntry = path.join(rootDir, 'dist', 'index.js')
@@ -41,8 +59,6 @@ exports.TamaguiExports = _interopRequireDefault(require("./tamagui-exports"));
41
59
  // tamagui-patch-end
42
60
  `
43
61
  )
44
-
45
- console.log(`Tamagui patched react-native-web`)
46
62
  }
47
63
  }
48
64