gtx-cli 2.6.31 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -1261
- package/README.md +12 -3
- package/dist/bin/bin-entry.js +2 -1
- package/dist/config/generateSettings.d.ts +1 -9
- package/dist/config/generateSettings.js +1 -214
- package/dist/config/resolveConfig.d.ts +1 -4
- package/dist/config/resolveConfig.js +1 -33
- package/dist/fs/config/setupConfig.d.ts +1 -17
- package/dist/fs/config/setupConfig.js +1 -50
- package/dist/fs/matchFiles.d.ts +1 -1
- package/dist/fs/matchFiles.js +1 -8
- package/dist/functions.d.ts +1 -7
- package/dist/functions.js +1 -6
- package/dist/index.d.ts +1 -4
- package/dist/index.js +1 -27
- package/dist/main.js +2 -2
- package/dist/next/parse/handleInitGT.d.ts +1 -7
- package/dist/next/parse/handleInitGT.js +1 -157
- package/dist/next/parse/wrapContent.d.ts +1 -12
- package/dist/next/parse/wrapContent.js +1 -164
- package/dist/react/parse/wrapContent.d.ts +1 -12
- package/dist/react/parse/wrapContent.js +1 -162
- package/dist/types/index.d.ts +1 -243
- package/dist/types/index.js +1 -1
- package/dist/utils/installPackage.d.ts +1 -3
- package/dist/utils/installPackage.js +1 -77
- package/dist/utils/packageInfo.d.ts +1 -3
- package/dist/utils/packageInfo.js +1 -17
- package/dist/utils/packageJson.d.ts +1 -6
- package/dist/utils/packageJson.js +1 -68
- package/dist/utils/packageManager.d.ts +1 -28
- package/dist/utils/packageManager.js +1 -269
- package/package.json +11 -97
- package/dist/api/collectUserEditDiffs.d.ts +0 -9
- package/dist/api/collectUserEditDiffs.js +0 -159
- package/dist/api/downloadFileBatch.d.ts +0 -23
- package/dist/api/downloadFileBatch.js +0 -190
- package/dist/api/saveLocalEdits.d.ts +0 -6
- package/dist/api/saveLocalEdits.js +0 -38
- package/dist/cli/base.d.ts +0 -59
- package/dist/cli/base.js +0 -529
- package/dist/cli/commands/download.d.ts +0 -8
- package/dist/cli/commands/download.js +0 -51
- package/dist/cli/commands/enqueue.d.ts +0 -9
- package/dist/cli/commands/enqueue.js +0 -27
- package/dist/cli/commands/setupProject.d.ts +0 -7
- package/dist/cli/commands/setupProject.js +0 -37
- package/dist/cli/commands/stage.d.ts +0 -9
- package/dist/cli/commands/stage.js +0 -59
- package/dist/cli/commands/translate.d.ts +0 -7
- package/dist/cli/commands/translate.js +0 -70
- package/dist/cli/commands/upload.d.ts +0 -13
- package/dist/cli/commands/upload.js +0 -142
- package/dist/cli/commands/utils/validation.d.ts +0 -13
- package/dist/cli/commands/utils/validation.js +0 -38
- package/dist/cli/flags.d.ts +0 -15
- package/dist/cli/flags.js +0 -70
- package/dist/cli/inline.d.ts +0 -17
- package/dist/cli/inline.js +0 -135
- package/dist/cli/next.d.ts +0 -10
- package/dist/cli/next.js +0 -12
- package/dist/cli/node.d.ts +0 -10
- package/dist/cli/node.js +0 -9
- package/dist/cli/react.d.ts +0 -12
- package/dist/cli/react.js +0 -72
- package/dist/config/optionPresets.d.ts +0 -3
- package/dist/config/optionPresets.js +0 -65
- package/dist/config/utils.d.ts +0 -2
- package/dist/config/utils.js +0 -4
- package/dist/config/validateSettings.d.ts +0 -3
- package/dist/config/validateSettings.js +0 -32
- package/dist/console/colors.d.ts +0 -6
- package/dist/console/colors.js +0 -19
- package/dist/console/displayTranslateSummary.d.ts +0 -1
- package/dist/console/displayTranslateSummary.js +0 -42
- package/dist/console/formatting.d.ts +0 -1
- package/dist/console/formatting.js +0 -7
- package/dist/console/index.d.ts +0 -34
- package/dist/console/index.js +0 -46
- package/dist/console/logger.d.ts +0 -35
- package/dist/console/logger.js +0 -250
- package/dist/console/logging.d.ts +0 -52
- package/dist/console/logging.js +0 -175
- package/dist/formats/files/aggregateFiles.d.ts +0 -4
- package/dist/formats/files/aggregateFiles.js +0 -156
- package/dist/formats/files/collectFiles.d.ts +0 -6
- package/dist/formats/files/collectFiles.js +0 -49
- package/dist/formats/files/convertToFileTranslationData.d.ts +0 -15
- package/dist/formats/files/convertToFileTranslationData.js +0 -21
- package/dist/formats/files/fileMapping.d.ts +0 -11
- package/dist/formats/files/fileMapping.js +0 -115
- package/dist/formats/files/preprocess/mdx.d.ts +0 -6
- package/dist/formats/files/preprocess/mdx.js +0 -14
- package/dist/formats/files/preprocess/mintlify.d.ts +0 -5
- package/dist/formats/files/preprocess/mintlify.js +0 -15
- package/dist/formats/files/preprocessContent.d.ts +0 -8
- package/dist/formats/files/preprocessContent.js +0 -23
- package/dist/formats/files/save.d.ts +0 -5
- package/dist/formats/files/save.js +0 -17
- package/dist/formats/files/supportedFiles.d.ts +0 -11
- package/dist/formats/files/supportedFiles.js +0 -20
- package/dist/formats/json/extractJson.d.ts +0 -15
- package/dist/formats/json/extractJson.js +0 -101
- package/dist/formats/json/flattenJson.d.ts +0 -14
- package/dist/formats/json/flattenJson.js +0 -64
- package/dist/formats/json/mergeJson.d.ts +0 -13
- package/dist/formats/json/mergeJson.js +0 -367
- package/dist/formats/json/parseJson.d.ts +0 -2
- package/dist/formats/json/parseJson.js +0 -109
- package/dist/formats/json/utils.d.ts +0 -47
- package/dist/formats/json/utils.js +0 -150
- package/dist/formats/utils.d.ts +0 -2
- package/dist/formats/utils.js +0 -24
- package/dist/formats/yaml/mergeYaml.d.ts +0 -5
- package/dist/formats/yaml/mergeYaml.js +0 -61
- package/dist/formats/yaml/parseYaml.d.ts +0 -5
- package/dist/formats/yaml/parseYaml.js +0 -24
- package/dist/formats/yaml/utils.d.ts +0 -2
- package/dist/formats/yaml/utils.js +0 -23
- package/dist/fs/clearLocaleDirs.d.ts +0 -8
- package/dist/fs/clearLocaleDirs.js +0 -126
- package/dist/fs/config/downloadedVersions.d.ts +0 -21
- package/dist/fs/config/downloadedVersions.js +0 -50
- package/dist/fs/config/loadConfig.d.ts +0 -1
- package/dist/fs/config/loadConfig.js +0 -9
- package/dist/fs/config/parseFilesConfig.d.ts +0 -27
- package/dist/fs/config/parseFilesConfig.js +0 -150
- package/dist/fs/config/updateConfig.d.ts +0 -21
- package/dist/fs/config/updateConfig.js +0 -57
- package/dist/fs/config/updateVersions.d.ts +0 -11
- package/dist/fs/config/updateVersions.js +0 -30
- package/dist/fs/copyFile.d.ts +0 -7
- package/dist/fs/copyFile.js +0 -39
- package/dist/fs/createLoadTranslationsFile.d.ts +0 -1
- package/dist/fs/createLoadTranslationsFile.js +0 -49
- package/dist/fs/determineFramework.d.ts +0 -5
- package/dist/fs/determineFramework.js +0 -53
- package/dist/fs/findFilepath.d.ts +0 -36
- package/dist/fs/findFilepath.js +0 -90
- package/dist/fs/index.d.ts +0 -1
- package/dist/fs/index.js +0 -1
- package/dist/fs/loadJSON.d.ts +0 -6
- package/dist/fs/loadJSON.js +0 -17
- package/dist/fs/saveJSON.d.ts +0 -1
- package/dist/fs/saveJSON.js +0 -7
- package/dist/fs/utils.d.ts +0 -1
- package/dist/fs/utils.js +0 -16
- package/dist/generated/version.d.ts +0 -1
- package/dist/generated/version.js +0 -2
- package/dist/git/branches.d.ts +0 -7
- package/dist/git/branches.js +0 -88
- package/dist/hooks/postProcess.d.ts +0 -4
- package/dist/hooks/postProcess.js +0 -110
- package/dist/locadex/setupFlow.d.ts +0 -2
- package/dist/locadex/setupFlow.js +0 -9
- package/dist/next/config/parseNextConfig.d.ts +0 -10
- package/dist/next/config/parseNextConfig.js +0 -53
- package/dist/next/jsx/utils.d.ts +0 -7
- package/dist/next/jsx/utils.js +0 -42
- package/dist/react/config/createESBuildConfig.d.ts +0 -2
- package/dist/react/config/createESBuildConfig.js +0 -119
- package/dist/react/jsx/evaluateJsx.d.ts +0 -24
- package/dist/react/jsx/evaluateJsx.js +0 -123
- package/dist/react/jsx/utils/buildImportMap.d.ts +0 -9
- package/dist/react/jsx/utils/buildImportMap.js +0 -30
- package/dist/react/jsx/utils/constants.d.ts +0 -15
- package/dist/react/jsx/utils/constants.js +0 -49
- package/dist/react/jsx/utils/getCalleeNameFromExpression.d.ts +0 -9
- package/dist/react/jsx/utils/getCalleeNameFromExpression.js +0 -32
- package/dist/react/jsx/utils/getPathsAndAliases.d.ts +0 -21
- package/dist/react/jsx/utils/getPathsAndAliases.js +0 -91
- package/dist/react/jsx/utils/isNumberLiteral.d.ts +0 -7
- package/dist/react/jsx/utils/isNumberLiteral.js +0 -13
- package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.d.ts +0 -9
- package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js +0 -138
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.d.ts +0 -6
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +0 -197
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.d.ts +0 -13
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js +0 -42
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.d.ts +0 -5
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js +0 -69
- package/dist/react/jsx/utils/jsxParsing/parseJsx.d.ts +0 -33
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js +0 -918
- package/dist/react/jsx/utils/jsxParsing/parseTProps.d.ts +0 -8
- package/dist/react/jsx/utils/jsxParsing/parseTProps.js +0 -65
- package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.d.ts +0 -2
- package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js +0 -61
- package/dist/react/jsx/utils/jsxParsing/types.d.ts +0 -48
- package/dist/react/jsx/utils/jsxParsing/types.js +0 -34
- package/dist/react/jsx/utils/mapAttributeName.d.ts +0 -11
- package/dist/react/jsx/utils/mapAttributeName.js +0 -12
- package/dist/react/jsx/utils/parseAst.d.ts +0 -31
- package/dist/react/jsx/utils/parseAst.js +0 -278
- package/dist/react/jsx/utils/parseDeclareStatic.d.ts +0 -15
- package/dist/react/jsx/utils/parseDeclareStatic.js +0 -540
- package/dist/react/jsx/utils/parseString.d.ts +0 -25
- package/dist/react/jsx/utils/parseString.js +0 -540
- package/dist/react/jsx/utils/parseStringFunction.d.ts +0 -30
- package/dist/react/jsx/utils/parseStringFunction.js +0 -348
- package/dist/react/jsx/utils/resolveImportPath.d.ts +0 -11
- package/dist/react/jsx/utils/resolveImportPath.js +0 -111
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.d.ts +0 -29
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js +0 -86
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.d.ts +0 -14
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js +0 -24
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.d.ts +0 -19
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js +0 -31
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleStaticTranslationCall.d.ts +0 -22
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleStaticTranslationCall.js +0 -51
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.d.ts +0 -18
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js +0 -39
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.d.ts +0 -24
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js +0 -68
- package/dist/react/jsx/utils/stringParsing/types.d.ts +0 -41
- package/dist/react/jsx/utils/stringParsing/types.js +0 -1
- package/dist/react/jsx/utils/types.d.ts +0 -14
- package/dist/react/jsx/utils/types.js +0 -1
- package/dist/react/jsx/utils/validateStringFunction.d.ts +0 -7
- package/dist/react/jsx/utils/validateStringFunction.js +0 -31
- package/dist/react/jsx/wrapJsx.d.ts +0 -51
- package/dist/react/jsx/wrapJsx.js +0 -387
- package/dist/react/parse/addVitePlugin/index.d.ts +0 -22
- package/dist/react/parse/addVitePlugin/index.js +0 -41
- package/dist/react/parse/addVitePlugin/installCompiler.d.ts +0 -8
- package/dist/react/parse/addVitePlugin/installCompiler.js +0 -22
- package/dist/react/parse/addVitePlugin/updateViteConfig.d.ts +0 -19
- package/dist/react/parse/addVitePlugin/updateViteConfig.js +0 -120
- package/dist/react/parse/addVitePlugin/utils/addCompilerImport.d.ts +0 -9
- package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js +0 -34
- package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.d.ts +0 -11
- package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js +0 -48
- package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.d.ts +0 -15
- package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js +0 -113
- package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.d.ts +0 -12
- package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js +0 -32
- package/dist/react/parse/createDictionaryUpdates.d.ts +0 -3
- package/dist/react/parse/createDictionaryUpdates.js +0 -187
- package/dist/react/parse/createInlineUpdates.d.ts +0 -13
- package/dist/react/parse/createInlineUpdates.js +0 -161
- package/dist/react/utils/flattenDictionary.d.ts +0 -20
- package/dist/react/utils/flattenDictionary.js +0 -75
- package/dist/react/utils/getEntryAndMetadata.d.ts +0 -5
- package/dist/react/utils/getEntryAndMetadata.js +0 -11
- package/dist/react/utils/getVariableName.d.ts +0 -25
- package/dist/react/utils/getVariableName.js +0 -37
- package/dist/setup/agentInstructions.d.ts +0 -24
- package/dist/setup/agentInstructions.js +0 -138
- package/dist/setup/detectFramework.d.ts +0 -31
- package/dist/setup/detectFramework.js +0 -106
- package/dist/setup/frameworkUtils.d.ts +0 -3
- package/dist/setup/frameworkUtils.js +0 -30
- package/dist/setup/instructions/base.md +0 -29
- package/dist/setup/instructions/gt-next.md +0 -107
- package/dist/setup/instructions/gt-react.md +0 -98
- package/dist/setup/userInput.d.ts +0 -4
- package/dist/setup/userInput.js +0 -32
- package/dist/setup/wizard.d.ts +0 -3
- package/dist/setup/wizard.js +0 -147
- package/dist/state/recentDownloads.d.ts +0 -12
- package/dist/state/recentDownloads.js +0 -18
- package/dist/state/translateWarnings.d.ts +0 -10
- package/dist/state/translateWarnings.js +0 -13
- package/dist/translation/parse.d.ts +0 -17
- package/dist/translation/parse.js +0 -77
- package/dist/translation/stage.d.ts +0 -3
- package/dist/translation/stage.js +0 -44
- package/dist/translation/validate.d.ts +0 -14
- package/dist/translation/validate.js +0 -100
- package/dist/types/branch.d.ts +0 -14
- package/dist/types/branch.js +0 -1
- package/dist/types/data/json.d.ts +0 -6
- package/dist/types/data/json.js +0 -1
- package/dist/types/data.d.ts +0 -37
- package/dist/types/data.js +0 -1
- package/dist/types/files.d.ts +0 -8
- package/dist/types/files.js +0 -1
- package/dist/types/libraries.d.ts +0 -31
- package/dist/types/libraries.js +0 -72
- package/dist/types/parsing.d.ts +0 -3
- package/dist/types/parsing.js +0 -1
- package/dist/utils/addExplicitAnchorIds.d.ts +0 -24
- package/dist/utils/addExplicitAnchorIds.js +0 -416
- package/dist/utils/constants.d.ts +0 -5
- package/dist/utils/constants.js +0 -6
- package/dist/utils/credentials.d.ts +0 -12
- package/dist/utils/credentials.js +0 -120
- package/dist/utils/flattenJsonFiles.d.ts +0 -2
- package/dist/utils/flattenJsonFiles.js +0 -36
- package/dist/utils/gitDiff.d.ts +0 -8
- package/dist/utils/gitDiff.js +0 -34
- package/dist/utils/gt.d.ts +0 -2
- package/dist/utils/gt.js +0 -2
- package/dist/utils/hash.d.ts +0 -6
- package/dist/utils/hash.js +0 -11
- package/dist/utils/headers.d.ts +0 -1
- package/dist/utils/headers.js +0 -14
- package/dist/utils/localizeRelativeAssets.d.ts +0 -8
- package/dist/utils/localizeRelativeAssets.js +0 -166
- package/dist/utils/localizeStaticImports.d.ts +0 -15
- package/dist/utils/localizeStaticImports.js +0 -397
- package/dist/utils/localizeStaticUrls.d.ts +0 -19
- package/dist/utils/localizeStaticUrls.js +0 -450
- package/dist/utils/mintlifyTitleFallback.d.ts +0 -6
- package/dist/utils/mintlifyTitleFallback.js +0 -80
- package/dist/utils/parse/needsCJS.d.ts +0 -20
- package/dist/utils/parse/needsCJS.js +0 -72
- package/dist/utils/persistPostprocessHashes.d.ts +0 -12
- package/dist/utils/persistPostprocessHashes.js +0 -39
- package/dist/utils/processAnchorIds.d.ts +0 -6
- package/dist/utils/processAnchorIds.js +0 -56
- package/dist/utils/processOpenApi.d.ts +0 -8
- package/dist/utils/processOpenApi.js +0 -651
- package/dist/utils/sanitizeFileContent.d.ts +0 -6
- package/dist/utils/sanitizeFileContent.js +0 -29
- package/dist/utils/sharedStaticAssets.d.ts +0 -9
- package/dist/utils/sharedStaticAssets.js +0 -384
- package/dist/utils/validateMdx.d.ts +0 -10
- package/dist/utils/validateMdx.js +0 -25
- package/dist/utils/wrapPlainUrls.d.ts +0 -8
- package/dist/utils/wrapPlainUrls.js +0 -72
- package/dist/workflows/download.d.ts +0 -32
- package/dist/workflows/download.js +0 -131
- package/dist/workflows/enqueue.d.ts +0 -17
- package/dist/workflows/enqueue.js +0 -59
- package/dist/workflows/setupProject.d.ts +0 -13
- package/dist/workflows/setupProject.js +0 -48
- package/dist/workflows/stage.d.ts +0 -18
- package/dist/workflows/stage.js +0 -59
- package/dist/workflows/steps/BranchStep.d.ts +0 -13
- package/dist/workflows/steps/BranchStep.js +0 -161
- package/dist/workflows/steps/DownloadStep.d.ts +0 -19
- package/dist/workflows/steps/DownloadStep.js +0 -131
- package/dist/workflows/steps/EnqueueStep.d.ts +0 -15
- package/dist/workflows/steps/EnqueueStep.js +0 -33
- package/dist/workflows/steps/PollJobsStep.d.ts +0 -31
- package/dist/workflows/steps/PollJobsStep.js +0 -288
- package/dist/workflows/steps/SetupStep.d.ts +0 -16
- package/dist/workflows/steps/SetupStep.js +0 -72
- package/dist/workflows/steps/UploadSourcesStep.d.ts +0 -27
- package/dist/workflows/steps/UploadSourcesStep.js +0 -131
- package/dist/workflows/steps/UploadTranslationsStep.d.ts +0 -22
- package/dist/workflows/steps/UploadTranslationsStep.js +0 -71
- package/dist/workflows/steps/UserEditDiffsStep.d.ts +0 -11
- package/dist/workflows/steps/UserEditDiffsStep.js +0 -30
- package/dist/workflows/steps/WorkflowStep.d.ts +0 -4
- package/dist/workflows/steps/WorkflowStep.js +0 -2
- package/dist/workflows/upload.d.ts +0 -15
- package/dist/workflows/upload.js +0 -47
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
import * as t from '@babel/types';
|
|
2
|
-
import { MSG_REGISTRATION_FUNCTION, INLINE_TRANSLATION_HOOK, INLINE_TRANSLATION_HOOK_ASYNC, INLINE_MESSAGE_HOOK, INLINE_MESSAGE_HOOK_ASYNC, } from './constants.js';
|
|
3
|
-
import { warnAsyncUseGT, warnSyncGetGT } from '../../../console/index.js';
|
|
4
|
-
import traverseModule from '@babel/traverse';
|
|
5
|
-
// Handle CommonJS/ESM interop
|
|
6
|
-
const traverse = traverseModule.default || traverseModule;
|
|
7
|
-
import fs from 'node:fs';
|
|
8
|
-
import { parse } from '@babel/parser';
|
|
9
|
-
import { resolveImportPath } from './resolveImportPath.js';
|
|
10
|
-
import { buildImportMap } from './buildImportMap.js';
|
|
11
|
-
import { processTranslationCall } from './stringParsing/processTranslationCall/index.js';
|
|
12
|
-
/**
|
|
13
|
-
* Cache for resolved import paths to avoid redundant I/O operations.
|
|
14
|
-
* Key: `${currentFile}::${importPath}`
|
|
15
|
-
* Value: resolved absolute path or null
|
|
16
|
-
*/
|
|
17
|
-
const resolveImportPathCache = new Map();
|
|
18
|
-
/**
|
|
19
|
-
* Cache for processed functions to avoid re-parsing the same files.
|
|
20
|
-
* Key: `${filePath}::${functionName}::${argIndex}`
|
|
21
|
-
* Value: boolean indicating whether the function was found and processed
|
|
22
|
-
*/
|
|
23
|
-
const processFunctionCache = new Map();
|
|
24
|
-
/**
|
|
25
|
-
* Clears all caches. Useful for testing or when file system changes.
|
|
26
|
-
*/
|
|
27
|
-
export function clearParsingCaches() {
|
|
28
|
-
resolveImportPathCache.clear();
|
|
29
|
-
processFunctionCache.clear();
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Extracts the parameter name from a function parameter node, handling TypeScript annotations and default values.
|
|
33
|
-
*/
|
|
34
|
-
function extractParameterName(param) {
|
|
35
|
-
if (t.isIdentifier(param)) {
|
|
36
|
-
return param.name;
|
|
37
|
-
}
|
|
38
|
-
// Handle parameters with default values: (gt = () => {})
|
|
39
|
-
if (t.isAssignmentPattern(param) && t.isIdentifier(param.left)) {
|
|
40
|
-
return param.left.name;
|
|
41
|
-
}
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Recursively resolves variable assignments to find all aliases of a translation callback parameter.
|
|
46
|
-
* Handles cases like: const t = translate; const a = translate; const b = a; const c = b;
|
|
47
|
-
*
|
|
48
|
-
* @param scope The scope to search within
|
|
49
|
-
* @param variableName The variable name to resolve
|
|
50
|
-
* @param visited Set to track already visited variables to prevent infinite loops
|
|
51
|
-
* @returns Array of all variable names that reference the original translation callback
|
|
52
|
-
*/
|
|
53
|
-
export function resolveVariableAliases(scope, variableName, visited = new Set()) {
|
|
54
|
-
if (visited.has(variableName)) {
|
|
55
|
-
return []; // Prevent infinite loops
|
|
56
|
-
}
|
|
57
|
-
visited.add(variableName);
|
|
58
|
-
const aliases = [variableName];
|
|
59
|
-
const binding = scope.bindings[variableName];
|
|
60
|
-
if (binding) {
|
|
61
|
-
// Look for variable declarations that assign this variable to another name
|
|
62
|
-
// Example: const t = translate; or const a = t;
|
|
63
|
-
for (const [otherVarName, otherBinding] of Object.entries(scope.bindings)) {
|
|
64
|
-
if (otherVarName === variableName || visited.has(otherVarName))
|
|
65
|
-
continue;
|
|
66
|
-
const otherBindingTyped = otherBinding;
|
|
67
|
-
if (otherBindingTyped.path &&
|
|
68
|
-
otherBindingTyped.path.isVariableDeclarator() &&
|
|
69
|
-
otherBindingTyped.path.node.init &&
|
|
70
|
-
t.isIdentifier(otherBindingTyped.path.node.init) &&
|
|
71
|
-
otherBindingTyped.path.node.init.name === variableName) {
|
|
72
|
-
// Found an alias: const otherVarName = variableName;
|
|
73
|
-
const nestedAliases = resolveVariableAliases(scope, otherVarName, visited);
|
|
74
|
-
aliases.push(...nestedAliases);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return aliases;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Handles how translation callbacks are used within code.
|
|
82
|
-
* This covers both direct translation calls (t('hello')) and prop drilling
|
|
83
|
-
* where the translation callback is passed to other functions (getData(t)).
|
|
84
|
-
*/
|
|
85
|
-
function handleFunctionCall(tPath, config, state, output) {
|
|
86
|
-
if (tPath.parent.type === 'CallExpression' &&
|
|
87
|
-
tPath.parent.callee === tPath.node) {
|
|
88
|
-
// Direct translation call: t('hello')
|
|
89
|
-
processTranslationCall(tPath, config, output);
|
|
90
|
-
}
|
|
91
|
-
else if (tPath.parent.type === 'CallExpression' &&
|
|
92
|
-
t.isExpression(tPath.node) &&
|
|
93
|
-
tPath.parent.arguments.includes(tPath.node)) {
|
|
94
|
-
// Parameter passed to another function: getData(t)
|
|
95
|
-
const argIndex = tPath.parent.arguments.indexOf(tPath.node);
|
|
96
|
-
const callee = tPath.parent.callee;
|
|
97
|
-
if (t.isIdentifier(callee)) {
|
|
98
|
-
const calleeBinding = tPath.scope.getBinding(callee.name);
|
|
99
|
-
if (calleeBinding && calleeBinding.path.isFunction()) {
|
|
100
|
-
const functionPath = calleeBinding.path;
|
|
101
|
-
processFunctionIfMatches(callee.name, argIndex, functionPath.node, functionPath, config, output);
|
|
102
|
-
}
|
|
103
|
-
// Handle arrow functions assigned to variables: const getData = (t) => {...}
|
|
104
|
-
else if (calleeBinding &&
|
|
105
|
-
calleeBinding.path.isVariableDeclarator() &&
|
|
106
|
-
calleeBinding.path.node.init &&
|
|
107
|
-
(t.isArrowFunctionExpression(calleeBinding.path.node.init) ||
|
|
108
|
-
t.isFunctionExpression(calleeBinding.path.node.init))) {
|
|
109
|
-
const initPath = calleeBinding.path.get('init');
|
|
110
|
-
processFunctionIfMatches(callee.name, argIndex, calleeBinding.path.node.init, initPath, config, output);
|
|
111
|
-
}
|
|
112
|
-
// If not found locally, check if it's an imported function
|
|
113
|
-
else if (state.importMap.has(callee.name)) {
|
|
114
|
-
const importPath = state.importMap.get(callee.name);
|
|
115
|
-
const resolvedPath = resolveImportPath(config.file, importPath, config.parsingOptions, resolveImportPathCache);
|
|
116
|
-
if (resolvedPath) {
|
|
117
|
-
processFunctionInFile(resolvedPath, callee.name, argIndex, config, state, output);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Processes a user-defined function that receives a translation callback as a parameter.
|
|
125
|
-
* Validates the function has enough parameters and traces how the translation callback
|
|
126
|
-
* is used within that function's body.
|
|
127
|
-
*/
|
|
128
|
-
function processFunctionIfMatches(_functionName, argIndex, functionNode, functionPath, config, output) {
|
|
129
|
-
if (functionNode.params.length > argIndex) {
|
|
130
|
-
const param = functionNode.params[argIndex];
|
|
131
|
-
const paramName = extractParameterName(param);
|
|
132
|
-
if (paramName) {
|
|
133
|
-
findFunctionParameterUsage(functionPath, paramName, config, output);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Finds all usages of a translation callback parameter within a user-defined function's scope.
|
|
139
|
-
* Processes both direct translation calls and cases where the translation callback is passed
|
|
140
|
-
* to other functions (prop drilling).
|
|
141
|
-
*
|
|
142
|
-
* Example: In function getInfo(t) { return t('hello'); }, this finds the t('hello') call.
|
|
143
|
-
* Example: In function getData(t) { return getFooter(t); }, this finds and traces into getFooter.
|
|
144
|
-
*/
|
|
145
|
-
function findFunctionParameterUsage(functionPath, parameterName, config, output) {
|
|
146
|
-
// Look for the function body and find all usages of the parameter
|
|
147
|
-
if (functionPath.isFunction()) {
|
|
148
|
-
const functionScope = functionPath.scope;
|
|
149
|
-
// Resolve all aliases of the translation callback parameter
|
|
150
|
-
// Example: translate -> [translate, t, a, b] for const t = translate; const a = t; const b = a;
|
|
151
|
-
const allParameterNames = resolveVariableAliases(functionScope, parameterName);
|
|
152
|
-
// Build import map for this function's scope to handle cross-file calls
|
|
153
|
-
const programPath = functionPath.scope.getProgramParent().path;
|
|
154
|
-
const importMap = buildImportMap(programPath);
|
|
155
|
-
// Process references for all parameter names and their aliases
|
|
156
|
-
allParameterNames.forEach((name) => {
|
|
157
|
-
const binding = functionScope.bindings[name];
|
|
158
|
-
if (binding) {
|
|
159
|
-
binding.referencePaths.forEach((refPath) => {
|
|
160
|
-
handleFunctionCall(refPath, config, { visited: new Set(), importMap }, output);
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Searches for a specific user-defined function in a file and analyzes how a translation callback
|
|
168
|
-
* parameter (at argIndex position) is used within that function.
|
|
169
|
-
*
|
|
170
|
-
* Handles multiple function declaration patterns:
|
|
171
|
-
* - function getInfo(t) { ... }
|
|
172
|
-
* - export function getInfo(t) { ... }
|
|
173
|
-
* - const getInfo = (t) => { ... }
|
|
174
|
-
*
|
|
175
|
-
* If the function is not found in the file, follows re-exports (export * from './other')
|
|
176
|
-
*/
|
|
177
|
-
function processFunctionInFile(filePath, functionName, argIndex, config, state, output) {
|
|
178
|
-
// Check cache first to avoid redundant parsing
|
|
179
|
-
const cacheKey = `${filePath}::${functionName}::${argIndex}`;
|
|
180
|
-
if (processFunctionCache.has(cacheKey)) {
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
// Prevent infinite loops from circular re-exports
|
|
184
|
-
if (state.visited.has(filePath)) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
state.visited.add(filePath);
|
|
188
|
-
try {
|
|
189
|
-
const code = fs.readFileSync(filePath, 'utf8');
|
|
190
|
-
const ast = parse(code, {
|
|
191
|
-
sourceType: 'module',
|
|
192
|
-
plugins: ['jsx', 'typescript'],
|
|
193
|
-
});
|
|
194
|
-
let found = false;
|
|
195
|
-
const reExports = [];
|
|
196
|
-
traverse(ast, {
|
|
197
|
-
// Handle function declarations: function getInfo(t) { ... }
|
|
198
|
-
FunctionDeclaration(path) {
|
|
199
|
-
if (path.node.id?.name === functionName) {
|
|
200
|
-
found = true;
|
|
201
|
-
processFunctionIfMatches(functionName, argIndex, path.node, path, config, output);
|
|
202
|
-
}
|
|
203
|
-
},
|
|
204
|
-
// Handle variable declarations: const getInfo = (t) => { ... }
|
|
205
|
-
VariableDeclarator(path) {
|
|
206
|
-
if (t.isIdentifier(path.node.id) &&
|
|
207
|
-
path.node.id.name === functionName &&
|
|
208
|
-
path.node.init &&
|
|
209
|
-
(t.isArrowFunctionExpression(path.node.init) ||
|
|
210
|
-
t.isFunctionExpression(path.node.init))) {
|
|
211
|
-
found = true;
|
|
212
|
-
const initPath = path.get('init');
|
|
213
|
-
processFunctionIfMatches(functionName, argIndex, path.node.init, initPath, config, output);
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
// Collect re-exports: export * from './other'
|
|
217
|
-
ExportAllDeclaration(path) {
|
|
218
|
-
if (t.isStringLiteral(path.node.source)) {
|
|
219
|
-
reExports.push(path.node.source.value);
|
|
220
|
-
}
|
|
221
|
-
},
|
|
222
|
-
// Collect named re-exports: export { foo } from './other'
|
|
223
|
-
ExportNamedDeclaration(path) {
|
|
224
|
-
if (path.node.source && t.isStringLiteral(path.node.source)) {
|
|
225
|
-
// Check if this export includes our function
|
|
226
|
-
const exportsFunction = path.node.specifiers.some((spec) => {
|
|
227
|
-
if (t.isExportSpecifier(spec)) {
|
|
228
|
-
const exportedName = t.isIdentifier(spec.exported)
|
|
229
|
-
? spec.exported.name
|
|
230
|
-
: spec.exported.value;
|
|
231
|
-
return exportedName === functionName;
|
|
232
|
-
}
|
|
233
|
-
return false;
|
|
234
|
-
});
|
|
235
|
-
if (exportsFunction) {
|
|
236
|
-
reExports.push(path.node.source.value);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
});
|
|
241
|
-
// If function not found, follow re-exports
|
|
242
|
-
if (!found && reExports.length > 0) {
|
|
243
|
-
for (const reExportPath of reExports) {
|
|
244
|
-
const resolvedPath = resolveImportPath(filePath, reExportPath, config.parsingOptions, resolveImportPathCache);
|
|
245
|
-
if (resolvedPath) {
|
|
246
|
-
processFunctionInFile(resolvedPath, functionName, argIndex, config, state, output);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
// Mark this function search as processed in the cache
|
|
251
|
-
processFunctionCache.set(cacheKey, found);
|
|
252
|
-
}
|
|
253
|
-
catch {
|
|
254
|
-
// Silently skip files that can't be parsed or accessed
|
|
255
|
-
// Still mark as processed to avoid retrying failed parses
|
|
256
|
-
processFunctionCache.set(cacheKey, false);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Main entry point for parsing translation strings from useGT() and getGT() calls.
|
|
261
|
-
*
|
|
262
|
-
* Supports complex patterns including:
|
|
263
|
-
* 1. Direct calls: const t = useGT(); t('hello');
|
|
264
|
-
* 2. Translation callback prop drilling: const t = useGT(); getInfo(t); where getInfo uses t() internally
|
|
265
|
-
* 3. Cross-file function calls: imported functions that receive the translation callback as a parameter
|
|
266
|
-
*
|
|
267
|
-
* Example flow:
|
|
268
|
-
* - const t = useGT();
|
|
269
|
-
* - const { home } = getInfo(t); // getInfo is imported from './constants'
|
|
270
|
-
* - This will parse constants.ts to find translation calls within getInfo function
|
|
271
|
-
*/
|
|
272
|
-
export function parseStrings(importName, originalName, path, config, output) {
|
|
273
|
-
// First, collect all imports in this file to track cross-file function calls
|
|
274
|
-
const importMap = buildImportMap(path.scope.getProgramParent().path);
|
|
275
|
-
const referencePaths = path.scope.bindings[importName]?.referencePaths || [];
|
|
276
|
-
for (const refPath of referencePaths) {
|
|
277
|
-
// Handle msg() calls directly without variable assignment
|
|
278
|
-
if (originalName === MSG_REGISTRATION_FUNCTION) {
|
|
279
|
-
const msgConfig = {
|
|
280
|
-
parsingOptions: config.parsingOptions,
|
|
281
|
-
file: config.file,
|
|
282
|
-
ignoreInlineMetadata: false,
|
|
283
|
-
ignoreDynamicContent: false,
|
|
284
|
-
ignoreInvalidIcu: false,
|
|
285
|
-
ignoreInlineListContent: false,
|
|
286
|
-
};
|
|
287
|
-
// Check if this is a direct call to msg('string')
|
|
288
|
-
if (refPath.parent.type === 'CallExpression' &&
|
|
289
|
-
refPath.parent.callee === refPath.node) {
|
|
290
|
-
processTranslationCall(refPath, msgConfig, output);
|
|
291
|
-
}
|
|
292
|
-
continue;
|
|
293
|
-
}
|
|
294
|
-
// Handle useGT(), getGT(), useMessages(), and getMessages() calls that need variable assignment
|
|
295
|
-
const callExpr = refPath.findParent((p) => p.isCallExpression());
|
|
296
|
-
if (callExpr) {
|
|
297
|
-
// Get the parent, handling both await and non-await cases
|
|
298
|
-
const parentPath = callExpr.parentPath;
|
|
299
|
-
const parentFunction = refPath.getFunctionParent();
|
|
300
|
-
const asyncScope = parentFunction?.node.async;
|
|
301
|
-
if (asyncScope &&
|
|
302
|
-
(originalName === INLINE_TRANSLATION_HOOK ||
|
|
303
|
-
originalName === INLINE_MESSAGE_HOOK)) {
|
|
304
|
-
output.errors.push(warnAsyncUseGT(config.file, `${refPath.node.loc?.start?.line}:${refPath.node.loc?.start?.column}`));
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
|
-
else if (!asyncScope &&
|
|
308
|
-
(originalName === INLINE_TRANSLATION_HOOK_ASYNC ||
|
|
309
|
-
originalName === INLINE_MESSAGE_HOOK_ASYNC)) {
|
|
310
|
-
output.errors.push(warnSyncGetGT(config.file, `${refPath.node.loc?.start?.line}:${refPath.node.loc?.start?.column}`));
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
const isMessageHook = originalName === INLINE_MESSAGE_HOOK ||
|
|
314
|
-
originalName === INLINE_MESSAGE_HOOK_ASYNC;
|
|
315
|
-
const isInlineGT = originalName === INLINE_TRANSLATION_HOOK ||
|
|
316
|
-
originalName === INLINE_TRANSLATION_HOOK_ASYNC;
|
|
317
|
-
const hookConfig = {
|
|
318
|
-
parsingOptions: config.parsingOptions,
|
|
319
|
-
file: config.file,
|
|
320
|
-
ignoreInlineMetadata: isMessageHook,
|
|
321
|
-
ignoreDynamicContent: isMessageHook,
|
|
322
|
-
ignoreInvalidIcu: isMessageHook,
|
|
323
|
-
// TODO: when we add support for array content in gt function, this should just always be false
|
|
324
|
-
ignoreInlineListContent: isInlineGT,
|
|
325
|
-
};
|
|
326
|
-
const effectiveParent = parentPath?.node.type === 'AwaitExpression'
|
|
327
|
-
? parentPath.parentPath
|
|
328
|
-
: parentPath;
|
|
329
|
-
if (effectiveParent &&
|
|
330
|
-
effectiveParent.node.type === 'VariableDeclarator' &&
|
|
331
|
-
effectiveParent.node.id.type === 'Identifier') {
|
|
332
|
-
const tFuncName = effectiveParent.node.id.name;
|
|
333
|
-
// Get the scope from the variable declaration
|
|
334
|
-
const variableScope = effectiveParent.scope;
|
|
335
|
-
// Resolve all aliases of the translation function
|
|
336
|
-
// Example: translate -> [translate, t, a, b] for const t = translate; const a = t; const b = a;
|
|
337
|
-
const allTranslationNames = resolveVariableAliases(variableScope, tFuncName);
|
|
338
|
-
// Process references for all translation function names and their aliases
|
|
339
|
-
allTranslationNames.forEach((name) => {
|
|
340
|
-
const tReferencePaths = variableScope.bindings[name]?.referencePaths || [];
|
|
341
|
-
for (const tPath of tReferencePaths) {
|
|
342
|
-
handleFunctionCall(tPath, hookConfig, { visited: new Set(), importMap }, output);
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ParsingConfigOptions } from '../../../types/parsing.js';
|
|
2
|
-
/**
|
|
3
|
-
* Resolves import paths to absolute file paths using battle-tested libraries.
|
|
4
|
-
* Handles relative paths, TypeScript paths, and node module resolution.
|
|
5
|
-
*
|
|
6
|
-
* Examples:
|
|
7
|
-
* - './constants' -> '/full/path/to/constants.ts'
|
|
8
|
-
* - '@/components/ui/button' -> '/full/path/to/src/components/ui/button.tsx'
|
|
9
|
-
* - '@shared/utils' -> '/full/path/to/packages/utils/index.ts'
|
|
10
|
-
*/
|
|
11
|
-
export declare function resolveImportPath(currentFile: string, importPath: string, parsingOptions: ParsingConfigOptions, resolveImportPathCache: Map<string, string | null>): string | null;
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { createMatchPath, loadConfig } from 'tsconfig-paths';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import resolve from 'resolve';
|
|
5
|
-
import enhancedResolve from 'enhanced-resolve';
|
|
6
|
-
const { ResolverFactory } = enhancedResolve;
|
|
7
|
-
/**
|
|
8
|
-
* Resolves import paths to absolute file paths using battle-tested libraries.
|
|
9
|
-
* Handles relative paths, TypeScript paths, and node module resolution.
|
|
10
|
-
*
|
|
11
|
-
* Examples:
|
|
12
|
-
* - './constants' -> '/full/path/to/constants.ts'
|
|
13
|
-
* - '@/components/ui/button' -> '/full/path/to/src/components/ui/button.tsx'
|
|
14
|
-
* - '@shared/utils' -> '/full/path/to/packages/utils/index.ts'
|
|
15
|
-
*/
|
|
16
|
-
export function resolveImportPath(currentFile, importPath, parsingOptions, resolveImportPathCache) {
|
|
17
|
-
// Check cache first
|
|
18
|
-
const cacheKey = `${currentFile}::${importPath}`;
|
|
19
|
-
if (resolveImportPathCache.has(cacheKey)) {
|
|
20
|
-
return resolveImportPathCache.get(cacheKey);
|
|
21
|
-
}
|
|
22
|
-
const basedir = path.dirname(currentFile);
|
|
23
|
-
const extensions = ['.tsx', '.ts', '.jsx', '.js'];
|
|
24
|
-
const mainFields = ['module', 'main'];
|
|
25
|
-
let result = null;
|
|
26
|
-
// 1. Try tsconfig-paths resolution first (handles TypeScript path mapping)
|
|
27
|
-
const tsConfigResult = loadConfig(basedir);
|
|
28
|
-
if (tsConfigResult.resultType === 'success') {
|
|
29
|
-
const matchPath = createMatchPath(tsConfigResult.absoluteBaseUrl, tsConfigResult.paths, mainFields);
|
|
30
|
-
// First try without any extension
|
|
31
|
-
let tsResolved = matchPath(importPath);
|
|
32
|
-
if (tsResolved && fs.existsSync(tsResolved)) {
|
|
33
|
-
result = tsResolved;
|
|
34
|
-
resolveImportPathCache.set(cacheKey, result);
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
// Then try with each extension
|
|
38
|
-
for (const ext of extensions) {
|
|
39
|
-
tsResolved = matchPath(importPath + ext);
|
|
40
|
-
if (tsResolved && fs.existsSync(tsResolved)) {
|
|
41
|
-
result = tsResolved;
|
|
42
|
-
resolveImportPathCache.set(cacheKey, result);
|
|
43
|
-
return result;
|
|
44
|
-
}
|
|
45
|
-
// Also try the resolved path with extension
|
|
46
|
-
tsResolved = matchPath(importPath);
|
|
47
|
-
if (tsResolved) {
|
|
48
|
-
const resolvedWithExt = tsResolved + ext;
|
|
49
|
-
if (fs.existsSync(resolvedWithExt)) {
|
|
50
|
-
result = resolvedWithExt;
|
|
51
|
-
resolveImportPathCache.set(cacheKey, result);
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
// 2. Try enhanced-resolve (handles package.json exports field and modern resolution)
|
|
58
|
-
try {
|
|
59
|
-
const resolver = ResolverFactory.createResolver({
|
|
60
|
-
useSyncFileSystemCalls: true,
|
|
61
|
-
fileSystem: fs,
|
|
62
|
-
extensions,
|
|
63
|
-
// Include 'development' condition to resolve to source files in monorepos
|
|
64
|
-
conditionNames: parsingOptions.conditionNames, // defaults to ['browser', 'module', 'import', 'require', 'default']. See generateSettings.ts for more details
|
|
65
|
-
exportsFields: ['exports'],
|
|
66
|
-
mainFields,
|
|
67
|
-
});
|
|
68
|
-
const resolved = resolver.resolveSync({}, basedir, importPath);
|
|
69
|
-
if (resolved) {
|
|
70
|
-
result = resolved;
|
|
71
|
-
resolveImportPathCache.set(cacheKey, result);
|
|
72
|
-
return result;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
// Fall through to next resolution strategy
|
|
77
|
-
}
|
|
78
|
-
// 3. Fallback to Node.js resolution (handles relative paths and node_modules)
|
|
79
|
-
try {
|
|
80
|
-
result = resolve.sync(importPath, { basedir, extensions });
|
|
81
|
-
resolveImportPathCache.set(cacheKey, result);
|
|
82
|
-
return result;
|
|
83
|
-
}
|
|
84
|
-
catch {
|
|
85
|
-
// If resolution fails, try to manually replace .js/.jsx with .ts/.tsx for source files
|
|
86
|
-
if (importPath.endsWith('.js')) {
|
|
87
|
-
const tsPath = importPath.replace(/\.js$/, '.ts');
|
|
88
|
-
try {
|
|
89
|
-
result = resolve.sync(tsPath, { basedir, extensions });
|
|
90
|
-
resolveImportPathCache.set(cacheKey, result);
|
|
91
|
-
return result;
|
|
92
|
-
}
|
|
93
|
-
catch {
|
|
94
|
-
// Continue to return null
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
else if (importPath.endsWith('.jsx')) {
|
|
98
|
-
const tsxPath = importPath.replace(/\.jsx$/, '.tsx');
|
|
99
|
-
try {
|
|
100
|
-
result = resolve.sync(tsxPath, { basedir, extensions });
|
|
101
|
-
resolveImportPathCache.set(cacheKey, result);
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
catch {
|
|
105
|
-
// Continue to return null
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
resolveImportPathCache.set(cacheKey, null);
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
}
|
package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import * as t from '@babel/types';
|
|
2
|
-
import { ParsingConfig } from '../types.js';
|
|
3
|
-
import { ParsingOutput } from '../types.js';
|
|
4
|
-
/**
|
|
5
|
-
* Metadata record type
|
|
6
|
-
*/
|
|
7
|
-
export type InlineMetadata = {
|
|
8
|
-
maxChars?: number;
|
|
9
|
-
context?: string;
|
|
10
|
-
id?: string;
|
|
11
|
-
hash?: string;
|
|
12
|
-
filePaths?: string[];
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Extracts inline metadata from a string entry
|
|
16
|
-
* @param metadata - The metadata record to inject the data into
|
|
17
|
-
* @param entry - The string entry to extract the metadata from
|
|
18
|
-
* @param output - The output to use
|
|
19
|
-
* @param config - The configuration to use
|
|
20
|
-
* @returns The inline metadata
|
|
21
|
-
*
|
|
22
|
-
* @note - this function does not automatically append the index to the id, this must be done manually in the caller.
|
|
23
|
-
*
|
|
24
|
-
*/
|
|
25
|
-
export declare function extractStringEntryMetadata({ options, output, config, }: {
|
|
26
|
-
options?: t.CallExpression['arguments'][number];
|
|
27
|
-
output: ParsingOutput;
|
|
28
|
-
config: ParsingConfig;
|
|
29
|
-
}): InlineMetadata;
|
package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import * as t from '@babel/types';
|
|
2
|
-
import { isStaticExpression } from '../../../evaluateJsx.js';
|
|
3
|
-
import { warnInvalidMaxCharsSync } from '../../../../../console/index.js';
|
|
4
|
-
import { warnNonStaticExpressionSync } from '../../../../../console/index.js';
|
|
5
|
-
import { GT_ATTRIBUTES_WITH_SUGAR } from '../../constants.js';
|
|
6
|
-
import generateModule from '@babel/generator';
|
|
7
|
-
import { mapAttributeName } from '../../mapAttributeName.js';
|
|
8
|
-
import pathModule from 'node:path';
|
|
9
|
-
import { isNumberLiteral } from '../../isNumberLiteral.js';
|
|
10
|
-
// Handle CommonJS/ESM interop
|
|
11
|
-
const generate = generateModule.default || generateModule;
|
|
12
|
-
/**
|
|
13
|
-
* Extracts inline metadata from a string entry
|
|
14
|
-
* @param metadata - The metadata record to inject the data into
|
|
15
|
-
* @param entry - The string entry to extract the metadata from
|
|
16
|
-
* @param output - The output to use
|
|
17
|
-
* @param config - The configuration to use
|
|
18
|
-
* @returns The inline metadata
|
|
19
|
-
*
|
|
20
|
-
* @note - this function does not automatically append the index to the id, this must be done manually in the caller.
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
export function extractStringEntryMetadata({ options, output, config, }) {
|
|
24
|
-
// extract filepath for entry
|
|
25
|
-
const relativeFilepath = pathModule.relative(process.cwd(), config.file);
|
|
26
|
-
// extract inline metadata
|
|
27
|
-
const inlineMetadata = extractInlineMetadata({
|
|
28
|
-
options,
|
|
29
|
-
output,
|
|
30
|
-
config,
|
|
31
|
-
});
|
|
32
|
-
return {
|
|
33
|
-
...inlineMetadata,
|
|
34
|
-
filePaths: relativeFilepath ? [relativeFilepath] : undefined,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
// ----- Helper Functions ----- //
|
|
38
|
-
/**
|
|
39
|
-
* Extracts inline metadata specified e.g. gt('Hello', { $context: 'greeting' })
|
|
40
|
-
* @param options - The options to extract the metadata from
|
|
41
|
-
* @param output - The output to use
|
|
42
|
-
* @param config - The configuration to use
|
|
43
|
-
* @param index - The index of the string entry
|
|
44
|
-
* @returns The inline metadata
|
|
45
|
-
*/
|
|
46
|
-
function extractInlineMetadata({ options, output, config, }) {
|
|
47
|
-
const metadata = {};
|
|
48
|
-
if (options && options.type === 'ObjectExpression') {
|
|
49
|
-
options.properties.forEach((prop) => {
|
|
50
|
-
if (prop.type === 'ObjectProperty' && prop.key.type === 'Identifier') {
|
|
51
|
-
const attribute = prop.key.name;
|
|
52
|
-
if (GT_ATTRIBUTES_WITH_SUGAR.includes(attribute) &&
|
|
53
|
-
t.isExpression(prop.value)) {
|
|
54
|
-
const result = isStaticExpression(prop.value);
|
|
55
|
-
if (!result.isStatic) {
|
|
56
|
-
output.errors.push(warnNonStaticExpressionSync(config.file, attribute, generate(prop.value).code, `${prop.loc?.start?.line}:${prop.loc?.start?.column}`));
|
|
57
|
-
}
|
|
58
|
-
if (result.isStatic &&
|
|
59
|
-
result.value != null &&
|
|
60
|
-
!config.ignoreInlineMetadata) {
|
|
61
|
-
const mappedKey = mapAttributeName(attribute);
|
|
62
|
-
if (mappedKey === 'maxChars') {
|
|
63
|
-
// Handle maxChars attribute
|
|
64
|
-
if ((typeof result.value === 'string' &&
|
|
65
|
-
(isNaN(Number(result.value)) ||
|
|
66
|
-
!isNumberLiteral(prop.value))) ||
|
|
67
|
-
!Number.isInteger(Number(result.value))) {
|
|
68
|
-
output.errors.push(warnInvalidMaxCharsSync(config.file, generate(prop).code, `${prop.loc?.start?.line}:${prop.loc?.start?.column}`));
|
|
69
|
-
}
|
|
70
|
-
else if (typeof result.value === 'string') {
|
|
71
|
-
// Add the maxChars value to the metadata
|
|
72
|
-
metadata[mappedKey] = Math.abs(Number(result.value));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
// Add the $context or $id or other attributes value to the metadata
|
|
77
|
-
// TODO: why are we including everything? arent we only interested in relevant inline metadata?
|
|
78
|
-
metadata[mappedKey] = result.value;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
return metadata;
|
|
86
|
-
}
|
package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as t from '@babel/types';
|
|
2
|
-
import { ParsingConfig, ParsingOutput } from '../types.js';
|
|
3
|
-
/**
|
|
4
|
-
* For the processTranslationCall function, this function handles the case where a other translation call is used.
|
|
5
|
-
* Error is pushed if the other translation call is used.
|
|
6
|
-
* @param arg - The argument to parse
|
|
7
|
-
* @param config - The configuration to use
|
|
8
|
-
* @param output - The output to use
|
|
9
|
-
*/
|
|
10
|
-
export declare function handleInvalidTranslationCall({ arg, config, output, }: {
|
|
11
|
-
arg: t.ArgumentPlaceholder | t.SpreadElement | t.Expression;
|
|
12
|
-
config: ParsingConfig;
|
|
13
|
-
output: ParsingOutput;
|
|
14
|
-
}): void;
|
package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import * as t from '@babel/types';
|
|
2
|
-
import { warnNonStringSync, warnTemplateLiteralSync, } from '../../../../../console/index.js';
|
|
3
|
-
import generateModule from '@babel/generator';
|
|
4
|
-
// Handle CommonJS/ESM interop
|
|
5
|
-
const generate = generateModule.default || generateModule;
|
|
6
|
-
/**
|
|
7
|
-
* For the processTranslationCall function, this function handles the case where a other translation call is used.
|
|
8
|
-
* Error is pushed if the other translation call is used.
|
|
9
|
-
* @param arg - The argument to parse
|
|
10
|
-
* @param config - The configuration to use
|
|
11
|
-
* @param output - The output to use
|
|
12
|
-
*/
|
|
13
|
-
export function handleInvalidTranslationCall({ arg, config, output, }) {
|
|
14
|
-
if (config.ignoreDynamicContent)
|
|
15
|
-
return;
|
|
16
|
-
if (t.isTemplateLiteral(arg)) {
|
|
17
|
-
// Specific error for template literals
|
|
18
|
-
output.errors.push(warnTemplateLiteralSync(config.file, generate(arg).code, `${arg.loc?.start?.line}:${arg.loc?.start?.column}`));
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
// Generic error
|
|
22
|
-
output.errors.push(warnNonStringSync(config.file, generate(arg).code, `${arg.loc?.start?.line}:${arg.loc?.start?.column}`));
|
|
23
|
-
}
|
|
24
|
-
}
|
package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as t from '@babel/types';
|
|
2
|
-
import { ParsingConfig } from '../types.js';
|
|
3
|
-
import { ParsingOutput } from '../types.js';
|
|
4
|
-
import { InlineMetadata } from './extractStringEntryMetadata.js';
|
|
5
|
-
/**
|
|
6
|
-
* For the processTranslationCall function, this function handles the case where a string literal or template literal is used.
|
|
7
|
-
* @param arg - The argument to parse
|
|
8
|
-
* @param metadata - The metadata to use
|
|
9
|
-
* @param config - The configuration to use
|
|
10
|
-
* @param output - The output to use
|
|
11
|
-
* @param index - The index of the argument
|
|
12
|
-
*/
|
|
13
|
-
export declare function handleLiteralTranslationCall({ arg, metadata, config, output, index, }: {
|
|
14
|
-
arg: t.StringLiteral | t.TemplateLiteral;
|
|
15
|
-
metadata: InlineMetadata;
|
|
16
|
-
config: ParsingConfig;
|
|
17
|
-
output: ParsingOutput;
|
|
18
|
-
index?: number;
|
|
19
|
-
}): void;
|