@menapo/vi18n 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/README.md +19 -0
  2. package/dist/{apply-Bre-lY9J.js → apply-Bg-3rB2m.js} +69 -89
  3. package/dist/{captured-Bj8bO6vd.js → captured-DfLk50Ji.js} +196 -217
  4. package/dist/{check-BIKEuu6B.js → check-CunekuYs.js} +76 -85
  5. package/dist/cli.js +2 -3
  6. package/dist/{collect-Cx4_SKOe.js → collect-CYATDjdo.js} +1 -2
  7. package/dist/collisions-CDSdtLQm.js +215 -0
  8. package/dist/{compile-Cc97JaW2.js → compile-DqkofbiO.js} +376 -331
  9. package/dist/compile-hva0qjhZ.js +240 -0
  10. package/dist/concurrency-BCY_4zcr.js +1 -0
  11. package/dist/concurrency-Dy2ny50V.js +107 -0
  12. package/dist/config.d.ts +1 -5
  13. package/dist/config.js +4 -5
  14. package/dist/{types-D3QGM8XO.js → diagnostics-LgIWyeSp.js} +28 -27
  15. package/dist/{dir-zw6bGMKQ.js → dir-TGLYuOZb.js} +34 -37
  16. package/dist/{duplicates-yuRljQ6h.js → duplicates-8cudcHNj.js} +10 -27
  17. package/dist/engine-ecRD8-IE.js +556 -0
  18. package/dist/engine.d.ts +1 -5
  19. package/dist/engine.js +297 -168
  20. package/dist/exchange-DjwlrTQ9.js +41 -0
  21. package/dist/{exclude-Du-Zd_qI.js → exclude-BFETmvde.js} +2 -3
  22. package/dist/{export-C9Sy6UWv.js → export-D2tsqWIr.js} +17 -38
  23. package/dist/{extract-C3S8btx0.js → extract-BxYchVmY.js} +114 -82
  24. package/dist/{formats-9unqj_fZ.js → formats-BaryZ2N7.js} +352 -276
  25. package/dist/fs-ezCMZeDV.js +52 -0
  26. package/dist/i18next-COO6o0tX.js +1907 -0
  27. package/dist/i18next-Dr7DCQlQ.js +1 -0
  28. package/dist/{import-nANvQutw.js → import-vSC29Cn4.js} +81 -75
  29. package/dist/index.d.ts +1 -13
  30. package/dist/index.js +14 -16
  31. package/dist/{init-C2ScuW6a.js → init-Cc7A-8VX.js} +466 -501
  32. package/dist/{library-D5CWvTQs.js → library-tp_xqzSY.js} +975 -451
  33. package/dist/lingui-BnnlqGXT.js +902 -0
  34. package/dist/lint.d.ts +0 -4
  35. package/dist/lint.js +70 -82
  36. package/dist/{load-gW-oJt1Q.js → load-BSIeGJ5v.js} +275 -148
  37. package/dist/{load-CQRz4PpM.js → load-SSrAeJVB.js} +1214 -1116
  38. package/dist/{locales-DX4MOBFE.js → locales-D0U-yVRm.js} +271 -237
  39. package/dist/{lsp-RMMMc88P.js → lsp-DvC11pBZ.js} +4 -5
  40. package/dist/{match-BGr8EXB3.js → match-BLDcj610.js} +11 -4
  41. package/dist/{mcp-CHVwBoRP.js → mcp-D2zzOTBy.js} +4 -5
  42. package/dist/{merge-driver-BTX87aVm.js → merge-driver-BLI8OtAc.js} +138 -122
  43. package/dist/migrate-1r43OBfe.js +1 -0
  44. package/dist/migrate-ChDGhlC-.js +2169 -0
  45. package/dist/{openai-CTaMDcl-.js → openai-CLn4puY8.js} +128 -87
  46. package/dist/{output-DWE3SIUA.js → output-D5tAt8q4.js} +15 -9
  47. package/dist/parse.d.ts +1 -3
  48. package/dist/parse.js +7 -8
  49. package/dist/{pipeline-C9Dbotkh.js → pipeline-BJSkkRYC.js} +387 -359
  50. package/dist/{pipeline-DbX6rlo5.js → pipeline-BeCc441z.js} +1 -1
  51. package/dist/project-B5KIO0q-.js +544 -0
  52. package/dist/{pseudo-DRv30iN5.js → pseudo-B2DUpoLu.js} +126 -3
  53. package/dist/{raw-C4Y6vyGY.js → raw-YsYZMS9n.js} +52 -29
  54. package/dist/react-intl-C8JehBBL.js +634 -0
  55. package/dist/rename-ZVGq9ZG1.js +577 -0
  56. package/dist/repeated-uuI1tUGg.js +85 -0
  57. package/dist/restore-xlBIrtRt.js +199 -0
  58. package/dist/rewrite-BwzXoBiA.js +415 -0
  59. package/dist/{rich-DCUKl5HM.js → rich-ApY1Dm4S.js} +35 -28
  60. package/dist/rolldown-runtime-C1I3wEg2.js +43 -0
  61. package/dist/{rolldown-runtime-D7D4PA-g.js → rolldown-runtime-D8jQpDG7.js} +1 -2
  62. package/dist/run-CQ9pDLSa.js +674 -0
  63. package/dist/scan-worker.d.ts +2 -4
  64. package/dist/scan-worker.js +1 -1
  65. package/dist/{scoped-BMYpSthj.js → scoped-h3KE8XWW.js} +3 -4
  66. package/dist/{server-Da1Ot9IN.js → server-Br8tAuG2.js} +312 -386
  67. package/dist/{server-deBOq2vq.js → server-DJRpUQVZ.js} +1059 -333
  68. package/dist/server.d.ts +1 -17
  69. package/dist/server.js +419 -379
  70. package/dist/{sitemap-DJXzKoza.js → sitemap-CSAkm6oi.js} +21 -33
  71. package/dist/{sources-D19czDSA.js → sources-DNVbYsgs.js} +713 -373
  72. package/dist/{status-zr4jY59Y.js → status-q6M3rBrh.js} +30 -30
  73. package/dist/{stdio-FPOKQAgu.js → stdio-D9kTzyqB.js} +2 -4
  74. package/dist/{stdio-CVaJfxA7.js → stdio-FWIVU3P4.js} +1 -2
  75. package/dist/sync-BNIAwMhR.js +1352 -0
  76. package/dist/{t-DC-c9zE5.js → t-gvEXx25s.js} +76 -53
  77. package/dist/test.d.ts +5 -16
  78. package/dist/test.js +126 -56
  79. package/dist/translate-BP4iVhOR.js +336 -0
  80. package/dist/{ts-BaU5yOf0.js → ts-BX6kwig5.js} +25 -14
  81. package/dist/{types-DtvQ7UdD.js → types-3kwyaCAm.js} +1 -2
  82. package/dist/{types-DsdWBG0b.d.ts → types-B4wNX6PA.d.ts} +6 -8
  83. package/dist/{types-CgUCkFU1.d.ts → types-_4UdFhR9.d.ts} +24 -21
  84. package/dist/types-xR2exI3L.js +42 -0
  85. package/dist/{units-CQ5Q99RC.js → units-DPPfCN7j.js} +7 -16
  86. package/dist/{url-CRfCOhUI.js → url-Bpc6wLea.js} +24 -11
  87. package/dist/{url-CsBkRaJy.js → url-D2_VlEeH.js} +25 -12
  88. package/dist/{validate-BxpupdAf.js → validate-CgzaDdOY.js} +690 -377
  89. package/dist/{validate-D6DJepZv.js → validate-PGgMsasz.js} +3 -5
  90. package/dist/{version-Byqi2guX.js → version-DC-J5WvV.js} +3 -5
  91. package/dist/{vite-scan-CT_vsp4g.js → vite-scan-kM8Ta3rO.js} +87 -92
  92. package/dist/vite.d.ts +2 -6
  93. package/dist/vite.js +6500 -6032
  94. package/dist/vue-i18n-_uIXlFVh.js +806 -0
  95. package/dist/{which-BOemZ5Q8.js → which-DFWk_KwN.js} +44 -37
  96. package/dist/{worker-84U6uYB3.js → worker-zlhNj4y3.js} +454 -608
  97. package/package.json +5 -5
  98. package/dist/check-HsmmpJZg.js +0 -1
  99. package/dist/codec-DuvU2VQy.js +0 -207
  100. package/dist/collisions-CfpZU8e4.js +0 -217
  101. package/dist/compile-BaDh0cHG.js +0 -245
  102. package/dist/concurrency-C9UUWuDC.js +0 -96
  103. package/dist/concurrency-DONL7t4V.js +0 -1
  104. package/dist/engine-C2ENBRJe.js +0 -531
  105. package/dist/i18next-9HAoxwUI.js +0 -1
  106. package/dist/i18next-BEJgv_S8.js +0 -1596
  107. package/dist/lingui-zUiCl9Um.js +0 -833
  108. package/dist/messages-BfjIExyB.js +0 -166
  109. package/dist/migrate-IpLDMXmq.js +0 -1484
  110. package/dist/migrate-rCQuOGsf.js +0 -1
  111. package/dist/project-Bw9UPIdx.js +0 -1046
  112. package/dist/project-C4GpaN-n.js +0 -381
  113. package/dist/react-intl-BP0u-D5m.js +0 -519
  114. package/dist/restore-CiYv-jxS.js +0 -175
  115. package/dist/rewrite-EsIw_lsq.js +0 -803
  116. package/dist/run-BEcnBbu-.js +0 -694
  117. package/dist/runtime-DTMmliT1.js +0 -64
  118. package/dist/sync-B9V2KFwb.js +0 -658
  119. package/dist/translate-CQnJfLjO.js +0 -299
  120. package/dist/types-wSh9fCBY.js +0 -11
  121. package/dist/vue-i18n-g0iGy6CZ.js +0 -651
@@ -1,6 +1,6 @@
1
- import { t as EXIT } from "./types-wSh9fCBY.js";
2
- import { t as protocolConsole } from "./stdio-CVaJfxA7.js";
3
- //#region src/cli/commands/lsp.ts
1
+ import { r as EXIT } from "./types-xR2exI3L.js";
2
+ import { t as protocolConsole } from "./stdio-FWIVU3P4.js";
3
+ // src/cli/commands/lsp.ts
4
4
  /**
5
5
  * `vi18n lsp [--stdio]` (INTERNALS §2.17): runs the language server on the
6
6
  * process's stdin and stdout until the editor exits it. The server and
@@ -10,7 +10,7 @@ import { t as protocolConsole } from "./stdio-CVaJfxA7.js";
10
10
  async function lsp(ctx, _flags) {
11
11
  const streams = ctx.io.streams;
12
12
  if (streams === void 0) throw new Error("vi18n lsp needs the process's stdin and stdout");
13
- const { startLanguageServer } = await import("./server-deBOq2vq.js");
13
+ const { startLanguageServer } = await import("./server-DJRpUQVZ.js");
14
14
  const restore = protocolConsole(streams.output);
15
15
  try {
16
16
  return {
@@ -27,5 +27,4 @@ async function lsp(ctx, _flags) {
27
27
  restore();
28
28
  }
29
29
  }
30
- //#endregion
31
30
  export { lsp };
@@ -1,5 +1,5 @@
1
- import { d as splitLocalePath, l as matchRoute, t as ROUTES, u as routePath } from "./url-CsBkRaJy.js";
2
- //#region src/runtime/match.ts
1
+ import { d as matchRoute, f as routePath, p as splitLocalePath, t as ROUTES } from "./url-D2_VlEeH.js";
2
+ // src/runtime/match.ts
3
3
  /**
4
4
  * The first candidate that reaches a configured locale: exactly, through its
5
5
  * maximized form's truncations (`zh-TW` → `zh-Hant-TW` → `zh-Hant` → `zh`),
@@ -63,6 +63,14 @@ function readCookie(cookies, name) {
63
63
  }
64
64
  /** Storage key of the `localStorage` strategy (INTERNALS §6 D29). */
65
65
  const STORAGE_KEY = "vi18n_locale";
66
+ /**
67
+ * Header the client runtime adds to same-origin `fetch` calls
68
+ * (`routing.propagate`). The engine spells it, and the zone cookie, inline:
69
+ * a shared binding measured larger in its bundle.
70
+ */
71
+ const LOCALE_HEADER = "x-vi18n-locale";
72
+ /** Cookie the client runtime writes with the browser's IANA zone. */
73
+ const TIME_ZONE_COOKIE = "vi18n_tz";
66
74
  /** The client steps of §2.11.9: the effective chain, first result wins. */
67
75
  function clientLocale(config, input) {
68
76
  const { locales, sourceLocale } = config;
@@ -85,5 +93,4 @@ function clientLocale(config, input) {
85
93
  source: "default"
86
94
  };
87
95
  }
88
- //#endregion
89
- export { strategyFor as a, readCookie as i, clientLocale as n, urlLocale as o, matchLocale as r, STORAGE_KEY as t };
96
+ export { matchLocale as a, urlLocale as c, clientLocale as i, STORAGE_KEY as n, readCookie as o, TIME_ZONE_COOKIE as r, strategyFor as s, LOCALE_HEADER as t };
@@ -1,10 +1,10 @@
1
- import { t as EXIT } from "./types-wSh9fCBY.js";
2
- import { t as protocolConsole } from "./stdio-CVaJfxA7.js";
3
- //#region src/cli/commands/mcp.ts
1
+ import { t as protocolConsole } from "./stdio-FWIVU3P4.js";
2
+ import { r as EXIT } from "./types-xR2exI3L.js";
3
+ // src/cli/commands/mcp.ts
4
4
  async function mcp(ctx, _flags) {
5
5
  const streams = ctx.io.streams;
6
6
  if (streams === void 0) throw new Error("vi18n mcp needs the process's stdin and stdout");
7
- const { serveMcp } = await import("./server-Da1Ot9IN.js");
7
+ const { serveMcp } = await import("./server-Br8tAuG2.js");
8
8
  const restore = protocolConsole(streams.output);
9
9
  try {
10
10
  await serveMcp({
@@ -24,5 +24,4 @@ async function mcp(ctx, _flags) {
24
24
  restore();
25
25
  }
26
26
  }
27
- //#endregion
28
27
  export { mcp };
@@ -1,25 +1,21 @@
1
- import { d as parseCatalogBytes, o as catalogLayout, p as serializeCatalog } from "./library-D5CWvTQs.js";
2
- import { n as loadConfig } from "./load-gW-oJt1Q.js";
3
- import { t as VERSION } from "./version-Byqi2guX.js";
4
- import { r as plural } from "./output-DWE3SIUA.js";
5
- import { t as EXIT } from "./types-wSh9fCBY.js";
1
+ import { D as flagKey, O as stricterLimit, d as parseCatalogBytes, o as catalogLayout, p as serializeCatalog, v as STATE_RANK, y as catalogIdentity } from "./library-tp_xqzSY.js";
2
+ import { r as loadConfig } from "./load-BSIeGJ5v.js";
3
+ import { n as isDiagnosticError } from "./diagnostics-LgIWyeSp.js";
4
+ import { t as VERSION } from "./version-DC-J5WvV.js";
5
+ import { o as errorMessage, r as plural } from "./output-D5tAt8q4.js";
6
+ import { r as EXIT } from "./types-xR2exI3L.js";
6
7
  import { dirname, resolve } from "node:path";
7
8
  import { readFile, writeFile } from "node:fs/promises";
8
9
  import { promisify } from "node:util";
9
10
  import { execFile } from "node:child_process";
10
- //#region src/core/catalog/merge.ts
11
- /** The identity git-level tools use: `msgctxt` + `msgid`, or the JSON key. */
12
- function mergeKey(entry, layout) {
13
- if (layout === "json") return entry.manualId ?? entry.label ?? "";
14
- return `${entry.manualId ?? entry.foreignContext ?? ""}\u0004${(layout === "id" ? entry.label : entry.source) ?? ""}`;
15
- }
11
+ // src/core/catalog/merge.ts
16
12
  function index(catalog, layout) {
17
13
  const side = {
18
14
  first: /* @__PURE__ */ new Map(),
19
15
  rest: []
20
16
  };
21
17
  for (const entry of catalog?.entries ?? []) {
22
- const key = mergeKey(entry, layout);
18
+ const key = catalogIdentity(entry, layout);
23
19
  if (side.first.has(key)) side.rest.push(entry);
24
20
  else side.first.set(key, entry);
25
21
  }
@@ -83,63 +79,73 @@ function mergeList(base, ours, theirs, id) {
83
79
  return out;
84
80
  }
85
81
  const text = (value) => value;
86
- const flagId = (flag) => `${flag.line}${flag.name}`;
87
- const RANK = {
88
- translated: 2,
89
- ai: 1,
90
- untranslated: 0
91
- };
92
- function mergeEntry(base, ours, theirs) {
93
- const sorted = (values) => values.slice().sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
82
+ /** The fields that merge as sets, and `maxLength` and `extra`, which merge as values with a tie rule. */
83
+ function mergeShared(base, ours, theirs) {
94
84
  const common = {
95
85
  ...ours,
96
- refs: sorted(mergeList(base?.refs ?? [], ours.refs, theirs.refs, text)),
86
+ refs: mergeList(base?.refs ?? [], ours.refs, theirs.refs, text).sort(),
97
87
  contexts: mergeList(base?.contexts ?? [], ours.contexts, theirs.contexts, text),
98
88
  comments: mergeList(base?.comments ?? [], ours.comments, theirs.comments, text),
99
- flags: mergeList(base?.flags ?? [], ours.flags, theirs.flags, flagId),
89
+ flags: mergeList(base?.flags ?? [], ours.flags, theirs.flags, flagKey),
100
90
  line: 0,
101
91
  wrapped: false
102
92
  };
103
93
  const was = from(base);
104
94
  const maxLength = pick(was((e) => e.maxLength), ours.maxLength, theirs.maxLength, equal);
105
- common.maxLength = maxLength !== null ? maxLength.value : ours.maxLength === null ? theirs.maxLength : theirs.maxLength === null ? ours.maxLength : Math.min(ours.maxLength, theirs.maxLength);
95
+ common.maxLength = maxLength === null ? stricterLimit(ours.maxLength, theirs.maxLength) : maxLength.value;
106
96
  const extra = pick(was((e) => e.extra), ours.extra, theirs.extra, sameJson);
107
97
  const extraValue = extra === null ? ours.extra : extra.value;
108
98
  if (extraValue === void 0) delete common.extra;
109
99
  else common.extra = extraValue;
110
- let conflict = false;
100
+ return common;
101
+ }
102
+ const sourceOf = (entry) => ({
103
+ source: entry.source,
104
+ label: entry.label
105
+ });
106
+ const valueOf = (entry) => ({
107
+ translation: entry.translation,
108
+ state: entry.state,
109
+ fuzzy: entry.fuzzy
110
+ });
111
+ /**
112
+ * A translation belongs to the source it was made for (D10): one side's new
113
+ * translation cannot land on a source only the other side changed, which
114
+ * git's line merge also refuses, since `source` and `translation` (or
115
+ * `#. source:` and `msgstr`) are adjacent lines.
116
+ */
117
+ function isStale(base, ours, theirs) {
118
+ const moved = (entry) => !sameJson(sourceOf(base), sourceOf(entry));
119
+ const edited = (entry) => !sameJson(valueOf(base), valueOf(entry));
120
+ return moved(ours) && !moved(theirs) && edited(theirs) || moved(theirs) && !moved(ours) && edited(ours);
121
+ }
122
+ function mergeEntry(base, ours, theirs) {
123
+ const common = mergeShared(base, ours, theirs);
111
124
  const oursView = { ...common };
112
125
  const theirsView = { ...common };
113
- const sourceOf = (entry) => ({
114
- source: entry.source,
115
- label: entry.label
116
- });
117
- const valueOf = (entry) => ({
118
- translation: entry.translation,
119
- state: entry.state,
120
- fuzzy: entry.fuzzy
121
- });
126
+ const was = from(base);
122
127
  const source = pick(was(sourceOf), sourceOf(ours), sourceOf(theirs), sameJson);
123
128
  let value = pick(was(valueOf), valueOf(ours), valueOf(theirs), sameJson);
124
- if (value === null && ours.translation === theirs.translation && ours.fuzzy === theirs.fuzzy) value = { value: RANK[ours.state] >= RANK[theirs.state] ? valueOf(ours) : valueOf(theirs) };
125
- let stale = false;
126
- if (base !== void 0 && source !== null && value !== null) {
127
- const moved = (entry) => !sameJson(sourceOf(base), sourceOf(entry));
128
- const edited = (entry) => !sameJson(valueOf(base), valueOf(entry));
129
- stale = moved(ours) && !moved(theirs) && edited(theirs) || moved(theirs) && !moved(ours) && edited(ours);
129
+ if (value === null && ours.translation === theirs.translation && ours.fuzzy === theirs.fuzzy) {
130
+ const oursWins = STATE_RANK[ours.state] >= STATE_RANK[theirs.state];
131
+ value = { value: valueOf(oursWins ? ours : theirs) };
130
132
  }
133
+ const stale = base !== void 0 && source !== null && value !== null && isStale(base, ours, theirs);
131
134
  if (source === null || value === null || stale) {
132
- conflict = true;
133
135
  Object.assign(oursView, sourceOf(ours), valueOf(ours));
134
136
  Object.assign(theirsView, sourceOf(theirs), valueOf(theirs));
135
- } else {
136
- Object.assign(oursView, source.value, value.value);
137
- Object.assign(theirsView, source.value, value.value);
137
+ return {
138
+ ours: oursView,
139
+ theirs: theirsView,
140
+ conflict: true
141
+ };
138
142
  }
143
+ Object.assign(oursView, source.value, value.value);
144
+ Object.assign(theirsView, source.value, value.value);
139
145
  return {
140
146
  ours: oursView,
141
147
  theirs: theirsView,
142
- conflict
148
+ conflict: false
143
149
  };
144
150
  }
145
151
  function mergeHeader(base, ours, theirs) {
@@ -276,30 +282,24 @@ function mergeCatalogs(input) {
276
282
  conflicts,
277
283
  conflicting
278
284
  };
279
- const theirsText = serializeCatalog(view(header.theirs, theirsEntries), options);
280
- const left = blocks(oursText, layout);
281
- const right = blocks(theirsText, layout);
282
- let lines;
283
- if (left.length !== right.length) {
284
- lines = conflictLines(oursText.split("\n"), theirsText.split("\n"));
285
- return {
286
- text: `${lines.join("\n")}\n`,
287
- conflicts,
288
- conflicting
289
- };
290
- }
291
- const separator = layout === "json" ? "\n" : "\n\n";
292
285
  return {
293
- text: `${left.map((block, i) => {
294
- const other = right[i];
295
- return (block.length === other.length && block.every((line, k) => line === other[k]) ? block : conflictLines(block, other)).join("\n");
296
- }).join(separator)}\n`,
286
+ text: conflictText(oursText, serializeCatalog(view(header.theirs, theirsEntries), options), layout),
297
287
  conflicts,
298
288
  conflicting
299
289
  };
300
290
  }
301
- //#endregion
302
- //#region src/cli/commands/merge-driver.ts
291
+ /** The two views of the file, with conflict markers around each entry whose blocks differ. */
292
+ function conflictText(oursText, theirsText, layout) {
293
+ const left = blocks(oursText, layout);
294
+ const right = blocks(theirsText, layout);
295
+ if (left.length !== right.length) return `${conflictLines(oursText.split("\n"), theirsText.split("\n")).join("\n")}\n`;
296
+ const separator = layout === "json" ? "\n" : "\n\n";
297
+ return `${left.map((block, i) => {
298
+ const other = right[i];
299
+ return (block.length === other.length && block.every((line, k) => line === other[k]) ? block : conflictLines(block, other)).join("\n");
300
+ }).join(separator)}\n`;
301
+ }
302
+ // src/cli/commands/merge-driver.ts
303
303
  /**
304
304
  * `vi18n merge-driver <base> <ours> <theirs> [<path>]` (PLAN §4.4 P2,
305
305
  * INTERNALS §2.6.10): the catalog merge driver git runs as
@@ -311,16 +311,18 @@ function mergeCatalogs(input) {
311
311
  * failure never loses either side.
312
312
  */
313
313
  const run = promisify(execFile);
314
+ /** The config the catalog belongs to, or why there is none (the reason a line merge runs instead). */
314
315
  async function findConfig(ctx, start) {
316
+ let config;
315
317
  try {
316
- const config = await loadConfig({
318
+ config = await loadConfig({
317
319
  cwd: start,
318
320
  configFile: ctx.global.config
319
321
  });
320
- return config.configFile === null ? null : config;
321
- } catch {
322
- return null;
322
+ } catch (error) {
323
+ return `vi18n.config.ts could not be loaded (${isDiagnosticError(error) ? error.diagnostic.message : errorMessage(error)}); fix it`;
323
324
  }
325
+ return config.configFile === null ? "no vi18n.config.ts found" : config;
324
326
  }
325
327
  /** Parses one side; null when it is not a catalog vi18n reads without errors. */
326
328
  function read(bytes, layout, locale, isSourceLocale) {
@@ -333,9 +335,11 @@ function read(bytes, layout, locale, isSourceLocale) {
333
335
  }
334
336
  async function mergeDriver(ctx, flags) {
335
337
  const cwd = ctx.global.cwd;
336
- const base = resolve(cwd, flags.base);
337
- const ours = resolve(cwd, flags.ours);
338
- const theirs = resolve(cwd, flags.theirs);
338
+ const files = {
339
+ base: resolve(cwd, flags.base),
340
+ ours: resolve(cwd, flags.ours),
341
+ theirs: resolve(cwd, flags.theirs)
342
+ };
339
343
  const data = {
340
344
  path: flags.path,
341
345
  conflicts: 0,
@@ -343,63 +347,19 @@ async function mergeDriver(ctx, flags) {
343
347
  fallback: false
344
348
  };
345
349
  const shown = flags.path ?? flags.ours;
346
- const fallback = async (reason) => {
347
- data.fallback = true;
350
+ const fallback = (reason) => {
348
351
  ctx.out.note(`vi18n merge-driver: ${shown}: ${reason}; merging lines with git merge-file`);
349
- try {
350
- await run("git", [
351
- "merge-file",
352
- "-L",
353
- "ours",
354
- "-L",
355
- "base",
356
- "-L",
357
- "theirs",
358
- ours,
359
- base,
360
- theirs
361
- ]);
362
- return {
363
- exitCode: EXIT.ok,
364
- data
365
- };
366
- } catch (error) {
367
- const status = error.code;
368
- if (typeof status === "number" && status > 0) {
369
- data.conflicts = status;
370
- return {
371
- exitCode: EXIT.failure,
372
- data
373
- };
374
- }
375
- throw error;
376
- }
352
+ return lineMerge(files, data);
377
353
  };
378
354
  const config = await findConfig(ctx, flags.path === null ? cwd : dirname(resolve(cwd, flags.path)));
379
- if (config === null) return fallback("no vi18n.config.ts found");
380
- const layout = catalogLayout(config);
381
- const [baseBytes, oursBytes, theirsBytes] = await Promise.all([
382
- base,
383
- ours,
384
- theirs
385
- ].map((file) => readFile(file)));
386
- const probe = read(oursBytes, layout, "", false) ?? read(theirsBytes, layout, "", false);
387
- if (probe === null) return fallback("a side is not a catalog vi18n can read");
388
- const locale = probe.header.language;
389
- const isSourceLocale = locale === config.sourceLocale;
390
- const mine = read(oursBytes, layout, locale, isSourceLocale);
391
- const other = read(theirsBytes, layout, locale, isSourceLocale);
392
- const empty = baseBytes.toString("utf8").trim() === "";
393
- const was = empty ? null : read(baseBytes, layout, locale, isSourceLocale);
394
- if (mine === null || other === null || !empty && was === null) return fallback("a side is not a catalog vi18n can read");
355
+ if (typeof config === "string") return fallback(config);
356
+ const sides = await readSides(config, files);
357
+ if (sides === null) return fallback("a side is not a catalog vi18n can read");
395
358
  const outcome = mergeCatalogs({
396
- base: was,
397
- ours: mine,
398
- theirs: other,
399
- isSourceLocale,
359
+ ...sides,
400
360
  version: VERSION
401
361
  });
402
- await writeFile(ours, outcome.text);
362
+ await writeFile(files.ours, outcome.text);
403
363
  data.conflicts = outcome.conflicts;
404
364
  data.conflicting = outcome.conflicting;
405
365
  if (outcome.conflicts === 0) return {
@@ -418,5 +378,61 @@ async function mergeDriver(ctx, flags) {
418
378
  data
419
379
  };
420
380
  }
421
- //#endregion
381
+ /** The three sides as catalogs; null when one is not a catalog vi18n reads without errors. */
382
+ async function readSides(config, files) {
383
+ const layout = catalogLayout(config);
384
+ const [baseBytes, oursBytes, theirsBytes] = await Promise.all([
385
+ readFile(files.base),
386
+ readFile(files.ours),
387
+ readFile(files.theirs)
388
+ ]);
389
+ const probe = read(oursBytes, layout, "", false) ?? read(theirsBytes, layout, "", false);
390
+ if (probe === null) return null;
391
+ const locale = probe.header.language;
392
+ const isSourceLocale = locale === config.sourceLocale;
393
+ const ours = read(oursBytes, layout, locale, isSourceLocale);
394
+ const theirs = read(theirsBytes, layout, locale, isSourceLocale);
395
+ const empty = baseBytes.toString("utf8").trim() === "";
396
+ const base = empty ? null : read(baseBytes, layout, locale, isSourceLocale);
397
+ if (ours === null || theirs === null || !empty && base === null) return null;
398
+ return {
399
+ base,
400
+ ours,
401
+ theirs,
402
+ isSourceLocale
403
+ };
404
+ }
405
+ /** git's own line merge into `<ours>`; a positive status is the number of conflicts left as markers. */
406
+ async function lineMerge(files, data) {
407
+ data.fallback = true;
408
+ const { base, ours, theirs } = files;
409
+ try {
410
+ await run("git", [
411
+ "merge-file",
412
+ "-L",
413
+ "ours",
414
+ "-L",
415
+ "base",
416
+ "-L",
417
+ "theirs",
418
+ ours,
419
+ base,
420
+ theirs
421
+ ]);
422
+ return {
423
+ exitCode: EXIT.ok,
424
+ data
425
+ };
426
+ } catch (error) {
427
+ const status = error.code;
428
+ if (typeof status === "number" && status > 0) {
429
+ data.conflicts = status;
430
+ return {
431
+ exitCode: EXIT.failure,
432
+ data
433
+ };
434
+ }
435
+ throw error;
436
+ }
437
+ }
422
438
  export { mergeDriver };
@@ -0,0 +1 @@
1
+ export { c as migrate } from "./migrate-ChDGhlC-.js";