@tamagui/static 1.0.1-beta.190 → 1.0.1-beta.192

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 (40) hide show
  1. package/dist/constants.js +0 -3
  2. package/dist/constants.js.map +2 -2
  3. package/dist/extractor/buildClassName.js +20 -5
  4. package/dist/extractor/buildClassName.js.map +2 -2
  5. package/dist/extractor/createEvaluator.js +3 -3
  6. package/dist/extractor/createEvaluator.js.map +2 -2
  7. package/dist/extractor/createExtractor.js +72 -49
  8. package/dist/extractor/createExtractor.js.map +3 -3
  9. package/dist/extractor/ensureImportingConcat.js +4 -8
  10. package/dist/extractor/ensureImportingConcat.js.map +2 -2
  11. package/dist/extractor/extractHelpers.js +37 -9
  12. package/dist/extractor/extractHelpers.js.map +3 -3
  13. package/dist/extractor/extractMediaStyle.js +11 -11
  14. package/dist/extractor/extractMediaStyle.js.map +2 -2
  15. package/dist/extractor/extractToClassNames.js +5 -17
  16. package/dist/extractor/extractToClassNames.js.map +2 -2
  17. package/dist/extractor/getStaticBindingsForScope.js +3 -3
  18. package/dist/extractor/getStaticBindingsForScope.js.map +2 -2
  19. package/dist/extractor/loadTamagui.js +7 -5
  20. package/dist/extractor/loadTamagui.js.map +2 -2
  21. package/dist/types.js.map +1 -1
  22. package/package.json +16 -14
  23. package/src/constants.ts +0 -1
  24. package/src/extractor/buildClassName.ts +20 -4
  25. package/src/extractor/createEvaluator.ts +5 -5
  26. package/src/extractor/createExtractor.ts +53 -33
  27. package/src/extractor/ensureImportingConcat.ts +4 -11
  28. package/src/extractor/extractHelpers.ts +41 -7
  29. package/src/extractor/extractMediaStyle.ts +17 -10
  30. package/src/extractor/extractToClassNames.ts +6 -20
  31. package/src/extractor/getStaticBindingsForScope.ts +4 -4
  32. package/src/extractor/loadTamagui.ts +9 -7
  33. package/src/types.ts +5 -2
  34. package/types/constants.d.ts +0 -1
  35. package/types/extractor/buildClassName.d.ts +4 -1
  36. package/types/extractor/createEvaluator.d.ts +3 -3
  37. package/types/extractor/createExtractor.d.ts +1 -1
  38. package/types/extractor/extractHelpers.d.ts +5 -3
  39. package/types/extractor/extractMediaStyle.d.ts +3 -3
  40. package/types/types.d.ts +4 -2
@@ -1,13 +1,14 @@
1
1
  import { NodePath } from '@babel/traverse'
2
2
  import * as t from '@babel/types'
3
3
  import { TamaguiInternalConfig, getStylesAtomic, mediaObjectToString } from '@tamagui/core-node'
4
- import { ViewStyle } from 'react-native'
4
+ import type { ViewStyle } from 'react-native'
5
5
 
6
6
  import { MEDIA_SEP } from '../constants.js'
7
- import type { StyleObject, Ternary } from '../types.js'
8
- import { isInsideTamagui, isPresent } from './extractHelpers.js'
7
+ import type { StyleObject, TamaguiOptionsWithFileInfo, Ternary } from '../types.js'
8
+ import { isPresent, isValidImport } from './extractHelpers.js'
9
9
 
10
10
  export function extractMediaStyle(
11
+ props: TamaguiOptionsWithFileInfo,
11
12
  ternary: Ternary,
12
13
  jsxPath: NodePath<t.JSXElement>,
13
14
  tamaguiConfig: TamaguiInternalConfig,
@@ -15,13 +16,14 @@ export function extractMediaStyle(
15
16
  importance = 0,
16
17
  shouldPrintDebug: boolean | 'verbose' = false
17
18
  ) {
18
- const mt = getMediaQueryTernary(ternary, jsxPath, sourcePath)
19
+ const mt = getMediaQueryTernary(props, ternary, jsxPath, sourcePath)
19
20
  if (!mt) {
20
21
  return null
21
22
  }
22
23
  const { key } = mt
23
24
  const mq = tamaguiConfig.media[key]
24
25
  if (!mq) {
26
+ // eslint-disable-next-line no-console
25
27
  console.error(`Media query "${key}" not found: ${Object.keys(tamaguiConfig.media)}`)
26
28
  return null
27
29
  }
@@ -33,6 +35,7 @@ export function extractMediaStyle(
33
35
  getStyleObj(ternary.alternate, true),
34
36
  ].filter(isPresent)
35
37
  if (shouldPrintDebug && !styleOpts.length) {
38
+ // eslint-disable-next-line no-console
36
39
  console.log(' media query, no styles?')
37
40
  return null
38
41
  }
@@ -80,6 +83,7 @@ export function extractMediaStyle(
80
83
  })
81
84
  if (shouldPrintDebug === 'verbose') {
82
85
  // prettier-ignore
86
+ // eslint-disable-next-line no-console
83
87
  console.log(' media styles:', importance, styleObj, singleMediaStyles.map(x => x.identifier).join(', '))
84
88
  }
85
89
  // add to output
@@ -91,6 +95,7 @@ export function extractMediaStyle(
91
95
  }
92
96
 
93
97
  function getMediaQueryTernary(
98
+ props: TamaguiOptionsWithFileInfo,
94
99
  ternary: Ternary,
95
100
  jsxPath: NodePath<t.JSXElement>,
96
101
  sourcePath: string
@@ -104,6 +109,7 @@ function getMediaQueryTernary(
104
109
  if (t.isLogicalExpression(ternary.test) && ternary.test.operator === '&&') {
105
110
  // *should* be normalized to always be on left side
106
111
  const mediaLeft = getMediaInfoFromExpression(
112
+ props,
107
113
  ternary.test.left,
108
114
  jsxPath,
109
115
  sourcePath,
@@ -122,6 +128,7 @@ function getMediaQueryTernary(
122
128
  // const media = useMedia()
123
129
  // ... media.sm
124
130
  const result = getMediaInfoFromExpression(
131
+ props,
125
132
  ternary.test,
126
133
  jsxPath,
127
134
  sourcePath,
@@ -137,6 +144,7 @@ function getMediaQueryTernary(
137
144
  }
138
145
 
139
146
  function getMediaInfoFromExpression(
147
+ props: TamaguiOptionsWithFileInfo,
140
148
  test: t.Expression,
141
149
  jsxPath: NodePath<t.JSXElement>,
142
150
  sourcePath: string,
@@ -156,20 +164,21 @@ function getMediaInfoFromExpression(
156
164
  if (!binding) return false
157
165
  const bindingNode = binding.path?.node
158
166
  if (!t.isVariableDeclarator(bindingNode) || !bindingNode.init) return false
159
- if (!isValidMediaCall(jsxPath, bindingNode.init, sourcePath)) return false
167
+ if (!isValidMediaCall(props, jsxPath, bindingNode.init, sourcePath)) return false
160
168
  return { key, bindingName: name }
161
169
  }
162
170
  if (t.isIdentifier(test)) {
163
171
  const key = test.name
164
172
  const node = jsxPath.scope.getBinding(test.name)?.path?.node
165
173
  if (!t.isVariableDeclarator(node)) return false
166
- if (!node.init || !isValidMediaCall(jsxPath, node.init, sourcePath)) return false
174
+ if (!node.init || !isValidMediaCall(props, jsxPath, node.init, sourcePath)) return false
167
175
  return { key, bindingName: key }
168
176
  }
169
177
  return null
170
178
  }
171
179
 
172
180
  export function isValidMediaCall(
181
+ props: TamaguiOptionsWithFileInfo,
173
182
  jsxPath: NodePath<t.JSXElement>,
174
183
  init: t.Expression,
175
184
  sourcePath: string
@@ -183,10 +192,8 @@ export function isValidMediaCall(
183
192
  if (!mediaBinding) return false
184
193
  const useMediaImport = mediaBinding.path.parent
185
194
  if (!t.isImportDeclaration(useMediaImport)) return false
186
- if (useMediaImport.source.value !== 'tamagui') {
187
- if (!isInsideTamagui(sourcePath)) {
188
- return false
189
- }
195
+ if (!isValidImport(props, sourcePath)) {
196
+ return false
190
197
  }
191
198
  return true
192
199
  }
@@ -7,9 +7,8 @@ import * as t from '@babel/types'
7
7
  import { getStylesAtomic } from '@tamagui/core-node'
8
8
  import { concatClassName } from '@tamagui/helpers'
9
9
  import invariant from 'invariant'
10
- import { ViewStyle } from 'react-native'
10
+ import type { ViewStyle } from 'react-native'
11
11
 
12
- import { CONCAT_CLASSNAME_IMPORT } from '../constants.js'
13
12
  import type { ClassNameObject, StyleObject, TamaguiOptions, Ternary } from '../types.js'
14
13
  import { babelParse } from './babelParse.js'
15
14
  import { buildClassName } from './buildClassName.js'
@@ -86,9 +85,9 @@ export async function extractToClassNames({
86
85
  let hasFlattened = false
87
86
 
88
87
  const res = await extractor.parse(ast, {
89
- sourcePath,
90
88
  shouldPrintDebug,
91
89
  ...options,
90
+ sourcePath,
92
91
  target: 'html',
93
92
  extractStyledDefinitions: true,
94
93
  onStyleRule(identifier, rules) {
@@ -224,6 +223,7 @@ export async function extractToClassNames({
224
223
  }
225
224
  case 'ternary': {
226
225
  const mediaExtraction = extractMediaStyle(
226
+ { ...options, sourcePath },
227
227
  attr.value,
228
228
  jsxPath,
229
229
  extractor.getTamagui()!,
@@ -323,16 +323,7 @@ export async function extractToClassNames({
323
323
  })()
324
324
 
325
325
  // inserts the _cn variable and uses it for className
326
- let names = buildClassName(finalClassNames)
327
-
328
- if (names) {
329
- if (t.isStringLiteral(names)) {
330
- names.value = concatClassName(names.value)
331
- names.value = `${extraClassNames} ${names.value}`
332
- } else {
333
- names = t.binaryExpression('+', t.stringLiteral(extraClassNames), names)
334
- }
335
- }
326
+ const names = buildClassName(finalClassNames, extraClassNames)
336
327
 
337
328
  const nameExpr = names ? hoistClassNames(jsxPath, existingHoists, names) : null
338
329
  let expr = nameExpr
@@ -346,7 +337,7 @@ export async function extractToClassNames({
346
337
  const simpleSpreads = attrs.filter(
347
338
  (x) => t.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value)
348
339
  )
349
- expr = t.callExpression(t.identifier(CONCAT_CLASSNAME_IMPORT), [
340
+ expr = t.callExpression(t.identifier('concatClassName'), [
350
341
  expr,
351
342
  ...simpleSpreads.map((val) => val.value['argument']),
352
343
  ])
@@ -369,13 +360,8 @@ export async function extractToClassNames({
369
360
  cssMap.set(className, val)
370
361
  }
371
362
  } else if (rules.length) {
372
- if (rules.length > 1) {
373
- // eslint-disable-next-line no-console
374
- console.log(' rules error', { rules })
375
- throw new Error(`Shouldn't have more than one rule`)
376
- }
377
363
  cssMap.set(className, {
378
- css: rules[0],
364
+ css: rules.join('\n'),
379
365
  commentTexts: [comment],
380
366
  })
381
367
  }
@@ -120,14 +120,14 @@ export async function getStaticBindingsForScope(
120
120
  }
121
121
  }
122
122
  } catch (err: any) {
123
- if (process.env.DEBUG?.startsWith('tamagui')) {
124
- // eslint-disable-next-line no-console
125
- console.log(`Error in partial evaluation`, err.message, err.stack)
126
- } else {
123
+ if (shouldPrintDebug) {
127
124
  // eslint-disable-next-line no-console
128
125
  console.warn(
129
126
  ` | Skipping partial evaluation of constant file: ${moduleName} (DEBUG=tamagui for more)`
130
127
  )
128
+ } else if (process.env.DEBUG?.startsWith('tamagui')) {
129
+ // eslint-disable-next-line no-console
130
+ console.log(`Error in partial evaluation`, err.message, err.stack)
131
131
  }
132
132
  }
133
133
  }
@@ -63,7 +63,7 @@ export async function loadTamagui(props: Props): Promise<TamaguiProjectInfo> {
63
63
  const external = ['@tamagui/core', '@tamagui/core-node', 'react', 'react-dom']
64
64
  const configEntry = props.config ? join(process.cwd(), props.config) : ''
65
65
 
66
- if (process.env.DEBUG?.startsWith('tamagui')) {
66
+ if (process.env.NODE_ENV === 'development' && process.env.DEBUG?.startsWith('tamagui')) {
67
67
  console.log(`Building config entry`, configEntry)
68
68
  }
69
69
 
@@ -104,10 +104,6 @@ Tamagui built config and components:`
104
104
  }),
105
105
  ])
106
106
 
107
- if (process.env.DEBUG?.startsWith('tamagui')) {
108
- console.log(`Built configs`)
109
- }
110
-
111
107
  const coreNode = require('@tamagui/core-node')
112
108
 
113
109
  registerRequire(props.bubbleErrors)
@@ -122,6 +118,10 @@ Tamagui built config and components:`
122
118
  ...(includesCore && gatherTamaguiComponentInfo([coreNode])),
123
119
  }
124
120
 
121
+ if (process.env.NODE_ENV === 'development' && process.env.DEBUG?.startsWith('tamagui')) {
122
+ console.log('Loaded components', components)
123
+ }
124
+
125
125
  cache[key] = {
126
126
  components,
127
127
  nameToPaths: {},
@@ -254,7 +254,9 @@ export function loadTamaguiSync(props: Props): TamaguiProjectInfo {
254
254
  tamaguiConfig = (exp['default'] || exp) as TamaguiInternalConfig
255
255
  if (!tamaguiConfig || !tamaguiConfig.parsed) {
256
256
  const confPath = require.resolve(configPath)
257
- throw new Error(`Can't find valid config in ${confPath}`)
257
+ throw new Error(`Can't find valid config in ${confPath}:
258
+
259
+ Be sure you "export default" the config.`)
258
260
  }
259
261
  }
260
262
 
@@ -269,7 +271,7 @@ export function loadTamaguiSync(props: Props): TamaguiProjectInfo {
269
271
 
270
272
  // set up core-node
271
273
  if (tamaguiConfig) {
272
- createTamagui(tamaguiConfig)
274
+ createTamagui(tamaguiConfig as any)
273
275
  }
274
276
 
275
277
  cache[key] = {
package/src/types.ts CHANGED
@@ -62,9 +62,12 @@ export type ExtractTagProps = {
62
62
  staticConfig: StaticConfig
63
63
  }
64
64
 
65
- export type ExtractorParseProps = TamaguiOptions & {
65
+ export type TamaguiOptionsWithFileInfo = TamaguiOptions & {
66
+ sourcePath: string
67
+ }
68
+
69
+ export type ExtractorParseProps = TamaguiOptionsWithFileInfo & {
66
70
  target: 'native' | 'html'
67
- sourcePath?: string
68
71
  shouldPrintDebug?: boolean | 'verbose'
69
72
  onExtractTag: (props: ExtractTagProps) => void
70
73
  getFlattenedNode?: (props: { isTextView: boolean; tag: string }) => string
@@ -2,6 +2,5 @@ export declare const CSS_FILE_NAME = "__snack.css";
2
2
  export declare const MEDIA_SEP = "_";
3
3
  export declare const cacheDir: any;
4
4
  export declare const FAILED_EVAL: unique symbol;
5
- export declare const CONCAT_CLASSNAME_IMPORT = "concatClassName";
6
5
  export declare const SHOULD_DEBUG: boolean | undefined;
7
6
  //# sourceMappingURL=constants.d.ts.map
@@ -1,4 +1,7 @@
1
1
  import * as t from '@babel/types';
2
2
  import type { ClassNameObject } from '../types.js';
3
- export declare function buildClassName(classNameObjects: ClassNameObject[]): t.Expression | t.StringLiteral | null;
3
+ declare type Builder = (objects: ClassNameObject[], extras?: string) => t.Expression | t.StringLiteral | null;
4
+ export declare const buildClassName: Builder;
5
+ export declare const buildClassNameLogic: Builder;
6
+ export {};
4
7
  //# sourceMappingURL=buildClassName.d.ts.map
@@ -1,8 +1,8 @@
1
1
  import { NodePath } from '@babel/traverse';
2
2
  import * as t from '@babel/types';
3
- import type { TamaguiConfig } from '@tamagui/core-node';
4
- export declare function createEvaluator({ tamaguiConfig, staticNamespace, sourcePath, traversePath, shouldPrintDebug, }: {
5
- tamaguiConfig: TamaguiConfig;
3
+ import { TamaguiOptionsWithFileInfo } from '../types.js';
4
+ export declare function createEvaluator({ props, staticNamespace, sourcePath, traversePath, shouldPrintDebug, }: {
5
+ props: TamaguiOptionsWithFileInfo;
6
6
  staticNamespace: Record<string, any>;
7
7
  sourcePath: string;
8
8
  traversePath?: NodePath<t.JSXElement>;
@@ -16,7 +16,7 @@ export declare function createExtractor({ logger }?: ExtractorOptions): {
16
16
  [key: string]: Partial<import("@tamagui/core-node").TamaguiBaseTheme> & {
17
17
  [key: string]: import("@tamagui/core-node").VariableVal;
18
18
  };
19
- }, {}, {
19
+ }, import("@tamagui/core-node").GenericShorthands, {
20
20
  [key: string]: {
21
21
  [key: string]: string | number;
22
22
  };
@@ -1,12 +1,14 @@
1
1
  import type { NodePath } from '@babel/traverse';
2
2
  import * as t from '@babel/types';
3
- import type { ExtractedAttr, Ternary } from '../types.js';
3
+ import type { ExtractedAttr, TamaguiOptionsWithFileInfo, Ternary } from '../types.js';
4
4
  export declare function isPresent<T extends Object>(input: null | void | undefined | T): input is T;
5
5
  export declare function isSimpleSpread(node: t.JSXSpreadAttribute): boolean;
6
6
  export declare const attrStr: (attr?: ExtractedAttr) => string | t.JSXIdentifier;
7
7
  export declare const objToStr: (obj: any, spacer?: string) => any;
8
8
  export declare const ternaryStr: (x: Ternary) => string;
9
9
  export declare function findComponentName(scope: any): string | undefined;
10
- export declare function isValidThemeHook(jsxPath: NodePath<t.JSXElement>, n: t.MemberExpression, sourcePath: string): boolean;
11
- export declare const isInsideTamagui: (srcName: string) => boolean;
10
+ export declare function isValidThemeHook(props: TamaguiOptionsWithFileInfo, jsxPath: NodePath<t.JSXElement>, n: t.MemberExpression, sourcePath: string): boolean;
11
+ export declare const isInsideComponentPackage: (props: TamaguiOptionsWithFileInfo, srcName: string) => boolean;
12
+ export declare const isComponentPackage: (props: TamaguiOptionsWithFileInfo, srcName: string) => boolean;
13
+ export declare const isValidImport: (props: TamaguiOptionsWithFileInfo, srcName: string) => boolean;
12
14
  //# sourceMappingURL=extractHelpers.d.ts.map
@@ -1,10 +1,10 @@
1
1
  import { NodePath } from '@babel/traverse';
2
2
  import * as t from '@babel/types';
3
3
  import { TamaguiInternalConfig } from '@tamagui/core-node';
4
- import type { Ternary } from '../types.js';
5
- export declare function extractMediaStyle(ternary: Ternary, jsxPath: NodePath<t.JSXElement>, tamaguiConfig: TamaguiInternalConfig, sourcePath: string, importance?: number, shouldPrintDebug?: boolean | 'verbose'): {
4
+ import type { TamaguiOptionsWithFileInfo, Ternary } from '../types.js';
5
+ export declare function extractMediaStyle(props: TamaguiOptionsWithFileInfo, ternary: Ternary, jsxPath: NodePath<t.JSXElement>, tamaguiConfig: TamaguiInternalConfig, sourcePath: string, importance?: number, shouldPrintDebug?: boolean | 'verbose'): {
6
6
  mediaStyles: StyleObject[];
7
7
  ternaryWithoutMedia: Ternary | null;
8
8
  } | null;
9
- export declare function isValidMediaCall(jsxPath: NodePath<t.JSXElement>, init: t.Expression, sourcePath: string): boolean;
9
+ export declare function isValidMediaCall(props: TamaguiOptionsWithFileInfo, jsxPath: NodePath<t.JSXElement>, init: t.Expression, sourcePath: string): boolean;
10
10
  //# sourceMappingURL=extractMediaStyle.d.ts.map
package/types/types.d.ts CHANGED
@@ -50,9 +50,11 @@ export declare type ExtractTagProps = {
50
50
  completeProps: Record<string, any>;
51
51
  staticConfig: StaticConfig;
52
52
  };
53
- export declare type ExtractorParseProps = TamaguiOptions & {
53
+ export declare type TamaguiOptionsWithFileInfo = TamaguiOptions & {
54
+ sourcePath: string;
55
+ };
56
+ export declare type ExtractorParseProps = TamaguiOptionsWithFileInfo & {
54
57
  target: 'native' | 'html';
55
- sourcePath?: string;
56
58
  shouldPrintDebug?: boolean | 'verbose';
57
59
  onExtractTag: (props: ExtractTagProps) => void;
58
60
  getFlattenedNode?: (props: {