@tamagui/static 1.0.1-beta.140 → 1.0.1-beta.143
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/constants.js +0 -0
- package/dist/cjs/constants.js.map +0 -0
- package/dist/cjs/extractor/accessSafe.js +0 -0
- package/dist/cjs/extractor/accessSafe.js.map +0 -0
- package/dist/cjs/extractor/babelParse.js +0 -0
- package/dist/cjs/extractor/babelParse.js.map +0 -0
- package/dist/cjs/extractor/buildClassName.js +0 -0
- package/dist/cjs/extractor/buildClassName.js.map +0 -0
- package/dist/cjs/extractor/createEvaluator.js +0 -0
- package/dist/cjs/extractor/createEvaluator.js.map +2 -2
- package/dist/cjs/extractor/createExtractor.js +1138 -1106
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/cjs/extractor/ensureImportingConcat.js +0 -0
- package/dist/cjs/extractor/ensureImportingConcat.js.map +0 -0
- package/dist/cjs/extractor/evaluateAstNode.js +0 -0
- package/dist/cjs/extractor/evaluateAstNode.js.map +0 -0
- package/dist/cjs/extractor/extractHelpers.js +0 -0
- package/dist/cjs/extractor/extractHelpers.js.map +0 -0
- package/dist/cjs/extractor/extractMediaStyle.js +0 -0
- package/dist/cjs/extractor/extractMediaStyle.js.map +0 -0
- package/dist/cjs/extractor/extractToClassNames.js +4 -4
- package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
- package/dist/cjs/extractor/findTopmostFunction.js +0 -0
- package/dist/cjs/extractor/findTopmostFunction.js.map +0 -0
- package/dist/cjs/extractor/generatedUid.js +0 -0
- package/dist/cjs/extractor/generatedUid.js.map +0 -0
- package/dist/cjs/extractor/getPrefixLogs.js +0 -0
- package/dist/cjs/extractor/getPrefixLogs.js.map +0 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js +0 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +0 -0
- package/dist/cjs/extractor/getSourceModule.js +0 -0
- package/dist/cjs/extractor/getSourceModule.js.map +0 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js +18 -2
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +2 -2
- package/dist/cjs/extractor/hoistClassNames.js +0 -0
- package/dist/cjs/extractor/hoistClassNames.js.map +0 -0
- package/dist/cjs/extractor/literalToAst.js +0 -0
- package/dist/cjs/extractor/literalToAst.js.map +0 -0
- package/dist/cjs/extractor/loadFile.js +0 -0
- package/dist/cjs/extractor/loadFile.js.map +0 -0
- package/dist/cjs/extractor/loadTamagui.js +205 -28
- package/dist/cjs/extractor/loadTamagui.js.map +2 -2
- package/dist/cjs/extractor/logLines.js +0 -0
- package/dist/cjs/extractor/logLines.js.map +0 -0
- package/dist/cjs/extractor/normalizeTernaries.js +0 -0
- package/dist/cjs/extractor/normalizeTernaries.js.map +0 -0
- package/dist/cjs/extractor/removeUnusedHooks.js +0 -0
- package/dist/cjs/extractor/removeUnusedHooks.js.map +0 -0
- package/dist/cjs/extractor/timer.js +8 -1
- package/dist/cjs/extractor/timer.js.map +2 -2
- package/dist/cjs/extractor/validHTMLAttributes.js +0 -0
- package/dist/cjs/extractor/validHTMLAttributes.js.map +0 -0
- package/dist/cjs/getPragmaOptions.js +68 -0
- package/dist/cjs/getPragmaOptions.js.map +7 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/require.js +1 -20
- package/dist/cjs/require.js.map +2 -2
- package/dist/cjs/types.js +0 -0
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/webpackPlugin.js +35 -0
- package/dist/cjs/webpackPlugin.js.map +7 -0
- package/dist/esm/constants.js +0 -0
- package/dist/esm/constants.js.map +0 -0
- package/dist/esm/extractor/accessSafe.js +0 -0
- package/dist/esm/extractor/accessSafe.js.map +0 -0
- package/dist/esm/extractor/babelParse.js +0 -0
- package/dist/esm/extractor/babelParse.js.map +0 -0
- package/dist/esm/extractor/buildClassName.js +0 -0
- package/dist/esm/extractor/buildClassName.js.map +0 -0
- package/dist/esm/extractor/createEvaluator.js +0 -0
- package/dist/esm/extractor/createEvaluator.js.map +2 -2
- package/dist/esm/extractor/createExtractor.js +1140 -1108
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/ensureImportingConcat.js +0 -0
- package/dist/esm/extractor/ensureImportingConcat.js.map +0 -0
- package/dist/esm/extractor/evaluateAstNode.js +0 -0
- package/dist/esm/extractor/evaluateAstNode.js.map +0 -0
- package/dist/esm/extractor/extractHelpers.js +0 -0
- package/dist/esm/extractor/extractHelpers.js.map +0 -0
- package/dist/esm/extractor/extractMediaStyle.js +0 -0
- package/dist/esm/extractor/extractMediaStyle.js.map +0 -0
- package/dist/esm/extractor/extractToClassNames.js +4 -4
- package/dist/esm/extractor/extractToClassNames.js.map +2 -2
- package/dist/esm/extractor/findTopmostFunction.js +0 -0
- package/dist/esm/extractor/findTopmostFunction.js.map +0 -0
- package/dist/esm/extractor/generatedUid.js +0 -0
- package/dist/esm/extractor/generatedUid.js.map +0 -0
- package/dist/esm/extractor/getPrefixLogs.js +0 -0
- package/dist/esm/extractor/getPrefixLogs.js.map +0 -0
- package/dist/esm/extractor/getPropValueFromAttributes.js +0 -0
- package/dist/esm/extractor/getPropValueFromAttributes.js.map +0 -0
- package/dist/esm/extractor/getSourceModule.js +0 -0
- package/dist/esm/extractor/getSourceModule.js.map +0 -0
- package/dist/esm/extractor/getStaticBindingsForScope.js +17 -2
- package/dist/esm/extractor/getStaticBindingsForScope.js.map +2 -2
- package/dist/esm/extractor/hoistClassNames.js +0 -0
- package/dist/esm/extractor/hoistClassNames.js.map +0 -0
- package/dist/esm/extractor/literalToAst.js +0 -0
- package/dist/esm/extractor/literalToAst.js.map +0 -0
- package/dist/esm/extractor/loadFile.js +0 -0
- package/dist/esm/extractor/loadFile.js.map +0 -0
- package/dist/esm/extractor/loadTamagui.js +201 -28
- package/dist/esm/extractor/loadTamagui.js.map +2 -2
- package/dist/esm/extractor/logLines.js +0 -0
- package/dist/esm/extractor/logLines.js.map +0 -0
- package/dist/esm/extractor/normalizeTernaries.js +0 -0
- package/dist/esm/extractor/normalizeTernaries.js.map +0 -0
- package/dist/esm/extractor/removeUnusedHooks.js +0 -0
- package/dist/esm/extractor/removeUnusedHooks.js.map +0 -0
- package/dist/esm/extractor/timer.js +8 -1
- package/dist/esm/extractor/timer.js.map +2 -2
- package/dist/esm/extractor/validHTMLAttributes.js +0 -0
- package/dist/esm/extractor/validHTMLAttributes.js.map +0 -0
- package/dist/esm/getPragmaOptions.js +44 -0
- package/dist/esm/getPragmaOptions.js.map +7 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/require.js +2 -21
- package/dist/esm/require.js.map +2 -2
- package/dist/esm/types.js +0 -0
- package/dist/esm/types.js.map +0 -0
- package/dist/esm/webpackPlugin.js +11 -0
- package/dist/esm/webpackPlugin.js.map +7 -0
- package/dist/jsx/constants.js +1 -2
- package/dist/jsx/constants.js.map +1 -1
- package/dist/jsx/extractor/accessSafe.js +0 -0
- package/dist/jsx/extractor/accessSafe.js.map +0 -0
- package/dist/jsx/extractor/babelParse.js +0 -0
- package/dist/jsx/extractor/babelParse.js.map +0 -0
- package/dist/jsx/extractor/buildClassName.js +0 -0
- package/dist/jsx/extractor/buildClassName.js.map +0 -0
- package/dist/jsx/extractor/createEvaluator.js +0 -0
- package/dist/jsx/extractor/createEvaluator.js.map +2 -2
- package/dist/jsx/extractor/createExtractor.js +1133 -1108
- package/dist/jsx/extractor/createExtractor.js.map +2 -2
- package/dist/jsx/extractor/ensureImportingConcat.js +0 -0
- package/dist/jsx/extractor/ensureImportingConcat.js.map +0 -0
- package/dist/jsx/extractor/evaluateAstNode.js +0 -0
- package/dist/jsx/extractor/evaluateAstNode.js.map +0 -0
- package/dist/jsx/extractor/extractHelpers.js +3 -5
- package/dist/jsx/extractor/extractHelpers.js.map +1 -1
- package/dist/jsx/extractor/extractMediaStyle.js +2 -3
- package/dist/jsx/extractor/extractMediaStyle.js.map +1 -1
- package/dist/jsx/extractor/extractToClassNames.js +7 -10
- package/dist/jsx/extractor/extractToClassNames.js.map +2 -2
- package/dist/jsx/extractor/findTopmostFunction.js +0 -0
- package/dist/jsx/extractor/findTopmostFunction.js.map +0 -0
- package/dist/jsx/extractor/generatedUid.js +0 -0
- package/dist/jsx/extractor/generatedUid.js.map +0 -0
- package/dist/jsx/extractor/getPrefixLogs.js +1 -2
- package/dist/jsx/extractor/getPrefixLogs.js.map +1 -1
- package/dist/jsx/extractor/getPropValueFromAttributes.js +0 -0
- package/dist/jsx/extractor/getPropValueFromAttributes.js.map +0 -0
- package/dist/jsx/extractor/getSourceModule.js +0 -0
- package/dist/jsx/extractor/getSourceModule.js.map +0 -0
- package/dist/jsx/extractor/getStaticBindingsForScope.js +17 -2
- package/dist/jsx/extractor/getStaticBindingsForScope.js.map +2 -2
- package/dist/jsx/extractor/hoistClassNames.js +0 -0
- package/dist/jsx/extractor/hoistClassNames.js.map +0 -0
- package/dist/jsx/extractor/literalToAst.js +1 -1
- package/dist/jsx/extractor/literalToAst.js.map +1 -1
- package/dist/jsx/extractor/loadFile.js +3 -4
- package/dist/jsx/extractor/loadFile.js.map +1 -1
- package/dist/jsx/extractor/loadTamagui.js +199 -28
- package/dist/jsx/extractor/loadTamagui.js.map +2 -2
- package/dist/jsx/extractor/logLines.js +0 -0
- package/dist/jsx/extractor/logLines.js.map +0 -0
- package/dist/jsx/extractor/normalizeTernaries.js +2 -3
- package/dist/jsx/extractor/normalizeTernaries.js.map +1 -1
- package/dist/jsx/extractor/removeUnusedHooks.js +3 -5
- package/dist/jsx/extractor/removeUnusedHooks.js.map +1 -1
- package/dist/jsx/extractor/timer.js +8 -1
- package/dist/jsx/extractor/timer.js.map +2 -2
- package/dist/jsx/extractor/validHTMLAttributes.js +0 -0
- package/dist/jsx/extractor/validHTMLAttributes.js.map +0 -0
- package/dist/jsx/getPragmaOptions.js +43 -0
- package/dist/jsx/getPragmaOptions.js.map +7 -0
- package/dist/jsx/index.js +1 -0
- package/dist/jsx/index.js.map +2 -2
- package/dist/jsx/require.js +2 -21
- package/dist/jsx/require.js.map +2 -2
- package/dist/jsx/types.js +0 -0
- package/dist/jsx/types.js.map +0 -0
- package/dist/jsx/webpackPlugin.js +11 -0
- package/dist/jsx/webpackPlugin.js.map +7 -0
- package/package.json +20 -17
- package/src/extractor/createEvaluator.ts +2 -0
- package/src/extractor/createExtractor.ts +1592 -1532
- package/src/extractor/extractToClassNames.ts +25 -10
- package/src/extractor/getStaticBindingsForScope.ts +22 -5
- package/src/extractor/loadTamagui.ts +250 -32
- package/src/extractor/timer.ts +12 -1
- package/src/getPragmaOptions.ts +52 -0
- package/src/index.ts +2 -0
- package/src/require.ts +29 -24
- package/src/types.ts +16 -0
- package/src/webpackPlugin.ts +9 -0
- package/types/extractor/createExtractor.d.ts +22 -6
- package/types/extractor/extractToClassNames.d.ts +1 -1
- package/types/extractor/getStaticBindingsForScope.d.ts +1 -0
- package/types/extractor/loadTamagui.d.ts +5 -3
- package/types/getPragmaOptions.d.ts +9 -0
- package/types/index.d.ts +1 -0
- package/types/types.d.ts +13 -0
- 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
|
-
//
|
|
224
|
-
console.log(
|
|
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
|
-
//
|
|
272
|
-
console.log(
|
|
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
|
|
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
|
|
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 (
|
|
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,14 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { basename, dirname, join, sep } from 'path'
|
|
2
3
|
|
|
3
4
|
import { getDefaultTamaguiConfig } from '@tamagui/config-default-node'
|
|
4
5
|
import type { StaticConfig, TamaguiComponent, TamaguiInternalConfig } from '@tamagui/core-node'
|
|
5
6
|
import { createTamagui } from '@tamagui/core-node'
|
|
7
|
+
import esbuild from 'esbuild'
|
|
8
|
+
import { ensureDir, pathExists, remove, stat, writeFile } from 'fs-extra'
|
|
6
9
|
|
|
7
10
|
import { SHOULD_DEBUG } from '../constants'
|
|
8
11
|
import { getNameToPaths, registerRequire, unregisterRequire } from '../require'
|
|
9
12
|
|
|
10
|
-
let loadedTamagui: any = null
|
|
11
|
-
|
|
12
13
|
type NameToPaths = {
|
|
13
14
|
[key: string]: Set<string>
|
|
14
15
|
}
|
|
@@ -19,12 +20,177 @@ export type TamaguiProjectInfo = {
|
|
|
19
20
|
nameToPaths: NameToPaths
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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,
|
|
25
107
|
}
|
|
26
108
|
|
|
27
|
-
|
|
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('@tamagui/react-native-svg'),
|
|
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
|
+
}
|
|
28
194
|
|
|
29
195
|
const { unregister } = require('esbuild-register/dist/node').register({
|
|
30
196
|
target: 'es2019',
|
|
@@ -32,6 +198,8 @@ export function loadTamagui(props: { components: string[]; config: string }): Ta
|
|
|
32
198
|
})
|
|
33
199
|
|
|
34
200
|
try {
|
|
201
|
+
registerRequire()
|
|
202
|
+
|
|
35
203
|
// lets shim require and avoid importing react-native + react-native-web
|
|
36
204
|
// we just need to read the config around them
|
|
37
205
|
process.env.IS_STATIC = 'is_static'
|
|
@@ -41,41 +209,31 @@ export function loadTamagui(props: { components: string[]; config: string }): Ta
|
|
|
41
209
|
globalThis['__DEV__'] = process.env.NODE_ENV === 'development'
|
|
42
210
|
}
|
|
43
211
|
|
|
44
|
-
registerRequire()
|
|
45
|
-
|
|
46
212
|
try {
|
|
47
213
|
// import config
|
|
48
|
-
|
|
49
|
-
const tamaguiConfig = (exp['default'] || exp) as TamaguiInternalConfig
|
|
50
|
-
|
|
51
|
-
if (!tamaguiConfig || !tamaguiConfig.parsed) {
|
|
52
|
-
const confPath = require.resolve(configPath)
|
|
53
|
-
console.log(`Received:`, tamaguiConfig)
|
|
54
|
-
throw new Error(`Can't find valid config in ${confPath}`)
|
|
55
|
-
}
|
|
214
|
+
let tamaguiConfig: TamaguiInternalConfig | null = null
|
|
56
215
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
if (staticConfig) {
|
|
65
|
-
// remove non-stringifyable
|
|
66
|
-
const { Component, reactNativeWebComponent, ...sc } = staticConfig
|
|
67
|
-
Object.assign(components, { [Name]: { staticConfig: sc } })
|
|
68
|
-
}
|
|
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}`)
|
|
69
223
|
}
|
|
70
224
|
}
|
|
71
225
|
|
|
226
|
+
const components = loadComponents(props.components)
|
|
227
|
+
|
|
72
228
|
// undo shims
|
|
73
229
|
process.env.IS_STATIC = undefined
|
|
74
230
|
|
|
75
231
|
// set up core-node
|
|
76
|
-
|
|
232
|
+
if (tamaguiConfig) {
|
|
233
|
+
createTamagui(tamaguiConfig)
|
|
234
|
+
}
|
|
77
235
|
|
|
78
|
-
|
|
236
|
+
cache[key] = {
|
|
79
237
|
components,
|
|
80
238
|
tamaguiConfig,
|
|
81
239
|
nameToPaths: getNameToPaths(),
|
|
@@ -99,7 +257,7 @@ export function loadTamagui(props: { components: string[]; config: string }): Ta
|
|
|
99
257
|
}
|
|
100
258
|
}
|
|
101
259
|
|
|
102
|
-
return
|
|
260
|
+
return cache[key]
|
|
103
261
|
} catch (err) {
|
|
104
262
|
console.log('Error loading Tamagui', err)
|
|
105
263
|
throw err
|
|
@@ -108,3 +266,63 @@ export function loadTamagui(props: { components: string[]; config: string }): Ta
|
|
|
108
266
|
unregisterRequire()
|
|
109
267
|
}
|
|
110
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
|
+
}
|
package/src/extractor/timer.ts
CHANGED
|
@@ -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
|
-
|
|
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
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
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
)
|