@worldware/msg-cli 0.5.1 → 0.5.2

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.
@@ -154,17 +154,6 @@ function selectMessageToPgsExport(source) {
154
154
  }
155
155
  return selectMessageDataToPgsExport(msg);
156
156
  }
157
- function parsePatternFromSegmentBody(body) {
158
- const trimmed = body.trim();
159
- if (!trimmed) return [];
160
- try {
161
- const m = parseMessage(trimmed);
162
- if (m.type !== "message") return [];
163
- return m.pattern;
164
- } catch {
165
- return [];
166
- }
167
- }
168
157
  function ensureFallbackVariant(keysCount, variants) {
169
158
  const hasAllStars = variants.some(
170
159
  (v) => v.keys.length === keysCount && v.keys.every((k) => isCatchallKey(k))
@@ -226,11 +215,13 @@ function pgsImportToSelectMessage(switchAttr, segments) {
226
215
  const tokens = seg.caseAttr.trim().split(/\s+/).filter(Boolean);
227
216
  if (tokens.length !== n) return null;
228
217
  const keys = tokens.map(
229
- (t, i) => pgsTokenToMf2Key(t, parsedSwitch[i].kind)
218
+ (t, i2) => pgsTokenToMf2Key(t, parsedSwitch[i2].kind)
230
219
  );
231
220
  variants.push({
232
221
  keys,
233
- value: parsePatternFromSegmentBody(seg.body)
222
+ // Empty pattern: stringify emits `{{}}`, then we splice the raw XLIFF
223
+ // body so `\t` / `\n` / `\{` are not dropped or double-escaped.
224
+ value: []
234
225
  });
235
226
  }
236
227
  if (variants.length === 0) return null;
@@ -248,9 +239,15 @@ function pgsImportToSelectMessage(switchAttr, segments) {
248
239
  } catch {
249
240
  return null;
250
241
  }
251
- return stringifyMessage(
242
+ const bodies = segments.map((seg) => seg.body);
243
+ while (bodies.length < msg.variants.length) {
244
+ bodies.push(segments[segments.length - 1]?.body ?? "");
245
+ }
246
+ const skeleton = stringifyMessage(
252
247
  msg
253
248
  );
249
+ let i = 0;
250
+ return skeleton.replace(/\{\{\}\}/g, () => `{{${bodies[i++] ?? ""}}}`);
254
251
  }
255
252
  function messagesStructurallyEqual(a, b) {
256
253
  try {
@@ -3,10 +3,10 @@ import {
3
3
  } from "./chunk-Q775ZGC5.mjs";
4
4
  import {
5
5
  pgsImportToMf1Message
6
- } from "./chunk-XID5J2F7.mjs";
6
+ } from "./chunk-PQJA3H4Z.mjs";
7
7
  import {
8
8
  pgsImportToSelectMessage
9
- } from "./chunk-MGHC4AYZ.mjs";
9
+ } from "./chunk-HH6ZOHO4.mjs";
10
10
  import {
11
11
  dynamicImportFromUrl
12
12
  } from "./chunk-PO2Z7EWJ.mjs";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  parsePgsSwitch,
3
3
  selectMessageDataToPgsExport
4
- } from "./chunk-MGHC4AYZ.mjs";
4
+ } from "./chunk-HH6ZOHO4.mjs";
5
5
 
6
6
  // src/lib/pgs-mf1.ts
7
7
  import { parse } from "@messageformat/parser";
@@ -4,10 +4,10 @@ import {
4
4
  } from "./chunk-Q775ZGC5.mjs";
5
5
  import {
6
6
  mf1MessageToPgsExport
7
- } from "./chunk-XID5J2F7.mjs";
7
+ } from "./chunk-PQJA3H4Z.mjs";
8
8
  import {
9
9
  selectMessageToPgsExport
10
- } from "./chunk-MGHC4AYZ.mjs";
10
+ } from "./chunk-HH6ZOHO4.mjs";
11
11
  import {
12
12
  dynamicImportFromUrl
13
13
  } from "./chunk-PO2Z7EWJ.mjs";
@@ -5,10 +5,10 @@ import {
5
5
  importMsgResourcesFromPaths,
6
6
  serializeResourceGroupsToXliff,
7
7
  writeXliffFiles
8
- } from "../chunk-PYIBLOWY.mjs";
8
+ } from "../chunk-ZAU52MSA.mjs";
9
9
  import "../chunk-Q775ZGC5.mjs";
10
- import "../chunk-XID5J2F7.mjs";
11
- import "../chunk-MGHC4AYZ.mjs";
10
+ import "../chunk-PQJA3H4Z.mjs";
11
+ import "../chunk-HH6ZOHO4.mjs";
12
12
  import "../chunk-PO2Z7EWJ.mjs";
13
13
  import {
14
14
  loadPackageJsonForMsg
@@ -171,17 +171,6 @@ function pgsTokenToMf2Key(token, kind) {
171
171
  }
172
172
  return { type: "literal", value: token };
173
173
  }
174
- function parsePatternFromSegmentBody(body) {
175
- const trimmed = body.trim();
176
- if (!trimmed) return [];
177
- try {
178
- const m = (0, import_messageformat.parseMessage)(trimmed);
179
- if (m.type !== "message") return [];
180
- return m.pattern;
181
- } catch {
182
- return [];
183
- }
184
- }
185
174
  function ensureFallbackVariant(keysCount, variants) {
186
175
  const hasAllStars = variants.some(
187
176
  (v) => v.keys.length === keysCount && v.keys.every((k) => (0, import_messageformat.isCatchallKey)(k))
@@ -243,11 +232,13 @@ function pgsImportToSelectMessage(switchAttr, segments) {
243
232
  const tokens = seg.caseAttr.trim().split(/\s+/).filter(Boolean);
244
233
  if (tokens.length !== n) return null;
245
234
  const keys = tokens.map(
246
- (t, i) => pgsTokenToMf2Key(t, parsedSwitch[i].kind)
235
+ (t, i2) => pgsTokenToMf2Key(t, parsedSwitch[i2].kind)
247
236
  );
248
237
  variants.push({
249
238
  keys,
250
- value: parsePatternFromSegmentBody(seg.body)
239
+ // Empty pattern: stringify emits `{{}}`, then we splice the raw XLIFF
240
+ // body so `\t` / `\n` / `\{` are not dropped or double-escaped.
241
+ value: []
251
242
  });
252
243
  }
253
244
  if (variants.length === 0) return null;
@@ -265,9 +256,15 @@ function pgsImportToSelectMessage(switchAttr, segments) {
265
256
  } catch {
266
257
  return null;
267
258
  }
268
- return (0, import_messageformat.stringifyMessage)(
259
+ const bodies = segments.map((seg) => seg.body);
260
+ while (bodies.length < msg.variants.length) {
261
+ bodies.push(segments[segments.length - 1]?.body ?? "");
262
+ }
263
+ const skeleton = (0, import_messageformat.stringifyMessage)(
269
264
  msg
270
265
  );
266
+ let i = 0;
267
+ return skeleton.replace(/\{\{\}\}/g, () => `{{${bodies[i++] ?? ""}}}`);
271
268
  }
272
269
 
273
270
  // src/lib/pgs-mf1.ts
@@ -5,10 +5,10 @@ import {
5
5
  parseXliffFilename,
6
6
  processXliffFile,
7
7
  writeTranslationFiles
8
- } from "../chunk-MPDE5BUV.mjs";
8
+ } from "../chunk-NJKP7C5U.mjs";
9
9
  import "../chunk-Q775ZGC5.mjs";
10
- import "../chunk-XID5J2F7.mjs";
11
- import "../chunk-MGHC4AYZ.mjs";
10
+ import "../chunk-PQJA3H4Z.mjs";
11
+ import "../chunk-HH6ZOHO4.mjs";
12
12
  import "../chunk-PO2Z7EWJ.mjs";
13
13
  import {
14
14
  loadPackageJsonForMsg
@@ -5,10 +5,10 @@ import {
5
5
  importMsgResourcesFromPaths,
6
6
  serializeResourceGroupsToXliff,
7
7
  writeXliffFiles
8
- } from "../chunk-PYIBLOWY.mjs";
8
+ } from "../chunk-ZAU52MSA.mjs";
9
9
  import "../chunk-Q775ZGC5.mjs";
10
- import "../chunk-XID5J2F7.mjs";
11
- import "../chunk-MGHC4AYZ.mjs";
10
+ import "../chunk-PQJA3H4Z.mjs";
11
+ import "../chunk-HH6ZOHO4.mjs";
12
12
  import "../chunk-PO2Z7EWJ.mjs";
13
13
  import "../chunk-F7XZRKP7.mjs";
14
14
  export {
@@ -111,17 +111,6 @@ function pgsTokenToMf2Key(token, kind) {
111
111
  }
112
112
  return { type: "literal", value: token };
113
113
  }
114
- function parsePatternFromSegmentBody(body) {
115
- const trimmed = body.trim();
116
- if (!trimmed) return [];
117
- try {
118
- const m = (0, import_messageformat.parseMessage)(trimmed);
119
- if (m.type !== "message") return [];
120
- return m.pattern;
121
- } catch {
122
- return [];
123
- }
124
- }
125
114
  function ensureFallbackVariant(keysCount, variants) {
126
115
  const hasAllStars = variants.some(
127
116
  (v) => v.keys.length === keysCount && v.keys.every((k) => (0, import_messageformat.isCatchallKey)(k))
@@ -183,11 +172,13 @@ function pgsImportToSelectMessage(switchAttr, segments) {
183
172
  const tokens = seg.caseAttr.trim().split(/\s+/).filter(Boolean);
184
173
  if (tokens.length !== n) return null;
185
174
  const keys = tokens.map(
186
- (t, i) => pgsTokenToMf2Key(t, parsedSwitch[i].kind)
175
+ (t, i2) => pgsTokenToMf2Key(t, parsedSwitch[i2].kind)
187
176
  );
188
177
  variants.push({
189
178
  keys,
190
- value: parsePatternFromSegmentBody(seg.body)
179
+ // Empty pattern: stringify emits `{{}}`, then we splice the raw XLIFF
180
+ // body so `\t` / `\n` / `\{` are not dropped or double-escaped.
181
+ value: []
191
182
  });
192
183
  }
193
184
  if (variants.length === 0) return null;
@@ -205,9 +196,15 @@ function pgsImportToSelectMessage(switchAttr, segments) {
205
196
  } catch {
206
197
  return null;
207
198
  }
208
- return (0, import_messageformat.stringifyMessage)(
199
+ const bodies = segments.map((seg) => seg.body);
200
+ while (bodies.length < msg.variants.length) {
201
+ bodies.push(segments[segments.length - 1]?.body ?? "");
202
+ }
203
+ const skeleton = (0, import_messageformat.stringifyMessage)(
209
204
  msg
210
205
  );
206
+ let i = 0;
207
+ return skeleton.replace(/\{\{\}\}/g, () => `{{${bodies[i++] ?? ""}}}`);
211
208
  }
212
209
 
213
210
  // src/lib/pgs-mf1.ts
@@ -8,10 +8,10 @@ import {
8
8
  parseXliffFilename,
9
9
  processXliffFile,
10
10
  writeTranslationFiles
11
- } from "../chunk-MPDE5BUV.mjs";
11
+ } from "../chunk-NJKP7C5U.mjs";
12
12
  import "../chunk-Q775ZGC5.mjs";
13
- import "../chunk-XID5J2F7.mjs";
14
- import "../chunk-MGHC4AYZ.mjs";
13
+ import "../chunk-PQJA3H4Z.mjs";
14
+ import "../chunk-HH6ZOHO4.mjs";
15
15
  import "../chunk-PO2Z7EWJ.mjs";
16
16
  import "../chunk-F7XZRKP7.mjs";
17
17
  export {
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  mf1MessageToPgsExport,
3
3
  pgsImportToMf1Message
4
- } from "../chunk-XID5J2F7.mjs";
5
- import "../chunk-MGHC4AYZ.mjs";
4
+ } from "../chunk-PQJA3H4Z.mjs";
5
+ import "../chunk-HH6ZOHO4.mjs";
6
6
  export {
7
7
  mf1MessageToPgsExport,
8
8
  pgsImportToMf1Message
@@ -178,17 +178,6 @@ function selectMessageToPgsExport(source) {
178
178
  }
179
179
  return selectMessageDataToPgsExport(msg);
180
180
  }
181
- function parsePatternFromSegmentBody(body) {
182
- const trimmed = body.trim();
183
- if (!trimmed) return [];
184
- try {
185
- const m = (0, import_messageformat.parseMessage)(trimmed);
186
- if (m.type !== "message") return [];
187
- return m.pattern;
188
- } catch {
189
- return [];
190
- }
191
- }
192
181
  function ensureFallbackVariant(keysCount, variants) {
193
182
  const hasAllStars = variants.some(
194
183
  (v) => v.keys.length === keysCount && v.keys.every((k) => (0, import_messageformat.isCatchallKey)(k))
@@ -250,11 +239,13 @@ function pgsImportToSelectMessage(switchAttr, segments) {
250
239
  const tokens = seg.caseAttr.trim().split(/\s+/).filter(Boolean);
251
240
  if (tokens.length !== n) return null;
252
241
  const keys = tokens.map(
253
- (t, i) => pgsTokenToMf2Key(t, parsedSwitch[i].kind)
242
+ (t, i2) => pgsTokenToMf2Key(t, parsedSwitch[i2].kind)
254
243
  );
255
244
  variants.push({
256
245
  keys,
257
- value: parsePatternFromSegmentBody(seg.body)
246
+ // Empty pattern: stringify emits `{{}}`, then we splice the raw XLIFF
247
+ // body so `\t` / `\n` / `\{` are not dropped or double-escaped.
248
+ value: []
258
249
  });
259
250
  }
260
251
  if (variants.length === 0) return null;
@@ -272,9 +263,15 @@ function pgsImportToSelectMessage(switchAttr, segments) {
272
263
  } catch {
273
264
  return null;
274
265
  }
275
- return (0, import_messageformat.stringifyMessage)(
266
+ const bodies = segments.map((seg) => seg.body);
267
+ while (bodies.length < msg.variants.length) {
268
+ bodies.push(segments[segments.length - 1]?.body ?? "");
269
+ }
270
+ const skeleton = (0, import_messageformat.stringifyMessage)(
276
271
  msg
277
272
  );
273
+ let i = 0;
274
+ return skeleton.replace(/\{\{\}\}/g, () => `{{${bodies[i++] ?? ""}}}`);
278
275
  }
279
276
  function messagesStructurallyEqual(a, b) {
280
277
  try {
@@ -73,6 +73,9 @@ interface PgsSegmentImport {
73
73
  }
74
74
  /**
75
75
  * Builds MF2 source string from PGS `pgs:switch` and segment bodies.
76
+ *
77
+ * Segment bodies are spliced into quoted patterns as-is so XLIFF `\` sequences
78
+ * are not dropped (`\t`/`\n` are invalid MF2 escapes) or double-escaped.
76
79
  */
77
80
  declare function pgsImportToSelectMessage(switchAttr: string, segments: PgsSegmentImport[]): string | null;
78
81
  /** Compare two MF2 strings by parsing and re-stringifying both (for tests). */
@@ -73,6 +73,9 @@ interface PgsSegmentImport {
73
73
  }
74
74
  /**
75
75
  * Builds MF2 source string from PGS `pgs:switch` and segment bodies.
76
+ *
77
+ * Segment bodies are spliced into quoted patterns as-is so XLIFF `\` sequences
78
+ * are not dropped (`\t`/`\n` are invalid MF2 escapes) or double-escaped.
76
79
  */
77
80
  declare function pgsImportToSelectMessage(switchAttr: string, segments: PgsSegmentImport[]): string | null;
78
81
  /** Compare two MF2 strings by parsing and re-stringifying both (for tests). */
@@ -7,7 +7,7 @@ import {
7
7
  pgsTokenToMf2Key,
8
8
  selectMessageDataToPgsExport,
9
9
  selectMessageToPgsExport
10
- } from "../chunk-MGHC4AYZ.mjs";
10
+ } from "../chunk-HH6ZOHO4.mjs";
11
11
  export {
12
12
  classifySelectMessageForPgs,
13
13
  messagesStructurallyEqual,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@worldware/msg-cli",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "CLI for msg library",
5
5
  "main": "dist/commands/init.cjs",
6
6
  "module": "dist/commands/init.mjs",