gt 2.27.3 → 2.28.1

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 +20 -0
  2. package/dist/api/collectUserEditDiffs.js +77 -2
  3. package/dist/api/collectUserEditDiffs.js.map +1 -1
  4. package/dist/cli/base.d.ts +2 -0
  5. package/dist/cli/base.js +9 -5
  6. package/dist/cli/base.js.map +1 -1
  7. package/dist/cli/commands/setupProject.js +2 -0
  8. package/dist/cli/commands/setupProject.js.map +1 -1
  9. package/dist/cli/commands/stage.js +2 -0
  10. package/dist/cli/commands/stage.js.map +1 -1
  11. package/dist/cli/commands/upload.js +2 -0
  12. package/dist/cli/commands/upload.js.map +1 -1
  13. package/dist/generated/version.d.ts +1 -1
  14. package/dist/generated/version.js +1 -1
  15. package/dist/generated/version.js.map +1 -1
  16. package/dist/locadex/setupFlow.js +1 -1
  17. package/dist/locadex/setupFlow.js.map +1 -1
  18. package/dist/paraglide/collectParaglideContext.d.ts +5 -0
  19. package/dist/paraglide/collectParaglideContext.js +43 -0
  20. package/dist/paraglide/collectParaglideContext.js.map +1 -0
  21. package/dist/setup/developmentCredentials.d.ts +3 -1
  22. package/dist/setup/developmentCredentials.js +6 -2
  23. package/dist/setup/developmentCredentials.js.map +1 -1
  24. package/dist/setup/onboarding.d.ts +6 -2
  25. package/dist/setup/onboarding.js +8 -4
  26. package/dist/setup/onboarding.js.map +1 -1
  27. package/dist/setup/wizard.d.ts +8 -2
  28. package/dist/setup/wizard.js +26 -1
  29. package/dist/setup/wizard.js.map +1 -1
  30. package/dist/types/index.d.ts +2 -2
  31. package/dist/types/index.js.map +1 -1
  32. package/dist/types/parsing.d.ts +8 -1
  33. package/dist/types/parsing.js.map +1 -1
  34. package/dist/utils/resolveMintlifyRefs.d.ts +5 -0
  35. package/dist/utils/resolveMintlifyRefs.js +26 -8
  36. package/dist/utils/resolveMintlifyRefs.js.map +1 -1
  37. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.28.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2707](https://github.com/generaltranslation/gt/pull/2707) [`691493b`](https://github.com/generaltranslation/gt/commit/691493b9f75b10bcafc2fe50e0361a68b76ebd45) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - fix(cli): stop `--save-local` from replacing a Mintlify `docs.json` translation with an empty one when its languages are split into `$ref` files
8
+
9
+ ## 2.28.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#2692](https://github.com/generaltranslation/gt/pull/2692) [`2d4868c`](https://github.com/generaltranslation/gt/commit/2d4868c0ca2b2d61931446256b993999cab0284a) Thanks [@JacksonO123](https://github.com/JacksonO123)! - `gt translate`, `gt stage`, `gt upload` and `gt setup` collect the source code context of Paraglide JS messages before reading the files to upload. Set `files.json.parsingFlags.includeSourceCodeContext` to `true` in `gt.config.json` in a project that has `@generaltranslation/paraglide-js` installed; running `paraglide-context` before the CLI is then no longer needed.
14
+
15
+ ### Patch Changes
16
+
17
+ - [#2642](https://github.com/generaltranslation/gt/pull/2642) [`caea70d`](https://github.com/generaltranslation/gt/commit/caea70d11ba6f7a23d1cc8c14a9e1bec3704c493) Thanks [@eoinest](https://github.com/eoinest)! - `gt init --create-project` now lists the organizations you can use (name and ID) when a noninteractive run needs `--org-id` or gets one you can't access.
18
+
19
+ - [#2644](https://github.com/generaltranslation/gt/pull/2644) [`a3a9b6a`](https://github.com/generaltranslation/gt/commit/a3a9b6a2705cf155d315bc94dfd29aaf44ae71bb) Thanks [@eoinest](https://github.com/eoinest)! - `gt init --locadex` now returns you to the dashboard after you connect GitHub, instead of a page that doesn't exist.
20
+
21
+ - [#2645](https://github.com/generaltranslation/gt/pull/2645) [`69738aa`](https://github.com/generaltranslation/gt/commit/69738aa6f8a67aca67a10e3717d942db9f7410ac) Thanks [@eoinest](https://github.com/eoinest)! - `gt init` no longer installs gt-react or reports a finished setup on Next.js Pages Router apps. It leaves the app unchanged, links the Pages Router quickstart as a manual step, and adds `defaultLocale` to `locales` in `gt.config.json` so the quickstart's Next.js `i18n` config builds.
22
+
3
23
  ## 2.27.3
4
24
 
5
25
  ### Patch Changes
@@ -3,19 +3,81 @@ import { hashStringSync } from "../utils/hash.js";
3
3
  import { getRelative } from "../fs/findFilepath.js";
4
4
  import { api } from "../utils/api.js";
5
5
  import { readFileContent } from "../fs/fileContent.js";
6
+ import { getJSONPathMatches } from "../formats/json/jsonPath.js";
7
+ import { findMatchingItemArray, findMatchingItemObject, generateSourceObjectPointers, validateJsonSchema } from "../formats/json/utils.js";
6
8
  import { extractJson } from "../formats/json/extractJson.js";
7
9
  import { recordWarning } from "../state/translateWarnings.js";
8
10
  import { readLockfile } from "../fs/config/downloadedVersions.js";
9
11
  import { createFileMapping } from "../formats/files/fileMapping.js";
12
+ import { resolveMintlifyRefs, shouldResolveRefs } from "../utils/resolveMintlifyRefs.js";
10
13
  import { getGitUnifiedDiff } from "../utils/gitDiff.js";
11
14
  import { emptyLocaleContent, localeContent } from "../formats/files/localeContent.js";
12
15
  import { extractYaml } from "../formats/yaml/extractYaml.js";
13
16
  import { randomUUID } from "node:crypto";
17
+ import { isDeepStrictEqual } from "node:util";
14
18
  import * as path$1 from "node:path";
15
19
  import * as fs$1 from "node:fs";
20
+ import { createDiagnosticMessage } from "generaltranslation/diagnostics";
16
21
  import os from "node:os";
17
22
  import { isBinaryFileFormat } from "generaltranslation/types";
18
23
  //#region src/api/collectUserEditDiffs.ts
24
+ const unsavedJsonEditsWarning = (relativePath, locale, reason) => createDiagnosticMessage({
25
+ source: "gt",
26
+ severity: "Warning",
27
+ whatHappened: `Local edits to ${relativePath} were not saved for ${locale}`,
28
+ why: reason,
29
+ reassurance: "The stored translation was left unchanged"
30
+ });
31
+ const resolveLocalRefs = (content, outputPath, settings) => {
32
+ if (!shouldResolveRefs(outputPath, settings.options)) return {
33
+ content,
34
+ unreadableRefs: []
35
+ };
36
+ try {
37
+ const { resolved, unreadableRefs } = resolveMintlifyRefs(JSON.parse(content), outputPath);
38
+ return {
39
+ content: JSON.stringify(resolved, null, 2),
40
+ unreadableRefs
41
+ };
42
+ } catch {
43
+ return {
44
+ content,
45
+ unreadableRefs: []
46
+ };
47
+ }
48
+ };
49
+ /**
50
+ * The unreadable refs that could hold values of the locale: all of them,
51
+ * except those inside an entry of a composite file known to belong to another
52
+ * locale.
53
+ */
54
+ const unreadableRefsForLocale = (unreadableRefs, resolvedContent, fileName, locale, settings) => {
55
+ if (unreadableRefs.length === 0) return [];
56
+ const composite = validateJsonSchema(settings.options ?? {}, fileName)?.composite;
57
+ const json = parseJson(resolvedContent);
58
+ if (!composite || json === void 0) return unreadableRefs;
59
+ const localeKey = settings.options?.experimentalCanonicalLocaleKeys ? api.resolveCanonicalLocale(locale) : locale;
60
+ const otherLocalePointers = [];
61
+ for (const [pointer, { sourceObjectValue, sourceObjectOptions }] of Object.entries(generateSourceObjectPointers(composite, json))) if (sourceObjectOptions.type === "array") {
62
+ if (!Array.isArray(sourceObjectValue)) continue;
63
+ const ownItems = findMatchingItemArray(localeKey, sourceObjectOptions, pointer, sourceObjectValue);
64
+ sourceObjectValue.forEach((item, index) => {
65
+ if (!!sourceObjectOptions.key && (getJSONPathMatches(item, sourceObjectOptions.key)?.length ?? 0) > 0 && !(`/${index}` in ownItems)) otherLocalePointers.push(`${pointer}/${index}`);
66
+ });
67
+ } else if (sourceObjectValue && typeof sourceObjectValue === "object") {
68
+ const { keyParentProperty } = findMatchingItemObject(localeKey, pointer, sourceObjectOptions, sourceObjectValue);
69
+ for (const key of Object.keys(sourceObjectValue)) if (key !== keyParentProperty) otherLocalePointers.push(`${pointer}/${key}`);
70
+ }
71
+ return unreadableRefs.filter((ref) => !otherLocalePointers.some((pointer) => ref.pointer === pointer || ref.pointer.startsWith(`${pointer}/`)));
72
+ };
73
+ const hasLeafValue = (value) => value !== null && typeof value === "object" ? Object.values(value).some(hasLeafValue) : value !== void 0;
74
+ const parseJson = (content) => {
75
+ try {
76
+ return JSON.parse(content);
77
+ } catch {
78
+ return;
79
+ }
80
+ };
19
81
  /**
20
82
  * The bytes a file's pipeline content stands for: binary formats carry base64,
21
83
  * everything else carries UTF-8 text. Applied to both sides of the comparison
@@ -134,8 +196,21 @@ async function collectAndSendUserEditDiffs(files, settings) {
134
196
  const rawLocalContent = localBytes.toString("utf8");
135
197
  let localContent = rawLocalContent;
136
198
  if (c.fileName.endsWith(".json") && settings.options?.jsonSchema && c.locale !== settings.defaultLocale) {
137
- const extractedContent = extractJson(rawLocalContent, c.fileName, settings.options, c.locale, settings.defaultLocale);
138
- if (extractedContent) localContent = extractedContent;
199
+ const resolvedLocal = resolveLocalRefs(rawLocalContent, c.outputPath, settings);
200
+ const extractedContent = extractJson(resolvedLocal.content, c.fileName, settings.options, c.locale, settings.defaultLocale);
201
+ if (extractedContent) {
202
+ const extracted = parseJson(extractedContent);
203
+ const unreadableRefs = unreadableRefsForLocale(resolvedLocal.unreadableRefs, resolvedLocal.content, c.fileName, c.locale, settings);
204
+ const reason = unreadableRefs.length > 0 ? `these $ref files could not be read: ${unreadableRefs.map((ref) => ref.refPath).join(", ")}` : !hasLeafValue(extracted) ? "no translated values for that locale could be read from the file" : void 0;
205
+ if (reason) {
206
+ const relativePath = getRelative(c.outputPath);
207
+ logger.warn(unsavedJsonEditsWarning(relativePath, c.locale, reason));
208
+ recordWarning("skipped_file", relativePath, reason);
209
+ continue;
210
+ }
211
+ if (isDeepStrictEqual(extracted, parseJson(serverContent))) continue;
212
+ localContent = extractedContent;
213
+ }
139
214
  } else if ((c.fileName.endsWith(".yaml") || c.fileName.endsWith(".yml")) && settings.options?.yamlSchema && c.locale !== settings.defaultLocale) {
140
215
  const extractedContent = extractYaml(rawLocalContent, c.fileName, settings.options);
141
216
  if (extractedContent) localContent = extractedContent;
@@ -1 +1 @@
1
- {"version":3,"file":"collectUserEditDiffs.js","names":["path","fs"],"sources":["../../src/api/collectUserEditDiffs.ts"],"sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport {\n readLockfile,\n EntryMap,\n DownloadedTranslation,\n} from '../fs/config/downloadedVersions.js';\nimport { Settings } from '../types/index.js';\nimport { createFileMapping } from '../formats/files/fileMapping.js';\nimport { getGitUnifiedDiff } from '../utils/gitDiff.js';\nimport { api } from '../utils/api.js';\nimport {\n FileReference,\n isBinaryFileFormat,\n SubmitUserEditDiff,\n type FileFormat,\n} from 'generaltranslation/types';\nimport { readFileContent } from '../fs/fileContent.js';\nimport os from 'node:os';\nimport { randomUUID } from 'node:crypto';\nimport { hashStringSync } from '../utils/hash.js';\nimport { extractJson } from '../formats/json/extractJson.js';\nimport {\n emptyLocaleContent,\n localeContent,\n} from '../formats/files/localeContent.js';\nimport { extractYaml } from '../formats/yaml/extractYaml.js';\nimport { logger } from '../console/logger.js';\nimport { recordWarning } from '../state/translateWarnings.js';\nimport { getRelative } from '../fs/findFilepath.js';\n\ntype LatestDownloadedVersion = {\n versionId: string;\n entry: DownloadedTranslation;\n};\n\n/**\n * The bytes a file's pipeline content stands for: binary formats carry base64,\n * everything else carries UTF-8 text. Applied to both sides of the comparison\n * so they are measured the same way.\n */\nconst contentBytes = (content: string, fileFormat: FileFormat): Buffer =>\n isBinaryFileFormat(fileFormat)\n ? Buffer.from(content, 'base64')\n : Buffer.from(content, 'utf8');\n\nconst findLatestDownloadedVersion = (\n entryMap: EntryMap,\n fileId: string,\n locale: string\n): LatestDownloadedVersion | null => {\n const entry = entryMap.get(fileId);\n if (!entry) return null;\n\n const translation = entry.translations[locale];\n if (!translation) return null;\n\n return { versionId: entry.versionId, entry: translation };\n};\n\n/**\n * Collects local user edits by diffing the latest downloaded server translation version\n * against the current local translation file, and submits the diffs upstream.\n * A file that holds every locale is compared one locale slice at a time, so an\n * edit to one locale is submitted under that locale alone.\n *\n * Must run before enqueueing new translations so rules are available to the generator.\n */\nexport async function collectAndSendUserEditDiffs(\n files: FileReference[],\n settings: Settings\n): Promise<boolean> {\n if (!settings.files) return false;\n\n const { resolvedPaths, placeholderPaths, transformPaths, transformFormats } =\n settings.files;\n const fileMapping = createFileMapping(\n resolvedPaths,\n placeholderPaths,\n transformPaths,\n transformFormats,\n settings.locales,\n settings.defaultLocale\n );\n\n const { entryMap } = readLockfile(settings);\n\n const tempDir = path.join(os.tmpdir(), randomUUID());\n if (!fs.existsSync(tempDir)) fs.mkdirSync(tempDir, { recursive: true });\n\n // Build candidates for diff and batch-fetch server contents\n type DiffCandidate = {\n branchId: string;\n fileName: string;\n fileId: string;\n versionId: string;\n locale: string; // resolved\n outputPath: string;\n fileFormat: FileFormat;\n };\n const candidates: DiffCandidate[] = [];\n\n for (const uploadedFile of files) {\n for (const locale of settings.locales) {\n const outputPath = fileMapping[locale]?.[uploadedFile.fileName] ?? null;\n if (!outputPath) continue;\n if (!fs.existsSync(outputPath)) continue;\n\n const latestDownloaded = findLatestDownloadedVersion(\n entryMap,\n uploadedFile.fileId,\n locale\n );\n\n if (!latestDownloaded) continue;\n const downloadedVersion = latestDownloaded.entry;\n\n // Skip if the locale's local content matches the last recorded hash\n if (downloadedVersion.postProcessHash) {\n try {\n // Hashed from the locale's share of the pipeline content, which is\n // what was recorded, so an untouched locale matches regardless of\n // the file's encoding or of edits to its other locales.\n const localFile = readFileContent(\n outputPath,\n uploadedFile.fileFormat\n );\n const localHash = hashStringSync(\n localeContent(localFile, uploadedFile.fileFormat, locale) ??\n emptyLocaleContent(localFile, uploadedFile.fileFormat)\n );\n if (localHash === downloadedVersion.postProcessHash) {\n continue;\n }\n } catch {\n // If hash check fails, fall through to diff\n }\n }\n\n candidates.push({\n branchId: uploadedFile.branchId,\n fileName: uploadedFile.fileName,\n fileId: uploadedFile.fileId,\n versionId: latestDownloaded.versionId,\n locale: locale,\n outputPath,\n fileFormat: uploadedFile.fileFormat,\n });\n }\n }\n\n const collectedDiffs: SubmitUserEditDiff[] = [];\n\n if (candidates.length > 0) {\n const fileQueryData = candidates.map((c) => ({\n versionId: c.versionId,\n locale: c.locale,\n fileId: c.fileId,\n branchId: c.branchId,\n }));\n\n // Single batched check to obtain translation IDs\n const checkResponse = await api.queryFileData({\n translatedFiles: fileQueryData,\n });\n const translatedFiles =\n checkResponse.translatedFiles?.filter((t) => t.completedAt) ?? [];\n\n // The server's copy of each candidate, keyed like the candidates\n type ServerPayload = { data: string; fileFormat: FileFormat };\n const serverPayloadByKey = new Map<string, ServerPayload>();\n try {\n const resp = await api.downloadFileBatch(\n translatedFiles.map((file) => ({\n branchId: file.branchId,\n fileId: file.fileId,\n locale: file.locale,\n versionId: file.versionId,\n }))\n );\n for (const f of resp?.files || []) {\n if (!f.locale) continue;\n serverPayloadByKey.set(\n `${f.branchId}:${f.fileId}:${f.versionId}:${f.locale}`,\n { data: f.data, fileFormat: f.fileFormat }\n );\n }\n } catch {\n // Ignore chunk failures; proceed with what we have\n }\n\n // Compute diffs using fetched server contents\n for (const c of candidates) {\n const key = `${c.branchId}:${c.fileId}:${c.versionId}:${c.locale}`;\n const payload = serverPayloadByKey.get(key);\n // Absent means the batch did not return this file, so there is no\n // baseline. An empty payload is a baseline of nothing, which the user\n // may well have written against.\n if (!payload) continue;\n\n // The locale's share of the payload, read on its own so a payload the\n // server sent malformed costs only its own locale. A catalog payload\n // that carries nothing for the locale is that file's empty payload, and\n // a baseline of nothing like any other.\n let serverContent: string;\n try {\n serverContent =\n localeContent(payload.data, payload.fileFormat, c.locale) ??\n emptyLocaleContent(payload.data, payload.fileFormat);\n } catch (error) {\n const relativePath = getRelative(c.outputPath);\n const reason = `The downloaded ${c.locale} translation could not be read (${\n error instanceof Error ? error.message : String(error)\n })`;\n logger.warn(`Skipping local edits to ${relativePath}: ${reason}`);\n recordWarning('skipped_file', relativePath, reason);\n continue;\n }\n const serverBytes = contentBytes(serverContent, payload.fileFormat);\n\n try {\n // Read the local file the same way the pipeline read it originally, so\n // a file stored differently on disk than the server's copy is compared\n // as content rather than as bytes. Otherwise every such file would read\n // as edited on every run. Then cut to this locale's share, so a file\n // that holds every locale is compared slice to slice.\n const local = localeContent(\n readFileContent(c.outputPath, c.fileFormat),\n c.fileFormat,\n c.locale\n );\n // A catalog that no longer carries the locale has nothing to submit\n if (local === undefined) continue;\n const localBytes = contentBytes(local, c.fileFormat);\n\n // Nothing was edited, so there is no diff to compute or report.\n if (localBytes.equals(serverBytes)) continue;\n\n // A unified diff and localContent are both UTF-8 text, and every text\n // format's content is UTF-8 by the time it reaches here. Only a binary\n // format's bytes — a Lottie zip — have no text form at all. Say so:\n // the edit is real and will be lost on the next download.\n if (isBinaryFileFormat(c.fileFormat)) {\n const relativePath = getRelative(c.outputPath);\n const reason =\n 'Edited file is a binary format, so its changes cannot be submitted';\n logger.warn(`Skipping local edits to ${relativePath}: ${reason}`);\n recordWarning('skipped_file', relativePath, reason);\n continue;\n }\n\n const safeName = Buffer.from(\n `${c.branchId}:${c.fileId}:${c.versionId}:${c.locale}`\n )\n .toString('base64')\n .replace(/=+$/g, '');\n const tempServerFile = path.join(tempDir, `${safeName}.server`);\n await fs.promises.writeFile(tempServerFile, serverBytes);\n\n // git diff reads bytes, so both sides are written from the content\n // they represent rather than diffing the file as it sits on disk.\n const tempLocalFile = path.join(tempDir, `${safeName}.local`);\n await fs.promises.writeFile(tempLocalFile, localBytes);\n\n const diff = await getGitUnifiedDiff(tempServerFile, tempLocalFile);\n for (const tempFile of [tempServerFile, tempLocalFile]) {\n try {\n await fs.promises.unlink(tempFile);\n } catch {\n // Ignore cleanup errors for temporary comparison files.\n }\n }\n\n if (diff && diff.trim().length > 0) {\n const rawLocalContent = localBytes.toString('utf8');\n\n // For JSON files with jsonSchema config, extract to composite format\n let localContent = rawLocalContent;\n if (\n c.fileName.endsWith('.json') &&\n settings.options?.jsonSchema &&\n c.locale !== settings.defaultLocale\n ) {\n const extractedContent = extractJson(\n rawLocalContent,\n c.fileName,\n settings.options,\n c.locale,\n settings.defaultLocale\n );\n if (extractedContent) {\n localContent = extractedContent;\n }\n } else if (\n (c.fileName.endsWith('.yaml') || c.fileName.endsWith('.yml')) &&\n settings.options?.yamlSchema &&\n c.locale !== settings.defaultLocale\n ) {\n const extractedContent = extractYaml(\n rawLocalContent,\n c.fileName,\n settings.options\n );\n if (extractedContent) {\n localContent = extractedContent;\n }\n }\n\n collectedDiffs.push({\n fileName: c.fileName,\n locale: c.locale,\n diff,\n branchId: c.branchId,\n versionId: c.versionId,\n fileId: c.fileId,\n localContent,\n } satisfies SubmitUserEditDiff);\n }\n } catch {\n // Ignore failures for this file\n }\n }\n }\n\n if (collectedDiffs.length > 0) {\n await api.submitUserEditDiffs({ diffs: collectedDiffs });\n }\n\n return collectedDiffs.length > 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAM,gBAAgB,SAAiB,eACrC,mBAAmB,WAAW,GAC1B,OAAO,KAAK,SAAS,SAAS,GAC9B,OAAO,KAAK,SAAS,OAAO;AAElC,MAAM,+BACJ,UACA,QACA,WACmC;CACnC,MAAM,QAAQ,SAAS,IAAI,OAAO;AAClC,KAAI,CAAC,MAAO,QAAO;CAEnB,MAAM,cAAc,MAAM,aAAa;AACvC,KAAI,CAAC,YAAa,QAAO;AAEzB,QAAO;EAAE,WAAW,MAAM;EAAW,OAAO;EAAa;;;;;;;;;;AAW3D,eAAsB,4BACpB,OACA,UACkB;AAClB,KAAI,CAAC,SAAS,MAAO,QAAO;CAE5B,MAAM,EAAE,eAAe,kBAAkB,gBAAgB,qBACvD,SAAS;CACX,MAAM,cAAc,kBAClB,eACA,kBACA,gBACA,kBACA,SAAS,SACT,SAAS,cACV;CAED,MAAM,EAAE,aAAa,aAAa,SAAS;CAE3C,MAAM,UAAUA,OAAK,KAAK,GAAG,QAAQ,EAAE,YAAY,CAAC;AACpD,KAAI,CAACC,KAAG,WAAW,QAAQ,CAAE,MAAG,UAAU,SAAS,EAAE,WAAW,MAAM,CAAC;CAYvE,MAAM,aAA8B,EAAE;AAEtC,MAAK,MAAM,gBAAgB,MACzB,MAAK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,SAAS,UAAU,gBAAgB,YAAY;IAIxD,MAAM,gBAAgBD,OAAK,KAAK,SAAS,GAAG,SAAS,QAAQ;AAC7D,UAAMC,KAAG,SAAS,UAAU,eAAe,WAAW;IAEtD,MAAM,OAAO,MAAM,kBAAkB,gBAAgB,cAAc;AACnE,SAAK,MAAM,YAAY,CAAC,gBAAgB,cAAc,CACpD,KAAI;AACF,WAAMA,KAAG,SAAS,OAAO,SAAS;YAC5B;AAKV,QAAI,QAAQ,KAAK,MAAM,CAAC,SAAS,GAAG;KAClC,MAAM,kBAAkB,WAAW,SAAS,OAAO;KAGnD,IAAI,eAAe;AACnB,SACE,EAAE,SAAS,SAAS,QAAQ,IAC5B,SAAS,SAAS,cAClB,EAAE,WAAW,SAAS,eACtB;MACA,MAAM,mBAAmB,YACvB,iBACA,EAAE,UACF,SAAS,SACT,EAAE,QACF,SAAS,cACV;AACD,UAAI,iBACF,gBAAe;iBAGhB,EAAE,SAAS,SAAS,QAAQ,IAAI,EAAE,SAAS,SAAS,OAAO,KAC5D,SAAS,SAAS,cAClB,EAAE,WAAW,SAAS,eACtB;MACA,MAAM,mBAAmB,YACvB,iBACA,EAAE,UACF,SAAS,QACV;AACD,UAAI,iBACF,gBAAe;;AAInB,oBAAe,KAAK;MAClB,UAAU,EAAE;MACZ,QAAQ,EAAE;MACV;MACA,UAAU,EAAE;MACZ,WAAW,EAAE;MACb,QAAQ,EAAE;MACV;MACD,CAA8B;;WAE3B;;;AAMZ,KAAI,eAAe,SAAS,EAC1B,OAAM,IAAI,oBAAoB,EAAE,OAAO,gBAAgB,CAAC;AAG1D,QAAO,eAAe,SAAS"}
1
+ {"version":3,"file":"collectUserEditDiffs.js","names":["path","fs"],"sources":["../../src/api/collectUserEditDiffs.ts"],"sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport {\n readLockfile,\n EntryMap,\n DownloadedTranslation,\n} from '../fs/config/downloadedVersions.js';\nimport { Settings } from '../types/index.js';\nimport { createFileMapping } from '../formats/files/fileMapping.js';\nimport { getGitUnifiedDiff } from '../utils/gitDiff.js';\nimport { api } from '../utils/api.js';\nimport {\n FileReference,\n isBinaryFileFormat,\n SubmitUserEditDiff,\n type FileFormat,\n} from 'generaltranslation/types';\nimport { readFileContent } from '../fs/fileContent.js';\nimport os from 'node:os';\nimport { randomUUID } from 'node:crypto';\nimport { hashStringSync } from '../utils/hash.js';\nimport { extractJson } from '../formats/json/extractJson.js';\nimport {\n emptyLocaleContent,\n localeContent,\n} from '../formats/files/localeContent.js';\nimport { extractYaml } from '../formats/yaml/extractYaml.js';\nimport { logger } from '../console/logger.js';\nimport { recordWarning } from '../state/translateWarnings.js';\nimport { getRelative } from '../fs/findFilepath.js';\nimport {\n resolveMintlifyRefs,\n shouldResolveRefs,\n type UnreadableRef,\n} from '../utils/resolveMintlifyRefs.js';\nimport {\n findMatchingItemArray,\n findMatchingItemObject,\n generateSourceObjectPointers,\n validateJsonSchema,\n} from '../formats/json/utils.js';\nimport type { JSONObject, JSONValue } from '../types/data/json.js';\nimport { getJSONPathMatches } from '../formats/json/jsonPath.js';\nimport { createDiagnosticMessage } from 'generaltranslation/diagnostics';\nimport { isDeepStrictEqual } from 'node:util';\n\nconst unsavedJsonEditsWarning = (\n relativePath: string,\n locale: string,\n reason: string\n) =>\n createDiagnosticMessage({\n source: 'gt',\n severity: 'Warning',\n whatHappened: `Local edits to ${relativePath} were not saved for ${locale}`,\n why: reason,\n reassurance: 'The stored translation was left unchanged',\n });\n\nconst resolveLocalRefs = (\n content: string,\n outputPath: string,\n settings: Settings\n): { content: string; unreadableRefs: UnreadableRef[] } => {\n if (!shouldResolveRefs(outputPath, settings.options)) {\n return { content, unreadableRefs: [] };\n }\n try {\n const { resolved, unreadableRefs } = resolveMintlifyRefs(\n JSON.parse(content),\n outputPath\n );\n return { content: JSON.stringify(resolved, null, 2), unreadableRefs };\n } catch {\n return { content, unreadableRefs: [] };\n }\n};\n\n/**\n * The unreadable refs that could hold values of the locale: all of them,\n * except those inside an entry of a composite file known to belong to another\n * locale.\n */\nconst unreadableRefsForLocale = (\n unreadableRefs: UnreadableRef[],\n resolvedContent: string,\n fileName: string,\n locale: string,\n settings: Settings\n): UnreadableRef[] => {\n if (unreadableRefs.length === 0) return [];\n const composite = validateJsonSchema(\n settings.options ?? {},\n fileName\n )?.composite;\n const json = parseJson(resolvedContent) as JSONValue | undefined;\n if (!composite || json === undefined) return unreadableRefs;\n\n const localeKey = settings.options?.experimentalCanonicalLocaleKeys\n ? api.resolveCanonicalLocale(locale)\n : locale;\n const otherLocalePointers: string[] = [];\n for (const [\n pointer,\n { sourceObjectValue, sourceObjectOptions },\n ] of Object.entries(generateSourceObjectPointers(composite, json))) {\n if (sourceObjectOptions.type === 'array') {\n if (!Array.isArray(sourceObjectValue)) continue;\n const ownItems = findMatchingItemArray(\n localeKey,\n sourceObjectOptions,\n pointer,\n sourceObjectValue\n );\n sourceObjectValue.forEach((item, index) => {\n // An entry whose locale key sat in the unreadable file has no key\n // left, so it may be the locale's own.\n const hasLocaleKey =\n !!sourceObjectOptions.key &&\n (getJSONPathMatches(item, sourceObjectOptions.key)?.length ?? 0) > 0;\n if (hasLocaleKey && !(`/${index}` in ownItems)) {\n otherLocalePointers.push(`${pointer}/${index}`);\n }\n });\n } else if (sourceObjectValue && typeof sourceObjectValue === 'object') {\n const { keyParentProperty } = findMatchingItemObject(\n localeKey,\n pointer,\n sourceObjectOptions,\n sourceObjectValue as JSONObject\n );\n for (const key of Object.keys(sourceObjectValue)) {\n if (key !== keyParentProperty) {\n otherLocalePointers.push(`${pointer}/${key}`);\n }\n }\n }\n }\n return unreadableRefs.filter(\n (ref) =>\n !otherLocalePointers.some(\n (pointer) =>\n ref.pointer === pointer || ref.pointer.startsWith(`${pointer}/`)\n )\n );\n};\n\nconst hasLeafValue = (value: unknown): boolean =>\n value !== null && typeof value === 'object'\n ? Object.values(value).some(hasLeafValue)\n : value !== undefined;\n\nconst parseJson = (content: string): unknown => {\n try {\n return JSON.parse(content);\n } catch {\n return undefined;\n }\n};\n\ntype LatestDownloadedVersion = {\n versionId: string;\n entry: DownloadedTranslation;\n};\n\n/**\n * The bytes a file's pipeline content stands for: binary formats carry base64,\n * everything else carries UTF-8 text. Applied to both sides of the comparison\n * so they are measured the same way.\n */\nconst contentBytes = (content: string, fileFormat: FileFormat): Buffer =>\n isBinaryFileFormat(fileFormat)\n ? Buffer.from(content, 'base64')\n : Buffer.from(content, 'utf8');\n\nconst findLatestDownloadedVersion = (\n entryMap: EntryMap,\n fileId: string,\n locale: string\n): LatestDownloadedVersion | null => {\n const entry = entryMap.get(fileId);\n if (!entry) return null;\n\n const translation = entry.translations[locale];\n if (!translation) return null;\n\n return { versionId: entry.versionId, entry: translation };\n};\n\n/**\n * Collects local user edits by diffing the latest downloaded server translation version\n * against the current local translation file, and submits the diffs upstream.\n * A file that holds every locale is compared one locale slice at a time, so an\n * edit to one locale is submitted under that locale alone.\n *\n * Must run before enqueueing new translations so rules are available to the generator.\n */\nexport async function collectAndSendUserEditDiffs(\n files: FileReference[],\n settings: Settings\n): Promise<boolean> {\n if (!settings.files) return false;\n\n const { resolvedPaths, placeholderPaths, transformPaths, transformFormats } =\n settings.files;\n const fileMapping = createFileMapping(\n resolvedPaths,\n placeholderPaths,\n transformPaths,\n transformFormats,\n settings.locales,\n settings.defaultLocale\n );\n\n const { entryMap } = readLockfile(settings);\n\n const tempDir = path.join(os.tmpdir(), randomUUID());\n if (!fs.existsSync(tempDir)) fs.mkdirSync(tempDir, { recursive: true });\n\n // Build candidates for diff and batch-fetch server contents\n type DiffCandidate = {\n branchId: string;\n fileName: string;\n fileId: string;\n versionId: string;\n locale: string; // resolved\n outputPath: string;\n fileFormat: FileFormat;\n };\n const candidates: DiffCandidate[] = [];\n\n for (const uploadedFile of files) {\n for (const locale of settings.locales) {\n const outputPath = fileMapping[locale]?.[uploadedFile.fileName] ?? null;\n if (!outputPath) continue;\n if (!fs.existsSync(outputPath)) continue;\n\n const latestDownloaded = findLatestDownloadedVersion(\n entryMap,\n uploadedFile.fileId,\n locale\n );\n\n if (!latestDownloaded) continue;\n const downloadedVersion = latestDownloaded.entry;\n\n // Skip if the locale's local content matches the last recorded hash\n if (downloadedVersion.postProcessHash) {\n try {\n // Hashed from the locale's share of the pipeline content, which is\n // what was recorded, so an untouched locale matches regardless of\n // the file's encoding or of edits to its other locales.\n const localFile = readFileContent(\n outputPath,\n uploadedFile.fileFormat\n );\n const localHash = hashStringSync(\n localeContent(localFile, uploadedFile.fileFormat, locale) ??\n emptyLocaleContent(localFile, uploadedFile.fileFormat)\n );\n if (localHash === downloadedVersion.postProcessHash) {\n continue;\n }\n } catch {\n // If hash check fails, fall through to diff\n }\n }\n\n candidates.push({\n branchId: uploadedFile.branchId,\n fileName: uploadedFile.fileName,\n fileId: uploadedFile.fileId,\n versionId: latestDownloaded.versionId,\n locale: locale,\n outputPath,\n fileFormat: uploadedFile.fileFormat,\n });\n }\n }\n\n const collectedDiffs: SubmitUserEditDiff[] = [];\n\n if (candidates.length > 0) {\n const fileQueryData = candidates.map((c) => ({\n versionId: c.versionId,\n locale: c.locale,\n fileId: c.fileId,\n branchId: c.branchId,\n }));\n\n // Single batched check to obtain translation IDs\n const checkResponse = await api.queryFileData({\n translatedFiles: fileQueryData,\n });\n const translatedFiles =\n checkResponse.translatedFiles?.filter((t) => t.completedAt) ?? [];\n\n // The server's copy of each candidate, keyed like the candidates\n type ServerPayload = { data: string; fileFormat: FileFormat };\n const serverPayloadByKey = new Map<string, ServerPayload>();\n try {\n const resp = await api.downloadFileBatch(\n translatedFiles.map((file) => ({\n branchId: file.branchId,\n fileId: file.fileId,\n locale: file.locale,\n versionId: file.versionId,\n }))\n );\n for (const f of resp?.files || []) {\n if (!f.locale) continue;\n serverPayloadByKey.set(\n `${f.branchId}:${f.fileId}:${f.versionId}:${f.locale}`,\n { data: f.data, fileFormat: f.fileFormat }\n );\n }\n } catch {\n // Ignore chunk failures; proceed with what we have\n }\n\n // Compute diffs using fetched server contents\n for (const c of candidates) {\n const key = `${c.branchId}:${c.fileId}:${c.versionId}:${c.locale}`;\n const payload = serverPayloadByKey.get(key);\n // Absent means the batch did not return this file, so there is no\n // baseline. An empty payload is a baseline of nothing, which the user\n // may well have written against.\n if (!payload) continue;\n\n // The locale's share of the payload, read on its own so a payload the\n // server sent malformed costs only its own locale. A catalog payload\n // that carries nothing for the locale is that file's empty payload, and\n // a baseline of nothing like any other.\n let serverContent: string;\n try {\n serverContent =\n localeContent(payload.data, payload.fileFormat, c.locale) ??\n emptyLocaleContent(payload.data, payload.fileFormat);\n } catch (error) {\n const relativePath = getRelative(c.outputPath);\n const reason = `The downloaded ${c.locale} translation could not be read (${\n error instanceof Error ? error.message : String(error)\n })`;\n logger.warn(`Skipping local edits to ${relativePath}: ${reason}`);\n recordWarning('skipped_file', relativePath, reason);\n continue;\n }\n const serverBytes = contentBytes(serverContent, payload.fileFormat);\n\n try {\n // Read the local file the same way the pipeline read it originally, so\n // a file stored differently on disk than the server's copy is compared\n // as content rather than as bytes. Otherwise every such file would read\n // as edited on every run. Then cut to this locale's share, so a file\n // that holds every locale is compared slice to slice.\n const local = localeContent(\n readFileContent(c.outputPath, c.fileFormat),\n c.fileFormat,\n c.locale\n );\n // A catalog that no longer carries the locale has nothing to submit\n if (local === undefined) continue;\n const localBytes = contentBytes(local, c.fileFormat);\n\n // Nothing was edited, so there is no diff to compute or report.\n if (localBytes.equals(serverBytes)) continue;\n\n // A unified diff and localContent are both UTF-8 text, and every text\n // format's content is UTF-8 by the time it reaches here. Only a binary\n // format's bytes — a Lottie zip — have no text form at all. Say so:\n // the edit is real and will be lost on the next download.\n if (isBinaryFileFormat(c.fileFormat)) {\n const relativePath = getRelative(c.outputPath);\n const reason =\n 'Edited file is a binary format, so its changes cannot be submitted';\n logger.warn(`Skipping local edits to ${relativePath}: ${reason}`);\n recordWarning('skipped_file', relativePath, reason);\n continue;\n }\n\n const safeName = Buffer.from(\n `${c.branchId}:${c.fileId}:${c.versionId}:${c.locale}`\n )\n .toString('base64')\n .replace(/=+$/g, '');\n const tempServerFile = path.join(tempDir, `${safeName}.server`);\n await fs.promises.writeFile(tempServerFile, serverBytes);\n\n // git diff reads bytes, so both sides are written from the content\n // they represent rather than diffing the file as it sits on disk.\n const tempLocalFile = path.join(tempDir, `${safeName}.local`);\n await fs.promises.writeFile(tempLocalFile, localBytes);\n\n const diff = await getGitUnifiedDiff(tempServerFile, tempLocalFile);\n for (const tempFile of [tempServerFile, tempLocalFile]) {\n try {\n await fs.promises.unlink(tempFile);\n } catch {\n // Ignore cleanup errors for temporary comparison files.\n }\n }\n\n if (diff && diff.trim().length > 0) {\n const rawLocalContent = localBytes.toString('utf8');\n\n // For JSON files with jsonSchema config, extract to composite format\n let localContent = rawLocalContent;\n if (\n c.fileName.endsWith('.json') &&\n settings.options?.jsonSchema &&\n c.locale !== settings.defaultLocale\n ) {\n const resolvedLocal = resolveLocalRefs(\n rawLocalContent,\n c.outputPath,\n settings\n );\n const extractedContent = extractJson(\n resolvedLocal.content,\n c.fileName,\n settings.options,\n c.locale,\n settings.defaultLocale\n );\n if (extractedContent) {\n const extracted = parseJson(extractedContent);\n // The submitted content replaces the stored translation, so\n // values missing from it would be erased.\n const unreadableRefs = unreadableRefsForLocale(\n resolvedLocal.unreadableRefs,\n resolvedLocal.content,\n c.fileName,\n c.locale,\n settings\n );\n const reason =\n unreadableRefs.length > 0\n ? `these $ref files could not be read: ${unreadableRefs.map((ref) => ref.refPath).join(', ')}`\n : !hasLeafValue(extracted)\n ? 'no translated values for that locale could be read from the file'\n : undefined;\n if (reason) {\n const relativePath = getRelative(c.outputPath);\n logger.warn(\n unsavedJsonEditsWarning(relativePath, c.locale, reason)\n );\n recordWarning('skipped_file', relativePath, reason);\n continue;\n }\n if (isDeepStrictEqual(extracted, parseJson(serverContent))) {\n continue;\n }\n localContent = extractedContent;\n }\n } else if (\n (c.fileName.endsWith('.yaml') || c.fileName.endsWith('.yml')) &&\n settings.options?.yamlSchema &&\n c.locale !== settings.defaultLocale\n ) {\n const extractedContent = extractYaml(\n rawLocalContent,\n c.fileName,\n settings.options\n );\n if (extractedContent) {\n localContent = extractedContent;\n }\n }\n\n collectedDiffs.push({\n fileName: c.fileName,\n locale: c.locale,\n diff,\n branchId: c.branchId,\n versionId: c.versionId,\n fileId: c.fileId,\n localContent,\n } satisfies SubmitUserEditDiff);\n }\n } catch {\n // Ignore failures for this file\n }\n }\n }\n\n if (collectedDiffs.length > 0) {\n await api.submitUserEditDiffs({ diffs: collectedDiffs });\n }\n\n return collectedDiffs.length > 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAM,2BACJ,cACA,QACA,WAEA,wBAAwB;CACtB,QAAQ;CACR,UAAU;CACV,cAAc,kBAAkB,aAAa,sBAAsB;CACnE,KAAK;CACL,aAAa;CACd,CAAC;AAEJ,MAAM,oBACJ,SACA,YACA,aACyD;AACzD,KAAI,CAAC,kBAAkB,YAAY,SAAS,QAAQ,CAClD,QAAO;EAAE;EAAS,gBAAgB,EAAE;EAAE;AAExC,KAAI;EACF,MAAM,EAAE,UAAU,mBAAmB,oBACnC,KAAK,MAAM,QAAQ,EACnB,WACD;AACD,SAAO;GAAE,SAAS,KAAK,UAAU,UAAU,MAAM,EAAE;GAAE;GAAgB;SAC/D;AACN,SAAO;GAAE;GAAS,gBAAgB,EAAE;GAAE;;;;;;;;AAS1C,MAAM,2BACJ,gBACA,iBACA,UACA,QACA,aACoB;AACpB,KAAI,eAAe,WAAW,EAAG,QAAO,EAAE;CAC1C,MAAM,YAAY,mBAChB,SAAS,WAAW,EAAE,EACtB,SACD,EAAE;CACH,MAAM,OAAO,UAAU,gBAAgB;AACvC,KAAI,CAAC,aAAa,SAAS,KAAA,EAAW,QAAO;CAE7C,MAAM,YAAY,SAAS,SAAS,kCAChC,IAAI,uBAAuB,OAAO,GAClC;CACJ,MAAM,sBAAgC,EAAE;AACxC,MAAK,MAAM,CACT,SACA,EAAE,mBAAmB,0BAClB,OAAO,Q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CAAC,KAAK,KAAK,KAC1F,CAAC,aAAa,UAAU,GACtB,qEACA,KAAA;AACR,WAAI,QAAQ;QACV,MAAM,eAAe,YAAY,EAAE,WAAW;AAC9C,eAAO,KACL,wBAAwB,cAAc,EAAE,QAAQ,OAAO,CACxD;AACD,sBAAc,gBAAgB,cAAc,OAAO;AACnD;;AAEF,WAAI,kBAAkB,WAAW,UAAU,cAAc,CAAC,CACxD;AAEF,sBAAe;;iBAGhB,EAAE,SAAS,SAAS,QAAQ,IAAI,EAAE,SAAS,SAAS,OAAO,KAC5D,SAAS,SAAS,cAClB,EAAE,WAAW,SAAS,eACtB;MACA,MAAM,mBAAmB,YACvB,iBACA,EAAE,UACF,SAAS,QACV;AACD,UAAI,iBACF,gBAAe;;AAInB,oBAAe,KAAK;MAClB,UAAU,EAAE;MACZ,QAAQ,EAAE;MACV;MACA,UAAU,EAAE;MACZ,WAAW,EAAE;MACb,QAAQ,EAAE;MACV;MACD,CAA8B;;WAE3B;;;AAMZ,KAAI,eAAe,SAAS,EAC1B,OAAM,IAAI,oBAAoB,EAAE,OAAO,gBAAgB,CAAC;AAG1D,QAAO,eAAe,SAAS"}
@@ -103,6 +103,8 @@ export declare class BaseCLI {
103
103
  /** Write the framework even when no build-tool setup saves it. */
104
104
  saveFramework?: boolean;
105
105
  reactSetup?: ReactSetupPlan;
106
+ /** The app still needs a GT runtime the wizard could not set up. */
107
+ skippedReactSetup?: boolean;
106
108
  /** Init without the React setup never changes application source. */
107
109
  keepAppSource?: boolean;
108
110
  }): Promise<string[] | undefined>;
package/dist/cli/base.js CHANGED
@@ -444,13 +444,15 @@ var BaseCLI = class {
444
444
  defaultValue: true
445
445
  })
446
446
  }) === true;
447
- const reactSetup = reactDetected ? await resolveReactSetup(session, options, reactDetected, configuredReact) : void 0;
448
- const framework = reactSetup?.framework ?? options.framework ?? configured ?? detected.name;
447
+ const resolvedSetup = reactDetected ? await resolveReactSetup(session, options, reactDetected, configuredReact) : void 0;
448
+ const reactSetup = resolvedSetup && !("skipped" in resolvedSetup) ? resolvedSetup : void 0;
449
+ const framework = resolvedSetup?.framework ?? options.framework ?? configured ?? detected.name;
449
450
  const nextSteps = await this.handleInitCommand(session, options, {
450
451
  configFilepath,
451
452
  framework,
452
- saveFramework: Boolean(reactSetup || options.framework),
453
+ saveFramework: Boolean(resolvedSetup || options.framework),
453
454
  reactSetup,
455
+ skippedReactSetup: Boolean(resolvedSetup && !reactSetup),
454
456
  keepAppSource: !reactSetup
455
457
  });
456
458
  if (nextSteps) {
@@ -532,9 +534,11 @@ See https://www.npmjs.com/package/gt-vue`);
532
534
  const buildTool = getBuildToolSetup(setup.framework);
533
535
  const cwd = process.cwd();
534
536
  const existingConfig = readSetupConfig(configFilepath);
535
- const { defaultLocale, locales } = await getDesiredLocales(session, existingConfig, options);
537
+ const desiredLocales = await getDesiredLocales(session, existingConfig, options);
538
+ const { defaultLocale } = desiredLocales;
539
+ const locales = setup.framework === "next-pages" && defaultLocale && desiredLocales.locales && !desiredLocales.locales.includes(defaultLocale) ? [defaultLocale, ...desiredLocales.locales] : desiredLocales.locales;
536
540
  const packageJson = reactSetup?.packageJson ?? await searchForPackageJson();
537
- const runtimeSetup = packageJson ? this.getInlineRuntimeSetup(packageJson, Boolean(reactSetup)) : {
541
+ const runtimeSetup = packageJson ? this.getInlineRuntimeSetup(packageJson, Boolean(reactSetup || setup.skippedReactSetup)) : {
538
542
  hasOtherInlineRuntime: false,
539
543
  hasVueRuntime: false,
540
544
  ranReactSetup: false