@tamagui/static 1.14.9 → 1.15.0
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/extractor/bundleConfig.js +343 -0
- package/dist/cjs/extractor/bundleConfig.js.map +7 -0
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/cjs/extractor/generateTamaguiConfig.js +83 -0
- package/dist/cjs/extractor/generateTamaguiConfig.js.map +7 -0
- package/dist/cjs/extractor/loadTamagui.js +76 -292
- package/dist/cjs/extractor/loadTamagui.js.map +3 -3
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/extractor/bundleConfig.js +307 -0
- package/dist/esm/extractor/bundleConfig.js.map +7 -0
- package/dist/esm/extractor/bundleConfig.mjs +307 -0
- package/dist/esm/extractor/bundleConfig.mjs.map +7 -0
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/createExtractor.mjs.map +2 -2
- package/dist/esm/extractor/generateTamaguiConfig.js +49 -0
- package/dist/esm/extractor/generateTamaguiConfig.js.map +7 -0
- package/dist/esm/extractor/generateTamaguiConfig.mjs +49 -0
- package/dist/esm/extractor/generateTamaguiConfig.mjs.map +7 -0
- package/dist/esm/extractor/loadTamagui.js +76 -290
- package/dist/esm/extractor/loadTamagui.js.map +2 -2
- package/dist/esm/extractor/loadTamagui.mjs +76 -290
- package/dist/esm/extractor/loadTamagui.mjs.map +2 -2
- package/package.json +16 -16
- package/src/extractor/bundleConfig.ts +389 -0
- package/src/extractor/createExtractor.ts +3 -3
- package/src/extractor/generateTamaguiConfig.ts +65 -0
- package/src/extractor/loadTamagui.ts +81 -370
- package/src/types.ts +2 -3
- package/types/extractor/bundleConfig.d.ts +35 -0
- package/types/extractor/bundleConfig.d.ts.map +1 -0
- package/types/extractor/createExtractor.d.ts +2 -2
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/extractHelpers.d.ts +2 -2
- package/types/extractor/generateTamaguiConfig.d.ts +3 -0
- package/types/extractor/generateTamaguiConfig.d.ts.map +1 -0
- package/types/extractor/loadTamagui.d.ts +6 -21
- package/types/extractor/loadTamagui.d.ts.map +1 -1
- package/types/types.d.ts +1 -1
- package/types/types.d.ts.map +1 -1
|
@@ -1,52 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
/* eslint-disable no-console */
|
|
3
|
-
import { basename, dirname, extname, join, relative, resolve, sep } from 'path'
|
|
1
|
+
import { basename, dirname, extname, join, resolve } from 'path'
|
|
4
2
|
|
|
5
|
-
import generate from '@babel/generator'
|
|
6
|
-
import traverse from '@babel/traverse'
|
|
7
|
-
import * as t from '@babel/types'
|
|
8
|
-
import { Color, colorLog } from '@tamagui/cli-color'
|
|
9
3
|
import { getDefaultTamaguiConfig } from '@tamagui/config-default-node'
|
|
10
|
-
import type { StaticConfigParsed, TamaguiInternalConfig } from '@tamagui/core-node'
|
|
11
4
|
import { createTamagui } from '@tamagui/core-node'
|
|
5
|
+
import { CLIResolvedOptions, CLIUserOptions } from '@tamagui/types'
|
|
6
|
+
import type { TamaguiInternalConfig } from '@tamagui/web'
|
|
12
7
|
import esbuild from 'esbuild'
|
|
13
|
-
import {
|
|
8
|
+
import fs, { existsSync, pathExists, readJSON } from 'fs-extra'
|
|
14
9
|
|
|
15
10
|
import { SHOULD_DEBUG } from '../constants.js'
|
|
16
11
|
import { getNameToPaths, registerRequire, unregisterRequire } from '../require.js'
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
nameToInfo: Record<
|
|
27
|
-
string,
|
|
28
|
-
{
|
|
29
|
-
staticConfig: StaticConfigParsed
|
|
30
|
-
}
|
|
31
|
-
>
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type TamaguiProjectInfo = {
|
|
35
|
-
components: LoadedComponents[]
|
|
36
|
-
tamaguiConfig: TamaguiInternalConfig
|
|
37
|
-
nameToPaths: NameToPaths
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
type Props = {
|
|
41
|
-
components: string[]
|
|
42
|
-
config?: string
|
|
43
|
-
forceExports?: boolean
|
|
44
|
-
}
|
|
12
|
+
import { TamaguiOptions } from '../types.js'
|
|
13
|
+
import {
|
|
14
|
+
Props,
|
|
15
|
+
TamaguiProjectInfo,
|
|
16
|
+
bundleConfig,
|
|
17
|
+
esbuildOptions,
|
|
18
|
+
loadComponents,
|
|
19
|
+
} from './bundleConfig.js'
|
|
20
|
+
import { generateTamaguiConfig } from './generateTamaguiConfig.js'
|
|
45
21
|
|
|
46
22
|
const cache = {}
|
|
47
23
|
|
|
48
|
-
// TODO needs a plugin for webpack / vite to run this once at startup and not again until changed...
|
|
49
|
-
|
|
50
24
|
export async function loadTamagui(props: Props): Promise<TamaguiProjectInfo> {
|
|
51
25
|
const key = JSON.stringify(props)
|
|
52
26
|
if (cache[key]) {
|
|
@@ -61,126 +35,11 @@ export async function loadTamagui(props: Props): Promise<TamaguiProjectInfo> {
|
|
|
61
35
|
resolver = res
|
|
62
36
|
})
|
|
63
37
|
|
|
64
|
-
const tmpDir = join(process.cwd(), '.tamagui')
|
|
65
|
-
const configOutPath = join(tmpDir, `tamagui.config.cjs`)
|
|
66
|
-
const baseComponents = props.components.filter((x) => x !== '@tamagui/core')
|
|
67
|
-
|
|
68
|
-
const componentOutPaths = baseComponents.map((componentModule) =>
|
|
69
|
-
join(
|
|
70
|
-
tmpDir,
|
|
71
|
-
`${componentModule
|
|
72
|
-
.split(sep)
|
|
73
|
-
.join('-')
|
|
74
|
-
.replace(/[^a-z0-9]+/gi, '')}-components.config.cjs`
|
|
75
|
-
)
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
const external = [
|
|
79
|
-
'@tamagui/core',
|
|
80
|
-
'@tamagui/web',
|
|
81
|
-
'@tamagui/core-node',
|
|
82
|
-
'react',
|
|
83
|
-
'react-dom',
|
|
84
|
-
'react-native-svg',
|
|
85
|
-
]
|
|
86
|
-
const configEntry = props.config ? join(process.cwd(), props.config) : ''
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
process.env.NODE_ENV === 'development' &&
|
|
90
|
-
process.env.DEBUG?.startsWith('tamagui')
|
|
91
|
-
) {
|
|
92
|
-
console.log(`Building config entry`, configEntry)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// build them to node-compat versions
|
|
96
|
-
try {
|
|
97
|
-
await ensureDir(tmpDir)
|
|
98
|
-
} catch {
|
|
99
|
-
//
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
colorLog(
|
|
103
|
-
Color.FgYellow,
|
|
104
|
-
`
|
|
105
|
-
Tamagui built config and components:`
|
|
106
|
-
)
|
|
107
|
-
colorLog(
|
|
108
|
-
Color.Dim,
|
|
109
|
-
`
|
|
110
|
-
Config .${sep}${relative(process.cwd(), configOutPath)}
|
|
111
|
-
Components ${[
|
|
112
|
-
...componentOutPaths.map((p) => `.${sep}${relative(process.cwd(), p)}`),
|
|
113
|
-
].join('\n ')}
|
|
114
|
-
`
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
await Promise.all([
|
|
118
|
-
props.config
|
|
119
|
-
? bundle({
|
|
120
|
-
entryPoints: [configEntry],
|
|
121
|
-
external,
|
|
122
|
-
outfile: configOutPath,
|
|
123
|
-
})
|
|
124
|
-
: null,
|
|
125
|
-
...baseComponents.map((componentModule, i) => {
|
|
126
|
-
return bundle({
|
|
127
|
-
entryPoints: [componentModule],
|
|
128
|
-
resolvePlatformSpecificEntries: true,
|
|
129
|
-
external,
|
|
130
|
-
outfile: componentOutPaths[i],
|
|
131
|
-
})
|
|
132
|
-
}),
|
|
133
|
-
])
|
|
134
|
-
|
|
135
38
|
try {
|
|
136
39
|
registerRequire()
|
|
137
|
-
const
|
|
138
|
-
const config = out.default || out
|
|
139
|
-
|
|
140
|
-
if (!config) {
|
|
141
|
-
throw new Error(`No config: ${config}`)
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
let components = loadComponents({
|
|
145
|
-
...props,
|
|
146
|
-
components: componentOutPaths,
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
if (!components) {
|
|
150
|
-
throw new Error(`No components found: ${componentOutPaths.join(', ')}`)
|
|
151
|
-
}
|
|
40
|
+
const bundleInfo = await bundleConfig(props)
|
|
152
41
|
|
|
153
|
-
|
|
154
|
-
for (const component of components) {
|
|
155
|
-
component.moduleName =
|
|
156
|
-
baseComponents[componentOutPaths.indexOf(component.moduleName)]
|
|
157
|
-
if (!component.moduleName) {
|
|
158
|
-
throw new Error(`Tamagui internal err`)
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// always load core so we can optimize if directly importing
|
|
163
|
-
const coreComponents = loadComponents({
|
|
164
|
-
...props,
|
|
165
|
-
components: ['@tamagui/core-node'],
|
|
166
|
-
})
|
|
167
|
-
if (coreComponents) {
|
|
168
|
-
coreComponents[0].moduleName = '@tamagui/core'
|
|
169
|
-
components = [...components, ...coreComponents]
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (
|
|
173
|
-
process.env.NODE_ENV === 'development' &&
|
|
174
|
-
process.env.DEBUG?.startsWith('tamagui')
|
|
175
|
-
) {
|
|
176
|
-
console.log('Loaded components', components)
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
cache[key] = {
|
|
180
|
-
components,
|
|
181
|
-
nameToPaths: {},
|
|
182
|
-
tamaguiConfig: config,
|
|
183
|
-
}
|
|
42
|
+
cache[key] = bundleInfo
|
|
184
43
|
|
|
185
44
|
// init core-node
|
|
186
45
|
createTamagui(cache[key].tamaguiConfig)
|
|
@@ -206,14 +65,6 @@ export function resolveWebOrNativeSpecificEntry(entry: string) {
|
|
|
206
65
|
return entry
|
|
207
66
|
}
|
|
208
67
|
|
|
209
|
-
const esbuildOptions = {
|
|
210
|
-
loader: 'tsx',
|
|
211
|
-
target: 'es2018',
|
|
212
|
-
format: 'cjs',
|
|
213
|
-
jsx: 'transform',
|
|
214
|
-
platform: 'node',
|
|
215
|
-
} as const
|
|
216
|
-
|
|
217
68
|
// loads in-process using esbuild-register
|
|
218
69
|
export function loadTamaguiSync(props: Props): TamaguiProjectInfo {
|
|
219
70
|
const key = JSON.stringify(props)
|
|
@@ -296,219 +147,79 @@ export function loadTamaguiSync(props: Props): TamaguiProjectInfo {
|
|
|
296
147
|
}
|
|
297
148
|
}
|
|
298
149
|
|
|
299
|
-
function
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
150
|
+
export async function getOptions({
|
|
151
|
+
root = process.cwd(),
|
|
152
|
+
tsconfigPath = 'tsconfig.json',
|
|
153
|
+
tamaguiOptions,
|
|
154
|
+
host,
|
|
155
|
+
debug,
|
|
156
|
+
}: Partial<CLIUserOptions> = {}): Promise<CLIResolvedOptions> {
|
|
157
|
+
const tsConfigFilePath = join(root, tsconfigPath)
|
|
158
|
+
if (!(await fs.pathExists(tsConfigFilePath)))
|
|
159
|
+
throw new Error(`No tsconfig found: ${tsConfigFilePath}`)
|
|
160
|
+
const dotDir = join(root, '.tamagui')
|
|
161
|
+
const pkgJson = await readJSON(join(root, 'package.json'))
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
|
165
|
+
root,
|
|
166
|
+
host: host || '127.0.0.1',
|
|
167
|
+
pkgJson,
|
|
168
|
+
debug,
|
|
169
|
+
tsconfigPath,
|
|
170
|
+
tamaguiOptions: {
|
|
171
|
+
components: ['tamagui'],
|
|
172
|
+
config: await getDefaultTamaguiConfigPath(),
|
|
173
|
+
...tamaguiOptions,
|
|
319
174
|
},
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
VariableDeclaration(nodePath) {
|
|
325
|
-
// top level only
|
|
326
|
-
if (!t.isProgram(nodePath.parent)) return
|
|
327
|
-
const decs = nodePath.node.declarations
|
|
328
|
-
if (decs.length > 1) return
|
|
329
|
-
const [dec] = decs
|
|
330
|
-
if (!t.isIdentifier(dec.id)) return
|
|
331
|
-
if (!dec.init) return
|
|
332
|
-
if (usedNames.has(dec.id.name)) return
|
|
333
|
-
usedNames.add(dec.id.name)
|
|
334
|
-
nodePath.replaceWith(
|
|
335
|
-
t.exportNamedDeclaration(t.variableDeclaration('let', [dec]), [
|
|
336
|
-
t.exportSpecifier(t.identifier(dec.id.name), t.identifier(dec.id.name)),
|
|
337
|
-
])
|
|
338
|
-
)
|
|
175
|
+
paths: {
|
|
176
|
+
dotDir,
|
|
177
|
+
conf: join(dotDir, 'tamagui.config.json'),
|
|
178
|
+
types: join(dotDir, 'types.json'),
|
|
339
179
|
},
|
|
340
|
-
})
|
|
341
|
-
|
|
342
|
-
// @ts-ignore
|
|
343
|
-
return generate(ast as any, {
|
|
344
|
-
concise: false,
|
|
345
|
-
filename: 'test.tsx',
|
|
346
|
-
retainLines: false,
|
|
347
|
-
sourceMaps: false,
|
|
348
|
-
}).code
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
const esbuildit = (src: string, target?: 'modern') => {
|
|
352
|
-
return esbuild.transformSync(src, {
|
|
353
|
-
...esbuildOptions,
|
|
354
|
-
...(target === 'modern' && {
|
|
355
|
-
target: 'es2022',
|
|
356
|
-
jsx: 'transform',
|
|
357
|
-
loader: 'tsx',
|
|
358
|
-
platform: 'neutral',
|
|
359
|
-
format: 'esm',
|
|
360
|
-
}),
|
|
361
|
-
}).code
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
function loadComponents(props: Props): null | LoadedComponents[] {
|
|
365
|
-
const componentsModules = props.components
|
|
366
|
-
const key = componentsModules.join('')
|
|
367
|
-
if (cacheComponents[key]) {
|
|
368
|
-
return cacheComponents[key]
|
|
369
180
|
}
|
|
370
|
-
|
|
371
|
-
const info: LoadedComponents[] = componentsModules.flatMap((name) => {
|
|
372
|
-
const extension = extname(name)
|
|
373
|
-
const isLocal = Boolean(extension)
|
|
374
|
-
// during props.config pass we are passing in pre-bundled stuff
|
|
375
|
-
const isDynamic = isLocal && !props.config
|
|
376
|
-
|
|
377
|
-
if (isDynamic && !process.env.TAMAGUI_ENABLE_DYNAMIC_LOAD) {
|
|
378
|
-
return []
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
const fileContents = isDynamic ? readFileSync(name, 'utf-8') : ''
|
|
382
|
-
const loadModule = isDynamic
|
|
383
|
-
? join(dirname(name), `.tamagui-dynamic-eval-${basename(name)}.tsx`)
|
|
384
|
-
: name
|
|
385
|
-
let writtenContents = fileContents
|
|
386
|
-
let didBabel = false
|
|
387
|
-
|
|
388
|
-
function attemptLoad({ forceExports = false } = {}) {
|
|
389
|
-
// need to write to tsx to enable reading it properly (:/ esbuild-register)
|
|
390
|
-
if (isDynamic) {
|
|
391
|
-
writtenContents = forceExports
|
|
392
|
-
? esbuildit(
|
|
393
|
-
transformAddExports(babelParse(esbuildit(fileContents, 'modern')))
|
|
394
|
-
)
|
|
395
|
-
: esbuildit(fileContents)
|
|
396
|
-
|
|
397
|
-
writeFileSync(loadModule, writtenContents)
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
if (process.env.DEBUG === 'tamagui') {
|
|
401
|
-
console.log(`loadModule`, loadModule, require.resolve(loadModule))
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
return {
|
|
405
|
-
moduleName: name,
|
|
406
|
-
nameToInfo: getComponentStaticConfigByName(
|
|
407
|
-
name,
|
|
408
|
-
interopDefaultExport(require(loadModule))
|
|
409
|
-
),
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
const dispose = () => {
|
|
414
|
-
isDynamic && removeSync(loadModule)
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
try {
|
|
418
|
-
const res = attemptLoad({
|
|
419
|
-
forceExports: true,
|
|
420
|
-
})
|
|
421
|
-
didBabel = true
|
|
422
|
-
return res
|
|
423
|
-
} catch (err) {
|
|
424
|
-
console.log('babel err', err, writtenContents)
|
|
425
|
-
// ok
|
|
426
|
-
writtenContents = fileContents
|
|
427
|
-
if (process.env.DEBUG?.startsWith('tamagui')) {
|
|
428
|
-
console.log(`Error parsing babel likely`, err)
|
|
429
|
-
}
|
|
430
|
-
} finally {
|
|
431
|
-
dispose()
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
try {
|
|
435
|
-
return attemptLoad({
|
|
436
|
-
forceExports: false,
|
|
437
|
-
})
|
|
438
|
-
} catch (err) {
|
|
439
|
-
if (!process.env.TAMAGUI_DISABLE_WARN_DYNAMIC_LOAD) {
|
|
440
|
-
console.log(`
|
|
441
|
-
|
|
442
|
-
Tamagui attempted but failed to dynamically load components in:
|
|
443
|
-
${name}
|
|
444
|
-
|
|
445
|
-
This will leave some styled() tags unoptimized.
|
|
446
|
-
Disable this file (or dynamic loading altogether):
|
|
447
|
-
|
|
448
|
-
disableExtractFoundComponents: ['${name}'] | true
|
|
181
|
+
}
|
|
449
182
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
183
|
+
export async function watchTamaguiConfig(tamaguiOptions: TamaguiOptions) {
|
|
184
|
+
const options = await getOptions({ tamaguiOptions })
|
|
185
|
+
|
|
186
|
+
if (!options.tamaguiOptions.config) return
|
|
187
|
+
|
|
188
|
+
await generateTamaguiConfig(options)
|
|
189
|
+
const context = await esbuild.context({
|
|
190
|
+
entryPoints: [options.tamaguiOptions.config],
|
|
191
|
+
sourcemap: false,
|
|
192
|
+
// dont output just use esbuild as a watcher
|
|
193
|
+
write: false,
|
|
194
|
+
|
|
195
|
+
plugins: [
|
|
196
|
+
{
|
|
197
|
+
name: `on-rebuild`,
|
|
198
|
+
setup({ onEnd }) {
|
|
199
|
+
onEnd((res) => {
|
|
200
|
+
generateTamaguiConfig(options)
|
|
201
|
+
})
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
})
|
|
453
206
|
|
|
454
|
-
|
|
455
|
-
console.log(err)
|
|
456
|
-
console.log(
|
|
457
|
-
`At: ${loadModule}`,
|
|
458
|
-
`\ndidBabel: ${didBabel}`,
|
|
459
|
-
`\nIn:`,
|
|
460
|
-
writtenContents,
|
|
461
|
-
`\nisDynamic: `,
|
|
462
|
-
isDynamic
|
|
463
|
-
)
|
|
464
|
-
}
|
|
465
|
-
return []
|
|
466
|
-
} finally {
|
|
467
|
-
dispose()
|
|
468
|
-
}
|
|
469
|
-
})
|
|
470
|
-
cacheComponents[key] = info
|
|
471
|
-
return info
|
|
472
|
-
} catch (err: any) {
|
|
473
|
-
console.log(`Tamagui error bundling components`, err.message, err.stack)
|
|
474
|
-
return null
|
|
475
|
-
}
|
|
207
|
+
await context.watch()
|
|
476
208
|
}
|
|
477
209
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
try {
|
|
481
|
-
if (!exported || typeof exported !== 'object' || Array.isArray(exported)) {
|
|
482
|
-
throw new Error(`Invalid export from package ${name}: ${typeof exported}`)
|
|
483
|
-
}
|
|
484
|
-
for (const key in exported) {
|
|
485
|
-
const found = getTamaguiComponent(key, exported[key])
|
|
486
|
-
if (found) {
|
|
487
|
-
// remove non-stringifyable
|
|
488
|
-
const { Component, ...sc } = found.staticConfig
|
|
489
|
-
components[key] = { staticConfig: sc }
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
} catch (err) {
|
|
493
|
-
if (process.env.TAMAGUI_DISABLE_WARN_DYNAMIC_LOAD !== '1') {
|
|
494
|
-
console.error(
|
|
495
|
-
`Tamagui failed getting from ${name} (Disable error by setting environment variable TAMAGUI_DISABLE_WARN_DYNAMIC_LOAD=1)`
|
|
496
|
-
)
|
|
497
|
-
console.error(err)
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
return components
|
|
501
|
-
}
|
|
210
|
+
const defaultPaths = ['tamagui.config.ts', join('src', 'tamagui.config.ts')]
|
|
211
|
+
let cachedPath = ''
|
|
502
212
|
|
|
503
|
-
function
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
const staticConfig = Component?.staticConfig as StaticConfigParsed | undefined
|
|
511
|
-
if (staticConfig) {
|
|
512
|
-
return Component
|
|
213
|
+
async function getDefaultTamaguiConfigPath() {
|
|
214
|
+
if (cachedPath) return cachedPath
|
|
215
|
+
const existingPaths = await Promise.all(defaultPaths.map((path) => pathExists(path)))
|
|
216
|
+
const existing = existingPaths.findIndex((x) => !!x)
|
|
217
|
+
const found = defaultPaths[existing]
|
|
218
|
+
if (!found) {
|
|
219
|
+
throw new Error(`No found tamagui.config.ts`)
|
|
513
220
|
}
|
|
221
|
+
cachedPath = found
|
|
222
|
+
return found
|
|
514
223
|
}
|
|
224
|
+
|
|
225
|
+
export { TamaguiProjectInfo }
|
package/src/types.ts
CHANGED
|
@@ -2,11 +2,10 @@ import type { NodePath } from '@babel/traverse'
|
|
|
2
2
|
import * as t from '@babel/types'
|
|
3
3
|
import type { PseudoStyles, StaticConfig } from '@tamagui/core-node'
|
|
4
4
|
import type { StyleObject } from '@tamagui/helpers'
|
|
5
|
-
// @ts-ignore
|
|
6
5
|
import type { TamaguiOptions } from '@tamagui/types'
|
|
7
6
|
import type { ViewStyle } from 'react-native'
|
|
7
|
+
import { LoadedComponents } from './extractor/bundleConfig'
|
|
8
8
|
|
|
9
|
-
import { LoadedComponents } from './index.js'
|
|
10
9
|
|
|
11
10
|
// @ts-ignore
|
|
12
11
|
export type { TamaguiOptions } from '@tamagui/types'
|
|
@@ -100,4 +99,4 @@ export type ClassNameToStyleObj = {
|
|
|
100
99
|
|
|
101
100
|
export interface PluginContext {
|
|
102
101
|
write: (path: string, rules: { [key: string]: string }) => any
|
|
103
|
-
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { StaticConfigParsed, TamaguiInternalConfig } from '@tamagui/web';
|
|
2
|
+
type NameToPaths = {
|
|
3
|
+
[key: string]: Set<string>;
|
|
4
|
+
};
|
|
5
|
+
export type LoadedComponents = {
|
|
6
|
+
moduleName: string;
|
|
7
|
+
nameToInfo: Record<string, {
|
|
8
|
+
staticConfig: StaticConfigParsed;
|
|
9
|
+
}>;
|
|
10
|
+
};
|
|
11
|
+
export type TamaguiProjectInfo = {
|
|
12
|
+
components: LoadedComponents[];
|
|
13
|
+
tamaguiConfig: TamaguiInternalConfig;
|
|
14
|
+
nameToPaths: NameToPaths;
|
|
15
|
+
};
|
|
16
|
+
export type Props = {
|
|
17
|
+
components: string[];
|
|
18
|
+
config?: string;
|
|
19
|
+
forceExports?: boolean;
|
|
20
|
+
};
|
|
21
|
+
export declare const esbuildOptions: {
|
|
22
|
+
readonly loader: "tsx";
|
|
23
|
+
readonly target: "es2018";
|
|
24
|
+
readonly format: "cjs";
|
|
25
|
+
readonly jsx: "transform";
|
|
26
|
+
readonly platform: "node";
|
|
27
|
+
};
|
|
28
|
+
export declare function bundleConfig(props: Props): Promise<{
|
|
29
|
+
components: LoadedComponents[];
|
|
30
|
+
nameToPaths: {};
|
|
31
|
+
tamaguiConfig: any;
|
|
32
|
+
}>;
|
|
33
|
+
export declare function loadComponents(props: Props): null | LoadedComponents[];
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=bundleConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundleConfig.d.ts","sourceRoot":"","sources":["../../src/extractor/bundleConfig.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAS7E,KAAK,WAAW,GAAG;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAAA;CAC3B,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAChB,MAAM,EACN;QACE,YAAY,EAAE,kBAAkB,CAAA;KACjC,CACF,CAAA;CACF,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE,gBAAgB,EAAE,CAAA;IAC9B,aAAa,EAAE,qBAAqB,CAAA;IACpC,WAAW,EAAE,WAAW,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,KAAK,GAAG;IAClB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA;AAWD,eAAO,MAAM,cAAc;;;;;;CAMjB,CAAA;AAEV,wBAAsB,YAAY,CAAC,KAAK,EAAE,KAAK;;;;GAgH9C;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,GAAG,gBAAgB,EAAE,CAgHtE"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { NodePath } from '@babel/traverse';
|
|
2
2
|
import * as t from '@babel/types';
|
|
3
3
|
import type { ExtractorOptions, ExtractorParseProps, TamaguiOptions } from '../types.js';
|
|
4
|
+
import { TamaguiProjectInfo } from './bundleConfig.js';
|
|
4
5
|
import { cleanupBeforeExit } from './getStaticBindingsForScope.js';
|
|
5
|
-
import { TamaguiProjectInfo } from './loadTamagui.js';
|
|
6
6
|
export type Extractor = ReturnType<typeof createExtractor>;
|
|
7
7
|
type FileOrPath = NodePath<t.Program> | t.File;
|
|
8
8
|
export declare function createExtractor({ logger }?: ExtractorOptions): {
|
|
@@ -12,7 +12,7 @@ export declare function createExtractor({ logger }?: ExtractorOptions): {
|
|
|
12
12
|
cleanupBeforeExit: typeof cleanupBeforeExit;
|
|
13
13
|
loadTamagui: (props: TamaguiOptions) => Promise<TamaguiProjectInfo>;
|
|
14
14
|
loadTamaguiSync: (props: TamaguiOptions) => TamaguiProjectInfo;
|
|
15
|
-
getTamagui():
|
|
15
|
+
getTamagui(): import("@tamagui/web").TamaguiInternalConfig | undefined;
|
|
16
16
|
parseSync: (f: FileOrPath, props: ExtractorParseProps) => {
|
|
17
17
|
styled: number;
|
|
18
18
|
flattened: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createExtractor.d.ts","sourceRoot":"","sources":["../../src/extractor/createExtractor.ts"],"names":[],"mappings":"AAGA,OAAiB,EAAE,QAAQ,EAAmB,MAAM,iBAAiB,CAAA;AACrE,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"createExtractor.d.ts","sourceRoot":"","sources":["../../src/extractor/createExtractor.ts"],"names":[],"mappings":"AAGA,OAAiB,EAAE,QAAQ,EAAmB,MAAM,iBAAiB,CAAA;AACrE,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;AAajC,OAAO,KAAK,EAIV,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EAGf,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAatD,OAAO,EACL,iBAAiB,EAElB,MAAM,gCAAgC,CAAA;AAmCvC,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA;AAE1D,KAAK,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAA;AAI9C,wBAAgB,eAAe,CAC7B,EAAE,MAAgB,EAAE,GAAE,gBAAsC;;;;;yBA4BjC,cAAc;6BAPhB,cAAc;;mBAwBtB,UAAU,SAAS,mBAAmB;;;;;;;eAIpC,UAAU,SAAS,mBAAmB;;;;;;;EAo9D1D"}
|
|
@@ -11,14 +11,14 @@ export declare function isValidThemeHook(props: TamaguiOptionsWithFileInfo, jsxP
|
|
|
11
11
|
export declare const isInsideComponentPackage: (props: TamaguiOptionsWithFileInfo, moduleName: string) => any;
|
|
12
12
|
export declare const isComponentPackage: (props: TamaguiOptionsWithFileInfo, srcName: string) => any;
|
|
13
13
|
export declare function getValidComponent(props: TamaguiOptionsWithFileInfo, moduleName: string, componentName: string): false | {
|
|
14
|
-
staticConfig: StaticConfigParsed;
|
|
14
|
+
staticConfig: import("@tamagui/web").StaticConfigParsed;
|
|
15
15
|
} | null;
|
|
16
16
|
export declare const isValidModule: (props: TamaguiOptionsWithFileInfo, moduleName: string) => {
|
|
17
17
|
isLocal: boolean;
|
|
18
18
|
isValid: any;
|
|
19
19
|
};
|
|
20
20
|
export declare const getValidImport: (props: TamaguiOptionsWithFileInfo, moduleName: string, componentName?: string) => {
|
|
21
|
-
staticConfig: StaticConfigParsed;
|
|
21
|
+
staticConfig: import("@tamagui/web").StaticConfigParsed;
|
|
22
22
|
} | null;
|
|
23
23
|
export declare const isValidImport: (props: TamaguiOptionsWithFileInfo, moduleName: string, componentName?: string) => any;
|
|
24
24
|
//# sourceMappingURL=extractHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateTamaguiConfig.d.ts","sourceRoot":"","sources":["../../src/extractor/generateTamaguiConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AASnD,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,kBAAkB,iBAsDtE"}
|
|
@@ -1,25 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
export type LoadedComponents = {
|
|
6
|
-
moduleName: string;
|
|
7
|
-
nameToInfo: Record<string, {
|
|
8
|
-
staticConfig: StaticConfigParsed;
|
|
9
|
-
}>;
|
|
10
|
-
};
|
|
11
|
-
export type TamaguiProjectInfo = {
|
|
12
|
-
components: LoadedComponents[];
|
|
13
|
-
tamaguiConfig: TamaguiInternalConfig;
|
|
14
|
-
nameToPaths: NameToPaths;
|
|
15
|
-
};
|
|
16
|
-
type Props = {
|
|
17
|
-
components: string[];
|
|
18
|
-
config?: string;
|
|
19
|
-
forceExports?: boolean;
|
|
20
|
-
};
|
|
1
|
+
import { CLIResolvedOptions, CLIUserOptions } from '@tamagui/types';
|
|
2
|
+
import { TamaguiOptions } from '../types.js';
|
|
3
|
+
import { Props, TamaguiProjectInfo } from './bundleConfig.js';
|
|
21
4
|
export declare function loadTamagui(props: Props): Promise<TamaguiProjectInfo>;
|
|
22
5
|
export declare function resolveWebOrNativeSpecificEntry(entry: string): string;
|
|
23
6
|
export declare function loadTamaguiSync(props: Props): TamaguiProjectInfo;
|
|
24
|
-
export {}
|
|
7
|
+
export declare function getOptions({ root, tsconfigPath, tamaguiOptions, host, debug, }?: Partial<CLIUserOptions>): Promise<CLIResolvedOptions>;
|
|
8
|
+
export declare function watchTamaguiConfig(tamaguiOptions: TamaguiOptions): Promise<void>;
|
|
9
|
+
export { TamaguiProjectInfo };
|
|
25
10
|
//# sourceMappingURL=loadTamagui.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadTamagui.d.ts","sourceRoot":"","sources":["../../src/extractor/loadTamagui.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loadTamagui.d.ts","sourceRoot":"","sources":["../../src/extractor/loadTamagui.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAOnE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EACL,KAAK,EACL,kBAAkB,EAInB,MAAM,mBAAmB,CAAA;AAK1B,wBAAsB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA6B3E;AAED,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,MAAM,UAW5D;AAGD,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,kBAAkB,CA+EhE;AAED,wBAAsB,UAAU,CAAC,EAC/B,IAAoB,EACpB,YAA8B,EAC9B,cAAc,EACd,IAAI,EACJ,KAAK,GACN,GAAE,OAAO,CAAC,cAAc,CAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAyB5D;AAED,wBAAsB,kBAAkB,CAAC,cAAc,EAAE,cAAc,iBAyBtE;AAiBD,OAAO,EAAE,kBAAkB,EAAE,CAAA"}
|
package/types/types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { PseudoStyles, StaticConfig } from '@tamagui/core-node';
|
|
|
4
4
|
import type { StyleObject } from '@tamagui/helpers';
|
|
5
5
|
import type { TamaguiOptions } from '@tamagui/types';
|
|
6
6
|
import type { ViewStyle } from 'react-native';
|
|
7
|
-
import { LoadedComponents } from './
|
|
7
|
+
import { LoadedComponents } from './extractor/bundleConfig';
|
|
8
8
|
export type { TamaguiOptions } from '@tamagui/types';
|
|
9
9
|
export type { StyleObject } from '@tamagui/helpers';
|
|
10
10
|
export type ClassNameObject = t.StringLiteral | t.Expression;
|
package/types/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;AACjC,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;AACjC,OAAO,KAAK,EAA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