gt 2.26.9 → 2.26.11

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/console/logger.d.ts +6 -2
  3. package/dist/console/logger.js +25 -5
  4. package/dist/console/logger.js.map +1 -1
  5. package/dist/console/logging.js +1 -1
  6. package/dist/console/logging.js.map +1 -1
  7. package/dist/formats/files/postprocess/keepUntranslatedPagePaths.js +4 -2
  8. package/dist/formats/files/postprocess/keepUntranslatedPagePaths.js.map +1 -1
  9. package/dist/formats/files/postprocess/localizeMintlifyRedirects.js +3 -2
  10. package/dist/formats/files/postprocess/localizeMintlifyRedirects.js.map +1 -1
  11. package/dist/fs/config/downloadedVersions.js +3 -2
  12. package/dist/fs/config/downloadedVersions.js.map +1 -1
  13. package/dist/fs/config/setupConfig.js +1 -1
  14. package/dist/fs/config/updateConfig.js +6 -4
  15. package/dist/fs/config/updateConfig.js.map +1 -1
  16. package/dist/fs/config/updateVersions.js +2 -1
  17. package/dist/fs/config/updateVersions.js.map +1 -1
  18. package/dist/fs/saveJSON.js +2 -1
  19. package/dist/fs/saveJSON.js.map +1 -1
  20. package/dist/fs/stringifyJson.d.ts +7 -0
  21. package/dist/fs/stringifyJson.js +15 -0
  22. package/dist/fs/stringifyJson.js.map +1 -0
  23. package/dist/generated/version.d.ts +1 -1
  24. package/dist/generated/version.js +1 -1
  25. package/dist/generated/version.js.map +1 -1
  26. package/dist/git/setupMergeDrivers.js +1 -1
  27. package/dist/utils/credentials.js +1 -1
  28. package/dist/utils/flattenJsonFiles.js +4 -2
  29. package/dist/utils/flattenJsonFiles.js.map +1 -1
  30. package/dist/utils/gitDiff.js +1 -1
  31. package/dist/utils/packageJson.js +4 -1
  32. package/dist/utils/packageJson.js.map +1 -1
  33. package/dist/utils/processOpenApi.js +2 -1
  34. package/dist/utils/processOpenApi.js.map +1 -1
  35. package/dist/utils/splitMintlifyLanguageRefs.js +10 -3
  36. package/dist/utils/splitMintlifyLanguageRefs.js.map +1 -1
  37. package/package.json +4 -3
@@ -1 +1 @@
1
- {"version":3,"file":"splitMintlifyLanguageRefs.js","names":[],"sources":["../../src/utils/splitMintlifyLanguageRefs.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport { logger } from '../console/logger.js';\nimport { Settings, JsonSchema, SourceObjectOptions } from '../types/index.js';\nimport type { RefMap } from './resolveMintlifyRefs.js';\nimport { validateJsonSchema } from '../formats/json/utils.js';\nimport { getStoredRefMap, clearStoredRefMap } from '../state/mintlifyRefMap.js';\nimport { JSONPath } from 'jsonpath-plus';\nimport { getLocaleProperties } from '@generaltranslation/format';\n\ntype JsonContainer = Record<string, unknown> | unknown[];\n\nfunction isJsonContainer(value: unknown): value is JsonContainer {\n return typeof value === 'object' && value !== null;\n}\n\n/**\n * Post-processing step for composite JSON files with splitEntries enabled.\n *\n * After mergeJson writes a fully-inlined composite file, this function:\n * 1. Restores the original $ref structure (if the source used $ref / resolveRefs)\n * 2. Extracts non-default keyed entries into their own ref files\n * to keep the source file compact\n *\n * Driven entirely by the jsonSchema config — reads the composite path,\n * key field, and splitEntries flag from the schema.\n */\nexport async function splitMintlifyLanguageRefs(\n settings: Settings\n): Promise<void> {\n const refMap = getStoredRefMap();\n\n try {\n const resolvedJsonPaths = settings.files?.resolvedPaths?.json;\n if (!resolvedJsonPaths) return;\n\n // Find a JSON file that has splitEntries enabled or resolveRefs\n const targetFile = findTargetFile(resolvedJsonPaths, settings);\n if (!targetFile) return;\n\n const { filePath: compositeFilePath, splitConfig } = targetFile;\n if (!fs.existsSync(compositeFilePath)) return;\n\n let fileJson: unknown;\n try {\n fileJson = JSON.parse(fs.readFileSync(compositeFilePath, 'utf-8'));\n } catch {\n return;\n }\n\n const docsDir = path.dirname(compositeFilePath);\n\n // If splitEntries is configured, process it\n if (splitConfig) {\n processSplitEntries(\n fileJson,\n compositeFilePath,\n docsDir,\n splitConfig,\n settings,\n refMap\n );\n }\n\n // Restore top-level refs if any exist\n if (refMap && refMap.size > 0) {\n restoreTopLevelRefs(fileJson, refMap, splitConfig);\n }\n\n // Always write the composite file back — splitEntries modified the\n // languages array, and restoreTopLevelRefs may not have written it\n // (e.g., when all refs are inside language entries, not top-level)\n fs.writeFileSync(\n compositeFilePath,\n JSON.stringify(fileJson, null, 2),\n 'utf-8'\n );\n } finally {\n clearStoredRefMap();\n }\n}\n\ntype SplitConfig = {\n compositePath: string;\n jsonPointer: string;\n keyField: string;\n keyJsonPath: string;\n sourceObjectOptions: SourceObjectOptions;\n};\n\n/**\n * Find the target file and extract split configuration from the schema.\n */\nfunction findTargetFile(\n resolvedPaths: string[],\n settings: Settings\n): {\n filePath: string;\n schema: JsonSchema;\n splitConfig: SplitConfig | null;\n} | null {\n if (!settings.options?.jsonSchema) return null;\n\n for (const filePath of resolvedPaths) {\n const schema = validateJsonSchema(settings.options, filePath);\n if (!schema) continue;\n\n const hasSplitEntries = schema.composite\n ? Object.entries(schema.composite).some(([, opts]) => opts.splitEntries)\n : false;\n\n const hasResolveRefs = schema.resolveRefs;\n\n if (!hasSplitEntries && !hasResolveRefs) continue;\n\n // Extract split config if available\n let splitConfig: SplitConfig | null = null;\n if (schema.composite) {\n for (const [compositePath, opts] of Object.entries(schema.composite)) {\n if (opts.splitEntries && opts.type === 'array' && opts.key) {\n splitConfig = {\n compositePath,\n jsonPointer: jsonPathToPointer(compositePath),\n keyField: opts.key,\n keyJsonPath: opts.key,\n sourceObjectOptions: opts,\n };\n break;\n }\n }\n }\n\n return { filePath, schema, splitConfig };\n }\n\n return null;\n}\n\n/**\n * Process splitEntries: extract non-default keyed entries into ref files.\n */\nfunction processSplitEntries(\n fileJson: unknown,\n compositeFilePath: string,\n docsDir: string,\n splitConfig: SplitConfig,\n settings: Settings,\n refMap: RefMap | null\n): void {\n const { jsonPointer, keyJsonPath } = splitConfig;\n\n // Find the composite array — may be behind a $ref\n const parentPointer = jsonPointer.split('/').slice(0, -1).join('/') || '';\n const arrayKey = jsonPointer.split('/').pop() || '';\n const navRefEntry = parentPointer ? refMap?.get(parentPointer) : undefined;\n\n // Get the array from the file\n const arrayContainer = parentPointer\n ? getAtPointer(fileJson, parentPointer)\n : fileJson;\n if (!isJsonContainer(arrayContainer)) return;\n\n const entries = Array.isArray(arrayContainer)\n ? arrayContainer[Number(arrayKey)]\n : arrayContainer[arrayKey];\n if (!Array.isArray(entries) || entries.length <= 1) return;\n\n // Determine the default key value (the source entry)\n const defaultKeyValue = getDefaultKeyValue(\n settings.defaultLocale,\n splitConfig.sourceObjectOptions\n );\n\n const defaultIndex = entries.findIndex((e: unknown) => {\n if (!e || typeof e !== 'object') return false;\n const values = JSONPath({\n json: e,\n path: keyJsonPath,\n resultType: 'value',\n flatten: true,\n wrap: true,\n }) as unknown[];\n return values?.[0] === defaultKeyValue;\n });\n if (defaultIndex < 0) return;\n\n // Detect whether each language entry is itself a $ref (per-entry refs), as\n // opposed to the case where the *container* of the languages array is a $ref\n // (navRefEntry). With per-entry refs, the languages array still lives in the\n // composite file, but each entry's content lives in a separate ref file.\n const defaultEntryPointer = `${jsonPointer}/${defaultIndex}`;\n const defaultEntryRef = refMap?.get(defaultEntryPointer);\n\n // arrayHostDir: directory of the file that physically holds the languages\n // array — entry $refs in the array are written relative to this.\n // entryBaseDir: directory under which per-entry ref files (and their nested\n // refs) are written — mirrors the source entry file's location.\n // These coincide for the container-ref and fully-inline cases; they differ\n // only for per-entry refs, where the array lives in the composite file but\n // the entry files live next to the (default) entry's source ref.\n const arrayHostDir = navRefEntry\n ? path.dirname(navRefEntry.sourceFile)\n : docsDir;\n const entryBaseDir = navRefEntry\n ? path.dirname(navRefEntry.sourceFile)\n : defaultEntryRef\n ? path.dirname(defaultEntryRef.sourceFile)\n : docsDir;\n const navFileName = navRefEntry\n ? path.basename(navRefEntry.sourceFile)\n : defaultEntryRef\n ? path.basename(defaultEntryRef.sourceFile)\n : path.basename(compositeFilePath);\n\n // Restore $ref structure if the source used $ref\n if (refMap && refMap.size > 0) {\n const internalRefs = collectInternalRefs(refMap, defaultEntryPointer);\n\n if (internalRefs.length > 0) {\n // When the default entry is itself a $ref, it is restored to that single\n // $ref below and its source file is left untouched, so we must not restore\n // its nested refs in place. Otherwise (inlined default entry) we do.\n if (!defaultEntryRef) {\n const defaultEntry = entries[defaultIndex];\n for (const ref of internalRefs) {\n setAtPointer(defaultEntry, ref.relativePointer, {\n ...ref.siblings,\n $ref: ref.refPath,\n });\n }\n }\n\n // For each non-default entry, write localized copies of the nested ref\n // files (mirroring the source topology under the locale dir) and replace\n // the inlined subtrees with their $refs.\n for (let i = 0; i < entries.length; i++) {\n if (i === defaultIndex) continue;\n const entry = entries[i];\n\n const entryKeyValues = JSONPath({\n json: entry,\n path: keyJsonPath,\n resultType: 'value',\n flatten: true,\n wrap: true,\n }) as unknown[];\n if (entryKeyValues?.[0] === defaultKeyValue) continue;\n const keyValue =\n typeof entryKeyValues?.[0] === 'string'\n ? entryKeyValues[0]\n : 'unknown';\n\n for (const ref of internalRefs) {\n const subtree = getAtPointer(entry, ref.relativePointer);\n if (subtree === undefined) continue;\n\n const originalAbsPath = path.resolve(ref.resolvedDir, ref.refPath);\n const relToBaseDir = path.relative(entryBaseDir, originalAbsPath);\n const localeRelPath = path.join(keyValue, relToBaseDir);\n const outputPath = path.resolve(entryBaseDir, localeRelPath);\n\n const { siblings, content } = extractRefSiblings(subtree, ref);\n writeJsonFile(outputPath, content);\n\n setAtPointer(entry, ref.relativePointer, {\n ...siblings,\n $ref: ref.refPath,\n });\n }\n }\n\n logger.info(`Restored $ref structure for default entry`);\n }\n }\n\n // Get the actual property name from the key JSONPath (e.g., \"$.language\" → \"language\")\n const keyPropertyName = keyJsonPath.replace(/^\\$\\.?/, '');\n\n // Extract each non-default entry into its own ref file\n for (let i = 0; i < entries.length; i++) {\n if (i === defaultIndex) continue;\n const entry = entries[i];\n if (!entry || typeof entry !== 'object') continue;\n\n const keyValues = JSONPath({\n json: entry,\n path: keyJsonPath,\n resultType: 'value',\n flatten: true,\n wrap: true,\n }) as unknown[];\n const keyValue = keyValues?.[0];\n if (typeof keyValue !== 'string' || keyValue === defaultKeyValue) continue;\n\n if (!isJsonContainer(entry) || Array.isArray(entry)) continue;\n const { [keyPropertyName]: _, ...contentWithoutKey } = entry;\n\n // If the entry still carries a top-level $ref, it was never inlined this\n // run (e.g. the merge step didn't process this file). There is no content\n // to extract — writing would produce a self-referential stub that\n // overwrites or shadows the real ref file. Leave the entry untouched.\n if (typeof contentWithoutKey.$ref === 'string') {\n continue;\n }\n\n const entryFilePath = path.resolve(\n entryBaseDir,\n path.join(keyValue, navFileName)\n );\n writeJsonFile(entryFilePath, contentWithoutKey);\n\n entries[i] = {\n [keyPropertyName]: keyValue,\n $ref: toRelativeRefPath(arrayHostDir, entryFilePath),\n };\n }\n\n // When the default entry was itself a $ref, restore it to that single $ref;\n // its source file is the untouched English source already on disk.\n if (defaultEntryRef) {\n entries[defaultIndex] = {\n ...defaultEntryRef.siblings,\n $ref: defaultEntryRef.refPath,\n };\n }\n\n logger.info(`Split keyed entries into ref files`);\n}\n\n/**\n * Get the identifying key value for the default locale.\n */\nfunction getDefaultKeyValue(\n defaultLocale: string,\n sourceObjectOptions: SourceObjectOptions\n): string {\n const localeProperty = sourceObjectOptions.localeProperty || 'code';\n const localeProperties = getLocaleProperties(defaultLocale);\n return (\n (localeProperties as Record<string, string | undefined>)[localeProperty] ||\n localeProperties.code ||\n defaultLocale\n );\n}\n\n/**\n * Convert a JSONPath like \"$.navigation.languages\" to a JSON pointer like \"/navigation/languages\".\n */\nfunction jsonPathToPointer(jsonPath: string): string {\n return jsonPath\n .replace(/^\\$\\.?/, '')\n .split('.')\n .filter(Boolean)\n .map((segment) => `/${segment}`)\n .join('');\n}\n\n/**\n * Restore top-level $ref pointers in the composite file.\n * Sorted deepest-first so nested refs are written before parents.\n */\nfunction restoreTopLevelRefs(\n fileJson: unknown,\n refMap: RefMap,\n splitConfig: SplitConfig | null\n): void {\n // Build a regex to exclude entries inside the composite array\n const arrayPointerPattern = splitConfig\n ? new RegExp(\n `^${splitConfig.jsonPointer.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}\\\\/\\\\d+`\n )\n : null;\n\n const entries = [...refMap.entries()]\n .filter(\n ([pointer]) => !arrayPointerPattern || !arrayPointerPattern.test(pointer)\n )\n .sort(([a], [b]) => b.length - a.length);\n\n for (const [pointer, entry] of entries) {\n const subtree = getAtPointer(fileJson, pointer);\n if (subtree === undefined) continue;\n\n // If the value here is still an unresolved $ref placeholder, the referenced\n // file was never inlined at this pointer (e.g. mergeJson leaves non-composite\n // refs like `redirects` collapsed). Writing it back would overwrite the\n // source file with a self-referential stub and destroy its real contents —\n // the source already holds the correct data, so leave it untouched.\n if (\n isJsonContainer(subtree) &&\n !Array.isArray(subtree) &&\n typeof (subtree as Record<string, unknown>).$ref === 'string'\n ) {\n continue;\n }\n\n const { siblings, content } = extractRefSiblings(subtree, entry);\n writeJsonFile(entry.sourceFile, content);\n setAtPointer(fileJson, pointer, { ...siblings, $ref: entry.refPath });\n }\n}\n\n/**\n * Mintlify merges keys placed next to a `$ref` on top of the referenced file's\n * content, so ref resolution folds them into the inlined subtree. When\n * restoring the `$ref`, lift those keys back out: they stay next to the `$ref`\n * (with their possibly translated values) and are dropped from the content\n * written to the ref file — unless the referenced file also defined the key,\n * in which case it stays in both, preserving the source topology and\n * Mintlify's sibling-precedence semantics.\n */\nfunction extractRefSiblings(\n subtree: unknown,\n ref: {\n siblings?: Record<string, unknown>;\n originalContent?: unknown;\n refPath?: string;\n }\n): { siblings: Record<string, unknown>; content: unknown } {\n const originalSiblings = ref.siblings ?? {};\n const siblingKeys = Object.keys(originalSiblings);\n if (siblingKeys.length === 0) {\n return { siblings: {}, content: subtree };\n }\n if (!isJsonContainer(subtree) || Array.isArray(subtree)) {\n // Non-object content cannot carry merged siblings; restore the originals\n return { siblings: { ...originalSiblings }, content: subtree };\n }\n const content = { ...subtree };\n const siblings: Record<string, unknown> = {};\n const original = ref.originalContent;\n const originalContentHasKey = (key: string) =>\n isJsonContainer(original) && !Array.isArray(original) && key in original;\n for (const key of siblingKeys) {\n if (key in content) {\n siblings[key] = content[key];\n if (!originalContentHasKey(key)) {\n delete content[key];\n }\n } else {\n // Object resolutions always merge siblings into the subtree, so this\n // only fires if that invariant breaks upstream. Restoring the source\n // value keeps the output schema-valid, but it skips translation — warn\n // so the regression is visible.\n logger.warn(\n `Sibling key \"${key}\" missing from translated content for $ref ${ref.refPath ?? '(unknown)'}; restoring source value`\n );\n siblings[key] = originalSiblings[key];\n }\n }\n return { siblings, content };\n}\n\n/**\n * Collect refMap entries that describe an entry's internal $ref chain.\n * Sorted deepest-first so nested content is extracted before parents.\n */\nfunction collectInternalRefs(\n refMap: RefMap,\n entryPointerPrefix: string\n): {\n relativePointer: string;\n refPath: string;\n resolvedDir: string;\n siblings?: Record<string, unknown>;\n originalContent?: unknown;\n}[] {\n const refs: {\n relativePointer: string;\n refPath: string;\n resolvedDir: string;\n siblings?: Record<string, unknown>;\n originalContent?: unknown;\n }[] = [];\n\n for (const [pointer, entry] of refMap.entries()) {\n if (!pointer.startsWith(entryPointerPrefix + '/')) continue;\n refs.push({\n relativePointer: pointer.slice(entryPointerPrefix.length),\n refPath: entry.refPath,\n resolvedDir: entry.containingDir,\n siblings: entry.siblings,\n originalContent: entry.originalContent,\n });\n }\n\n refs.sort((a, b) => b.relativePointer.length - a.relativePointer.length);\n return refs;\n}\n\nfunction writeJsonFile(filePath: string, data: unknown): void {\n const dir = path.dirname(filePath);\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir, { recursive: true });\n }\n fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf-8');\n}\n\n/**\n * Build a relative $ref path (POSIX separators, \"./\"-prefixed when it isn't\n * already a relative or absolute path) from the directory that hosts the\n * languages array to a written entry file.\n */\nfunction toRelativeRefPath(fromDir: string, toPath: string): string {\n const rel = path.relative(fromDir, toPath).split(path.sep).join('/');\n return rel.startsWith('.') || rel.startsWith('/') ? rel : `./${rel}`;\n}\n\nfunction getAtPointer(obj: unknown, pointer: string): unknown {\n if (!pointer || pointer === '/') return obj;\n const parts = pointer.split('/').filter(Boolean);\n let current = obj;\n for (const part of parts) {\n if (!isJsonContainer(current)) return undefined;\n const index = /^\\d+$/.test(part) ? parseInt(part) : part;\n current = Array.isArray(current)\n ? current[index as number]\n : current[index];\n }\n return current;\n}\n\nfunction setAtPointer(obj: unknown, pointer: string, value: unknown): void {\n if (!pointer || pointer === '/') return;\n const parts = pointer.split('/').filter(Boolean);\n let current = obj;\n for (let i = 0; i < parts.length - 1; i++) {\n if (!isJsonContainer(current)) return;\n const index = /^\\d+$/.test(parts[i]) ? parseInt(parts[i]) : parts[i];\n const next = Array.isArray(current)\n ? current[index as number]\n : current[index];\n if (next === undefined) return;\n current = next;\n }\n const lastPart = parts[parts.length - 1];\n const lastIndex = /^\\d+$/.test(lastPart) ? parseInt(lastPart) : lastPart;\n if (!isJsonContainer(current)) return;\n if (Array.isArray(current)) {\n current[lastIndex as number] = value;\n } else {\n current[lastIndex] = value;\n }\n}\n"],"mappings":";;;;;;;;AAYA,SAAS,gBAAgB,OAAwC;AAC/D,QAAO,OAAO,UAAU,YAAY,UAAU;;;;;;;;;;;;;AAchD,eAAsB,0BACpB,UACe;CACf,MAAM,SAAS,iBAAiB;AAEhC,KAAI;EACF,MAAM,oBAAoB,SAAS,OAAO,eAAe;AACzD,MAAI,CAAC,kBAAmB;EAGxB,MAAM,aAAa,eAAe,mBAAmB,SAAS;AAC9D,MAAI,CAAC,WAAY;EAEjB,MAAM,EAAE,UAAU,mBAAmB,gBAAgB;AACrD,MAAI,CAAC,GAAG,WAAW,kBAAkB,CAAE;EAEvC,IAAI;AACJ,MAAI;AACF,cAAW,KAAK,MAAM,GAAG,aAAa,mBAAmB,QAAQ,CAAC;UAC5D;AACN;;EAGF,MAAM,UAAU,KAAK,QAAQ,kBAAkB;AAG/C,MAAI,YACF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../src/utils/splitMintlifyLanguageRefs.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport { logger } from '../console/logger.js';\nimport { stringifyJson } from '../fs/stringifyJson.js';\nimport { Settings, JsonSchema, SourceObjectOptions } from '../types/index.js';\nimport type { RefMap } from './resolveMintlifyRefs.js';\nimport { validateJsonSchema } from '../formats/json/utils.js';\nimport { getStoredRefMap, clearStoredRefMap } from '../state/mintlifyRefMap.js';\nimport { JSONPath } from 'jsonpath-plus';\nimport { getLocaleProperties } from '@generaltranslation/format';\n\ntype JsonContainer = Record<string, unknown> | unknown[];\n\nfunction isJsonContainer(value: unknown): value is JsonContainer {\n return typeof value === 'object' && value !== null;\n}\n\n/**\n * Post-processing step for composite JSON files with splitEntries enabled.\n *\n * After mergeJson writes a fully-inlined composite file, this function:\n * 1. Restores the original $ref structure (if the source used $ref / resolveRefs)\n * 2. Extracts non-default keyed entries into their own ref files\n * to keep the source file compact\n *\n * Driven entirely by the jsonSchema config — reads the composite path,\n * key field, and splitEntries flag from the schema.\n */\nexport async function splitMintlifyLanguageRefs(\n settings: Settings\n): Promise<void> {\n const refMap = getStoredRefMap();\n\n try {\n const resolvedJsonPaths = settings.files?.resolvedPaths?.json;\n if (!resolvedJsonPaths) return;\n\n // Find a JSON file that has splitEntries enabled or resolveRefs\n const targetFile = findTargetFile(resolvedJsonPaths, settings);\n if (!targetFile) return;\n\n const { filePath: compositeFilePath, splitConfig } = targetFile;\n if (!fs.existsSync(compositeFilePath)) return;\n\n let fileContent: string;\n let fileJson: unknown;\n try {\n fileContent = fs.readFileSync(compositeFilePath, 'utf-8');\n fileJson = JSON.parse(fileContent);\n } catch {\n return;\n }\n\n const docsDir = path.dirname(compositeFilePath);\n\n // If splitEntries is configured, process it\n if (splitConfig) {\n processSplitEntries(\n fileJson,\n compositeFilePath,\n docsDir,\n splitConfig,\n settings,\n refMap\n );\n }\n\n // Restore top-level refs if any exist\n if (refMap && refMap.size > 0) {\n restoreTopLevelRefs(fileJson, refMap, splitConfig);\n }\n\n // Always write the composite file back — splitEntries modified the\n // languages array, and restoreTopLevelRefs may not have written it\n // (e.g., when all refs are inside language entries, not top-level)\n fs.writeFileSync(\n compositeFilePath,\n stringifyJson(fileJson, fileContent),\n 'utf-8'\n );\n } finally {\n clearStoredRefMap();\n }\n}\n\ntype SplitConfig = {\n compositePath: string;\n jsonPointer: string;\n keyField: string;\n keyJsonPath: string;\n sourceObjectOptions: SourceObjectOptions;\n};\n\n/**\n * Find the target file and extract split configuration from the schema.\n */\nfunction findTargetFile(\n resolvedPaths: string[],\n settings: Settings\n): {\n filePath: string;\n schema: JsonSchema;\n splitConfig: SplitConfig | null;\n} | null {\n if (!settings.options?.jsonSchema) return null;\n\n for (const filePath of resolvedPaths) {\n const schema = validateJsonSchema(settings.options, filePath);\n if (!schema) continue;\n\n const hasSplitEntries = schema.composite\n ? Object.entries(schema.composite).some(([, opts]) => opts.splitEntries)\n : false;\n\n const hasResolveRefs = schema.resolveRefs;\n\n if (!hasSplitEntries && !hasResolveRefs) continue;\n\n // Extract split config if available\n let splitConfig: SplitConfig | null = null;\n if (schema.composite) {\n for (const [compositePath, opts] of Object.entries(schema.composite)) {\n if (opts.splitEntries && opts.type === 'array' && opts.key) {\n splitConfig = {\n compositePath,\n jsonPointer: jsonPathToPointer(compositePath),\n keyField: opts.key,\n keyJsonPath: opts.key,\n sourceObjectOptions: opts,\n };\n break;\n }\n }\n }\n\n return { filePath, schema, splitConfig };\n }\n\n return null;\n}\n\n/**\n * Process splitEntries: extract non-default keyed entries into ref files.\n */\nfunction processSplitEntries(\n fileJson: unknown,\n compositeFilePath: string,\n docsDir: string,\n splitConfig: SplitConfig,\n settings: Settings,\n refMap: RefMap | null\n): void {\n const { jsonPointer, keyJsonPath } = splitConfig;\n\n // Find the composite array — may be behind a $ref\n const parentPointer = jsonPointer.split('/').slice(0, -1).join('/') || '';\n const arrayKey = jsonPointer.split('/').pop() || '';\n const navRefEntry = parentPointer ? refMap?.get(parentPointer) : undefined;\n\n // Get the array from the file\n const arrayContainer = parentPointer\n ? getAtPointer(fileJson, parentPointer)\n : fileJson;\n if (!isJsonContainer(arrayContainer)) return;\n\n const entries = Array.isArray(arrayContainer)\n ? arrayContainer[Number(arrayKey)]\n : arrayContainer[arrayKey];\n if (!Array.isArray(entries) || entries.length <= 1) return;\n\n // Determine the default key value (the source entry)\n const defaultKeyValue = getDefaultKeyValue(\n settings.defaultLocale,\n splitConfig.sourceObjectOptions\n );\n\n const defaultIndex = entries.findIndex((e: unknown) => {\n if (!e || typeof e !== 'object') return false;\n const values = JSONPath({\n json: e,\n path: keyJsonPath,\n resultType: 'value',\n flatten: true,\n wrap: true,\n }) as unknown[];\n return values?.[0] === defaultKeyValue;\n });\n if (defaultIndex < 0) return;\n\n // Detect whether each language entry is itself a $ref (per-entry refs), as\n // opposed to the case where the *container* of the languages array is a $ref\n // (navRefEntry). With per-entry refs, the languages array still lives in the\n // composite file, but each entry's content lives in a separate ref file.\n const defaultEntryPointer = `${jsonPointer}/${defaultIndex}`;\n const defaultEntryRef = refMap?.get(defaultEntryPointer);\n\n // arrayHostDir: directory of the file that physically holds the languages\n // array — entry $refs in the array are written relative to this.\n // entryBaseDir: directory under which per-entry ref files (and their nested\n // refs) are written — mirrors the source entry file's location.\n // These coincide for the container-ref and fully-inline cases; they differ\n // only for per-entry refs, where the array lives in the composite file but\n // the entry files live next to the (default) entry's source ref.\n const arrayHostDir = navRefEntry\n ? path.dirname(navRefEntry.sourceFile)\n : docsDir;\n const entryBaseDir = navRefEntry\n ? path.dirname(navRefEntry.sourceFile)\n : defaultEntryRef\n ? path.dirname(defaultEntryRef.sourceFile)\n : docsDir;\n const navFileName = navRefEntry\n ? path.basename(navRefEntry.sourceFile)\n : defaultEntryRef\n ? path.basename(defaultEntryRef.sourceFile)\n : path.basename(compositeFilePath);\n\n // Restore $ref structure if the source used $ref\n if (refMap && refMap.size > 0) {\n const internalRefs = collectInternalRefs(refMap, defaultEntryPointer);\n\n if (internalRefs.length > 0) {\n // When the default entry is itself a $ref, it is restored to that single\n // $ref below and its source file is left untouched, so we must not restore\n // its nested refs in place. Otherwise (inlined default entry) we do.\n if (!defaultEntryRef) {\n const defaultEntry = entries[defaultIndex];\n for (const ref of internalRefs) {\n setAtPointer(defaultEntry, ref.relativePointer, {\n ...ref.siblings,\n $ref: ref.refPath,\n });\n }\n }\n\n // For each non-default entry, write localized copies of the nested ref\n // files (mirroring the source topology under the locale dir) and replace\n // the inlined subtrees with their $refs.\n for (let i = 0; i < entries.length; i++) {\n if (i === defaultIndex) continue;\n const entry = entries[i];\n\n const entryKeyValues = JSONPath({\n json: entry,\n path: keyJsonPath,\n resultType: 'value',\n flatten: true,\n wrap: true,\n }) as unknown[];\n if (entryKeyValues?.[0] === defaultKeyValue) continue;\n const keyValue =\n typeof entryKeyValues?.[0] === 'string'\n ? entryKeyValues[0]\n : 'unknown';\n\n for (const ref of internalRefs) {\n const subtree = getAtPointer(entry, ref.relativePointer);\n if (subtree === undefined) continue;\n\n const originalAbsPath = path.resolve(ref.resolvedDir, ref.refPath);\n const relToBaseDir = path.relative(entryBaseDir, originalAbsPath);\n const localeRelPath = path.join(keyValue, relToBaseDir);\n const outputPath = path.resolve(entryBaseDir, localeRelPath);\n\n const { siblings, content } = extractRefSiblings(subtree, ref);\n writeJsonFile(outputPath, content);\n\n setAtPointer(entry, ref.relativePointer, {\n ...siblings,\n $ref: ref.refPath,\n });\n }\n }\n\n logger.info(`Restored $ref structure for default entry`);\n }\n }\n\n // Get the actual property name from the key JSONPath (e.g., \"$.language\" → \"language\")\n const keyPropertyName = keyJsonPath.replace(/^\\$\\.?/, '');\n\n // Extract each non-default entry into its own ref file\n for (let i = 0; i < entries.length; i++) {\n if (i === defaultIndex) continue;\n const entry = entries[i];\n if (!entry || typeof entry !== 'object') continue;\n\n const keyValues = JSONPath({\n json: entry,\n path: keyJsonPath,\n resultType: 'value',\n flatten: true,\n wrap: true,\n }) as unknown[];\n const keyValue = keyValues?.[0];\n if (typeof keyValue !== 'string' || keyValue === defaultKeyValue) continue;\n\n if (!isJsonContainer(entry) || Array.isArray(entry)) continue;\n const { [keyPropertyName]: _, ...contentWithoutKey } = entry;\n\n // If the entry still carries a top-level $ref, it was never inlined this\n // run (e.g. the merge step didn't process this file). There is no content\n // to extract — writing would produce a self-referential stub that\n // overwrites or shadows the real ref file. Leave the entry untouched.\n if (typeof contentWithoutKey.$ref === 'string') {\n continue;\n }\n\n const entryFilePath = path.resolve(\n entryBaseDir,\n path.join(keyValue, navFileName)\n );\n writeJsonFile(entryFilePath, contentWithoutKey);\n\n entries[i] = {\n [keyPropertyName]: keyValue,\n $ref: toRelativeRefPath(arrayHostDir, entryFilePath),\n };\n }\n\n // When the default entry was itself a $ref, restore it to that single $ref;\n // its source file is the untouched English source already on disk.\n if (defaultEntryRef) {\n entries[defaultIndex] = {\n ...defaultEntryRef.siblings,\n $ref: defaultEntryRef.refPath,\n };\n }\n\n logger.info(`Split keyed entries into ref files`);\n}\n\n/**\n * Get the identifying key value for the default locale.\n */\nfunction getDefaultKeyValue(\n defaultLocale: string,\n sourceObjectOptions: SourceObjectOptions\n): string {\n const localeProperty = sourceObjectOptions.localeProperty || 'code';\n const localeProperties = getLocaleProperties(defaultLocale);\n return (\n (localeProperties as Record<string, string | undefined>)[localeProperty] ||\n localeProperties.code ||\n defaultLocale\n );\n}\n\n/**\n * Convert a JSONPath like \"$.navigation.languages\" to a JSON pointer like \"/navigation/languages\".\n */\nfunction jsonPathToPointer(jsonPath: string): string {\n return jsonPath\n .replace(/^\\$\\.?/, '')\n .split('.')\n .filter(Boolean)\n .map((segment) => `/${segment}`)\n .join('');\n}\n\n/**\n * Restore top-level $ref pointers in the composite file.\n * Sorted deepest-first so nested refs are written before parents.\n */\nfunction restoreTopLevelRefs(\n fileJson: unknown,\n refMap: RefMap,\n splitConfig: SplitConfig | null\n): void {\n // Build a regex to exclude entries inside the composite array\n const arrayPointerPattern = splitConfig\n ? new RegExp(\n `^${splitConfig.jsonPointer.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}\\\\/\\\\d+`\n )\n : null;\n\n const entries = [...refMap.entries()]\n .filter(\n ([pointer]) => !arrayPointerPattern || !arrayPointerPattern.test(pointer)\n )\n .sort(([a], [b]) => b.length - a.length);\n\n for (const [pointer, entry] of entries) {\n const subtree = getAtPointer(fileJson, pointer);\n if (subtree === undefined) continue;\n\n // If the value here is still an unresolved $ref placeholder, the referenced\n // file was never inlined at this pointer (e.g. mergeJson leaves non-composite\n // refs like `redirects` collapsed). Writing it back would overwrite the\n // source file with a self-referential stub and destroy its real contents —\n // the source already holds the correct data, so leave it untouched.\n if (\n isJsonContainer(subtree) &&\n !Array.isArray(subtree) &&\n typeof (subtree as Record<string, unknown>).$ref === 'string'\n ) {\n continue;\n }\n\n const { siblings, content } = extractRefSiblings(subtree, entry);\n writeJsonFile(entry.sourceFile, content);\n setAtPointer(fileJson, pointer, { ...siblings, $ref: entry.refPath });\n }\n}\n\n/**\n * Mintlify merges keys placed next to a `$ref` on top of the referenced file's\n * content, so ref resolution folds them into the inlined subtree. When\n * restoring the `$ref`, lift those keys back out: they stay next to the `$ref`\n * (with their possibly translated values) and are dropped from the content\n * written to the ref file — unless the referenced file also defined the key,\n * in which case it stays in both, preserving the source topology and\n * Mintlify's sibling-precedence semantics.\n */\nfunction extractRefSiblings(\n subtree: unknown,\n ref: {\n siblings?: Record<string, unknown>;\n originalContent?: unknown;\n refPath?: string;\n }\n): { siblings: Record<string, unknown>; content: unknown } {\n const originalSiblings = ref.siblings ?? {};\n const siblingKeys = Object.keys(originalSiblings);\n if (siblingKeys.length === 0) {\n return { siblings: {}, content: subtree };\n }\n if (!isJsonContainer(subtree) || Array.isArray(subtree)) {\n // Non-object content cannot carry merged siblings; restore the originals\n return { siblings: { ...originalSiblings }, content: subtree };\n }\n const content = { ...subtree };\n const siblings: Record<string, unknown> = {};\n const original = ref.originalContent;\n const originalContentHasKey = (key: string) =>\n isJsonContainer(original) && !Array.isArray(original) && key in original;\n for (const key of siblingKeys) {\n if (key in content) {\n siblings[key] = content[key];\n if (!originalContentHasKey(key)) {\n delete content[key];\n }\n } else {\n // Object resolutions always merge siblings into the subtree, so this\n // only fires if that invariant breaks upstream. Restoring the source\n // value keeps the output schema-valid, but it skips translation — warn\n // so the regression is visible.\n logger.warn(\n `Sibling key \"${key}\" missing from translated content for $ref ${ref.refPath ?? '(unknown)'}; restoring source value`\n );\n siblings[key] = originalSiblings[key];\n }\n }\n return { siblings, content };\n}\n\n/**\n * Collect refMap entries that describe an entry's internal $ref chain.\n * Sorted deepest-first so nested content is extracted before parents.\n */\nfunction collectInternalRefs(\n refMap: RefMap,\n entryPointerPrefix: string\n): {\n relativePointer: string;\n refPath: string;\n resolvedDir: string;\n siblings?: Record<string, unknown>;\n originalContent?: unknown;\n}[] {\n const refs: {\n relativePointer: string;\n refPath: string;\n resolvedDir: string;\n siblings?: Record<string, unknown>;\n originalContent?: unknown;\n }[] = [];\n\n for (const [pointer, entry] of refMap.entries()) {\n if (!pointer.startsWith(entryPointerPrefix + '/')) continue;\n refs.push({\n relativePointer: pointer.slice(entryPointerPrefix.length),\n refPath: entry.refPath,\n resolvedDir: entry.containingDir,\n siblings: entry.siblings,\n originalContent: entry.originalContent,\n });\n }\n\n refs.sort((a, b) => b.relativePointer.length - a.relativePointer.length);\n return refs;\n}\n\nfunction writeJsonFile(filePath: string, data: unknown): void {\n const dir = path.dirname(filePath);\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir, { recursive: true });\n }\n let original: string | undefined;\n try {\n original = fs.readFileSync(filePath, 'utf-8');\n } catch {\n // New file\n }\n fs.writeFileSync(filePath, stringifyJson(data, original), 'utf-8');\n}\n\n/**\n * Build a relative $ref path (POSIX separators, \"./\"-prefixed when it isn't\n * already a relative or absolute path) from the directory that hosts the\n * languages array to a written entry file.\n */\nfunction toRelativeRefPath(fromDir: string, toPath: string): string {\n const rel = path.relative(fromDir, toPath).split(path.sep).join('/');\n return rel.startsWith('.') || rel.startsWith('/') ? rel : `./${rel}`;\n}\n\nfunction getAtPointer(obj: unknown, pointer: string): unknown {\n if (!pointer || pointer === '/') return obj;\n const parts = pointer.split('/').filter(Boolean);\n let current = obj;\n for (const part of parts) {\n if (!isJsonContainer(current)) return undefined;\n const index = /^\\d+$/.test(part) ? parseInt(part) : part;\n current = Array.isArray(current)\n ? current[index as number]\n : current[index];\n }\n return current;\n}\n\nfunction setAtPointer(obj: unknown, pointer: string, value: unknown): void {\n if (!pointer || pointer === '/') return;\n const parts = pointer.split('/').filter(Boolean);\n let current = obj;\n for (let i = 0; i < parts.length - 1; i++) {\n if (!isJsonContainer(current)) return;\n const index = /^\\d+$/.test(parts[i]) ? parseInt(parts[i]) : parts[i];\n const next = Array.isArray(current)\n ? current[index as number]\n : current[index];\n if (next === undefined) return;\n current = next;\n }\n const lastPart = parts[parts.length - 1];\n const lastIndex = /^\\d+$/.test(lastPart) ? parseInt(lastPart) : lastPart;\n if (!isJsonContainer(current)) return;\n if (Array.isArray(current)) {\n current[lastIndex as number] = value;\n } else {\n current[lastIndex] = value;\n }\n}\n"],"mappings":";;;;;;;;;AAaA,SAAS,gBAAgB,OAAwC;AAC/D,QAAO,OAAO,UAAU,YAAY,UAAU;;;;;;;;;;;;;AAchD,eAAsB,0BACpB,UACe;CACf,MAAM,SAAS,iBAAiB;AAEhC,KAAI;EACF,MAAM,oBAAoB,SAAS,OAAO,eAAe;AACzD,MAAI,CAAC,kBAAmB;EAGxB,MAAM,aAAa,eAAe,mBAAmB,SAAS;AAC9D,MAAI,CAAC,WAAY;EAEjB,MAAM,EAAE,UAAU,mBAAmB,gBAAgB;AACrD,MAAI,CAAC,GAAG,WAAW,kBAAkB,CAAE;EAEvC,IAAI;EACJ,IAAI;AACJ,MAAI;AACF,iBAAc,GAAG,aAAa,mBAAmB,QAAQ;AACzD,cAAW,KAAK,MAAM,YAAY;UAC5B;AACN;;EAGF,MAAM,UAAU,KAAK,QAAQ,kBAAkB;AAG/C,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}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gt",
3
- "version": "2.26.9",
3
+ "version": "2.26.11",
4
4
  "main": "dist/index.js",
5
5
  "bin": "bin/main.js",
6
6
  "files": [
@@ -104,6 +104,7 @@
104
104
  "openid-client": "6.8.8",
105
105
  "package-manager-detector": "^1.8.0",
106
106
  "pino": "^10.1.0",
107
+ "pino-pretty": "^13.2.0",
107
108
  "remark-frontmatter": "^5.0.0",
108
109
  "remark-mdx": "^3.1.0",
109
110
  "remark-parse": "^11.0.0",
@@ -115,12 +116,12 @@
115
116
  "unified": "^11.0.5",
116
117
  "unist-util-visit": "^5.0.0",
117
118
  "yaml": "^2.8.0",
118
- "@generaltranslation/format": "0.1.9",
119
119
  "@generaltranslation/icu": "0.1.2",
120
+ "@generaltranslation/format": "0.1.9",
120
121
  "@generaltranslation/python-extractor": "0.2.63",
121
- "@generaltranslation/supported-locales": "2.1.44",
122
122
  "@generaltranslation/vue-extractor": "0.1.22",
123
123
  "generaltranslation": "9.5.8",
124
+ "@generaltranslation/supported-locales": "2.1.44",
124
125
  "gt-remark": "1.0.12"
125
126
  },
126
127
  "devDependencies": {