gt 2.14.34 → 2.14.35

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 (41) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/config/generateSettings.d.ts +24 -1
  3. package/dist/config/generateSettings.js +3 -2
  4. package/dist/config/resolveConfig.d.ts +1 -1
  5. package/dist/config/validateSettings.js +1 -1
  6. package/dist/formats/files/fileMapping.js +1 -1
  7. package/dist/formats/json/mergeJson.js +1 -1
  8. package/dist/formats/json/utils.js +1 -1
  9. package/dist/formats/utils.d.ts +1 -1
  10. package/dist/fs/config/loadConfig.d.ts +1 -1
  11. package/dist/fs/config/setupConfig.js +5 -1
  12. package/dist/fs/config/updateConfig.js +5 -1
  13. package/dist/fs/loadJSON.d.ts +1 -1
  14. package/dist/fs/saveJSON.d.ts +1 -1
  15. package/dist/generated/version.d.ts +1 -1
  16. package/dist/generated/version.js +1 -1
  17. package/dist/react/config/createESBuildConfig.d.ts +7 -1
  18. package/dist/react/config/createESBuildConfig.js +2 -2
  19. package/dist/react/jsx/utils/getPathsAndAliases.d.ts +2 -1
  20. package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.d.ts +1 -1
  21. package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js +4 -3
  22. package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +5 -1
  23. package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.d.ts +1 -1
  24. package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js +6 -1
  25. package/dist/react/jsx/utils/jsxParsing/parseJsx.js +1 -1
  26. package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.d.ts +1 -1
  27. package/dist/react/jsx/utils/jsxParsing/types.d.ts +2 -2
  28. package/dist/react/jsx/utils/parseAst.js +1 -0
  29. package/dist/react/parse/createDictionaryUpdates.js +14 -13
  30. package/dist/react/utils/getVariableName.d.ts +2 -2
  31. package/dist/react/utils/getVariableName.js +1 -1
  32. package/dist/setup/detectFramework.d.ts +1 -1
  33. package/dist/types/data.d.ts +5 -4
  34. package/dist/types/index.d.ts +2 -1
  35. package/dist/utils/gitDiff.js +3 -2
  36. package/dist/utils/packageJson.d.ts +5 -5
  37. package/dist/utils/packageJson.js +10 -6
  38. package/dist/utils/resolveMintlifyRefs.d.ts +1 -1
  39. package/dist/utils/resolveMintlifyRefs.js +2 -1
  40. package/dist/utils/splitMintlifyLanguageRefs.js +34 -11
  41. package/package.json +4 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.14.35
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1408](https://github.com/generaltranslation/gt/pull/1408) [`425d3e4`](https://github.com/generaltranslation/gt/commit/425d3e4e6c61afd108c65c27f7693ba2470b33c6) Thanks [@bgub](https://github.com/bgub)! - Use @generaltranslation/format directly for shared formatting and locale helpers.
8
+
9
+ - Updated dependencies [[`73f3ac1`](https://github.com/generaltranslation/gt/commit/73f3ac1308df11c1e6230c13c1999bfc5f6afc99), [`425d3e4`](https://github.com/generaltranslation/gt/commit/425d3e4e6c61afd108c65c27f7693ba2470b33c6)]:
10
+ - @generaltranslation/format@0.1.0
11
+ - generaltranslation@8.2.14
12
+ - @generaltranslation/python-extractor@0.2.20
13
+
3
14
  ## 2.14.34
4
15
 
5
16
  ### Patch Changes
@@ -2,6 +2,28 @@ import { Settings } from '../types/index.js';
2
2
  export declare const DEFAULT_SRC_PATTERNS: string[];
3
3
  export declare const DEFAULT_PYTHON_SRC_PATTERNS: string[];
4
4
  export declare const DEFAULT_PYTHON_SRC_EXCLUDES: string[];
5
+ type GenerateSettingsInput = Partial<Omit<Settings, 'tag'>> & {
6
+ config?: string;
7
+ projectId?: string;
8
+ locales?: string[];
9
+ options?: Settings['options'];
10
+ files?: unknown;
11
+ publish?: boolean;
12
+ tag?: string | boolean;
13
+ message?: string;
14
+ branch?: string;
15
+ enableBranching?: boolean;
16
+ disableBranchDetection?: boolean;
17
+ remoteName?: string;
18
+ experimentalLocalizeStaticImports?: boolean;
19
+ experimentalLocalizeStaticUrls?: boolean;
20
+ experimentalLocalizeRelativeAssets?: boolean;
21
+ experimentalHideDefaultLocale?: boolean;
22
+ experimentalFlattenJsonFiles?: boolean;
23
+ experimentalClearLocaleDirs?: boolean;
24
+ clearLocaleDirsExclude?: string[];
25
+ [key: string]: unknown;
26
+ };
5
27
  /**
6
28
  * Generates settings from any
7
29
  * @param flags - The CLI flags to generate settings from
@@ -10,6 +32,7 @@ export declare const DEFAULT_PYTHON_SRC_EXCLUDES: string[];
10
32
  * @param options.requireConfig - If true, exit with an error when no config file is found
11
33
  * @returns The generated settings
12
34
  */
13
- export declare function generateSettings(flags: Record<string, any>, cwd?: string, options?: {
35
+ export declare function generateSettings(flags: GenerateSettingsInput, cwd?: string, options?: {
14
36
  requireConfig?: boolean;
15
37
  }): Promise<Settings>;
38
+ export {};
@@ -62,7 +62,7 @@ export async function generateSettings(flags, cwd = process.cwd(), options) {
62
62
  }
63
63
  // Warn if apiKey is present in gt.config.json
64
64
  if (gtConfig.apiKey) {
65
- warnApiKeyInConfig(flags.config);
65
+ warnApiKeyInConfig(flags.config ?? 'gt.config.json');
66
66
  exitSync(1);
67
67
  }
68
68
  const projectIdEnv = resolveProjectId();
@@ -93,7 +93,8 @@ export async function generateSettings(flags, cwd = process.cwd(), options) {
93
93
  }
94
94
  }
95
95
  // Warn on deprecated includeSourceCodeContext
96
- if (gtConfig.files?.gt?.includeSourceCodeContext != null) {
96
+ const configuredFiles = gtConfig.files;
97
+ if (configuredFiles?.gt?.includeSourceCodeContext != null) {
97
98
  warnDeprecatedField('files.gt.includeSourceCodeContext', 'files.gt.parsingFlags.includeSourceCodeContext');
98
99
  }
99
100
  // merge options
@@ -1,4 +1,4 @@
1
1
  export declare function resolveConfig(cwd: string): {
2
2
  path: string;
3
- config: Record<string, any>;
3
+ config: Record<string, unknown>;
4
4
  } | null;
@@ -1,4 +1,4 @@
1
- import { isValidLocale, isSupersetLocale } from 'generaltranslation';
1
+ import { isValidLocale, isSupersetLocale } from '@generaltranslation/format';
2
2
  import { logErrorAndExit } from '../console/logging.js';
3
3
  import fs from 'node:fs';
4
4
  import path from 'node:path';
@@ -2,7 +2,7 @@ import { SUPPORTED_FILE_EXTENSIONS } from '../files/supportedFiles.js';
2
2
  import { resolveLocaleFiles } from '../../fs/config/parseFilesConfig.js';
3
3
  import path from 'node:path';
4
4
  import { getRelative } from '../../fs/findFilepath.js';
5
- import { getLocaleProperties } from 'generaltranslation';
5
+ import { getLocaleProperties } from '@generaltranslation/format';
6
6
  import { replaceLocalePlaceholders } from '../utils.js';
7
7
  import { TEMPLATE_FILE_NAME } from '../../utils/constants.js';
8
8
  import { replaceFileExtensionForFormat } from './transformFormat.js';
@@ -1,7 +1,7 @@
1
1
  import { exitSync } from '../../console/logging.js';
2
2
  import { logger } from '../../console/logger.js';
3
3
  import { findMatchingItemArray, findMatchingItemObject, generateSourceObjectPointers, getIdentifyingLocaleProperty, getSourceObjectOptionsArray, validateJsonSchema, } from './utils.js';
4
- import { getLocaleProperties } from 'generaltranslation';
4
+ import { getLocaleProperties } from '@generaltranslation/format';
5
5
  import { replaceLocalePlaceholders } from '../utils.js';
6
6
  import { gt } from '../../utils/gt.js';
7
7
  import { applyStructuralTransforms, unapplyStructuralTransforms, } from './transformJson.js';
@@ -1,4 +1,4 @@
1
- import { getLocaleProperties } from 'generaltranslation';
1
+ import { getLocaleProperties } from '@generaltranslation/format';
2
2
  import { exitSync } from '../../console/logging.js';
3
3
  import { logger } from '../../console/logger.js';
4
4
  import { flattenJson } from './flattenJson.js';
@@ -1,2 +1,2 @@
1
- import { LocaleProperties } from 'generaltranslation/types';
1
+ import type { LocaleProperties } from '@generaltranslation/format/types';
2
2
  export declare function replaceLocalePlaceholders(string: string, localeProperties: LocaleProperties): string;
@@ -1 +1 @@
1
- export declare function loadConfig(filepath: string): Record<string, any>;
1
+ export declare function loadConfig(filepath: string): Record<string, unknown>;
@@ -23,7 +23,11 @@ export async function createOrUpdateConfig(configFilepath, options) {
23
23
  // if file exists
24
24
  let oldContent = {};
25
25
  if (fs.existsSync(configFilepath)) {
26
- oldContent = JSON.parse(await fs.promises.readFile(configFilepath, 'utf-8'));
26
+ const parsed = JSON.parse(await fs.promises.readFile(configFilepath, 'utf-8'));
27
+ oldContent =
28
+ typeof parsed === 'object' && parsed !== null
29
+ ? parsed
30
+ : {};
27
31
  }
28
32
  // merge old and new content
29
33
  const mergedContent = {
@@ -23,7 +23,11 @@ export default async function updateConfig(configFilepath, options) {
23
23
  // if file exists
24
24
  let oldContent = {};
25
25
  if (fs.existsSync(configFilepath)) {
26
- oldContent = JSON.parse(await fs.promises.readFile(configFilepath, 'utf-8'));
26
+ const parsed = JSON.parse(await fs.promises.readFile(configFilepath, 'utf-8'));
27
+ oldContent =
28
+ typeof parsed === 'object' && parsed !== null
29
+ ? parsed
30
+ : {};
27
31
  }
28
32
  // merge old and new content
29
33
  const mergedContent = {
@@ -3,4 +3,4 @@
3
3
  * @param {string} filepath - The path to the JSON file.
4
4
  * @returns {Record<string, any> | null} - The parsed JSON object or null if an error occurs.
5
5
  */
6
- export default function loadJSON(filepath: string): Record<string, any> | null;
6
+ export default function loadJSON(filepath: string): Record<string, unknown> | null;
@@ -1 +1 @@
1
- export declare function saveJSON(filepath: string, data: Record<string, any>): Promise<void>;
1
+ export declare function saveJSON(filepath: string, data: Record<string, unknown>): Promise<void>;
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "2.14.34";
1
+ export declare const PACKAGE_VERSION = "2.14.35";
@@ -1,2 +1,2 @@
1
1
  // This file is auto-generated. Do not edit manually.
2
- export const PACKAGE_VERSION = '2.14.34';
2
+ export const PACKAGE_VERSION = '2.14.35';
@@ -1,2 +1,8 @@
1
1
  import esbuild from 'esbuild';
2
- export default function createESBuildConfig(config?: Record<string, any>): esbuild.BuildOptions;
2
+ type TSConfig = {
3
+ compilerOptions?: {
4
+ paths?: Record<string, string[]>;
5
+ };
6
+ };
7
+ export default function createESBuildConfig(config?: TSConfig): esbuild.BuildOptions;
8
+ export {};
@@ -20,7 +20,7 @@ export default function createESBuildConfig(config = {}) {
20
20
  plugins: [],
21
21
  };
22
22
  // Add the custom plugin to handle 'server-only' imports
23
- esbuildOptions.plugins.push({
23
+ esbuildOptions.plugins?.push({
24
24
  name: 'ignore-server-only',
25
25
  setup(build) {
26
26
  build.onResolve({ filter: /^server-only$/ }, () => {
@@ -38,7 +38,7 @@ export default function createESBuildConfig(config = {}) {
38
38
  },
39
39
  });
40
40
  // Add a plugin to handle CSS imports
41
- esbuildOptions.plugins.push({
41
+ esbuildOptions.plugins?.push({
42
42
  name: 'css-module',
43
43
  setup(build) {
44
44
  build.onResolve({ filter: /\.css$/ }, (args) => {
@@ -1,12 +1,13 @@
1
1
  import { NodePath } from '@babel/traverse';
2
2
  import { GTLibrary } from '../../../types/libraries.js';
3
+ import * as t from '@babel/types';
3
4
  /**
4
5
  * Constructs tracking for gt related variables of interest
5
6
  * inlineTranslationPaths: these are string-related translation functions
6
7
  * translationComponentPaths: these are just <T> components
7
8
  * importAliases: any other GT related imports
8
9
  */
9
- export declare function getPathsAndAliases(ast: any, pkgs: GTLibrary[]): {
10
+ export declare function getPathsAndAliases(ast: t.Node, pkgs: GTLibrary[]): {
10
11
  importAliases: Record<string, string>;
11
12
  inlineTranslationPaths: Array<{
12
13
  localName: string;
@@ -1,4 +1,4 @@
1
- import { JsxChildren } from 'generaltranslation/types';
1
+ import { JsxChildren } from '@generaltranslation/format/types';
2
2
  import { MultipliedTreeNode } from './types.js';
3
3
  /**
4
4
  * Add GT Identifier and minify the tree (recreates addGTIdentifier and writeChildrenAsObjects)
@@ -1,4 +1,4 @@
1
- import { HTML_CONTENT_PROPS, } from 'generaltranslation/types';
1
+ import { HTML_CONTENT_PROPS, } from '@generaltranslation/format/types';
2
2
  import { defaultVariableNames, getVariableName, minifyVariableType, } from '../../../utils/getVariableName.js';
3
3
  import { isAcceptedPluralForm } from 'generaltranslation/internal';
4
4
  import { DATA_ATTR_PREFIX, BRANCH_COMPONENT, PLURAL_COMPONENT, } from '../constants.js';
@@ -12,8 +12,9 @@ import { DATA_ATTR_PREFIX, BRANCH_COMPONENT, PLURAL_COMPONENT, } from '../consta
12
12
  function constructGTProp(type, props, id) {
13
13
  // Add translatable HTML content props
14
14
  const generaltranslation = Object.entries(HTML_CONTENT_PROPS).reduce((acc, [minifiedName, fullName]) => {
15
- if (props[fullName]) {
16
- acc[minifiedName] = props[fullName];
15
+ const value = props[fullName];
16
+ if (typeof value === 'string') {
17
+ acc[minifiedName] = value;
17
18
  }
18
19
  return acc;
19
20
  }, {});
@@ -162,7 +162,11 @@ export function handleChildrenWhitespace(currentTree, parentNodeType = undefined
162
162
  if (!shouldProcess) {
163
163
  return [key, value];
164
164
  }
165
- return [key, handleChildrenWhitespace(value)];
165
+ const processChild = handleChildrenWhitespace;
166
+ return [
167
+ key,
168
+ processChild(value),
169
+ ];
166
170
  }));
167
171
  return {
168
172
  nodeType: 'element',
@@ -1,6 +1,6 @@
1
1
  import { WhitespaceJsxTreeResult, WhitespaceMultiplicationNode } from '../types.js';
2
2
  export type MultiplicationNodeResult = {
3
- parent: any | undefined;
3
+ parent: Record<string, unknown> | unknown[] | undefined;
4
4
  key: string | undefined;
5
5
  node: WhitespaceMultiplicationNode;
6
6
  };
@@ -57,7 +57,12 @@ function multiplyBranches(branches) {
57
57
  }
58
58
  else {
59
59
  // Replace the multiplication node with the sub branch
60
- parent[key] = subBranch;
60
+ if (Array.isArray(parent)) {
61
+ parent[Number(key)] = subBranch;
62
+ }
63
+ else {
64
+ parent[key] = subBranch;
65
+ }
61
66
  newBranch = structuredClone(branch);
62
67
  // Add the new branch to the list
63
68
  branchQueue.push(newBranch);
@@ -10,7 +10,7 @@ import { warnHasUnwrappedExpressionSync, warnNestedTComponent, warnFunctionNotFo
10
10
  import { isAcceptedPluralForm } from 'generaltranslation/internal';
11
11
  import { isStaticExpression } from '../../evaluateJsx.js';
12
12
  import { DATA_ATTR_PREFIX, STATIC_COMPONENT, DERIVE_COMPONENT, TRANSLATION_COMPONENT, INTERNAL_TRANSLATION_COMPONENT, VARIABLE_COMPONENTS, } from '../constants.js';
13
- import { HTML_CONTENT_PROPS } from 'generaltranslation/types';
13
+ import { HTML_CONTENT_PROPS, } from '@generaltranslation/format/types';
14
14
  import { resolveImportPath } from '../resolveImportPath.js';
15
15
  import traverseModule from '@babel/traverse';
16
16
  import { buildImportMap } from '../buildImportMap.js';
@@ -1,2 +1,2 @@
1
- import { JsxChildren } from 'generaltranslation/types';
1
+ import type { JsxChildren } from '@generaltranslation/format/types';
2
2
  export declare function removeNullChildrenFields(tree: JsxChildren): JsxChildren;
@@ -11,7 +11,7 @@ type ElementNode = {
11
11
  type: string;
12
12
  props?: {
13
13
  children?: JsxTree | MultiplicationNode | (JsxTree | MultiplicationNode)[];
14
- [key: string]: any;
14
+ [key: string]: unknown;
15
15
  };
16
16
  };
17
17
  type JsxTree = ElementNode | ExpressionNode | string | number | boolean | null;
@@ -29,7 +29,7 @@ type WhitespaceJsxTree = {
29
29
  type: string;
30
30
  props?: {
31
31
  children?: (WhitespaceJsxTreeResult | WhitespaceMultiplicationNode)[];
32
- [key: string]: any;
32
+ [key: string]: unknown;
33
33
  };
34
34
  };
35
35
  type WhitespaceJsxTreeResult = WhitespaceJsxTree | string | number | boolean | null;
@@ -248,6 +248,7 @@ export function extractImportName(node, pkgs, translationFuncs) {
248
248
  for (let i = 0; i < parentBody.length; i++) {
249
249
  const stmt = parentBody[i];
250
250
  if (stmt.type === 'VariableDeclaration' &&
251
+ stmt.declarations[0]?.id.type === 'Identifier' &&
251
252
  stmt.declarations[0]?.init?.type === 'MemberExpression' &&
252
253
  stmt.declarations[0].init.object.type === 'Identifier' &&
253
254
  stmt.declarations[0].init.object.name === requireVarName &&
@@ -12,10 +12,10 @@ import { isValidIcu } from '../jsx/evaluateJsx.js';
12
12
  import { warnInvalidIcuSync, warnInvalidMaxCharsSync, } from '../../console/index.js';
13
13
  import { exitSync } from '../../console/logging.js';
14
14
  export async function createDictionaryUpdates(dictionaryPath, errors, warnings, esbuildConfig) {
15
- let dictionary;
15
+ let dictionary = {};
16
16
  // ---- HANDLE JSON STRING DICTIONARY ----- //
17
17
  if (dictionaryPath.endsWith('.json')) {
18
- dictionary = flattenDictionary(loadJSON(dictionaryPath) || {});
18
+ dictionary = flattenDictionary((loadJSON(dictionaryPath) || {}));
19
19
  }
20
20
  // ----- HANDLE REACT DICTIONARY ---- //
21
21
  else {
@@ -88,24 +88,25 @@ function unwrapDictionaryModule(mod) {
88
88
  let current = mod;
89
89
  // Keep unwrapping until we get to the actual dictionary
90
90
  while (current && typeof current === 'object') {
91
- const keys = Object.keys(current);
91
+ const currentObject = current;
92
+ const keys = Object.keys(currentObject);
92
93
  // Check if this looks like a module namespace object (has only module-related keys)
93
94
  const isModuleNamespace = keys.every((key) => key === 'default' || key === 'module.exports' || key === '__esModule');
94
95
  // Check if this is a module with named exports (has 'dictionary' export)
95
96
  // Only check for named exports if it's NOT a pure module namespace
96
97
  const hasNamedDictionary = !isModuleNamespace &&
97
- 'dictionary' in current &&
98
- current.dictionary &&
99
- typeof current.dictionary === 'object' &&
100
- !Array.isArray(current.dictionary);
98
+ 'dictionary' in currentObject &&
99
+ currentObject.dictionary &&
100
+ typeof currentObject.dictionary === 'object' &&
101
+ !Array.isArray(currentObject.dictionary);
101
102
  if (hasNamedDictionary) {
102
103
  // If there's a named 'dictionary' export, use that
103
- return current.dictionary;
104
+ return currentObject.dictionary;
104
105
  }
105
106
  else if (isModuleNamespace) {
106
107
  // Try to get the default export
107
- if ('default' in current) {
108
- let result = current.default;
108
+ if ('default' in currentObject) {
109
+ let result = currentObject.default;
109
110
  // If the default export is a function (getter), call it
110
111
  if (typeof result === 'function') {
111
112
  try {
@@ -141,8 +142,8 @@ function unwrapDictionaryModule(mod) {
141
142
  }
142
143
  }
143
144
  // Try module.exports as fallback
144
- if ('module.exports' in current) {
145
- let result = current['module.exports'];
145
+ if ('module.exports' in currentObject) {
146
+ let result = currentObject['module.exports'];
146
147
  if (typeof result === 'function') {
147
148
  try {
148
149
  result = result();
@@ -183,5 +184,5 @@ function unwrapDictionaryModule(mod) {
183
184
  break;
184
185
  }
185
186
  }
186
- return current || {};
187
+ return (current || {});
187
188
  }
@@ -1,4 +1,4 @@
1
- import { VariableType } from 'generaltranslation/types';
1
+ import type { VariableType } from '@generaltranslation/format/types';
2
2
  /**
3
3
  * These are the names of the variable components as they appear in gt-next and gt-react
4
4
  */
@@ -24,4 +24,4 @@ export declare const baseVariablePrefix = "_gt_";
24
24
  * @param id - The id of the variable
25
25
  * @returns The name of the variable
26
26
  */
27
- export declare function getVariableName(props: Record<string, any> | undefined, variableType: keyof typeof defaultVariableNames, id: number): string;
27
+ export declare function getVariableName(props: Record<string, unknown> | undefined, variableType: keyof typeof defaultVariableNames, id: number): string;
@@ -34,7 +34,7 @@ export const baseVariablePrefix = '_gt_';
34
34
  * @returns The name of the variable
35
35
  */
36
36
  export function getVariableName(props = {}, variableType, id) {
37
- if (props.name)
37
+ if (typeof props.name === 'string')
38
38
  return props.name;
39
39
  const baseVariableName = defaultVariableNames[variableType] || 'value';
40
40
  return `${baseVariablePrefix}${baseVariableName}_${id}`;
@@ -28,4 +28,4 @@ export declare function detectFramework(): Promise<FrameworkObject | {
28
28
  * but kept for API consistency with other detection functions)
29
29
  * @returns True if the project is identified as a Mintlify project, false otherwise
30
30
  */
31
- export declare function isMintlifyProject(_packageJson: Record<string, any> | null): boolean;
31
+ export declare function isMintlifyProject(_packageJson: Record<string, unknown> | null): boolean;
@@ -8,8 +8,8 @@ export type DictionaryMetadata = {
8
8
  /** @deprecated use $maxChars instead */
9
9
  maxChars?: number;
10
10
  /** @deprecated */
11
- variablesOptions?: Record<string, any>;
12
- [key: string]: any;
11
+ variablesOptions?: Record<string, unknown>;
12
+ [key: string]: unknown;
13
13
  };
14
14
  export type DictionaryEntry = Entry | [Entry] | [Entry, DictionaryMetadata];
15
15
  export type Dictionary = {
@@ -24,8 +24,9 @@ export type JSONDictionary = {
24
24
  export type FlattenedJSONDictionary = {
25
25
  [key: string]: string;
26
26
  };
27
- export type { FileFormat, DataFormat, FileToUpload, } from 'generaltranslation/types';
28
- export type JsxChildren = string | string[] | any;
27
+ export type { DataFormat } from '@generaltranslation/format/types';
28
+ export type { FileFormat, FileToUpload } from 'generaltranslation/types';
29
+ export type JsxChildren = string | string[] | unknown;
29
30
  export type Translations = {
30
31
  [key: string]: JsxChildren;
31
32
  };
@@ -1,4 +1,5 @@
1
- import { CustomMapping, FileFormat } from 'generaltranslation/types';
1
+ import type { CustomMapping } from '@generaltranslation/format/types';
2
+ import type { FileFormat } from 'generaltranslation/types';
2
3
  import { SUPPORTED_FILE_EXTENSIONS } from '../formats/files/supportedFiles.js';
3
4
  import { ParsingConfigOptions, GTParsingFlags, BaseParsingFlags, ParseFlagsByFileType } from './parsing.js';
4
5
  import { Libraries, InlineLibrary } from './libraries.js';
@@ -26,8 +26,9 @@ export async function getGitUnifiedDiff(oldPath, newPath) {
26
26
  }
27
27
  catch (error) {
28
28
  // Exit code 1 means differences found; stdout contains the diff
29
- if (error && error.code === 1 && typeof error.stdout === 'string') {
30
- return error.stdout;
29
+ const execError = error;
30
+ if (execError.code === 1 && typeof execError.stdout === 'string') {
31
+ return execError.stdout;
31
32
  }
32
33
  throw error;
33
34
  }
@@ -1,6 +1,6 @@
1
- export declare function searchForPackageJson(cwd?: string): Promise<Record<string, any> | null>;
2
- export declare function getPackageJson(cwd?: string): Promise<Record<string, any> | null>;
1
+ export declare function searchForPackageJson(cwd?: string): Promise<Record<string, unknown> | null>;
2
+ export declare function getPackageJson(cwd?: string): Promise<Record<string, unknown> | null>;
3
3
  export declare function getCLIVersion(): string;
4
- export declare function updatePackageJson(packageJson: Record<string, any>, cwd?: string): Promise<void>;
5
- export declare function isPackageInstalled(packageName: string, packageJson: Record<string, any>, asDevDependency?: boolean, checkBoth?: boolean): boolean;
6
- export declare function getPackageVersion(packageName: string, packageJson: Record<string, any>): string | undefined;
4
+ export declare function updatePackageJson(packageJson: Record<string, unknown>, cwd?: string): Promise<void>;
5
+ export declare function isPackageInstalled(packageName: string, packageJson: Record<string, unknown>, asDevDependency?: boolean, checkBoth?: boolean): boolean;
6
+ export declare function getPackageVersion(packageName: string, packageJson: Record<string, unknown>): string | undefined;
@@ -46,23 +46,27 @@ export async function updatePackageJson(packageJson, cwd = process.cwd()) {
46
46
  }
47
47
  // check if a package is installed in the package.json file
48
48
  export function isPackageInstalled(packageName, packageJson, asDevDependency = false, checkBoth = false) {
49
+ const devDependencies = packageJson.devDependencies ?? {};
50
+ const prodDependencies = packageJson.dependencies ?? {};
49
51
  const dependencies = checkBoth
50
52
  ? {
51
- ...packageJson.devDependencies,
52
- ...packageJson.dependencies,
53
+ ...devDependencies,
54
+ ...prodDependencies,
53
55
  }
54
56
  : asDevDependency
55
- ? packageJson.devDependencies
56
- : packageJson.dependencies;
57
+ ? devDependencies
58
+ : prodDependencies;
57
59
  if (!dependencies) {
58
60
  return false;
59
61
  }
60
62
  return dependencies[packageName] !== undefined;
61
63
  }
62
64
  export function getPackageVersion(packageName, packageJson) {
65
+ const devDependencies = packageJson.devDependencies ?? {};
66
+ const prodDependencies = packageJson.dependencies ?? {};
63
67
  const dependencies = {
64
- ...packageJson.dependencies,
65
- ...packageJson.devDependencies,
68
+ ...prodDependencies,
69
+ ...devDependencies,
66
70
  };
67
71
  return dependencies[packageName] ?? undefined;
68
72
  }
@@ -22,5 +22,5 @@ export declare function resolveMintlifyRefs(json: unknown, filePath: string): Re
22
22
  * Returns true if the file matches a jsonSchema entry with resolveRefs: true.
23
23
  */
24
24
  export declare function shouldResolveRefs(filePath: string, options?: {
25
- jsonSchema?: Record<string, any>;
25
+ jsonSchema?: Record<string, unknown>;
26
26
  }): boolean;
@@ -99,7 +99,8 @@ export function shouldResolveRefs(filePath, options) {
99
99
  return false;
100
100
  const relative = path.relative(process.cwd(), filePath);
101
101
  for (const [glob, schema] of Object.entries(options.jsonSchema)) {
102
- if (schema?.resolveRefs && micromatch.isMatch(relative, glob)) {
102
+ const jsonSchema = schema;
103
+ if (jsonSchema.resolveRefs && micromatch.isMatch(relative, glob)) {
103
104
  return true;
104
105
  }
105
106
  }
@@ -4,7 +4,10 @@ import { logger } from '../console/logger.js';
4
4
  import { validateJsonSchema } from '../formats/json/utils.js';
5
5
  import { getStoredRefMap, clearStoredRefMap } from '../state/mintlifyRefMap.js';
6
6
  import { JSONPath } from 'jsonpath-plus';
7
- import { getLocaleProperties } from 'generaltranslation';
7
+ import { getLocaleProperties } from '@generaltranslation/format';
8
+ function isJsonContainer(value) {
9
+ return typeof value === 'object' && value !== null;
10
+ }
8
11
  /**
9
12
  * Post-processing step for composite JSON files with splitEntries enabled.
10
13
  *
@@ -98,14 +101,16 @@ function processSplitEntries(fileJson, compositeFilePath, docsDir, splitConfig,
98
101
  // Find the composite array — may be behind a $ref
99
102
  const parentPointer = jsonPointer.split('/').slice(0, -1).join('/') || '';
100
103
  const arrayKey = jsonPointer.split('/').pop() || '';
101
- const navRefEntry = refMap?.get(parentPointer || undefined);
104
+ const navRefEntry = parentPointer ? refMap?.get(parentPointer) : undefined;
102
105
  // Get the array from the file
103
106
  const arrayContainer = parentPointer
104
107
  ? getAtPointer(fileJson, parentPointer)
105
108
  : fileJson;
106
- if (!arrayContainer)
109
+ if (!isJsonContainer(arrayContainer))
107
110
  return;
108
- const entries = arrayContainer[arrayKey];
111
+ const entries = Array.isArray(arrayContainer)
112
+ ? arrayContainer[Number(arrayKey)]
113
+ : arrayContainer[arrayKey];
109
114
  if (!Array.isArray(entries) || entries.length <= 1)
110
115
  return;
111
116
  // Determine the default key value (the source entry)
@@ -153,7 +158,9 @@ function processSplitEntries(fileJson, compositeFilePath, docsDir, splitConfig,
153
158
  continue;
154
159
  const originalAbsPath = path.resolve(ref.resolvedDir, ref.refPath);
155
160
  const relToNavDir = path.relative(navDir, originalAbsPath);
156
- const keyValue = entryKeyValues?.[0] || 'unknown';
161
+ const keyValue = typeof entryKeyValues?.[0] === 'string'
162
+ ? entryKeyValues[0]
163
+ : 'unknown';
157
164
  const localeRelPath = path.join(keyValue, relToNavDir);
158
165
  const outputPath = path.resolve(navDir, localeRelPath);
159
166
  writeJsonFile(outputPath, subtree);
@@ -181,7 +188,9 @@ function processSplitEntries(fileJson, compositeFilePath, docsDir, splitConfig,
181
188
  wrap: true,
182
189
  });
183
190
  const keyValue = keyValues?.[0];
184
- if (!keyValue || keyValue === defaultKeyValue)
191
+ if (typeof keyValue !== 'string' || keyValue === defaultKeyValue)
192
+ continue;
193
+ if (!isJsonContainer(entry) || Array.isArray(entry))
185
194
  continue;
186
195
  const { [keyPropertyName]: _, ...contentWithoutKey } = entry;
187
196
  const entryFileName = `${keyValue}/${navFileName}`;
@@ -263,10 +272,12 @@ function getAtPointer(obj, pointer) {
263
272
  const parts = pointer.split('/').filter(Boolean);
264
273
  let current = obj;
265
274
  for (const part of parts) {
266
- if (current === null || current === undefined)
275
+ if (!isJsonContainer(current))
267
276
  return undefined;
268
277
  const index = /^\d+$/.test(part) ? parseInt(part) : part;
269
- current = current[index];
278
+ current = Array.isArray(current)
279
+ ? current[index]
280
+ : current[index];
270
281
  }
271
282
  return current;
272
283
  }
@@ -276,12 +287,24 @@ function setAtPointer(obj, pointer, value) {
276
287
  const parts = pointer.split('/').filter(Boolean);
277
288
  let current = obj;
278
289
  for (let i = 0; i < parts.length - 1; i++) {
290
+ if (!isJsonContainer(current))
291
+ return;
279
292
  const index = /^\d+$/.test(parts[i]) ? parseInt(parts[i]) : parts[i];
280
- if (current[index] === undefined)
293
+ const next = Array.isArray(current)
294
+ ? current[index]
295
+ : current[index];
296
+ if (next === undefined)
281
297
  return;
282
- current = current[index];
298
+ current = next;
283
299
  }
284
300
  const lastPart = parts[parts.length - 1];
285
301
  const lastIndex = /^\d+$/.test(lastPart) ? parseInt(lastPart) : lastPart;
286
- current[lastIndex] = value;
302
+ if (!isJsonContainer(current))
303
+ return;
304
+ if (Array.isArray(current)) {
305
+ current[lastIndex] = value;
306
+ }
307
+ else {
308
+ current[lastIndex] = value;
309
+ }
287
310
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gt",
3
- "version": "2.14.34",
3
+ "version": "2.14.35",
4
4
  "main": "dist/index.js",
5
5
  "bin": "bin/main.js",
6
6
  "files": [
@@ -111,8 +111,9 @@
111
111
  "unified": "^11.0.5",
112
112
  "unist-util-visit": "^5.0.0",
113
113
  "yaml": "^2.8.0",
114
- "@generaltranslation/python-extractor": "0.2.19",
115
- "generaltranslation": "8.2.13",
114
+ "@generaltranslation/format": "0.1.0",
115
+ "@generaltranslation/python-extractor": "0.2.20",
116
+ "generaltranslation": "8.2.14",
116
117
  "gt-remark": "1.0.7"
117
118
  },
118
119
  "devDependencies": {