@lingui/cli 4.0.0-next.4 → 4.0.0-next.5

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 (68) hide show
  1. package/dist/api/catalog/extractFromFiles.js +64 -0
  2. package/dist/api/catalog/getCatalogs.js +137 -0
  3. package/dist/api/catalog/getTranslationsForCatalog.js +68 -0
  4. package/dist/api/catalog/mergeCatalog.js +86 -0
  5. package/dist/api/catalog.js +286 -0
  6. package/dist/api/compile.js +115 -0
  7. package/dist/api/extractors/babel.js +158 -0
  8. package/dist/api/extractors/index.js +44 -0
  9. package/dist/api/extractors/typescript.js +15 -0
  10. package/dist/api/formats/formatterWrapper.js +48 -0
  11. package/dist/api/formats/index.js +95 -0
  12. package/dist/api/help.js +41 -0
  13. package/dist/api/index.js +31 -0
  14. package/dist/api/pseudoLocalize.js +60 -0
  15. package/dist/api/rethrownError.js +16 -0
  16. package/dist/api/stats.js +73 -0
  17. package/{build → dist}/api/types.js +2 -3
  18. package/dist/api/utils.js +117 -0
  19. package/dist/extract-experimental/buildExternalizeFilter.js +83 -0
  20. package/dist/extract-experimental/bundleSource.js +127 -0
  21. package/dist/extract-experimental/constants.js +16 -0
  22. package/dist/extract-experimental/getEntryPoints.js +20 -0
  23. package/dist/extract-experimental/getExperimentalCatalogs.js +30 -0
  24. package/dist/extract-experimental/resolveCatalogPath.js +34 -0
  25. package/dist/extract-experimental/resolveTemplatePath.js +19 -0
  26. package/dist/extract-experimental/writeCatalogs.js +54 -0
  27. package/dist/lingui-compile.js +158 -0
  28. package/dist/lingui-extract-experimental.js +113 -0
  29. package/dist/lingui-extract-template.js +52 -0
  30. package/dist/lingui-extract.js +192 -0
  31. package/dist/lingui.js +8 -0
  32. package/dist/services/translationIO.js +261 -0
  33. package/dist/tests.js +137 -0
  34. package/package.json +19 -13
  35. package/build/LICENSE +0 -21
  36. package/build/api/catalog/extractFromFiles.js +0 -45
  37. package/build/api/catalog/getCatalogs.js +0 -138
  38. package/build/api/catalog/getTranslationsForCatalog.js +0 -77
  39. package/build/api/catalog/mergeCatalog.js +0 -44
  40. package/build/api/catalog.js +0 -245
  41. package/build/api/compile.js +0 -72
  42. package/build/api/extractors/babel.js +0 -92
  43. package/build/api/extractors/index.js +0 -36
  44. package/build/api/extractors/typescript.js +0 -14
  45. package/build/api/formats/formatterWrapper.js +0 -45
  46. package/build/api/formats/index.js +0 -57
  47. package/build/api/generateMessageId.js +0 -12
  48. package/build/api/help.js +0 -42
  49. package/build/api/index.js +0 -58
  50. package/build/api/pseudoLocalize.js +0 -60
  51. package/build/api/rethrownError.js +0 -14
  52. package/build/api/stats.js +0 -40
  53. package/build/api/utils.js +0 -117
  54. package/build/extract-experimental/buildExternalizeFilter.js +0 -39
  55. package/build/extract-experimental/bundleSource.js +0 -69
  56. package/build/extract-experimental/constants.js +0 -10
  57. package/build/extract-experimental/getEntryPoints.js +0 -14
  58. package/build/extract-experimental/getExperimentalCatalogs.js +0 -28
  59. package/build/extract-experimental/resolveCatalogPath.js +0 -23
  60. package/build/extract-experimental/resolveTemplatePath.js +0 -17
  61. package/build/extract-experimental/writeCatalogs.js +0 -59
  62. package/build/lingui-compile.js +0 -156
  63. package/build/lingui-extract-experimental.js +0 -103
  64. package/build/lingui-extract-template.js +0 -46
  65. package/build/lingui-extract.js +0 -143
  66. package/build/lingui.js +0 -6
  67. package/build/services/translationIO.js +0 -266
  68. package/build/tests.js +0 -133
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ createCompiledCatalog: ()=>createCompiledCatalog,
13
+ compile: ()=>compile
14
+ });
15
+ const _types = /*#__PURE__*/ _interopRequireWildcard(require("@babel/types"));
16
+ const _generator = /*#__PURE__*/ _interopRequireDefault(require("@babel/generator"));
17
+ const _compileMessage = require("@lingui/message-utils/compileMessage");
18
+ const _pseudoLocalize = /*#__PURE__*/ _interopRequireDefault(require("./pseudoLocalize"));
19
+ function _interopRequireDefault(obj) {
20
+ return obj && obj.__esModule ? obj : {
21
+ default: obj
22
+ };
23
+ }
24
+ function _getRequireWildcardCache(nodeInterop) {
25
+ if (typeof WeakMap !== "function") return null;
26
+ var cacheBabelInterop = new WeakMap();
27
+ var cacheNodeInterop = new WeakMap();
28
+ return (_getRequireWildcardCache = function(nodeInterop) {
29
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
30
+ })(nodeInterop);
31
+ }
32
+ function _interopRequireWildcard(obj, nodeInterop) {
33
+ if (!nodeInterop && obj && obj.__esModule) {
34
+ return obj;
35
+ }
36
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
37
+ return {
38
+ default: obj
39
+ };
40
+ }
41
+ var cache = _getRequireWildcardCache(nodeInterop);
42
+ if (cache && cache.has(obj)) {
43
+ return cache.get(obj);
44
+ }
45
+ var newObj = {};
46
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
47
+ for(var key in obj){
48
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
49
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
50
+ if (desc && (desc.get || desc.set)) {
51
+ Object.defineProperty(newObj, key, desc);
52
+ } else {
53
+ newObj[key] = obj[key];
54
+ }
55
+ }
56
+ }
57
+ newObj.default = obj;
58
+ if (cache) {
59
+ cache.set(obj, newObj);
60
+ }
61
+ return newObj;
62
+ }
63
+ function createCompiledCatalog(locale, messages, options) {
64
+ const { strict =false , namespace ="cjs" , pseudoLocale , compilerBabelOptions ={} } = options;
65
+ const shouldPseudolocalize = locale === pseudoLocale;
66
+ const compiledMessages = Object.keys(messages).reduce((obj, key)=>{
67
+ // Don't use `key` as a fallback translation in strict mode.
68
+ const translation = messages[key] || (!strict ? key : "");
69
+ obj[key] = compile(translation, shouldPseudolocalize);
70
+ return obj;
71
+ }, {});
72
+ if (namespace === "json") {
73
+ return JSON.stringify({
74
+ messages: compiledMessages
75
+ });
76
+ }
77
+ const ast = buildExportStatement(//build JSON.parse(<compiledMessages>) statement
78
+ _types.callExpression(_types.memberExpression(_types.identifier("JSON"), _types.identifier("parse")), [
79
+ _types.stringLiteral(JSON.stringify(compiledMessages))
80
+ ]), namespace);
81
+ const code = (0, _generator.default)(ast, {
82
+ minified: true,
83
+ jsescOption: {
84
+ minimal: true
85
+ },
86
+ ...compilerBabelOptions
87
+ }).code;
88
+ return "/*eslint-disable*/" + code;
89
+ }
90
+ function buildExportStatement(expression, namespace) {
91
+ if (namespace === "es" || namespace === "ts") {
92
+ // export const messages = { message: "Translation" }
93
+ return _types.exportNamedDeclaration(_types.variableDeclaration("const", [
94
+ _types.variableDeclarator(_types.identifier("messages"), expression)
95
+ ]));
96
+ } else {
97
+ let exportExpression = null;
98
+ const matches = namespace.match(/^(window|global)\.([^.\s]+)$/);
99
+ if (namespace === "cjs") {
100
+ // module.exports.messages = { message: "Translation" }
101
+ exportExpression = _types.memberExpression(_types.identifier("module"), _types.identifier("exports"));
102
+ } else if (matches) {
103
+ // window.i18nMessages = { messages: { message: "Translation" }}
104
+ exportExpression = _types.memberExpression(_types.identifier(matches[1]), _types.identifier(matches[2]));
105
+ } else {
106
+ throw new Error(`Invalid namespace param: "${namespace}"`);
107
+ }
108
+ return _types.expressionStatement(_types.assignmentExpression("=", exportExpression, _types.objectExpression([
109
+ _types.objectProperty(_types.identifier("messages"), expression)
110
+ ])));
111
+ }
112
+ }
113
+ function compile(message, shouldPseudolocalize = false) {
114
+ return (0, _compileMessage.compileMessage)(message, (value)=>shouldPseudolocalize ? (0, _pseudoLocalize.default)(value) : value);
115
+ }
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>_default
8
+ });
9
+ const _core = require("@babel/core");
10
+ const _babelPluginExtractMessages = /*#__PURE__*/ _interopRequireDefault(require("@lingui/babel-plugin-extract-messages"));
11
+ const _sourceMap = require("source-map");
12
+ function _interopRequireDefault(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
16
+ }
17
+ function _getRequireWildcardCache(nodeInterop) {
18
+ if (typeof WeakMap !== "function") return null;
19
+ var cacheBabelInterop = new WeakMap();
20
+ var cacheNodeInterop = new WeakMap();
21
+ return (_getRequireWildcardCache = function(nodeInterop) {
22
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
23
+ })(nodeInterop);
24
+ }
25
+ function _interopRequireWildcard(obj, nodeInterop) {
26
+ if (!nodeInterop && obj && obj.__esModule) {
27
+ return obj;
28
+ }
29
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
30
+ return {
31
+ default: obj
32
+ };
33
+ }
34
+ var cache = _getRequireWildcardCache(nodeInterop);
35
+ if (cache && cache.has(obj)) {
36
+ return cache.get(obj);
37
+ }
38
+ var newObj = {};
39
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
40
+ for(var key in obj){
41
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
42
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
43
+ if (desc && (desc.get || desc.set)) {
44
+ Object.defineProperty(newObj, key, desc);
45
+ } else {
46
+ newObj[key] = obj[key];
47
+ }
48
+ }
49
+ }
50
+ newObj.default = obj;
51
+ if (cache) {
52
+ cache.set(obj, newObj);
53
+ }
54
+ return newObj;
55
+ }
56
+ const babelRe = new RegExp("\\.(" + [
57
+ ..._core.DEFAULT_EXTENSIONS,
58
+ ".ts",
59
+ ".mts",
60
+ ".cts",
61
+ ".tsx"
62
+ ].map((ext)=>ext.slice(1)).join("|") + ")$", "i");
63
+ const inlineSourceMapsRE = new RegExp(/\/[\/\*][#@]\s+sourceMappingURL=data:application\/json;(?:charset:utf-8;)?base64,/i);
64
+ const extractor = {
65
+ match (filename) {
66
+ return babelRe.test(filename);
67
+ },
68
+ async extract (filename, code, onMessageExtracted, ctx) {
69
+ const parserOptions = ctx.linguiConfig.extractorParserOptions;
70
+ // https://babeljs.io/docs/en/babel-parser#latest-ecmascript-features
71
+ const parserPlugins = [];
72
+ if ([
73
+ /\.ts$/,
74
+ /\.mts$/,
75
+ /\.cts$/,
76
+ /\.tsx$/
77
+ ].some((r)=>filename.match(r))) {
78
+ parserPlugins.push("typescript");
79
+ if (parserOptions.tsExperimentalDecorators) {
80
+ parserPlugins.push("decorators-legacy");
81
+ } else {
82
+ parserPlugins.push("decorators");
83
+ }
84
+ } else {
85
+ parserPlugins.push("decorators");
86
+ if (parserOptions === null || parserOptions === void 0 ? void 0 : parserOptions.flow) {
87
+ parserPlugins.push("flow");
88
+ }
89
+ }
90
+ if ([
91
+ /\.jsx$/,
92
+ /\.tsx$/
93
+ ].some((r)=>filename.match(r))) {
94
+ parserPlugins.push("jsx");
95
+ }
96
+ let sourceMapsConsumer;
97
+ if (ctx === null || ctx === void 0 ? void 0 : ctx.sourceMaps) {
98
+ sourceMapsConsumer = await new _sourceMap.SourceMapConsumer(ctx === null || ctx === void 0 ? void 0 : ctx.sourceMaps);
99
+ } else if (code.search(inlineSourceMapsRE) != -1) {
100
+ const { fromSource } = await Promise.resolve().then(()=>/*#__PURE__*/ _interopRequireWildcard(require("convert-source-map")));
101
+ sourceMapsConsumer = await new _sourceMap.SourceMapConsumer(fromSource(code).toObject());
102
+ }
103
+ await (0, _core.transformAsync)(code, {
104
+ // don't generate code
105
+ code: false,
106
+ babelrc: false,
107
+ configFile: false,
108
+ filename: filename,
109
+ inputSourceMap: ctx === null || ctx === void 0 ? void 0 : ctx.sourceMaps,
110
+ parserOpts: {
111
+ plugins: parserPlugins
112
+ },
113
+ plugins: [
114
+ [
115
+ "macros",
116
+ {
117
+ // macro plugin uses package `resolve` to find a path of macro file
118
+ // this will not follow jest pathMapping and will resolve path from ./build
119
+ // instead of ./src which makes testing & developing hard.
120
+ // here we override resolve and provide correct path for testing
121
+ resolvePath: (source)=>require.resolve(source),
122
+ lingui: {
123
+ extract: true,
124
+ linguiConfig: ctx.linguiConfig
125
+ }
126
+ }
127
+ ],
128
+ [
129
+ _babelPluginExtractMessages.default,
130
+ {
131
+ onMessageExtracted: (msg)=>{
132
+ if (!sourceMapsConsumer) {
133
+ return onMessageExtracted(msg);
134
+ }
135
+ const [_, line, column] = msg.origin;
136
+ const mappedPosition = sourceMapsConsumer.originalPositionFor({
137
+ line,
138
+ column
139
+ });
140
+ return onMessageExtracted({
141
+ ...msg,
142
+ origin: [
143
+ mappedPosition.source,
144
+ mappedPosition.line,
145
+ mappedPosition.column
146
+ ]
147
+ });
148
+ }
149
+ }
150
+ ]
151
+ ]
152
+ });
153
+ if (sourceMapsConsumer) {
154
+ sourceMapsConsumer.destroy();
155
+ }
156
+ }
157
+ };
158
+ const _default = extractor;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>extract
8
+ });
9
+ const _promises = /*#__PURE__*/ _interopRequireDefault(require("fs/promises"));
10
+ const _babel = /*#__PURE__*/ _interopRequireDefault(require("./babel"));
11
+ function _interopRequireDefault(obj) {
12
+ return obj && obj.__esModule ? obj : {
13
+ default: obj
14
+ };
15
+ }
16
+ const DEFAULT_EXTRACTORS = [
17
+ _babel.default
18
+ ];
19
+ async function extract(filename, onMessageExtracted, linguiConfig, options) {
20
+ const extractorsToExtract = options.extractors ?? DEFAULT_EXTRACTORS;
21
+ for (let e of extractorsToExtract){
22
+ let ext = e;
23
+ if (typeof e === "string") {
24
+ // in case of the user using require.resolve in their extractors, we require that module
25
+ ext = require(e);
26
+ }
27
+ if (ext.default) {
28
+ ext = ext.default;
29
+ }
30
+ if (!ext.match(filename)) continue;
31
+ try {
32
+ const file = await _promises.default.readFile(filename);
33
+ await ext.extract(filename, file.toString(), onMessageExtracted, {
34
+ linguiConfig
35
+ });
36
+ return true;
37
+ } catch (e) {
38
+ console.error(`Cannot process file ${filename} ${e.message}`);
39
+ console.error(e.stack);
40
+ return false;
41
+ }
42
+ }
43
+ return true;
44
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>_default
8
+ });
9
+ const extractor = {
10
+ match (filename) {
11
+ throw new Error("Typescript extractor was removed. " + "Lingui CLI can parse typescript out of the box. " + "Please remove it from your lingui.config.js");
12
+ },
13
+ extract () {}
14
+ };
15
+ const _default = extractor;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "FormatterWrapper", {
6
+ enumerable: true,
7
+ get: ()=>FormatterWrapper
8
+ });
9
+ const _utils = require("../utils");
10
+ const _rethrownError = require("../rethrownError");
11
+ class FormatterWrapper {
12
+ f;
13
+ sourceLocale;
14
+ constructor(f, sourceLocale){
15
+ this.f = f;
16
+ this.sourceLocale = sourceLocale;
17
+ }
18
+ getCatalogExtension() {
19
+ return this.f.catalogExtension;
20
+ }
21
+ getTemplateExtension() {
22
+ return this.f.templateExtension || this.f.catalogExtension;
23
+ }
24
+ async write(filename, catalog, locale) {
25
+ const content = await this.f.serialize(catalog, {
26
+ locale,
27
+ sourceLocale: this.sourceLocale,
28
+ existing: await (0, _utils.readFile)(filename),
29
+ filename
30
+ });
31
+ await (0, _utils.writeFileIfChanged)(filename, content);
32
+ }
33
+ async read(filename, locale) {
34
+ const content = await (0, _utils.readFile)(filename);
35
+ if (!content) {
36
+ return null;
37
+ }
38
+ try {
39
+ return this.f.parse(content, {
40
+ locale,
41
+ sourceLocale: this.sourceLocale,
42
+ filename
43
+ });
44
+ } catch (e) {
45
+ throw new _rethrownError.RethrownError(`Cannot read ${filename}`, e);
46
+ }
47
+ }
48
+ }
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ FormatterWrapper: ()=>_formatterWrapper.FormatterWrapper,
13
+ getFormat: ()=>getFormat
14
+ });
15
+ const _formatterWrapper = require("./formatterWrapper");
16
+ const _utils = require("../utils");
17
+ function _getRequireWildcardCache(nodeInterop) {
18
+ if (typeof WeakMap !== "function") return null;
19
+ var cacheBabelInterop = new WeakMap();
20
+ var cacheNodeInterop = new WeakMap();
21
+ return (_getRequireWildcardCache = function(nodeInterop) {
22
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
23
+ })(nodeInterop);
24
+ }
25
+ function _interopRequireWildcard(obj, nodeInterop) {
26
+ if (!nodeInterop && obj && obj.__esModule) {
27
+ return obj;
28
+ }
29
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
30
+ return {
31
+ default: obj
32
+ };
33
+ }
34
+ var cache = _getRequireWildcardCache(nodeInterop);
35
+ if (cache && cache.has(obj)) {
36
+ return cache.get(obj);
37
+ }
38
+ var newObj = {};
39
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
40
+ for(var key in obj){
41
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
42
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
43
+ if (desc && (desc.get || desc.set)) {
44
+ Object.defineProperty(newObj, key, desc);
45
+ } else {
46
+ newObj[key] = obj[key];
47
+ }
48
+ }
49
+ }
50
+ newObj.default = obj;
51
+ if (cache) {
52
+ cache.set(obj, newObj);
53
+ }
54
+ return newObj;
55
+ }
56
+ function createDeprecationError(packageName, format, installCode) {
57
+ const installCmd = (0, _utils.makeInstall)(packageName);
58
+ return `
59
+ Format \`${format}\` is no longer included in \`@lingui/cli\` by default.
60
+ You need to install it using ${installCmd} command and add to your \`lingui.config.{js,ts}\`:
61
+
62
+ import { formatter } from "${packageName}"
63
+
64
+ export default {
65
+ [...]
66
+ format: ${installCode}
67
+ }
68
+ `.trim();
69
+ }
70
+ // Introduced in v4. Remove this deprecation in v5
71
+ const formats = {
72
+ lingui: async ()=>{
73
+ throw new Error(createDeprecationError("@lingui/format-json", "lingui", 'formatter({style: "lingui"})'));
74
+ },
75
+ minimal: async ()=>{
76
+ throw new Error(createDeprecationError("@lingui/format-json", "minimal", 'formatter({style: "minimal"})'));
77
+ },
78
+ po: async ()=>(await Promise.resolve().then(()=>/*#__PURE__*/ _interopRequireWildcard(require("@lingui/format-po")))).formatter,
79
+ csv: async ()=>{
80
+ throw new Error(createDeprecationError("@lingui/format-csv", "csv", "formatter()"));
81
+ },
82
+ "po-gettext": async ()=>{
83
+ throw new Error(createDeprecationError("@lingui/format-po-gettext", "po-gettext", "formatter()"));
84
+ }
85
+ };
86
+ async function getFormat(_format, options, sourceLocale) {
87
+ if (typeof _format !== "string") {
88
+ return new _formatterWrapper.FormatterWrapper(_format, sourceLocale);
89
+ }
90
+ const format = formats[_format];
91
+ if (!format) {
92
+ throw new Error(`Unknown format "${_format}". Use one of following: ${Object.keys(formats).join(", ")}`);
93
+ }
94
+ return new _formatterWrapper.FormatterWrapper((await format())(options), sourceLocale);
95
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Detect where's is the command lingui extract or lingui compile
3
+ * and how is being run (npm, yarn) and construct help
4
+ * for follow-up commands based on that.
5
+ *
6
+ * Example:
7
+ * $ yarn extract
8
+ * ...
9
+ * (use "yarn compile" to compile catalogs for production)
10
+ *
11
+ * $ yarn lingui extract
12
+ * ...
13
+ * (use "yarn lingui compile" to compile catalogs for production)
14
+ *
15
+ * $ npm run extract
16
+ * ...
17
+ * (use "npm run compile" to compile catalogs for production)
18
+ */ "use strict";
19
+ Object.defineProperty(exports, "__esModule", {
20
+ value: true
21
+ });
22
+ Object.defineProperty(exports, "helpRun", {
23
+ enumerable: true,
24
+ get: ()=>helpRun
25
+ });
26
+ const _path = require("path");
27
+ function helpRun(command) {
28
+ let findRootPkgJson;
29
+ try {
30
+ findRootPkgJson = require((0, _path.resolve)((0, _path.join)(process.cwd(), "package.json")));
31
+ } catch (error) {}
32
+ if (findRootPkgJson === null || findRootPkgJson === void 0 ? void 0 : findRootPkgJson.scripts) {
33
+ const res = Object.entries(findRootPkgJson.scripts).find(([_, value])=>value.includes(`lingui ${command}`));
34
+ if (res) {
35
+ command = res[0];
36
+ }
37
+ }
38
+ const isYarn = process.env.npm_config_user_agent && process.env.npm_config_user_agent.includes("yarn");
39
+ const runCommand = isYarn ? "yarn" : "npm run";
40
+ return `${runCommand} ${command}`;
41
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ getFormat: ()=>_formats.getFormat,
13
+ getCatalogForFile: ()=>_getCatalogs.getCatalogForFile,
14
+ getCatalogs: ()=>_getCatalogs.getCatalogs,
15
+ createCompiledCatalog: ()=>_compile.createCompiledCatalog
16
+ });
17
+ const _formats = require("./formats");
18
+ const _getCatalogs = require("./catalog/getCatalogs");
19
+ const _compile = require("./compile");
20
+ _exportStar(require("./types"), exports);
21
+ function _exportStar(from, to) {
22
+ Object.keys(from).forEach(function(k) {
23
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
24
+ enumerable: true,
25
+ get: function() {
26
+ return from[k];
27
+ }
28
+ });
29
+ });
30
+ return from;
31
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>_default
8
+ });
9
+ const _ramda = /*#__PURE__*/ _interopRequireDefault(require("ramda"));
10
+ const _pseudolocale = /*#__PURE__*/ _interopRequireDefault(require("pseudolocale"));
11
+ function _interopRequireDefault(obj) {
12
+ return obj && obj.__esModule ? obj : {
13
+ default: obj
14
+ };
15
+ }
16
+ const delimiter = "%&&&%";
17
+ _pseudolocale.default.option.delimiter = delimiter;
18
+ // We do not want prepending and appending because of Plurals structure
19
+ _pseudolocale.default.option.prepend = "";
20
+ _pseudolocale.default.option.append = "";
21
+ /**
22
+ * Regex should match HTML tags
23
+ * It was taken from https://haacked.com/archive/2004/10/25/usingregularexpressionstomatchhtml.aspx/
24
+ * Example: https://regex101.com/r/bDHD9z/3
25
+ */ const HTMLRegex = /<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/g;
26
+ /**
27
+ * Regex should match js-lingui Plurals, Select and SelectOrdinal components
28
+ * Example:
29
+ * Plurals https://regex101.com/r/VUJXg0/1
30
+ * SelectOrdinal https://regex101.com/r/T7hSLU/2
31
+ * Select https://regex101.com/r/9JnqB9/1
32
+ */ const MacroRegex = /({\w*,\s*(plural|selectordinal|select),(.|\n)*?{)|(}\s*\w*\s*{)/gi;
33
+ /**
34
+ * Regex should match js-lingui variables
35
+ * Example: https://regex101.com/r/dw1QHb/2
36
+ */ const VariableRegex = /({\s*[a-zA-Z_$][a-zA-Z_$0-9]*\s*})/g;
37
+ function addDelimitersHTMLTags(message) {
38
+ return message.replace(HTMLRegex, (matchedString)=>{
39
+ return `${delimiter}${matchedString}${delimiter}`;
40
+ });
41
+ }
42
+ function addDelimitersMacro(message) {
43
+ return message.replace(MacroRegex, (matchedString)=>{
44
+ return `${delimiter}${matchedString}${delimiter}`;
45
+ });
46
+ }
47
+ function addDelimitersVariables(message) {
48
+ return message.replace(VariableRegex, (matchedString)=>{
49
+ return `${delimiter}${matchedString}${delimiter}`;
50
+ });
51
+ }
52
+ const addDelimiters = _ramda.default.compose(addDelimitersVariables, addDelimitersMacro, addDelimitersHTMLTags);
53
+ function removeDelimiters(message) {
54
+ return message.replace(new RegExp(delimiter, "g"), "");
55
+ }
56
+ function _default(message) {
57
+ message = addDelimiters(message);
58
+ message = _pseudolocale.default.str(message);
59
+ return removeDelimiters(message);
60
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "RethrownError", {
6
+ enumerable: true,
7
+ get: ()=>RethrownError
8
+ });
9
+ class RethrownError extends Error {
10
+ message;
11
+ constructor(message, originalError){
12
+ super();
13
+ this.message = message + " " + originalError.message;
14
+ this.stack = `Error: ${message} \nOriginal: ` + originalError.stack;
15
+ }
16
+ }