@lingui/cli 4.11.1 → 4.11.3

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.
@@ -88,7 +88,7 @@ class Catalog {
88
88
  async collect(options = {}) {
89
89
  let paths = this.sourcePaths;
90
90
  if (options.files) {
91
- options.files = options.files.map((p) => (0, normalize_path_1.default)(p, false));
91
+ options.files = options.files.map((p) => (0, utils_1.makePathRegexSafe)((0, normalize_path_1.default)(p, false)));
92
92
  const regex = new RegExp(options.files.join("|"), "i");
93
93
  paths = paths.filter((path) => regex.test(path));
94
94
  }
@@ -57,12 +57,11 @@ function buildExportStatement(expression, namespace) {
57
57
  // import type { Messages } from "@lingui/core";
58
58
  const importMessagesTypeDeclaration = t.importDeclaration([t.importSpecifier(t.identifier("Messages"), t.identifier("Messages"))], t.stringLiteral("@lingui/core"));
59
59
  importMessagesTypeDeclaration.importKind = "type";
60
- // Create the exported `messages` identifier with a `Messages` TS type annotation
61
- const messagesIdentifier = t.identifier("messages");
62
- messagesIdentifier.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier("Messages")));
63
- // export const messages:Messages = { message: "Translation" }
60
+ // Cast the expression to `Messages`
61
+ const castExpression = t.tsAsExpression(expression, t.tsTypeReference(t.identifier("Messages")));
62
+ // export const messages = ({ message: "Translation" } as Messages)
64
63
  const exportDeclaration = t.exportNamedDeclaration(t.variableDeclaration("const", [
65
- t.variableDeclarator(messagesIdentifier, expression),
64
+ t.variableDeclarator(t.identifier("messages"), castExpression),
66
65
  ]));
67
66
  return t.program([importMessagesTypeDeclaration, exportDeclaration]);
68
67
  }
package/dist/api/help.js CHANGED
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.helpRun = void 0;
4
4
  /**
5
- * Detect where's is the command lingui extract or lingui compile
6
- * and how is being run (npm, yarn) and construct help
5
+ * Detect where is the command lingui extract or lingui compile
6
+ * and how is being run (npm, yarn, pnpm) and construct help
7
7
  * for follow-up commands based on that.
8
8
  *
9
9
  * Example:
@@ -15,6 +15,10 @@ exports.helpRun = void 0;
15
15
  * ...
16
16
  * (use "yarn lingui compile" to compile catalogs for production)
17
17
  *
18
+ * $ pnpm run extract
19
+ * ...
20
+ * (use "pnpm run compile" to compile catalogs for production)
21
+ *
18
22
  * $ npm run extract
19
23
  * ...
20
24
  * (use "npm run compile" to compile catalogs for production)
@@ -32,9 +36,20 @@ function helpRun(command) {
32
36
  command = res[0];
33
37
  }
34
38
  }
35
- const isYarn = process.env.npm_config_user_agent &&
36
- process.env.npm_config_user_agent.includes("yarn");
37
- const runCommand = isYarn ? "yarn" : "npm run";
39
+ const runCommand = runCommandFrom(process.env.npm_config_user_agent);
38
40
  return `${runCommand} ${command}`;
39
41
  }
40
42
  exports.helpRun = helpRun;
43
+ function runCommandFrom(userAgent) {
44
+ const defaultRunCommand = "npm run";
45
+ if (!userAgent) {
46
+ return defaultRunCommand;
47
+ }
48
+ if (userAgent.includes("yarn")) {
49
+ return "yarn";
50
+ }
51
+ if (userAgent.includes("pnpm")) {
52
+ return "pnpm run";
53
+ }
54
+ return defaultRunCommand;
55
+ }
@@ -18,3 +18,7 @@ export declare function normalizeSlashes(path: string): string;
18
18
  * Preserve absolute paths: /absolute/path => /absolute/path
19
19
  */
20
20
  export declare function normalizeRelativePath(sourcePath: string): string;
21
+ /**
22
+ * Escape special regex characters used in file-based routing systems
23
+ */
24
+ export declare function makePathRegexSafe(path: string): string;
package/dist/api/utils.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.normalizeRelativePath = exports.normalizeSlashes = exports.makeInstall = exports.hasYarn = exports.writeFileIfChanged = exports.writeFile = exports.isDirectory = exports.readFile = exports.replacePlaceholders = exports.prettyOrigin = exports.PATHSEP = void 0;
6
+ exports.makePathRegexSafe = exports.normalizeRelativePath = exports.normalizeSlashes = exports.makeInstall = exports.hasYarn = exports.writeFileIfChanged = exports.writeFile = exports.isDirectory = exports.readFile = exports.replacePlaceholders = exports.prettyOrigin = exports.PATHSEP = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const normalize_path_1 = __importDefault(require("normalize-path"));
@@ -110,3 +110,10 @@ function normalizeRelativePath(sourcePath) {
110
110
  (isDir ? "/" : ""));
111
111
  }
112
112
  exports.normalizeRelativePath = normalizeRelativePath;
113
+ /**
114
+ * Escape special regex characters used in file-based routing systems
115
+ */
116
+ function makePathRegexSafe(path) {
117
+ return path.replace(/[(){}[\]^$+]/g, "\\$&");
118
+ }
119
+ exports.makePathRegexSafe = makePathRegexSafe;
@@ -9,6 +9,8 @@ const pofile_1 = __importDefault(require("pofile"));
9
9
  const https_1 = __importDefault(require("https"));
10
10
  const glob_1 = __importDefault(require("glob"));
11
11
  const date_fns_1 = require("date-fns");
12
+ const EXPLICIT_ID_FLAG = "js-lingui-explicit-id";
13
+ const EXPLICIT_ID_AND_CONTEXT_FLAG = "js-lingui-explicit-id-and-context";
12
14
  const getCreateHeaders = (language) => ({
13
15
  "POT-Creation-Date": (0, date_fns_1.format)(new Date(), "yyyy-MM-dd HH:mmxxxx"),
14
16
  "MIME-Version": "1.0",
@@ -141,32 +143,64 @@ function sync(config, options, successCallback, failCallback) {
141
143
  });
142
144
  }
143
145
  function createSegmentFromPoItem(item) {
144
- const itemHasId = item.msgid != item.msgstr[0] && item.msgstr[0].length;
146
+ const itemHasExplicitId = item.extractedComments.includes(EXPLICIT_ID_FLAG);
147
+ const itemHasContext = item.msgctxt != null;
145
148
  const segment = {
146
149
  type: "source",
147
- source: itemHasId ? item.msgstr[0] : item.msgid,
150
+ source: "",
148
151
  context: "",
149
152
  references: [],
150
153
  comment: "",
151
154
  };
152
- if (itemHasId) {
155
+ // For segment.source & segment.context, we must remain compatible with projects created/synced before Lingui V4
156
+ if (itemHasExplicitId) {
157
+ segment.source = item.msgstr[0];
153
158
  segment.context = item.msgid;
154
159
  }
160
+ else {
161
+ segment.source = item.msgid;
162
+ if (itemHasContext) {
163
+ segment.context = item.msgctxt;
164
+ }
165
+ }
155
166
  if (item.references.length) {
156
167
  segment.references = item.references;
157
168
  }
169
+ // Since Lingui v4, when using explicit IDs, Lingui automatically adds 'js-lingui-explicit-id' to the extractedComments array
158
170
  if (item.extractedComments.length) {
159
171
  segment.comment = item.extractedComments.join(" | ");
172
+ if (itemHasExplicitId && itemHasContext) {
173
+ // segment.context is already used for the explicit ID, so we need to pass the context (for translators) in segment.comment
174
+ segment.comment = `${item.msgctxt} | ${segment.comment}`;
175
+ // Replace the flag to let us know how to recompose a target PO Item that is consistent with the source PO Item
176
+ segment.comment = segment.comment.replace(EXPLICIT_ID_FLAG, EXPLICIT_ID_AND_CONTEXT_FLAG);
177
+ }
160
178
  }
161
179
  return segment;
162
180
  }
163
181
  function createPoItemFromSegment(segment) {
182
+ var _a, _b;
183
+ const segmentHasExplicitId = (_a = segment.comment) === null || _a === void 0 ? void 0 : _a.includes(EXPLICIT_ID_FLAG);
184
+ const segmentHasExplicitIdAndContext = (_b = segment.comment) === null || _b === void 0 ? void 0 : _b.includes(EXPLICIT_ID_AND_CONTEXT_FLAG);
164
185
  const item = new pofile_1.default.Item();
165
- item.msgid = segment.context ? segment.context : segment.source;
186
+ if (segmentHasExplicitId || segmentHasExplicitIdAndContext) {
187
+ item.msgid = segment.context;
188
+ }
189
+ else {
190
+ item.msgid = segment.source;
191
+ item.msgctxt = segment.context;
192
+ }
166
193
  item.msgstr = [segment.target];
167
194
  item.references =
168
195
  segment.references && segment.references.length ? segment.references : [];
169
- item.extractedComments = segment.comment ? segment.comment.split(" | ") : [];
196
+ if (segment.comment) {
197
+ segment.comment = segment.comment.replace(EXPLICIT_ID_AND_CONTEXT_FLAG, EXPLICIT_ID_FLAG);
198
+ item.extractedComments = segment.comment ? segment.comment.split(" | ") : [];
199
+ // We recompose a target PO Item that is consistent with the source PO Item
200
+ if (segmentHasExplicitIdAndContext) {
201
+ item.msgctxt = item.extractedComments.shift();
202
+ }
203
+ }
170
204
  return item;
171
205
  }
172
206
  function saveSegmentsToTargetPos(config, paths, segmentsPerLocale) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/cli",
3
- "version": "4.11.1",
3
+ "version": "4.11.3",
4
4
  "description": "CLI for working wit message catalogs",
5
5
  "keywords": [
6
6
  "cli",
@@ -53,15 +53,15 @@
53
53
  "@babel/parser": "^7.21.2",
54
54
  "@babel/runtime": "^7.21.0",
55
55
  "@babel/types": "^7.21.2",
56
- "@lingui/babel-plugin-extract-messages": "4.11.1",
57
- "@lingui/conf": "4.11.1",
58
- "@lingui/core": "4.11.1",
59
- "@lingui/format-po": "4.11.1",
60
- "@lingui/message-utils": "4.11.1",
56
+ "@lingui/babel-plugin-extract-messages": "4.11.3",
57
+ "@lingui/conf": "4.11.3",
58
+ "@lingui/core": "4.11.3",
59
+ "@lingui/format-po": "4.11.3",
60
+ "@lingui/message-utils": "4.11.3",
61
61
  "babel-plugin-macros": "^3.0.1",
62
62
  "chalk": "^4.1.0",
63
63
  "chokidar": "3.5.1",
64
- "cli-table": "0.3.6",
64
+ "cli-table": "^0.3.11",
65
65
  "commander": "^10.0.0",
66
66
  "convert-source-map": "^2.0.0",
67
67
  "date-fns": "^3.6.0",
@@ -80,7 +80,7 @@
80
80
  },
81
81
  "devDependencies": {
82
82
  "@lingui/jest-mocks": "*",
83
- "@lingui/macro": "4.11.1",
83
+ "@lingui/macro": "4.11.3",
84
84
  "@types/convert-source-map": "^2.0.0",
85
85
  "@types/glob": "^8.1.0",
86
86
  "@types/micromatch": "^4.0.1",
@@ -88,5 +88,5 @@
88
88
  "mock-fs": "^5.2.0",
89
89
  "mockdate": "^3.0.5"
90
90
  },
91
- "gitHead": "ec49d0cc53dbc4f9e0f92f0edcdf59f3e5c1de1f"
91
+ "gitHead": "088efe57f23e88aee7ef72c58a45db427ecd78c9"
92
92
  }