@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
|
@@ -6,12 +6,12 @@ import template from '@babel/template'
|
|
|
6
6
|
import * as t from '@babel/types'
|
|
7
7
|
import { basename } from 'node:path'
|
|
8
8
|
import { getPragmaOptions } from '../getPragmaOptions'
|
|
9
|
-
import type {
|
|
9
|
+
import type { HanzoguiOptions } from '../types'
|
|
10
10
|
import { createExtractor } from './createExtractor'
|
|
11
11
|
import { createLogger } from './createLogger'
|
|
12
12
|
import { isSimpleSpread } from './extractHelpers'
|
|
13
13
|
import { literalToAst } from './literalToAst'
|
|
14
|
-
import {
|
|
14
|
+
import { loadHanzoguiBuildConfigSync } from './loadHanzogui'
|
|
15
15
|
|
|
16
16
|
const importNativeView = template(`
|
|
17
17
|
const __ReactNativeView = require('react-native').View;
|
|
@@ -26,12 +26,12 @@ const importWithStyle = template.ast(`import { _withStableStyle } from '@hanzogu
|
|
|
26
26
|
|
|
27
27
|
const extractor = createExtractor({ platform: 'native' })
|
|
28
28
|
|
|
29
|
-
let
|
|
29
|
+
let hanzoguiBuildOptionsLoaded: HanzoguiOptions | null
|
|
30
30
|
|
|
31
31
|
export function extractToNative(
|
|
32
32
|
sourceFileName: string,
|
|
33
33
|
sourceCode: string,
|
|
34
|
-
options:
|
|
34
|
+
options: HanzoguiOptions
|
|
35
35
|
): BabelFileResult {
|
|
36
36
|
const ast = parse(sourceCode, {
|
|
37
37
|
sourceType: 'module',
|
|
@@ -55,15 +55,15 @@ export function extractToNative(
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export function getBabelPlugin() {
|
|
58
|
-
return declare((api, options:
|
|
58
|
+
return declare((api, options: HanzoguiOptions) => {
|
|
59
59
|
api.assertVersion(7)
|
|
60
60
|
return getBabelParseDefinition(options)
|
|
61
61
|
})
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
export function getBabelParseDefinition(options:
|
|
64
|
+
export function getBabelParseDefinition(options: HanzoguiOptions) {
|
|
65
65
|
return {
|
|
66
|
-
name: '
|
|
66
|
+
name: 'hanzogui',
|
|
67
67
|
|
|
68
68
|
visitor: {
|
|
69
69
|
Program: {
|
|
@@ -106,16 +106,16 @@ export function getBabelParseDefinition(options: GuiOptions) {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
if (!options.config && !options.components) {
|
|
109
|
-
// if no config/components given try and load from the
|
|
110
|
-
|
|
109
|
+
// if no config/components given try and load from the hanzogui.build.ts file
|
|
110
|
+
hanzoguiBuildOptionsLoaded ||= loadHanzoguiBuildConfigSync({})
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
const finalOptions = {
|
|
114
114
|
// @ts-ignore just in case they leave it out
|
|
115
115
|
platform: 'native',
|
|
116
|
-
...
|
|
116
|
+
...hanzoguiBuildOptionsLoaded,
|
|
117
117
|
...options,
|
|
118
|
-
} satisfies
|
|
118
|
+
} satisfies HanzoguiOptions
|
|
119
119
|
|
|
120
120
|
const printLog = createLogger(sourcePath, finalOptions)
|
|
121
121
|
|
|
@@ -419,7 +419,7 @@ export function getBabelParseDefinition(options: GuiOptions) {
|
|
|
419
419
|
if (message.includes('Unexpected return value from visitor method')) {
|
|
420
420
|
message = 'Unexpected return value from visitor method'
|
|
421
421
|
}
|
|
422
|
-
console.warn('Error in
|
|
422
|
+
console.warn('Error in Hanzogui parse, skipping', message, err.stack)
|
|
423
423
|
return
|
|
424
424
|
}
|
|
425
425
|
}
|
|
@@ -466,7 +466,7 @@ function assertValidTag(node: t.JSXOpeningElement) {
|
|
|
466
466
|
if (node.attributes.find((x) => x.type === 'JSXAttribute' && x.name.name === 'style')) {
|
|
467
467
|
// we can just deopt here instead and log warning
|
|
468
468
|
// need to make onExtractTag have a special catch error or similar
|
|
469
|
-
if (process.env.DEBUG?.startsWith('
|
|
469
|
+
if (process.env.DEBUG?.startsWith('hanzogui')) {
|
|
470
470
|
console.warn('⚠️ Cannot pass style attribute to extracted style')
|
|
471
471
|
}
|
|
472
472
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { isAbsolute, join } from 'node:path'
|
|
2
2
|
|
|
3
3
|
import { statSync } from 'node:fs'
|
|
4
|
-
import type {
|
|
4
|
+
import type { HanzoguiOptions } from '../types'
|
|
5
5
|
|
|
6
|
-
export function
|
|
7
|
-
config: NonNullable<
|
|
6
|
+
export function getHanzoguiConfigPathFromOptionsConfig(
|
|
7
|
+
config: NonNullable<HanzoguiOptions['config']>
|
|
8
8
|
) {
|
|
9
9
|
if (isAbsolute(config)) {
|
|
10
10
|
return config
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Color, colorString } from '@hanzogui/cli-color'
|
|
2
|
-
import type {
|
|
2
|
+
import type { HanzoguiOptions } from '../types'
|
|
3
3
|
|
|
4
|
-
export function getPrefixLogs(options?:
|
|
4
|
+
export function getPrefixLogs(options?: HanzoguiOptions) {
|
|
5
5
|
return (
|
|
6
6
|
options?.prefixLogs ??
|
|
7
|
-
` 🐥 [
|
|
7
|
+
` 🐥 [hanzogui] ${colorString(Color.FgYellow, options?.platform || 'web')}`
|
|
8
8
|
)
|
|
9
9
|
}
|
|
@@ -137,9 +137,9 @@ export async function getStaticBindingsForScope(
|
|
|
137
137
|
} catch (err: any) {
|
|
138
138
|
if (shouldPrintDebug) {
|
|
139
139
|
console.warn(
|
|
140
|
-
` | Skipping partial evaluation of constant file: ${moduleName} (DEBUG=
|
|
140
|
+
` | Skipping partial evaluation of constant file: ${moduleName} (DEBUG=hanzogui for more)`
|
|
141
141
|
)
|
|
142
|
-
} else if (process.env.DEBUG?.startsWith('
|
|
142
|
+
} else if (process.env.DEBUG?.startsWith('hanzogui')) {
|
|
143
143
|
console.info(`Error in partial evaluation`, err.message, err.stack)
|
|
144
144
|
}
|
|
145
145
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import traverse from '@babel/traverse'
|
|
2
|
+
import { babelParse } from './babelParse'
|
|
3
|
+
|
|
4
|
+
export function hasTopLevelAwait(contents: string, fileName?: string) {
|
|
5
|
+
if (!contents.includes('await')) {
|
|
6
|
+
return false
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const ast = babelParse(contents, fileName)
|
|
10
|
+
let found = false
|
|
11
|
+
|
|
12
|
+
traverse(ast, {
|
|
13
|
+
AwaitExpression(path) {
|
|
14
|
+
if (!path.getFunctionParent()) {
|
|
15
|
+
found = true
|
|
16
|
+
path.stop()
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
ForOfStatement(path) {
|
|
20
|
+
if (path.node.await && !path.getFunctionParent()) {
|
|
21
|
+
found = true
|
|
22
|
+
path.stop()
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
return found
|
|
28
|
+
}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
import { basename, dirname, extname, join, relative, resolve } from 'node:path'
|
|
2
2
|
// @ts-ignore why
|
|
3
3
|
import { Color, colorLog } from '@hanzogui/cli-color'
|
|
4
|
-
import type { CLIResolvedOptions, CLIUserOptions,
|
|
5
|
-
import type {
|
|
4
|
+
import type { CLIResolvedOptions, CLIUserOptions, HanzoguiOptions } from '@hanzogui/types'
|
|
5
|
+
import type { HanzoguiInternalConfig } from '@hanzogui/web'
|
|
6
6
|
import esbuild from 'esbuild'
|
|
7
7
|
import * as esbuildWasm from 'esbuild-wasm'
|
|
8
8
|
import * as fsExtra from 'fs-extra'
|
|
9
9
|
|
|
10
10
|
import { SHOULD_DEBUG } from '../constants'
|
|
11
|
-
import {
|
|
11
|
+
import { requireHanzoguiCore } from '../helpers/requireHanzoguiCore'
|
|
12
12
|
import { getNameToPaths, registerRequire } from '../registerRequire'
|
|
13
13
|
import {
|
|
14
|
-
type
|
|
14
|
+
type HanzoguiProjectInfo,
|
|
15
15
|
getBundledConfig,
|
|
16
16
|
getLoadedConfig,
|
|
17
17
|
hasBundledConfigChanged,
|
|
18
18
|
loadComponentsSync,
|
|
19
|
-
|
|
19
|
+
writeHanzoguiCSS,
|
|
20
20
|
} from './bundleConfig'
|
|
21
|
-
import {
|
|
21
|
+
import { getHanzoguiConfigPathFromOptionsConfig } from './getHanzoguiConfigPathFromOptionsConfig'
|
|
22
22
|
import {
|
|
23
|
-
|
|
23
|
+
generateHanzoguiThemes,
|
|
24
24
|
regenerateConfig,
|
|
25
25
|
regenerateConfigSync,
|
|
26
26
|
} from './regenerateConfig'
|
|
27
27
|
|
|
28
|
-
const getFilledOptions = (propsIn: Partial<
|
|
28
|
+
const getFilledOptions = (propsIn: Partial<HanzoguiOptions>): HanzoguiOptions => ({
|
|
29
29
|
// defaults
|
|
30
|
-
platform: (process.env.
|
|
31
|
-
config: '
|
|
32
|
-
components: ['
|
|
33
|
-
...(propsIn as Partial<
|
|
30
|
+
platform: (process.env.TAMAGUI_TARGET as any) || 'web',
|
|
31
|
+
config: 'hanzogui.config.ts',
|
|
32
|
+
components: ['hanzogui'],
|
|
33
|
+
...(propsIn as Partial<HanzoguiOptions>),
|
|
34
34
|
})
|
|
35
35
|
|
|
36
36
|
let isLoadingPromise: null | Promise<any>
|
|
37
37
|
|
|
38
|
-
export async function
|
|
39
|
-
propsIn: Partial<
|
|
40
|
-
): Promise<
|
|
38
|
+
export async function loadHanzogui(
|
|
39
|
+
propsIn: Partial<HanzoguiOptions>
|
|
40
|
+
): Promise<HanzoguiProjectInfo | null> {
|
|
41
41
|
if (isLoadingPromise) return await isLoadingPromise
|
|
42
42
|
|
|
43
43
|
let resolvePromise
|
|
@@ -53,7 +53,7 @@ export async function loadGui(
|
|
|
53
53
|
const bundleInfo = await getBundledConfig(props)
|
|
54
54
|
if (!bundleInfo) {
|
|
55
55
|
console.warn(
|
|
56
|
-
`No bundled config generated, maybe an error in bundling. Set DEBUG=
|
|
56
|
+
`No bundled config generated, maybe an error in bundling. Set DEBUG=hanzogui and re-run to get logs.`
|
|
57
57
|
)
|
|
58
58
|
resolvePromise(null)
|
|
59
59
|
return null
|
|
@@ -62,11 +62,11 @@ export async function loadGui(
|
|
|
62
62
|
// this affects the bundled config so run it first
|
|
63
63
|
await generateThemesAndLog(props)
|
|
64
64
|
|
|
65
|
-
// if they accidently pass in a config without
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
68
|
-
const {
|
|
69
|
-
bundleInfo.
|
|
65
|
+
// if they accidently pass in a config without createHanzogui called,call it
|
|
66
|
+
const maybeHanzoguiConfig = bundleInfo.hanzoguiConfig as HanzoguiInternalConfig
|
|
67
|
+
if (maybeHanzoguiConfig && !maybeHanzoguiConfig.parsed) {
|
|
68
|
+
const { createHanzogui } = requireHanzoguiCore(props.platform || 'web')
|
|
69
|
+
bundleInfo.hanzoguiConfig = createHanzogui(bundleInfo.hanzoguiConfig as any)
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
if (!hasBundledConfigChanged()) {
|
|
@@ -89,20 +89,20 @@ export async function loadGui(
|
|
|
89
89
|
// debounce a bit
|
|
90
90
|
let waiting = false
|
|
91
91
|
|
|
92
|
-
export const generateThemesAndLog = async (options:
|
|
92
|
+
export const generateThemesAndLog = async (options: HanzoguiOptions, force = false) => {
|
|
93
93
|
if (waiting) return
|
|
94
94
|
if (!options.themeBuilder) return
|
|
95
95
|
try {
|
|
96
96
|
waiting = true
|
|
97
97
|
await new Promise((res) => setTimeout(res, 30))
|
|
98
|
-
const didGenerate = await
|
|
98
|
+
const didGenerate = await generateHanzoguiThemes(options, force)
|
|
99
99
|
|
|
100
100
|
// only logs when changed
|
|
101
101
|
if (didGenerate) {
|
|
102
102
|
const whitespaceBefore = ` `
|
|
103
103
|
colorLog(
|
|
104
104
|
Color.FgYellow,
|
|
105
|
-
`${whitespaceBefore}➡ [
|
|
105
|
+
`${whitespaceBefore}➡ [hanzogui] generated themes: ${relative(
|
|
106
106
|
process.cwd(),
|
|
107
107
|
options.themeBuilder.output
|
|
108
108
|
)}`
|
|
@@ -111,7 +111,7 @@ export const generateThemesAndLog = async (options: GuiOptions, force = false) =
|
|
|
111
111
|
if (options.outputCSS) {
|
|
112
112
|
const loadedConfig = getLoadedConfig()
|
|
113
113
|
if (loadedConfig) {
|
|
114
|
-
await
|
|
114
|
+
await writeHanzoguiCSS(options.outputCSS, loadedConfig)
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
}
|
|
@@ -120,20 +120,20 @@ export const generateThemesAndLog = async (options: GuiOptions, force = false) =
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
const last: Record<string,
|
|
123
|
+
const last: Record<string, HanzoguiProjectInfo | null> = {}
|
|
124
124
|
const lastVersion: Record<string, string> = {}
|
|
125
125
|
|
|
126
126
|
// esbuild-wasm state - initialized once per process
|
|
127
127
|
let esbuildWasmInitialized = false
|
|
128
128
|
|
|
129
129
|
/**
|
|
130
|
-
* Load
|
|
130
|
+
* Load hanzogui.build.ts config using esbuild-wasm transform
|
|
131
131
|
* Uses WASM to avoid native esbuild service lifecycle issues (EPIPE errors)
|
|
132
132
|
*/
|
|
133
|
-
export async function
|
|
134
|
-
|
|
135
|
-
): Promise<
|
|
136
|
-
const buildFilePath =
|
|
133
|
+
export async function loadHanzoguiBuildConfigAsync(
|
|
134
|
+
hanzoguiOptions: Partial<HanzoguiOptions> | undefined
|
|
135
|
+
): Promise<HanzoguiOptions> {
|
|
136
|
+
const buildFilePath = hanzoguiOptions?.buildFile ?? './hanzogui.build.ts'
|
|
137
137
|
const absolutePath =
|
|
138
138
|
buildFilePath[0] === '.' ? join(process.cwd(), buildFilePath) : buildFilePath
|
|
139
139
|
|
|
@@ -166,34 +166,36 @@ export async function loadGuiBuildConfigAsync(
|
|
|
166
166
|
throw new Error(`No default export found in ${buildFilePath}: ${out}`)
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
|
|
170
|
-
...
|
|
169
|
+
hanzoguiOptions = {
|
|
170
|
+
...hanzoguiOptions,
|
|
171
171
|
...out,
|
|
172
172
|
}
|
|
173
173
|
} catch (err) {
|
|
174
|
-
console.error(`[
|
|
174
|
+
console.error(`[hanzogui] Error loading ${buildFilePath}:`, err)
|
|
175
175
|
throw err
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
if (!
|
|
179
|
+
if (!hanzoguiOptions) {
|
|
180
180
|
throw new Error(
|
|
181
|
-
`No
|
|
181
|
+
`No hanzogui build options found either via input props or at hanzogui.build.ts`
|
|
182
182
|
)
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
return {
|
|
186
|
-
config: '
|
|
187
|
-
components: ['
|
|
188
|
-
...
|
|
189
|
-
} as
|
|
186
|
+
config: 'hanzogui.config.ts',
|
|
187
|
+
components: ['hanzogui', '@hanzogui/core'],
|
|
188
|
+
...hanzoguiOptions,
|
|
189
|
+
} as HanzoguiOptions
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
/**
|
|
193
|
-
* @deprecated Use
|
|
193
|
+
* @deprecated Use loadHanzoguiBuildConfigAsync instead to avoid EPIPE errors
|
|
194
194
|
*/
|
|
195
|
-
export function
|
|
196
|
-
|
|
195
|
+
export function loadHanzoguiBuildConfigSync(
|
|
196
|
+
hanzoguiOptions: Partial<HanzoguiOptions> | undefined
|
|
197
|
+
) {
|
|
198
|
+
const buildFilePath = hanzoguiOptions?.buildFile ?? './hanzogui.build.ts'
|
|
197
199
|
if (fsExtra.existsSync(buildFilePath)) {
|
|
198
200
|
const registered = registerRequire('web')
|
|
199
201
|
try {
|
|
@@ -204,35 +206,35 @@ export function loadGuiBuildConfigSync(guiOptions: Partial<GuiOptions> | undefin
|
|
|
204
206
|
throw new Error(`No default export found in ${buildFilePath}: ${out}`)
|
|
205
207
|
}
|
|
206
208
|
|
|
207
|
-
|
|
208
|
-
...
|
|
209
|
+
hanzoguiOptions = {
|
|
210
|
+
...hanzoguiOptions,
|
|
209
211
|
...out,
|
|
210
212
|
}
|
|
211
213
|
} finally {
|
|
212
214
|
registered.unregister()
|
|
213
215
|
}
|
|
214
216
|
}
|
|
215
|
-
if (!
|
|
217
|
+
if (!hanzoguiOptions) {
|
|
216
218
|
throw new Error(
|
|
217
|
-
`No
|
|
219
|
+
`No hanzogui build options found either via input props or at hanzogui.build.ts`
|
|
218
220
|
)
|
|
219
221
|
}
|
|
220
222
|
return {
|
|
221
|
-
config: '
|
|
222
|
-
components: ['
|
|
223
|
-
...
|
|
224
|
-
} as
|
|
223
|
+
config: 'hanzogui.config.ts',
|
|
224
|
+
components: ['hanzogui', '@hanzogui/core'],
|
|
225
|
+
...hanzoguiOptions,
|
|
226
|
+
} as HanzoguiOptions
|
|
225
227
|
}
|
|
226
228
|
|
|
227
229
|
// loads in-process using esbuild-register
|
|
228
|
-
export function
|
|
230
|
+
export function loadHanzoguiSync({
|
|
229
231
|
forceExports,
|
|
230
232
|
cacheKey,
|
|
231
233
|
...propsIn
|
|
232
|
-
}: Partial<
|
|
234
|
+
}: Partial<HanzoguiOptions> & {
|
|
233
235
|
forceExports?: boolean
|
|
234
236
|
cacheKey?: string
|
|
235
|
-
}):
|
|
237
|
+
}): HanzoguiProjectInfo {
|
|
236
238
|
const key = JSON.stringify(propsIn)
|
|
237
239
|
|
|
238
240
|
if (last[key] && !hasBundledConfigChanged()) {
|
|
@@ -248,7 +250,7 @@ export function loadGuiSync({
|
|
|
248
250
|
// lets shim require and avoid importing react-native + react-native-web
|
|
249
251
|
// we just need to read the config around them
|
|
250
252
|
process.env.IS_STATIC = 'is_static'
|
|
251
|
-
process.env.
|
|
253
|
+
process.env.TAMAGUI_IS_SERVER = 'true'
|
|
252
254
|
|
|
253
255
|
const { unregister } = registerRequire(props.platform || 'web', {
|
|
254
256
|
proxyWormImports: !!forceExports,
|
|
@@ -260,18 +262,18 @@ export function loadGuiSync({
|
|
|
260
262
|
|
|
261
263
|
try {
|
|
262
264
|
// config
|
|
263
|
-
let
|
|
265
|
+
let hanzoguiConfig: HanzoguiInternalConfig | null = null
|
|
264
266
|
if (propsIn.config) {
|
|
265
|
-
const configPath =
|
|
267
|
+
const configPath = getHanzoguiConfigPathFromOptionsConfig(propsIn.config)
|
|
266
268
|
const exp = require(configPath)
|
|
267
269
|
|
|
268
270
|
if (!exp || exp._isProxyWorm) {
|
|
269
271
|
throw new Error(`Got a empty / proxied config!`)
|
|
270
272
|
}
|
|
271
273
|
|
|
272
|
-
|
|
274
|
+
hanzoguiConfig = (exp['default'] || exp['config'] || exp) as HanzoguiInternalConfig
|
|
273
275
|
|
|
274
|
-
if (!
|
|
276
|
+
if (!hanzoguiConfig || !hanzoguiConfig.parsed) {
|
|
275
277
|
const confPath = require.resolve(configPath)
|
|
276
278
|
throw new Error(`Can't find valid config in ${confPath}:
|
|
277
279
|
|
|
@@ -279,9 +281,9 @@ export function loadGuiSync({
|
|
|
279
281
|
}
|
|
280
282
|
|
|
281
283
|
// set up core
|
|
282
|
-
if (
|
|
283
|
-
const {
|
|
284
|
-
|
|
284
|
+
if (hanzoguiConfig) {
|
|
285
|
+
const { createHanzogui } = requireHanzoguiCore(props.platform || 'web')
|
|
286
|
+
createHanzogui(hanzoguiConfig as any)
|
|
285
287
|
}
|
|
286
288
|
}
|
|
287
289
|
|
|
@@ -290,7 +292,7 @@ export function loadGuiSync({
|
|
|
290
292
|
if (!components) {
|
|
291
293
|
throw new Error(`No components loaded`)
|
|
292
294
|
}
|
|
293
|
-
if (process.env.DEBUG === '
|
|
295
|
+
if (process.env.DEBUG === 'hanzogui') {
|
|
294
296
|
console.info(`components`, components)
|
|
295
297
|
}
|
|
296
298
|
|
|
@@ -300,14 +302,14 @@ export function loadGuiSync({
|
|
|
300
302
|
|
|
301
303
|
const info = {
|
|
302
304
|
components,
|
|
303
|
-
|
|
305
|
+
hanzoguiConfig,
|
|
304
306
|
nameToPaths: getNameToPaths(),
|
|
305
|
-
} satisfies
|
|
307
|
+
} satisfies HanzoguiProjectInfo
|
|
306
308
|
|
|
307
|
-
if (
|
|
309
|
+
if (hanzoguiConfig) {
|
|
308
310
|
const { outputCSS } = props
|
|
309
311
|
if (outputCSS) {
|
|
310
|
-
|
|
312
|
+
writeHanzoguiCSS(outputCSS, hanzoguiConfig)
|
|
311
313
|
}
|
|
312
314
|
|
|
313
315
|
regenerateConfigSync(props, info)
|
|
@@ -323,7 +325,7 @@ export function loadGuiSync({
|
|
|
323
325
|
if (err instanceof Error) {
|
|
324
326
|
if (!SHOULD_DEBUG && !forceExports) {
|
|
325
327
|
console.warn(
|
|
326
|
-
`Error loading
|
|
328
|
+
`Error loading hanzogui.config.ts (set DEBUG=hanzogui to see full stack), running hanzogui without custom config`
|
|
327
329
|
)
|
|
328
330
|
console.info(`\n\n ${err.message}\n\n`)
|
|
329
331
|
} else {
|
|
@@ -332,12 +334,12 @@ export function loadGuiSync({
|
|
|
332
334
|
}
|
|
333
335
|
}
|
|
334
336
|
} else {
|
|
335
|
-
console.error(`Error loading
|
|
337
|
+
console.error(`Error loading hanzogui.config.ts`, err)
|
|
336
338
|
}
|
|
337
339
|
|
|
338
340
|
return {
|
|
339
341
|
components: [],
|
|
340
|
-
|
|
342
|
+
hanzoguiConfig: null,
|
|
341
343
|
nameToPaths: {},
|
|
342
344
|
}
|
|
343
345
|
}
|
|
@@ -349,11 +351,11 @@ export function loadGuiSync({
|
|
|
349
351
|
export async function getOptions({
|
|
350
352
|
root = process.cwd(),
|
|
351
353
|
tsconfigPath = 'tsconfig.json',
|
|
352
|
-
|
|
354
|
+
hanzoguiOptions,
|
|
353
355
|
host,
|
|
354
356
|
debug,
|
|
355
357
|
}: Partial<CLIUserOptions> = {}): Promise<CLIResolvedOptions> {
|
|
356
|
-
const dotDir = join(root, '.
|
|
358
|
+
const dotDir = join(root, '.hanzogui')
|
|
357
359
|
let pkgJson = {}
|
|
358
360
|
|
|
359
361
|
try {
|
|
@@ -369,17 +371,18 @@ export async function getOptions({
|
|
|
369
371
|
pkgJson,
|
|
370
372
|
debug,
|
|
371
373
|
tsconfigPath,
|
|
372
|
-
|
|
373
|
-
platform: (process.env.
|
|
374
|
-
components: ['
|
|
375
|
-
...
|
|
374
|
+
hanzoguiOptions: {
|
|
375
|
+
platform: (process.env.TAMAGUI_TARGET as any) || 'web',
|
|
376
|
+
components: ['hanzogui'],
|
|
377
|
+
...hanzoguiOptions,
|
|
376
378
|
config:
|
|
377
|
-
|
|
379
|
+
hanzoguiOptions?.config ??
|
|
380
|
+
(await getDefaultHanzoguiConfigPath(root, hanzoguiOptions?.config)),
|
|
378
381
|
},
|
|
379
382
|
paths: {
|
|
380
383
|
root,
|
|
381
384
|
dotDir,
|
|
382
|
-
conf: join(dotDir, '
|
|
385
|
+
conf: join(dotDir, 'hanzogui.config.json'),
|
|
383
386
|
types: join(dotDir, 'types.json'),
|
|
384
387
|
},
|
|
385
388
|
}
|
|
@@ -390,7 +393,7 @@ export function resolveWebOrNativeSpecificEntry(entry: string) {
|
|
|
390
393
|
const resolved = require.resolve(entry, { paths: [workspaceRoot] })
|
|
391
394
|
const ext = extname(resolved)
|
|
392
395
|
const fileName = basename(resolved).replace(ext, '')
|
|
393
|
-
const specificExt = process.env.
|
|
396
|
+
const specificExt = process.env.TAMAGUI_TARGET === 'web' ? 'web' : 'native'
|
|
394
397
|
const specificFile = join(dirname(resolved), fileName + '.' + specificExt + ext)
|
|
395
398
|
if (fsExtra.existsSync(specificFile)) {
|
|
396
399
|
return specificFile
|
|
@@ -398,10 +401,10 @@ export function resolveWebOrNativeSpecificEntry(entry: string) {
|
|
|
398
401
|
return entry
|
|
399
402
|
}
|
|
400
403
|
|
|
401
|
-
const defaultPaths = ['
|
|
404
|
+
const defaultPaths = ['hanzogui.config.ts', join('src', 'hanzogui.config.ts')]
|
|
402
405
|
let hasWarnedOnce = false
|
|
403
406
|
|
|
404
|
-
async function
|
|
407
|
+
async function getDefaultHanzoguiConfigPath(root: string, configPath?: string) {
|
|
405
408
|
const searchPaths = [
|
|
406
409
|
...new Set(
|
|
407
410
|
[configPath, ...defaultPaths].filter(Boolean).map((p) => join(root, p as string))
|
|
@@ -416,13 +419,13 @@ async function getDefaultGuiConfigPath(root: string, configPath?: string) {
|
|
|
416
419
|
|
|
417
420
|
if (!hasWarnedOnce) {
|
|
418
421
|
hasWarnedOnce = true
|
|
419
|
-
console.warn(`Warning: couldn't find
|
|
422
|
+
console.warn(`Warning: couldn't find hanzogui.config.ts in the following paths given configuration "${configPath}":
|
|
420
423
|
${searchPaths.join(`\n `)}
|
|
421
424
|
`)
|
|
422
425
|
}
|
|
423
426
|
}
|
|
424
427
|
|
|
425
|
-
export type {
|
|
428
|
+
export type { HanzoguiProjectInfo }
|
|
426
429
|
|
|
427
430
|
export async function esbuildWatchFiles(entry: string, onChanged: () => void) {
|
|
428
431
|
let hasRunOnce = false
|