@hanzogui/static 4.3.1 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/check-dep-versions.cjs +1 -1
- package/dist/checkDeps.cjs +11 -11
- package/dist/constants.cjs +2 -2
- package/dist/exports.cjs +2 -2
- package/dist/extractor/babelParse.cjs +1 -1
- package/dist/extractor/bundle.cjs +23 -39
- package/dist/extractor/bundleConfig.cjs +51 -48
- package/dist/extractor/createExtractor.cjs +39 -39
- package/dist/extractor/createLogger.cjs +1 -1
- package/dist/extractor/extractHelpers.cjs +1 -1
- package/dist/extractor/extractMediaStyle.cjs +7 -7
- package/dist/extractor/extractToClassNames.cjs +9 -9
- package/dist/extractor/extractToNative.cjs +7 -7
- package/dist/extractor/{getGuiConfigPathFromOptionsConfig.cjs → getHanzoguiConfigPathFromOptionsConfig.cjs} +5 -5
- package/dist/extractor/getPrefixLogs.cjs +1 -1
- package/dist/extractor/getStaticBindingsForScope.cjs +2 -2
- package/dist/extractor/hasTopLevelAwait.cjs +62 -0
- package/dist/extractor/{loadGui.cjs → loadHanzogui.cjs} +97 -141
- package/dist/extractor/regenerateConfig.cjs +20 -20
- package/dist/extractor/{watchGuiConfig.cjs → watchHanzoguiConfig.cjs} +15 -15
- package/dist/getPragmaOptions.cjs +6 -6
- package/dist/helpers/{requireGuiCore.cjs → requireHanzoguiCore.cjs} +12 -12
- package/dist/registerRequire.cjs +58 -20
- package/dist/worker.cjs +3 -3
- package/package.json +22 -22
- package/src/check-dep-versions.ts +1 -5
- package/src/checkDeps.ts +28 -30
- package/src/constants.ts +2 -2
- package/src/exports.ts +2 -2
- package/src/extractor/babelParse.ts +1 -0
- package/src/extractor/bundle.ts +16 -18
- package/src/extractor/bundleConfig.ts +62 -62
- package/src/extractor/createEvaluator.ts +2 -2
- package/src/extractor/createExtractor.ts +62 -55
- package/src/extractor/createLogger.ts +5 -3
- package/src/extractor/esbuildTsconfigPaths.ts +1 -1
- package/src/extractor/extractHelpers.ts +15 -12
- package/src/extractor/extractMediaStyle.ts +19 -13
- package/src/extractor/extractToClassNames.ts +11 -11
- package/src/extractor/extractToNative.ts +13 -13
- package/src/extractor/{getGuiConfigPathFromOptionsConfig.ts → getHanzoguiConfigPathFromOptionsConfig.ts} +3 -3
- package/src/extractor/getPrefixLogs.ts +3 -3
- package/src/extractor/getStaticBindingsForScope.ts +2 -2
- package/src/extractor/hasTopLevelAwait.ts +28 -0
- package/src/extractor/{loadGui.ts → loadHanzogui.ts} +86 -83
- package/src/extractor/regenerateConfig.ts +34 -24
- package/src/extractor/{watchGuiConfig.ts → watchHanzoguiConfig.ts} +10 -10
- package/src/getPragmaOptions.ts +6 -6
- package/src/helpers/requireHanzoguiCore.ts +28 -0
- package/src/registerRequire.ts +79 -34
- package/src/server.ts +2 -2
- package/src/types.ts +13 -10
- package/src/worker.ts +7 -7
- package/types/check-dep-versions.d.ts.map +1 -1
- package/types/checkDeps.d.ts.map +1 -1
- package/types/constants.d.ts.map +1 -1
- package/types/exports.d.ts +2 -2
- package/types/exports.d.ts.map +1 -1
- package/types/extractor/babelParse.d.ts.map +1 -1
- package/types/extractor/bundle.d.ts +2 -2
- package/types/extractor/bundle.d.ts.map +1 -1
- package/types/extractor/bundleConfig.d.ts +12 -12
- package/types/extractor/bundleConfig.d.ts.map +1 -1
- package/types/extractor/createEvaluator.d.ts +2 -2
- package/types/extractor/createEvaluator.d.ts.map +1 -1
- package/types/extractor/createExtractor.d.ts +5 -5
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/createLogger.d.ts +2 -2
- package/types/extractor/createLogger.d.ts.map +1 -1
- package/types/extractor/extractHelpers.d.ts +8 -8
- package/types/extractor/extractHelpers.d.ts.map +1 -1
- package/types/extractor/extractMediaStyle.d.ts +4 -4
- package/types/extractor/extractMediaStyle.d.ts.map +1 -1
- package/types/extractor/extractToClassNames.d.ts +2 -2
- package/types/extractor/extractToClassNames.d.ts.map +1 -1
- package/types/extractor/extractToNative.d.ts +3 -3
- package/types/extractor/extractToNative.d.ts.map +1 -1
- package/types/extractor/getHanzoguiConfigPathFromOptionsConfig.d.ts +3 -0
- package/types/extractor/getHanzoguiConfigPathFromOptionsConfig.d.ts.map +1 -0
- package/types/extractor/getPrefixLogs.d.ts +2 -2
- package/types/extractor/getPrefixLogs.d.ts.map +1 -1
- package/types/extractor/hasTopLevelAwait.d.ts +2 -0
- package/types/extractor/hasTopLevelAwait.d.ts.map +1 -0
- package/types/extractor/loadHanzogui.d.ts +22 -0
- package/types/extractor/loadHanzogui.d.ts.map +1 -0
- package/types/extractor/regenerateConfig.d.ts +4 -4
- package/types/extractor/regenerateConfig.d.ts.map +1 -1
- package/types/extractor/watchHanzoguiConfig.d.ts +5 -0
- package/types/extractor/watchHanzoguiConfig.d.ts.map +1 -0
- package/types/helpers/requireHanzoguiCore.d.ts +3 -0
- package/types/helpers/requireHanzoguiCore.d.ts.map +1 -0
- package/types/registerRequire.d.ts +3 -3
- package/types/registerRequire.d.ts.map +1 -1
- package/types/server.d.ts +2 -2
- package/types/server.d.ts.map +1 -1
- package/types/types.d.ts +10 -10
- package/types/types.d.ts.map +1 -1
- package/types/worker.d.ts +4 -4
- package/types/worker.d.ts.map +1 -1
- package/src/helpers/requireGuiCore.ts +0 -28
- package/types/extractor/getGuiConfigPathFromOptionsConfig.d.ts +0 -3
- package/types/extractor/getGuiConfigPathFromOptionsConfig.d.ts.map +0 -1
- package/types/extractor/loadGui.d.ts +0 -22
- package/types/extractor/loadGui.d.ts.map +0 -1
- package/types/extractor/watchGuiConfig.d.ts +0 -5
- package/types/extractor/watchGuiConfig.d.ts.map +0 -1
- package/types/helpers/requireGuiCore.d.ts +0 -3
- package/types/helpers/requireGuiCore.d.ts.map +0 -1
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
type PseudoStyles,
|
|
11
11
|
type SplitStyleProps,
|
|
12
12
|
type StaticConfig,
|
|
13
|
-
type
|
|
13
|
+
type HanzoguiComponentState,
|
|
14
14
|
} from '@hanzogui/web'
|
|
15
15
|
import { existsSync, readFileSync } from 'node:fs'
|
|
16
16
|
import { basename, dirname, resolve, relative } from 'node:path'
|
|
@@ -18,17 +18,17 @@ import { nodeModuleNameResolver, sys } from 'typescript'
|
|
|
18
18
|
import type { ViewStyle } from 'react-native'
|
|
19
19
|
|
|
20
20
|
import { FAILED_EVAL } from '../constants'
|
|
21
|
-
import {
|
|
21
|
+
import { requireHanzoguiCore } from '../helpers/requireHanzoguiCore'
|
|
22
22
|
import type {
|
|
23
23
|
ExtractedAttr,
|
|
24
24
|
ExtractedAttrStyle,
|
|
25
25
|
ExtractorOptions,
|
|
26
26
|
ExtractorParseProps,
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
HanzoguiOptions,
|
|
28
|
+
HanzoguiOptionsWithFileInfo,
|
|
29
29
|
Ternary,
|
|
30
30
|
} from '../types'
|
|
31
|
-
import type { LoadedComponents,
|
|
31
|
+
import type { LoadedComponents, HanzoguiProjectInfo } from './bundleConfig'
|
|
32
32
|
import { createEvaluator, createSafeEvaluator } from './createEvaluator'
|
|
33
33
|
import { evaluateAstNode } from './evaluateAstNode'
|
|
34
34
|
import {
|
|
@@ -44,7 +44,7 @@ import {
|
|
|
44
44
|
import { findTopmostFunction } from './findTopmostFunction'
|
|
45
45
|
import { cleanupBeforeExit, getStaticBindingsForScope } from './getStaticBindingsForScope'
|
|
46
46
|
import { literalToAst } from './literalToAst'
|
|
47
|
-
import {
|
|
47
|
+
import { loadHanzogui, loadHanzoguiSync } from './loadHanzogui'
|
|
48
48
|
import { logLines } from './logLines'
|
|
49
49
|
import { normalizeTernaries } from './normalizeTernaries'
|
|
50
50
|
import { setPropsToFontFamily } from './propsToFontFamilyCache'
|
|
@@ -72,7 +72,7 @@ type FileOrPath = NodePath<t.Program> | t.File
|
|
|
72
72
|
|
|
73
73
|
let hasLoggedBaseInfo = false
|
|
74
74
|
|
|
75
|
-
function isFullyDisabled(props:
|
|
75
|
+
function isFullyDisabled(props: HanzoguiOptions) {
|
|
76
76
|
return props.disableExtraction && props.disableDebugAttr
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -114,7 +114,7 @@ export function createExtractor(
|
|
|
114
114
|
}),
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
const componentState:
|
|
117
|
+
const componentState: HanzoguiComponentState = {
|
|
118
118
|
focus: false,
|
|
119
119
|
focusVisible: false,
|
|
120
120
|
focusWithin: false,
|
|
@@ -138,7 +138,7 @@ export function createExtractor(
|
|
|
138
138
|
process.env.IDENTIFY_TAGS !== 'false' &&
|
|
139
139
|
(process.env.NODE_ENV === 'development' || process.env.IDENTIFY_TAGS)
|
|
140
140
|
|
|
141
|
-
let projectInfo:
|
|
141
|
+
let projectInfo: HanzoguiProjectInfo | null = null
|
|
142
142
|
|
|
143
143
|
// cache of dynamically discovered styled components, keyed by absolute file path
|
|
144
144
|
// persists across files within the same worker/extractor instance
|
|
@@ -217,21 +217,21 @@ export function createExtractor(
|
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
-
// we load
|
|
220
|
+
// we load hanzogui delayed because we need to set some global/env stuff before importing
|
|
221
221
|
// otherwise we'd import `rnw` and cause it to evaluate react-native-web which causes errors
|
|
222
222
|
|
|
223
|
-
function loadSync(props:
|
|
223
|
+
function loadSync(props: HanzoguiOptions) {
|
|
224
224
|
if (isFullyDisabled(props)) {
|
|
225
225
|
return null
|
|
226
226
|
}
|
|
227
|
-
return (projectInfo ||=
|
|
227
|
+
return (projectInfo ||= loadHanzoguiSync(props))
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
-
async function load(props:
|
|
230
|
+
async function load(props: HanzoguiOptions) {
|
|
231
231
|
if (isFullyDisabled(props)) {
|
|
232
232
|
return null
|
|
233
233
|
}
|
|
234
|
-
return (projectInfo ||= await
|
|
234
|
+
return (projectInfo ||= await loadHanzogui(props))
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
return {
|
|
@@ -239,10 +239,10 @@ export function createExtractor(
|
|
|
239
239
|
logger,
|
|
240
240
|
},
|
|
241
241
|
cleanupBeforeExit,
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
return projectInfo?.
|
|
242
|
+
loadHanzogui: load,
|
|
243
|
+
loadHanzoguiSync: loadSync,
|
|
244
|
+
getHanzogui() {
|
|
245
|
+
return projectInfo?.hanzoguiConfig
|
|
246
246
|
},
|
|
247
247
|
parseSync: (f: FileOrPath, props: ExtractorParseProps) => {
|
|
248
248
|
globalThis.expo ||= {} // expo-modules-core checks this and avoids loading "native" modules if exists
|
|
@@ -257,12 +257,12 @@ export function createExtractor(
|
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
function parseWithConfig(
|
|
260
|
-
{ components,
|
|
260
|
+
{ components, hanzoguiConfig }: HanzoguiProjectInfo,
|
|
261
261
|
fileOrPath: FileOrPath,
|
|
262
262
|
options: ExtractorParseProps
|
|
263
263
|
) {
|
|
264
264
|
const {
|
|
265
|
-
config = '
|
|
265
|
+
config = 'hanzogui.config.ts',
|
|
266
266
|
importsWhitelist = ['constants.js'],
|
|
267
267
|
evaluateVars = true,
|
|
268
268
|
sourcePath = '',
|
|
@@ -288,7 +288,7 @@ export function createExtractor(
|
|
|
288
288
|
styledCheckCache.delete(sourcePath)
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
if (sourcePath.includes('.
|
|
291
|
+
if (sourcePath.includes('.hanzogui-dynamic-eval')) {
|
|
292
292
|
return null
|
|
293
293
|
}
|
|
294
294
|
|
|
@@ -300,7 +300,7 @@ export function createExtractor(
|
|
|
300
300
|
proxyThemeVariables,
|
|
301
301
|
getDefaultProps,
|
|
302
302
|
pseudoDescriptors,
|
|
303
|
-
} =
|
|
303
|
+
} = requireHanzoguiCore(platform)
|
|
304
304
|
|
|
305
305
|
let shouldPrintDebug = options.shouldPrintDebug || false
|
|
306
306
|
|
|
@@ -331,7 +331,7 @@ export function createExtractor(
|
|
|
331
331
|
|
|
332
332
|
function isValidStyleKey(name: string, staticConfig: StaticConfig) {
|
|
333
333
|
if (!projectInfo) {
|
|
334
|
-
throw new Error(`
|
|
334
|
+
throw new Error(`Hanzogui extractor not loaded yet`)
|
|
335
335
|
}
|
|
336
336
|
if (platform === 'native' && name[0] === '$' && mediaQueryConfig[name.slice(1)]) {
|
|
337
337
|
return false
|
|
@@ -355,7 +355,7 @@ export function createExtractor(
|
|
|
355
355
|
pseudoDescriptors[name] ||
|
|
356
356
|
// don't disable variants or else you lose many things flattening
|
|
357
357
|
staticConfig.variants?.[name] ||
|
|
358
|
-
projectInfo?.
|
|
358
|
+
projectInfo?.hanzoguiConfig?.shorthands[name]
|
|
359
359
|
)
|
|
360
360
|
}
|
|
361
361
|
|
|
@@ -366,7 +366,7 @@ export function createExtractor(
|
|
|
366
366
|
const isTargetingHTML = platform === 'web'
|
|
367
367
|
const ogDebug = shouldPrintDebug
|
|
368
368
|
const tm = timer()
|
|
369
|
-
const propsWithFileInfo:
|
|
369
|
+
const propsWithFileInfo: HanzoguiOptionsWithFileInfo = {
|
|
370
370
|
...options,
|
|
371
371
|
sourcePath,
|
|
372
372
|
allLoadedComponents: components ? [...components] : [],
|
|
@@ -384,7 +384,7 @@ export function createExtractor(
|
|
|
384
384
|
].join(' ')
|
|
385
385
|
)
|
|
386
386
|
}
|
|
387
|
-
if (process.env.DEBUG?.startsWith('
|
|
387
|
+
if (process.env.DEBUG?.startsWith('hanzogui')) {
|
|
388
388
|
logger.info(
|
|
389
389
|
[
|
|
390
390
|
'loaded:',
|
|
@@ -394,14 +394,14 @@ export function createExtractor(
|
|
|
394
394
|
}
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
-
tm.mark('load-
|
|
397
|
+
tm.mark('load-hanzogui', !!shouldPrintDebug)
|
|
398
398
|
|
|
399
399
|
if (!isFullyDisabled(options)) {
|
|
400
|
-
if (!
|
|
400
|
+
if (!hanzoguiConfig?.themes) {
|
|
401
401
|
console.error(
|
|
402
|
-
`⛔️ Error: Missing "themes" in your
|
|
402
|
+
`⛔️ Error: Missing "themes" in your hanzogui.config file:
|
|
403
403
|
|
|
404
|
-
You may not need the compiler! Remember you can run
|
|
404
|
+
You may not need the compiler! Remember you can run Hanzogui with no configuration at all.
|
|
405
405
|
|
|
406
406
|
You may have not "export default" your config (you can also "export const config").
|
|
407
407
|
|
|
@@ -410,17 +410,17 @@ export function createExtractor(
|
|
|
410
410
|
- or search your lockfile for mis-matches.
|
|
411
411
|
`
|
|
412
412
|
)
|
|
413
|
-
console.info(` Got config:`,
|
|
413
|
+
console.info(` Got config:`, hanzoguiConfig)
|
|
414
414
|
process.exit(0)
|
|
415
415
|
}
|
|
416
416
|
}
|
|
417
417
|
|
|
418
|
-
const firstThemeName = Object.keys(
|
|
419
|
-
const firstTheme =
|
|
418
|
+
const firstThemeName = Object.keys(hanzoguiConfig?.themes || {})[0]
|
|
419
|
+
const firstTheme = hanzoguiConfig?.themes[firstThemeName] || {}
|
|
420
420
|
|
|
421
421
|
if (!firstTheme || typeof firstTheme !== 'object') {
|
|
422
422
|
const err = `Missing theme ${firstThemeName}, an error occurred when importing your config`
|
|
423
|
-
console.info(err, `Got config:`,
|
|
423
|
+
console.info(err, `Got config:`, hanzoguiConfig)
|
|
424
424
|
console.info(`Looking for theme:`, firstThemeName)
|
|
425
425
|
throw new Error(err)
|
|
426
426
|
}
|
|
@@ -443,9 +443,9 @@ export function createExtractor(
|
|
|
443
443
|
if (!isFullyDisabled(options)) {
|
|
444
444
|
if (Object.keys(components || []).length === 0) {
|
|
445
445
|
console.warn(
|
|
446
|
-
`Warning:
|
|
446
|
+
`Warning: Hanzogui didn't find any valid components (DEBUG=hanzogui for more)`
|
|
447
447
|
)
|
|
448
|
-
if (process.env.DEBUG === '
|
|
448
|
+
if (process.env.DEBUG === 'hanzogui') {
|
|
449
449
|
console.info(`components`, Object.keys(components || []), components)
|
|
450
450
|
}
|
|
451
451
|
}
|
|
@@ -487,7 +487,7 @@ export function createExtractor(
|
|
|
487
487
|
|
|
488
488
|
if (extractStyledDefinitions && enableDynamicEvaluation) {
|
|
489
489
|
// check all imports for `styled`, not just valid packages
|
|
490
|
-
// styled( is basically guaranteed to be
|
|
490
|
+
// styled( is basically guaranteed to be hanzogui regardless of source
|
|
491
491
|
if (node.specifiers.some((specifier) => specifier.local.name === 'styled')) {
|
|
492
492
|
doesUseValidImport = true
|
|
493
493
|
// don't break - need to collect all import declarations for the styled() handler
|
|
@@ -655,7 +655,7 @@ export function createExtractor(
|
|
|
655
655
|
)
|
|
656
656
|
}
|
|
657
657
|
|
|
658
|
-
const out =
|
|
658
|
+
const out = loadHanzoguiSync({
|
|
659
659
|
forceExports: true,
|
|
660
660
|
components: [sourcePath],
|
|
661
661
|
cacheKey: version,
|
|
@@ -684,14 +684,14 @@ export function createExtractor(
|
|
|
684
684
|
if (foundNames) {
|
|
685
685
|
colorLog(
|
|
686
686
|
Color.FgYellow,
|
|
687
|
-
` |
|
|
687
|
+
` | Hanzogui found dynamic components: ${foundNames}`
|
|
688
688
|
)
|
|
689
689
|
}
|
|
690
690
|
}
|
|
691
691
|
} catch (err: any) {
|
|
692
692
|
if (shouldPrintDebug) {
|
|
693
693
|
logger.info(
|
|
694
|
-
`skip optimize styled(${variableName}), unable to pre-process (DEBUG=
|
|
694
|
+
`skip optimize styled(${variableName}), unable to pre-process (DEBUG=hanzogui for more)`
|
|
695
695
|
)
|
|
696
696
|
}
|
|
697
697
|
}
|
|
@@ -895,7 +895,7 @@ export function createExtractor(
|
|
|
895
895
|
return
|
|
896
896
|
}
|
|
897
897
|
|
|
898
|
-
// validate its a proper import from
|
|
898
|
+
// validate its a proper import from hanzogui (or internally inside hanzogui)
|
|
899
899
|
const binding = traversePath.scope.getBinding(node.name.name)
|
|
900
900
|
let moduleName = ''
|
|
901
901
|
let dynamicComponent: { staticConfig: any } | null = null
|
|
@@ -919,7 +919,7 @@ export function createExtractor(
|
|
|
919
919
|
// proactively load the file
|
|
920
920
|
dynamicLoadingInProgress.add(resolved)
|
|
921
921
|
try {
|
|
922
|
-
const out =
|
|
922
|
+
const out = loadHanzoguiSync({
|
|
923
923
|
forceExports: true,
|
|
924
924
|
components: [resolved],
|
|
925
925
|
})
|
|
@@ -971,7 +971,7 @@ export function createExtractor(
|
|
|
971
971
|
getValidComponent(propsWithFileInfo, moduleName, node.name.name)
|
|
972
972
|
if (!component || !component.staticConfig) {
|
|
973
973
|
if (shouldPrintDebug) {
|
|
974
|
-
logger.info(`\n - No
|
|
974
|
+
logger.info(`\n - No Hanzogui conf for: ${node.name.name}\n`)
|
|
975
975
|
}
|
|
976
976
|
return
|
|
977
977
|
}
|
|
@@ -1104,7 +1104,9 @@ export function createExtractor(
|
|
|
1104
1104
|
: []),
|
|
1105
1105
|
|
|
1106
1106
|
// when using a non-CSS driver, de-opt on enterStyle/exitStyle
|
|
1107
|
-
...(
|
|
1107
|
+
...(hanzoguiConfig?.animations.isReactNative
|
|
1108
|
+
? ['enterStyle', 'exitStyle']
|
|
1109
|
+
: []),
|
|
1108
1110
|
])
|
|
1109
1111
|
|
|
1110
1112
|
const inlineWhenUnflattened = new Set(staticConfig.inlineWhenUnflattened || [])
|
|
@@ -1174,7 +1176,7 @@ export function createExtractor(
|
|
|
1174
1176
|
style: {},
|
|
1175
1177
|
theme: defaultTheme,
|
|
1176
1178
|
viewProps: defaultProps,
|
|
1177
|
-
conf:
|
|
1179
|
+
conf: hanzoguiConfig!,
|
|
1178
1180
|
props: defaultProps,
|
|
1179
1181
|
componentState,
|
|
1180
1182
|
styleProps: {
|
|
@@ -1286,9 +1288,9 @@ export function createExtractor(
|
|
|
1286
1288
|
|
|
1287
1289
|
const name = attribute.name.name
|
|
1288
1290
|
|
|
1289
|
-
// in
|
|
1291
|
+
// in hanzogui style is handled at the end of the style loop so its not as simple as just
|
|
1290
1292
|
// adding this as a "style" property
|
|
1291
|
-
// its not used often when using
|
|
1293
|
+
// its not used often when using hanzogui so not optimizing it for now
|
|
1292
1294
|
if (name === 'style') {
|
|
1293
1295
|
shouldDeopt = true
|
|
1294
1296
|
return null
|
|
@@ -1909,7 +1911,7 @@ export function createExtractor(
|
|
|
1909
1911
|
if (!isValidStyleKey(key, staticConfig)) {
|
|
1910
1912
|
return []
|
|
1911
1913
|
}
|
|
1912
|
-
const name =
|
|
1914
|
+
const name = hanzoguiConfig?.shorthands[key] || key
|
|
1913
1915
|
if (value === undefined) {
|
|
1914
1916
|
logger.warn(
|
|
1915
1917
|
`⚠️ Error evaluating default style for component, prop ${key} ${value}`
|
|
@@ -2018,7 +2020,12 @@ export function createExtractor(
|
|
|
2018
2020
|
hasImportedTheme = true
|
|
2019
2021
|
programPath.node.body.push(
|
|
2020
2022
|
t.importDeclaration(
|
|
2021
|
-
[
|
|
2023
|
+
[
|
|
2024
|
+
t.importSpecifier(
|
|
2025
|
+
t.identifier('_HanzoguiTheme'),
|
|
2026
|
+
t.identifier('Theme')
|
|
2027
|
+
),
|
|
2028
|
+
],
|
|
2022
2029
|
t.stringLiteral('@hanzogui/web')
|
|
2023
2030
|
)
|
|
2024
2031
|
)
|
|
@@ -2026,10 +2033,10 @@ export function createExtractor(
|
|
|
2026
2033
|
|
|
2027
2034
|
traversePath.replaceWith(
|
|
2028
2035
|
t.jsxElement(
|
|
2029
|
-
t.jsxOpeningElement(t.jsxIdentifier('
|
|
2036
|
+
t.jsxOpeningElement(t.jsxIdentifier('_HanzoguiTheme'), [
|
|
2030
2037
|
t.jsxAttribute(t.jsxIdentifier('name'), themeVal.value),
|
|
2031
2038
|
]),
|
|
2032
|
-
t.jsxClosingElement(t.jsxIdentifier('
|
|
2039
|
+
t.jsxClosingElement(t.jsxIdentifier('_HanzoguiTheme')),
|
|
2033
2040
|
[traversePath.node]
|
|
2034
2041
|
)
|
|
2035
2042
|
)
|
|
@@ -2187,7 +2194,7 @@ export function createExtractor(
|
|
|
2187
2194
|
|
|
2188
2195
|
let key = Object.keys(cur.value)[0]
|
|
2189
2196
|
const value = cur.value[key]
|
|
2190
|
-
const fullKey =
|
|
2197
|
+
const fullKey = hanzoguiConfig?.shorthands[key]
|
|
2191
2198
|
// expand shorthands
|
|
2192
2199
|
if (fullKey) {
|
|
2193
2200
|
cur.value = { [fullKey]: value }
|
|
@@ -2615,7 +2622,7 @@ export function createExtractor(
|
|
|
2615
2622
|
node,
|
|
2616
2623
|
lineNumbers,
|
|
2617
2624
|
filePath,
|
|
2618
|
-
config:
|
|
2625
|
+
config: hanzoguiConfig!,
|
|
2619
2626
|
flatNodeName,
|
|
2620
2627
|
attemptEval,
|
|
2621
2628
|
jsxPath: traversePath,
|
|
@@ -2651,9 +2658,9 @@ export function createExtractor(
|
|
|
2651
2658
|
|
|
2652
2659
|
if (!(err instanceof BailOptimizationError)) {
|
|
2653
2660
|
console.error(
|
|
2654
|
-
`@hanzogui/static error, reverting optimization. In ${filePath} ${lineNumbers} on ${originalNodeName}: ${err.message}. For stack trace set environment
|
|
2661
|
+
`@hanzogui/static error, reverting optimization. In ${filePath} ${lineNumbers} on ${originalNodeName}: ${err.message}. For stack trace set environment TAMAGUI_DEBUG=1`
|
|
2655
2662
|
)
|
|
2656
|
-
if (process.env.
|
|
2663
|
+
if (process.env.TAMAGUI_DEBUG === '1') {
|
|
2657
2664
|
console.error(err.stack)
|
|
2658
2665
|
}
|
|
2659
2666
|
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { basename } from 'node:path'
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { HanzoguiOptions } from '../types'
|
|
4
4
|
import { getPrefixLogs } from './getPrefixLogs'
|
|
5
5
|
|
|
6
|
-
export function createLogger(sourcePath: string, options:
|
|
6
|
+
export function createLogger(sourcePath: string, options: HanzoguiOptions) {
|
|
7
7
|
const shouldLogTiming = options.logTimings ?? true
|
|
8
8
|
const start = Date.now()
|
|
9
9
|
const mem =
|
|
10
|
-
process.env.
|
|
10
|
+
process.env.TAMAGUI_SHOW_MEMORY_USAGE && shouldLogTiming
|
|
11
|
+
? process.memoryUsage()
|
|
12
|
+
: null
|
|
11
13
|
|
|
12
14
|
return (res) => {
|
|
13
15
|
if (!shouldLogTiming) {
|
|
@@ -25,7 +25,7 @@ export function TsconfigPathsPlugin(): Plugin {
|
|
|
25
25
|
name,
|
|
26
26
|
setup({ onResolve }) {
|
|
27
27
|
onResolve({ filter: /.*/ }, (args) => {
|
|
28
|
-
// skip @
|
|
28
|
+
// skip @hanzogui packages - they should be externalized, not resolved via tsconfig
|
|
29
29
|
if (args.path.startsWith('@hanzogui/')) {
|
|
30
30
|
return null
|
|
31
31
|
}
|
|
@@ -6,7 +6,7 @@ import * as t from '@babel/types'
|
|
|
6
6
|
import findRoot from 'find-root'
|
|
7
7
|
|
|
8
8
|
import { memoize } from '../helpers/memoize'
|
|
9
|
-
import type { ExtractedAttr,
|
|
9
|
+
import type { ExtractedAttr, HanzoguiOptionsWithFileInfo, Ternary } from '../types'
|
|
10
10
|
|
|
11
11
|
// import { astToLiteral } from './literalToAst'
|
|
12
12
|
|
|
@@ -98,7 +98,7 @@ export function findComponentName(scope) {
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
export function isValidThemeHook(
|
|
101
|
-
props:
|
|
101
|
+
props: HanzoguiOptionsWithFileInfo,
|
|
102
102
|
jsxPath: NodePath<t.JSXElement>,
|
|
103
103
|
n: t.MemberExpression,
|
|
104
104
|
sourcePath?: string
|
|
@@ -122,7 +122,7 @@ export function isValidThemeHook(
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
export const isInsideComponentPackage = (
|
|
125
|
-
props:
|
|
125
|
+
props: HanzoguiOptionsWithFileInfo,
|
|
126
126
|
moduleName: string
|
|
127
127
|
) => {
|
|
128
128
|
return getValidComponentsPaths(props).some((path) => {
|
|
@@ -130,14 +130,17 @@ export const isInsideComponentPackage = (
|
|
|
130
130
|
})
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
export const isComponentPackage = (
|
|
133
|
+
export const isComponentPackage = (
|
|
134
|
+
props: HanzoguiOptionsWithFileInfo,
|
|
135
|
+
srcName: string
|
|
136
|
+
) => {
|
|
134
137
|
return getValidComponentsPaths(props).some((path) => {
|
|
135
138
|
return srcName.startsWith(path)
|
|
136
139
|
})
|
|
137
140
|
}
|
|
138
141
|
|
|
139
142
|
export function getValidComponent(
|
|
140
|
-
props:
|
|
143
|
+
props: HanzoguiOptionsWithFileInfo,
|
|
141
144
|
moduleName: string,
|
|
142
145
|
componentName: string
|
|
143
146
|
) {
|
|
@@ -158,7 +161,7 @@ export function getValidComponent(
|
|
|
158
161
|
return null
|
|
159
162
|
}
|
|
160
163
|
|
|
161
|
-
export const isValidModule = (props:
|
|
164
|
+
export const isValidModule = (props: HanzoguiOptionsWithFileInfo, moduleName: string) => {
|
|
162
165
|
if (typeof moduleName !== 'string') {
|
|
163
166
|
throw new Error(`No module name`)
|
|
164
167
|
}
|
|
@@ -172,7 +175,7 @@ export const isValidModule = (props: GuiOptionsWithFileInfo, moduleName: string)
|
|
|
172
175
|
}
|
|
173
176
|
|
|
174
177
|
export const getValidImport = (
|
|
175
|
-
props:
|
|
178
|
+
props: HanzoguiOptionsWithFileInfo,
|
|
176
179
|
moduleName: string,
|
|
177
180
|
componentName?: string
|
|
178
181
|
) => {
|
|
@@ -184,7 +187,7 @@ export const getValidImport = (
|
|
|
184
187
|
}
|
|
185
188
|
|
|
186
189
|
export const isValidImport = (
|
|
187
|
-
props:
|
|
190
|
+
props: HanzoguiOptionsWithFileInfo,
|
|
188
191
|
moduleName: string,
|
|
189
192
|
componentName?: string
|
|
190
193
|
) => {
|
|
@@ -194,12 +197,12 @@ export const isValidImport = (
|
|
|
194
197
|
return Boolean(getValidImport(props, moduleName, componentName))
|
|
195
198
|
}
|
|
196
199
|
|
|
197
|
-
const getValidComponentPackages = memoize((props:
|
|
198
|
-
// just always look for `
|
|
199
|
-
return [...new Set(['@hanzogui/core', '
|
|
200
|
+
const getValidComponentPackages = memoize((props: HanzoguiOptionsWithFileInfo) => {
|
|
201
|
+
// just always look for `hanzogui` and `@hanzogui/core`
|
|
202
|
+
return [...new Set(['@hanzogui/core', 'hanzogui', ...(props.components || [])])]
|
|
200
203
|
})
|
|
201
204
|
|
|
202
|
-
export const getValidComponentsPaths = memoize((props:
|
|
205
|
+
export const getValidComponentsPaths = memoize((props: HanzoguiOptionsWithFileInfo) => {
|
|
203
206
|
return getValidComponentPackages(props).flatMap((pkg) => {
|
|
204
207
|
const root = findRoot(pkg)
|
|
205
208
|
const based = basename(root)
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import type { NodePath } from '@babel/traverse'
|
|
2
2
|
import * as t from '@babel/types'
|
|
3
|
-
import type {
|
|
3
|
+
import type { HanzoguiInternalConfig } from '@hanzogui/core'
|
|
4
4
|
import * as core from '@hanzogui/core'
|
|
5
5
|
import type { ViewStyle } from 'react-native'
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import type { StyleObject,
|
|
7
|
+
import { requireHanzoguiCore } from '../helpers/requireHanzoguiCore'
|
|
8
|
+
import type { StyleObject, HanzoguiOptionsWithFileInfo, Ternary } from '../types'
|
|
9
9
|
import { isPresent, isValidImport } from './extractHelpers'
|
|
10
10
|
|
|
11
11
|
export function extractMediaStyle(
|
|
12
|
-
props:
|
|
12
|
+
props: HanzoguiOptionsWithFileInfo,
|
|
13
13
|
ternary: Ternary,
|
|
14
14
|
jsxPath: NodePath<t.JSXElement>,
|
|
15
|
-
|
|
15
|
+
hanzoguiConfig: HanzoguiInternalConfig,
|
|
16
16
|
sourcePath: string,
|
|
17
17
|
importance = 0,
|
|
18
18
|
shouldPrintDebug: boolean | 'verbose' = false
|
|
19
19
|
) {
|
|
20
|
-
const { getCSSStylesAtomic } =
|
|
20
|
+
const { getCSSStylesAtomic } = requireHanzoguiCore('web')
|
|
21
21
|
const mt = getMediaQueryTernary(props, ternary, jsxPath, sourcePath)
|
|
22
22
|
if (!mt) {
|
|
23
23
|
return null
|
|
24
24
|
}
|
|
25
25
|
const { key } = mt
|
|
26
|
-
const mq =
|
|
26
|
+
const mq = hanzoguiConfig.media[key]
|
|
27
27
|
if (!mq) {
|
|
28
|
-
console.error(`Media query "${key}" not found: ${Object.keys(
|
|
28
|
+
console.error(`Media query "${key}" not found: ${Object.keys(hanzoguiConfig.media)}`)
|
|
29
29
|
return null
|
|
30
30
|
}
|
|
31
31
|
const getStyleObj = (styleObj: ViewStyle | null, negate = false) => {
|
|
@@ -40,7 +40,7 @@ export function extractMediaStyle(
|
|
|
40
40
|
return null
|
|
41
41
|
}
|
|
42
42
|
// for now order first strongest
|
|
43
|
-
const mediaKeys = Object.keys(
|
|
43
|
+
const mediaKeys = Object.keys(hanzoguiConfig.media)
|
|
44
44
|
const mediaKeyPrecendence = mediaKeys.reduce((acc, cur, i) => {
|
|
45
45
|
acc[cur] = new Array(importance + 1).fill(':root').join('')
|
|
46
46
|
return acc
|
|
@@ -54,7 +54,13 @@ export function extractMediaStyle(
|
|
|
54
54
|
const styles = getCSSStylesAtomic(styleObj as any)
|
|
55
55
|
|
|
56
56
|
const singleMediaStyles = styles.map((style) => {
|
|
57
|
-
const mediaStyle = core.createMediaStyle(
|
|
57
|
+
const mediaStyle = core.createMediaStyle(
|
|
58
|
+
style,
|
|
59
|
+
key,
|
|
60
|
+
hanzoguiConfig.media,
|
|
61
|
+
true,
|
|
62
|
+
negate
|
|
63
|
+
)
|
|
58
64
|
const className = `.${mediaStyle[core.StyleObjectIdentifier]}`
|
|
59
65
|
return {
|
|
60
66
|
...mediaStyle,
|
|
@@ -79,7 +85,7 @@ export function extractMediaStyle(
|
|
|
79
85
|
}
|
|
80
86
|
|
|
81
87
|
function getMediaQueryTernary(
|
|
82
|
-
props:
|
|
88
|
+
props: HanzoguiOptionsWithFileInfo,
|
|
83
89
|
ternary: Ternary,
|
|
84
90
|
jsxPath: NodePath<t.JSXElement>,
|
|
85
91
|
sourcePath: string
|
|
@@ -128,7 +134,7 @@ function getMediaQueryTernary(
|
|
|
128
134
|
}
|
|
129
135
|
|
|
130
136
|
function getMediaInfoFromExpression(
|
|
131
|
-
props:
|
|
137
|
+
props: HanzoguiOptionsWithFileInfo,
|
|
132
138
|
test: t.Expression,
|
|
133
139
|
jsxPath: NodePath<t.JSXElement>,
|
|
134
140
|
sourcePath: string,
|
|
@@ -167,7 +173,7 @@ function getMediaInfoFromExpression(
|
|
|
167
173
|
}
|
|
168
174
|
|
|
169
175
|
export function isValidMediaCall(
|
|
170
|
-
props:
|
|
176
|
+
props: HanzoguiOptionsWithFileInfo,
|
|
171
177
|
jsxPath: NodePath<t.JSXElement>,
|
|
172
178
|
init: t.Expression,
|
|
173
179
|
sourcePath: string
|
|
@@ -4,8 +4,8 @@ import * as t from '@babel/types'
|
|
|
4
4
|
import { mergeProps, StyleObjectIdentifier, StyleObjectRules } from '@hanzogui/web'
|
|
5
5
|
import * as path from 'node:path'
|
|
6
6
|
import * as util from 'node:util'
|
|
7
|
-
import {
|
|
8
|
-
import type { StyleObject,
|
|
7
|
+
import { requireHanzoguiCore } from '../helpers/requireHanzoguiCore'
|
|
8
|
+
import type { StyleObject, HanzoguiOptions, Ternary } from '../types'
|
|
9
9
|
import { babelParse } from './babelParse'
|
|
10
10
|
import type { Extractor } from './createExtractor'
|
|
11
11
|
import { createLogger } from './createLogger'
|
|
@@ -37,7 +37,7 @@ export type ExtractToClassNamesProps = {
|
|
|
37
37
|
extractor: Extractor
|
|
38
38
|
source: string | Buffer
|
|
39
39
|
sourcePath?: string
|
|
40
|
-
options:
|
|
40
|
+
options: HanzoguiOptions
|
|
41
41
|
shouldPrintDebug: boolean | 'verbose'
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -55,7 +55,7 @@ export async function extractToClassNames({
|
|
|
55
55
|
shouldPrintDebug,
|
|
56
56
|
}: ExtractToClassNamesProps): Promise<ExtractedResponse | null> {
|
|
57
57
|
const tm = timer()
|
|
58
|
-
const { getCSSStylesAtomic, createMediaStyle } =
|
|
58
|
+
const { getCSSStylesAtomic, createMediaStyle } = requireHanzoguiCore('web')
|
|
59
59
|
|
|
60
60
|
if (sourcePath.includes('node_modules')) {
|
|
61
61
|
return null
|
|
@@ -78,9 +78,9 @@ export async function extractToClassNames({
|
|
|
78
78
|
console.warn(`${sourcePath.slice(0, 100)} - bad filename.`)
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
if (!options.disableExtraction && !options['
|
|
81
|
+
if (!options.disableExtraction && !options['_disableLoadHanzogui']) {
|
|
82
82
|
// dont include loading in timing of parsing (one time cost)
|
|
83
|
-
await extractor.
|
|
83
|
+
await extractor.loadHanzogui(options)
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
const printLog = createLogger(sourcePath, options)
|
|
@@ -98,7 +98,7 @@ export async function extractToClassNames({
|
|
|
98
98
|
tm.mark(`babel-parse`, shouldPrintDebug === 'verbose')
|
|
99
99
|
|
|
100
100
|
const cssMap = new Map<string, { css: string; commentTexts: string[] }>()
|
|
101
|
-
const
|
|
101
|
+
const hanzoguiConfig = extractor.getHanzogui()!
|
|
102
102
|
|
|
103
103
|
const res = await extractor.parse(ast, {
|
|
104
104
|
shouldPrintDebug,
|
|
@@ -208,7 +208,7 @@ export async function extractToClassNames({
|
|
|
208
208
|
const mediaStyle = createMediaStyle(
|
|
209
209
|
style,
|
|
210
210
|
mediaName,
|
|
211
|
-
extractor.
|
|
211
|
+
extractor.getHanzogui()!.media,
|
|
212
212
|
mediaType,
|
|
213
213
|
false,
|
|
214
214
|
mediaStylesSeen
|
|
@@ -218,11 +218,11 @@ export async function extractToClassNames({
|
|
|
218
218
|
continue
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
if (mediaName in
|
|
221
|
+
if (mediaName in hanzoguiConfig.media) {
|
|
222
222
|
const mediaStyle = createMediaStyle(
|
|
223
223
|
style,
|
|
224
224
|
mediaName,
|
|
225
|
-
extractor.
|
|
225
|
+
extractor.getHanzogui()!.media,
|
|
226
226
|
true,
|
|
227
227
|
false,
|
|
228
228
|
mediaStylesSeen
|
|
@@ -284,7 +284,7 @@ export async function extractToClassNames({
|
|
|
284
284
|
parserProps,
|
|
285
285
|
attr.value,
|
|
286
286
|
jsxPath,
|
|
287
|
-
extractor.
|
|
287
|
+
extractor.getHanzogui()!,
|
|
288
288
|
sourcePath || '',
|
|
289
289
|
mediaStylesSeen++,
|
|
290
290
|
shouldPrintDebug
|