@formatjs/cli-lib 8.1.0 → 8.1.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 (40) hide show
  1. package/index.d.ts +7 -7
  2. package/index.js +2 -2
  3. package/main.d.ts +0 -1
  4. package/main.js +1 -1
  5. package/package.json +4 -4
  6. package/src/cli.js +99 -153
  7. package/src/compile.d.ts +45 -45
  8. package/src/compile.js +79 -80
  9. package/src/compile_folder.d.ts +1 -1
  10. package/src/compile_folder.js +6 -6
  11. package/src/console_utils.d.ts +3 -1
  12. package/src/console_utils.js +44 -46
  13. package/src/extract.d.ts +68 -68
  14. package/src/extract.js +165 -178
  15. package/src/formatters/crowdin.d.ts +3 -3
  16. package/src/formatters/crowdin.js +19 -20
  17. package/src/formatters/default.d.ts +1 -1
  18. package/src/formatters/default.js +8 -7
  19. package/src/formatters/index.d.ts +6 -6
  20. package/src/formatters/index.js +29 -34
  21. package/src/formatters/lokalise.d.ts +5 -5
  22. package/src/formatters/lokalise.js +16 -17
  23. package/src/formatters/simple.d.ts +1 -1
  24. package/src/formatters/simple.js +7 -6
  25. package/src/formatters/smartling.d.ts +13 -15
  26. package/src/formatters/smartling.js +35 -40
  27. package/src/formatters/transifex.d.ts +5 -5
  28. package/src/formatters/transifex.js +16 -17
  29. package/src/gts_extractor.js +11 -11
  30. package/src/hbs_extractor.js +34 -41
  31. package/src/parse_script.d.ts +5 -5
  32. package/src/parse_script.js +40 -43
  33. package/src/pseudo_locale.d.ts +15 -15
  34. package/src/pseudo_locale.js +210 -94
  35. package/src/verify/checkExtraKeys.js +28 -32
  36. package/src/verify/checkMissingKeys.js +29 -33
  37. package/src/verify/checkStructuralEquality.js +67 -71
  38. package/src/verify/index.d.ts +5 -5
  39. package/src/verify/index.js +24 -27
  40. package/src/vue_extractor.js +52 -62
@@ -1,44 +1,39 @@
1
- export const format = msgs => {
2
- const results = {
3
- smartling: {
4
- translate_paths: [
5
- {
6
- path: '*/message',
7
- key: '{*}/message',
8
- instruction: '*/description',
9
- },
10
- ],
11
- variants_enabled: true,
12
- string_format: 'icu',
13
- },
14
- };
15
- for (const [id, msg] of Object.entries(msgs)) {
16
- results[id] = {
17
- message: msg.defaultMessage,
18
- description: typeof msg.description === 'string'
19
- ? msg.description
20
- : JSON.stringify(msg.description),
21
- };
22
- }
23
- return results;
1
+ import "./default.js";
2
+ export const format = (msgs) => {
3
+ const results = { smartling: {
4
+ translate_paths: [{
5
+ path: "*/message",
6
+ key: "{*}/message",
7
+ instruction: "*/description"
8
+ }],
9
+ variants_enabled: true,
10
+ string_format: "icu"
11
+ } };
12
+ for (const [id, msg] of Object.entries(msgs)) {
13
+ results[id] = {
14
+ message: msg.defaultMessage,
15
+ description: typeof msg.description === "string" ? msg.description : JSON.stringify(msg.description)
16
+ };
17
+ }
18
+ return results;
24
19
  };
25
20
  export const compareMessages = (el1, el2) => {
26
- // `smartling` has to be the 1st key
27
- if (el1.key === 'smartling') {
28
- return -1;
29
- }
30
- if (el2.key === 'smartling') {
31
- return 1;
32
- }
33
- return el1.key < el2.key ? -1 : el1.key === el2.key ? 0 : 1;
21
+ // `smartling` has to be the 1st key
22
+ if (el1.key === "smartling") {
23
+ return -1;
24
+ }
25
+ if (el2.key === "smartling") {
26
+ return 1;
27
+ }
28
+ return el1.key < el2.key ? -1 : el1.key === el2.key ? 0 : 1;
34
29
  };
35
- export const compile = msgs => {
36
- const results = {};
37
- for (const [id, msg] of Object.entries(msgs)) {
38
- if (id === 'smartling') {
39
- continue;
40
- }
41
- results[id] = msg.message;
42
- }
43
- return results;
30
+ export const compile = (msgs) => {
31
+ const results = {};
32
+ for (const [id, msg] of Object.entries(msgs)) {
33
+ if (id === "smartling") {
34
+ continue;
35
+ }
36
+ results[id] = msg.message;
37
+ }
38
+ return results;
44
39
  };
@@ -1,9 +1,9 @@
1
- import { CompileFn, FormatFn } from './default.js';
1
+ import { type CompileFn, type FormatFn } from "./default.js";
2
2
  export type StructuredJson = Record<string, {
3
- string: string;
4
- developer_comment?: string;
5
- context?: string;
6
- character_limit?: string;
3
+ string: string;
4
+ developer_comment?: string;
5
+ context?: string;
6
+ character_limit?: string;
7
7
  }>;
8
8
  export declare const format: FormatFn<StructuredJson>;
9
9
  export declare const compile: CompileFn<StructuredJson>;
@@ -1,19 +1,18 @@
1
- export const format = msgs => {
2
- const results = {};
3
- for (const [id, msg] of Object.entries(msgs)) {
4
- results[id] = {
5
- string: msg.defaultMessage,
6
- developer_comment: typeof msg.description === 'string'
7
- ? msg.description
8
- : JSON.stringify(msg.description),
9
- };
10
- }
11
- return results;
1
+ import "./default.js";
2
+ export const format = (msgs) => {
3
+ const results = {};
4
+ for (const [id, msg] of Object.entries(msgs)) {
5
+ results[id] = {
6
+ string: msg.defaultMessage,
7
+ developer_comment: typeof msg.description === "string" ? msg.description : JSON.stringify(msg.description)
8
+ };
9
+ }
10
+ return results;
12
11
  };
13
- export const compile = msgs => {
14
- const results = {};
15
- for (const [id, msg] of Object.entries(msgs)) {
16
- results[id] = msg.string;
17
- }
18
- return results;
12
+ export const compile = (msgs) => {
13
+ const results = {};
14
+ for (const [id, msg] of Object.entries(msgs)) {
15
+ results[id] = msg.string;
16
+ }
17
+ return results;
19
18
  };
@@ -1,14 +1,14 @@
1
- import { Preprocessor } from 'content-tag';
2
- import { parseFile as parseHbsFile } from './hbs_extractor.js';
3
- import { parseScript } from './parse_script.js';
1
+ import { Preprocessor } from "content-tag";
2
+ import { parseFile as parseHbsFile } from "./hbs_extractor.js";
3
+ import { parseScript } from "./parse_script.js";
4
4
  let p = new Preprocessor();
5
5
  export function parseFile(source, fileName, options) {
6
- const scriptParseFn = parseScript(options, fileName);
7
- const transformedSource = p.process(source, { filename: fileName });
8
- scriptParseFn(transformedSource.code);
9
- // extract template from transformed source to then run through hbs processor
10
- const parseResult = p.parse(source, { filename: fileName });
11
- for (let parsed of parseResult) {
12
- parseHbsFile(parsed.contents, fileName, options);
13
- }
6
+ const scriptParseFn = parseScript(options, fileName);
7
+ const transformedSource = p.process(source, { filename: fileName });
8
+ scriptParseFn(transformedSource.code);
9
+ // extract template from transformed source to then run through hbs processor
10
+ const parseResult = p.parse(source, { filename: fileName });
11
+ for (let parsed of parseResult) {
12
+ parseHbsFile(parsed.contents, fileName, options);
13
+ }
14
14
  }
@@ -1,45 +1,38 @@
1
- import { transform } from 'ember-template-recast';
1
+ import "@formatjs/ts-transformer";
2
+ import { transform } from "ember-template-recast";
2
3
  function extractText(node, fileName, options) {
3
- if (!options.onMsgExtracted)
4
- return;
5
- if (!options.overrideIdFn)
6
- return;
7
- if (node.path.type !== 'PathExpression')
8
- return;
9
- if (['format-message', 'formatMessage'].includes(node.path.original)) {
10
- let [first, second] = node.params;
11
- if (first.type !== 'StringLiteral')
12
- return;
13
- let message = first?.value;
14
- let desc;
15
- if (second?.type === 'StringLiteral') {
16
- desc = second.value?.trim().replace(/\s+/gm, ' ');
17
- }
18
- let defaultMessage = message?.trim().replace(/\s+/gm, ' ');
19
- let id = typeof options.overrideIdFn === 'string'
20
- ? options.overrideIdFn
21
- : options.overrideIdFn(undefined, defaultMessage, desc, fileName);
22
- options.onMsgExtracted(fileName, [
23
- {
24
- id: id,
25
- defaultMessage: defaultMessage,
26
- description: desc,
27
- },
28
- ]);
29
- }
4
+ if (!options.onMsgExtracted) return;
5
+ if (!options.overrideIdFn) return;
6
+ if (node.path.type !== "PathExpression") return;
7
+ if (["format-message", "formatMessage"].includes(node.path.original)) {
8
+ let [first, second] = node.params;
9
+ if (first.type !== "StringLiteral") return;
10
+ let message = first?.value;
11
+ let desc;
12
+ if (second?.type === "StringLiteral") {
13
+ desc = second.value?.trim().replace(/\s+/gm, " ");
14
+ }
15
+ let defaultMessage = message?.trim().replace(/\s+/gm, " ");
16
+ let id = typeof options.overrideIdFn === "string" ? options.overrideIdFn : options.overrideIdFn(undefined, defaultMessage, desc, fileName);
17
+ options.onMsgExtracted(fileName, [{
18
+ id,
19
+ defaultMessage,
20
+ description: desc
21
+ }]);
22
+ }
30
23
  }
31
24
  export function parseFile(source, fileName, options) {
32
- let visitor = function () {
33
- return {
34
- MustacheStatement(node) {
35
- extractText(node, fileName, options);
36
- },
37
- SubExpression(node) {
38
- extractText(node, fileName, options);
39
- },
40
- };
41
- };
42
- // SAFETY: ember-template-recast's types are out of date,
43
- // but it does not affect runtime
44
- transform(source, visitor);
25
+ let visitor = function() {
26
+ return {
27
+ MustacheStatement(node) {
28
+ extractText(node, fileName, options);
29
+ },
30
+ SubExpression(node) {
31
+ extractText(node, fileName, options);
32
+ }
33
+ };
34
+ };
35
+ // SAFETY: ember-template-recast's types are out of date,
36
+ // but it does not affect runtime
37
+ transform(source, visitor);
45
38
  }
@@ -1,7 +1,7 @@
1
- import { Opts } from '@formatjs/ts-transformer';
1
+ import { type Opts } from "@formatjs/ts-transformer";
2
2
  /**
3
- * Invoid TypeScript module transpilation with our TS transformer
4
- * @param opts Formatjs TS Transformer opt
5
- * @param fn filename
6
- */
3
+ * Invoid TypeScript module transpilation with our TS transformer
4
+ * @param opts Formatjs TS Transformer opt
5
+ * @param fn filename
6
+ */
7
7
  export declare function parseScript(opts: Opts, fn?: string): (source: string) => void;
@@ -1,46 +1,43 @@
1
- import { transformWithTs } from '@formatjs/ts-transformer';
2
- import * as ts from 'typescript';
3
- import { debug } from './console_utils.js';
1
+ import { transformWithTs } from "@formatjs/ts-transformer";
2
+ import * as ts from "typescript";
3
+ import { debug } from "./console_utils.js";
4
4
  /**
5
- * Invoid TypeScript module transpilation with our TS transformer
6
- * @param opts Formatjs TS Transformer opt
7
- * @param fn filename
8
- */
5
+ * Invoid TypeScript module transpilation with our TS transformer
6
+ * @param opts Formatjs TS Transformer opt
7
+ * @param fn filename
8
+ */
9
9
  export function parseScript(opts, fn) {
10
- return (source) => {
11
- let output;
12
- try {
13
- debug('Using TS compiler to process file', fn);
14
- output = ts.transpileModule(source, {
15
- compilerOptions: {
16
- allowJs: true,
17
- target: ts.ScriptTarget.ESNext,
18
- noEmit: true,
19
- experimentalDecorators: true,
20
- },
21
- reportDiagnostics: true,
22
- fileName: fn,
23
- transformers: {
24
- before: [transformWithTs(ts, opts)],
25
- },
26
- });
27
- }
28
- catch (e) {
29
- if (e instanceof Error) {
30
- e.message = `Error processing file ${fn}
31
- ${e.message || ''}`;
32
- }
33
- throw e;
34
- }
35
- if (output.diagnostics) {
36
- const errs = output.diagnostics.filter(d => d.category === ts.DiagnosticCategory.Error);
37
- if (errs.length) {
38
- throw new Error(ts.formatDiagnosticsWithColorAndContext(errs, {
39
- getCanonicalFileName: fileName => fileName,
40
- getCurrentDirectory: () => process.cwd(),
41
- getNewLine: () => ts.sys.newLine,
42
- }));
43
- }
44
- }
45
- };
10
+ return (source) => {
11
+ let output;
12
+ try {
13
+ debug("Using TS compiler to process file", fn);
14
+ output = ts.transpileModule(source, {
15
+ compilerOptions: {
16
+ allowJs: true,
17
+ target: ts.ScriptTarget.ESNext,
18
+ noEmit: true,
19
+ experimentalDecorators: true
20
+ },
21
+ reportDiagnostics: true,
22
+ fileName: fn,
23
+ transformers: { before: [transformWithTs(ts, opts)] }
24
+ });
25
+ } catch (e) {
26
+ if (e instanceof Error) {
27
+ e.message = `Error processing file ${fn}
28
+ ${e.message || ""}`;
29
+ }
30
+ throw e;
31
+ }
32
+ if (output.diagnostics) {
33
+ const errs = output.diagnostics.filter((d) => d.category === ts.DiagnosticCategory.Error);
34
+ if (errs.length) {
35
+ throw new Error(ts.formatDiagnosticsWithColorAndContext(errs, {
36
+ getCanonicalFileName: (fileName) => fileName,
37
+ getCurrentDirectory: () => process.cwd(),
38
+ getNewLine: () => ts.sys.newLine
39
+ }));
40
+ }
41
+ }
42
+ };
46
43
  }
@@ -1,22 +1,22 @@
1
- import { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
1
+ import { type MessageFormatElement } from "@formatjs/icu-messageformat-parser";
2
2
  export declare function generateXXLS(msg: string | MessageFormatElement[]): MessageFormatElement[];
3
3
  export declare function generateXXAC(msg: string | MessageFormatElement[]): MessageFormatElement[];
4
4
  export declare function generateXXHA(msg: string | MessageFormatElement[]): MessageFormatElement[];
5
5
  /**
6
- * accented - Ȧȧƈƈḗḗƞŧḗḗḓ Ḗḗƞɠŀīīşħ
7
- * --------------------------------
8
- *
9
- * This locale replaces all Latin characters with their accented equivalents, and duplicates some
10
- * vowels to create roughly 30% longer strings. Strings are wrapped in markers (square brackets),
11
- * which help with detecting truncation.
12
- */
6
+ * accented - Ȧȧƈƈḗḗƞŧḗḗḓ Ḗḗƞɠŀīīşħ
7
+ * --------------------------------
8
+ *
9
+ * This locale replaces all Latin characters with their accented equivalents, and duplicates some
10
+ * vowels to create roughly 30% longer strings. Strings are wrapped in markers (square brackets),
11
+ * which help with detecting truncation.
12
+ */
13
13
  export declare function generateENXA(msg: string | MessageFormatElement[]): MessageFormatElement[];
14
14
  /**
15
- * bidi - ɥsıʅƃuƎ ıpıԐ
16
- * -------------------
17
- *
18
- * This strategy replaces all Latin characters with their 180 degree rotated versions and enforces
19
- * right to left text flow using Unicode UAX#9 Explicit Directional Embeddings. In this mode, the UI
20
- * directionality will also be set to right-to-left.
21
- */
15
+ * bidi - ɥsıʅƃuƎ ıpıԐ
16
+ * -------------------
17
+ *
18
+ * This strategy replaces all Latin characters with their 180 degree rotated versions and enforces
19
+ * right to left text flow using Unicode UAX#9 Explicit Directional Embeddings. In this mode, the UI
20
+ * directionality will also be set to right-to-left.
21
+ */
22
22
  export declare function generateENXB(msg: string | MessageFormatElement[]): MessageFormatElement[];