@tamagui/static 1.0.1-beta.141 → 1.0.1-beta.142

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 (78) hide show
  1. package/dist/cjs/extractor/createEvaluator.js.map +2 -2
  2. package/dist/cjs/extractor/createExtractor.js +1138 -1106
  3. package/dist/cjs/extractor/createExtractor.js.map +2 -2
  4. package/dist/cjs/extractor/extractToClassNames.js +4 -4
  5. package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
  6. package/dist/cjs/extractor/getStaticBindingsForScope.js +18 -2
  7. package/dist/cjs/extractor/getStaticBindingsForScope.js.map +2 -2
  8. package/dist/cjs/extractor/loadTamagui.js +205 -28
  9. package/dist/cjs/extractor/loadTamagui.js.map +2 -2
  10. package/dist/cjs/extractor/timer.js +8 -1
  11. package/dist/cjs/extractor/timer.js.map +2 -2
  12. package/dist/cjs/getPragmaOptions.js +68 -0
  13. package/dist/cjs/getPragmaOptions.js.map +7 -0
  14. package/dist/cjs/index.js +1 -0
  15. package/dist/cjs/index.js.map +2 -2
  16. package/dist/cjs/require.js +1 -20
  17. package/dist/cjs/require.js.map +2 -2
  18. package/dist/cjs/types.js.map +1 -1
  19. package/dist/cjs/webpackPlugin.js +35 -0
  20. package/dist/cjs/webpackPlugin.js.map +7 -0
  21. package/dist/esm/extractor/createEvaluator.js.map +2 -2
  22. package/dist/esm/extractor/createExtractor.js +1140 -1108
  23. package/dist/esm/extractor/createExtractor.js.map +2 -2
  24. package/dist/esm/extractor/extractToClassNames.js +4 -4
  25. package/dist/esm/extractor/extractToClassNames.js.map +2 -2
  26. package/dist/esm/extractor/getStaticBindingsForScope.js +17 -2
  27. package/dist/esm/extractor/getStaticBindingsForScope.js.map +2 -2
  28. package/dist/esm/extractor/loadTamagui.js +201 -28
  29. package/dist/esm/extractor/loadTamagui.js.map +2 -2
  30. package/dist/esm/extractor/timer.js +8 -1
  31. package/dist/esm/extractor/timer.js.map +2 -2
  32. package/dist/esm/getPragmaOptions.js +44 -0
  33. package/dist/esm/getPragmaOptions.js.map +7 -0
  34. package/dist/esm/index.js +1 -0
  35. package/dist/esm/index.js.map +2 -2
  36. package/dist/esm/require.js +2 -21
  37. package/dist/esm/require.js.map +2 -2
  38. package/dist/esm/webpackPlugin.js +11 -0
  39. package/dist/esm/webpackPlugin.js.map +7 -0
  40. package/dist/jsx/extractor/createEvaluator.js.map +2 -2
  41. package/dist/jsx/extractor/createExtractor.js +1133 -1101
  42. package/dist/jsx/extractor/createExtractor.js.map +2 -2
  43. package/dist/jsx/extractor/extractToClassNames.js +4 -4
  44. package/dist/jsx/extractor/extractToClassNames.js.map +2 -2
  45. package/dist/jsx/extractor/getStaticBindingsForScope.js +17 -2
  46. package/dist/jsx/extractor/getStaticBindingsForScope.js.map +2 -2
  47. package/dist/jsx/extractor/loadTamagui.js +199 -28
  48. package/dist/jsx/extractor/loadTamagui.js.map +2 -2
  49. package/dist/jsx/extractor/timer.js +8 -1
  50. package/dist/jsx/extractor/timer.js.map +2 -2
  51. package/dist/jsx/getPragmaOptions.js +43 -0
  52. package/dist/jsx/getPragmaOptions.js.map +7 -0
  53. package/dist/jsx/index.js +1 -0
  54. package/dist/jsx/index.js.map +2 -2
  55. package/dist/jsx/require.js +2 -21
  56. package/dist/jsx/require.js.map +2 -2
  57. package/dist/jsx/webpackPlugin.js +11 -0
  58. package/dist/jsx/webpackPlugin.js.map +7 -0
  59. package/package.json +20 -17
  60. package/src/extractor/createEvaluator.ts +2 -0
  61. package/src/extractor/createExtractor.ts +1592 -1532
  62. package/src/extractor/extractToClassNames.ts +25 -10
  63. package/src/extractor/getStaticBindingsForScope.ts +22 -5
  64. package/src/extractor/loadTamagui.ts +249 -32
  65. package/src/extractor/timer.ts +12 -1
  66. package/src/getPragmaOptions.ts +52 -0
  67. package/src/index.ts +2 -0
  68. package/src/require.ts +29 -24
  69. package/src/types.ts +16 -0
  70. package/src/webpackPlugin.ts +9 -0
  71. package/types/extractor/createExtractor.d.ts +21 -17
  72. package/types/extractor/extractToClassNames.d.ts +1 -1
  73. package/types/extractor/getStaticBindingsForScope.d.ts +1 -0
  74. package/types/extractor/loadTamagui.d.ts +5 -3
  75. package/types/getPragmaOptions.d.ts +9 -0
  76. package/types/index.d.ts +1 -0
  77. package/types/types.d.ts +13 -0
  78. package/types/webpackPlugin.d.ts +4 -0
@@ -37,7 +37,7 @@ export type ExtractedResponse = {
37
37
  map: any // RawSourceMap from 'source-map'
38
38
  }
39
39
 
40
- export function extractToClassNames({
40
+ export async function extractToClassNames({
41
41
  extractor,
42
42
  source,
43
43
  sourcePath,
@@ -49,7 +49,7 @@ export function extractToClassNames({
49
49
  sourcePath: string
50
50
  options: TamaguiOptions
51
51
  shouldPrintDebug: boolean | 'verbose'
52
- }): ExtractedResponse | null {
52
+ }): Promise<ExtractedResponse | null> {
53
53
  const tm = timer()
54
54
 
55
55
  if (typeof source !== 'string') {
@@ -60,6 +60,9 @@ export function extractToClassNames({
60
60
  '`sourcePath` must be an absolute path to a .js file'
61
61
  )
62
62
 
63
+ // dont include loading in timing of parsing (one time cost)
64
+ await extractor.loadTamagui(options)
65
+
63
66
  const shouldLogTiming = options.logTimings ?? true
64
67
  const start = Date.now()
65
68
  const mem = shouldLogTiming ? process.memoryUsage() : null
@@ -70,6 +73,7 @@ export function extractToClassNames({
70
73
  try {
71
74
  ast = babelParse(source)
72
75
  } catch (err) {
76
+ // eslint-disable-next-line no-console
73
77
  console.error('babel parse error:', sourcePath)
74
78
  throw err
75
79
  }
@@ -81,7 +85,7 @@ export function extractToClassNames({
81
85
 
82
86
  let hasFlattened = false
83
87
 
84
- const res = extractor.parse(ast, {
88
+ const res = await extractor.parse(ast, {
85
89
  sourcePath,
86
90
  shouldPrintDebug,
87
91
  ...options,
@@ -213,15 +217,19 @@ export function extractToClassNames({
213
217
  const mediaExtraction = extractMediaStyle(
214
218
  attr.value,
215
219
  jsxPath,
216
- extractor.getTamagui(),
220
+ extractor.getTamagui()!,
217
221
  sourcePath,
218
222
  lastMediaImportance,
219
223
  shouldPrintDebug
220
224
  )
221
225
  if (shouldPrintDebug) {
222
226
  if (mediaExtraction) {
223
- // prettier-ignore
224
- console.log('ternary (mediaStyles)', mediaExtraction.ternaryWithoutMedia?.inlineMediaQuery ?? '', mediaExtraction.mediaStyles.map((x) => x.identifier).join('.'))
227
+ // eslint-disable-next-line no-console
228
+ console.log(
229
+ 'ternary (mediaStyles)',
230
+ mediaExtraction.ternaryWithoutMedia?.inlineMediaQuery ?? '',
231
+ mediaExtraction.mediaStyles.map((x) => x.identifier).join('.')
232
+ )
225
233
  }
226
234
  }
227
235
  if (!mediaExtraction) {
@@ -268,8 +276,11 @@ export function extractToClassNames({
268
276
  }
269
277
 
270
278
  if (shouldPrintDebug) {
271
- // prettier-ignore
272
- console.log(' finalClassNames\n', logLines(finalClassNames.map(x => x['value']).join(' ')))
279
+ // eslint-disable-next-line no-console
280
+ console.log(
281
+ ' finalClassNames\n',
282
+ logLines(finalClassNames.map((x) => x['value']).join(' '))
283
+ )
273
284
  }
274
285
 
275
286
  node.attributes = finalAttrs
@@ -350,6 +361,7 @@ export function extractToClassNames({
350
361
  }
351
362
  } else if (rules.length) {
352
363
  if (rules.length > 1) {
364
+ // eslint-disable-next-line no-console
353
365
  console.log(' rules error', { rules })
354
366
  throw new Error(`Shouldn't have more than one rule`)
355
367
  }
@@ -364,6 +376,7 @@ export function extractToClassNames({
364
376
 
365
377
  if (!res || (!res.modified && !res.optimized && !res.flattened && !res.styled)) {
366
378
  if (shouldPrintDebug) {
379
+ // eslint-disable-next-line no-console
367
380
  console.log('no res or none modified', res)
368
381
  }
369
382
  return null
@@ -388,6 +401,7 @@ export function extractToClassNames({
388
401
  )
389
402
 
390
403
  if (shouldPrintDebug) {
404
+ // eslint-disable-next-line no-console
391
405
  console.log(
392
406
  '\n -------- output code ------- \n\n',
393
407
  result.code
@@ -395,6 +409,7 @@ export function extractToClassNames({
395
409
  .filter((x) => !x.startsWith('//'))
396
410
  .join('\n')
397
411
  )
412
+ // eslint-disable-next-line no-console
398
413
  console.log('\n -------- output style -------- \n\n', styles)
399
414
  }
400
415
 
@@ -414,10 +429,10 @@ export function extractToClassNames({
414
429
  const numFlattened = `${res.flattened}`.padStart(3)
415
430
  const memory = process.env.DEBUG && memUsed > 10 ? ` ${memUsed}MB` : ''
416
431
  const timing = Date.now() - start
417
- const timingWarning = timing > 150 ? '⚠️' : timing > 150 ? '☢️' : ''
418
- const timingStr = `${timing}ms ${timingWarning}`.padStart(6)
432
+ const timingStr = `${timing}ms`.padStart(6)
419
433
  const pre = getPrefixLogs(options)
420
434
  const memStr = memory ? `(${memory})` : ''
435
+ // eslint-disable-next-line no-console
421
436
  console.log(
422
437
  `${pre} ${path} ${numFound} · ${numOptimized} · ${numFlattened} · ${numStyled} ${timingStr} ${memStr}`
423
438
  )
@@ -1,10 +1,8 @@
1
- import { fork, spawn } from 'child_process'
1
+ import { fork } from 'child_process'
2
2
  import { dirname, extname, join, resolve } from 'path'
3
3
 
4
4
  import { Binding, NodePath } from '@babel/traverse'
5
5
  import * as t from '@babel/types'
6
- import esbuild from 'esbuild'
7
- import { existsSync } from 'fs-extra'
8
6
 
9
7
  import { evaluateAstNode } from './evaluateAstNode'
10
8
  import { getSourceModule } from './getSourceModule'
@@ -31,10 +29,27 @@ setInterval(() => {
31
29
  }, 10)
32
30
 
33
31
  const loadCmd = `${join(__dirname, 'loadFile.js')}`
32
+
33
+ let exited = false
34
34
  const child = fork(loadCmd, [], {
35
35
  execArgv: ['-r', 'esbuild-register'],
36
+ detached: true,
37
+ stdio: 'ignore',
36
38
  })
37
39
 
40
+ export function cleanupBeforeExit() {
41
+ if (exited) return
42
+ child.removeAllListeners()
43
+ child.unref()
44
+ child.disconnect()
45
+ child.kill()
46
+ exited = true
47
+ }
48
+
49
+ process.once('SIGTERM', cleanupBeforeExit)
50
+ process.once('SIGINT', cleanupBeforeExit)
51
+ process.once('beforeExit', cleanupBeforeExit)
52
+
38
53
  function importModule(path: string) {
39
54
  if (pending.has(path)) {
40
55
  return pending.get(path)
@@ -72,9 +87,11 @@ export async function getStaticBindingsForScope(
72
87
  const bindings: Record<string, Binding> = scope.getAllBindings() as any
73
88
  const ret: Record<string, any> = {}
74
89
 
75
- if (shouldPrintDebug) {
90
+ if (
91
+ shouldPrintDebug
92
+ ) {
76
93
  // prettier-ignore
77
- console.log(' ', Object.keys(bindings).length, 'variables in scope')
94
+ // console.log(' ', Object.keys(bindings).length, 'variables in scope')
78
95
  // .map(x => bindings[x].identifier?.name).join(', ')
79
96
  }
80
97
 
@@ -1,15 +1,15 @@
1
1
  /* eslint-disable no-console */
2
- import { join } from 'path'
2
+ import { basename, dirname, join, sep } from 'path'
3
3
 
4
4
  import { getDefaultTamaguiConfig } from '@tamagui/config-default-node'
5
5
  import type { StaticConfig, TamaguiComponent, TamaguiInternalConfig } from '@tamagui/core-node'
6
6
  import { createTamagui } from '@tamagui/core-node'
7
+ import esbuild from 'esbuild'
8
+ import { ensureDir, pathExists, remove, stat, writeFile } from 'fs-extra'
7
9
 
8
10
  import { SHOULD_DEBUG } from '../constants'
9
11
  import { getNameToPaths, registerRequire, unregisterRequire } from '../require'
10
12
 
11
- let loadedTamagui: any = null
12
-
13
13
  type NameToPaths = {
14
14
  [key: string]: Set<string>
15
15
  }
@@ -20,12 +20,177 @@ export type TamaguiProjectInfo = {
20
20
  nameToPaths: NameToPaths
21
21
  }
22
22
 
23
- export function loadTamagui(props: { components: string[]; config: string }): TamaguiProjectInfo {
24
- if (loadedTamagui) {
25
- return loadedTamagui
23
+ type Props = { components: string[]; config?: string }
24
+
25
+ const cache = {}
26
+
27
+ // TODO needs a plugin for webpack / vite to run this once at startup and not again until changed...
28
+
29
+ export async function loadTamagui(props: Props): Promise<TamaguiProjectInfo> {
30
+ const key = JSON.stringify(props)
31
+ if (cache[key]) {
32
+ if (cache[key] instanceof Promise) {
33
+ return await cache[key]
34
+ }
35
+ return cache[key]
36
+ }
37
+
38
+ let resolver: Function = () => {}
39
+ cache[key] = new Promise((res) => {
40
+ resolver = res
41
+ })
42
+
43
+ const tmpDir = join(process.cwd(), 'dist', 'tamagui-node')
44
+ const configOutPath = join(tmpDir, `tamagui.config.js`)
45
+ const includesCore = props.components.includes('@tamagui/core')
46
+ const baseComponents = props.components.filter((x) => x !== '@tamagui/core')
47
+ const componentOutPaths = baseComponents.map((componentModule) =>
48
+ join(
49
+ tmpDir,
50
+ `${componentModule
51
+ .split(sep)
52
+ .join('-')
53
+ .replace(/[^a-z0-9]+/gi, '')}-components.config.js`
54
+ )
55
+ )
56
+
57
+ const external = ['@tamagui/core', '@tamagui/core-node', 'react', 'react-dom']
58
+ const configEntry = props.config ? join(process.cwd(), props.config) : ''
59
+
60
+ if (process.env.DEBUG?.startsWith('tamagui')) {
61
+ console.log(`Building config entry`, configEntry)
62
+ }
63
+
64
+ // build them to node-compat versions
65
+ try {
66
+ await ensureDir(tmpDir)
67
+ } catch {
68
+ //
69
+ }
70
+
71
+ await Promise.all([
72
+ props.config
73
+ ? buildTamaguiConfig({
74
+ entryPoints: [configEntry],
75
+ external,
76
+ outfile: configOutPath,
77
+ })
78
+ : null,
79
+ ...baseComponents.map((componentModule, i) => {
80
+ return buildTamaguiConfig({
81
+ entryPoints: [componentModule],
82
+ external,
83
+ outfile: componentOutPaths[i],
84
+ })
85
+ }),
86
+ ])
87
+
88
+ if (process.env.DEBUG?.startsWith('tamagui')) {
89
+ console.log(`Built configs`)
90
+ }
91
+
92
+ const coreNode = require('@tamagui/core-node')
93
+
94
+ registerRequire()
95
+ const config = require(configOutPath).default
96
+ unregisterRequire()
97
+
98
+ const components = {
99
+ ...loadComponents(componentOutPaths),
100
+ ...(includesCore && gatherTamaguiComponentInfo([coreNode])),
101
+ }
102
+
103
+ cache[key] = {
104
+ components,
105
+ nameToPaths: {},
106
+ tamaguiConfig: config,
26
107
  }
27
108
 
28
- const configPath = join(process.cwd(), props.config)
109
+ // init core-node
110
+ createTamagui(cache[key].tamaguiConfig)
111
+
112
+ resolver(cache[key])
113
+
114
+ return cache[key]
115
+ }
116
+
117
+ async function buildTamaguiConfig(
118
+ options: Partial<esbuild.BuildOptions> & { outfile: string },
119
+ aliases?: Record<string, string>
120
+ ) {
121
+ const alias = require('@tamagui/core-node').aliasPlugin
122
+ // until i do fancier things w plugins:
123
+ const lockFile = join(dirname(options.outfile), basename(options.outfile, '.lock'))
124
+ const lockStat = await stat(lockFile).catch(() => {
125
+ // ok
126
+ })
127
+ const lockedMsAgo = !lockStat
128
+ ? Infinity
129
+ : new Date().getTime() - new Date(lockStat.mtime).getTime()
130
+ if (lockedMsAgo < 500) {
131
+ if (process.env.DEBUG?.startsWith('tamagui')) {
132
+ console.log(`Waiting for existing build`, options.entryPoints)
133
+ }
134
+ let tries = 5
135
+ while (tries--) {
136
+ if (await pathExists(options.outfile)) {
137
+ return
138
+ } else {
139
+ await new Promise((res) => setTimeout(res, 50))
140
+ }
141
+ }
142
+ }
143
+ writeFile(lockFile, '')
144
+ if (process.env.DEBUG?.startsWith('tamagui')) {
145
+ console.log(`Building`, options.entryPoints)
146
+ }
147
+ return esbuild.build({
148
+ bundle: true,
149
+ ...options,
150
+ format: 'cjs',
151
+ target: 'node18',
152
+ keepNames: true,
153
+ platform: 'node',
154
+ loader: {
155
+ '.js': 'jsx',
156
+ },
157
+ allowOverwrite: true,
158
+ logLevel: 'warning',
159
+ plugins: [
160
+ {
161
+ name: 'external',
162
+ setup(build) {
163
+ build.onResolve({ filter: /@tamagui\/core/ }, (args) => {
164
+ return {
165
+ path: '@tamagui/core-node',
166
+ external: true,
167
+ }
168
+ })
169
+
170
+ build.onResolve({ filter: /^(react-native)$/ }, (args) => {
171
+ return {
172
+ path: 'react-native-web-lite',
173
+ external: true,
174
+ }
175
+ })
176
+ },
177
+ },
178
+ alias({
179
+ 'react-native-svg': require.resolve('react-native-svg-web'),
180
+ 'react-native-safe-area-context': require.resolve('@tamagui/fake-react-native'),
181
+ 'react-native-gesture-handler': require.resolve('@tamagui/proxy-worm'),
182
+ ...aliases,
183
+ }),
184
+ ],
185
+ })
186
+ }
187
+
188
+ // loads in-process using esbuild-register
189
+ export function loadTamaguiSync(props: Props): TamaguiProjectInfo {
190
+ const key = JSON.stringify(props)
191
+ if (cache[key]) {
192
+ return cache[key]
193
+ }
29
194
 
30
195
  const { unregister } = require('esbuild-register/dist/node').register({
31
196
  target: 'es2019',
@@ -33,6 +198,8 @@ export function loadTamagui(props: { components: string[]; config: string }): Ta
33
198
  })
34
199
 
35
200
  try {
201
+ registerRequire()
202
+
36
203
  // lets shim require and avoid importing react-native + react-native-web
37
204
  // we just need to read the config around them
38
205
  process.env.IS_STATIC = 'is_static'
@@ -42,41 +209,31 @@ export function loadTamagui(props: { components: string[]; config: string }): Ta
42
209
  globalThis['__DEV__'] = process.env.NODE_ENV === 'development'
43
210
  }
44
211
 
45
- registerRequire()
46
-
47
212
  try {
48
213
  // import config
49
- const exp = require(configPath)
50
- const tamaguiConfig = (exp['default'] || exp) as TamaguiInternalConfig
51
-
52
- if (!tamaguiConfig || !tamaguiConfig.parsed) {
53
- const confPath = require.resolve(configPath)
54
- console.log(`Received:`, tamaguiConfig)
55
- throw new Error(`Can't find valid config in ${confPath}`)
56
- }
214
+ let tamaguiConfig: TamaguiInternalConfig | null = null
57
215
 
58
- // import components
59
- const components = {}
60
- for (const moduleName of props.components) {
61
- const exported = require(moduleName)
62
- for (const Name in exported) {
63
- const val = exported[Name]
64
- const staticConfig = val?.staticConfig as StaticConfig | undefined
65
- if (staticConfig) {
66
- // remove non-stringifyable
67
- const { Component, reactNativeWebComponent, ...sc } = staticConfig
68
- Object.assign(components, { [Name]: { staticConfig: sc } })
69
- }
216
+ if (props.config) {
217
+ const configPath = join(process.cwd(), props.config)
218
+ const exp = require(configPath)
219
+ tamaguiConfig = (exp['default'] || exp) as TamaguiInternalConfig
220
+ if (!tamaguiConfig || !tamaguiConfig.parsed) {
221
+ const confPath = require.resolve(configPath)
222
+ throw new Error(`Can't find valid config in ${confPath}`)
70
223
  }
71
224
  }
72
225
 
226
+ const components = loadComponents(props.components)
227
+
73
228
  // undo shims
74
229
  process.env.IS_STATIC = undefined
75
230
 
76
231
  // set up core-node
77
- createTamagui(tamaguiConfig as any)
232
+ if (tamaguiConfig) {
233
+ createTamagui(tamaguiConfig)
234
+ }
78
235
 
79
- loadedTamagui = {
236
+ cache[key] = {
80
237
  components,
81
238
  tamaguiConfig,
82
239
  nameToPaths: getNameToPaths(),
@@ -100,7 +257,7 @@ export function loadTamagui(props: { components: string[]; config: string }): Ta
100
257
  }
101
258
  }
102
259
 
103
- return loadedTamagui
260
+ return cache[key]
104
261
  } catch (err) {
105
262
  console.log('Error loading Tamagui', err)
106
263
  throw err
@@ -109,3 +266,63 @@ export function loadTamagui(props: { components: string[]; config: string }): Ta
109
266
  unregisterRequire()
110
267
  }
111
268
  }
269
+
270
+ function interopDefaultExport(mod: any) {
271
+ return mod?.default ?? mod
272
+ }
273
+
274
+ const cacheComponents = {}
275
+
276
+ function loadComponents(componentsModules: string[]) {
277
+ const key = componentsModules.join('')
278
+ if (cacheComponents[key]) {
279
+ return cacheComponents[key]
280
+ }
281
+ try {
282
+ const requiredModules = componentsModules.map((name) => {
283
+ return interopDefaultExport(require(name))
284
+ })
285
+ const res = gatherTamaguiComponentInfo(requiredModules)
286
+ cacheComponents[key] = res
287
+ return res
288
+ } catch (err: any) {
289
+ console.log(`Tamagui error bundling components`, err.message, err.stack)
290
+ }
291
+ }
292
+
293
+ function gatherTamaguiComponentInfo(packages: any[]) {
294
+ const components = {}
295
+ for (const exported of packages) {
296
+ try {
297
+ for (const componentName in exported) {
298
+ const found = getTamaguiComponent(componentName, exported[componentName])
299
+ if (found) {
300
+ // remove non-stringifyable
301
+ const { Component, reactNativeWebComponent, ...sc } = found.staticConfig
302
+ Object.assign(components, { [componentName]: { staticConfig: sc } })
303
+ }
304
+ }
305
+ } catch (err) {
306
+ console.error(`Tamagui failed getting components`)
307
+ if (err instanceof Error) {
308
+ console.error(err.message, err.stack)
309
+ } else {
310
+ console.error(err)
311
+ }
312
+ }
313
+ }
314
+ return components
315
+ }
316
+
317
+ function getTamaguiComponent(
318
+ name: string,
319
+ Component: any
320
+ ): undefined | { staticConfig: StaticConfig } {
321
+ if (name[0].toUpperCase() !== name[0]) {
322
+ return
323
+ }
324
+ const staticConfig = Component?.staticConfig as StaticConfig | undefined
325
+ if (staticConfig) {
326
+ return Component
327
+ }
328
+ }
@@ -6,12 +6,23 @@ export const timer = () => {
6
6
  if (print) {
7
7
  const took = Date.now() - last
8
8
  last = Date.now()
9
+ // eslint-disable-next-line no-console
9
10
  console.log(`Time ${name}: ${took}ms`)
11
+ if (took > 10) {
12
+ // eslint-disable-next-line no-console
13
+ console.log(' long timer')
14
+ }
10
15
  }
11
16
  },
12
17
  done: (print = false) => {
13
18
  if (print) {
14
- console.log(`Total time: ${Date.now() - start}ms`)
19
+ const total = Date.now() - start
20
+ // eslint-disable-next-line no-console
21
+ console.log(`Total time: ${total}ms`)
22
+ if (total > 50) {
23
+ // eslint-disable-next-line no-console
24
+ console.log(' long timer')
25
+ }
15
26
  }
16
27
  },
17
28
  }
@@ -0,0 +1,52 @@
1
+ export function getPragmaOptions({
2
+ source,
3
+ path,
4
+ disableCommentCheck,
5
+ }: {
6
+ source: string
7
+ path: string
8
+ disableCommentCheck?: boolean
9
+ }) {
10
+ if (!disableCommentCheck && !source.startsWith('//') && !source.startsWith('/*')) {
11
+ return {
12
+ shouldPrintDebug: false,
13
+ shouldDisable: false,
14
+ }
15
+ }
16
+
17
+ let shouldPrintDebug: boolean | 'verbose' = false
18
+ let shouldDisable = false
19
+
20
+ const firstLine = source.split('\n', 1)[0]
21
+
22
+ if (firstLine.includes('tamagui-ignore')) {
23
+ shouldDisable = true
24
+ }
25
+
26
+ if (firstLine.includes('debug')) {
27
+ shouldPrintDebug = true
28
+ }
29
+
30
+ if (firstLine.includes('debug-verbose')) {
31
+ shouldPrintDebug = 'verbose'
32
+ }
33
+
34
+ if (process.env.TAMAGUI_DEBUG_FILE) {
35
+ if (path.includes(process.env.TAMAGUI_DEBUG_FILE)) {
36
+ shouldPrintDebug = 'verbose'
37
+ }
38
+ }
39
+
40
+ if (process.env.DEBUG?.includes('tamagui')) {
41
+ shouldPrintDebug = true
42
+ }
43
+
44
+ if (process.env.DEBUG?.includes('tamagui-verbose')) {
45
+ shouldPrintDebug = 'verbose'
46
+ }
47
+
48
+ return {
49
+ shouldPrintDebug,
50
+ shouldDisable,
51
+ }
52
+ }
package/src/index.ts CHANGED
@@ -9,3 +9,5 @@ export * from './extractor/extractHelpers'
9
9
  export * from '@tamagui/patch-rnw'
10
10
  export * from './extractor/loadTamagui'
11
11
  export * from './require'
12
+ export * from './getPragmaOptions'
13
+ // export * from './webpackPlugin'
package/src/require.ts CHANGED
@@ -19,17 +19,20 @@ setInterval(() => {
19
19
 
20
20
  export function registerRequire() {
21
21
  if (Module.prototype.require !== globalThis['ogRequire']) {
22
+ // eslint-disable-next-line no-console
22
23
  console.warn('didnt unregister before re-registering')
23
24
  process.exit(1)
24
25
  }
25
26
 
26
27
  const proxyWorm = require('@tamagui/proxy-worm')
28
+ // TODO can swap with react-native-web-lite
27
29
  const rnw = require('react-native-web')
28
30
  const core = require('@tamagui/core-node')
29
31
 
30
32
  Module.prototype.require = function (path: string) {
31
33
  if (SHOULD_DEBUG) {
32
- console.log('tamagui require', path)
34
+ // eslint-disable-next-line no-console
35
+ console.log('tamagui:require', path)
33
36
  }
34
37
  if (path.endsWith('.css') || path.endsWith('.json') || path.endsWith('.ttf')) {
35
38
  return {}
@@ -48,38 +51,39 @@ export function registerRequire() {
48
51
  !path.startsWith('react-native-web/dist/cjs/exports'.replace(/\//g, sep))
49
52
  ) {
50
53
  return rnw
51
- // return og('react-native-web')
52
54
  }
53
55
  if (path === '@tamagui/core') {
54
56
  return core
55
57
  }
56
58
  try {
57
59
  const out = og.apply(this, arguments)
58
- if (!nameToPaths[path]) {
59
- if (out && typeof out === 'object') {
60
- for (const key in out) {
61
- try {
62
- const conf = out[key]?.staticConfig as StaticConfig
63
- if (conf) {
64
- if (conf.componentName) {
65
- nameToPaths[conf.componentName] ??= new Set()
66
- const fullName = path.startsWith('.')
67
- ? join(`${this.path.replace(/dist(\/cjs)?/, 'src')}`, path)
68
- : path
69
- nameToPaths[conf.componentName].add(fullName)
70
- } else {
71
- // console.log('no name component', path)
72
- }
73
- }
74
- } catch {
75
- // ok
76
- }
77
- }
78
- }
79
- }
60
+ // only for studio disable for now
61
+ // if (!nameToPaths[path]) {
62
+ // if (out && typeof out === 'object') {
63
+ // for (const key in out) {
64
+ // try {
65
+ // const conf = out[key]?.staticConfig as StaticConfig
66
+ // if (conf) {
67
+ // if (conf.componentName) {
68
+ // nameToPaths[conf.componentName] ??= new Set()
69
+ // const fullName = path.startsWith('.')
70
+ // ? join(`${this.path.replace(/dist(\/cjs)?/, 'src')}`, path)
71
+ // : path
72
+ // nameToPaths[conf.componentName].add(fullName)
73
+ // } else {
74
+ // // console.log('no name component', path)
75
+ // }
76
+ // }
77
+ // } catch {
78
+ // // ok
79
+ // }
80
+ // }
81
+ // }
82
+ // }
80
83
  return out
81
84
  } catch (err: any) {
82
85
  if (SHOULD_DEBUG) {
86
+ // eslint-disable-next-line no-console
83
87
  console.error(
84
88
  `Tamagui failed requiring ${path} from your tamagui.config.ts file, ignoring\n`,
85
89
  err.message,
@@ -88,6 +92,7 @@ export function registerRequire() {
88
92
  }
89
93
  const max = process.env.TAMAGUI_MAX_ERRORS ? +process.env.TAMAGUI_MAX_ERRORS : 200
90
94
  if (++tries > max) {
95
+ // eslint-disable-next-line no-console
91
96
  console.log(
92
97
  `Too many errors loading design system, exiting (set TAMAGUI_MAX_ERRORS to override)..`
93
98
  )