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

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 (44) hide show
  1. package/dist/extractor/babelParse.js.map +2 -2
  2. package/dist/extractor/bundle.js +117 -0
  3. package/dist/extractor/bundle.js.map +7 -0
  4. package/dist/extractor/createExtractor.js +147 -79
  5. package/dist/extractor/createExtractor.js.map +3 -3
  6. package/dist/extractor/extractHelpers.js +41 -6
  7. package/dist/extractor/extractHelpers.js.map +2 -2
  8. package/dist/extractor/extractToClassNames.js +2 -1
  9. package/dist/extractor/extractToClassNames.js.map +2 -2
  10. package/dist/extractor/getPropValueFromAttributes.js.map +2 -2
  11. package/dist/extractor/loadTamagui.js +219 -117
  12. package/dist/extractor/loadTamagui.js.map +3 -3
  13. package/dist/extractor/normalizeTernaries.js.map +2 -2
  14. package/dist/getPragmaOptions.js +1 -1
  15. package/dist/getPragmaOptions.js.map +2 -2
  16. package/dist/index.js +0 -1
  17. package/dist/index.js.map +2 -2
  18. package/dist/require.js +13 -7
  19. package/dist/require.js.map +2 -2
  20. package/dist/tamagui-node/tamagui.config.js +6781 -0
  21. package/dist/tamagui-node/tamaguicore-components.config.js +0 -0
  22. package/dist/tamagui-node/tamaguitestdesignsystem-components.config.js +31 -0
  23. package/dist/types.js.map +1 -1
  24. package/package.json +20 -17
  25. package/src/extractor/babelParse.ts +3 -2
  26. package/src/extractor/bundle.ts +110 -0
  27. package/src/extractor/createExtractor.ts +167 -70
  28. package/src/extractor/extractHelpers.ts +57 -10
  29. package/src/extractor/extractToClassNames.ts +12 -9
  30. package/src/extractor/getPropValueFromAttributes.ts +1 -1
  31. package/src/extractor/loadTamagui.ts +256 -145
  32. package/src/extractor/normalizeTernaries.ts +1 -1
  33. package/src/getPragmaOptions.ts +2 -1
  34. package/src/index.ts +0 -1
  35. package/src/require.ts +16 -8
  36. package/src/types.ts +5 -1
  37. package/types/extractor/babelParse.d.ts +2 -1
  38. package/types/extractor/bundle.d.ts +13 -0
  39. package/types/extractor/extractHelpers.d.ts +13 -3
  40. package/types/extractor/extractToClassNames.d.ts +3 -2
  41. package/types/extractor/findTopmostFunction.d.ts +1 -1
  42. package/types/extractor/loadTamagui.d.ts +9 -2
  43. package/types/index.d.ts +0 -1
  44. package/types/types.d.ts +4 -1
@@ -1,22 +1,38 @@
1
+ import { readFileSync } from 'fs'
1
2
  /* eslint-disable no-console */
2
- import { basename, dirname, join, relative, sep } from 'path'
3
+ import { basename, dirname, extname, join, relative, sep } from 'path'
3
4
 
5
+ import generate from '@babel/generator'
6
+ import traverse from '@babel/traverse'
7
+ import * as t from '@babel/types'
4
8
  import { Color, colorLog } from '@tamagui/cli-color'
5
9
  import { getDefaultTamaguiConfig } from '@tamagui/config-default-node'
6
- import type { StaticConfig, TamaguiComponent, TamaguiInternalConfig } from '@tamagui/core-node'
10
+ import type { StaticConfigParsed, TamaguiInternalConfig } from '@tamagui/core-node'
7
11
  import { createTamagui } from '@tamagui/core-node'
8
12
  import esbuild from 'esbuild'
9
- import { ensureDir, pathExists, stat, writeFile } from 'fs-extra'
13
+ import { ensureDir, existsSync, removeSync, writeFileSync } from 'fs-extra'
10
14
 
11
15
  import { SHOULD_DEBUG } from '../constants.js'
12
16
  import { getNameToPaths, registerRequire, unregisterRequire } from '../require.js'
17
+ import { babelParse } from './babelParse'
18
+ import { bundle } from './bundle'
13
19
 
14
20
  type NameToPaths = {
15
21
  [key: string]: Set<string>
16
22
  }
17
23
 
24
+ export type LoadedComponents = {
25
+ moduleName: string
26
+ nameToInfo: Record<
27
+ string,
28
+ {
29
+ staticConfig: StaticConfigParsed
30
+ }
31
+ >
32
+ }
33
+
18
34
  export type TamaguiProjectInfo = {
19
- components: Record<string, TamaguiComponent>
35
+ components: LoadedComponents[]
20
36
  tamaguiConfig: TamaguiInternalConfig
21
37
  nameToPaths: NameToPaths
22
38
  }
@@ -46,9 +62,8 @@ export async function loadTamagui(props: Props): Promise<TamaguiProjectInfo> {
46
62
  resolver = res
47
63
  })
48
64
 
49
- const tmpDir = join(process.cwd(), 'dist', 'tamagui-node')
65
+ const tmpDir = join(process.cwd(), '.tamagui', 'tamagui-node')
50
66
  const configOutPath = join(tmpDir, `tamagui.config.js`)
51
- const includesCore = props.components.includes('@tamagui/core')
52
67
  const baseComponents = props.components.filter((x) => x !== '@tamagui/core')
53
68
  const componentOutPaths = baseComponents.map((componentModule) =>
54
69
  join(
@@ -89,139 +104,98 @@ Tamagui built config and components:`
89
104
 
90
105
  await Promise.all([
91
106
  props.config
92
- ? buildTamaguiConfig(props, {
107
+ ? bundle({
93
108
  entryPoints: [configEntry],
94
109
  external,
95
110
  outfile: configOutPath,
96
111
  })
97
112
  : null,
98
113
  ...baseComponents.map((componentModule, i) => {
99
- return buildTamaguiConfig(props, {
114
+ return bundle({
100
115
  entryPoints: [componentModule],
116
+ resolvePlatformSpecificEntries: true,
101
117
  external,
102
118
  outfile: componentOutPaths[i],
103
119
  })
104
120
  }),
105
121
  ])
106
122
 
107
- const coreNode = require('@tamagui/core-node')
123
+ try {
124
+ registerRequire(props.bubbleErrors)
125
+ const out = require(configOutPath)
126
+ const config = out.default || out
108
127
 
109
- registerRequire(props.bubbleErrors)
110
- const config = require(configOutPath).default
111
- unregisterRequire()
128
+ if (!config) {
129
+ throw new Error(`No config: ${config}`)
130
+ }
112
131
 
113
- const components = {
114
- ...loadComponents({
132
+ let components = loadComponents({
115
133
  ...props,
116
134
  components: componentOutPaths,
117
- }),
118
- ...(includesCore && gatherTamaguiComponentInfo([coreNode])),
119
- }
120
-
121
- if (process.env.NODE_ENV === 'development' && process.env.DEBUG?.startsWith('tamagui')) {
122
- console.log('Loaded components', components)
123
- }
124
-
125
- cache[key] = {
126
- components,
127
- nameToPaths: {},
128
- tamaguiConfig: config,
129
- }
135
+ })
130
136
 
131
- // init core-node
132
- createTamagui(cache[key].tamaguiConfig)
137
+ if (!components) {
138
+ throw new Error(`No components found: ${componentOutPaths.join(', ')}`)
139
+ }
133
140
 
134
- resolver(cache[key])
141
+ // map from built back to original module names
142
+ for (const component of components) {
143
+ component.moduleName = baseComponents[componentOutPaths.indexOf(component.moduleName)]
144
+ if (!component.moduleName) {
145
+ throw new Error(`Tamagui internal err`)
146
+ }
147
+ }
135
148
 
136
- return cache[key]
137
- }
149
+ // always load core so we can optimize if directly importing
150
+ const coreComponents = loadComponents({
151
+ ...props,
152
+ components: ['@tamagui/core-node'],
153
+ })
154
+ if (coreComponents) {
155
+ coreComponents[0].moduleName = '@tamagui/core'
156
+ components = [...components, ...coreComponents]
157
+ }
138
158
 
139
- async function buildTamaguiConfig(
140
- props: Props,
141
- options: Partial<esbuild.BuildOptions> & { outfile: string },
142
- aliases?: Record<string, string>
143
- ) {
144
- const alias = require('@tamagui/core-node').aliasPlugin
145
- // until i do fancier things w plugins:
146
- const lockFile = join(dirname(options.outfile), basename(options.outfile, '.lock'))
147
- const lockStat = await stat(lockFile).catch(() => {
148
- // ok
149
- })
150
- const lockedMsAgo = !lockStat
151
- ? Infinity
152
- : new Date().getTime() - new Date(lockStat.mtime).getTime()
153
- if (lockedMsAgo < 500) {
154
- if (process.env.DEBUG?.startsWith('tamagui')) {
155
- console.log(`Waiting for existing build`, options.entryPoints)
159
+ if (process.env.NODE_ENV === 'development' && process.env.DEBUG?.startsWith('tamagui')) {
160
+ console.log('Loaded components', components)
156
161
  }
157
- let tries = 5
158
- while (tries--) {
159
- if (await pathExists(options.outfile)) {
160
- return
161
- } else {
162
- await new Promise((res) => setTimeout(res, 50))
163
- }
162
+
163
+ cache[key] = {
164
+ components,
165
+ nameToPaths: {},
166
+ tamaguiConfig: config,
164
167
  }
165
- }
166
168
 
167
- void writeFile(lockFile, '')
169
+ // init core-node
170
+ createTamagui(cache[key].tamaguiConfig)
168
171
 
169
- if (process.env.DEBUG?.startsWith('tamagui')) {
170
- console.log(`Building`, options.entryPoints)
172
+ resolver(cache[key])
173
+
174
+ return cache[key]
175
+ } finally {
176
+ unregisterRequire()
171
177
  }
178
+ }
172
179
 
173
- const tsconfig = join(__dirname, '..', '..', 'tamagui.tsconfig.json')
174
-
175
- return esbuild.build({
176
- bundle: true,
177
- ...options,
178
- format: 'cjs',
179
- target: 'node18',
180
- jsx: 'transform',
181
- jsxFactory: 'react',
182
- allowOverwrite: true,
183
- keepNames: true,
184
- platform: 'node',
185
- tsconfig,
186
- loader: {
187
- '.js': 'jsx',
188
- },
189
- logLevel: 'warning',
190
- plugins: [
191
- {
192
- name: 'external',
193
- setup(build) {
194
- build.onResolve({ filter: /@tamagui\/core/ }, (args) => {
195
- return {
196
- path: '@tamagui/core-node',
197
- external: true,
198
- }
199
- })
200
-
201
- build.onResolve({ filter: /^(react-native|react-native\/.*)$/ }, (args) => {
202
- return {
203
- path: 'react-native-web-lite',
204
- external: true,
205
- }
206
- })
207
- },
208
- },
209
- alias({
210
- 'react-native-svg': require.resolve('@tamagui/react-native-svg'),
211
- 'react-native-safe-area-context': require.resolve('@tamagui/fake-react-native'),
212
- 'react-native-gesture-handler': require.resolve('@tamagui/proxy-worm'),
213
- 'react-native-reanimated': require.resolve('@tamagui/proxy-worm'),
214
- ...aliases,
215
- }),
216
- ],
217
- })
180
+ export function resolveWebOrNativeSpecificEntry(entry: string) {
181
+ const resolved = require.resolve(entry)
182
+ const ext = extname(resolved)
183
+ const fileName = basename(resolved).replace(ext, '')
184
+ const specificExt = process.env.TAMAGUI_TARGET === 'web' ? 'web' : 'native'
185
+ const specificFile = join(dirname(resolved), fileName + '.' + specificExt + ext)
186
+ if (existsSync(specificFile)) {
187
+ return specificFile
188
+ }
189
+ return entry
218
190
  }
219
191
 
220
- const esbuildOptions: esbuild.BuildOptions = {
221
- target: 'es2019',
192
+ const esbuildOptions = {
193
+ loader: 'tsx',
194
+ target: 'es2018',
222
195
  format: 'cjs',
223
196
  jsx: 'transform',
224
- }
197
+ platform: 'node',
198
+ } as const
225
199
 
226
200
  // loads in-process using esbuild-register
227
201
  export function loadTamaguiSync(props: Props): TamaguiProjectInfo {
@@ -238,16 +212,11 @@ export function loadTamaguiSync(props: Props): TamaguiProjectInfo {
238
212
  // lets shim require and avoid importing react-native + react-native-web
239
213
  // we just need to read the config around them
240
214
  process.env.IS_STATIC = 'is_static'
241
- // @ts-ignore
242
- if (typeof globalThis['__DEV__'] === 'undefined') {
243
- // @ts-ignore
244
- globalThis['__DEV__'] = process.env.NODE_ENV === 'development'
245
- }
215
+ globalThis['__DEV__' as any] = process.env.NODE_ENV === 'development'
246
216
 
247
217
  try {
248
- // import config
218
+ // config
249
219
  let tamaguiConfig: TamaguiInternalConfig | null = null
250
-
251
220
  if (props.config) {
252
221
  const configPath = join(process.cwd(), props.config)
253
222
  const exp = require(configPath)
@@ -260,17 +229,21 @@ export function loadTamaguiSync(props: Props): TamaguiProjectInfo {
260
229
  }
261
230
  }
262
231
 
232
+ // components
263
233
  const components = loadComponents(props)
264
-
234
+ if (!components) {
235
+ throw new Error(`No components loaded`)
236
+ }
265
237
  if (process.env.DEBUG === 'tamagui') {
266
238
  console.log(`components`, components)
267
239
  }
268
240
 
269
241
  // undo shims
270
242
  process.env.IS_STATIC = undefined
243
+ delete globalThis['__DEV__' as any]
271
244
 
272
245
  // set up core-node
273
- if (tamaguiConfig) {
246
+ if (props.config && tamaguiConfig) {
274
247
  createTamagui(tamaguiConfig as any)
275
248
  }
276
249
 
@@ -296,7 +269,7 @@ export function loadTamaguiSync(props: Props): TamaguiProjectInfo {
296
269
  console.error(`Error loading tamagui.config.ts`, err)
297
270
  }
298
271
  return {
299
- components: {},
272
+ components: [],
300
273
  tamaguiConfig: getDefaultTamaguiConfig(),
301
274
  nameToPaths: {},
302
275
  }
@@ -318,49 +291,187 @@ function interopDefaultExport(mod: any) {
318
291
  return mod?.default ?? mod
319
292
  }
320
293
 
321
- const cacheComponents = {}
294
+ const cacheComponents: Record<string, LoadedComponents[]> = {}
295
+
296
+ function transformAddExports(ast: t.File) {
297
+ const usedNames = new Set<string>()
298
+
299
+ // avoid clobbering
300
+ traverse(ast, {
301
+ ExportNamedDeclaration(nodePath) {
302
+ if (nodePath.node.specifiers) {
303
+ for (const spec of nodePath.node.specifiers) {
304
+ usedNames.add(t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value)
305
+ }
306
+ }
307
+ },
308
+ })
309
+
310
+ traverse(ast, {
311
+ VariableDeclaration(nodePath) {
312
+ // top level only
313
+ if (!t.isProgram(nodePath.parent)) return
314
+ const decs = nodePath.node.declarations
315
+ if (decs.length > 1) return
316
+ const [dec] = decs
317
+ if (!t.isIdentifier(dec.id)) return
318
+ if (!dec.init) return
319
+ if (usedNames.has(dec.id.name)) return
320
+ usedNames.add(dec.id.name)
321
+ nodePath.replaceWith(
322
+ t.exportNamedDeclaration(t.variableDeclaration('let', [dec]), [
323
+ t.exportSpecifier(t.identifier(dec.id.name), t.identifier(dec.id.name)),
324
+ ])
325
+ )
326
+ },
327
+ })
322
328
 
323
- function loadComponents(props: Props) {
329
+ return generate(ast as any, {
330
+ concise: false,
331
+ filename: 'test.tsx',
332
+ retainLines: false,
333
+ sourceMaps: false,
334
+ }).code
335
+ }
336
+
337
+ function loadComponents(props: Props): null | LoadedComponents[] {
324
338
  const componentsModules = props.components
325
339
  const key = componentsModules.join('')
326
340
  if (cacheComponents[key]) {
327
341
  return cacheComponents[key]
328
342
  }
329
343
  try {
330
- const requiredModules = componentsModules.map((name) => {
331
- return interopDefaultExport(require(name))
344
+ const info: LoadedComponents[] = componentsModules.flatMap((name) => {
345
+ const extension = extname(name)
346
+ const isLocal = Boolean(extension)
347
+ // during props.config pass we are passing in pre-bundled stuff
348
+ const writeTmp = isLocal && !props.config
349
+ const fileContents = writeTmp ? readFileSync(name, 'utf-8') : ''
350
+ const loadModule = writeTmp
351
+ ? join(dirname(name), `.tamagui-dynamic-eval-${basename(name)}.tsx`)
352
+ : name
353
+ let writtenContents = fileContents
354
+ let didBabel = false
355
+
356
+ const esbuildit = (src: string, target?: 'modern') =>
357
+ esbuild.transformSync(src, {
358
+ ...esbuildOptions,
359
+ ...(target === 'modern' && {
360
+ target: 'es2022',
361
+ jsx: 'transform',
362
+ loader: 'tsx',
363
+ platform: 'neutral',
364
+ format: 'esm',
365
+ }),
366
+ }).code
367
+
368
+ function attemptLoad({ forceExports = false } = {}) {
369
+ // need to write to tsx to enable reading it properly (:/ esbuild-register)
370
+ if (writeTmp) {
371
+ writtenContents = forceExports
372
+ ? esbuildit(transformAddExports(babelParse(esbuildit(fileContents, 'modern'))))
373
+ : esbuildit(fileContents)
374
+
375
+ writeFileSync(loadModule, writtenContents)
376
+ }
377
+ return {
378
+ moduleName: name,
379
+ nameToInfo: getComponentStaticConfigByName(
380
+ name,
381
+ interopDefaultExport(require(loadModule))
382
+ ),
383
+ }
384
+ }
385
+
386
+ const dispose = () => {
387
+ writeTmp && removeSync(loadModule)
388
+ }
389
+
390
+ try {
391
+ const res = attemptLoad({
392
+ forceExports: true,
393
+ })
394
+ didBabel = true
395
+ return res
396
+ } catch (err) {
397
+ console.log('babel err', err, writtenContents)
398
+ // ok
399
+ writtenContents = fileContents
400
+ if (process.env.DEBUG?.startsWith('tamagui')) {
401
+ console.log(`Error parsing babel likely`, err)
402
+ }
403
+ } finally {
404
+ dispose()
405
+ }
406
+
407
+ try {
408
+ return attemptLoad({
409
+ forceExports: false,
410
+ })
411
+ } catch (err) {
412
+ if (!process.env.TAMAGUI_DISABLE_WARN_DYNAMIC_LOAD) {
413
+ console.log(`
414
+
415
+ Tamagui attempted but failed to dynamically load components in:
416
+ ${name}
417
+
418
+ This will leave some styled() tags unoptimized.
419
+ Disable this file (or dynamic loading altogether):
420
+
421
+ disableExtractFoundComponents: ['${name}'] | true
422
+
423
+ Quiet this warning with environment variable:
424
+
425
+ TAMAGUI_DISABLE_WARN_DYNAMIC_LOAD=1
426
+
427
+ `)
428
+ console.log(err)
429
+ console.log(
430
+ `At: ${loadModule}`,
431
+ `\ndidBabel: ${didBabel}`,
432
+ `\nIn:`,
433
+ writtenContents,
434
+ `\nwriteTmp: `,
435
+ writeTmp
436
+ )
437
+ }
438
+ return []
439
+ } finally {
440
+ dispose()
441
+ }
332
442
  })
333
- const res = gatherTamaguiComponentInfo(requiredModules)
334
- cacheComponents[key] = res
335
- return res
443
+ cacheComponents[key] = info
444
+ return info
336
445
  } catch (err: any) {
337
446
  if (props.bubbleErrors) {
338
447
  throw err
339
448
  }
340
449
  console.log(`Tamagui error bundling components`, err.message, err.stack)
450
+ return null
341
451
  }
342
452
  }
343
453
 
344
- function gatherTamaguiComponentInfo(packages: any[]) {
345
- const components = {}
346
- for (const exported of packages) {
347
- try {
348
- for (const componentName in exported) {
349
- const found = getTamaguiComponent(componentName, exported[componentName])
350
- if (found) {
351
- // remove non-stringifyable
352
- const { Component, reactNativeWebComponent, ...sc } = found.staticConfig
353
- Object.assign(components, { [componentName]: { staticConfig: sc } })
354
- }
355
- }
356
- } catch (err) {
357
- console.error(`Tamagui failed getting components`)
358
- if (err instanceof Error) {
359
- console.error(err.message, err.stack)
360
- } else {
361
- console.error(err)
454
+ function getComponentStaticConfigByName(name: string, exported: any) {
455
+ if (!exported || typeof exported !== 'object' || Array.isArray(exported)) {
456
+ throw new Error(`Invalid export from package ${name}: ${typeof exported}`)
457
+ }
458
+ const components: Record<string, { staticConfig: StaticConfigParsed }> = {}
459
+ try {
460
+ for (const key in exported) {
461
+ const found = getTamaguiComponent(key, exported[key])
462
+ if (found) {
463
+ // remove non-stringifyable
464
+ const { Component, reactNativeWebComponent, ...sc } = found.staticConfig
465
+ components[key] = { staticConfig: sc }
362
466
  }
363
467
  }
468
+ } catch (err) {
469
+ console.error(`Tamagui failed getting components`)
470
+ if (err instanceof Error) {
471
+ console.error(err.message, err.stack)
472
+ } else {
473
+ console.error(err)
474
+ }
364
475
  }
365
476
  return components
366
477
  }
@@ -368,11 +479,11 @@ function gatherTamaguiComponentInfo(packages: any[]) {
368
479
  function getTamaguiComponent(
369
480
  name: string,
370
481
  Component: any
371
- ): undefined | { staticConfig: StaticConfig } {
482
+ ): undefined | { staticConfig: StaticConfigParsed } {
372
483
  if (name[0].toUpperCase() !== name[0]) {
373
484
  return
374
485
  }
375
- const staticConfig = Component?.staticConfig as StaticConfig | undefined
486
+ const staticConfig = Component?.staticConfig as StaticConfigParsed | undefined
376
487
  if (staticConfig) {
377
488
  return Component
378
489
  }
@@ -38,7 +38,7 @@ export function normalizeTernaries(ternaries: Ternary[]) {
38
38
  }
39
39
  }
40
40
 
41
- const key = generate(ternaryTest).code
41
+ const key = generate(ternaryTest as any).code
42
42
 
43
43
  if (!ternariesByKey[key]) {
44
44
  ternariesByKey[key] = {
@@ -17,7 +17,8 @@ export function getPragmaOptions({
17
17
  let shouldPrintDebug: boolean | 'verbose' = false
18
18
  let shouldDisable = false
19
19
 
20
- const firstLine = source.split('\n', 1)[0]
20
+ // try and avoid too much parsing but sometimes esbuild adds helpers above..
21
+ const firstLine = source.slice(0, 800).split('\n')[0]
21
22
 
22
23
  if (firstLine.includes('tamagui-ignore')) {
23
24
  shouldDisable = true
package/src/index.ts CHANGED
@@ -6,7 +6,6 @@ export { literalToAst } from './extractor/literalToAst.js'
6
6
  export * from './constants.js'
7
7
  export * from './extractor/extractToClassNames.js'
8
8
  export * from './extractor/extractHelpers.js'
9
- export * from '@tamagui/patch-rnw'
10
9
  export * from './extractor/loadTamagui.js'
11
10
  export * from './require.js'
12
11
  export * from './getPragmaOptions.js'
package/src/require.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { sep } from 'path'
1
+ import { relative, sep } from 'path'
2
2
 
3
3
  import { SHOULD_DEBUG } from './constants.js'
4
4
 
@@ -32,7 +32,7 @@ export function registerRequire(bubbleErrors?: boolean) {
32
32
  // eslint-disable-next-line no-console
33
33
  console.log('tamagui:require', path)
34
34
  }
35
- if (path.endsWith('.css') || path.endsWith('.json') || path.endsWith('.ttf')) {
35
+ if (/\.(gif|jpe?g|png|svg|ttf|otf|woff2?|bmp|webp)$/.test(path)) {
36
36
  return {}
37
37
  }
38
38
  if (
@@ -86,11 +86,19 @@ export function registerRequire(bubbleErrors?: boolean) {
86
86
 
87
87
  // eslint-disable-next-line no-console
88
88
  console.error(
89
- `Tamagui failed requiring ${path} from your tamagui.config.ts file, ignoring\n`,
90
- err.message,
91
- err.stack
89
+ `Tamagui failed loading the pre-built tamagui.config.ts
90
+
91
+ ${err.message}
92
+ ${err.stack}
93
+
94
+ You can see if it loads in the node repl:
95
+
96
+ require("./${relative(process.cwd(), path)}").default
97
+
98
+ `
92
99
  )
93
- const max = process.env.TAMAGUI_MAX_ERRORS ? +process.env.TAMAGUI_MAX_ERRORS : 200
100
+
101
+ const max = process.env.TAMAGUI_MAX_ERRORS ? +process.env.TAMAGUI_MAX_ERRORS : 50
94
102
  if (++tries > max) {
95
103
  // eslint-disable-next-line no-console
96
104
  console.log(
@@ -99,8 +107,8 @@ export function registerRequire(bubbleErrors?: boolean) {
99
107
  // avoid infinite loops
100
108
  process.exit(1)
101
109
  }
102
- // return proxyWorm by default
103
- return proxyWorm
110
+
111
+ return null
104
112
  }
105
113
  }
106
114
 
package/src/types.ts CHANGED
@@ -5,6 +5,8 @@ import type { StyleObject } from '@tamagui/helpers'
5
5
  import type { TamaguiOptions } from '@tamagui/helpers-node'
6
6
  import type { ViewStyle } from 'react-native'
7
7
 
8
+ import { LoadedComponents } from './index'
9
+
8
10
  export type { TamaguiOptions } from '@tamagui/helpers-node'
9
11
 
10
12
  export type { StyleObject } from '@tamagui/helpers'
@@ -49,6 +51,7 @@ export type ExtractedAttr =
49
51
  | ExtractedAttrStyle
50
52
 
51
53
  export type ExtractTagProps = {
54
+ parserProps: TamaguiOptionsWithFileInfo
52
55
  attrs: ExtractedAttr[]
53
56
  node: t.JSXOpeningElement
54
57
  attemptEval: (exprNode: t.Node, evalFn?: ((node: t.Node) => any) | undefined) => any
@@ -64,9 +67,10 @@ export type ExtractTagProps = {
64
67
 
65
68
  export type TamaguiOptionsWithFileInfo = TamaguiOptions & {
66
69
  sourcePath: string
70
+ allLoadedComponents: LoadedComponents[]
67
71
  }
68
72
 
69
- export type ExtractorParseProps = TamaguiOptionsWithFileInfo & {
73
+ export type ExtractorParseProps = Omit<TamaguiOptionsWithFileInfo, 'allLoadedComponents'> & {
70
74
  target: 'native' | 'html'
71
75
  shouldPrintDebug?: boolean | 'verbose'
72
76
  onExtractTag: (props: ExtractTagProps) => void
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import * as babelParser from '@babel/parser';
3
+ import * as t from '@babel/types';
3
4
  export declare const parserOptions: babelParser.ParserOptions;
4
- export declare function babelParse(code: string | Buffer): any;
5
+ export declare function babelParse(code: string | Buffer): t.File;
5
6
  //# sourceMappingURL=babelParse.d.ts.map
@@ -0,0 +1,13 @@
1
+ import esbuild from 'esbuild';
2
+ /**
3
+ * For internal loading of new files
4
+ */
5
+ declare type Props = Omit<Partial<esbuild.BuildOptions>, 'entryPoints'> & {
6
+ outfile: string;
7
+ entryPoints: string[];
8
+ resolvePlatformSpecificEntries?: boolean;
9
+ };
10
+ export declare function bundle(props: Props, aliases?: Record<string, string>): Promise<esbuild.BuildResult>;
11
+ export declare function bundleSync(props: Props, aliases?: Record<string, string>): esbuild.BuildResult;
12
+ export {};
13
+ //# sourceMappingURL=bundle.d.ts.map
@@ -8,7 +8,17 @@ 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
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;
11
+ export declare const isInsideComponentPackage: (props: TamaguiOptionsWithFileInfo, moduleName: string) => any;
12
+ export declare const isComponentPackage: (props: TamaguiOptionsWithFileInfo, srcName: string) => any;
13
+ export declare function getValidComponent(props: TamaguiOptionsWithFileInfo, moduleName: string, componentName: string): false | {
14
+ staticConfig: import("@tamagui/core-node").StaticConfigParsed;
15
+ } | null;
16
+ export declare const isValidModule: (props: TamaguiOptionsWithFileInfo, moduleName: string) => {
17
+ isLocal: boolean;
18
+ isValid: any;
19
+ };
20
+ export declare const getValidImport: (props: TamaguiOptionsWithFileInfo, moduleName: string, componentName?: string) => {
21
+ staticConfig: import("@tamagui/core-node").StaticConfigParsed;
22
+ } | null;
23
+ export declare const isValidImport: (props: TamaguiOptionsWithFileInfo, moduleName: string, componentName?: string) => any;
14
24
  //# sourceMappingURL=extractHelpers.d.ts.map