@tamagui/static 2.7.7 → 3.0.0-beta.643.1
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/check-dep-versions.cjs +355 -0
- package/dist/cjs/checkDeps.cjs +302 -0
- package/dist/cjs/compiler.cjs +286 -0
- package/dist/cjs/compilerHost.cjs +1695 -0
- package/dist/cjs/constants.cjs +33 -0
- package/dist/cjs/domStructuralPass.cjs +112 -0
- package/dist/cjs/exports.cjs +42 -0
- package/dist/cjs/extractor/addLocalExports.cjs +64 -0
- package/dist/cjs/extractor/bundle.cjs +203 -0
- package/dist/cjs/extractor/bundleConfig.cjs +747 -0
- package/dist/cjs/extractor/concatClassName.cjs +117 -0
- package/dist/cjs/extractor/detectModuleFormat.cjs +54 -0
- package/dist/cjs/extractor/esbuildAliasPlugin.cjs +47 -0
- package/dist/cjs/extractor/esbuildTsconfigPaths.cjs +92 -0
- package/dist/cjs/extractor/getTamaguiConfigPathFromOptionsConfig.cjs +38 -0
- package/dist/cjs/extractor/loadTamagui.cjs +344 -0
- package/dist/cjs/extractor/regenerateConfig.cjs +161 -0
- package/dist/cjs/extractor/watchTamaguiConfig.cjs +64 -0
- package/dist/cjs/getPragmaOptions.cjs +67 -0
- package/dist/cjs/helpers/memoize.cjs +42 -0
- package/dist/cjs/helpers/requireTamaguiCore.cjs +40 -0
- package/dist/cjs/index.cjs +34 -0
- package/dist/cjs/registerRequire.cjs +220 -0
- package/dist/cjs/server.cjs +66 -0
- package/dist/cjs/staticEvaluationIgnoredModules.cjs +86 -0
- package/dist/cjs/types.cjs +17 -0
- package/dist/cjs/zero/artifact.cjs +145 -0
- package/dist/cjs/zero/graph.cjs +209 -0
- package/dist/cjs/zero/identity.cjs +61 -0
- package/dist/cjs/zero/index.cjs +26 -0
- package/dist/cjs/zero/islands.cjs +232 -0
- package/dist/cjs/zero/options.cjs +163 -0
- package/dist/cjs/zero/ownership.cjs +79 -0
- package/dist/cjs/zero/theme.cjs +328 -0
- package/dist/cjs/zero/transform.cjs +203 -0
- package/dist/esm/check-dep-versions.mjs +329 -0
- package/dist/esm/check-dep-versions.mjs.map +1 -0
- package/dist/esm/checkDeps.mjs +279 -0
- package/dist/esm/checkDeps.mjs.map +1 -0
- package/dist/esm/compiler.mjs +255 -0
- package/dist/esm/compiler.mjs.map +1 -0
- package/dist/esm/compilerHost.mjs +1675 -0
- package/dist/esm/compilerHost.mjs.map +1 -0
- package/dist/esm/constants.mjs +7 -0
- package/dist/esm/constants.mjs.map +1 -0
- package/dist/esm/domStructuralPass.mjs +92 -0
- package/dist/esm/domStructuralPass.mjs.map +1 -0
- package/dist/esm/exports.mjs +26 -0
- package/dist/esm/extractor/addLocalExports.mjs +44 -0
- package/dist/esm/extractor/addLocalExports.mjs.map +1 -0
- package/dist/esm/extractor/bundle.mjs +173 -0
- package/dist/esm/extractor/bundle.mjs.map +1 -0
- package/dist/esm/extractor/bundleConfig.mjs +706 -0
- package/dist/esm/extractor/bundleConfig.mjs.map +1 -0
- package/dist/esm/extractor/concatClassName.mjs +96 -0
- package/dist/esm/extractor/concatClassName.mjs.map +1 -0
- package/dist/esm/extractor/detectModuleFormat.mjs +31 -0
- package/dist/esm/extractor/detectModuleFormat.mjs.map +1 -0
- package/dist/esm/extractor/esbuildAliasPlugin.mjs +26 -0
- package/dist/esm/extractor/esbuildAliasPlugin.mjs.map +1 -0
- package/dist/esm/extractor/esbuildTsconfigPaths.mjs +63 -0
- package/dist/esm/extractor/esbuildTsconfigPaths.mjs.map +1 -0
- package/dist/esm/extractor/getTamaguiConfigPathFromOptionsConfig.mjs +18 -0
- package/dist/esm/extractor/getTamaguiConfigPathFromOptionsConfig.mjs.map +1 -0
- package/dist/esm/extractor/loadTamagui.mjs +306 -0
- package/dist/esm/extractor/loadTamagui.mjs.map +1 -0
- package/dist/esm/extractor/regenerateConfig.mjs +131 -0
- package/dist/esm/extractor/regenerateConfig.mjs.map +1 -0
- package/dist/esm/extractor/watchTamaguiConfig.mjs +43 -0
- package/dist/esm/extractor/watchTamaguiConfig.mjs.map +1 -0
- package/dist/esm/getPragmaOptions.mjs +46 -0
- package/dist/esm/getPragmaOptions.mjs.map +1 -0
- package/dist/esm/helpers/memoize.mjs +21 -0
- package/dist/esm/helpers/memoize.mjs.map +1 -0
- package/dist/esm/helpers/requireTamaguiCore.mjs +19 -0
- package/dist/esm/helpers/requireTamaguiCore.mjs.map +1 -0
- package/dist/esm/index.mjs +8 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/registerRequire.mjs +195 -0
- package/dist/esm/registerRequire.mjs.map +1 -0
- package/dist/esm/server.mjs +40 -0
- package/dist/esm/server.mjs.map +1 -0
- package/dist/esm/setup.mjs +0 -0
- package/dist/esm/staticEvaluationIgnoredModules.mjs +61 -0
- package/dist/esm/staticEvaluationIgnoredModules.mjs.map +1 -0
- package/dist/esm/types.mjs +0 -0
- package/dist/esm/zero/artifact.mjs +119 -0
- package/dist/esm/zero/artifact.mjs.map +1 -0
- package/dist/esm/zero/graph.mjs +170 -0
- package/dist/esm/zero/graph.mjs.map +1 -0
- package/dist/esm/zero/identity.mjs +36 -0
- package/dist/esm/zero/identity.mjs.map +1 -0
- package/dist/esm/zero/index.mjs +15 -0
- package/dist/esm/zero/islands.mjs +197 -0
- package/dist/esm/zero/islands.mjs.map +1 -0
- package/dist/esm/zero/options.mjs +129 -0
- package/dist/esm/zero/options.mjs.map +1 -0
- package/dist/esm/zero/ownership.mjs +48 -0
- package/dist/esm/zero/ownership.mjs.map +1 -0
- package/dist/esm/zero/theme.mjs +303 -0
- package/dist/esm/zero/theme.mjs.map +1 -0
- package/dist/esm/zero/transform.mjs +177 -0
- package/dist/esm/zero/transform.mjs.map +1 -0
- package/package.json +33 -43
- package/src/check-dep-versions.ts +2 -2
- package/src/checkDeps.ts +3 -2
- package/src/compiler.ts +425 -0
- package/src/compilerHost.ts +3125 -0
- package/src/constants.ts +0 -5
- package/src/domStructuralPass.ts +170 -0
- package/src/exports.ts +3 -6
- package/src/extractor/addLocalExports.ts +49 -0
- package/src/extractor/bundle.ts +20 -35
- package/src/extractor/bundleConfig.ts +334 -187
- package/src/extractor/concatClassName.ts +13 -20
- package/src/extractor/getTamaguiConfigPathFromOptionsConfig.ts +5 -4
- package/src/extractor/loadTamagui.ts +196 -143
- package/src/extractor/regenerateConfig.ts +65 -13
- package/src/extractor/watchTamaguiConfig.ts +6 -1
- package/src/helpers/requireTamaguiCore.ts +6 -1
- package/src/registerRequire.ts +94 -132
- package/src/staticEvaluationIgnoredModules.ts +74 -0
- package/src/types.ts +2 -107
- package/src/zero/artifact.ts +142 -0
- package/src/zero/graph.ts +359 -0
- package/src/zero/identity.ts +73 -0
- package/src/zero/index.ts +8 -0
- package/src/zero/islands.ts +262 -0
- package/src/zero/options.ts +239 -0
- package/src/zero/ownership.ts +113 -0
- package/src/zero/theme.ts +478 -0
- package/src/zero/transform.ts +320 -0
- package/types/check-dep-versions.d.ts.map +1 -1
- package/types/checkDeps.d.ts.map +1 -1
- package/types/compiler.d.ts +117 -0
- package/types/compiler.d.ts.map +1 -0
- package/types/compilerHost.d.ts +25 -0
- package/types/compilerHost.d.ts.map +1 -0
- package/types/constants.d.ts +0 -1
- package/types/constants.d.ts.map +1 -1
- package/types/domStructuralPass.d.ts +3 -0
- package/types/domStructuralPass.d.ts.map +1 -0
- package/types/exports.d.ts +3 -6
- package/types/exports.d.ts.map +1 -1
- package/types/extractor/addLocalExports.d.ts +3 -0
- package/types/extractor/addLocalExports.d.ts.map +1 -0
- package/types/extractor/bundle.d.ts +66 -65
- package/types/extractor/bundle.d.ts.map +1 -1
- package/types/extractor/bundleConfig.d.ts +19 -4
- package/types/extractor/bundleConfig.d.ts.map +1 -1
- package/types/extractor/esbuildAliasPlugin.d.ts.map +1 -1
- package/types/extractor/getTamaguiConfigPathFromOptionsConfig.d.ts +1 -1
- package/types/extractor/getTamaguiConfigPathFromOptionsConfig.d.ts.map +1 -1
- package/types/extractor/loadTamagui.d.ts +26 -3
- package/types/extractor/loadTamagui.d.ts.map +1 -1
- package/types/extractor/regenerateConfig.d.ts +1 -1
- package/types/extractor/regenerateConfig.d.ts.map +1 -1
- package/types/extractor/watchTamaguiConfig.d.ts.map +1 -1
- package/types/getPragmaOptions.d.ts +1 -1
- package/types/helpers/memoize.d.ts +1 -1
- package/types/helpers/memoize.d.ts.map +1 -1
- package/types/helpers/requireTamaguiCore.d.ts.map +1 -1
- package/types/index.d.ts.map +1 -1
- package/types/registerRequire.d.ts +2 -2
- package/types/registerRequire.d.ts.map +1 -1
- package/types/staticEvaluationIgnoredModules.d.ts +9 -0
- package/types/staticEvaluationIgnoredModules.d.ts.map +1 -0
- package/types/types.d.ts +2 -90
- package/types/types.d.ts.map +1 -1
- package/types/zero/artifact.d.ts +44 -0
- package/types/zero/artifact.d.ts.map +1 -0
- package/types/zero/graph.d.ts +139 -0
- package/types/zero/graph.d.ts.map +1 -0
- package/types/zero/identity.d.ts +33 -0
- package/types/zero/identity.d.ts.map +1 -0
- package/types/zero/index.d.ts +9 -0
- package/types/zero/index.d.ts.map +1 -0
- package/types/zero/islands.d.ts +56 -0
- package/types/zero/islands.d.ts.map +1 -0
- package/types/zero/options.d.ts +58 -0
- package/types/zero/options.d.ts.map +1 -0
- package/types/zero/ownership.d.ts +51 -0
- package/types/zero/ownership.d.ts.map +1 -0
- package/types/zero/theme.d.ts +83 -0
- package/types/zero/theme.d.ts.map +1 -0
- package/types/zero/transform.d.ts +53 -0
- package/types/zero/transform.d.ts.map +1 -0
- package/dist/check-dep-versions.cjs +0 -372
- package/dist/checkDeps.cjs +0 -271
- package/dist/constants.cjs +0 -51
- package/dist/exports.cjs +0 -48
- package/dist/extractor/accessSafe.cjs +0 -48
- package/dist/extractor/babelParse.cjs +0 -56
- package/dist/extractor/buildClassName.cjs +0 -86
- package/dist/extractor/bundle.cjs +0 -234
- package/dist/extractor/bundleConfig.cjs +0 -729
- package/dist/extractor/concatClassName.cjs +0 -129
- package/dist/extractor/createEvaluator.cjs +0 -88
- package/dist/extractor/createExtractor.cjs +0 -1968
- package/dist/extractor/createLogger.cjs +0 -50
- package/dist/extractor/detectModuleFormat.cjs +0 -55
- package/dist/extractor/ensureImportingConcat.cjs +0 -54
- package/dist/extractor/errors.cjs +0 -28
- package/dist/extractor/esbuildAliasPlugin.cjs +0 -56
- package/dist/extractor/esbuildTsconfigPaths.cjs +0 -108
- package/dist/extractor/evaluateAstNode.cjs +0 -128
- package/dist/extractor/extractHelpers.cjs +0 -182
- package/dist/extractor/extractMediaStyle.cjs +0 -169
- package/dist/extractor/extractToClassNames.cjs +0 -475
- package/dist/extractor/extractToNative.cjs +0 -369
- package/dist/extractor/findTopmostFunction.cjs +0 -43
- package/dist/extractor/generatedUid.cjs +0 -58
- package/dist/extractor/getPrefixLogs.cjs +0 -31
- package/dist/extractor/getPropValueFromAttributes.cjs +0 -85
- package/dist/extractor/getSourceModule.cjs +0 -100
- package/dist/extractor/getStaticBindingsForScope.cjs +0 -213
- package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.cjs +0 -41
- package/dist/extractor/hasTopLevelAwait.cjs +0 -62
- package/dist/extractor/hoistClassNames.cjs +0 -76
- package/dist/extractor/literalToAst.cjs +0 -109
- package/dist/extractor/loadFile.cjs +0 -17
- package/dist/extractor/loadTamagui.cjs +0 -373
- package/dist/extractor/logLines.cjs +0 -43
- package/dist/extractor/normalizeTernaries.cjs +0 -100
- package/dist/extractor/propsToFontFamilyCache.cjs +0 -42
- package/dist/extractor/regenerateConfig.cjs +0 -178
- package/dist/extractor/removeUnusedHooks.cjs +0 -108
- package/dist/extractor/timer.cjs +0 -52
- package/dist/extractor/validHTMLAttributes.cjs +0 -79
- package/dist/extractor/watchTamaguiConfig.cjs +0 -70
- package/dist/getPragmaOptions.cjs +0 -73
- package/dist/helpers/memoize.cjs +0 -45
- package/dist/helpers/requireTamaguiCore.cjs +0 -40
- package/dist/index.cjs +0 -42
- package/dist/registerRequire.cjs +0 -209
- package/dist/server.cjs +0 -82
- package/dist/types.cjs +0 -18
- package/dist/worker.cjs +0 -111
- package/src/extractor/accessSafe.ts +0 -22
- package/src/extractor/babelParse.ts +0 -38
- package/src/extractor/buildClassName.ts +0 -76
- package/src/extractor/createEvaluator.ts +0 -82
- package/src/extractor/createExtractor.ts +0 -2970
- package/src/extractor/createLogger.ts +0 -41
- package/src/extractor/ensureImportingConcat.ts +0 -36
- package/src/extractor/errors.ts +0 -1
- package/src/extractor/evaluateAstNode.ts +0 -136
- package/src/extractor/extractHelpers.ts +0 -211
- package/src/extractor/extractMediaStyle.ts +0 -194
- package/src/extractor/extractToClassNames.ts +0 -733
- package/src/extractor/extractToNative.ts +0 -506
- package/src/extractor/findTopmostFunction.ts +0 -24
- package/src/extractor/generatedUid.ts +0 -41
- package/src/extractor/getPrefixLogs.ts +0 -9
- package/src/extractor/getPropValueFromAttributes.ts +0 -95
- package/src/extractor/getSourceModule.ts +0 -96
- package/src/extractor/getStaticBindingsForScope.ts +0 -237
- package/src/extractor/hasTopLevelAwait.ts +0 -28
- package/src/extractor/hoistClassNames.ts +0 -52
- package/src/extractor/literalToAst.ts +0 -85
- package/src/extractor/loadFile.ts +0 -17
- package/src/extractor/logLines.ts +0 -16
- package/src/extractor/normalizeTernaries.ts +0 -89
- package/src/extractor/propsToFontFamilyCache.ts +0 -18
- package/src/extractor/removeUnusedHooks.ts +0 -83
- package/src/extractor/timer.ts +0 -25
- package/src/extractor/validHTMLAttributes.ts +0 -52
- package/src/worker.ts +0 -142
- package/types/extractor/accessSafe.d.ts +0 -3
- package/types/extractor/accessSafe.d.ts.map +0 -1
- package/types/extractor/babelParse.d.ts +0 -5
- package/types/extractor/babelParse.d.ts.map +0 -1
- package/types/extractor/buildClassName.d.ts +0 -7
- package/types/extractor/buildClassName.d.ts.map +0 -1
- package/types/extractor/createEvaluator.d.ts +0 -12
- package/types/extractor/createEvaluator.d.ts.map +0 -1
- package/types/extractor/createExtractor.d.ts +0 -32
- package/types/extractor/createExtractor.d.ts.map +0 -1
- package/types/extractor/createLogger.d.ts +0 -3
- package/types/extractor/createLogger.d.ts.map +0 -1
- package/types/extractor/ensureImportingConcat.d.ts +0 -4
- package/types/extractor/ensureImportingConcat.d.ts.map +0 -1
- package/types/extractor/errors.d.ts +0 -3
- package/types/extractor/errors.d.ts.map +0 -1
- package/types/extractor/evaluateAstNode.d.ts +0 -3
- package/types/extractor/evaluateAstNode.d.ts.map +0 -1
- package/types/extractor/extractHelpers.d.ts +0 -28
- package/types/extractor/extractHelpers.d.ts.map +0 -1
- package/types/extractor/extractMediaStyle.d.ts +0 -11
- package/types/extractor/extractMediaStyle.d.ts.map +0 -1
- package/types/extractor/extractToClassNames.d.ts +0 -25
- package/types/extractor/extractToClassNames.d.ts.map +0 -1
- package/types/extractor/extractToNative.d.ts +0 -13
- package/types/extractor/extractToNative.d.ts.map +0 -1
- package/types/extractor/findTopmostFunction.d.ts +0 -4
- package/types/extractor/findTopmostFunction.d.ts.map +0 -1
- package/types/extractor/generatedUid.d.ts +0 -5
- package/types/extractor/generatedUid.d.ts.map +0 -1
- package/types/extractor/getPrefixLogs.d.ts +0 -3
- package/types/extractor/getPrefixLogs.d.ts.map +0 -1
- package/types/extractor/getPropValueFromAttributes.d.ts +0 -19
- package/types/extractor/getPropValueFromAttributes.d.ts.map +0 -1
- package/types/extractor/getSourceModule.d.ts +0 -16
- package/types/extractor/getSourceModule.d.ts.map +0 -1
- package/types/extractor/getStaticBindingsForScope.d.ts +0 -5
- package/types/extractor/getStaticBindingsForScope.d.ts.map +0 -1
- package/types/extractor/hasTopLevelAwait.d.ts +0 -2
- package/types/extractor/hasTopLevelAwait.d.ts.map +0 -1
- package/types/extractor/hoistClassNames.d.ts +0 -6
- package/types/extractor/hoistClassNames.d.ts.map +0 -1
- package/types/extractor/literalToAst.d.ts +0 -4
- package/types/extractor/literalToAst.d.ts.map +0 -1
- package/types/extractor/loadFile.d.ts +0 -1
- package/types/extractor/loadFile.d.ts.map +0 -1
- package/types/extractor/logLines.d.ts +0 -2
- package/types/extractor/logLines.d.ts.map +0 -1
- package/types/extractor/normalizeTernaries.d.ts +0 -5
- package/types/extractor/normalizeTernaries.d.ts.map +0 -1
- package/types/extractor/propsToFontFamilyCache.d.ts +0 -4
- package/types/extractor/propsToFontFamilyCache.d.ts.map +0 -1
- package/types/extractor/removeUnusedHooks.d.ts +0 -3
- package/types/extractor/removeUnusedHooks.d.ts.map +0 -1
- package/types/extractor/timer.d.ts +0 -5
- package/types/extractor/timer.d.ts.map +0 -1
- package/types/extractor/validHTMLAttributes.d.ts +0 -52
- package/types/extractor/validHTMLAttributes.d.ts.map +0 -1
- package/types/worker.d.ts +0 -46
- package/types/worker.d.ts.map +0 -1
- /package/dist/{setup.cjs → cjs/setup.cjs} +0 -0
|
@@ -1,24 +1,36 @@
|
|
|
1
|
-
import generate from '@babel/generator'
|
|
2
|
-
import traverse from '@babel/traverse'
|
|
3
|
-
import * as t from '@babel/types'
|
|
4
1
|
import { createHash } from 'node:crypto'
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
5
3
|
import { existsSync, readFileSync, unlinkSync } from 'node:fs'
|
|
6
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
basename,
|
|
6
|
+
dirname,
|
|
7
|
+
extname,
|
|
8
|
+
isAbsolute,
|
|
9
|
+
join,
|
|
10
|
+
relative,
|
|
11
|
+
resolve,
|
|
12
|
+
sep,
|
|
13
|
+
} from 'node:path'
|
|
7
14
|
import { pathToFileURL } from 'node:url'
|
|
8
15
|
// @ts-ignore why
|
|
9
16
|
import { Color, colorLog } from '@tamagui/cli-color'
|
|
10
17
|
import { type StaticConfig, type TamaguiInternalConfig } from '@tamagui/web'
|
|
11
18
|
import esbuild from 'esbuild'
|
|
12
|
-
import
|
|
19
|
+
import FS from 'fs-extra'
|
|
13
20
|
import { readFile } from 'node:fs/promises'
|
|
14
21
|
import { registerRequire, setRequireResult } from '../registerRequire'
|
|
15
22
|
import type { TamaguiOptions } from '../types'
|
|
16
|
-
import {
|
|
23
|
+
import { addLocalExports } from './addLocalExports'
|
|
17
24
|
import { esbuildLoaderConfig, esbundleTamaguiConfig } from './bundle'
|
|
18
25
|
import { getTamaguiConfigPathFromOptionsConfig } from './getTamaguiConfigPathFromOptionsConfig'
|
|
19
|
-
import { hasTopLevelAwait } from './hasTopLevelAwait'
|
|
20
26
|
import { requireTamaguiCore } from '../helpers/requireTamaguiCore'
|
|
21
27
|
import { detectModuleFormat } from './detectModuleFormat'
|
|
28
|
+
import { staticEvaluationIgnorePlugin } from '../staticEvaluationIgnoredModules'
|
|
29
|
+
|
|
30
|
+
const nodeRequire = createRequire(
|
|
31
|
+
typeof __filename === 'string' ? __filename : import.meta.url
|
|
32
|
+
)
|
|
33
|
+
const componentDisplayName = /* @__PURE__ */ Symbol.for('tamagui.componentDisplayName')
|
|
22
34
|
|
|
23
35
|
// track temp files for cleanup on exit
|
|
24
36
|
const activeTempFiles = new Set<string>()
|
|
@@ -45,10 +57,10 @@ function getEsbuildStdinLoader(filePath: string): esbuild.Loader {
|
|
|
45
57
|
|
|
46
58
|
function resolvePackageEntry(packageName: string, format: 'esm' | 'cjs') {
|
|
47
59
|
if (format === 'cjs') {
|
|
48
|
-
return
|
|
60
|
+
return nodeRequire.resolve(packageName)
|
|
49
61
|
}
|
|
50
62
|
|
|
51
|
-
const packageJsonPath =
|
|
63
|
+
const packageJsonPath = nodeRequire.resolve(`${packageName}/package.json`)
|
|
52
64
|
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'))
|
|
53
65
|
const packageRoot = dirname(packageJsonPath)
|
|
54
66
|
const exportEntry = packageJson.exports?.['.']
|
|
@@ -63,7 +75,7 @@ function resolvePackageEntry(packageName: string, format: 'esm' | 'cjs') {
|
|
|
63
75
|
return join(packageRoot, esmEntry)
|
|
64
76
|
}
|
|
65
77
|
|
|
66
|
-
return
|
|
78
|
+
return nodeRequire.resolve(packageName)
|
|
67
79
|
}
|
|
68
80
|
|
|
69
81
|
function cleanupTempFiles() {
|
|
@@ -95,6 +107,7 @@ export type LoadedComponents = {
|
|
|
95
107
|
string,
|
|
96
108
|
{
|
|
97
109
|
staticConfig: StaticConfig
|
|
110
|
+
displayName?: string
|
|
98
111
|
}
|
|
99
112
|
>
|
|
100
113
|
}
|
|
@@ -104,6 +117,15 @@ export type TamaguiProjectInfo = {
|
|
|
104
117
|
tamaguiConfig?: TamaguiInternalConfig | null
|
|
105
118
|
nameToPaths?: NameToPaths
|
|
106
119
|
cached?: boolean
|
|
120
|
+
dependencies?: string[]
|
|
121
|
+
/**
|
|
122
|
+
* The files whose bytes determine every compiler input this project produced:
|
|
123
|
+
* the evaluated config and each component's static config. The compile cache
|
|
124
|
+
* stamp is hashed from them, so they must be complete - a project that cannot
|
|
125
|
+
* name them gets no stamp and no cache rather than a stamp that misses a
|
|
126
|
+
* config change.
|
|
127
|
+
*/
|
|
128
|
+
stampSources?: string[]
|
|
107
129
|
}
|
|
108
130
|
|
|
109
131
|
const external = [
|
|
@@ -159,19 +181,6 @@ const handleEsmFeaturesPlugin: esbuild.Plugin = {
|
|
|
159
181
|
modified = true
|
|
160
182
|
}
|
|
161
183
|
|
|
162
|
-
// stub files with top-level await - they're typically runtime-only
|
|
163
|
-
if (hasTopLevelAwait(contents, args.path)) {
|
|
164
|
-
if (process.env.DEBUG?.startsWith('tamagui')) {
|
|
165
|
-
console.info(`[tamagui] stubbing file with top-level await: ${args.path}`)
|
|
166
|
-
}
|
|
167
|
-
return {
|
|
168
|
-
// Keep this as an ESM-shaped stub so esbuild doesn't inline a top-level
|
|
169
|
-
// `module.exports = {}` into the parent bundle and wipe its exports.
|
|
170
|
-
contents: `// stubbed - contains top-level await\nexport default {}`,
|
|
171
|
-
loader: 'js',
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
184
|
if (modified) {
|
|
176
185
|
return {
|
|
177
186
|
contents,
|
|
@@ -230,15 +239,61 @@ export function hasBundledConfigChanged() {
|
|
|
230
239
|
let loadedConfig: TamaguiInternalConfig | null = null
|
|
231
240
|
|
|
232
241
|
export const getLoadedConfig = () => loadedConfig
|
|
242
|
+
export const setLoadedConfig = (config: TamaguiInternalConfig) => {
|
|
243
|
+
loadedConfig = config
|
|
244
|
+
}
|
|
233
245
|
|
|
234
246
|
function getBundleKey(props: TamaguiOptions) {
|
|
235
247
|
return JSON.stringify({
|
|
248
|
+
root: props.root,
|
|
236
249
|
components: props.components,
|
|
237
250
|
config: props.config,
|
|
238
251
|
platform: props.platform,
|
|
252
|
+
dangerouslyIgnoreStaticEvaluationModules:
|
|
253
|
+
props.dangerouslyIgnoreStaticEvaluationModules,
|
|
239
254
|
})
|
|
240
255
|
}
|
|
241
256
|
|
|
257
|
+
function getPackageNameFromPath(modulePath: string) {
|
|
258
|
+
const normalized = modulePath.split(sep).join('/')
|
|
259
|
+
const nodeModulesIndex = normalized.lastIndexOf('/node_modules/')
|
|
260
|
+
if (nodeModulesIndex === -1) {
|
|
261
|
+
return normalized.startsWith('.') || isAbsolute(normalized) ? undefined : normalized
|
|
262
|
+
}
|
|
263
|
+
const packagePath = normalized.slice(nodeModulesIndex + '/node_modules/'.length)
|
|
264
|
+
const parts = packagePath.split('/')
|
|
265
|
+
return parts[0]?.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0]
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function findStaticEvaluationError(error: unknown):
|
|
269
|
+
| {
|
|
270
|
+
moduleName: string
|
|
271
|
+
importer: string
|
|
272
|
+
failedModule: string
|
|
273
|
+
reason: string
|
|
274
|
+
}
|
|
275
|
+
| undefined {
|
|
276
|
+
let current = error
|
|
277
|
+
while (current instanceof Error) {
|
|
278
|
+
if (
|
|
279
|
+
'code' in current &&
|
|
280
|
+
current.code === 'TAMAGUI_STATIC_EVALUATION_ERROR' &&
|
|
281
|
+
'moduleName' in current &&
|
|
282
|
+
'importer' in current &&
|
|
283
|
+
'failedModule' in current &&
|
|
284
|
+
'reason' in current
|
|
285
|
+
) {
|
|
286
|
+
return current as Error & {
|
|
287
|
+
moduleName: string
|
|
288
|
+
importer: string
|
|
289
|
+
failedModule: string
|
|
290
|
+
reason: string
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
current = current.cause
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
242
297
|
export async function getBundledConfig(props: TamaguiOptions, rebuild = false) {
|
|
243
298
|
const bundleKey = getBundleKey(props)
|
|
244
299
|
if (isBundling) {
|
|
@@ -248,7 +303,7 @@ export async function getBundledConfig(props: TamaguiOptions, rebuild = false) {
|
|
|
248
303
|
}
|
|
249
304
|
|
|
250
305
|
if (!currentBundle || currentBundleKey !== bundleKey || rebuild) {
|
|
251
|
-
return await bundleConfig(props)
|
|
306
|
+
return await bundleConfig(props, rebuild)
|
|
252
307
|
}
|
|
253
308
|
|
|
254
309
|
return currentBundle
|
|
@@ -269,10 +324,67 @@ let hasBundledOnce = false
|
|
|
269
324
|
// that's acceptable - better than nothing
|
|
270
325
|
let hasLoggedBuild = false
|
|
271
326
|
|
|
272
|
-
|
|
327
|
+
const packageNameByDirectory = new Map<string, string | null>()
|
|
328
|
+
|
|
329
|
+
/** The name of the package a file belongs to, by nearest package.json. */
|
|
330
|
+
function owningPackageName(file: string): string | null {
|
|
331
|
+
let directory = dirname(file)
|
|
332
|
+
const walked: string[] = []
|
|
333
|
+
while (true) {
|
|
334
|
+
const known = packageNameByDirectory.get(directory)
|
|
335
|
+
if (known !== undefined) {
|
|
336
|
+
for (const step of walked) packageNameByDirectory.set(step, known)
|
|
337
|
+
return known
|
|
338
|
+
}
|
|
339
|
+
walked.push(directory)
|
|
340
|
+
const manifest = join(directory, 'package.json')
|
|
341
|
+
if (existsSync(manifest)) {
|
|
342
|
+
let name: string | null = null
|
|
343
|
+
try {
|
|
344
|
+
name = JSON.parse(readFileSync(manifest, 'utf-8')).name ?? null
|
|
345
|
+
} catch {
|
|
346
|
+
name = null
|
|
347
|
+
}
|
|
348
|
+
for (const step of walked) packageNameByDirectory.set(step, name)
|
|
349
|
+
return name
|
|
350
|
+
}
|
|
351
|
+
const parent = dirname(directory)
|
|
352
|
+
if (parent === directory) {
|
|
353
|
+
for (const step of walked) packageNameByDirectory.set(step, null)
|
|
354
|
+
return null
|
|
355
|
+
}
|
|
356
|
+
directory = parent
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Every Tamagui-owned file this process actually loaded, read off the one CJS
|
|
362
|
+
* module cache the compiler host requires through. Derived rather than listed:
|
|
363
|
+
* a hardcoded package list silently misses whatever the engine grows next, and
|
|
364
|
+
* this already covers 20+ packages the compiler reads through @tamagui/core.
|
|
365
|
+
*/
|
|
366
|
+
function requiredTamaguiPackageFiles(): string[] {
|
|
367
|
+
const found: string[] = []
|
|
368
|
+
for (const file of Object.keys(nodeRequire.cache)) {
|
|
369
|
+
if (!file.includes('.')) continue
|
|
370
|
+
const name = owningPackageName(file)
|
|
371
|
+
if (name === 'tamagui' || name?.startsWith('@tamagui/')) found.push(file)
|
|
372
|
+
}
|
|
373
|
+
return found
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export async function bundleConfig(props: TamaguiOptions, rebuild = false) {
|
|
273
377
|
const bundleKey = getBundleKey(props)
|
|
378
|
+
const root = props.root || process.cwd()
|
|
379
|
+
const configEntry = props.config
|
|
380
|
+
? getTamaguiConfigPathFromOptionsConfig(props.config, root)
|
|
381
|
+
: ''
|
|
382
|
+
const baseComponents = (props.components || []).filter((x) => x !== '@tamagui/core')
|
|
383
|
+
let componentOutPaths: string[] = []
|
|
384
|
+
let componentImports: string[][] = []
|
|
274
385
|
// webpack is calling this a ton for no reason
|
|
275
386
|
if (
|
|
387
|
+
!rebuild &&
|
|
276
388
|
global.tamaguiLastBundledConfig &&
|
|
277
389
|
global.tamaguiLastBundledConfigKey === bundleKey &&
|
|
278
390
|
Date.now() - global.tamaguiLastLoaded < 3000
|
|
@@ -284,35 +396,46 @@ export async function bundleConfig(props: TamaguiOptions) {
|
|
|
284
396
|
try {
|
|
285
397
|
isBundling = true
|
|
286
398
|
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
399
|
+
const rootRequire = createRequire(join(root, 'package.json'))
|
|
400
|
+
const tmpDir = join(root, '.tamagui')
|
|
401
|
+
// esbuild inlines process.env.TAMAGUI_TARGET into these bundles (see bundle.ts),
|
|
402
|
+
// so their contents are platform-specific. keep web and native on separate paths:
|
|
403
|
+
// sharing one path let a native bundle be picked up as the web config (and vice
|
|
404
|
+
// versa) by the mtime reuse check below, emitting web classes with no CSS variables.
|
|
405
|
+
const platformSuffix = (props.platform || 'web') === 'native' ? '.native' : '.web'
|
|
291
406
|
// detect module format from config entry point
|
|
292
407
|
const configFormat = configEntry ? detectModuleFormat(configEntry) : 'cjs'
|
|
293
408
|
const configExt = configFormat === 'esm' ? '.mjs' : '.cjs'
|
|
294
|
-
const configOutPath = join(tmpDir, `tamagui.config${configExt}`)
|
|
295
|
-
|
|
296
|
-
//
|
|
409
|
+
const configOutPath = join(tmpDir, `tamagui.config${platformSuffix}${configExt}`)
|
|
410
|
+
// resolve from the consumer root, then walk from the exported subpath because
|
|
411
|
+
// packages are not required to export their package.json
|
|
297
412
|
const componentFormats: Array<'esm' | 'cjs'> = baseComponents.map((mod) => {
|
|
298
413
|
try {
|
|
299
|
-
|
|
300
|
-
|
|
414
|
+
let packageRoot = dirname(rootRequire.resolve(mod))
|
|
415
|
+
while (!existsSync(join(packageRoot, 'package.json'))) {
|
|
416
|
+
const parent = dirname(packageRoot)
|
|
417
|
+
if (parent === packageRoot) {
|
|
418
|
+
return 'cjs'
|
|
419
|
+
}
|
|
420
|
+
packageRoot = parent
|
|
421
|
+
}
|
|
422
|
+
const pkg = JSON.parse(readFileSync(join(packageRoot, 'package.json'), 'utf-8'))
|
|
301
423
|
return pkg.type === 'module' ? 'esm' : 'cjs'
|
|
302
424
|
} catch {
|
|
303
425
|
return 'cjs'
|
|
304
426
|
}
|
|
305
427
|
})
|
|
306
|
-
|
|
428
|
+
componentOutPaths = baseComponents.map((componentModule, i) => {
|
|
307
429
|
const ext = componentFormats[i] === 'esm' ? '.mjs' : '.cjs'
|
|
308
430
|
return join(
|
|
309
431
|
tmpDir,
|
|
310
432
|
`${componentModule
|
|
311
433
|
.split(sep)
|
|
312
434
|
.join('-')
|
|
313
|
-
.replace(/[^a-z0-9]+/gi, '')}-components.config${ext}`
|
|
435
|
+
.replace(/[^a-z0-9]+/gi, '')}-components.config${platformSuffix}${ext}`
|
|
314
436
|
)
|
|
315
437
|
})
|
|
438
|
+
let compilerDependencies: string[] = currentBundle?.dependencies ?? []
|
|
316
439
|
|
|
317
440
|
if (
|
|
318
441
|
process.env.NODE_ENV === 'development' &&
|
|
@@ -325,8 +448,8 @@ export async function bundleConfig(props: TamaguiOptions) {
|
|
|
325
448
|
// (built by another worker) - this prevents duplicate builds across worker threads
|
|
326
449
|
// we must check ALL files, not just the config, to avoid a race where another
|
|
327
450
|
// worker has written the config but not yet finished writing component files
|
|
328
|
-
let shouldBuild = !props.disableInitialBuild
|
|
329
|
-
if (shouldBuild && props.config) {
|
|
451
|
+
let shouldBuild = rebuild || !props.disableInitialBuild
|
|
452
|
+
if (shouldBuild && props.config && !rebuild) {
|
|
330
453
|
const allOutFiles = [configOutPath, ...componentOutPaths]
|
|
331
454
|
try {
|
|
332
455
|
const stats = await Promise.all(
|
|
@@ -353,7 +476,7 @@ export async function bundleConfig(props: TamaguiOptions) {
|
|
|
353
476
|
|
|
354
477
|
const start = Date.now()
|
|
355
478
|
|
|
356
|
-
await Promise.all([
|
|
479
|
+
const buildResults = await Promise.all([
|
|
357
480
|
props.config
|
|
358
481
|
? esbundleTamaguiConfig(
|
|
359
482
|
{
|
|
@@ -362,6 +485,10 @@ export async function bundleConfig(props: TamaguiOptions) {
|
|
|
362
485
|
outfile: configOutPath,
|
|
363
486
|
target: 'node24',
|
|
364
487
|
format: configFormat,
|
|
488
|
+
absWorkingDir: root,
|
|
489
|
+
metafile: true,
|
|
490
|
+
dangerouslyIgnoreStaticEvaluationModules:
|
|
491
|
+
props.dangerouslyIgnoreStaticEvaluationModules,
|
|
365
492
|
...esbuildExtraOptions,
|
|
366
493
|
},
|
|
367
494
|
props.platform || 'web'
|
|
@@ -371,11 +498,21 @@ export async function bundleConfig(props: TamaguiOptions) {
|
|
|
371
498
|
return esbundleTamaguiConfig(
|
|
372
499
|
{
|
|
373
500
|
entryPoints: [componentModule],
|
|
374
|
-
|
|
501
|
+
// bare packages must stay bare so esbuild can select their
|
|
502
|
+
// react-native conditional export; local files still use siblings
|
|
503
|
+
resolvePlatformSpecificEntries:
|
|
504
|
+
props.platform !== 'native' ||
|
|
505
|
+
componentModule.startsWith('.') ||
|
|
506
|
+
isAbsolute(componentModule),
|
|
507
|
+
conditions: props.platform === 'native' ? ['react-native'] : undefined,
|
|
375
508
|
external,
|
|
376
509
|
outfile: componentOutPaths[i],
|
|
377
510
|
target: 'node24',
|
|
378
511
|
format: componentFormats[i],
|
|
512
|
+
absWorkingDir: root,
|
|
513
|
+
metafile: true,
|
|
514
|
+
dangerouslyIgnoreStaticEvaluationModules:
|
|
515
|
+
props.dangerouslyIgnoreStaticEvaluationModules,
|
|
379
516
|
...esbuildExtraOptions,
|
|
380
517
|
},
|
|
381
518
|
props.platform || 'web'
|
|
@@ -383,6 +520,31 @@ export async function bundleConfig(props: TamaguiOptions) {
|
|
|
383
520
|
}),
|
|
384
521
|
])
|
|
385
522
|
|
|
523
|
+
compilerDependencies = buildResults.flatMap((result) =>
|
|
524
|
+
result?.metafile
|
|
525
|
+
? Object.keys(result.metafile.inputs).map((input) => resolve(root, input))
|
|
526
|
+
: []
|
|
527
|
+
)
|
|
528
|
+
|
|
529
|
+
componentImports = buildResults.slice(1).map((result) => {
|
|
530
|
+
if (!result?.metafile) {
|
|
531
|
+
return []
|
|
532
|
+
}
|
|
533
|
+
const entryPoint = Object.values(result.metafile.outputs).find(
|
|
534
|
+
(output) => output.entryPoint
|
|
535
|
+
)?.entryPoint
|
|
536
|
+
if (!entryPoint) {
|
|
537
|
+
return []
|
|
538
|
+
}
|
|
539
|
+
return [
|
|
540
|
+
...new Set(
|
|
541
|
+
result.metafile.inputs[entryPoint]?.imports
|
|
542
|
+
.map((item) => getPackageNameFromPath(item.path))
|
|
543
|
+
.filter((moduleName): moduleName is string => Boolean(moduleName)) || []
|
|
544
|
+
),
|
|
545
|
+
]
|
|
546
|
+
})
|
|
547
|
+
|
|
386
548
|
// only log once per process to avoid duplicate messages
|
|
387
549
|
// also skip if _skipBuildLog is set (used during worker recycle warmup)
|
|
388
550
|
if (!hasLoggedBuild && !props['_skipBuildLog']) {
|
|
@@ -397,8 +559,8 @@ export async function bundleConfig(props: TamaguiOptions) {
|
|
|
397
559
|
colorLog(
|
|
398
560
|
Color.Dim,
|
|
399
561
|
`
|
|
400
|
-
Config .${sep}${relative(
|
|
401
|
-
Components ${componentOutPaths.map((p) => `.${sep}${relative(
|
|
562
|
+
Config .${sep}${relative(root, configOutPath)}
|
|
563
|
+
Components ${componentOutPaths.map((p) => `.${sep}${relative(root, p)}`).join('\n ')}
|
|
402
564
|
`
|
|
403
565
|
)
|
|
404
566
|
}
|
|
@@ -407,16 +569,16 @@ export async function bundleConfig(props: TamaguiOptions) {
|
|
|
407
569
|
|
|
408
570
|
// clear specific output file caches so we pick up the fresh (or newly discovered) build
|
|
409
571
|
// only clear the built output files - not all require.cache entries, since that breaks
|
|
410
|
-
// external requires like @tamagui/config/
|
|
572
|
+
// external requires like @tamagui/config/v6 that are externalized in the bundled CJS
|
|
411
573
|
if (hasBundledOnce) {
|
|
412
574
|
try {
|
|
413
|
-
delete
|
|
575
|
+
delete nodeRequire.cache[nodeRequire.resolve(configOutPath)]
|
|
414
576
|
} catch {
|
|
415
577
|
// file may not exist yet
|
|
416
578
|
}
|
|
417
579
|
for (const p of componentOutPaths) {
|
|
418
580
|
try {
|
|
419
|
-
delete
|
|
581
|
+
delete nodeRequire.cache[nodeRequire.resolve(p)]
|
|
420
582
|
} catch {
|
|
421
583
|
// file may not exist yet
|
|
422
584
|
}
|
|
@@ -428,9 +590,11 @@ export async function bundleConfig(props: TamaguiOptions) {
|
|
|
428
590
|
let out: any
|
|
429
591
|
if (configFormat === 'esm') {
|
|
430
592
|
// use file:// URL for proper ESM resolution
|
|
431
|
-
out = await import(
|
|
593
|
+
out = await import(
|
|
594
|
+
`${pathToFileURL(configOutPath).href}?v=${FS.statSync(configOutPath).mtimeMs}`
|
|
595
|
+
)
|
|
432
596
|
} else {
|
|
433
|
-
out =
|
|
597
|
+
out = nodeRequire(configOutPath)
|
|
434
598
|
}
|
|
435
599
|
|
|
436
600
|
// try and find .config, even if on .default
|
|
@@ -443,25 +607,28 @@ export async function bundleConfig(props: TamaguiOptions) {
|
|
|
443
607
|
throw new Error(`No config: ${config}`)
|
|
444
608
|
}
|
|
445
609
|
|
|
446
|
-
// check for ProxyWorm - indicates a module loading error
|
|
447
|
-
if (config._isProxyWorm) {
|
|
448
|
-
throw new Error(
|
|
449
|
-
`Got a proxied config - likely a module loading error. Set DEBUG=tamagui for details.`
|
|
450
|
-
)
|
|
451
|
-
}
|
|
452
|
-
|
|
453
610
|
loadedConfig = config
|
|
454
611
|
|
|
455
612
|
if (!config.parsed) {
|
|
456
613
|
const { createTamagui } = requireTamaguiCore(props.platform || 'web')
|
|
457
614
|
// need to create it
|
|
458
615
|
config = createTamagui(config)
|
|
616
|
+
} else {
|
|
617
|
+
// an esm-evaluated config parses inside its own core module instance,
|
|
618
|
+
// leaving this host copy with empty token and media state. install the
|
|
619
|
+
// already-parsed config so host module-local state matches, same as
|
|
620
|
+
// loadTamaguiFromModules, without re-parsing or browser css discovery.
|
|
621
|
+
const { installTamaguiConfig } = requireTamaguiCore(props.platform || 'web')
|
|
622
|
+
installTamaguiConfig(config)
|
|
459
623
|
}
|
|
460
624
|
|
|
461
625
|
if (props.outputCSS) {
|
|
462
626
|
await writeTamaguiCSS(props.outputCSS, config)
|
|
463
627
|
}
|
|
464
628
|
|
|
629
|
+
if (rebuild) {
|
|
630
|
+
delete cacheComponents[componentOutPaths.join('\0')]
|
|
631
|
+
}
|
|
465
632
|
let components = await loadComponents({
|
|
466
633
|
...props,
|
|
467
634
|
components: componentOutPaths,
|
|
@@ -499,6 +666,23 @@ export async function bundleConfig(props: TamaguiOptions) {
|
|
|
499
666
|
components,
|
|
500
667
|
nameToPaths: {},
|
|
501
668
|
tamaguiConfig: config,
|
|
669
|
+
dependencies: compilerDependencies,
|
|
670
|
+
// the generated bundles inline every source they were built from,
|
|
671
|
+
// including the component packages resolved out of node_modules, so their
|
|
672
|
+
// bytes are a complete description of what the compiler host will read
|
|
673
|
+
stampSources: [
|
|
674
|
+
...(configEntry ? [configOutPath] : []),
|
|
675
|
+
...componentOutPaths,
|
|
676
|
+
// The generated bundles inline the user's config and components, but
|
|
677
|
+
// `external` keeps @tamagui/core and @tamagui/web out of them, and
|
|
678
|
+
// everything reached only through those two is left out with them.
|
|
679
|
+
// Those packages hold the staticConfig and style engine every lowering
|
|
680
|
+
// is computed against, so without their bytes an in-place engine edit at
|
|
681
|
+
// the same version - exactly what `bun run watch` and
|
|
682
|
+
// `bun release --into` produce - would serve plans built by the
|
|
683
|
+
// previous engine.
|
|
684
|
+
...requiredTamaguiPackageFiles(),
|
|
685
|
+
],
|
|
502
686
|
}
|
|
503
687
|
|
|
504
688
|
currentBundle = res
|
|
@@ -507,12 +691,28 @@ export async function bundleConfig(props: TamaguiOptions) {
|
|
|
507
691
|
|
|
508
692
|
return res
|
|
509
693
|
} catch (err: any) {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
694
|
+
const failure = findStaticEvaluationError(err)
|
|
695
|
+
const componentIndex = failure
|
|
696
|
+
? componentOutPaths.findIndex(
|
|
697
|
+
(outputPath) =>
|
|
698
|
+
outputPath === failure.moduleName || outputPath === failure.importer
|
|
699
|
+
)
|
|
700
|
+
: -1
|
|
701
|
+
const configuredComponent = baseComponents[componentIndex]
|
|
702
|
+
if (failure && configuredComponent) {
|
|
703
|
+
const configuredImport =
|
|
704
|
+
configuredComponent.startsWith('.') || isAbsolute(configuredComponent)
|
|
705
|
+
? componentImports[componentIndex]?.[0] || configuredComponent
|
|
706
|
+
: configuredComponent
|
|
707
|
+
throw new Error(
|
|
708
|
+
`[tamagui] Static evaluation could not proceed for configured component "${configuredComponent}".\nThe import "${configuredImport}" reached module "${failure.failedModule}", which failed during Node evaluation.\nReason: ${failure.reason}\nFix the failing module so it can run in Node during the build. If "${configuredImport}" is runtime-only and none of its exports create your Tamagui config or components, add "${configuredImport}" to dangerouslyIgnoreStaticEvaluationModules in tamagui.build.ts.`,
|
|
709
|
+
{ cause: err }
|
|
710
|
+
)
|
|
515
711
|
}
|
|
712
|
+
throw new Error(
|
|
713
|
+
`[tamagui] Static evaluation could not proceed for configured Tamagui config "${configEntry || '<default config>'}".\nReason: ${err instanceof Error ? err.message : String(err)}\nFix the failing import so it can run in Node during the build. If it is runtime-only and none of its exports create your Tamagui config or components, add its exact module name to dangerouslyIgnoreStaticEvaluationModules in tamagui.build.ts.`,
|
|
714
|
+
{ cause: err }
|
|
715
|
+
)
|
|
516
716
|
} finally {
|
|
517
717
|
isBundling = false
|
|
518
718
|
waitForBundle.forEach((cb) => cb())
|
|
@@ -523,6 +723,7 @@ export async function bundleConfig(props: TamaguiOptions) {
|
|
|
523
723
|
export async function writeTamaguiCSS(outputCSS: string, config: TamaguiInternalConfig) {
|
|
524
724
|
const flush = async () => {
|
|
525
725
|
colorLog(Color.FgYellow, ` ➡ [tamagui] output css: ${outputCSS}`)
|
|
726
|
+
await FS.mkdirp(dirname(outputCSS))
|
|
526
727
|
await FS.writeFile(outputCSS, css)
|
|
527
728
|
}
|
|
528
729
|
|
|
@@ -544,13 +745,13 @@ export async function writeTamaguiCSS(outputCSS: string, config: TamaguiInternal
|
|
|
544
745
|
export async function loadComponents(props: TamaguiOptions, forceExports = false) {
|
|
545
746
|
const coreComponents = getCoreComponentsSync(props)
|
|
546
747
|
const otherComponents = await loadComponentsInner(props, forceExports)
|
|
547
|
-
return [...coreComponents, ...
|
|
748
|
+
return [...coreComponents, ...otherComponents]
|
|
548
749
|
}
|
|
549
750
|
|
|
550
751
|
export function loadComponentsSync(props: TamaguiOptions, forceExports = false) {
|
|
551
752
|
const coreComponents = getCoreComponentsSync(props)
|
|
552
753
|
const otherComponents = loadComponentsInnerSync(props, forceExports)
|
|
553
|
-
return [...coreComponents, ...
|
|
754
|
+
return [...coreComponents, ...otherComponents]
|
|
554
755
|
}
|
|
555
756
|
|
|
556
757
|
function getCoreComponentsSync(props: TamaguiOptions) {
|
|
@@ -559,7 +760,7 @@ function getCoreComponentsSync(props: TamaguiOptions) {
|
|
|
559
760
|
components: ['@tamagui/core'],
|
|
560
761
|
})
|
|
561
762
|
|
|
562
|
-
if (!loaded) {
|
|
763
|
+
if (!loaded[0]) {
|
|
563
764
|
throw new Error(`Core should always load`)
|
|
564
765
|
}
|
|
565
766
|
|
|
@@ -575,17 +776,21 @@ function getCoreComponentsSync(props: TamaguiOptions) {
|
|
|
575
776
|
export async function loadComponentsInner(
|
|
576
777
|
props: TamaguiOptions,
|
|
577
778
|
forceExports = false
|
|
578
|
-
): Promise<
|
|
779
|
+
): Promise<LoadedComponents[]> {
|
|
579
780
|
const componentsModules = props.components || []
|
|
580
781
|
|
|
581
|
-
const key =
|
|
782
|
+
const key = JSON.stringify([
|
|
783
|
+
props.platform,
|
|
784
|
+
componentsModules,
|
|
785
|
+
props.dangerouslyIgnoreStaticEvaluationModules,
|
|
786
|
+
])
|
|
582
787
|
|
|
583
788
|
if (!forceExports && cacheComponents[key]) {
|
|
584
789
|
return cacheComponents[key]
|
|
585
790
|
}
|
|
586
791
|
|
|
587
792
|
const { unregister } = registerRequire(props.platform || 'web', {
|
|
588
|
-
|
|
793
|
+
ignoredModules: props.dangerouslyIgnoreStaticEvaluationModules,
|
|
589
794
|
})
|
|
590
795
|
|
|
591
796
|
try {
|
|
@@ -600,12 +805,11 @@ export async function loadComponentsInner(
|
|
|
600
805
|
const fileContents = isDynamic ? readFileSync(name, 'utf-8') : ''
|
|
601
806
|
let loadModule = name
|
|
602
807
|
let writtenContents = fileContents
|
|
603
|
-
let didBabel = false
|
|
604
808
|
|
|
605
809
|
const attemptLoad = async ({ forceExports = false } = {}) => {
|
|
606
810
|
if (isDynamic) {
|
|
607
811
|
writtenContents = forceExports
|
|
608
|
-
?
|
|
812
|
+
? addLocalExports(esbuildit(fileContents, 'modern'), name)
|
|
609
813
|
: fileContents
|
|
610
814
|
loadModule = getDynamicEvalOutfile(name, format, writtenContents)
|
|
611
815
|
|
|
@@ -614,6 +818,12 @@ export async function loadComponentsInner(
|
|
|
614
818
|
|
|
615
819
|
await esbuild.build({
|
|
616
820
|
...esbuildOptionsWithPlugins,
|
|
821
|
+
plugins: [
|
|
822
|
+
...(esbuildOptionsWithPlugins.plugins || []),
|
|
823
|
+
staticEvaluationIgnorePlugin(
|
|
824
|
+
props.dangerouslyIgnoreStaticEvaluationModules
|
|
825
|
+
),
|
|
826
|
+
],
|
|
617
827
|
format,
|
|
618
828
|
outfile: loadModule,
|
|
619
829
|
stdin: {
|
|
@@ -651,9 +861,11 @@ export async function loadComponentsInner(
|
|
|
651
861
|
let moduleResult: any
|
|
652
862
|
if (format === 'esm') {
|
|
653
863
|
// use file:// URL for proper ESM resolution
|
|
654
|
-
moduleResult = await import(
|
|
864
|
+
moduleResult = await import(
|
|
865
|
+
`${pathToFileURL(loadModule).href}?v=${FS.statSync(loadModule).mtimeMs}`
|
|
866
|
+
)
|
|
655
867
|
} else {
|
|
656
|
-
moduleResult =
|
|
868
|
+
moduleResult = nodeRequire(loadModule)
|
|
657
869
|
}
|
|
658
870
|
|
|
659
871
|
if (!forceExports) {
|
|
@@ -681,33 +893,26 @@ export async function loadComponentsInner(
|
|
|
681
893
|
let loaded: LoadedComponents | LoadedComponents[] | undefined
|
|
682
894
|
|
|
683
895
|
try {
|
|
684
|
-
loaded = await attemptLoad({ forceExports:
|
|
685
|
-
didBabel = true
|
|
896
|
+
loaded = await attemptLoad({ forceExports: isDynamic })
|
|
686
897
|
} catch (err) {
|
|
687
|
-
|
|
898
|
+
if (!isDynamic) {
|
|
899
|
+
throw new Error(
|
|
900
|
+
`[tamagui] Failed to statically evaluate configured component module "${name}". ${err instanceof Error ? err.message : String(err)}`,
|
|
901
|
+
{ cause: err }
|
|
902
|
+
)
|
|
903
|
+
}
|
|
688
904
|
writtenContents = fileContents
|
|
689
905
|
if (process.env.DEBUG?.startsWith('tamagui')) {
|
|
690
|
-
console.info(`Error
|
|
906
|
+
console.info(`Error adding local component exports`, err)
|
|
691
907
|
}
|
|
692
908
|
|
|
693
909
|
try {
|
|
694
910
|
loaded = await attemptLoad({ forceExports: false })
|
|
695
911
|
} catch (err2) {
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
console.info(err2)
|
|
701
|
-
console.info(
|
|
702
|
-
`At: ${loadModule}`,
|
|
703
|
-
`\ndidBabel: ${didBabel}`,
|
|
704
|
-
`\nIn:`,
|
|
705
|
-
writtenContents,
|
|
706
|
-
`\nisDynamic: `,
|
|
707
|
-
isDynamic
|
|
708
|
-
)
|
|
709
|
-
}
|
|
710
|
-
loaded = []
|
|
912
|
+
throw new Error(
|
|
913
|
+
`[tamagui] Failed to statically evaluate configured component module "${name}" at "${loadModule}". ${err2 instanceof Error ? err2.message : String(err2)}`,
|
|
914
|
+
{ cause: err2 }
|
|
915
|
+
)
|
|
711
916
|
}
|
|
712
917
|
} finally {
|
|
713
918
|
dispose()
|
|
@@ -722,9 +927,6 @@ export async function loadComponentsInner(
|
|
|
722
927
|
|
|
723
928
|
cacheComponents[key] = results
|
|
724
929
|
return results
|
|
725
|
-
} catch (err: any) {
|
|
726
|
-
console.info(`Tamagui error bundling components`, err.message, err.stack)
|
|
727
|
-
return null
|
|
728
930
|
} finally {
|
|
729
931
|
unregister()
|
|
730
932
|
}
|
|
@@ -734,17 +936,21 @@ export async function loadComponentsInner(
|
|
|
734
936
|
export function loadComponentsInnerSync(
|
|
735
937
|
props: TamaguiOptions,
|
|
736
938
|
forceExports = false
|
|
737
|
-
):
|
|
939
|
+
): LoadedComponents[] {
|
|
738
940
|
const componentsModules = props.components || []
|
|
739
941
|
|
|
740
|
-
const key =
|
|
942
|
+
const key = JSON.stringify([
|
|
943
|
+
props.platform,
|
|
944
|
+
componentsModules,
|
|
945
|
+
props.dangerouslyIgnoreStaticEvaluationModules,
|
|
946
|
+
])
|
|
741
947
|
|
|
742
948
|
if (!forceExports && cacheComponents[key]) {
|
|
743
949
|
return cacheComponents[key]
|
|
744
950
|
}
|
|
745
951
|
|
|
746
952
|
const { unregister } = registerRequire(props.platform || 'web', {
|
|
747
|
-
|
|
953
|
+
ignoredModules: props.dangerouslyIgnoreStaticEvaluationModules,
|
|
748
954
|
})
|
|
749
955
|
|
|
750
956
|
try {
|
|
@@ -756,12 +962,11 @@ export function loadComponentsInnerSync(
|
|
|
756
962
|
const fileContents = isDynamic ? readFileSync(name, 'utf-8') : ''
|
|
757
963
|
let loadModule = name
|
|
758
964
|
let writtenContents = fileContents
|
|
759
|
-
let didBabel = false
|
|
760
965
|
|
|
761
966
|
function attemptLoad({ forceExports = false } = {}) {
|
|
762
967
|
if (isDynamic) {
|
|
763
968
|
writtenContents = forceExports
|
|
764
|
-
?
|
|
969
|
+
? addLocalExports(esbuildit(fileContents, 'modern'), name)
|
|
765
970
|
: fileContents
|
|
766
971
|
loadModule = getDynamicEvalOutfile(name, 'cjs', writtenContents)
|
|
767
972
|
|
|
@@ -800,10 +1005,10 @@ export function loadComponentsInnerSync(
|
|
|
800
1005
|
}
|
|
801
1006
|
|
|
802
1007
|
if (process.env.DEBUG === 'tamagui') {
|
|
803
|
-
console.info(`loadModule`, loadModule,
|
|
1008
|
+
console.info(`loadModule`, loadModule, nodeRequire.resolve(loadModule))
|
|
804
1009
|
}
|
|
805
1010
|
|
|
806
|
-
const moduleResult =
|
|
1011
|
+
const moduleResult = nodeRequire(loadModule)
|
|
807
1012
|
|
|
808
1013
|
if (!forceExports) {
|
|
809
1014
|
setRequireResult(name, moduleResult)
|
|
@@ -828,14 +1033,18 @@ export function loadComponentsInnerSync(
|
|
|
828
1033
|
}
|
|
829
1034
|
|
|
830
1035
|
try {
|
|
831
|
-
const res = attemptLoad({ forceExports:
|
|
832
|
-
didBabel = true
|
|
1036
|
+
const res = attemptLoad({ forceExports: isDynamic })
|
|
833
1037
|
return res
|
|
834
1038
|
} catch (err) {
|
|
835
|
-
|
|
1039
|
+
if (!isDynamic) {
|
|
1040
|
+
throw new Error(
|
|
1041
|
+
`[tamagui] Failed to statically evaluate configured component module "${name}". ${err instanceof Error ? err.message : String(err)}`,
|
|
1042
|
+
{ cause: err }
|
|
1043
|
+
)
|
|
1044
|
+
}
|
|
836
1045
|
writtenContents = fileContents
|
|
837
1046
|
if (process.env.DEBUG?.startsWith('tamagui')) {
|
|
838
|
-
console.info(`Error
|
|
1047
|
+
console.info(`Error adding local component exports`, err)
|
|
839
1048
|
}
|
|
840
1049
|
} finally {
|
|
841
1050
|
dispose()
|
|
@@ -844,30 +1053,16 @@ export function loadComponentsInnerSync(
|
|
|
844
1053
|
try {
|
|
845
1054
|
return attemptLoad({ forceExports: false })
|
|
846
1055
|
} catch (err) {
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
console.info(err)
|
|
852
|
-
console.info(
|
|
853
|
-
`At: ${loadModule}`,
|
|
854
|
-
`\ndidBabel: ${didBabel}`,
|
|
855
|
-
`\nIn:`,
|
|
856
|
-
writtenContents,
|
|
857
|
-
`\nisDynamic: `,
|
|
858
|
-
isDynamic
|
|
859
|
-
)
|
|
860
|
-
}
|
|
861
|
-
return []
|
|
1056
|
+
throw new Error(
|
|
1057
|
+
`[tamagui] Failed to statically evaluate configured component module "${name}" at "${loadModule}". ${err instanceof Error ? err.message : String(err)}`,
|
|
1058
|
+
{ cause: err }
|
|
1059
|
+
)
|
|
862
1060
|
} finally {
|
|
863
1061
|
dispose()
|
|
864
1062
|
}
|
|
865
1063
|
})
|
|
866
1064
|
cacheComponents[key] = info
|
|
867
1065
|
return info
|
|
868
|
-
} catch (err: any) {
|
|
869
|
-
console.info(`Tamagui error bundling components`, err.message, err.stack)
|
|
870
|
-
return null
|
|
871
1066
|
} finally {
|
|
872
1067
|
unregister()
|
|
873
1068
|
}
|
|
@@ -886,28 +1081,23 @@ const esbuildit = (src: string, target?: 'modern') => {
|
|
|
886
1081
|
}).code
|
|
887
1082
|
}
|
|
888
1083
|
|
|
889
|
-
function getComponentStaticConfigByName(name: string, exported: any) {
|
|
890
|
-
const components: Record<string, { staticConfig: StaticConfig }> =
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
1084
|
+
export function getComponentStaticConfigByName(name: string, exported: any) {
|
|
1085
|
+
const components: Record<string, { staticConfig: StaticConfig; displayName?: string }> =
|
|
1086
|
+
{}
|
|
1087
|
+
if (!exported || typeof exported !== 'object' || Array.isArray(exported)) {
|
|
1088
|
+
throw new Error(`Invalid export from package ${name}: ${typeof exported}`)
|
|
1089
|
+
}
|
|
895
1090
|
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
1091
|
+
for (const key in exported) {
|
|
1092
|
+
const found = getTamaguiComponent(key, exported[key])
|
|
1093
|
+
if (found) {
|
|
1094
|
+
// remove non-stringifyable
|
|
1095
|
+
const { Component, ...sc } = found.staticConfig
|
|
1096
|
+
components[key] = {
|
|
1097
|
+
staticConfig: sc,
|
|
1098
|
+
...(found.displayName && { displayName: found.displayName }),
|
|
902
1099
|
}
|
|
903
1100
|
}
|
|
904
|
-
} catch (err) {
|
|
905
|
-
if (process.env.TAMAGUI_ENABLE_WARN_DYNAMIC_LOAD) {
|
|
906
|
-
console.error(
|
|
907
|
-
`Tamagui failed getting components from ${name} (Disable error by setting environment variable TAMAGUI_ENABLE_WARN_DYNAMIC_LOAD=1)`
|
|
908
|
-
)
|
|
909
|
-
console.error(err)
|
|
910
|
-
}
|
|
911
1101
|
}
|
|
912
1102
|
return components
|
|
913
1103
|
}
|
|
@@ -915,13 +1105,16 @@ function getComponentStaticConfigByName(name: string, exported: any) {
|
|
|
915
1105
|
function getTamaguiComponent(
|
|
916
1106
|
name: string,
|
|
917
1107
|
Component: any
|
|
918
|
-
): undefined | { staticConfig: StaticConfig } {
|
|
1108
|
+
): undefined | { staticConfig: StaticConfig; displayName?: string } {
|
|
919
1109
|
if (name[0].toUpperCase() !== name[0]) {
|
|
920
1110
|
return
|
|
921
1111
|
}
|
|
922
1112
|
const staticConfig = Component?.staticConfig as StaticConfig | undefined
|
|
923
1113
|
if (staticConfig) {
|
|
924
|
-
return
|
|
1114
|
+
return {
|
|
1115
|
+
staticConfig,
|
|
1116
|
+
displayName: Component[componentDisplayName] as string | undefined,
|
|
1117
|
+
}
|
|
925
1118
|
}
|
|
926
1119
|
}
|
|
927
1120
|
|
|
@@ -930,49 +1123,3 @@ function interopDefaultExport(mod: any) {
|
|
|
930
1123
|
}
|
|
931
1124
|
|
|
932
1125
|
const cacheComponents: Record<string, LoadedComponents[]> = {}
|
|
933
|
-
|
|
934
|
-
function transformAddExports(ast: t.File) {
|
|
935
|
-
const usedNames = new Set<string>()
|
|
936
|
-
|
|
937
|
-
// avoid clobbering
|
|
938
|
-
// @ts-ignore
|
|
939
|
-
traverse(ast, {
|
|
940
|
-
ExportNamedDeclaration(nodePath) {
|
|
941
|
-
if (nodePath.node.specifiers) {
|
|
942
|
-
for (const spec of nodePath.node.specifiers) {
|
|
943
|
-
usedNames.add(
|
|
944
|
-
t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value
|
|
945
|
-
)
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
},
|
|
949
|
-
})
|
|
950
|
-
|
|
951
|
-
// @ts-ignore
|
|
952
|
-
traverse(ast, {
|
|
953
|
-
VariableDeclaration(nodePath) {
|
|
954
|
-
// top level only
|
|
955
|
-
if (!t.isProgram(nodePath.parent)) return
|
|
956
|
-
const decs = nodePath.node.declarations
|
|
957
|
-
if (decs.length > 1) return
|
|
958
|
-
const [dec] = decs
|
|
959
|
-
if (!t.isIdentifier(dec.id)) return
|
|
960
|
-
if (!dec.init) return
|
|
961
|
-
if (usedNames.has(dec.id.name)) return
|
|
962
|
-
usedNames.add(dec.id.name)
|
|
963
|
-
nodePath.replaceWith(
|
|
964
|
-
t.exportNamedDeclaration(t.variableDeclaration('let', [dec]), [
|
|
965
|
-
t.exportSpecifier(t.identifier(dec.id.name), t.identifier(dec.id.name)),
|
|
966
|
-
])
|
|
967
|
-
)
|
|
968
|
-
},
|
|
969
|
-
})
|
|
970
|
-
|
|
971
|
-
// @ts-ignore
|
|
972
|
-
return generate(ast as any, {
|
|
973
|
-
concise: false,
|
|
974
|
-
filename: 'test.tsx',
|
|
975
|
-
retainLines: false,
|
|
976
|
-
sourceMaps: false,
|
|
977
|
-
}).code
|
|
978
|
-
}
|