gt 2.14.35 → 2.14.37
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/CHANGELOG.md +22 -1
- package/dist/api/collectUserEditDiffs.js +112 -155
- package/dist/api/collectUserEditDiffs.js.map +1 -0
- package/dist/api/downloadFileBatch.js +164 -241
- package/dist/api/downloadFileBatch.js.map +1 -0
- package/dist/api/saveLocalEdits.js +37 -41
- package/dist/api/saveLocalEdits.js.map +1 -0
- package/dist/bin/bin-entry.js +17 -7
- package/dist/bin/bin-entry.js.map +1 -0
- package/dist/bin/bin-main.js +43 -61
- package/dist/bin/bin-main.js.map +1 -0
- package/dist/cli/base.js +382 -497
- package/dist/cli/base.js.map +1 -0
- package/dist/cli/commands/download.js +41 -49
- package/dist/cli/commands/download.js.map +1 -0
- package/dist/cli/commands/enqueue.js +26 -25
- package/dist/cli/commands/enqueue.js.map +1 -0
- package/dist/cli/commands/setupProject.js +33 -36
- package/dist/cli/commands/setupProject.js.map +1 -0
- package/dist/cli/commands/stage.js +53 -61
- package/dist/cli/commands/stage.js.map +1 -0
- package/dist/cli/commands/translate.js +75 -112
- package/dist/cli/commands/translate.js.map +1 -0
- package/dist/cli/commands/upload.js +185 -213
- package/dist/cli/commands/upload.js.map +1 -0
- package/dist/cli/commands/utils/validation.js +39 -34
- package/dist/cli/commands/utils/validation.js.map +1 -0
- package/dist/cli/flags.js +35 -62
- package/dist/cli/flags.js.map +1 -0
- package/dist/cli/inline.js +112 -137
- package/dist/cli/inline.js.map +1 -0
- package/dist/cli/next.js +17 -12
- package/dist/cli/next.js.map +1 -0
- package/dist/cli/node.js +19 -15
- package/dist/cli/node.js.map +1 -0
- package/dist/cli/python.js +13 -8
- package/dist/cli/python.js.map +1 -0
- package/dist/cli/react.js +61 -78
- package/dist/cli/react.js.map +1 -0
- package/dist/config/defaults.js +16 -11
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/generateSettings.js +167 -269
- package/dist/config/generateSettings.js.map +1 -0
- package/dist/config/optionPresets.js +78 -96
- package/dist/config/optionPresets.js.map +1 -0
- package/dist/config/resolveConfig.js +27 -32
- package/dist/config/resolveConfig.js.map +1 -0
- package/dist/config/utils.js +7 -3
- package/dist/config/utils.js.map +1 -0
- package/dist/config/validateSettings.js +19 -30
- package/dist/config/validateSettings.js.map +1 -0
- package/dist/console/colors.js +18 -13
- package/dist/console/colors.js.map +1 -0
- package/dist/console/displayTranslateSummary.js +40 -37
- package/dist/console/displayTranslateSummary.js.map +1 -0
- package/dist/console/formatting.js +8 -5
- package/dist/console/formatting.js.map +1 -0
- package/dist/console/index.d.ts +11 -9
- package/dist/console/index.js +53 -50
- package/dist/console/index.js.map +1 -0
- package/dist/console/inkFields.d.ts +23 -0
- package/dist/console/inkFields.js +87 -0
- package/dist/console/inkFields.js.map +1 -0
- package/dist/console/inkLayout.d.ts +7 -0
- package/dist/console/inkLayout.js +139 -0
- package/dist/console/inkLayout.js.map +1 -0
- package/dist/console/inkLocaleData.d.ts +4 -0
- package/dist/console/inkLocaleData.js +32 -0
- package/dist/console/inkLocaleData.js.map +1 -0
- package/dist/console/inkPrompts.d.ts +8 -0
- package/dist/console/inkPrompts.js +496 -0
- package/dist/console/inkPrompts.js.map +1 -0
- package/dist/console/inkSession.d.ts +3 -0
- package/dist/console/inkSession.js +42 -0
- package/dist/console/inkSession.js.map +1 -0
- package/dist/console/inkTerminal.d.ts +4 -0
- package/dist/console/inkTerminal.js +15 -0
- package/dist/console/inkTerminal.js.map +1 -0
- package/dist/console/inkTypes.d.ts +66 -0
- package/dist/console/inkTypes.js +1 -0
- package/dist/console/inkUtils.d.ts +24 -0
- package/dist/console/inkUtils.js +87 -0
- package/dist/console/inkUtils.js.map +1 -0
- package/dist/console/logger.js +209 -249
- package/dist/console/logger.js.map +1 -0
- package/dist/console/logging.d.ts +14 -0
- package/dist/console/logging.js +203 -162
- package/dist/console/logging.js.map +1 -0
- package/dist/console/promptParsing.d.ts +5 -0
- package/dist/console/promptParsing.js +28 -0
- package/dist/console/promptParsing.js.map +1 -0
- package/dist/console/terminalSession.d.ts +5 -0
- package/dist/console/terminalSession.js +38 -0
- package/dist/console/terminalSession.js.map +1 -0
- package/dist/extraction/index.js +3 -2
- package/dist/extraction/mapToUpdates.js +19 -18
- package/dist/extraction/mapToUpdates.js.map +1 -0
- package/dist/extraction/postProcess.js +68 -86
- package/dist/extraction/postProcess.js.map +1 -0
- package/dist/formats/files/aggregateFiles.js +223 -304
- package/dist/formats/files/aggregateFiles.js.map +1 -0
- package/dist/formats/files/collectFiles.js +53 -54
- package/dist/formats/files/collectFiles.js.map +1 -0
- package/dist/formats/files/convertToFileTranslationData.js +21 -19
- package/dist/formats/files/convertToFileTranslationData.js.map +1 -0
- package/dist/formats/files/fileMapping.js +82 -119
- package/dist/formats/files/fileMapping.js.map +1 -0
- package/dist/formats/files/preprocess/mdx.js +15 -12
- package/dist/formats/files/preprocess/mdx.js.map +1 -0
- package/dist/formats/files/preprocess/mintlify.js +15 -13
- package/dist/formats/files/preprocess/mintlify.js.map +1 -0
- package/dist/formats/files/preprocessContent.js +20 -21
- package/dist/formats/files/preprocessContent.js.map +1 -0
- package/dist/formats/files/save.js +18 -15
- package/dist/formats/files/save.js.map +1 -0
- package/dist/formats/files/supportedFiles.js +27 -22
- package/dist/formats/files/supportedFiles.js.map +1 -0
- package/dist/formats/files/transformFormat.js +93 -100
- package/dist/formats/files/transformFormat.js.map +1 -0
- package/dist/formats/json/extractJson.js +83 -110
- package/dist/formats/json/extractJson.js.map +1 -0
- package/dist/formats/json/flattenJson.js +41 -48
- package/dist/formats/json/flattenJson.js.map +1 -0
- package/dist/formats/json/jsonPath.js +20 -15
- package/dist/formats/json/jsonPath.js.map +1 -0
- package/dist/formats/json/jsonPointer.js +17 -17
- package/dist/formats/json/jsonPointer.js.map +1 -0
- package/dist/formats/json/mergeJson.js +230 -371
- package/dist/formats/json/mergeJson.js.map +1 -0
- package/dist/formats/json/parseJson.js +74 -111
- package/dist/formats/json/parseJson.js.map +1 -0
- package/dist/formats/json/transformJson.js +53 -61
- package/dist/formats/json/transformJson.js.map +1 -0
- package/dist/formats/json/utils.js +158 -187
- package/dist/formats/json/utils.js.map +1 -0
- package/dist/formats/parseKeyedMetadata.js +85 -106
- package/dist/formats/parseKeyedMetadata.js.map +1 -0
- package/dist/formats/utils.js +13 -23
- package/dist/formats/utils.js.map +1 -0
- package/dist/formats/yaml/extractYaml.js +32 -31
- package/dist/formats/yaml/extractYaml.js.map +1 -0
- package/dist/formats/yaml/mergeYaml.js +43 -60
- package/dist/formats/yaml/mergeYaml.js.map +1 -0
- package/dist/formats/yaml/parseYaml.js +34 -23
- package/dist/formats/yaml/parseYaml.js.map +1 -0
- package/dist/formats/yaml/utils.js +19 -21
- package/dist/formats/yaml/utils.js.map +1 -0
- package/dist/fs/clearLocaleDirs.js +82 -114
- package/dist/fs/clearLocaleDirs.js.map +1 -0
- package/dist/fs/config/downloadedVersions.js +174 -188
- package/dist/fs/config/downloadedVersions.js.map +1 -0
- package/dist/fs/config/loadConfig.js +12 -8
- package/dist/fs/config/loadConfig.js.map +1 -0
- package/dist/fs/config/parseFilesConfig.js +166 -227
- package/dist/fs/config/parseFilesConfig.js.map +1 -0
- package/dist/fs/config/setupConfig.js +43 -52
- package/dist/fs/config/setupConfig.js.map +1 -0
- package/dist/fs/config/updateConfig.js +44 -56
- package/dist/fs/config/updateConfig.js.map +1 -0
- package/dist/fs/config/updateVersions.js +27 -28
- package/dist/fs/config/updateVersions.js.map +1 -0
- package/dist/fs/copyFile.js +33 -37
- package/dist/fs/copyFile.js.map +1 -0
- package/dist/fs/createLoadTranslationsFile.js +32 -48
- package/dist/fs/createLoadTranslationsFile.js.map +1 -0
- package/dist/fs/determineFramework/detectPythonLibrary.js +30 -34
- package/dist/fs/determineFramework/detectPythonLibrary.js.map +1 -0
- package/dist/fs/determineFramework/index.js +46 -64
- package/dist/fs/determineFramework/index.js.map +1 -0
- package/dist/fs/determineFramework/matchPyprojectDependency.js +65 -78
- package/dist/fs/determineFramework/matchPyprojectDependency.js.map +1 -0
- package/dist/fs/determineFramework/matchRequirementsTxtDependency.js +21 -19
- package/dist/fs/determineFramework/matchRequirementsTxtDependency.js.map +1 -0
- package/dist/fs/determineFramework/matchSetupPyDependency.js +60 -81
- package/dist/fs/determineFramework/matchSetupPyDependency.js.map +1 -0
- package/dist/fs/determineFramework/resolveGtDependency.js +15 -15
- package/dist/fs/determineFramework/resolveGtDependency.js.map +1 -0
- package/dist/fs/findFilepath.js +63 -78
- package/dist/fs/findFilepath.js.map +1 -0
- package/dist/fs/loadJSON.js +18 -15
- package/dist/fs/loadJSON.js.map +1 -0
- package/dist/fs/matchFiles.js +12 -7
- package/dist/fs/matchFiles.js.map +1 -0
- package/dist/fs/saveJSON.js +10 -6
- package/dist/fs/saveJSON.js.map +1 -0
- package/dist/fs/utils.js +19 -15
- package/dist/fs/utils.js.map +1 -0
- package/dist/functions.d.ts +2 -1
- package/dist/functions.js +3 -6
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +6 -2
- package/dist/generated/version.js.map +1 -0
- package/dist/git/branches.js +77 -83
- package/dist/git/branches.js.map +1 -0
- package/dist/hooks/postProcess.js +97 -114
- package/dist/hooks/postProcess.js.map +1 -0
- package/dist/index.js +23 -31
- package/dist/index.js.map +1 -0
- package/dist/locadex/setupFlow.js +11 -8
- package/dist/locadex/setupFlow.js.map +1 -0
- package/dist/main.js +17 -7
- package/dist/main.js.map +1 -0
- package/dist/next/config/parseNextConfig.js +32 -51
- package/dist/next/config/parseNextConfig.js.map +1 -0
- package/dist/next/jsx/utils.js +25 -37
- package/dist/next/jsx/utils.js.map +1 -0
- package/dist/next/parse/handleInitGT.js +87 -154
- package/dist/next/parse/handleInitGT.js.map +1 -0
- package/dist/next/parse/wrapContent.js +136 -158
- package/dist/next/parse/wrapContent.js.map +1 -0
- package/dist/python/parse/createPythonInlineUpdates.js +36 -33
- package/dist/python/parse/createPythonInlineUpdates.js.map +1 -0
- package/dist/react/config/createESBuildConfig.js +115 -115
- package/dist/react/config/createESBuildConfig.js.map +1 -0
- package/dist/react/jsx/evaluateJsx.js +90 -124
- package/dist/react/jsx/evaluateJsx.js.map +1 -0
- package/dist/react/jsx/utils/buildImportMap.js +24 -28
- package/dist/react/jsx/utils/buildImportMap.js.map +1 -0
- package/dist/react/jsx/utils/constants.js +79 -87
- package/dist/react/jsx/utils/constants.js.map +1 -0
- package/dist/react/jsx/utils/extractSourceCode.js +36 -37
- package/dist/react/jsx/utils/extractSourceCode.js.map +1 -0
- package/dist/react/jsx/utils/getCalleeNameFromExpression.js +30 -30
- package/dist/react/jsx/utils/getCalleeNameFromExpression.js.map +1 -0
- package/dist/react/jsx/utils/getPathsAndAliases.js +70 -105
- package/dist/react/jsx/utils/getPathsAndAliases.js.map +1 -0
- package/dist/react/jsx/utils/isNumberLiteral.js +13 -11
- package/dist/react/jsx/utils/isNumberLiteral.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js +103 -148
- package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/autoInsertion.js +305 -389
- package/dist/react/jsx/utils/jsxParsing/autoInsertion.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +122 -193
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js +50 -64
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js +41 -68
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js +760 -1107
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/parseTProps.js +35 -71
- package/dist/react/jsx/utils/jsxParsing/parseTProps.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js +39 -58
- package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/types.js +10 -24
- package/dist/react/jsx/utils/jsxParsing/types.js.map +1 -0
- package/dist/react/jsx/utils/mapAttributeName.js +13 -13
- package/dist/react/jsx/utils/mapAttributeName.js.map +1 -0
- package/dist/react/jsx/utils/parseAst.js +142 -272
- package/dist/react/jsx/utils/parseAst.js.map +1 -0
- package/dist/react/jsx/utils/parseString.js +726 -1090
- package/dist/react/jsx/utils/parseString.js.map +1 -0
- package/dist/react/jsx/utils/parseStringFunction.js +274 -401
- package/dist/react/jsx/utils/parseStringFunction.js.map +1 -0
- package/dist/react/jsx/utils/resolveImportPath.d.ts +1 -1
- package/dist/react/jsx/utils/resolveImportPath.js +125 -108
- package/dist/react/jsx/utils/resolveImportPath.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js +18 -24
- package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js +412 -579
- package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/index.js +57 -67
- package/dist/react/jsx/utils/stringParsing/derivation/index.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js +26 -36
- package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js +29 -24
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js +34 -32
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js +80 -117
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js +24 -19
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js +18 -21
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js +45 -50
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js +54 -59
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js +56 -69
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/validateStringFunction.js +21 -29
- package/dist/react/jsx/utils/validateStringFunction.js.map +1 -0
- package/dist/react/jsx/wrapJsx.js +192 -375
- package/dist/react/jsx/wrapJsx.js.map +1 -0
- package/dist/react/parse/addVitePlugin/index.js +40 -34
- package/dist/react/parse/addVitePlugin/index.js.map +1 -0
- package/dist/react/parse/addVitePlugin/installCompiler.js +18 -20
- package/dist/react/parse/addVitePlugin/installCompiler.js.map +1 -0
- package/dist/react/parse/addVitePlugin/updateViteConfig.js +107 -111
- package/dist/react/parse/addVitePlugin/updateViteConfig.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js +23 -26
- package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js +29 -43
- package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js +70 -104
- package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js +23 -29
- package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js.map +1 -0
- package/dist/react/parse/createDictionaryUpdates.js +121 -185
- package/dist/react/parse/createDictionaryUpdates.js.map +1 -0
- package/dist/react/parse/createInlineUpdates.js +123 -139
- package/dist/react/parse/createInlineUpdates.js.map +1 -0
- package/dist/react/parse/wrapContent.js +131 -156
- package/dist/react/parse/wrapContent.js.map +1 -0
- package/dist/react/utils/flattenDictionary.js +55 -70
- package/dist/react/utils/flattenDictionary.js.map +1 -0
- package/dist/react/utils/getEntryAndMetadata.js +14 -10
- package/dist/react/utils/getEntryAndMetadata.js.map +1 -0
- package/dist/react/utils/getVariableName.js +36 -33
- package/dist/react/utils/getVariableName.js.map +1 -0
- package/dist/setup/detectFramework.js +85 -102
- package/dist/setup/detectFramework.js.map +1 -0
- package/dist/setup/frameworkUtils.js +17 -28
- package/dist/setup/frameworkUtils.js.map +1 -0
- package/dist/setup/userInput.js +24 -31
- package/dist/setup/userInput.js.map +1 -0
- package/dist/setup/wizard.js +141 -143
- package/dist/setup/wizard.js.map +1 -0
- package/dist/state/mintlifyRefMap.js +12 -9
- package/dist/state/mintlifyRefMap.js.map +1 -0
- package/dist/state/recentDownloads.js +26 -23
- package/dist/state/recentDownloads.js.map +1 -0
- package/dist/state/translateWarnings.js +17 -8
- package/dist/state/translateWarnings.js.map +1 -0
- package/dist/translation/parse.js +77 -98
- package/dist/translation/parse.js.map +1 -0
- package/dist/translation/stage.js +28 -43
- package/dist/translation/stage.js.map +1 -0
- package/dist/translation/validate.js +68 -91
- package/dist/translation/validate.js.map +1 -0
- package/dist/types/libraries.js +93 -91
- package/dist/types/libraries.js.map +1 -0
- package/dist/types/parsing.js +19 -10
- package/dist/types/parsing.js.map +1 -0
- package/dist/utils/addExplicitAnchorIds.js +270 -389
- package/dist/utils/addExplicitAnchorIds.js.map +1 -0
- package/dist/utils/calculateTimeoutMs.js +11 -6
- package/dist/utils/calculateTimeoutMs.js.map +1 -0
- package/dist/utils/constants.js +15 -12
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/credentials.js +67 -114
- package/dist/utils/credentials.js.map +1 -0
- package/dist/utils/fetch.js +22 -20
- package/dist/utils/fetch.js.map +1 -0
- package/dist/utils/flattenJsonFiles.js +27 -34
- package/dist/utils/flattenJsonFiles.js.map +1 -0
- package/dist/utils/gitDiff.js +30 -32
- package/dist/utils/gitDiff.js.map +1 -0
- package/dist/utils/gt.js +7 -2
- package/dist/utils/gt.js.map +1 -0
- package/dist/utils/hash.js +14 -9
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/headers.js +10 -13
- package/dist/utils/headers.js.map +1 -0
- package/dist/utils/installPackage.js +70 -75
- package/dist/utils/installPackage.js.map +1 -0
- package/dist/utils/localizeRelativeAssets.js +114 -157
- package/dist/utils/localizeRelativeAssets.js.map +1 -0
- package/dist/utils/localizeStaticImports.js +229 -371
- package/dist/utils/localizeStaticImports.js.map +1 -0
- package/dist/utils/localizeStaticUrls.js +241 -424
- package/dist/utils/localizeStaticUrls.js.map +1 -0
- package/dist/utils/mintlifyTitleFallback.js +64 -72
- package/dist/utils/mintlifyTitleFallback.js.map +1 -0
- package/dist/utils/monorepoVersionCheck.js +177 -215
- package/dist/utils/monorepoVersionCheck.js.map +1 -0
- package/dist/utils/packageInfo.js +17 -16
- package/dist/utils/packageInfo.js.map +1 -0
- package/dist/utils/packageJson.js +51 -66
- package/dist/utils/packageJson.js.map +1 -0
- package/dist/utils/packageManager.js +237 -260
- package/dist/utils/packageManager.js.map +1 -0
- package/dist/utils/parse/needsCJS.js +36 -69
- package/dist/utils/parse/needsCJS.js.map +1 -0
- package/dist/utils/persistPostprocessHashes.js +30 -32
- package/dist/utils/persistPostprocessHashes.js.map +1 -0
- package/dist/utils/processAnchorIds.js +32 -54
- package/dist/utils/processAnchorIds.js.map +1 -0
- package/dist/utils/processOpenApi.js +469 -578
- package/dist/utils/processOpenApi.js.map +1 -0
- package/dist/utils/resolveMintlifyRefs.js +89 -105
- package/dist/utils/resolveMintlifyRefs.js.map +1 -0
- package/dist/utils/resolvePublish.js +46 -54
- package/dist/utils/resolvePublish.js.map +1 -0
- package/dist/utils/sanitizeFileContent.js +20 -27
- package/dist/utils/sanitizeFileContent.js.map +1 -0
- package/dist/utils/sharedStaticAssets.js +248 -366
- package/dist/utils/sharedStaticAssets.js.map +1 -0
- package/dist/utils/splitMintlifyLanguageRefs.js +208 -282
- package/dist/utils/splitMintlifyLanguageRefs.js.map +1 -0
- package/dist/utils/validateMdx.js +26 -23
- package/dist/utils/validateMdx.js.map +1 -0
- package/dist/utils/wrapPlainUrls.js +58 -70
- package/dist/utils/wrapPlainUrls.js.map +1 -0
- package/dist/workflows/download.js +92 -126
- package/dist/workflows/download.js.map +1 -0
- package/dist/workflows/enqueue.js +47 -54
- package/dist/workflows/enqueue.js.map +1 -0
- package/dist/workflows/publish.js +29 -29
- package/dist/workflows/publish.js.map +1 -0
- package/dist/workflows/setupProject.js +39 -40
- package/dist/workflows/setupProject.js.map +1 -0
- package/dist/workflows/stage.js +61 -65
- package/dist/workflows/stage.js.map +1 -0
- package/dist/workflows/steps/BranchStep.js +118 -163
- package/dist/workflows/steps/BranchStep.js.map +1 -0
- package/dist/workflows/steps/DownloadStep.js +107 -137
- package/dist/workflows/steps/DownloadStep.js.map +1 -0
- package/dist/workflows/steps/EnqueueStep.js +32 -32
- package/dist/workflows/steps/EnqueueStep.js.map +1 -0
- package/dist/workflows/steps/PollJobsStep.js +208 -292
- package/dist/workflows/steps/PollJobsStep.js.map +1 -0
- package/dist/workflows/steps/PublishStep.js +33 -38
- package/dist/workflows/steps/PublishStep.js.map +1 -0
- package/dist/workflows/steps/SetupStep.js +71 -72
- package/dist/workflows/steps/SetupStep.js.map +1 -0
- package/dist/workflows/steps/TagStep.js +39 -44
- package/dist/workflows/steps/TagStep.js.map +1 -0
- package/dist/workflows/steps/UploadSourcesStep.js +108 -140
- package/dist/workflows/steps/UploadSourcesStep.js.map +1 -0
- package/dist/workflows/steps/UploadTranslationsStep.js +61 -71
- package/dist/workflows/steps/UploadTranslationsStep.js.map +1 -0
- package/dist/workflows/steps/UserEditDiffsStep.js +32 -34
- package/dist/workflows/steps/UserEditDiffsStep.js.map +1 -0
- package/dist/workflows/steps/WorkflowStep.js +6 -2
- package/dist/workflows/steps/WorkflowStep.js.map +1 -0
- package/dist/workflows/upload.js +45 -46
- package/dist/workflows/upload.js.map +1 -0
- package/package.json +14 -7
|
@@ -1,279 +1,149 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as babel from "@babel/types";
|
|
2
|
+
import traverseModule from "@babel/traverse";
|
|
3
|
+
//#region src/react/jsx/utils/parseAst.ts
|
|
3
4
|
const traverse = traverseModule.default || traverseModule;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return isESM;
|
|
5
|
+
function determineModuleType(ast) {
|
|
6
|
+
let isESM = false;
|
|
7
|
+
traverse(ast, {
|
|
8
|
+
ImportDeclaration() {
|
|
9
|
+
isESM = true;
|
|
10
|
+
},
|
|
11
|
+
ExportDefaultDeclaration() {
|
|
12
|
+
isESM = true;
|
|
13
|
+
},
|
|
14
|
+
ExportNamedDeclaration() {
|
|
15
|
+
isESM = true;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return isESM;
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
? babel.importDefaultSpecifier(babel.identifier(imp.local))
|
|
45
|
-
: babel.importSpecifier(babel.identifier(imp.local), babel.identifier(imp.imported))), babel.stringLiteral(source));
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
// For CommonJS, handle default imports differently
|
|
49
|
-
return babel.variableDeclaration('const', [
|
|
50
|
-
babel.variableDeclarator(imports.some((imp) => imp.imported === 'default')
|
|
51
|
-
? babel.identifier(imports[0].local)
|
|
52
|
-
: babel.objectPattern(imports.map((imp) => babel.objectProperty(babel.identifier(imp.local), babel.identifier(imp.imported), false, imp.local === imp.imported))), babel.callExpression(babel.identifier('require'), [
|
|
53
|
-
babel.stringLiteral(source),
|
|
54
|
-
])),
|
|
55
|
-
]);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return importNodes;
|
|
20
|
+
function generateImports(needsImport, isESM, importMap) {
|
|
21
|
+
const importsBySource = needsImport.reduce((acc, imp) => {
|
|
22
|
+
if (typeof imp === "string") {
|
|
23
|
+
const importInfo = importMap[imp];
|
|
24
|
+
const source = importInfo.source;
|
|
25
|
+
if (!acc[source]) acc[source] = [];
|
|
26
|
+
acc[source].push({
|
|
27
|
+
local: imp,
|
|
28
|
+
imported: importInfo.name
|
|
29
|
+
});
|
|
30
|
+
} else {
|
|
31
|
+
const source = imp.source;
|
|
32
|
+
if (!acc[source]) acc[source] = [];
|
|
33
|
+
acc[source].push({
|
|
34
|
+
local: imp.local,
|
|
35
|
+
imported: imp.imported
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return acc;
|
|
39
|
+
}, {});
|
|
40
|
+
return Object.entries(importsBySource).map(([source, imports]) => {
|
|
41
|
+
if (isESM) return babel.importDeclaration(imports.map((imp) => imp.imported === "default" ? babel.importDefaultSpecifier(babel.identifier(imp.local)) : babel.importSpecifier(babel.identifier(imp.local), babel.identifier(imp.imported))), babel.stringLiteral(source));
|
|
42
|
+
else return babel.variableDeclaration("const", [babel.variableDeclarator(imports.some((imp) => imp.imported === "default") ? babel.identifier(imports[0].local) : babel.objectPattern(imports.map((imp) => babel.objectProperty(babel.identifier(imp.local), babel.identifier(imp.imported), false, imp.local === imp.imported))), babel.callExpression(babel.identifier("require"), [babel.stringLiteral(source)]))]);
|
|
43
|
+
});
|
|
59
44
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
...initialImports,
|
|
112
|
-
...declaration.id.properties
|
|
113
|
-
.map((prop) => {
|
|
114
|
-
if (babel.isObjectProperty(prop) &&
|
|
115
|
-
babel.isIdentifier(prop.key)) {
|
|
116
|
-
return prop.key.name;
|
|
117
|
-
}
|
|
118
|
-
return '';
|
|
119
|
-
})
|
|
120
|
-
.filter(Boolean),
|
|
121
|
-
];
|
|
122
|
-
}
|
|
123
|
-
// Handle const temp = require('pkg') followed by const { T, Var } = temp
|
|
124
|
-
if (babel.isCallExpression(declaration.init) &&
|
|
125
|
-
babel.isIdentifier(declaration.init.callee) &&
|
|
126
|
-
declaration.init.callee.name === 'require' &&
|
|
127
|
-
babel.isStringLiteral(declaration.init.arguments[0]) &&
|
|
128
|
-
declaration.init.arguments[0].value === pkg &&
|
|
129
|
-
babel.isIdentifier(declaration.id)) {
|
|
130
|
-
const requireVarName = declaration.id.name;
|
|
131
|
-
const parentBody = babel.isProgram(path.parent) || babel.isBlockStatement(path.parent)
|
|
132
|
-
? path.parent.body
|
|
133
|
-
: [];
|
|
134
|
-
// Look for subsequent destructuring
|
|
135
|
-
for (const node of parentBody) {
|
|
136
|
-
if (babel.isVariableDeclaration(node) &&
|
|
137
|
-
node.declarations[0] &&
|
|
138
|
-
babel.isObjectPattern(node.declarations[0].id) &&
|
|
139
|
-
babel.isMemberExpression(node.declarations[0].init) &&
|
|
140
|
-
babel.isIdentifier(node.declarations[0].init.object) &&
|
|
141
|
-
node.declarations[0].init.object.name === requireVarName) {
|
|
142
|
-
initialImports = [
|
|
143
|
-
...initialImports,
|
|
144
|
-
...node.declarations[0].id.properties
|
|
145
|
-
.map((prop) => {
|
|
146
|
-
if (babel.isObjectProperty(prop) &&
|
|
147
|
-
babel.isIdentifier(prop.key)) {
|
|
148
|
-
return prop.key.name;
|
|
149
|
-
}
|
|
150
|
-
return '';
|
|
151
|
-
})
|
|
152
|
-
.filter(Boolean),
|
|
153
|
-
];
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
// Check for conflicting requires
|
|
158
|
-
if (babel.isCallExpression(declaration.init) &&
|
|
159
|
-
babel.isIdentifier(declaration.init.callee) &&
|
|
160
|
-
declaration.init.callee.name === 'require' &&
|
|
161
|
-
babel.isStringLiteral(declaration.init.arguments[0]) &&
|
|
162
|
-
declaration.init.arguments[0].value !== pkg &&
|
|
163
|
-
babel.isObjectPattern(declaration.id)) {
|
|
164
|
-
declaration.id.properties.forEach((prop) => {
|
|
165
|
-
if (babel.isObjectProperty(prop) && babel.isIdentifier(prop.value)) {
|
|
166
|
-
if (prop.value.name === 'T')
|
|
167
|
-
importAlias.TComponent = 'GTT';
|
|
168
|
-
if (prop.value.name === 'Var')
|
|
169
|
-
importAlias.VarComponent = 'GTVar';
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
// Add check for intermediate variable conflict
|
|
174
|
-
if (babel.isIdentifier(declaration.id)) {
|
|
175
|
-
if (declaration.id.name === 'T')
|
|
176
|
-
importAlias.TComponent = 'GTT';
|
|
177
|
-
if (declaration.id.name === 'Var')
|
|
178
|
-
importAlias.VarComponent = 'GTVar';
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
});
|
|
182
|
-
return { initialImports, importAlias };
|
|
45
|
+
function generateImportMap(ast, pkg) {
|
|
46
|
+
const importAlias = {
|
|
47
|
+
TComponent: "T",
|
|
48
|
+
VarComponent: "Var"
|
|
49
|
+
};
|
|
50
|
+
let initialImports = [];
|
|
51
|
+
traverse(ast, {
|
|
52
|
+
ImportDeclaration(path) {
|
|
53
|
+
const source = path.node.source.value;
|
|
54
|
+
if (source === pkg) initialImports = [...initialImports, ...path.node.specifiers.map((spec) => {
|
|
55
|
+
if (babel.isImportSpecifier(spec)) return babel.isIdentifier(spec.imported) ? spec.imported.name : spec.imported.value;
|
|
56
|
+
return spec.local.name;
|
|
57
|
+
})];
|
|
58
|
+
if (source !== pkg) path.node.specifiers.forEach((spec) => {
|
|
59
|
+
if (babel.isImportSpecifier(spec) || babel.isImportDefaultSpecifier(spec)) {
|
|
60
|
+
if (spec.local.name === "T") importAlias.TComponent = "GTT";
|
|
61
|
+
if (spec.local.name === "Var") importAlias.VarComponent = "GTVar";
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
VariableDeclaration(path) {
|
|
66
|
+
const declaration = path.node.declarations[0];
|
|
67
|
+
if (!declaration) return;
|
|
68
|
+
if (babel.isCallExpression(declaration.init) && babel.isIdentifier(declaration.init.callee) && declaration.init.callee.name === "require" && babel.isStringLiteral(declaration.init.arguments[0]) && declaration.init.arguments[0].value === pkg && babel.isObjectPattern(declaration.id)) initialImports = [...initialImports, ...declaration.id.properties.map((prop) => {
|
|
69
|
+
if (babel.isObjectProperty(prop) && babel.isIdentifier(prop.key)) return prop.key.name;
|
|
70
|
+
return "";
|
|
71
|
+
}).filter(Boolean)];
|
|
72
|
+
if (babel.isCallExpression(declaration.init) && babel.isIdentifier(declaration.init.callee) && declaration.init.callee.name === "require" && babel.isStringLiteral(declaration.init.arguments[0]) && declaration.init.arguments[0].value === pkg && babel.isIdentifier(declaration.id)) {
|
|
73
|
+
const requireVarName = declaration.id.name;
|
|
74
|
+
const parentBody = babel.isProgram(path.parent) || babel.isBlockStatement(path.parent) ? path.parent.body : [];
|
|
75
|
+
for (const node of parentBody) if (babel.isVariableDeclaration(node) && node.declarations[0] && babel.isObjectPattern(node.declarations[0].id) && babel.isMemberExpression(node.declarations[0].init) && babel.isIdentifier(node.declarations[0].init.object) && node.declarations[0].init.object.name === requireVarName) initialImports = [...initialImports, ...node.declarations[0].id.properties.map((prop) => {
|
|
76
|
+
if (babel.isObjectProperty(prop) && babel.isIdentifier(prop.key)) return prop.key.name;
|
|
77
|
+
return "";
|
|
78
|
+
}).filter(Boolean)];
|
|
79
|
+
}
|
|
80
|
+
if (babel.isCallExpression(declaration.init) && babel.isIdentifier(declaration.init.callee) && declaration.init.callee.name === "require" && babel.isStringLiteral(declaration.init.arguments[0]) && declaration.init.arguments[0].value !== pkg && babel.isObjectPattern(declaration.id)) declaration.id.properties.forEach((prop) => {
|
|
81
|
+
if (babel.isObjectProperty(prop) && babel.isIdentifier(prop.value)) {
|
|
82
|
+
if (prop.value.name === "T") importAlias.TComponent = "GTT";
|
|
83
|
+
if (prop.value.name === "Var") importAlias.VarComponent = "GTVar";
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
if (babel.isIdentifier(declaration.id)) {
|
|
87
|
+
if (declaration.id.name === "T") importAlias.TComponent = "GTT";
|
|
88
|
+
if (declaration.id.name === "Var") importAlias.VarComponent = "GTVar";
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
initialImports,
|
|
94
|
+
importAlias
|
|
95
|
+
};
|
|
183
96
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
// Insert all import nodes
|
|
195
|
-
ast.program.body.splice(insertIndex, 0, ...importNodes);
|
|
97
|
+
function insertImports(ast, importNodes) {
|
|
98
|
+
let insertIndex = 0;
|
|
99
|
+
for (let i = 0; i < ast.program.body.length; i++) {
|
|
100
|
+
if (!babel.isImportDeclaration(ast.program.body[i])) {
|
|
101
|
+
insertIndex = i;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
insertIndex = i + 1;
|
|
105
|
+
}
|
|
106
|
+
ast.program.body.splice(insertIndex, 0, ...importNodes);
|
|
196
107
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const importNodes = generateImports(needsImport, isESM, importMap);
|
|
200
|
-
insertImports(ast, importNodes);
|
|
108
|
+
function createImports(ast, needsImport, importMap) {
|
|
109
|
+
insertImports(ast, generateImports(needsImport, determineModuleType(ast), importMap));
|
|
201
110
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
results.push({
|
|
237
|
-
local: prop.value.name,
|
|
238
|
-
original: prop.key.name,
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
// Handle intermediate variable case: const temp = require('gt-next')
|
|
244
|
-
else if (declaration.id.type === 'Identifier') {
|
|
245
|
-
const requireVarName = declaration.id.name;
|
|
246
|
-
const parentBody = node.parent?.body;
|
|
247
|
-
if (parentBody) {
|
|
248
|
-
for (let i = 0; i < parentBody.length; i++) {
|
|
249
|
-
const stmt = parentBody[i];
|
|
250
|
-
if (stmt.type === 'VariableDeclaration' &&
|
|
251
|
-
stmt.declarations[0]?.id.type === 'Identifier' &&
|
|
252
|
-
stmt.declarations[0]?.init?.type === 'MemberExpression' &&
|
|
253
|
-
stmt.declarations[0].init.object.type === 'Identifier' &&
|
|
254
|
-
stmt.declarations[0].init.object.name === requireVarName &&
|
|
255
|
-
stmt.declarations[0].init.property.type === 'Identifier' &&
|
|
256
|
-
translationFuncs.includes(stmt.declarations[0].init.property.name)) {
|
|
257
|
-
results.push({
|
|
258
|
-
local: stmt.declarations[0].id.name,
|
|
259
|
-
original: stmt.declarations[0].init.property.name,
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
// Handle member expression assignment: const TranslateFunc = temp.T
|
|
267
|
-
if (declaration.init?.type === 'MemberExpression' &&
|
|
268
|
-
declaration.init.property.type === 'Identifier' &&
|
|
269
|
-
translationFuncs.includes(declaration.init.property.name) &&
|
|
270
|
-
declaration.id.type === 'Identifier') {
|
|
271
|
-
results.push({
|
|
272
|
-
local: declaration.id.name,
|
|
273
|
-
original: declaration.init.property.name,
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return results;
|
|
111
|
+
function extractImportName(node, pkgs, translationFuncs) {
|
|
112
|
+
const results = [];
|
|
113
|
+
if (node.type === "ImportDeclaration") {
|
|
114
|
+
if (pkgs.some((pkg) => node.source.value.startsWith(pkg))) {
|
|
115
|
+
for (const specifier of node.specifiers) if (specifier.type === "ImportSpecifier" && "name" in specifier.imported && translationFuncs.includes(specifier.imported.name)) results.push({
|
|
116
|
+
local: specifier.local.name,
|
|
117
|
+
original: specifier.imported.name
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
} else if (node.type === "VariableDeclaration") for (const declaration of node.declarations) {
|
|
121
|
+
if (declaration.init?.type === "CallExpression" && declaration.init.callee.type === "Identifier" && declaration.init.callee.name === "require" && declaration.init.arguments[0]?.type === "StringLiteral" && pkgs.some((pkg) => declaration.init.arguments[0].value.startsWith(pkg))) {
|
|
122
|
+
if (declaration.id.type === "ObjectPattern") {
|
|
123
|
+
for (const prop of declaration.id.properties) if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && translationFuncs.includes(prop.key.name) && prop.value.type === "Identifier") results.push({
|
|
124
|
+
local: prop.value.name,
|
|
125
|
+
original: prop.key.name
|
|
126
|
+
});
|
|
127
|
+
} else if (declaration.id.type === "Identifier") {
|
|
128
|
+
const requireVarName = declaration.id.name;
|
|
129
|
+
const parentBody = node.parent?.body;
|
|
130
|
+
if (parentBody) for (let i = 0; i < parentBody.length; i++) {
|
|
131
|
+
const stmt = parentBody[i];
|
|
132
|
+
if (stmt.type === "VariableDeclaration" && stmt.declarations[0]?.id.type === "Identifier" && stmt.declarations[0]?.init?.type === "MemberExpression" && stmt.declarations[0].init.object.type === "Identifier" && stmt.declarations[0].init.object.name === requireVarName && stmt.declarations[0].init.property.type === "Identifier" && translationFuncs.includes(stmt.declarations[0].init.property.name)) results.push({
|
|
133
|
+
local: stmt.declarations[0].id.name,
|
|
134
|
+
original: stmt.declarations[0].init.property.name
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (declaration.init?.type === "MemberExpression" && declaration.init.property.type === "Identifier" && translationFuncs.includes(declaration.init.property.name) && declaration.id.type === "Identifier") results.push({
|
|
140
|
+
local: declaration.id.name,
|
|
141
|
+
original: declaration.init.property.name
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return results;
|
|
279
145
|
}
|
|
146
|
+
//#endregion
|
|
147
|
+
export { createImports, determineModuleType, extractImportName, generateImportMap, generateImports, insertImports };
|
|
148
|
+
|
|
149
|
+
//# sourceMappingURL=parseAst.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseAst.js","names":[],"sources":["../../../../src/react/jsx/utils/parseAst.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport traverseModule from '@babel/traverse';\n\n// Handle CommonJS/ESM interop\nconst traverse = traverseModule.default || traverseModule;\n\nimport { ParseResult } from '@babel/parser';\nimport * as babel from '@babel/types';\nimport { ImportDeclaration, VariableDeclaration } from '@babel/types';\nimport { GTLibrary } from '../../../types/libraries.js';\n\ntype NodeWithParentBody = t.Node & {\n parent?: {\n body?: t.Statement[];\n };\n};\n\nexport function determineModuleType(ast: ParseResult<t.File>) {\n let isESM = false;\n traverse(ast, {\n ImportDeclaration() {\n isESM = true;\n },\n ExportDefaultDeclaration() {\n isESM = true;\n },\n ExportNamedDeclaration() {\n isESM = true;\n },\n });\n return isESM;\n}\n\nexport type ImportItem =\n | string\n | {\n local: string;\n imported: string;\n source: string;\n };\n\nexport function generateImports(\n needsImport: ImportItem[],\n isESM: boolean,\n importMap: Record<string, { name: string; source: string }>\n) {\n // Group imports by their source\n const importsBySource = needsImport.reduce(\n (acc, imp) => {\n if (typeof imp === 'string') {\n // Handle standard GT component imports\n const importInfo = importMap[imp];\n const source = importInfo.source;\n if (!acc[source]) acc[source] = [];\n acc[source].push({ local: imp, imported: importInfo.name });\n } else {\n // Handle custom imports (like config)\n const source = imp.source;\n if (!acc[source]) acc[source] = [];\n acc[source].push({ local: imp.local, imported: imp.imported });\n }\n return acc;\n },\n {} as Record<string, { local: string; imported: string }[]>\n );\n\n // Generate import nodes for each source\n const importNodes = Object.entries(importsBySource).map(\n ([source, imports]) => {\n if (isESM) {\n return babel.importDeclaration(\n imports.map((imp) =>\n imp.imported === 'default'\n ? babel.importDefaultSpecifier(babel.identifier(imp.local))\n : babel.importSpecifier(\n babel.identifier(imp.local),\n babel.identifier(imp.imported)\n )\n ),\n babel.stringLiteral(source)\n );\n } else {\n // For CommonJS, handle default imports differently\n return babel.variableDeclaration('const', [\n babel.variableDeclarator(\n imports.some((imp) => imp.imported === 'default')\n ? babel.identifier(imports[0].local)\n : babel.objectPattern(\n imports.map((imp) =>\n babel.objectProperty(\n babel.identifier(imp.local),\n babel.identifier(imp.imported),\n false,\n imp.local === imp.imported\n )\n )\n ),\n babel.callExpression(babel.identifier('require'), [\n babel.stringLiteral(source),\n ])\n ),\n ]);\n }\n }\n );\n return importNodes;\n}\n\n/*\n * This function traverses the AST and records the relevant imports for the pkg.\n * It also records the import aliases for the T and Var components. (in case of conflicts)\n */\nexport function generateImportMap(ast: ParseResult<t.File>, pkg: string) {\n const importAlias = { TComponent: 'T', VarComponent: 'Var' };\n // Check existing imports\n let initialImports: string[] = [];\n traverse(ast, {\n ImportDeclaration(path) {\n const source = path.node.source.value;\n if (source === pkg) {\n initialImports = [\n ...initialImports,\n ...path.node.specifiers.map((spec) => {\n // For named imports (import { x as y }), use the original name\n if (babel.isImportSpecifier(spec)) {\n return babel.isIdentifier(spec.imported)\n ? spec.imported.name\n : spec.imported.value;\n }\n // For default imports, fall back to local name\n return spec.local.name;\n }),\n ];\n }\n // Check for conflicting imports only if they're not from gt libraries\n if (source !== pkg) {\n path.node.specifiers.forEach((spec) => {\n if (\n babel.isImportSpecifier(spec) ||\n babel.isImportDefaultSpecifier(spec)\n ) {\n if (spec.local.name === 'T') importAlias.TComponent = 'GTT';\n if (spec.local.name === 'Var') importAlias.VarComponent = 'GTVar';\n }\n });\n }\n },\n VariableDeclaration(path) {\n const declaration = path.node.declarations[0];\n if (!declaration) return;\n\n // Handle const { T, Var } = require('pkg')\n if (\n babel.isCallExpression(declaration.init) &&\n babel.isIdentifier(declaration.init.callee) &&\n declaration.init.callee.name === 'require' &&\n babel.isStringLiteral(declaration.init.arguments[0]) &&\n declaration.init.arguments[0].value === pkg &&\n babel.isObjectPattern(declaration.id)\n ) {\n initialImports = [\n ...initialImports,\n ...declaration.id.properties\n .map((prop) => {\n if (\n babel.isObjectProperty(prop) &&\n babel.isIdentifier(prop.key)\n ) {\n return prop.key.name;\n }\n return '';\n })\n .filter(Boolean),\n ];\n }\n\n // Handle const temp = require('pkg') followed by const { T, Var } = temp\n if (\n babel.isCallExpression(declaration.init) &&\n babel.isIdentifier(declaration.init.callee) &&\n declaration.init.callee.name === 'require' &&\n babel.isStringLiteral(declaration.init.arguments[0]) &&\n declaration.init.arguments[0].value === pkg &&\n babel.isIdentifier(declaration.id)\n ) {\n const requireVarName = declaration.id.name;\n const parentBody =\n babel.isProgram(path.parent) || babel.isBlockStatement(path.parent)\n ? path.parent.body\n : [];\n\n // Look for subsequent destructuring\n for (const node of parentBody) {\n if (\n babel.isVariableDeclaration(node) &&\n node.declarations[0] &&\n babel.isObjectPattern(node.declarations[0].id) &&\n babel.isMemberExpression(node.declarations[0].init) &&\n babel.isIdentifier(node.declarations[0].init.object) &&\n node.declarations[0].init.object.name === requireVarName\n ) {\n initialImports = [\n ...initialImports,\n ...node.declarations[0].id.properties\n .map((prop) => {\n if (\n babel.isObjectProperty(prop) &&\n babel.isIdentifier(prop.key)\n ) {\n return prop.key.name;\n }\n return '';\n })\n .filter(Boolean),\n ];\n }\n }\n }\n\n // Check for conflicting requires\n if (\n babel.isCallExpression(declaration.init) &&\n babel.isIdentifier(declaration.init.callee) &&\n declaration.init.callee.name === 'require' &&\n babel.isStringLiteral(declaration.init.arguments[0]) &&\n declaration.init.arguments[0].value !== pkg &&\n babel.isObjectPattern(declaration.id)\n ) {\n declaration.id.properties.forEach((prop) => {\n if (babel.isObjectProperty(prop) && babel.isIdentifier(prop.value)) {\n if (prop.value.name === 'T') importAlias.TComponent = 'GTT';\n if (prop.value.name === 'Var') importAlias.VarComponent = 'GTVar';\n }\n });\n }\n\n // Add check for intermediate variable conflict\n if (babel.isIdentifier(declaration.id)) {\n if (declaration.id.name === 'T') importAlias.TComponent = 'GTT';\n if (declaration.id.name === 'Var') importAlias.VarComponent = 'GTVar';\n }\n },\n });\n return { initialImports, importAlias };\n}\n\nexport function insertImports(\n ast: ParseResult<t.File>,\n importNodes: (t.ImportDeclaration | t.VariableDeclaration)[]\n) {\n // Find the best position to insert the imports\n let insertIndex = 0;\n for (let i = 0; i < ast.program.body.length; i++) {\n if (!babel.isImportDeclaration(ast.program.body[i])) {\n insertIndex = i;\n break;\n }\n insertIndex = i + 1;\n }\n\n // Insert all import nodes\n ast.program.body.splice(insertIndex, 0, ...importNodes);\n}\n\nexport function createImports(\n ast: ParseResult<t.File>,\n needsImport: ImportItem[],\n importMap: Record<string, { name: string; source: string }>\n) {\n const isESM = determineModuleType(ast);\n\n const importNodes = generateImports(needsImport, isESM, importMap);\n\n insertImports(ast, importNodes);\n}\n\nexport interface ImportNameResult {\n local: string;\n original: string;\n}\n\nexport function extractImportName(\n node: ImportDeclaration | VariableDeclaration,\n pkgs: GTLibrary[],\n translationFuncs: string[]\n): ImportNameResult[] {\n const results: ImportNameResult[] = [];\n\n if (node.type === 'ImportDeclaration') {\n // Handle ES6 imports\n if (pkgs.some((pkg) => node.source.value.startsWith(pkg))) {\n for (const specifier of node.specifiers) {\n if (\n specifier.type === 'ImportSpecifier' &&\n 'name' in specifier.imported &&\n translationFuncs.includes(specifier.imported.name)\n ) {\n results.push({\n local: specifier.local.name,\n original: specifier.imported.name,\n });\n }\n }\n }\n } else if (node.type === 'VariableDeclaration') {\n // Handle CJS requires\n for (const declaration of node.declarations) {\n // Handle direct require with destructuring\n if (\n declaration.init?.type === 'CallExpression' &&\n declaration.init.callee.type === 'Identifier' &&\n declaration.init.callee.name === 'require' &&\n declaration.init.arguments[0]?.type === 'StringLiteral' &&\n pkgs.some((pkg) =>\n (\n (declaration!.init as t.CallExpression)\n .arguments[0] as t.StringLiteral\n ).value.startsWith(pkg)\n )\n ) {\n // Handle destructuring case: const { T } = require('gt-next')\n if (declaration.id.type === 'ObjectPattern') {\n for (const prop of declaration.id.properties) {\n if (\n prop.type === 'ObjectProperty' &&\n prop.key.type === 'Identifier' &&\n translationFuncs.includes(prop.key.name) &&\n prop.value.type === 'Identifier'\n ) {\n results.push({\n local: prop.value.name,\n original: prop.key.name,\n });\n }\n }\n }\n // Handle intermediate variable case: const temp = require('gt-next')\n else if (declaration.id.type === 'Identifier') {\n const requireVarName = declaration.id.name;\n const parentBody = (node as NodeWithParentBody).parent?.body;\n if (parentBody) {\n for (let i = 0; i < parentBody.length; i++) {\n const stmt = parentBody[i];\n if (\n stmt.type === 'VariableDeclaration' &&\n stmt.declarations[0]?.id.type === 'Identifier' &&\n stmt.declarations[0]?.init?.type === 'MemberExpression' &&\n stmt.declarations[0].init.object.type === 'Identifier' &&\n stmt.declarations[0].init.object.name === requireVarName &&\n stmt.declarations[0].init.property.type === 'Identifier' &&\n translationFuncs.includes(\n stmt.declarations[0].init.property.name\n )\n ) {\n results.push({\n local: stmt.declarations[0].id.name,\n original: stmt.declarations[0].init.property.name,\n });\n }\n }\n }\n }\n }\n // Handle member expression assignment: const TranslateFunc = temp.T\n if (\n declaration.init?.type === 'MemberExpression' &&\n declaration.init.property.type === 'Identifier' &&\n translationFuncs.includes(declaration.init.property.name) &&\n declaration.id.type === 'Identifier'\n ) {\n results.push({\n local: declaration.id.name,\n original: declaration.init.property.name,\n });\n }\n }\n }\n return results;\n}\n"],"mappings":";;;AAIA,MAAM,WAAW,eAAe,WAAW;AAa3C,SAAgB,oBAAoB,KAA0B;CAC5D,IAAI,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