@tamagui/static 2.7.7 → 3.0.0-beta.1097.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 +354 -0
- package/dist/cjs/checkDeps.cjs +301 -0
- package/dist/cjs/compiler.cjs +349 -0
- package/dist/cjs/compilerHost.cjs +2287 -0
- package/dist/cjs/componentDiscovery.cjs +94 -0
- package/dist/cjs/constants.cjs +32 -0
- package/dist/cjs/domStructuralPass.cjs +121 -0
- package/dist/cjs/exports.cjs +44 -0
- package/dist/cjs/extractor/addLocalExports.cjs +63 -0
- package/dist/cjs/extractor/bundle.cjs +229 -0
- package/dist/cjs/extractor/bundleConfig.cjs +769 -0
- package/dist/cjs/extractor/concatClassName.cjs +120 -0
- package/dist/cjs/extractor/detectModuleFormat.cjs +53 -0
- package/dist/cjs/extractor/esbuildAliasPlugin.cjs +46 -0
- package/dist/cjs/extractor/esbuildTsconfigPaths.cjs +91 -0
- package/dist/cjs/extractor/getTamaguiConfigPathFromOptionsConfig.cjs +42 -0
- package/dist/cjs/extractor/loadTamagui.cjs +394 -0
- package/dist/cjs/extractor/regenerateConfig.cjs +160 -0
- package/dist/cjs/extractor/watchTamaguiConfig.cjs +63 -0
- package/dist/cjs/getPragmaOptions.cjs +66 -0
- package/dist/cjs/helpers/memoize.cjs +41 -0
- package/dist/cjs/helpers/requireTamaguiCore.cjs +39 -0
- package/dist/cjs/index.cjs +33 -0
- package/dist/cjs/registerRequire.cjs +219 -0
- package/dist/cjs/server.cjs +65 -0
- package/dist/cjs/staticEvaluationIgnoredModules.cjs +85 -0
- package/dist/cjs/types.cjs +16 -0
- package/dist/cjs/zero/artifact.cjs +144 -0
- package/dist/cjs/zero/graph.cjs +208 -0
- package/dist/cjs/zero/identity.cjs +60 -0
- package/dist/cjs/zero/index.cjs +33 -0
- package/dist/cjs/zero/islands.cjs +235 -0
- package/dist/cjs/zero/options.cjs +162 -0
- package/dist/cjs/zero/ownership.cjs +78 -0
- package/dist/cjs/zero/theme.cjs +337 -0
- package/dist/cjs/zero/transform.cjs +207 -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 +319 -0
- package/dist/esm/compiler.mjs.map +1 -0
- package/dist/esm/compilerHost.mjs +2265 -0
- package/dist/esm/compilerHost.mjs.map +1 -0
- package/dist/esm/componentDiscovery.mjs +69 -0
- package/dist/esm/componentDiscovery.mjs.map +1 -0
- package/dist/esm/constants.mjs +7 -0
- package/dist/esm/constants.mjs.map +1 -0
- package/dist/esm/domStructuralPass.mjs +102 -0
- package/dist/esm/domStructuralPass.mjs.map +1 -0
- package/dist/esm/exports.mjs +29 -0
- package/dist/esm/extractor/addLocalExports.mjs +44 -0
- package/dist/esm/extractor/addLocalExports.mjs.map +1 -0
- package/dist/esm/extractor/bundle.mjs +199 -0
- package/dist/esm/extractor/bundle.mjs.map +1 -0
- package/dist/esm/extractor/bundleConfig.mjs +728 -0
- package/dist/esm/extractor/bundleConfig.mjs.map +1 -0
- package/dist/esm/extractor/concatClassName.mjs +100 -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 +23 -0
- package/dist/esm/extractor/getTamaguiConfigPathFromOptionsConfig.mjs.map +1 -0
- package/dist/esm/extractor/loadTamagui.mjs +357 -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 +19 -0
- package/dist/esm/zero/islands.mjs +201 -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 +313 -0
- package/dist/esm/zero/theme.mjs.map +1 -0
- package/dist/esm/zero/transform.mjs +182 -0
- package/dist/esm/zero/transform.mjs.map +1 -0
- package/package.json +38 -47
- package/src/check-dep-versions.ts +2 -2
- package/src/checkDeps.ts +3 -2
- package/src/compiler.ts +506 -0
- package/src/compilerHost.ts +3739 -0
- package/src/componentDiscovery.ts +105 -0
- package/src/constants.ts +0 -5
- package/src/domStructuralPass.ts +190 -0
- package/src/exports.ts +5 -6
- package/src/extractor/addLocalExports.ts +49 -0
- package/src/extractor/bundle.ts +38 -40
- package/src/extractor/bundleConfig.ts +368 -187
- package/src/extractor/concatClassName.ts +21 -24
- package/src/extractor/getTamaguiConfigPathFromOptionsConfig.ts +13 -5
- 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 +9 -0
- package/src/zero/islands.ts +266 -0
- package/src/zero/options.ts +239 -0
- package/src/zero/ownership.ts +113 -0
- package/src/zero/theme.ts +526 -0
- package/src/zero/transform.ts +329 -0
- package/types/check-dep-versions.d.ts.map +1 -1
- package/types/checkDeps.d.ts.map +1 -1
- package/types/compiler.d.ts +134 -0
- package/types/compiler.d.ts.map +1 -0
- package/types/compilerHost.d.ts +38 -0
- package/types/compilerHost.d.ts.map +1 -0
- package/types/componentDiscovery.d.ts +27 -0
- package/types/componentDiscovery.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 +5 -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 +26 -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 +10 -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 +85 -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,47 @@ 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]
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* Evaluate one host-resolved module under the platform's static-evaluation
|
|
753
|
+
* hooks, the way configured `components` load, and return its exports. The
|
|
754
|
+
* compiler frontend uses this for component discovery when no module runner is
|
|
755
|
+
* available (the Vite native environment plans for Metro).
|
|
756
|
+
*/
|
|
757
|
+
export async function evaluateComponentModule(
|
|
758
|
+
props: TamaguiOptions,
|
|
759
|
+
id: string
|
|
760
|
+
): Promise<Record<string, unknown>> {
|
|
761
|
+
const previousIsStatic = process.env.IS_STATIC
|
|
762
|
+
const previousIsServer = process.env.TAMAGUI_IS_SERVER
|
|
763
|
+
process.env.IS_STATIC = 'is_static'
|
|
764
|
+
process.env.TAMAGUI_IS_SERVER = 'true'
|
|
765
|
+
const { unregister } = registerRequire(props.platform || 'web', {
|
|
766
|
+
ignoredModules: props.dangerouslyIgnoreStaticEvaluationModules,
|
|
767
|
+
})
|
|
768
|
+
try {
|
|
769
|
+
try {
|
|
770
|
+
return nodeRequire(id)
|
|
771
|
+
} catch (error) {
|
|
772
|
+
const code = (error as { code?: string })?.code
|
|
773
|
+
if (code !== 'ERR_REQUIRE_ESM' && code !== 'ERR_REQUIRE_ASYNC_MODULE') throw error
|
|
774
|
+
}
|
|
775
|
+
} finally {
|
|
776
|
+
unregister()
|
|
777
|
+
if (previousIsStatic === undefined) delete process.env.IS_STATIC
|
|
778
|
+
else process.env.IS_STATIC = previousIsStatic
|
|
779
|
+
if (previousIsServer === undefined) delete process.env.TAMAGUI_IS_SERVER
|
|
780
|
+
else process.env.TAMAGUI_IS_SERVER = previousIsServer
|
|
781
|
+
}
|
|
782
|
+
return import(`${pathToFileURL(id).href}?v=${FS.statSync(id).mtimeMs}`)
|
|
548
783
|
}
|
|
549
784
|
|
|
550
785
|
export function loadComponentsSync(props: TamaguiOptions, forceExports = false) {
|
|
551
786
|
const coreComponents = getCoreComponentsSync(props)
|
|
552
787
|
const otherComponents = loadComponentsInnerSync(props, forceExports)
|
|
553
|
-
return [...coreComponents, ...
|
|
788
|
+
return [...coreComponents, ...otherComponents]
|
|
554
789
|
}
|
|
555
790
|
|
|
556
791
|
function getCoreComponentsSync(props: TamaguiOptions) {
|
|
@@ -559,7 +794,7 @@ function getCoreComponentsSync(props: TamaguiOptions) {
|
|
|
559
794
|
components: ['@tamagui/core'],
|
|
560
795
|
})
|
|
561
796
|
|
|
562
|
-
if (!loaded) {
|
|
797
|
+
if (!loaded[0]) {
|
|
563
798
|
throw new Error(`Core should always load`)
|
|
564
799
|
}
|
|
565
800
|
|
|
@@ -575,17 +810,21 @@ function getCoreComponentsSync(props: TamaguiOptions) {
|
|
|
575
810
|
export async function loadComponentsInner(
|
|
576
811
|
props: TamaguiOptions,
|
|
577
812
|
forceExports = false
|
|
578
|
-
): Promise<
|
|
813
|
+
): Promise<LoadedComponents[]> {
|
|
579
814
|
const componentsModules = props.components || []
|
|
580
815
|
|
|
581
|
-
const key =
|
|
816
|
+
const key = JSON.stringify([
|
|
817
|
+
props.platform,
|
|
818
|
+
componentsModules,
|
|
819
|
+
props.dangerouslyIgnoreStaticEvaluationModules,
|
|
820
|
+
])
|
|
582
821
|
|
|
583
822
|
if (!forceExports && cacheComponents[key]) {
|
|
584
823
|
return cacheComponents[key]
|
|
585
824
|
}
|
|
586
825
|
|
|
587
826
|
const { unregister } = registerRequire(props.platform || 'web', {
|
|
588
|
-
|
|
827
|
+
ignoredModules: props.dangerouslyIgnoreStaticEvaluationModules,
|
|
589
828
|
})
|
|
590
829
|
|
|
591
830
|
try {
|
|
@@ -600,12 +839,11 @@ export async function loadComponentsInner(
|
|
|
600
839
|
const fileContents = isDynamic ? readFileSync(name, 'utf-8') : ''
|
|
601
840
|
let loadModule = name
|
|
602
841
|
let writtenContents = fileContents
|
|
603
|
-
let didBabel = false
|
|
604
842
|
|
|
605
843
|
const attemptLoad = async ({ forceExports = false } = {}) => {
|
|
606
844
|
if (isDynamic) {
|
|
607
845
|
writtenContents = forceExports
|
|
608
|
-
?
|
|
846
|
+
? addLocalExports(esbuildit(fileContents, 'modern'), name)
|
|
609
847
|
: fileContents
|
|
610
848
|
loadModule = getDynamicEvalOutfile(name, format, writtenContents)
|
|
611
849
|
|
|
@@ -614,6 +852,12 @@ export async function loadComponentsInner(
|
|
|
614
852
|
|
|
615
853
|
await esbuild.build({
|
|
616
854
|
...esbuildOptionsWithPlugins,
|
|
855
|
+
plugins: [
|
|
856
|
+
...(esbuildOptionsWithPlugins.plugins || []),
|
|
857
|
+
staticEvaluationIgnorePlugin(
|
|
858
|
+
props.dangerouslyIgnoreStaticEvaluationModules
|
|
859
|
+
),
|
|
860
|
+
],
|
|
617
861
|
format,
|
|
618
862
|
outfile: loadModule,
|
|
619
863
|
stdin: {
|
|
@@ -651,9 +895,11 @@ export async function loadComponentsInner(
|
|
|
651
895
|
let moduleResult: any
|
|
652
896
|
if (format === 'esm') {
|
|
653
897
|
// use file:// URL for proper ESM resolution
|
|
654
|
-
moduleResult = await import(
|
|
898
|
+
moduleResult = await import(
|
|
899
|
+
`${pathToFileURL(loadModule).href}?v=${FS.statSync(loadModule).mtimeMs}`
|
|
900
|
+
)
|
|
655
901
|
} else {
|
|
656
|
-
moduleResult =
|
|
902
|
+
moduleResult = nodeRequire(loadModule)
|
|
657
903
|
}
|
|
658
904
|
|
|
659
905
|
if (!forceExports) {
|
|
@@ -681,33 +927,26 @@ export async function loadComponentsInner(
|
|
|
681
927
|
let loaded: LoadedComponents | LoadedComponents[] | undefined
|
|
682
928
|
|
|
683
929
|
try {
|
|
684
|
-
loaded = await attemptLoad({ forceExports:
|
|
685
|
-
didBabel = true
|
|
930
|
+
loaded = await attemptLoad({ forceExports: isDynamic })
|
|
686
931
|
} catch (err) {
|
|
687
|
-
|
|
932
|
+
if (!isDynamic) {
|
|
933
|
+
throw new Error(
|
|
934
|
+
`[tamagui] Failed to statically evaluate configured component module "${name}". ${err instanceof Error ? err.message : String(err)}`,
|
|
935
|
+
{ cause: err }
|
|
936
|
+
)
|
|
937
|
+
}
|
|
688
938
|
writtenContents = fileContents
|
|
689
939
|
if (process.env.DEBUG?.startsWith('tamagui')) {
|
|
690
|
-
console.info(`Error
|
|
940
|
+
console.info(`Error adding local component exports`, err)
|
|
691
941
|
}
|
|
692
942
|
|
|
693
943
|
try {
|
|
694
944
|
loaded = await attemptLoad({ forceExports: false })
|
|
695
945
|
} 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 = []
|
|
946
|
+
throw new Error(
|
|
947
|
+
`[tamagui] Failed to statically evaluate configured component module "${name}" at "${loadModule}". ${err2 instanceof Error ? err2.message : String(err2)}`,
|
|
948
|
+
{ cause: err2 }
|
|
949
|
+
)
|
|
711
950
|
}
|
|
712
951
|
} finally {
|
|
713
952
|
dispose()
|
|
@@ -722,9 +961,6 @@ export async function loadComponentsInner(
|
|
|
722
961
|
|
|
723
962
|
cacheComponents[key] = results
|
|
724
963
|
return results
|
|
725
|
-
} catch (err: any) {
|
|
726
|
-
console.info(`Tamagui error bundling components`, err.message, err.stack)
|
|
727
|
-
return null
|
|
728
964
|
} finally {
|
|
729
965
|
unregister()
|
|
730
966
|
}
|
|
@@ -734,17 +970,21 @@ export async function loadComponentsInner(
|
|
|
734
970
|
export function loadComponentsInnerSync(
|
|
735
971
|
props: TamaguiOptions,
|
|
736
972
|
forceExports = false
|
|
737
|
-
):
|
|
973
|
+
): LoadedComponents[] {
|
|
738
974
|
const componentsModules = props.components || []
|
|
739
975
|
|
|
740
|
-
const key =
|
|
976
|
+
const key = JSON.stringify([
|
|
977
|
+
props.platform,
|
|
978
|
+
componentsModules,
|
|
979
|
+
props.dangerouslyIgnoreStaticEvaluationModules,
|
|
980
|
+
])
|
|
741
981
|
|
|
742
982
|
if (!forceExports && cacheComponents[key]) {
|
|
743
983
|
return cacheComponents[key]
|
|
744
984
|
}
|
|
745
985
|
|
|
746
986
|
const { unregister } = registerRequire(props.platform || 'web', {
|
|
747
|
-
|
|
987
|
+
ignoredModules: props.dangerouslyIgnoreStaticEvaluationModules,
|
|
748
988
|
})
|
|
749
989
|
|
|
750
990
|
try {
|
|
@@ -756,12 +996,11 @@ export function loadComponentsInnerSync(
|
|
|
756
996
|
const fileContents = isDynamic ? readFileSync(name, 'utf-8') : ''
|
|
757
997
|
let loadModule = name
|
|
758
998
|
let writtenContents = fileContents
|
|
759
|
-
let didBabel = false
|
|
760
999
|
|
|
761
1000
|
function attemptLoad({ forceExports = false } = {}) {
|
|
762
1001
|
if (isDynamic) {
|
|
763
1002
|
writtenContents = forceExports
|
|
764
|
-
?
|
|
1003
|
+
? addLocalExports(esbuildit(fileContents, 'modern'), name)
|
|
765
1004
|
: fileContents
|
|
766
1005
|
loadModule = getDynamicEvalOutfile(name, 'cjs', writtenContents)
|
|
767
1006
|
|
|
@@ -800,10 +1039,10 @@ export function loadComponentsInnerSync(
|
|
|
800
1039
|
}
|
|
801
1040
|
|
|
802
1041
|
if (process.env.DEBUG === 'tamagui') {
|
|
803
|
-
console.info(`loadModule`, loadModule,
|
|
1042
|
+
console.info(`loadModule`, loadModule, nodeRequire.resolve(loadModule))
|
|
804
1043
|
}
|
|
805
1044
|
|
|
806
|
-
const moduleResult =
|
|
1045
|
+
const moduleResult = nodeRequire(loadModule)
|
|
807
1046
|
|
|
808
1047
|
if (!forceExports) {
|
|
809
1048
|
setRequireResult(name, moduleResult)
|
|
@@ -828,14 +1067,18 @@ export function loadComponentsInnerSync(
|
|
|
828
1067
|
}
|
|
829
1068
|
|
|
830
1069
|
try {
|
|
831
|
-
const res = attemptLoad({ forceExports:
|
|
832
|
-
didBabel = true
|
|
1070
|
+
const res = attemptLoad({ forceExports: isDynamic })
|
|
833
1071
|
return res
|
|
834
1072
|
} catch (err) {
|
|
835
|
-
|
|
1073
|
+
if (!isDynamic) {
|
|
1074
|
+
throw new Error(
|
|
1075
|
+
`[tamagui] Failed to statically evaluate configured component module "${name}". ${err instanceof Error ? err.message : String(err)}`,
|
|
1076
|
+
{ cause: err }
|
|
1077
|
+
)
|
|
1078
|
+
}
|
|
836
1079
|
writtenContents = fileContents
|
|
837
1080
|
if (process.env.DEBUG?.startsWith('tamagui')) {
|
|
838
|
-
console.info(`Error
|
|
1081
|
+
console.info(`Error adding local component exports`, err)
|
|
839
1082
|
}
|
|
840
1083
|
} finally {
|
|
841
1084
|
dispose()
|
|
@@ -844,30 +1087,16 @@ export function loadComponentsInnerSync(
|
|
|
844
1087
|
try {
|
|
845
1088
|
return attemptLoad({ forceExports: false })
|
|
846
1089
|
} 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 []
|
|
1090
|
+
throw new Error(
|
|
1091
|
+
`[tamagui] Failed to statically evaluate configured component module "${name}" at "${loadModule}". ${err instanceof Error ? err.message : String(err)}`,
|
|
1092
|
+
{ cause: err }
|
|
1093
|
+
)
|
|
862
1094
|
} finally {
|
|
863
1095
|
dispose()
|
|
864
1096
|
}
|
|
865
1097
|
})
|
|
866
1098
|
cacheComponents[key] = info
|
|
867
1099
|
return info
|
|
868
|
-
} catch (err: any) {
|
|
869
|
-
console.info(`Tamagui error bundling components`, err.message, err.stack)
|
|
870
|
-
return null
|
|
871
1100
|
} finally {
|
|
872
1101
|
unregister()
|
|
873
1102
|
}
|
|
@@ -886,28 +1115,23 @@ const esbuildit = (src: string, target?: 'modern') => {
|
|
|
886
1115
|
}).code
|
|
887
1116
|
}
|
|
888
1117
|
|
|
889
|
-
function getComponentStaticConfigByName(name: string, exported: any) {
|
|
890
|
-
const components: Record<string, { staticConfig: StaticConfig }> =
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
1118
|
+
export function getComponentStaticConfigByName(name: string, exported: any) {
|
|
1119
|
+
const components: Record<string, { staticConfig: StaticConfig; displayName?: string }> =
|
|
1120
|
+
{}
|
|
1121
|
+
if (!exported || typeof exported !== 'object' || Array.isArray(exported)) {
|
|
1122
|
+
throw new Error(`Invalid export from package ${name}: ${typeof exported}`)
|
|
1123
|
+
}
|
|
895
1124
|
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
1125
|
+
for (const key in exported) {
|
|
1126
|
+
const found = getTamaguiComponent(key, exported[key])
|
|
1127
|
+
if (found) {
|
|
1128
|
+
// remove non-stringifyable
|
|
1129
|
+
const { Component, ...sc } = found.staticConfig
|
|
1130
|
+
components[key] = {
|
|
1131
|
+
staticConfig: sc,
|
|
1132
|
+
...(found.displayName && { displayName: found.displayName }),
|
|
902
1133
|
}
|
|
903
1134
|
}
|
|
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
1135
|
}
|
|
912
1136
|
return components
|
|
913
1137
|
}
|
|
@@ -915,13 +1139,16 @@ function getComponentStaticConfigByName(name: string, exported: any) {
|
|
|
915
1139
|
function getTamaguiComponent(
|
|
916
1140
|
name: string,
|
|
917
1141
|
Component: any
|
|
918
|
-
): undefined | { staticConfig: StaticConfig } {
|
|
1142
|
+
): undefined | { staticConfig: StaticConfig; displayName?: string } {
|
|
919
1143
|
if (name[0].toUpperCase() !== name[0]) {
|
|
920
1144
|
return
|
|
921
1145
|
}
|
|
922
1146
|
const staticConfig = Component?.staticConfig as StaticConfig | undefined
|
|
923
1147
|
if (staticConfig) {
|
|
924
|
-
return
|
|
1148
|
+
return {
|
|
1149
|
+
staticConfig,
|
|
1150
|
+
displayName: Component[componentDisplayName] as string | undefined,
|
|
1151
|
+
}
|
|
925
1152
|
}
|
|
926
1153
|
}
|
|
927
1154
|
|
|
@@ -930,49 +1157,3 @@ function interopDefaultExport(mod: any) {
|
|
|
930
1157
|
}
|
|
931
1158
|
|
|
932
1159
|
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
|
-
}
|