@hanzogui/static 8.3.0 → 8.3.2
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.js +438 -0
- package/dist/cjs/check-dep-versions.js.map +1 -0
- package/dist/cjs/checkDeps.js +343 -0
- package/dist/cjs/checkDeps.js.map +1 -0
- package/dist/cjs/constants.js +13 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/exports.js +27 -0
- package/dist/cjs/exports.js.map +1 -0
- package/dist/cjs/extractor/accessSafe.js +17 -0
- package/dist/cjs/extractor/accessSafe.js.map +1 -0
- package/dist/cjs/extractor/babelParse.js +27 -0
- package/dist/cjs/extractor/babelParse.js.map +1 -0
- package/dist/cjs/extractor/buildClassName.js +65 -0
- package/dist/cjs/extractor/buildClassName.js.map +1 -0
- package/dist/cjs/extractor/bundle.js +257 -0
- package/dist/cjs/extractor/bundle.js.map +1 -0
- package/dist/cjs/extractor/bundleConfig.js +794 -0
- package/dist/cjs/extractor/bundleConfig.js.map +1 -0
- package/dist/cjs/extractor/concatClassName.js +101 -0
- package/dist/cjs/extractor/concatClassName.js.map +1 -0
- package/dist/cjs/extractor/createEvaluator.js +56 -0
- package/dist/cjs/extractor/createEvaluator.js.map +1 -0
- package/dist/cjs/extractor/createExtractor.js +2285 -0
- package/dist/cjs/extractor/createExtractor.js.map +1 -0
- package/dist/cjs/extractor/createLogger.js +34 -0
- package/dist/cjs/extractor/createLogger.js.map +1 -0
- package/dist/cjs/extractor/detectModuleFormat.js +41 -0
- package/dist/cjs/extractor/detectModuleFormat.js.map +1 -0
- package/dist/cjs/extractor/ensureImportingConcat.js +23 -0
- package/dist/cjs/extractor/ensureImportingConcat.js.map +1 -0
- package/dist/cjs/extractor/errors.js +7 -0
- package/dist/cjs/extractor/errors.js.map +1 -0
- package/dist/cjs/extractor/esbuildAliasPlugin.js +43 -0
- package/dist/cjs/extractor/esbuildAliasPlugin.js.map +1 -0
- package/dist/cjs/extractor/esbuildTsconfigPaths.js +68 -0
- package/dist/cjs/extractor/esbuildTsconfigPaths.js.map +1 -0
- package/dist/cjs/extractor/evaluateAstNode.js +107 -0
- package/dist/cjs/extractor/evaluateAstNode.js.map +1 -0
- package/dist/cjs/extractor/extractHelpers.js +183 -0
- package/dist/cjs/extractor/extractHelpers.js.map +1 -0
- package/dist/cjs/extractor/extractMediaStyle.js +143 -0
- package/dist/cjs/extractor/extractMediaStyle.js.map +1 -0
- package/dist/cjs/extractor/extractToClassNames.js +541 -0
- package/dist/cjs/extractor/extractToClassNames.js.map +1 -0
- package/dist/cjs/extractor/extractToNative.js +404 -0
- package/dist/cjs/extractor/extractToNative.js.map +1 -0
- package/dist/cjs/extractor/extractablePath.js +89 -0
- package/dist/cjs/extractor/extractablePath.js.map +1 -0
- package/dist/cjs/extractor/findTopmostFunction.js +17 -0
- package/dist/cjs/extractor/findTopmostFunction.js.map +1 -0
- package/dist/cjs/extractor/generatedUid.js +35 -0
- package/dist/cjs/extractor/generatedUid.js.map +1 -0
- package/dist/cjs/extractor/getGuiConfigPathFromOptionsConfig.js +21 -0
- package/dist/cjs/extractor/getGuiConfigPathFromOptionsConfig.js.map +1 -0
- package/dist/cjs/extractor/getPrefixLogs.js +9 -0
- package/dist/cjs/extractor/getPrefixLogs.js.map +1 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js +75 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +1 -0
- package/dist/cjs/extractor/getSourceModule.js +81 -0
- package/dist/cjs/extractor/getSourceModule.js.map +1 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js +212 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +1 -0
- package/dist/cjs/extractor/hasTopLevelAwait.js +29 -0
- package/dist/cjs/extractor/hasTopLevelAwait.js.map +1 -0
- package/dist/cjs/extractor/hoistClassNames.js +47 -0
- package/dist/cjs/extractor/hoistClassNames.js.map +1 -0
- package/dist/cjs/extractor/literalToAst.js +83 -0
- package/dist/cjs/extractor/literalToAst.js.map +1 -0
- package/dist/cjs/extractor/loadFile.js +24 -0
- package/dist/cjs/extractor/loadFile.js.map +1 -0
- package/dist/cjs/extractor/loadGui.js +414 -0
- package/dist/cjs/extractor/loadGui.js.map +1 -0
- package/dist/cjs/extractor/logLines.js +20 -0
- package/dist/cjs/extractor/logLines.js.map +1 -0
- package/dist/cjs/extractor/normalizeTernaries.js +60 -0
- package/dist/cjs/extractor/normalizeTernaries.js.map +1 -0
- package/dist/cjs/extractor/propsToFontFamilyCache.js +20 -0
- package/dist/cjs/extractor/propsToFontFamilyCache.js.map +1 -0
- package/dist/cjs/extractor/regenerateConfig.js +151 -0
- package/dist/cjs/extractor/regenerateConfig.js.map +1 -0
- package/dist/cjs/extractor/removeUnusedHooks.js +84 -0
- package/dist/cjs/extractor/removeUnusedHooks.js.map +1 -0
- package/dist/cjs/extractor/timer.js +30 -0
- package/dist/cjs/extractor/timer.js.map +1 -0
- package/dist/cjs/extractor/validHTMLAttributes.js +56 -0
- package/dist/cjs/extractor/validHTMLAttributes.js.map +1 -0
- package/dist/cjs/extractor/watchGuiConfig.js +56 -0
- package/dist/cjs/extractor/watchGuiConfig.js.map +1 -0
- package/dist/cjs/getPragmaOptions.js +52 -0
- package/dist/cjs/getPragmaOptions.js.map +1 -0
- package/dist/cjs/helpers/memoize.js +24 -0
- package/dist/cjs/helpers/memoize.js.map +1 -0
- package/dist/cjs/helpers/nativeEntry.js +87 -0
- package/dist/cjs/helpers/nativeEntry.js.map +1 -0
- package/dist/cjs/helpers/requireGuiCore.js +25 -0
- package/dist/cjs/helpers/requireGuiCore.js.map +1 -0
- package/dist/cjs/here.js +8 -0
- package/dist/cjs/here.js.map +1 -0
- package/dist/cjs/index.js +8 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/registerRequire.js +263 -0
- package/dist/cjs/registerRequire.js.map +1 -0
- package/dist/cjs/server.js +41 -0
- package/dist/cjs/server.js.map +1 -0
- package/dist/cjs/setup.js +2 -0
- package/dist/cjs/setup.js.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/worker.js +95 -0
- package/dist/cjs/worker.js.map +1 -0
- package/dist/esm/check-dep-versions.js +433 -0
- package/dist/esm/check-dep-versions.js.map +1 -0
- package/dist/esm/checkDeps.js +339 -0
- package/dist/esm/checkDeps.js.map +1 -0
- package/dist/esm/constants.js +9 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/exports.js +18 -0
- package/dist/esm/exports.js.map +1 -0
- package/dist/esm/extractor/accessSafe.js +13 -0
- package/dist/esm/extractor/accessSafe.js.map +1 -0
- package/dist/esm/extractor/babelParse.js +22 -0
- package/dist/esm/extractor/babelParse.js.map +1 -0
- package/dist/esm/extractor/buildClassName.js +59 -0
- package/dist/esm/extractor/buildClassName.js.map +1 -0
- package/dist/esm/extractor/bundle.js +252 -0
- package/dist/esm/extractor/bundle.js.map +1 -0
- package/dist/esm/extractor/bundleConfig.js +781 -0
- package/dist/esm/extractor/bundleConfig.js.map +1 -0
- package/dist/esm/extractor/concatClassName.js +98 -0
- package/dist/esm/extractor/concatClassName.js.map +1 -0
- package/dist/esm/extractor/createEvaluator.js +51 -0
- package/dist/esm/extractor/createEvaluator.js.map +1 -0
- package/dist/esm/extractor/createExtractor.js +2281 -0
- package/dist/esm/extractor/createExtractor.js.map +1 -0
- package/dist/esm/extractor/createLogger.js +31 -0
- package/dist/esm/extractor/createLogger.js.map +1 -0
- package/dist/esm/extractor/detectModuleFormat.js +37 -0
- package/dist/esm/extractor/detectModuleFormat.js.map +1 -0
- package/dist/esm/extractor/ensureImportingConcat.js +19 -0
- package/dist/esm/extractor/ensureImportingConcat.js.map +1 -0
- package/dist/esm/extractor/errors.js +3 -0
- package/dist/esm/extractor/errors.js.map +1 -0
- package/dist/esm/extractor/esbuildAliasPlugin.js +39 -0
- package/dist/esm/extractor/esbuildAliasPlugin.js.map +1 -0
- package/dist/esm/extractor/esbuildTsconfigPaths.js +63 -0
- package/dist/esm/extractor/esbuildTsconfigPaths.js.map +1 -0
- package/dist/esm/extractor/evaluateAstNode.js +103 -0
- package/dist/esm/extractor/evaluateAstNode.js.map +1 -0
- package/dist/esm/extractor/extractHelpers.js +166 -0
- package/dist/esm/extractor/extractHelpers.js.map +1 -0
- package/dist/esm/extractor/extractMediaStyle.js +138 -0
- package/dist/esm/extractor/extractMediaStyle.js.map +1 -0
- package/dist/esm/extractor/extractToClassNames.js +537 -0
- package/dist/esm/extractor/extractToClassNames.js.map +1 -0
- package/dist/esm/extractor/extractToNative.js +398 -0
- package/dist/esm/extractor/extractToNative.js.map +1 -0
- package/dist/esm/extractor/extractablePath.js +84 -0
- package/dist/esm/extractor/extractablePath.js.map +1 -0
- package/dist/esm/extractor/findTopmostFunction.js +14 -0
- package/dist/esm/extractor/findTopmostFunction.js.map +1 -0
- package/dist/esm/extractor/generatedUid.js +31 -0
- package/dist/esm/extractor/generatedUid.js.map +1 -0
- package/dist/esm/extractor/getGuiConfigPathFromOptionsConfig.js +18 -0
- package/dist/esm/extractor/getGuiConfigPathFromOptionsConfig.js.map +1 -0
- package/dist/esm/extractor/getPrefixLogs.js +6 -0
- package/dist/esm/extractor/getPrefixLogs.js.map +1 -0
- package/dist/esm/extractor/getPropValueFromAttributes.js +71 -0
- package/dist/esm/extractor/getPropValueFromAttributes.js.map +1 -0
- package/dist/esm/extractor/getSourceModule.js +77 -0
- package/dist/esm/extractor/getSourceModule.js.map +1 -0
- package/dist/esm/extractor/getStaticBindingsForScope.js +207 -0
- package/dist/esm/extractor/getStaticBindingsForScope.js.map +1 -0
- package/dist/esm/extractor/hasTopLevelAwait.js +25 -0
- package/dist/esm/extractor/hasTopLevelAwait.js.map +1 -0
- package/dist/esm/extractor/hoistClassNames.js +43 -0
- package/dist/esm/extractor/hoistClassNames.js.map +1 -0
- package/dist/esm/extractor/literalToAst.js +78 -0
- package/dist/esm/extractor/literalToAst.js.map +1 -0
- package/dist/esm/extractor/loadFile.js +22 -0
- package/dist/esm/extractor/loadFile.js.map +1 -0
- package/dist/esm/extractor/loadGui.js +402 -0
- package/dist/esm/extractor/loadGui.js.map +1 -0
- package/dist/esm/extractor/logLines.js +16 -0
- package/dist/esm/extractor/logLines.js.map +1 -0
- package/dist/esm/extractor/normalizeTernaries.js +56 -0
- package/dist/esm/extractor/normalizeTernaries.js.map +1 -0
- package/dist/esm/extractor/propsToFontFamilyCache.js +15 -0
- package/dist/esm/extractor/propsToFontFamilyCache.js.map +1 -0
- package/dist/esm/extractor/regenerateConfig.js +145 -0
- package/dist/esm/extractor/regenerateConfig.js.map +1 -0
- package/dist/esm/extractor/removeUnusedHooks.js +80 -0
- package/dist/esm/extractor/removeUnusedHooks.js.map +1 -0
- package/dist/esm/extractor/timer.js +26 -0
- package/dist/esm/extractor/timer.js.map +1 -0
- package/dist/esm/extractor/validHTMLAttributes.js +53 -0
- package/dist/esm/extractor/validHTMLAttributes.js.map +1 -0
- package/dist/esm/extractor/watchGuiConfig.js +53 -0
- package/dist/esm/extractor/watchGuiConfig.js.map +1 -0
- package/dist/esm/getPragmaOptions.js +49 -0
- package/dist/esm/getPragmaOptions.js.map +1 -0
- package/dist/esm/helpers/memoize.js +21 -0
- package/dist/esm/helpers/memoize.js.map +1 -0
- package/dist/esm/helpers/nativeEntry.js +82 -0
- package/dist/esm/helpers/nativeEntry.js.map +1 -0
- package/dist/esm/helpers/requireGuiCore.js +22 -0
- package/dist/esm/helpers/requireGuiCore.js.map +1 -0
- package/dist/esm/here.js +7 -0
- package/dist/esm/here.js.map +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/registerRequire.js +256 -0
- package/dist/esm/registerRequire.js.map +1 -0
- package/dist/esm/server.js +37 -0
- package/dist/esm/server.js.map +1 -0
- package/dist/esm/setup.js +2 -0
- package/dist/esm/setup.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/worker.js +92 -0
- package/dist/esm/worker.js.map +1 -0
- package/package.json +77 -56
- package/src/check-dep-versions.ts +2 -1
- package/src/checkDeps.ts +1 -1
- package/src/exports.ts +17 -17
- package/src/extractor/babelParse.ts +2 -11
- package/src/extractor/buildClassName.ts +1 -1
- package/src/extractor/bundle.ts +13 -9
- package/src/extractor/bundleConfig.ts +25 -21
- package/src/extractor/createEvaluator.ts +3 -3
- package/src/extractor/createExtractor.ts +59 -77
- package/src/extractor/createLogger.ts +2 -2
- package/src/extractor/esbuildTsconfigPaths.ts +55 -120
- package/src/extractor/evaluateAstNode.ts +2 -2
- package/src/extractor/extractHelpers.ts +3 -3
- package/src/extractor/extractMediaStyle.ts +3 -3
- package/src/extractor/extractToClassNames.ts +12 -12
- package/src/extractor/extractToNative.ts +20 -22
- package/src/extractor/findTopmostFunction.ts +5 -13
- package/src/extractor/getGuiConfigPathFromOptionsConfig.ts +1 -1
- package/src/extractor/getPrefixLogs.ts +1 -1
- package/src/extractor/getPropValueFromAttributes.ts +2 -2
- package/src/extractor/getStaticBindingsForScope.ts +6 -6
- package/src/extractor/hasTopLevelAwait.ts +1 -1
- package/src/extractor/literalToAst.ts +2 -2
- package/src/extractor/loadFile.ts +6 -1
- package/src/extractor/loadGui.ts +16 -12
- package/src/extractor/normalizeTernaries.ts +3 -3
- package/src/extractor/regenerateConfig.ts +10 -6
- package/src/extractor/watchGuiConfig.ts +7 -3
- package/src/helpers/nativeEntry.ts +92 -0
- package/src/helpers/requireGuiCore.ts +8 -3
- package/src/here.cjs.ts +6 -0
- package/src/here.ts +8 -0
- package/src/index.ts +2 -2
- package/src/registerRequire.ts +30 -14
- package/src/server.ts +1 -1
- package/src/types.ts +1 -1
- package/src/worker.ts +7 -7
- package/types/check-dep-versions.d.ts.map +1 -1
- package/types/constants.d.ts +1 -1
- package/types/constants.d.ts.map +1 -1
- package/types/exports.d.ts +17 -17
- package/types/exports.d.ts.map +1 -1
- package/types/extractor/babelParse.d.ts.map +1 -1
- package/types/extractor/buildClassName.d.ts +1 -1
- package/types/extractor/buildClassName.d.ts.map +1 -1
- package/types/extractor/bundle.d.ts +66 -66
- package/types/extractor/bundle.d.ts.map +1 -1
- package/types/extractor/bundleConfig.d.ts +2 -2
- package/types/extractor/bundleConfig.d.ts.map +1 -1
- package/types/extractor/createEvaluator.d.ts +1 -1
- package/types/extractor/createEvaluator.d.ts.map +1 -1
- package/types/extractor/createExtractor.d.ts +4 -4
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/createLogger.d.ts +1 -1
- package/types/extractor/createLogger.d.ts.map +1 -1
- package/types/extractor/esbuildAliasPlugin.d.ts.map +1 -1
- package/types/extractor/esbuildTsconfigPaths.d.ts +4 -9
- package/types/extractor/esbuildTsconfigPaths.d.ts.map +1 -1
- package/types/extractor/extractHelpers.d.ts +1 -1
- package/types/extractor/extractHelpers.d.ts.map +1 -1
- package/types/extractor/extractMediaStyle.d.ts +2 -3
- 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 +4 -4
- package/types/extractor/extractToNative.d.ts.map +1 -1
- package/types/extractor/findTopmostFunction.d.ts +1 -1
- package/types/extractor/findTopmostFunction.d.ts.map +1 -1
- package/types/extractor/getGuiConfigPathFromOptionsConfig.d.ts +1 -1
- package/types/extractor/getGuiConfigPathFromOptionsConfig.d.ts.map +1 -1
- package/types/extractor/getPrefixLogs.d.ts +1 -1
- package/types/extractor/getPrefixLogs.d.ts.map +1 -1
- package/types/extractor/loadFile.d.ts +1 -0
- package/types/extractor/loadGui.d.ts +1 -1
- package/types/extractor/loadGui.d.ts.map +1 -1
- package/types/extractor/logLines.d.ts.map +1 -1
- package/types/extractor/normalizeTernaries.d.ts +1 -1
- package/types/extractor/normalizeTernaries.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/timer.d.ts.map +1 -1
- package/types/extractor/validHTMLAttributes.d.ts.map +1 -1
- package/types/extractor/watchGuiConfig.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/nativeEntry.d.ts +16 -0
- package/types/helpers/nativeEntry.d.ts.map +1 -0
- package/types/helpers/requireGuiCore.d.ts +1 -1
- package/types/helpers/requireGuiCore.d.ts.map +1 -1
- package/types/here.d.ts +3 -0
- package/types/here.d.ts.map +1 -0
- package/types/index.d.ts +2 -2
- package/types/index.d.ts.map +1 -1
- package/types/registerRequire.d.ts +1 -1
- package/types/registerRequire.d.ts.map +1 -1
- package/types/server.d.ts +1 -1
- package/types/server.d.ts.map +1 -1
- package/types/types.d.ts +1 -1
- package/types/types.d.ts.map +1 -1
- package/types/worker.d.ts +4 -4
- package/types/worker.d.ts.map +1 -1
- 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 -49
- 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 -121
- package/dist/extractor/createEvaluator.cjs +0 -88
- package/dist/extractor/createExtractor.cjs +0 -1935
- 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 -126
- 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 -476
- package/dist/extractor/extractToNative.cjs +0 -369
- package/dist/extractor/extractablePath.cjs +0 -51
- package/dist/extractor/findTopmostFunction.cjs +0 -43
- package/dist/extractor/generatedUid.cjs +0 -58
- package/dist/extractor/getGuiConfigPathFromOptionsConfig.cjs +0 -41
- 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/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/loadGui.cjs +0 -373
- package/dist/extractor/logLines.cjs +0 -43
- package/dist/extractor/normalizeTernaries.cjs +0 -95
- 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/watchGuiConfig.cjs +0 -70
- package/dist/getPragmaOptions.cjs +0 -73
- package/dist/helpers/memoize.cjs +0 -45
- package/dist/helpers/requireGuiCore.cjs +0 -40
- package/dist/index.cjs +0 -42
- package/dist/registerRequire.cjs +0 -209
- package/dist/server.cjs +0 -82
- package/dist/setup.cjs +0 -0
- package/dist/types.cjs +0 -18
- package/dist/worker.cjs +0 -111
|
@@ -21,7 +21,7 @@ export function evaluateAstNode(
|
|
|
21
21
|
// loop through ObjectExpression keys
|
|
22
22
|
if (t.isObjectExpression(exprNode)) {
|
|
23
23
|
const ret: Record<string, any> = {}
|
|
24
|
-
for (let idx = -1, len = exprNode.properties.length; ++idx < len;
|
|
24
|
+
for (let idx = -1, len = exprNode.properties.length; ++idx < len;) {
|
|
25
25
|
const value = exprNode.properties[idx]
|
|
26
26
|
|
|
27
27
|
if (!t.isObjectProperty(value)) {
|
|
@@ -75,7 +75,7 @@ export function evaluateAstNode(
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
let ret = ''
|
|
78
|
-
for (let idx = -1, len = exprNode.quasis.length; ++idx < len;
|
|
78
|
+
for (let idx = -1, len = exprNode.quasis.length; ++idx < len;) {
|
|
79
79
|
const quasi = exprNode.quasis[idx]
|
|
80
80
|
const expr = exprNode.expressions[idx]
|
|
81
81
|
ret += quasi.value.raw
|
|
@@ -5,10 +5,10 @@ import type { NodePath } from '@babel/traverse'
|
|
|
5
5
|
import * as t from '@babel/types'
|
|
6
6
|
import findRoot from 'find-root'
|
|
7
7
|
|
|
8
|
-
import { memoize } from '../helpers/memoize'
|
|
9
|
-
import type { ExtractedAttr, GuiOptionsWithFileInfo, Ternary } from '../types'
|
|
8
|
+
import { memoize } from '../helpers/memoize.ts'
|
|
9
|
+
import type { ExtractedAttr, GuiOptionsWithFileInfo, Ternary } from '../types.ts'
|
|
10
10
|
|
|
11
|
-
// import { astToLiteral } from './literalToAst'
|
|
11
|
+
// import { astToLiteral } from './literalToAst.ts'
|
|
12
12
|
|
|
13
13
|
export function isPresent<T extends object>(
|
|
14
14
|
input: null | void | undefined | T
|
|
@@ -4,9 +4,9 @@ import type { GuiInternalConfig } from '@hanzogui/core'
|
|
|
4
4
|
import * as core from '@hanzogui/core'
|
|
5
5
|
import type { ViewStyle } from 'react-native'
|
|
6
6
|
|
|
7
|
-
import { requireGuiCore } from '../helpers/requireGuiCore'
|
|
8
|
-
import type { StyleObject, GuiOptionsWithFileInfo, Ternary } from '../types'
|
|
9
|
-
import { isPresent, isValidImport } from './extractHelpers'
|
|
7
|
+
import { requireGuiCore } from '../helpers/requireGuiCore.ts'
|
|
8
|
+
import type { StyleObject, GuiOptionsWithFileInfo, Ternary } from '../types.ts'
|
|
9
|
+
import { isPresent, isValidImport } from './extractHelpers.ts'
|
|
10
10
|
|
|
11
11
|
export function extractMediaStyle(
|
|
12
12
|
props: GuiOptionsWithFileInfo,
|
|
@@ -4,21 +4,21 @@ 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 { requireGuiCore } from '../helpers/requireGuiCore'
|
|
8
|
-
import type { StyleObject, GuiOptions, Ternary } from '../types'
|
|
9
|
-
import { babelParse } from './babelParse'
|
|
10
|
-
import { isExtractable } from './extractablePath'
|
|
11
|
-
import type { Extractor } from './createExtractor'
|
|
12
|
-
import { createLogger } from './createLogger'
|
|
13
|
-
import { extractMediaStyle } from './extractMediaStyle'
|
|
14
|
-
import { normalizeTernaries } from './normalizeTernaries'
|
|
7
|
+
import { requireGuiCore } from '../helpers/requireGuiCore.ts'
|
|
8
|
+
import type { StyleObject, GuiOptions, Ternary } from '../types.ts'
|
|
9
|
+
import { babelParse } from './babelParse.ts'
|
|
10
|
+
import { isExtractable } from './extractablePath.ts'
|
|
11
|
+
import type { Extractor } from './createExtractor.ts'
|
|
12
|
+
import { createLogger } from './createLogger.ts'
|
|
13
|
+
import { extractMediaStyle } from './extractMediaStyle.ts'
|
|
14
|
+
import { normalizeTernaries } from './normalizeTernaries.ts'
|
|
15
15
|
import {
|
|
16
16
|
forwardFontFamilyName,
|
|
17
17
|
getFontFamilyNameFromProps,
|
|
18
|
-
} from './propsToFontFamilyCache'
|
|
19
|
-
import { timer } from './timer'
|
|
20
|
-
import { BailOptimizationError } from './errors'
|
|
21
|
-
import { concatClassName } from './concatClassName'
|
|
18
|
+
} from './propsToFontFamilyCache.ts'
|
|
19
|
+
import { timer } from './timer.ts'
|
|
20
|
+
import { BailOptimizationError } from './errors.ts'
|
|
21
|
+
import { concatClassName } from './concatClassName.ts'
|
|
22
22
|
|
|
23
23
|
export type ExtractedResponse = {
|
|
24
24
|
js: string | Buffer
|
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type FileResult, transformSync } from '@babel/core'
|
|
2
2
|
import generator from '@babel/generator'
|
|
3
3
|
import { declare } from '@babel/helper-plugin-utils'
|
|
4
|
-
import { parse } from '@babel/parser'
|
|
5
4
|
import template from '@babel/template'
|
|
6
5
|
import * as t from '@babel/types'
|
|
7
6
|
import { basename } from 'node:path'
|
|
8
|
-
import { getPragmaOptions } from '../getPragmaOptions'
|
|
9
|
-
import type { GuiOptions } from '../types'
|
|
10
|
-
import { createExtractor } from './createExtractor'
|
|
11
|
-
import { createLogger } from './createLogger'
|
|
12
|
-
import { isSimpleSpread } from './extractHelpers'
|
|
13
|
-
import { literalToAst } from './literalToAst'
|
|
14
|
-
import { loadGuiBuildConfigSync } from './loadGui'
|
|
7
|
+
import { getPragmaOptions } from '../getPragmaOptions.ts'
|
|
8
|
+
import type { GuiOptions } from '../types.ts'
|
|
9
|
+
import { createExtractor } from './createExtractor.ts'
|
|
10
|
+
import { createLogger } from './createLogger.ts'
|
|
11
|
+
import { isSimpleSpread } from './extractHelpers.ts'
|
|
12
|
+
import { literalToAst } from './literalToAst.ts'
|
|
13
|
+
import { loadGuiBuildConfigSync } from './loadGui.ts'
|
|
14
|
+
import { createRequire } from 'node:module'
|
|
15
|
+
import { url } from '../here.ts'
|
|
16
|
+
|
|
17
|
+
const need = createRequire(url)
|
|
15
18
|
|
|
16
19
|
const importNativeView = template(`
|
|
17
|
-
const __ReactNativeView =
|
|
18
|
-
const __ReactNativeText =
|
|
20
|
+
const __ReactNativeView = need('react-native').View;
|
|
21
|
+
const __ReactNativeText = need('react-native').Text;
|
|
19
22
|
`)
|
|
20
23
|
|
|
21
24
|
const importStyleSheet = template(`
|
|
22
|
-
const __ReactNativeStyleSheet =
|
|
25
|
+
const __ReactNativeStyleSheet = need('react-native').StyleSheet;
|
|
23
26
|
`)
|
|
24
27
|
|
|
25
28
|
const importWithStyle = template.ast(`import { _withStableStyle } from '@hanzogui/core';`)
|
|
@@ -32,16 +35,11 @@ export function extractToNative(
|
|
|
32
35
|
sourceFileName: string,
|
|
33
36
|
sourceCode: string,
|
|
34
37
|
options: GuiOptions
|
|
35
|
-
):
|
|
36
|
-
const
|
|
38
|
+
): FileResult {
|
|
39
|
+
const out = transformSync(sourceCode, {
|
|
40
|
+
plugins: [[getBabelPlugin(), options]],
|
|
37
41
|
sourceType: 'module',
|
|
38
|
-
plugins: ['jsx', 'typescript'],
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
const babelPlugin = getBabelPlugin()
|
|
42
|
-
|
|
43
|
-
const out = transformFromAstSync(ast, sourceCode, {
|
|
44
|
-
plugins: [[babelPlugin, options]],
|
|
42
|
+
parserOpts: { plugins: ['jsx', 'typescript'] },
|
|
45
43
|
configFile: false,
|
|
46
44
|
sourceFileName,
|
|
47
45
|
filename: sourceFileName,
|
|
@@ -56,7 +54,7 @@ export function extractToNative(
|
|
|
56
54
|
|
|
57
55
|
export function getBabelPlugin() {
|
|
58
56
|
return declare((api, options: GuiOptions) => {
|
|
59
|
-
api.assertVersion(7)
|
|
57
|
+
api.assertVersion('^7.0.0 || ^8.0.0-0')
|
|
60
58
|
return getBabelParseDefinition(options)
|
|
61
59
|
})
|
|
62
60
|
}
|
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
import type { NodePath } from '@babel/traverse'
|
|
2
2
|
import type * as t from '@babel/types'
|
|
3
3
|
|
|
4
|
-
export function findTopmostFunction(jsxPath: NodePath<t.JSXElement>) {
|
|
5
|
-
|
|
6
|
-
const isFunction = (path: NodePath<any>) =>
|
|
4
|
+
export function findTopmostFunction(jsxPath: NodePath<t.JSXElement>): NodePath | null {
|
|
5
|
+
const isFunction = (path: NodePath) =>
|
|
7
6
|
path.isArrowFunctionExpression() ||
|
|
8
7
|
path.isFunctionDeclaration() ||
|
|
9
8
|
path.isFunctionExpression()
|
|
10
|
-
let compFn
|
|
9
|
+
let compFn = jsxPath.findParent(isFunction)
|
|
11
10
|
while (compFn) {
|
|
12
11
|
const parent = compFn.findParent(isFunction)
|
|
13
|
-
if (parent)
|
|
14
|
-
|
|
15
|
-
} else {
|
|
16
|
-
break
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
if (!compFn) {
|
|
20
|
-
// console.error(`Couldn't find a topmost function for media query extraction`)
|
|
21
|
-
return null
|
|
12
|
+
if (!parent) break
|
|
13
|
+
compFn = parent
|
|
22
14
|
}
|
|
23
15
|
return compFn
|
|
24
16
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isAbsolute, join } from 'node:path'
|
|
2
2
|
|
|
3
3
|
import { statSync } from 'node:fs'
|
|
4
|
-
import type { GuiOptions } from '../types'
|
|
4
|
+
import type { GuiOptions } from '../types.ts'
|
|
5
5
|
|
|
6
6
|
export function getGuiConfigPathFromOptionsConfig(
|
|
7
7
|
config: NonNullable<GuiOptions['config']>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import generate from '@babel/generator'
|
|
2
2
|
import * as t from '@babel/types'
|
|
3
3
|
|
|
4
|
-
import { accessSafe } from './accessSafe'
|
|
4
|
+
import { accessSafe } from './accessSafe.ts'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* getPropValueFromAttributes gets a prop by name from a list of attributes and accounts for potential spread operators.
|
|
@@ -25,7 +25,7 @@ export function getPropValueFromAttributes(
|
|
|
25
25
|
): t.Expression | null {
|
|
26
26
|
let propIndex = -1
|
|
27
27
|
let jsxAttr: t.JSXAttribute | null = null
|
|
28
|
-
for (let idx = -1, len = attrs.length; ++idx < len;
|
|
28
|
+
for (let idx = -1, len = attrs.length; ++idx < len;) {
|
|
29
29
|
const attr = attrs[idx]
|
|
30
30
|
if (t.isJSXAttribute(attr) && attr.name && attr.name.name === propName) {
|
|
31
31
|
propIndex = idx
|
|
@@ -5,12 +5,12 @@ import { dirname, extname, join, resolve } from 'node:path'
|
|
|
5
5
|
import type { Binding, NodePath } from '@babel/traverse'
|
|
6
6
|
import * as t from '@babel/types'
|
|
7
7
|
|
|
8
|
-
import { evaluateAstNode } from './evaluateAstNode'
|
|
9
|
-
import { getSourceModule } from './getSourceModule'
|
|
8
|
+
import { evaluateAstNode } from './evaluateAstNode.ts'
|
|
9
|
+
import { getSourceModule } from './getSourceModule.ts'
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
import { fileURLToPath } from 'node:url'
|
|
12
|
+
import { url } from '../here.ts'
|
|
13
|
+
const extractor = join(dirname(fileURLToPath(url)), 'extractor')
|
|
14
14
|
|
|
15
15
|
const isLocalImport = (path: string) => path.startsWith('.') || path.startsWith('/')
|
|
16
16
|
|
|
@@ -28,7 +28,7 @@ function resolveImportPath(sourcePath: string, path: string) {
|
|
|
28
28
|
const cache = new Map()
|
|
29
29
|
const pending = new Map<string, Promise<any>>()
|
|
30
30
|
|
|
31
|
-
const loadCmd = `${join(
|
|
31
|
+
const loadCmd = `${join(extractor, 'loadFile.js')}`
|
|
32
32
|
|
|
33
33
|
let exited = false
|
|
34
34
|
|
|
@@ -8,13 +8,13 @@ export function literalToAst(literal: any): t.Expression {
|
|
|
8
8
|
case 'function':
|
|
9
9
|
throw new Error('Unsupported')
|
|
10
10
|
case 'number':
|
|
11
|
-
return t.
|
|
11
|
+
return t.valueToNode(literal)
|
|
12
12
|
case 'string':
|
|
13
13
|
return t.stringLiteral(literal)
|
|
14
14
|
case 'boolean':
|
|
15
15
|
return t.booleanLiteral(literal)
|
|
16
16
|
case 'undefined':
|
|
17
|
-
return t.unaryExpression('void', t.
|
|
17
|
+
return t.unaryExpression('void', t.valueToNode(0), true)
|
|
18
18
|
default:
|
|
19
19
|
if (Array.isArray(literal)) {
|
|
20
20
|
return t.arrayExpression(literal.map(literalToAst))
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { createRequire } from 'node:module'
|
|
2
|
+
import { url } from '../here.ts'
|
|
3
|
+
|
|
4
|
+
const need = createRequire(url)
|
|
5
|
+
|
|
1
6
|
process.on('message', (path) => {
|
|
2
7
|
if (typeof path !== 'string') {
|
|
3
8
|
throw new Error(`Not a string: ${path}`)
|
|
4
9
|
}
|
|
5
10
|
try {
|
|
6
|
-
const out =
|
|
11
|
+
const out = need(path)
|
|
7
12
|
process.send?.(JSON.stringify(out))
|
|
8
13
|
} catch (err) {
|
|
9
14
|
if (err instanceof Error) {
|
package/src/extractor/loadGui.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { basename, dirname, extname, join, relative, resolve } from 'node:path'
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
3
|
+
import { url } from '../here.ts'
|
|
4
|
+
|
|
5
|
+
const need = createRequire(url)
|
|
2
6
|
// @ts-ignore why
|
|
3
7
|
import { Color, colorLog } from '@hanzogui/cli-color'
|
|
4
8
|
import type { CLIResolvedOptions, CLIUserOptions, GuiOptions } from '@hanzogui/types'
|
|
5
9
|
import type { GuiInternalConfig } from '@hanzogui/web'
|
|
6
10
|
import esbuild from 'esbuild'
|
|
7
11
|
import * as esbuildWasm from 'esbuild-wasm'
|
|
8
|
-
import
|
|
12
|
+
import fsExtra from 'fs-extra'
|
|
9
13
|
|
|
10
|
-
import { SHOULD_DEBUG } from '../constants'
|
|
11
|
-
import { requireGuiCore } from '../helpers/requireGuiCore'
|
|
12
|
-
import { getNameToPaths, registerRequire } from '../registerRequire'
|
|
14
|
+
import { SHOULD_DEBUG } from '../constants.ts'
|
|
15
|
+
import { requireGuiCore } from '../helpers/requireGuiCore.ts'
|
|
16
|
+
import { getNameToPaths, registerRequire } from '../registerRequire.ts'
|
|
13
17
|
import {
|
|
14
18
|
type GuiProjectInfo,
|
|
15
19
|
getBundledConfig,
|
|
@@ -17,13 +21,13 @@ import {
|
|
|
17
21
|
hasBundledConfigChanged,
|
|
18
22
|
loadComponentsSync,
|
|
19
23
|
writeGuiCSS,
|
|
20
|
-
} from './bundleConfig'
|
|
21
|
-
import { getGuiConfigPathFromOptionsConfig } from './getGuiConfigPathFromOptionsConfig'
|
|
24
|
+
} from './bundleConfig.ts'
|
|
25
|
+
import { getGuiConfigPathFromOptionsConfig } from './getGuiConfigPathFromOptionsConfig.ts'
|
|
22
26
|
import {
|
|
23
27
|
generateGuiThemes,
|
|
24
28
|
regenerateConfig,
|
|
25
29
|
regenerateConfigSync,
|
|
26
|
-
} from './regenerateConfig'
|
|
30
|
+
} from './regenerateConfig.ts'
|
|
27
31
|
|
|
28
32
|
const getFilledOptions = (propsIn: Partial<GuiOptions>): GuiOptions => ({
|
|
29
33
|
// defaults
|
|
@@ -163,7 +167,7 @@ export async function loadGuiBuildConfigAsync(
|
|
|
163
167
|
// pass process so process.env works in the config
|
|
164
168
|
const module = { exports: {} as any }
|
|
165
169
|
const fn = new Function('module', 'exports', 'require', 'process', result.code)
|
|
166
|
-
fn(module, module.exports,
|
|
170
|
+
fn(module, module.exports, need, process)
|
|
167
171
|
|
|
168
172
|
const out = module.exports.default || module.exports
|
|
169
173
|
if (!out || typeof out !== 'object') {
|
|
@@ -211,7 +215,7 @@ export function loadGuiBuildConfigSync(hanzoguiOptions: Partial<GuiOptions> | un
|
|
|
211
215
|
if (fsExtra.existsSync(buildFilePath)) {
|
|
212
216
|
const registered = registerRequire('web')
|
|
213
217
|
try {
|
|
214
|
-
const out =
|
|
218
|
+
const out = need(
|
|
215
219
|
buildFilePath[0] === '.' ? join(process.cwd(), buildFilePath) : buildFilePath
|
|
216
220
|
).default
|
|
217
221
|
if (!out) {
|
|
@@ -277,7 +281,7 @@ export function loadGuiSync({
|
|
|
277
281
|
let hanzoguiConfig: GuiInternalConfig | null = null
|
|
278
282
|
if (propsIn.config) {
|
|
279
283
|
const configPath = getGuiConfigPathFromOptionsConfig(propsIn.config)
|
|
280
|
-
const exp =
|
|
284
|
+
const exp = need(configPath)
|
|
281
285
|
|
|
282
286
|
if (!exp || exp._isProxyWorm) {
|
|
283
287
|
throw new Error(`Got a empty / proxied config!`)
|
|
@@ -286,7 +290,7 @@ export function loadGuiSync({
|
|
|
286
290
|
hanzoguiConfig = (exp['default'] || exp['config'] || exp) as GuiInternalConfig
|
|
287
291
|
|
|
288
292
|
if (!hanzoguiConfig || !hanzoguiConfig.parsed) {
|
|
289
|
-
const confPath =
|
|
293
|
+
const confPath = need.resolve(configPath)
|
|
290
294
|
throw new Error(`Can't find valid config in ${confPath}:
|
|
291
295
|
|
|
292
296
|
Be sure you "export default" or "export const config" the config.`)
|
|
@@ -402,7 +406,7 @@ export async function getOptions({
|
|
|
402
406
|
|
|
403
407
|
export function resolveWebOrNativeSpecificEntry(entry: string, platform?: string) {
|
|
404
408
|
const workspaceRoot = resolve()
|
|
405
|
-
const resolved =
|
|
409
|
+
const resolved = need.resolve(entry, { paths: [workspaceRoot] })
|
|
406
410
|
const ext = extname(resolved)
|
|
407
411
|
const fileName = basename(resolved).replace(ext, '')
|
|
408
412
|
const target = platform || process.env.GUI_TARGET || 'web'
|
|
@@ -2,8 +2,8 @@ import generate from '@babel/generator'
|
|
|
2
2
|
import * as t from '@babel/types'
|
|
3
3
|
import { mergeProps } from '@hanzogui/web'
|
|
4
4
|
import invariant from 'invariant'
|
|
5
|
-
import type { Ternary } from '../types'
|
|
6
|
-
import { forwardFontFamilyName } from './propsToFontFamilyCache'
|
|
5
|
+
import type { Ternary } from '../types.ts'
|
|
6
|
+
import { forwardFontFamilyName } from './propsToFontFamilyCache.ts'
|
|
7
7
|
|
|
8
8
|
export function normalizeTernaries(ternaries: Ternary[]) {
|
|
9
9
|
invariant(
|
|
@@ -17,7 +17,7 @@ export function normalizeTernaries(ternaries: Ternary[]) {
|
|
|
17
17
|
|
|
18
18
|
const ternariesByKey: { [key: string]: Ternary } = {}
|
|
19
19
|
|
|
20
|
-
for (let idx = -1, len = ternaries.length; ++idx < len;
|
|
20
|
+
for (let idx = -1, len = ternaries.length; ++idx < len;) {
|
|
21
21
|
const { test, consequent, alternate, remove, ...rest } = ternaries[idx]
|
|
22
22
|
|
|
23
23
|
let ternaryTest = test
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
+
import { createRequire } from 'node:module'
|
|
1
2
|
import { dirname, join } from 'node:path'
|
|
2
3
|
|
|
3
4
|
import { generateThemes, writeGeneratedThemes } from '@hanzogui/generate-themes'
|
|
4
5
|
import type { GuiOptions } from '@hanzogui/types'
|
|
5
|
-
import
|
|
6
|
+
import FS from 'fs-extra'
|
|
7
|
+
import { url } from '../here.ts'
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
9
|
+
const need = createRequire(url)
|
|
10
|
+
|
|
11
|
+
import { requireGuiCore } from '../helpers/requireGuiCore.ts'
|
|
12
|
+
import type { GuiPlatform } from '../types.ts'
|
|
13
|
+
import type { BundledConfig } from './bundleConfig.ts'
|
|
14
|
+
import { getBundledConfig } from './bundleConfig.ts'
|
|
11
15
|
|
|
12
16
|
const hanzoguiDir = join(process.cwd(), '.hanzogui')
|
|
13
17
|
const confFile = join(hanzoguiDir, 'hanzogui.config.json')
|
|
@@ -94,7 +98,7 @@ export async function generateGuiThemes(hanzoguiOptions: GuiOptions, force = fal
|
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
const resolveRelativePath = (inputPath: string) =>
|
|
97
|
-
inputPath.startsWith('.') ? join(process.cwd(), inputPath) :
|
|
101
|
+
inputPath.startsWith('.') ? join(process.cwd(), inputPath) : need.resolve(inputPath)
|
|
98
102
|
|
|
99
103
|
function cloneDeepSafe(x: any, excludeKeys = {}) {
|
|
100
104
|
if (!x) return x
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { createRequire } from 'node:module'
|
|
1
2
|
import type { GuiOptions } from '@hanzogui/types'
|
|
2
|
-
import { esbuildWatchFiles, generateThemesAndLog, getOptions } from './loadGui'
|
|
3
|
-
import { regenerateConfig } from './regenerateConfig'
|
|
3
|
+
import { esbuildWatchFiles, generateThemesAndLog, getOptions } from './loadGui.ts'
|
|
4
|
+
import { regenerateConfig } from './regenerateConfig.ts'
|
|
5
|
+
import { url } from '../here.ts'
|
|
6
|
+
|
|
7
|
+
const need = createRequire(url)
|
|
4
8
|
|
|
5
9
|
let isWatching = false
|
|
6
10
|
|
|
@@ -43,7 +47,7 @@ export async function watchGuiConfig(hanzoguiOptions: GuiOptions) {
|
|
|
43
47
|
if (themeBuilderInput) {
|
|
44
48
|
let inputPath = themeBuilderInput
|
|
45
49
|
try {
|
|
46
|
-
inputPath =
|
|
50
|
+
inputPath = need.resolve(themeBuilderInput)
|
|
47
51
|
} catch {
|
|
48
52
|
// ok
|
|
49
53
|
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import Module, { createRequire } from 'node:module'
|
|
3
|
+
import { dirname, join } from 'node:path'
|
|
4
|
+
import { runInThisContext } from 'node:vm'
|
|
5
|
+
import { transformSync } from 'esbuild'
|
|
6
|
+
import { url } from '../here.ts'
|
|
7
|
+
|
|
8
|
+
const need = createRequire(url)
|
|
9
|
+
|
|
10
|
+
type Target = string | { default?: string } | undefined
|
|
11
|
+
type Exports = Record<string, string | Record<string, Target> | undefined>
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The file a package's `react-native` export names for a request. Node's own
|
|
15
|
+
* conditions never select it, so the native pass asks here and requires the
|
|
16
|
+
* file by path. A request with no such export resolves as Node would.
|
|
17
|
+
*/
|
|
18
|
+
export function nativeEntry(request: string): string {
|
|
19
|
+
const parts = request.split('/')
|
|
20
|
+
const name = request.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0]
|
|
21
|
+
const subpath = request.slice(name.length)
|
|
22
|
+
let manifest: string
|
|
23
|
+
try {
|
|
24
|
+
manifest = need.resolve(`${name}/package.json`)
|
|
25
|
+
} catch {
|
|
26
|
+
return request
|
|
27
|
+
}
|
|
28
|
+
const exports = (need(manifest) as { exports?: Exports }).exports
|
|
29
|
+
const entry = exports?.[`.${subpath}`]
|
|
30
|
+
const native = typeof entry === 'string' ? undefined : entry?.['react-native']
|
|
31
|
+
const file = typeof native === 'string' ? native : native?.default
|
|
32
|
+
return file ? join(dirname(manifest), file) : request
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Whether the nearest package.json above a file says `type: module`. */
|
|
36
|
+
const kinds = new Map<string, boolean>()
|
|
37
|
+
function kindOf(dir: string): boolean {
|
|
38
|
+
const known = kinds.get(dir)
|
|
39
|
+
if (known !== undefined) return known
|
|
40
|
+
let found: boolean | undefined
|
|
41
|
+
try {
|
|
42
|
+
found =
|
|
43
|
+
(JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as { type?: string })
|
|
44
|
+
.type === 'module'
|
|
45
|
+
} catch {}
|
|
46
|
+
const parent = dirname(dir)
|
|
47
|
+
const result = found ?? (parent === dir ? false : kindOf(parent))
|
|
48
|
+
kinds.set(dir, result)
|
|
49
|
+
return result
|
|
50
|
+
}
|
|
51
|
+
const inModulePackage = (filename: string) => kindOf(dirname(filename))
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* An emit of ours is ESM; a native one even says a bare require, as Metro
|
|
55
|
+
* allows. While this hook is in place, a `.js` file of a module package that
|
|
56
|
+
* Node is asked to require is translated to CommonJS on the way in and run
|
|
57
|
+
* through the CommonJS wrapper directly, since the compile hook other loaders
|
|
58
|
+
* patch would translate it again. It wraps whatever loader is current when it
|
|
59
|
+
* is installed, so it must go in after esbuild-register's, and comes out first.
|
|
60
|
+
*/
|
|
61
|
+
export function hookModuleJs(): () => void {
|
|
62
|
+
const extensions = (Module as unknown as { _extensions: Record<string, Loader> })
|
|
63
|
+
._extensions
|
|
64
|
+
const loader = extensions['.js']
|
|
65
|
+
extensions['.js'] = (module, filename) => {
|
|
66
|
+
if (!inModulePackage(filename)) return loader(module, filename)
|
|
67
|
+
const { code } = transformSync(readFileSync(filename, 'utf8'), {
|
|
68
|
+
format: 'cjs',
|
|
69
|
+
loader: 'js',
|
|
70
|
+
target: 'node20',
|
|
71
|
+
sourcefile: filename,
|
|
72
|
+
})
|
|
73
|
+
const own = createRequire(filename)
|
|
74
|
+
const require = Object.assign((id: string) => module.require(id), {
|
|
75
|
+
resolve: own.resolve,
|
|
76
|
+
cache: own.cache,
|
|
77
|
+
})
|
|
78
|
+
const fn = runInThisContext(Module.wrap(code), { filename }) as (
|
|
79
|
+
exports: unknown,
|
|
80
|
+
require: unknown,
|
|
81
|
+
module: NodeModule,
|
|
82
|
+
filename: string,
|
|
83
|
+
dirname: string
|
|
84
|
+
) => void
|
|
85
|
+
fn.call(module.exports, module.exports, require, module, filename, dirname(filename))
|
|
86
|
+
}
|
|
87
|
+
return () => {
|
|
88
|
+
extensions['.js'] = loader
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
type Loader = (module: NodeModule, filename: string) => void
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
// this allows us to swap between core native and web in the same process:
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { createRequire } from 'node:module'
|
|
4
|
+
import type { GuiPlatform } from '../types.ts'
|
|
5
|
+
import { url } from '../here.ts'
|
|
6
|
+
import { nativeEntry } from './nativeEntry.ts'
|
|
7
|
+
|
|
8
|
+
const need = createRequire(url)
|
|
4
9
|
|
|
5
10
|
export function requireGuiCore(
|
|
6
11
|
platform: GuiPlatform,
|
|
7
|
-
ogRequire: Function =
|
|
12
|
+
ogRequire: Function = need
|
|
8
13
|
): typeof import('@hanzogui/core') {
|
|
9
14
|
if (!platform) {
|
|
10
15
|
throw new Error(`No platform given to requireGuiCore`)
|
|
@@ -17,7 +22,7 @@ export function requireGuiCore(
|
|
|
17
22
|
process.env.GUI_KEEP_THEMES ||= '1'
|
|
18
23
|
|
|
19
24
|
const exported = ogRequire(
|
|
20
|
-
platform === 'native' ? '@hanzogui/core
|
|
25
|
+
platform === 'native' ? nativeEntry('@hanzogui/core') : '@hanzogui/core'
|
|
21
26
|
)
|
|
22
27
|
|
|
23
28
|
// restore back
|
package/src/here.cjs.ts
ADDED
package/src/here.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { pathToFileURL } from 'node:url'
|
|
2
|
+
|
|
3
|
+
// This module's own URL. A require made from it resolves from this package.
|
|
4
|
+
export const url = import.meta.url
|
|
5
|
+
|
|
6
|
+
// A file loaded as a module, the way this emit loads modules.
|
|
7
|
+
export const load = (file: string): Promise<Record<string, unknown>> =>
|
|
8
|
+
import(pathToFileURL(file).href)
|
package/src/index.ts
CHANGED