@intlayer/chokidar 7.0.0-canary.3 → 7.0.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 (42) hide show
  1. package/dist/cjs/writeContentDeclaration/detectFormatCommand.cjs +25 -0
  2. package/dist/cjs/writeContentDeclaration/detectFormatCommand.cjs.map +1 -0
  3. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +19 -7
  4. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -1
  5. package/dist/esm/writeContentDeclaration/detectFormatCommand.mjs +23 -0
  6. package/dist/esm/writeContentDeclaration/detectFormatCommand.mjs.map +1 -0
  7. package/dist/esm/writeContentDeclaration/writeJSFile.mjs +19 -7
  8. package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -1
  9. package/dist/types/buildIntlayerDictionary/index.d.ts.map +1 -0
  10. package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts +3 -3
  11. package/dist/types/buildIntlayerDictionary/writeFetchDictionary.d.ts +3 -3
  12. package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts +2 -2
  13. package/dist/types/createDictionaryEntryPoint/createDictionaryEntryPoint.d.ts +2 -2
  14. package/dist/types/createDictionaryEntryPoint/generateDictionaryListContent.d.ts +2 -2
  15. package/dist/types/createDictionaryEntryPoint/index.d.ts.map +1 -0
  16. package/dist/types/createType/index.d.ts.map +1 -0
  17. package/dist/types/index.d.ts.map +1 -0
  18. package/dist/types/loadDictionaries/index.d.ts.map +1 -0
  19. package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +2 -2
  20. package/dist/types/utils/extractErrorMessage.d.ts +1 -4
  21. package/dist/types/utils/extractErrorMessage.d.ts.map +1 -1
  22. package/dist/types/utils/getExtension.d.ts +3 -0
  23. package/dist/types/utils/getExtension.d.ts.map +1 -0
  24. package/dist/types/writeContentDeclaration/_test.content.d.ts +4 -0
  25. package/dist/types/writeContentDeclaration/_test.content.d.ts.map +1 -0
  26. package/dist/types/writeContentDeclaration/detectFormatCommand.d.ts +7 -0
  27. package/dist/types/writeContentDeclaration/detectFormatCommand.d.ts.map +1 -0
  28. package/dist/types/writeContentDeclaration/formatCode.d.ts +2 -0
  29. package/dist/types/writeContentDeclaration/formatCode.d.ts.map +1 -0
  30. package/dist/types/writeContentDeclaration/index.d.ts.map +1 -0
  31. package/dist/types/writeContentDeclaration/writeJSFile.d.ts.map +1 -1
  32. package/package.json +18 -18
  33. package/dist/cjs/utils/extractErrorMessage.cjs +0 -95
  34. package/dist/cjs/utils/extractErrorMessage.cjs.map +0 -1
  35. package/dist/cjs/utils/verifyIdenticObjectFormat copy.cjs +0 -54
  36. package/dist/cjs/utils/verifyIdenticObjectFormat copy.cjs.map +0 -1
  37. package/dist/esm/utils/extractErrorMessage.mjs +0 -94
  38. package/dist/esm/utils/extractErrorMessage.mjs.map +0 -1
  39. package/dist/esm/utils/verifyIdenticObjectFormat copy.mjs +0 -53
  40. package/dist/esm/utils/verifyIdenticObjectFormat copy.mjs.map +0 -1
  41. package/dist/types/utils/verifyIdenticObjectFormat copy.d.ts +0 -23
  42. package/dist/types/utils/verifyIdenticObjectFormat copy.d.ts.map +0 -1
@@ -0,0 +1,25 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ let __intlayer_config = require("@intlayer/config");
3
+ __intlayer_config = require_rolldown_runtime.__toESM(__intlayer_config);
4
+
5
+ //#region src/writeContentDeclaration/detectFormatCommand.ts
6
+ const detectFormatCommand = (configuration) => {
7
+ const { formatCommand } = configuration.content;
8
+ if (formatCommand) return formatCommand;
9
+ try {
10
+ __intlayer_config.ESMxCJSRequire.resolve("prettier");
11
+ return "prettier --write \"{{file}}\" --log-level silent";
12
+ } catch (_error) {}
13
+ try {
14
+ __intlayer_config.ESMxCJSRequire.resolve("biome");
15
+ return "biome format \"{{file}}\" --write --log-level none";
16
+ } catch (_error) {}
17
+ try {
18
+ __intlayer_config.ESMxCJSRequire.resolve("eslint");
19
+ return "eslint --fix \"{{file}}\" --quiet";
20
+ } catch (_error) {}
21
+ };
22
+
23
+ //#endregion
24
+ exports.detectFormatCommand = detectFormatCommand;
25
+ //# sourceMappingURL=detectFormatCommand.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detectFormatCommand.cjs","names":[],"sources":["../../../src/writeContentDeclaration/detectFormatCommand.ts"],"sourcesContent":["import { ESMxCJSRequire } from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\n\nexport const detectFormatCommand = (configuration: IntlayerConfig) => {\n const { formatCommand } = configuration.content;\n\n if (formatCommand) {\n return formatCommand;\n }\n\n // Try Prettier\n try {\n ESMxCJSRequire.resolve('prettier');\n\n return 'prettier --write \"{{file}}\" --log-level silent';\n } catch (_error) {\n // Prettier not found, continue to next option\n }\n\n // Try Biome\n try {\n ESMxCJSRequire.resolve('biome');\n\n return 'biome format \"{{file}}\" --write --log-level none';\n } catch (_error) {\n // Biome not found, continue to next option\n }\n\n // Try ESLint\n try {\n ESMxCJSRequire.resolve('eslint');\n\n return 'eslint --fix \"{{file}}\" --quiet';\n } catch (_error) {\n // ESLint not found, no formatter available\n }\n\n // No formatter found\n return undefined;\n};\n"],"mappings":";;;;;AAGA,MAAa,uBAAuB,kBAAkC;CACpE,MAAM,EAAE,kBAAkB,cAAc;AAExC,KAAI,cACF,QAAO;AAIT,KAAI;AACF,mCAAe,QAAQ,WAAW;AAElC,SAAO;UACA,QAAQ;AAKjB,KAAI;AACF,mCAAe,QAAQ,QAAQ;AAE/B,SAAO;UACA,QAAQ;AAKjB,KAAI;AACF,mCAAe,QAAQ,SAAS;AAEhC,SAAO;UACA,QAAQ"}
@@ -2,6 +2,7 @@ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
2
  const require_getContentDeclarationFileTemplate_getContentDeclarationFileTemplate = require('../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs');
3
3
  const require_utils_getFormatFromExtension = require('../utils/getFormatFromExtension.cjs');
4
4
  const require_writeContentDeclaration_transformJSFile = require('./transformJSFile.cjs');
5
+ const require_writeContentDeclaration_detectFormatCommand = require('./detectFormatCommand.cjs');
5
6
  let node_fs = require("node:fs");
6
7
  node_fs = require_rolldown_runtime.__toESM(node_fs);
7
8
  let __intlayer_config = require("@intlayer/config");
@@ -21,15 +22,25 @@ node_child_process = require_rolldown_runtime.__toESM(node_child_process);
21
22
  * of 't' (translation) function calls.
22
23
  */
23
24
  const writeJSFile = async (filePath, dictionary, configuration) => {
24
- const { key, locale, filled } = dictionary;
25
+ const mergedDictionary = {
26
+ ...configuration.dictionary,
27
+ ...dictionary
28
+ };
25
29
  const appLogger = (0, __intlayer_config.getAppLogger)(configuration);
26
30
  if (!(0, node_fs.existsSync)(filePath)) {
27
31
  const format = require_utils_getFormatFromExtension.getFormatFromExtension((0, node_path.extname)(filePath));
28
32
  appLogger("File does not exist, creating it", { isVerbose: true });
29
- await (0, node_fs_promises.writeFile)(filePath, await require_getContentDeclarationFileTemplate_getContentDeclarationFileTemplate.getContentDeclarationFileTemplate(key, format, {
30
- locale,
31
- filled
32
- }), "utf-8");
33
+ await (0, node_fs_promises.writeFile)(filePath, await require_getContentDeclarationFileTemplate_getContentDeclarationFileTemplate.getContentDeclarationFileTemplate(mergedDictionary.key, format, Object.fromEntries(Object.entries({
34
+ locale: mergedDictionary.locale,
35
+ filled: mergedDictionary.filled,
36
+ fill: mergedDictionary.fill,
37
+ description: mergedDictionary.description,
38
+ title: mergedDictionary.title,
39
+ tags: mergedDictionary.tags,
40
+ version: mergedDictionary.version,
41
+ priority: mergedDictionary.priority,
42
+ live: mergedDictionary.live
43
+ }).filter(([, value]) => value !== void 0))), "utf-8");
33
44
  }
34
45
  const finalCode = await require_writeContentDeclaration_transformJSFile.transformJSFile(await (0, node_fs_promises.readFile)(filePath, "utf-8"), dictionary);
35
46
  try {
@@ -43,8 +54,9 @@ const writeJSFile = async (filePath, dictionary, configuration) => {
43
54
  (0, __intlayer_config.logger)(`Failed to write updated file: ${filePath}`, { level: "error" });
44
55
  throw new Error(`Failed to write updated file ${filePath}: ${err.message}`);
45
56
  }
46
- if (configuration.editor.formatCommand) try {
47
- (0, node_child_process.execSync)(configuration.editor.formatCommand.replace("{{file}}", filePath), {
57
+ const formatCommand = require_writeContentDeclaration_detectFormatCommand.detectFormatCommand(configuration);
58
+ if (formatCommand) try {
59
+ (0, node_child_process.execSync)(formatCommand.replace("{{file}}", filePath), {
48
60
  stdio: "inherit",
49
61
  cwd: configuration.content.baseDir
50
62
  });
@@ -1 +1 @@
1
- {"version":3,"file":"writeJSFile.cjs","names":["getFormatFromExtension","getContentDeclarationFileTemplate","transformJSFile"],"sources":["../../../src/writeContentDeclaration/writeJSFile.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { readFile, writeFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport { getAppLogger, logger } from '@intlayer/config';\nimport type { Dictionary, IntlayerConfig } from '@intlayer/types';\nimport { getContentDeclarationFileTemplate } from '../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate';\nimport {\n type Extension,\n getFormatFromExtension,\n} from '../utils/getFormatFromExtension';\nimport { transformJSFile } from './transformJSFile';\n\n/**\n * Updates a JavaScript/TypeScript file based on the provided JSON instructions.\n * It targets a specific dictionary object within the file (identified by its 'key' property)\n * and updates its 'content' entries. Currently, it focuses on modifying arguments\n * of 't' (translation) function calls.\n */\nexport const writeJSFile = async (\n filePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig\n): Promise<void> => {\n const { key, locale, filled } = dictionary;\n const appLogger = getAppLogger(configuration);\n\n // Check if the file exist\n if (!existsSync(filePath)) {\n const fileExtension = extname(filePath) as Extension;\n\n const format = getFormatFromExtension(fileExtension);\n\n appLogger('File does not exist, creating it', {\n isVerbose: true,\n });\n const template = await getContentDeclarationFileTemplate(key, format, {\n locale,\n filled,\n });\n\n await writeFile(filePath, template, 'utf-8');\n }\n\n const fileContent = await readFile(filePath, 'utf-8');\n\n const finalCode = await transformJSFile(fileContent, dictionary);\n\n // Write the modified code back to the file\n try {\n await writeFile(filePath, finalCode, 'utf-8');\n logger(`Successfully updated ${filePath}`, {\n level: 'info',\n isVerbose: true,\n });\n } catch (error) {\n const err = error as Error;\n logger(`Failed to write updated file: ${filePath}`, {\n level: 'error',\n });\n throw new Error(`Failed to write updated file ${filePath}: ${err.message}`);\n }\n\n if (configuration.editor.formatCommand) {\n try {\n execSync(\n configuration.editor.formatCommand.replace('{{file}}', filePath),\n {\n stdio: 'inherit',\n cwd: configuration.content.baseDir,\n }\n );\n } catch (error) {\n console.error(error);\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmBA,MAAa,cAAc,OACzB,UACA,YACA,kBACkB;CAClB,MAAM,EAAE,KAAK,QAAQ,WAAW;CAChC,MAAM,gDAAyB,cAAc;AAG7C,KAAI,yBAAY,SAAS,EAAE;EAGzB,MAAM,SAASA,mFAFe,SAAS,CAEa;AAEpD,YAAU,oCAAoC,EAC5C,WAAW,MACZ,CAAC;AAMF,wCAAgB,UALC,MAAMC,8GAAkC,KAAK,QAAQ;GACpE;GACA;GACD,CAAC,EAEkC,QAAQ;;CAK9C,MAAM,YAAY,MAAMC,gEAFJ,qCAAe,UAAU,QAAQ,EAEA,WAAW;AAGhE,KAAI;AACF,wCAAgB,UAAU,WAAW,QAAQ;AAC7C,gCAAO,wBAAwB,YAAY;GACzC,OAAO;GACP,WAAW;GACZ,CAAC;UACK,OAAO;EACd,MAAM,MAAM;AACZ,gCAAO,iCAAiC,YAAY,EAClD,OAAO,SACR,CAAC;AACF,QAAM,IAAI,MAAM,gCAAgC,SAAS,IAAI,IAAI,UAAU;;AAG7E,KAAI,cAAc,OAAO,cACvB,KAAI;AACF,mCACE,cAAc,OAAO,cAAc,QAAQ,YAAY,SAAS,EAChE;GACE,OAAO;GACP,KAAK,cAAc,QAAQ;GAC5B,CACF;UACM,OAAO;AACd,UAAQ,MAAM,MAAM"}
1
+ {"version":3,"file":"writeJSFile.cjs","names":["getFormatFromExtension","getContentDeclarationFileTemplate","transformJSFile","detectFormatCommand"],"sources":["../../../src/writeContentDeclaration/writeJSFile.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { readFile, writeFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport { getAppLogger, logger } from '@intlayer/config';\nimport type { Dictionary, IntlayerConfig } from '@intlayer/types';\nimport { getContentDeclarationFileTemplate } from '../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate';\nimport {\n type Extension,\n getFormatFromExtension,\n} from '../utils/getFormatFromExtension';\nimport { detectFormatCommand } from './detectFormatCommand';\nimport { transformJSFile } from './transformJSFile';\n\n/**\n * Updates a JavaScript/TypeScript file based on the provided JSON instructions.\n * It targets a specific dictionary object within the file (identified by its 'key' property)\n * and updates its 'content' entries. Currently, it focuses on modifying arguments\n * of 't' (translation) function calls.\n */\nexport const writeJSFile = async (\n filePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig\n): Promise<void> => {\n const mergedDictionary = {\n ...configuration.dictionary,\n ...dictionary,\n };\n\n const appLogger = getAppLogger(configuration);\n\n // Check if the file exist\n if (!existsSync(filePath)) {\n const fileExtension = extname(filePath) as Extension;\n\n const format = getFormatFromExtension(fileExtension);\n\n appLogger('File does not exist, creating it', {\n isVerbose: true,\n });\n const template = await getContentDeclarationFileTemplate(\n mergedDictionary.key,\n format,\n // Filter out undefined values\n Object.fromEntries(\n Object.entries({\n locale: mergedDictionary.locale,\n filled: mergedDictionary.filled,\n fill: mergedDictionary.fill,\n description: mergedDictionary.description,\n title: mergedDictionary.title,\n tags: mergedDictionary.tags,\n version: mergedDictionary.version,\n priority: mergedDictionary.priority,\n live: mergedDictionary.live,\n }).filter(([, value]) => value !== undefined)\n )\n );\n\n await writeFile(filePath, template, 'utf-8');\n }\n\n const fileContent = await readFile(filePath, 'utf-8');\n\n const finalCode = await transformJSFile(fileContent, dictionary);\n\n // Write the modified code back to the file\n try {\n await writeFile(filePath, finalCode, 'utf-8');\n logger(`Successfully updated ${filePath}`, {\n level: 'info',\n isVerbose: true,\n });\n } catch (error) {\n const err = error as Error;\n logger(`Failed to write updated file: ${filePath}`, {\n level: 'error',\n });\n throw new Error(`Failed to write updated file ${filePath}: ${err.message}`);\n }\n\n const formatCommand = detectFormatCommand(configuration);\n\n if (formatCommand) {\n try {\n execSync(formatCommand.replace('{{file}}', filePath), {\n stdio: 'inherit',\n cwd: configuration.content.baseDir,\n });\n } catch (error) {\n console.error(error);\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,cAAc,OACzB,UACA,YACA,kBACkB;CAClB,MAAM,mBAAmB;EACvB,GAAG,cAAc;EACjB,GAAG;EACJ;CAED,MAAM,gDAAyB,cAAc;AAG7C,KAAI,yBAAY,SAAS,EAAE;EAGzB,MAAM,SAASA,mFAFe,SAAS,CAEa;AAEpD,YAAU,oCAAoC,EAC5C,WAAW,MACZ,CAAC;AAoBF,wCAAgB,UAnBC,MAAMC,8GACrB,iBAAiB,KACjB,QAEA,OAAO,YACL,OAAO,QAAQ;GACb,QAAQ,iBAAiB;GACzB,QAAQ,iBAAiB;GACzB,MAAM,iBAAiB;GACvB,aAAa,iBAAiB;GAC9B,OAAO,iBAAiB;GACxB,MAAM,iBAAiB;GACvB,SAAS,iBAAiB;GAC1B,UAAU,iBAAiB;GAC3B,MAAM,iBAAiB;GACxB,CAAC,CAAC,QAAQ,GAAG,WAAW,UAAU,OAAU,CAC9C,CACF,EAEmC,QAAQ;;CAK9C,MAAM,YAAY,MAAMC,gEAFJ,qCAAe,UAAU,QAAQ,EAEA,WAAW;AAGhE,KAAI;AACF,wCAAgB,UAAU,WAAW,QAAQ;AAC7C,gCAAO,wBAAwB,YAAY;GACzC,OAAO;GACP,WAAW;GACZ,CAAC;UACK,OAAO;EACd,MAAM,MAAM;AACZ,gCAAO,iCAAiC,YAAY,EAClD,OAAO,SACR,CAAC;AACF,QAAM,IAAI,MAAM,gCAAgC,SAAS,IAAI,IAAI,UAAU;;CAG7E,MAAM,gBAAgBC,wEAAoB,cAAc;AAExD,KAAI,cACF,KAAI;AACF,mCAAS,cAAc,QAAQ,YAAY,SAAS,EAAE;GACpD,OAAO;GACP,KAAK,cAAc,QAAQ;GAC5B,CAAC;UACK,OAAO;AACd,UAAQ,MAAM,MAAM"}
@@ -0,0 +1,23 @@
1
+ import { ESMxCJSRequire } from "@intlayer/config";
2
+
3
+ //#region src/writeContentDeclaration/detectFormatCommand.ts
4
+ const detectFormatCommand = (configuration) => {
5
+ const { formatCommand } = configuration.content;
6
+ if (formatCommand) return formatCommand;
7
+ try {
8
+ ESMxCJSRequire.resolve("prettier");
9
+ return "prettier --write \"{{file}}\" --log-level silent";
10
+ } catch (_error) {}
11
+ try {
12
+ ESMxCJSRequire.resolve("biome");
13
+ return "biome format \"{{file}}\" --write --log-level none";
14
+ } catch (_error) {}
15
+ try {
16
+ ESMxCJSRequire.resolve("eslint");
17
+ return "eslint --fix \"{{file}}\" --quiet";
18
+ } catch (_error) {}
19
+ };
20
+
21
+ //#endregion
22
+ export { detectFormatCommand };
23
+ //# sourceMappingURL=detectFormatCommand.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detectFormatCommand.mjs","names":[],"sources":["../../../src/writeContentDeclaration/detectFormatCommand.ts"],"sourcesContent":["import { ESMxCJSRequire } from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\n\nexport const detectFormatCommand = (configuration: IntlayerConfig) => {\n const { formatCommand } = configuration.content;\n\n if (formatCommand) {\n return formatCommand;\n }\n\n // Try Prettier\n try {\n ESMxCJSRequire.resolve('prettier');\n\n return 'prettier --write \"{{file}}\" --log-level silent';\n } catch (_error) {\n // Prettier not found, continue to next option\n }\n\n // Try Biome\n try {\n ESMxCJSRequire.resolve('biome');\n\n return 'biome format \"{{file}}\" --write --log-level none';\n } catch (_error) {\n // Biome not found, continue to next option\n }\n\n // Try ESLint\n try {\n ESMxCJSRequire.resolve('eslint');\n\n return 'eslint --fix \"{{file}}\" --quiet';\n } catch (_error) {\n // ESLint not found, no formatter available\n }\n\n // No formatter found\n return undefined;\n};\n"],"mappings":";;;AAGA,MAAa,uBAAuB,kBAAkC;CACpE,MAAM,EAAE,kBAAkB,cAAc;AAExC,KAAI,cACF,QAAO;AAIT,KAAI;AACF,iBAAe,QAAQ,WAAW;AAElC,SAAO;UACA,QAAQ;AAKjB,KAAI;AACF,iBAAe,QAAQ,QAAQ;AAE/B,SAAO;UACA,QAAQ;AAKjB,KAAI;AACF,iBAAe,QAAQ,SAAS;AAEhC,SAAO;UACA,QAAQ"}
@@ -1,6 +1,7 @@
1
1
  import { getContentDeclarationFileTemplate } from "../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs";
2
2
  import { getFormatFromExtension } from "../utils/getFormatFromExtension.mjs";
3
3
  import { transformJSFile } from "./transformJSFile.mjs";
4
+ import { detectFormatCommand } from "./detectFormatCommand.mjs";
4
5
  import { existsSync } from "node:fs";
5
6
  import { getAppLogger, logger } from "@intlayer/config";
6
7
  import { extname } from "node:path";
@@ -15,15 +16,25 @@ import { execSync } from "node:child_process";
15
16
  * of 't' (translation) function calls.
16
17
  */
17
18
  const writeJSFile = async (filePath, dictionary, configuration) => {
18
- const { key, locale, filled } = dictionary;
19
+ const mergedDictionary = {
20
+ ...configuration.dictionary,
21
+ ...dictionary
22
+ };
19
23
  const appLogger = getAppLogger(configuration);
20
24
  if (!existsSync(filePath)) {
21
25
  const format = getFormatFromExtension(extname(filePath));
22
26
  appLogger("File does not exist, creating it", { isVerbose: true });
23
- await writeFile(filePath, await getContentDeclarationFileTemplate(key, format, {
24
- locale,
25
- filled
26
- }), "utf-8");
27
+ await writeFile(filePath, await getContentDeclarationFileTemplate(mergedDictionary.key, format, Object.fromEntries(Object.entries({
28
+ locale: mergedDictionary.locale,
29
+ filled: mergedDictionary.filled,
30
+ fill: mergedDictionary.fill,
31
+ description: mergedDictionary.description,
32
+ title: mergedDictionary.title,
33
+ tags: mergedDictionary.tags,
34
+ version: mergedDictionary.version,
35
+ priority: mergedDictionary.priority,
36
+ live: mergedDictionary.live
37
+ }).filter(([, value]) => value !== void 0))), "utf-8");
27
38
  }
28
39
  const finalCode = await transformJSFile(await readFile(filePath, "utf-8"), dictionary);
29
40
  try {
@@ -37,8 +48,9 @@ const writeJSFile = async (filePath, dictionary, configuration) => {
37
48
  logger(`Failed to write updated file: ${filePath}`, { level: "error" });
38
49
  throw new Error(`Failed to write updated file ${filePath}: ${err.message}`);
39
50
  }
40
- if (configuration.editor.formatCommand) try {
41
- execSync(configuration.editor.formatCommand.replace("{{file}}", filePath), {
51
+ const formatCommand = detectFormatCommand(configuration);
52
+ if (formatCommand) try {
53
+ execSync(formatCommand.replace("{{file}}", filePath), {
42
54
  stdio: "inherit",
43
55
  cwd: configuration.content.baseDir
44
56
  });
@@ -1 +1 @@
1
- {"version":3,"file":"writeJSFile.mjs","names":[],"sources":["../../../src/writeContentDeclaration/writeJSFile.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { readFile, writeFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport { getAppLogger, logger } from '@intlayer/config';\nimport type { Dictionary, IntlayerConfig } from '@intlayer/types';\nimport { getContentDeclarationFileTemplate } from '../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate';\nimport {\n type Extension,\n getFormatFromExtension,\n} from '../utils/getFormatFromExtension';\nimport { transformJSFile } from './transformJSFile';\n\n/**\n * Updates a JavaScript/TypeScript file based on the provided JSON instructions.\n * It targets a specific dictionary object within the file (identified by its 'key' property)\n * and updates its 'content' entries. Currently, it focuses on modifying arguments\n * of 't' (translation) function calls.\n */\nexport const writeJSFile = async (\n filePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig\n): Promise<void> => {\n const { key, locale, filled } = dictionary;\n const appLogger = getAppLogger(configuration);\n\n // Check if the file exist\n if (!existsSync(filePath)) {\n const fileExtension = extname(filePath) as Extension;\n\n const format = getFormatFromExtension(fileExtension);\n\n appLogger('File does not exist, creating it', {\n isVerbose: true,\n });\n const template = await getContentDeclarationFileTemplate(key, format, {\n locale,\n filled,\n });\n\n await writeFile(filePath, template, 'utf-8');\n }\n\n const fileContent = await readFile(filePath, 'utf-8');\n\n const finalCode = await transformJSFile(fileContent, dictionary);\n\n // Write the modified code back to the file\n try {\n await writeFile(filePath, finalCode, 'utf-8');\n logger(`Successfully updated ${filePath}`, {\n level: 'info',\n isVerbose: true,\n });\n } catch (error) {\n const err = error as Error;\n logger(`Failed to write updated file: ${filePath}`, {\n level: 'error',\n });\n throw new Error(`Failed to write updated file ${filePath}: ${err.message}`);\n }\n\n if (configuration.editor.formatCommand) {\n try {\n execSync(\n configuration.editor.formatCommand.replace('{{file}}', filePath),\n {\n stdio: 'inherit',\n cwd: configuration.content.baseDir,\n }\n );\n } catch (error) {\n console.error(error);\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAmBA,MAAa,cAAc,OACzB,UACA,YACA,kBACkB;CAClB,MAAM,EAAE,KAAK,QAAQ,WAAW;CAChC,MAAM,YAAY,aAAa,cAAc;AAG7C,KAAI,CAAC,WAAW,SAAS,EAAE;EAGzB,MAAM,SAAS,uBAFO,QAAQ,SAAS,CAEa;AAEpD,YAAU,oCAAoC,EAC5C,WAAW,MACZ,CAAC;AAMF,QAAM,UAAU,UALC,MAAM,kCAAkC,KAAK,QAAQ;GACpE;GACA;GACD,CAAC,EAEkC,QAAQ;;CAK9C,MAAM,YAAY,MAAM,gBAFJ,MAAM,SAAS,UAAU,QAAQ,EAEA,WAAW;AAGhE,KAAI;AACF,QAAM,UAAU,UAAU,WAAW,QAAQ;AAC7C,SAAO,wBAAwB,YAAY;GACzC,OAAO;GACP,WAAW;GACZ,CAAC;UACK,OAAO;EACd,MAAM,MAAM;AACZ,SAAO,iCAAiC,YAAY,EAClD,OAAO,SACR,CAAC;AACF,QAAM,IAAI,MAAM,gCAAgC,SAAS,IAAI,IAAI,UAAU;;AAG7E,KAAI,cAAc,OAAO,cACvB,KAAI;AACF,WACE,cAAc,OAAO,cAAc,QAAQ,YAAY,SAAS,EAChE;GACE,OAAO;GACP,KAAK,cAAc,QAAQ;GAC5B,CACF;UACM,OAAO;AACd,UAAQ,MAAM,MAAM"}
1
+ {"version":3,"file":"writeJSFile.mjs","names":[],"sources":["../../../src/writeContentDeclaration/writeJSFile.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { readFile, writeFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport { getAppLogger, logger } from '@intlayer/config';\nimport type { Dictionary, IntlayerConfig } from '@intlayer/types';\nimport { getContentDeclarationFileTemplate } from '../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate';\nimport {\n type Extension,\n getFormatFromExtension,\n} from '../utils/getFormatFromExtension';\nimport { detectFormatCommand } from './detectFormatCommand';\nimport { transformJSFile } from './transformJSFile';\n\n/**\n * Updates a JavaScript/TypeScript file based on the provided JSON instructions.\n * It targets a specific dictionary object within the file (identified by its 'key' property)\n * and updates its 'content' entries. Currently, it focuses on modifying arguments\n * of 't' (translation) function calls.\n */\nexport const writeJSFile = async (\n filePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig\n): Promise<void> => {\n const mergedDictionary = {\n ...configuration.dictionary,\n ...dictionary,\n };\n\n const appLogger = getAppLogger(configuration);\n\n // Check if the file exist\n if (!existsSync(filePath)) {\n const fileExtension = extname(filePath) as Extension;\n\n const format = getFormatFromExtension(fileExtension);\n\n appLogger('File does not exist, creating it', {\n isVerbose: true,\n });\n const template = await getContentDeclarationFileTemplate(\n mergedDictionary.key,\n format,\n // Filter out undefined values\n Object.fromEntries(\n Object.entries({\n locale: mergedDictionary.locale,\n filled: mergedDictionary.filled,\n fill: mergedDictionary.fill,\n description: mergedDictionary.description,\n title: mergedDictionary.title,\n tags: mergedDictionary.tags,\n version: mergedDictionary.version,\n priority: mergedDictionary.priority,\n live: mergedDictionary.live,\n }).filter(([, value]) => value !== undefined)\n )\n );\n\n await writeFile(filePath, template, 'utf-8');\n }\n\n const fileContent = await readFile(filePath, 'utf-8');\n\n const finalCode = await transformJSFile(fileContent, dictionary);\n\n // Write the modified code back to the file\n try {\n await writeFile(filePath, finalCode, 'utf-8');\n logger(`Successfully updated ${filePath}`, {\n level: 'info',\n isVerbose: true,\n });\n } catch (error) {\n const err = error as Error;\n logger(`Failed to write updated file: ${filePath}`, {\n level: 'error',\n });\n throw new Error(`Failed to write updated file ${filePath}: ${err.message}`);\n }\n\n const formatCommand = detectFormatCommand(configuration);\n\n if (formatCommand) {\n try {\n execSync(formatCommand.replace('{{file}}', filePath), {\n stdio: 'inherit',\n cwd: configuration.content.baseDir,\n });\n } catch (error) {\n console.error(error);\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,MAAa,cAAc,OACzB,UACA,YACA,kBACkB;CAClB,MAAM,mBAAmB;EACvB,GAAG,cAAc;EACjB,GAAG;EACJ;CAED,MAAM,YAAY,aAAa,cAAc;AAG7C,KAAI,CAAC,WAAW,SAAS,EAAE;EAGzB,MAAM,SAAS,uBAFO,QAAQ,SAAS,CAEa;AAEpD,YAAU,oCAAoC,EAC5C,WAAW,MACZ,CAAC;AAoBF,QAAM,UAAU,UAnBC,MAAM,kCACrB,iBAAiB,KACjB,QAEA,OAAO,YACL,OAAO,QAAQ;GACb,QAAQ,iBAAiB;GACzB,QAAQ,iBAAiB;GACzB,MAAM,iBAAiB;GACvB,aAAa,iBAAiB;GAC9B,OAAO,iBAAiB;GACxB,MAAM,iBAAiB;GACvB,SAAS,iBAAiB;GAC1B,UAAU,iBAAiB;GAC3B,MAAM,iBAAiB;GACxB,CAAC,CAAC,QAAQ,GAAG,WAAW,UAAU,OAAU,CAC9C,CACF,EAEmC,QAAQ;;CAK9C,MAAM,YAAY,MAAM,gBAFJ,MAAM,SAAS,UAAU,QAAQ,EAEA,WAAW;AAGhE,KAAI;AACF,QAAM,UAAU,UAAU,WAAW,QAAQ;AAC7C,SAAO,wBAAwB,YAAY;GACzC,OAAO;GACP,WAAW;GACZ,CAAC;UACK,OAAO;EACd,MAAM,MAAM;AACZ,SAAO,iCAAiC,YAAY,EAClD,OAAO,SACR,CAAC;AACF,QAAM,IAAI,MAAM,gCAAgC,SAAS,IAAI,IAAI,UAAU;;CAG7E,MAAM,gBAAgB,oBAAoB,cAAc;AAExD,KAAI,cACF,KAAI;AACF,WAAS,cAAc,QAAQ,YAAY,SAAS,EAAE;GACpD,OAAO;GACP,KAAK,cAAc,QAAQ;GAC5B,CAAC;UACK,OAAO;AACd,UAAQ,MAAM,MAAM"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/buildIntlayerDictionary/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { MergedDictionaryOutput } from "./writeMergedDictionary.js";
2
- import * as _intlayer_types7 from "@intlayer/types";
2
+ import * as _intlayer_types0 from "@intlayer/types";
3
3
  import { Dictionary, Locale } from "@intlayer/types";
4
4
 
5
5
  //#region src/buildIntlayerDictionary/writeDynamicDictionary.d.ts
@@ -12,7 +12,7 @@ type LocalizedDictionaryOutput = Record<string, LocalizedDictionaryResult>;
12
12
  /**
13
13
  * This function generates the content of the dictionary list file
14
14
  */
15
- declare const generateDictionaryEntryPoint: (localizedDictionariesPathsRecord: LocalizedDictionaryResult, format?: "cjs" | "esm", configuration?: _intlayer_types7.IntlayerConfig) => string;
15
+ declare const generateDictionaryEntryPoint: (localizedDictionariesPathsRecord: LocalizedDictionaryResult, format?: "cjs" | "esm", configuration?: _intlayer_types0.IntlayerConfig) => string;
16
16
  /**
17
17
  * Write the localized dictionaries to the dictionariesDir
18
18
  * @param mergedDictionaries - The merged dictionaries
@@ -29,7 +29,7 @@ declare const generateDictionaryEntryPoint: (localizedDictionariesPathsRecord: L
29
29
  * // { key: 'home', content: { ... } },
30
30
  * ```
31
31
  */
32
- declare const writeDynamicDictionary: (mergedDictionaries: MergedDictionaryOutput, configuration?: _intlayer_types7.IntlayerConfig, formats?: ("cjs" | "esm")[]) => Promise<LocalizedDictionaryOutput>;
32
+ declare const writeDynamicDictionary: (mergedDictionaries: MergedDictionaryOutput, configuration?: _intlayer_types0.IntlayerConfig, formats?: ("cjs" | "esm")[]) => Promise<LocalizedDictionaryOutput>;
33
33
  //#endregion
34
34
  export { DictionaryResult, LocalizedDictionaryOutput, LocalizedDictionaryResult, generateDictionaryEntryPoint, writeDynamicDictionary };
35
35
  //# sourceMappingURL=writeDynamicDictionary.d.ts.map
@@ -1,11 +1,11 @@
1
1
  import { LocalizedDictionaryOutput, LocalizedDictionaryResult } from "./writeDynamicDictionary.js";
2
- import * as _intlayer_types2 from "@intlayer/types";
2
+ import * as _intlayer_types6 from "@intlayer/types";
3
3
 
4
4
  //#region src/buildIntlayerDictionary/writeFetchDictionary.d.ts
5
5
  /**
6
6
  * This function generates the content of the dictionary list file
7
7
  */
8
- declare const generateDictionaryEntryPoint: (localedDictionariesPathsRecord: LocalizedDictionaryResult, format?: "cjs" | "esm", configuration?: _intlayer_types2.IntlayerConfig) => string;
8
+ declare const generateDictionaryEntryPoint: (localedDictionariesPathsRecord: LocalizedDictionaryResult, format?: "cjs" | "esm", configuration?: _intlayer_types6.IntlayerConfig) => string;
9
9
  /**
10
10
  * Write the localized dictionaries to the dictionariesDir
11
11
  * @param mergedDictionaries - The merged dictionaries
@@ -22,7 +22,7 @@ declare const generateDictionaryEntryPoint: (localedDictionariesPathsRecord: Loc
22
22
  * // { key: 'home', content: { ... } },
23
23
  * ```
24
24
  */
25
- declare const writeFetchDictionary: (dynamicDictionaries: LocalizedDictionaryOutput, configuration?: _intlayer_types2.IntlayerConfig, formats?: ("cjs" | "esm")[]) => Promise<LocalizedDictionaryOutput>;
25
+ declare const writeFetchDictionary: (dynamicDictionaries: LocalizedDictionaryOutput, configuration?: _intlayer_types6.IntlayerConfig, formats?: ("cjs" | "esm")[]) => Promise<LocalizedDictionaryOutput>;
26
26
  //#endregion
27
27
  export { generateDictionaryEntryPoint, writeFetchDictionary };
28
28
  //# sourceMappingURL=writeFetchDictionary.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { UnmergedDictionaryOutput } from "./writeUnmergedDictionary.js";
2
- import * as _intlayer_types4 from "@intlayer/types";
2
+ import * as _intlayer_types2 from "@intlayer/types";
3
3
  import { Dictionary } from "@intlayer/types";
4
4
 
5
5
  //#region src/buildIntlayerDictionary/writeMergedDictionary.d.ts
@@ -24,7 +24,7 @@ type MergedDictionaryOutput = Record<string, MergedDictionaryResult>;
24
24
  * // { key: 'home', content: { ... } },
25
25
  * ```
26
26
  */
27
- declare const writeMergedDictionaries: (groupedDictionaries: UnmergedDictionaryOutput, configuration?: _intlayer_types4.IntlayerConfig) => Promise<MergedDictionaryOutput>;
27
+ declare const writeMergedDictionaries: (groupedDictionaries: UnmergedDictionaryOutput, configuration?: _intlayer_types2.IntlayerConfig) => Promise<MergedDictionaryOutput>;
28
28
  //#endregion
29
29
  export { MergedDictionaryOutput, MergedDictionaryResult, writeMergedDictionaries };
30
30
  //# sourceMappingURL=writeMergedDictionary.d.ts.map
@@ -1,10 +1,10 @@
1
- import * as _intlayer_types1 from "@intlayer/types";
1
+ import * as _intlayer_types3 from "@intlayer/types";
2
2
 
3
3
  //#region src/createDictionaryEntryPoint/createDictionaryEntryPoint.d.ts
4
4
  /**
5
5
  * This function generates a list of dictionaries in the main directory
6
6
  */
7
- declare const createDictionaryEntryPoint: (configuration?: _intlayer_types1.IntlayerConfig, formats?: ("cjs" | "esm")[]) => Promise<void>;
7
+ declare const createDictionaryEntryPoint: (configuration?: _intlayer_types3.IntlayerConfig, formats?: ("cjs" | "esm")[]) => Promise<void>;
8
8
  //#endregion
9
9
  export { createDictionaryEntryPoint };
10
10
  //# sourceMappingURL=createDictionaryEntryPoint.d.ts.map
@@ -1,10 +1,10 @@
1
- import * as _intlayer_types0 from "@intlayer/types";
1
+ import * as _intlayer_types4 from "@intlayer/types";
2
2
 
3
3
  //#region src/createDictionaryEntryPoint/generateDictionaryListContent.d.ts
4
4
  /**
5
5
  * This function generates the content of the dictionary list file
6
6
  */
7
- declare const generateDictionaryListContent: (dictionaries: string[], functionName: string, format?: "cjs" | "esm", configuration?: _intlayer_types0.IntlayerConfig) => string;
7
+ declare const generateDictionaryListContent: (dictionaries: string[], functionName: string, format?: "cjs" | "esm", configuration?: _intlayer_types4.IntlayerConfig) => string;
8
8
  //#endregion
9
9
  export { generateDictionaryListContent };
10
10
  //# sourceMappingURL=generateDictionaryListContent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/createDictionaryEntryPoint/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,oCAAoC,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/createType/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,cAAc,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mDAAmD,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAC7B,wBAAwB,EACxB,+BAA+B,EAC/B,6BAA6B,EAC7B,8BAA8B,EAC9B,gCAAgC,GACjC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AACjF,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,iCAAiC,EAAE,MAAM,uEAAuE,CAAC;AAC1H,OAAO,EAAE,sCAAsC,EAAE,MAAM,0CAA0C,CAAC;AAClG,OAAO,EAAE,kCAAkC,EAAE,MAAM,sCAAsC,CAAC;AAC1F,OAAO,EAAE,oCAAoC,EAAE,MAAM,wCAAwC,CAAC;AAC9F,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,YAAY,EACZ,YAAY,GACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mDAAmD,CAAC;AAC5F,OAAO,EACL,YAAY,EACZ,SAAS,EACT,KAAK,UAAU,EACf,KAAK,SAAS,GACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EACL,KAAK,SAAS,EACd,KAAK,MAAM,EACX,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,KAAK,cAAc,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EACL,KAAK,gBAAgB,EACrB,2BAA2B,EAC3B,UAAU,EACV,eAAe,EACf,uBAAuB,EACvB,WAAW,GACZ,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,gCAAgC,EAAE,MAAM,4DAA4D,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/loadDictionaries/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC"}
@@ -1,11 +1,11 @@
1
1
  import { DictionariesStatus } from "./loadDictionaries.js";
2
- import * as _intlayer_types6 from "@intlayer/types";
2
+ import * as _intlayer_types8 from "@intlayer/types";
3
3
  import { Dictionary } from "@intlayer/types";
4
4
  import { DictionaryAPI } from "@intlayer/backend";
5
5
 
6
6
  //#region src/loadDictionaries/loadRemoteDictionaries.d.ts
7
7
  declare const formatDistantDictionaries: (dictionaries: (DictionaryAPI | Dictionary)[]) => Dictionary[];
8
- declare const loadRemoteDictionaries: (configuration?: _intlayer_types6.IntlayerConfig, onStatusUpdate?: (status: DictionariesStatus[]) => void, options?: {
8
+ declare const loadRemoteDictionaries: (configuration?: _intlayer_types8.IntlayerConfig, onStatusUpdate?: (status: DictionariesStatus[]) => void, options?: {
9
9
  onStartRemoteCheck?: () => void;
10
10
  onStopRemoteCheck?: () => void;
11
11
  onError?: (error: Error) => void;
@@ -1,5 +1,2 @@
1
- //#region src/utils/extractErrorMessage.d.ts
2
- declare const extractErrorMessage: (error: unknown) => string;
3
- //#endregion
4
- export { extractErrorMessage };
1
+ export declare const extractErrorMessage: (error: unknown) => string;
5
2
  //# sourceMappingURL=extractErrorMessage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extractErrorMessage.d.ts","names":[],"sources":["../../../src/utils/extractErrorMessage.ts"],"sourcesContent":[],"mappings":";cAAa"}
1
+ {"version":3,"file":"extractErrorMessage.d.ts","sourceRoot":"","sources":["../../../src/utils/extractErrorMessage.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,GAAI,OAAO,OAAO,KAAG,MA+JpD,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type IntlayerConfig } from '@intlayer/config';
2
+ export declare const getExtension: (configuration?: IntlayerConfig, format?: "esm" | "cjs" | undefined) => "cjs" | "mjs";
3
+ //# sourceMappingURL=getExtension.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getExtension.d.ts","sourceRoot":"","sources":["../../../src/utils/getExtension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEzE,eAAO,MAAM,YAAY,GACvB,gBAAe,cAAmC,EAClD,SAAS,KAAK,GAAG,KAAK,GAAG,SAAS,kBAWnC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type Dictionary } from '@intlayer/core';
2
+ declare const content: Dictionary;
3
+ export default content;
4
+ //# sourceMappingURL=_test.content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_test.content.d.ts","sourceRoot":"","sources":["../../../src/writeContentDeclaration/_test.content.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EAOhB,MAAM,gBAAgB,CAAC;AAGxB,QAAA,MAAM,OAAO,EAAE,UA8Gd,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { IntlayerConfig } from "@intlayer/types";
2
+
3
+ //#region src/writeContentDeclaration/detectFormatCommand.d.ts
4
+ declare const detectFormatCommand: (configuration: IntlayerConfig) => string;
5
+ //#endregion
6
+ export { detectFormatCommand };
7
+ //# sourceMappingURL=detectFormatCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detectFormatCommand.d.ts","names":[],"sources":["../../../src/writeContentDeclaration/detectFormatCommand.ts"],"sourcesContent":[],"mappings":";;;cAGa,qCAAsC"}
@@ -0,0 +1,2 @@
1
+ export declare const formatCode: (filePath: string, code: string) => Promise<any>;
2
+ //# sourceMappingURL=formatCode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatCode.d.ts","sourceRoot":"","sources":["../../../src/writeContentDeclaration/formatCode.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,GAAU,UAAU,MAAM,EAAE,MAAM,MAAM,iBA+C9D,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/writeContentDeclaration/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"writeJSFile.d.ts","names":[],"sources":["../../../src/writeContentDeclaration/writeJSFile.ts"],"sourcesContent":[],"mappings":";;;;;;AAmBA;;;;AAIU,cAJG,WAIH,EAAA,CAAA,QAAA,EAAA,MAAA,EAAA,UAAA,EAFI,UAEJ,EAAA,aAAA,EADO,cACP,EAAA,GAAP,OAAO,CAAA,IAAA,CAAA"}
1
+ {"version":3,"file":"writeJSFile.d.ts","names":[],"sources":["../../../src/writeContentDeclaration/writeJSFile.ts"],"sourcesContent":[],"mappings":";;;;;;AAoBA;;;;AAIU,cAJG,WAIH,EAAA,CAAA,QAAA,EAAA,MAAA,EAAA,UAAA,EAFI,UAEJ,EAAA,aAAA,EADO,cACP,EAAA,GAAP,OAAO,CAAA,IAAA,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/chokidar",
3
- "version": "7.0.0-canary.3",
3
+ "version": "7.0.0",
4
4
  "private": false,
5
5
  "description": "Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.",
6
6
  "keywords": [
@@ -71,13 +71,13 @@
71
71
  "typecheck": "tsc --noEmit --project tsconfig.types.json"
72
72
  },
73
73
  "dependencies": {
74
- "@intlayer/api": "7.0.0-canary.3",
75
- "@intlayer/config": "7.0.0-canary.3",
76
- "@intlayer/core": "7.0.0-canary.3",
77
- "@intlayer/dictionaries-entry": "7.0.0-canary.3",
78
- "@intlayer/remote-dictionaries-entry": "7.0.0-canary.3",
79
- "@intlayer/types": "7.0.0-canary.3",
80
- "@intlayer/unmerged-dictionaries-entry": "7.0.0-canary.3",
74
+ "@intlayer/api": "7.0.0",
75
+ "@intlayer/config": "7.0.0",
76
+ "@intlayer/core": "7.0.0",
77
+ "@intlayer/dictionaries-entry": "7.0.0",
78
+ "@intlayer/remote-dictionaries-entry": "7.0.0",
79
+ "@intlayer/types": "7.0.0",
80
+ "@intlayer/unmerged-dictionaries-entry": "7.0.0",
81
81
  "chokidar": "3.6.0",
82
82
  "crypto-js": "4.2.0",
83
83
  "deep-equal": "2.2.3",
@@ -90,22 +90,22 @@
90
90
  "@types/crypto-js": "4.2.2",
91
91
  "@types/deep-equal": "1.0.4",
92
92
  "@types/node": "24.9.1",
93
- "@utils/ts-config": "7.0.0-canary.3",
94
- "@utils/ts-config-types": "7.0.0-canary.3",
95
- "@utils/tsdown-config": "7.0.0-canary.3",
93
+ "@utils/ts-config": "7.0.0",
94
+ "@utils/ts-config-types": "7.0.0",
95
+ "@utils/tsdown-config": "7.0.0",
96
96
  "rimraf": "6.0.1",
97
97
  "tsdown": "0.15.9",
98
98
  "typescript": "5.9.3",
99
99
  "vitest": "4.0.3"
100
100
  },
101
101
  "peerDependencies": {
102
- "@intlayer/api": "7.0.0-canary.3",
103
- "@intlayer/config": "7.0.0-canary.3",
104
- "@intlayer/core": "7.0.0-canary.3",
105
- "@intlayer/dictionaries-entry": "7.0.0-canary.3",
106
- "@intlayer/remote-dictionaries-entry": "7.0.0-canary.3",
107
- "@intlayer/types": "7.0.0-canary.3",
108
- "@intlayer/unmerged-dictionaries-entry": "7.0.0-canary.3",
102
+ "@intlayer/api": "7.0.0",
103
+ "@intlayer/config": "7.0.0",
104
+ "@intlayer/core": "7.0.0",
105
+ "@intlayer/dictionaries-entry": "7.0.0",
106
+ "@intlayer/remote-dictionaries-entry": "7.0.0",
107
+ "@intlayer/types": "7.0.0",
108
+ "@intlayer/unmerged-dictionaries-entry": "7.0.0",
109
109
  "fast-glob": "3.3.3"
110
110
  },
111
111
  "engines": {
@@ -1,95 +0,0 @@
1
-
2
- //#region src/utils/extractErrorMessage.ts
3
- const extractErrorMessage = (error) => {
4
- const trimToSingleLine = (text) => text.split(/\r?\n/).map((s) => s.trim()).filter(Boolean)[0] ?? text.trim();
5
- const looksLikeJson = (value) => {
6
- const s = value.trim();
7
- if (!s) return false;
8
- const first = s[0];
9
- return first === "{" || first === "[" || first === "\"";
10
- };
11
- const sanitizeUnexpectedTokenMessage = (text) => {
12
- const t = text.trim();
13
- if (/Unexpected token/i.test(t) && /not valid JSON/i.test(t)) {
14
- const quoted = t.match(/"([^"]+)"/);
15
- if (quoted?.[1]) return quoted[1];
16
- const afterColon = t.split(":").slice(1).join(":").trim();
17
- if (afterColon) return afterColon;
18
- }
19
- return t;
20
- };
21
- const pickFieldsFromObject = (value, seen) => {
22
- if (!value || typeof value !== "object") return void 0;
23
- if (seen.has(value)) return void 0;
24
- seen.add(value);
25
- const obj = value;
26
- if (typeof obj.message === "string" && obj.message.trim()) return obj.message;
27
- if (typeof obj.error_description === "string" && obj.error_description.trim()) return obj.error_description;
28
- if (typeof obj.error === "string" && obj.error.trim()) return obj.error;
29
- const title = typeof obj.title === "string" ? obj.title.trim() : "";
30
- const code = typeof obj.code === "string" ? obj.code.trim() : "";
31
- if (title && code) return `${title} (${code})`;
32
- if (title) return title;
33
- if (code) return code;
34
- if (typeof obj.statusText === "string" && obj.statusText.trim()) return obj.statusText;
35
- const response = obj.response;
36
- if (response && typeof response === "object") {
37
- const data$1 = response.data;
38
- const fromData$1 = pickFieldsFromObject(data$1, seen);
39
- if (fromData$1) return fromData$1;
40
- }
41
- const data = obj.data;
42
- const fromData = pickFieldsFromObject(data, seen);
43
- if (fromData) return fromData;
44
- const cause = obj.cause;
45
- const fromCause = pickFieldsFromObject(cause, seen) ?? (typeof cause?.message === "string" ? cause.message : void 0);
46
- if (fromCause) return fromCause;
47
- const errors = obj.errors;
48
- if (Array.isArray(errors)) for (const item of errors) {
49
- const fromItem = pickFieldsFromObject(item, seen);
50
- if (fromItem) return fromItem;
51
- if (typeof item?.message === "string") return item.message;
52
- }
53
- };
54
- const tryParseJsonString = (maybeJson) => {
55
- if (!looksLikeJson(maybeJson)) return void 0;
56
- try {
57
- const parsed = JSON.parse(maybeJson);
58
- const picked = pickFieldsFromObject(parsed, /* @__PURE__ */ new Set());
59
- if (picked) return picked;
60
- if (typeof parsed === "string") return parsed;
61
- return;
62
- } catch {
63
- return;
64
- }
65
- };
66
- if (typeof error === "string") {
67
- const cleaned = sanitizeUnexpectedTokenMessage(error);
68
- return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);
69
- }
70
- if (error && typeof error === "object") {
71
- if (error instanceof Error) {
72
- const cleaned = sanitizeUnexpectedTokenMessage(error.message);
73
- const fromMessage = tryParseJsonString(cleaned);
74
- if (fromMessage) return trimToSingleLine(fromMessage);
75
- const fromCause = extractErrorMessage(error.cause);
76
- if (fromCause && fromCause !== "An unknown error occurred") return trimToSingleLine(fromCause);
77
- return trimToSingleLine(cleaned);
78
- }
79
- const fromObject = pickFieldsFromObject(error, /* @__PURE__ */ new Set());
80
- if (fromObject) {
81
- const cleaned = sanitizeUnexpectedTokenMessage(fromObject);
82
- return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);
83
- }
84
- try {
85
- return trimToSingleLine(JSON.stringify(error));
86
- } catch {
87
- return trimToSingleLine(String(error));
88
- }
89
- }
90
- return "An unknown error occurred";
91
- };
92
-
93
- //#endregion
94
- exports.extractErrorMessage = extractErrorMessage;
95
- //# sourceMappingURL=extractErrorMessage.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extractErrorMessage.cjs","names":["data","fromData"],"sources":["../../../src/utils/extractErrorMessage.ts"],"sourcesContent":["export const extractErrorMessage = (error: unknown): string => {\n const trimToSingleLine = (text: string): string =>\n text\n .split(/\\r?\\n/)\n .map((s) => s.trim())\n .filter(Boolean)[0] ?? text.trim();\n\n const looksLikeJson = (value: string): boolean => {\n const s = value.trim();\n if (!s) return false;\n const first = s[0];\n return first === '{' || first === '[' || first === '\"';\n };\n\n const sanitizeUnexpectedTokenMessage = (text: string): string => {\n // If the text mentions an invalid JSON parse, try to extract the meaningful part\n const t = text.trim();\n if (/Unexpected token/i.test(t) && /not valid JSON/i.test(t)) {\n const quoted = t.match(/\"([^\"]+)\"/);\n if (quoted?.[1]) return quoted[1];\n // Fallback: drop the leading parser error description\n const afterColon = t.split(':').slice(1).join(':').trim();\n if (afterColon) return afterColon;\n }\n return t;\n };\n\n const pickFieldsFromObject = (\n value: unknown,\n seen: Set<unknown>\n ): string | undefined => {\n if (!value || typeof value !== 'object') return undefined;\n if (seen.has(value)) return undefined;\n seen.add(value);\n\n const obj = value as Record<string, unknown>;\n\n // Check for message first (highest priority)\n if (typeof obj.message === 'string' && obj.message.trim()) {\n return obj.message;\n }\n\n // Check for error_description\n if (\n typeof obj.error_description === 'string' &&\n obj.error_description.trim()\n ) {\n return obj.error_description;\n }\n\n // Check for error\n if (typeof obj.error === 'string' && obj.error.trim()) {\n return obj.error;\n }\n\n // Handle title and code combination\n const title = typeof obj.title === 'string' ? obj.title.trim() : '';\n const code = typeof obj.code === 'string' ? obj.code.trim() : '';\n\n if (title && code) {\n return `${title} (${code})`;\n }\n\n if (title) {\n return title;\n }\n\n if (code) {\n return code;\n }\n\n // Check for statusText\n if (typeof obj.statusText === 'string' && obj.statusText.trim()) {\n return obj.statusText;\n }\n\n // Common nested structures (Axios/Fetch-like)\n const response = obj.response as Record<string, unknown> | undefined;\n if (response && typeof response === 'object') {\n const data = response.data as unknown;\n const fromData = pickFieldsFromObject(data, seen);\n if (fromData) return fromData;\n }\n\n const data = obj.data as unknown;\n const fromData = pickFieldsFromObject(data, seen);\n if (fromData) return fromData;\n\n // Nested cause chain\n const cause = (obj as { cause?: unknown }).cause;\n const fromCause =\n pickFieldsFromObject(cause, seen) ??\n (typeof (cause as any)?.message === 'string'\n ? (cause as any).message\n : undefined);\n if (fromCause) return fromCause;\n\n // Arrays of errors\n const errors = obj.errors as unknown;\n if (Array.isArray(errors)) {\n for (const item of errors) {\n const fromItem = pickFieldsFromObject(item, seen);\n if (fromItem) return fromItem;\n if (typeof (item as any)?.message === 'string')\n return (item as any).message;\n }\n }\n\n return undefined;\n };\n\n const tryParseJsonString = (maybeJson: string): string | undefined => {\n if (!looksLikeJson(maybeJson)) return undefined;\n try {\n const parsed = JSON.parse(maybeJson);\n const picked = pickFieldsFromObject(parsed, new Set());\n if (picked) return picked;\n if (typeof parsed === 'string') return parsed;\n return undefined;\n } catch {\n return undefined;\n }\n };\n\n if (typeof error === 'string') {\n const cleaned = sanitizeUnexpectedTokenMessage(error);\n return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);\n }\n\n if (error && typeof error === 'object') {\n // Native Error instance\n if (error instanceof Error) {\n const cleaned = sanitizeUnexpectedTokenMessage(error.message);\n const fromMessage = tryParseJsonString(cleaned);\n if (fromMessage) return trimToSingleLine(fromMessage);\n // Dive into cause when present\n const fromCause = extractErrorMessage(error.cause as unknown);\n if (fromCause && fromCause !== 'An unknown error occurred')\n return trimToSingleLine(fromCause);\n return trimToSingleLine(cleaned);\n }\n\n // Generic object\n const seen = new Set<unknown>();\n const fromObject = pickFieldsFromObject(error, seen);\n if (fromObject) {\n const cleaned = sanitizeUnexpectedTokenMessage(fromObject);\n return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);\n }\n\n try {\n const serialized = JSON.stringify(error);\n return trimToSingleLine(serialized);\n } catch {\n return trimToSingleLine(String(error));\n }\n }\n\n return 'An unknown error occurred';\n};\n"],"mappings":"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"}
@@ -1,54 +0,0 @@
1
-
2
- //#region src/utils/verifyIdenticObjectFormat copy.ts
3
- /**
4
- * Verifies that two objects have identical structure (same keys, array lengths, and types)
5
- * but not necessarily the same values.
6
- * Useful for validating translations maintain the same format as the original.
7
- *
8
- * @param object - The object to verify
9
- * @param expectedFormat - The expected format to compare against
10
- * @param path - Current path in the object tree (for error messages)
11
- * @returns true if structures match, throws error with details if they don't
12
- */
13
- const verifyIdenticObjectFormat = (object, expectedFormat, path = "root") => {
14
- if (expectedFormat === null || expectedFormat === void 0) {
15
- if (expectedFormat !== object) return {
16
- isIdentic: false,
17
- error: `Type mismatch at ${path}: expected ${expectedFormat === null ? "null" : "undefined"}, got ${object === null ? "null" : typeof object}`
18
- };
19
- return { isIdentic: true };
20
- }
21
- const expectedType = Array.isArray(expectedFormat) ? "array" : typeof expectedFormat;
22
- const objectType = Array.isArray(object) ? "array" : typeof object;
23
- if (expectedType !== objectType) return {
24
- isIdentic: false,
25
- error: `Type mismatch at ${path}: expected ${expectedType}, got ${objectType}`
26
- };
27
- if (Array.isArray(expectedFormat) && Array.isArray(object)) {
28
- if (expectedFormat.length !== object.length) return {
29
- isIdentic: false,
30
- error: `Array length mismatch at ${path}: expected ${expectedFormat.length} elements, got ${object.length}`
31
- };
32
- for (let i = 0; i < expectedFormat.length; i++) verifyIdenticObjectFormat(object[i], expectedFormat[i], `${path}[${i}]`);
33
- return { isIdentic: true };
34
- }
35
- if (typeof expectedFormat === "object" && typeof object === "object" && expectedFormat !== null && object !== null) {
36
- const expectedKeys = Object.keys(expectedFormat);
37
- const objectKeys = Object.keys(object);
38
- if (expectedKeys.length !== objectKeys.length) return {
39
- isIdentic: false,
40
- error: `Object keys count mismatch at ${path}: expected ${expectedKeys.length} keys, got ${objectKeys.length}`
41
- };
42
- for (let i = 0; i < expectedKeys.length; i++) if (expectedKeys[i] !== objectKeys[i]) return {
43
- isIdentic: false,
44
- error: `Object keys mismatch at ${path}: expected key "${expectedKeys[i]}" at position ${i}, got "${objectKeys[i]}"`
45
- };
46
- for (const key of expectedKeys) verifyIdenticObjectFormat(object[key], expectedFormat[key], `${path}.${key}`);
47
- return { isIdentic: true };
48
- }
49
- return { isIdentic: true };
50
- };
51
-
52
- //#endregion
53
- exports.verifyIdenticObjectFormat = verifyIdenticObjectFormat;
54
- //# sourceMappingURL=verifyIdenticObjectFormat copy.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"verifyIdenticObjectFormat copy.cjs","names":[],"sources":["../../../src/utils/verifyIdenticObjectFormat copy.ts"],"sourcesContent":["type FlatType = string | number | boolean | object | null | undefined;\n\ntype RecursiveType =\n | FlatType\n | { [key: string]: RecursiveType }\n | Array<RecursiveType>;\n\ntype VerifyIdenticObjectFormatResult = {\n isIdentic: boolean;\n error?: string;\n};\n\n/**\n * Verifies that two objects have identical structure (same keys, array lengths, and types)\n * but not necessarily the same values.\n * Useful for validating translations maintain the same format as the original.\n *\n * @param object - The object to verify\n * @param expectedFormat - The expected format to compare against\n * @param path - Current path in the object tree (for error messages)\n * @returns true if structures match, throws error with details if they don't\n */\nexport const verifyIdenticObjectFormat = (\n object: RecursiveType,\n expectedFormat: RecursiveType,\n path: string = 'root'\n): VerifyIdenticObjectFormatResult => {\n // Check if both are null or undefined\n if (expectedFormat === null || expectedFormat === undefined) {\n if (expectedFormat !== object) {\n return {\n isIdentic: false,\n error: `Type mismatch at ${path}: expected ${expectedFormat === null ? 'null' : 'undefined'}, got ${object === null ? 'null' : typeof object}`,\n };\n }\n return {\n isIdentic: true,\n };\n }\n\n // Get the type of both values\n const expectedType = Array.isArray(expectedFormat)\n ? 'array'\n : typeof expectedFormat;\n const objectType = Array.isArray(object) ? 'array' : typeof object;\n\n // Check if types match\n if (expectedType !== objectType) {\n return {\n isIdentic: false,\n error: `Type mismatch at ${path}: expected ${expectedType}, got ${objectType}`,\n };\n }\n\n // Handle arrays\n if (Array.isArray(expectedFormat) && Array.isArray(object)) {\n if (expectedFormat.length !== object.length) {\n return {\n isIdentic: false,\n error: `Array length mismatch at ${path}: expected ${expectedFormat.length} elements, got ${object.length}`,\n };\n }\n\n // Recursively check each element\n for (let i = 0; i < expectedFormat.length; i++) {\n verifyIdenticObjectFormat(object[i], expectedFormat[i], `${path}[${i}]`);\n }\n\n return {\n isIdentic: true,\n };\n }\n\n // Handle objects (excluding null and arrays)\n if (\n typeof expectedFormat === 'object' &&\n typeof object === 'object' &&\n expectedFormat !== null &&\n object !== null\n ) {\n const expectedKeys = Object.keys(expectedFormat);\n const objectKeys = Object.keys(object);\n\n // Check if number of keys match\n if (expectedKeys.length !== objectKeys.length) {\n return {\n isIdentic: false,\n error: `Object keys count mismatch at ${path}: expected ${expectedKeys.length} keys, got ${objectKeys.length}`,\n };\n }\n\n // Check if keys match and are in the same order\n for (let i = 0; i < expectedKeys.length; i++) {\n if (expectedKeys[i] !== objectKeys[i]) {\n return {\n isIdentic: false,\n error: `Object keys mismatch at ${path}: expected key \"${expectedKeys[i]}\" at position ${i}, got \"${objectKeys[i]}\"`,\n };\n }\n }\n\n // Recursively check each property\n for (const key of expectedKeys) {\n verifyIdenticObjectFormat(\n (object as Record<string, RecursiveType>)[key],\n (expectedFormat as Record<string, RecursiveType>)[key],\n `${path}.${key}`\n );\n }\n\n return {\n isIdentic: true,\n };\n }\n\n // For primitive types (string, number, boolean), just verify they're the same type\n // We don't check the actual values as per requirements\n return {\n isIdentic: true,\n };\n};\n"],"mappings":";;;;;;;;;;;;AAsBA,MAAa,6BACX,QACA,gBACA,OAAe,WACqB;AAEpC,KAAI,mBAAmB,QAAQ,mBAAmB,QAAW;AAC3D,MAAI,mBAAmB,OACrB,QAAO;GACL,WAAW;GACX,OAAO,oBAAoB,KAAK,aAAa,mBAAmB,OAAO,SAAS,YAAY,QAAQ,WAAW,OAAO,SAAS,OAAO;GACvI;AAEH,SAAO,EACL,WAAW,MACZ;;CAIH,MAAM,eAAe,MAAM,QAAQ,eAAe,GAC9C,UACA,OAAO;CACX,MAAM,aAAa,MAAM,QAAQ,OAAO,GAAG,UAAU,OAAO;AAG5D,KAAI,iBAAiB,WACnB,QAAO;EACL,WAAW;EACX,OAAO,oBAAoB,KAAK,aAAa,aAAa,QAAQ;EACnE;AAIH,KAAI,MAAM,QAAQ,eAAe,IAAI,MAAM,QAAQ,OAAO,EAAE;AAC1D,MAAI,eAAe,WAAW,OAAO,OACnC,QAAO;GACL,WAAW;GACX,OAAO,4BAA4B,KAAK,aAAa,eAAe,OAAO,iBAAiB,OAAO;GACpG;AAIH,OAAK,IAAI,IAAI,GAAG,IAAI,eAAe,QAAQ,IACzC,2BAA0B,OAAO,IAAI,eAAe,IAAI,GAAG,KAAK,GAAG,EAAE,GAAG;AAG1E,SAAO,EACL,WAAW,MACZ;;AAIH,KACE,OAAO,mBAAmB,YAC1B,OAAO,WAAW,YAClB,mBAAmB,QACnB,WAAW,MACX;EACA,MAAM,eAAe,OAAO,KAAK,eAAe;EAChD,MAAM,aAAa,OAAO,KAAK,OAAO;AAGtC,MAAI,aAAa,WAAW,WAAW,OACrC,QAAO;GACL,WAAW;GACX,OAAO,iCAAiC,KAAK,aAAa,aAAa,OAAO,aAAa,WAAW;GACvG;AAIH,OAAK,IAAI,IAAI,GAAG,IAAI,aAAa,QAAQ,IACvC,KAAI,aAAa,OAAO,WAAW,GACjC,QAAO;GACL,WAAW;GACX,OAAO,2BAA2B,KAAK,kBAAkB,aAAa,GAAG,gBAAgB,EAAE,SAAS,WAAW,GAAG;GACnH;AAKL,OAAK,MAAM,OAAO,aAChB,2BACG,OAAyC,MACzC,eAAiD,MAClD,GAAG,KAAK,GAAG,MACZ;AAGH,SAAO,EACL,WAAW,MACZ;;AAKH,QAAO,EACL,WAAW,MACZ"}
@@ -1,94 +0,0 @@
1
- //#region src/utils/extractErrorMessage.ts
2
- const extractErrorMessage = (error) => {
3
- const trimToSingleLine = (text) => text.split(/\r?\n/).map((s) => s.trim()).filter(Boolean)[0] ?? text.trim();
4
- const looksLikeJson = (value) => {
5
- const s = value.trim();
6
- if (!s) return false;
7
- const first = s[0];
8
- return first === "{" || first === "[" || first === "\"";
9
- };
10
- const sanitizeUnexpectedTokenMessage = (text) => {
11
- const t = text.trim();
12
- if (/Unexpected token/i.test(t) && /not valid JSON/i.test(t)) {
13
- const quoted = t.match(/"([^"]+)"/);
14
- if (quoted?.[1]) return quoted[1];
15
- const afterColon = t.split(":").slice(1).join(":").trim();
16
- if (afterColon) return afterColon;
17
- }
18
- return t;
19
- };
20
- const pickFieldsFromObject = (value, seen) => {
21
- if (!value || typeof value !== "object") return void 0;
22
- if (seen.has(value)) return void 0;
23
- seen.add(value);
24
- const obj = value;
25
- if (typeof obj.message === "string" && obj.message.trim()) return obj.message;
26
- if (typeof obj.error_description === "string" && obj.error_description.trim()) return obj.error_description;
27
- if (typeof obj.error === "string" && obj.error.trim()) return obj.error;
28
- const title = typeof obj.title === "string" ? obj.title.trim() : "";
29
- const code = typeof obj.code === "string" ? obj.code.trim() : "";
30
- if (title && code) return `${title} (${code})`;
31
- if (title) return title;
32
- if (code) return code;
33
- if (typeof obj.statusText === "string" && obj.statusText.trim()) return obj.statusText;
34
- const response = obj.response;
35
- if (response && typeof response === "object") {
36
- const data$1 = response.data;
37
- const fromData$1 = pickFieldsFromObject(data$1, seen);
38
- if (fromData$1) return fromData$1;
39
- }
40
- const data = obj.data;
41
- const fromData = pickFieldsFromObject(data, seen);
42
- if (fromData) return fromData;
43
- const cause = obj.cause;
44
- const fromCause = pickFieldsFromObject(cause, seen) ?? (typeof cause?.message === "string" ? cause.message : void 0);
45
- if (fromCause) return fromCause;
46
- const errors = obj.errors;
47
- if (Array.isArray(errors)) for (const item of errors) {
48
- const fromItem = pickFieldsFromObject(item, seen);
49
- if (fromItem) return fromItem;
50
- if (typeof item?.message === "string") return item.message;
51
- }
52
- };
53
- const tryParseJsonString = (maybeJson) => {
54
- if (!looksLikeJson(maybeJson)) return void 0;
55
- try {
56
- const parsed = JSON.parse(maybeJson);
57
- const picked = pickFieldsFromObject(parsed, /* @__PURE__ */ new Set());
58
- if (picked) return picked;
59
- if (typeof parsed === "string") return parsed;
60
- return;
61
- } catch {
62
- return;
63
- }
64
- };
65
- if (typeof error === "string") {
66
- const cleaned = sanitizeUnexpectedTokenMessage(error);
67
- return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);
68
- }
69
- if (error && typeof error === "object") {
70
- if (error instanceof Error) {
71
- const cleaned = sanitizeUnexpectedTokenMessage(error.message);
72
- const fromMessage = tryParseJsonString(cleaned);
73
- if (fromMessage) return trimToSingleLine(fromMessage);
74
- const fromCause = extractErrorMessage(error.cause);
75
- if (fromCause && fromCause !== "An unknown error occurred") return trimToSingleLine(fromCause);
76
- return trimToSingleLine(cleaned);
77
- }
78
- const fromObject = pickFieldsFromObject(error, /* @__PURE__ */ new Set());
79
- if (fromObject) {
80
- const cleaned = sanitizeUnexpectedTokenMessage(fromObject);
81
- return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);
82
- }
83
- try {
84
- return trimToSingleLine(JSON.stringify(error));
85
- } catch {
86
- return trimToSingleLine(String(error));
87
- }
88
- }
89
- return "An unknown error occurred";
90
- };
91
-
92
- //#endregion
93
- export { extractErrorMessage };
94
- //# sourceMappingURL=extractErrorMessage.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extractErrorMessage.mjs","names":["data","fromData"],"sources":["../../../src/utils/extractErrorMessage.ts"],"sourcesContent":["export const extractErrorMessage = (error: unknown): string => {\n const trimToSingleLine = (text: string): string =>\n text\n .split(/\\r?\\n/)\n .map((s) => s.trim())\n .filter(Boolean)[0] ?? text.trim();\n\n const looksLikeJson = (value: string): boolean => {\n const s = value.trim();\n if (!s) return false;\n const first = s[0];\n return first === '{' || first === '[' || first === '\"';\n };\n\n const sanitizeUnexpectedTokenMessage = (text: string): string => {\n // If the text mentions an invalid JSON parse, try to extract the meaningful part\n const t = text.trim();\n if (/Unexpected token/i.test(t) && /not valid JSON/i.test(t)) {\n const quoted = t.match(/\"([^\"]+)\"/);\n if (quoted?.[1]) return quoted[1];\n // Fallback: drop the leading parser error description\n const afterColon = t.split(':').slice(1).join(':').trim();\n if (afterColon) return afterColon;\n }\n return t;\n };\n\n const pickFieldsFromObject = (\n value: unknown,\n seen: Set<unknown>\n ): string | undefined => {\n if (!value || typeof value !== 'object') return undefined;\n if (seen.has(value)) return undefined;\n seen.add(value);\n\n const obj = value as Record<string, unknown>;\n\n // Check for message first (highest priority)\n if (typeof obj.message === 'string' && obj.message.trim()) {\n return obj.message;\n }\n\n // Check for error_description\n if (\n typeof obj.error_description === 'string' &&\n obj.error_description.trim()\n ) {\n return obj.error_description;\n }\n\n // Check for error\n if (typeof obj.error === 'string' && obj.error.trim()) {\n return obj.error;\n }\n\n // Handle title and code combination\n const title = typeof obj.title === 'string' ? obj.title.trim() : '';\n const code = typeof obj.code === 'string' ? obj.code.trim() : '';\n\n if (title && code) {\n return `${title} (${code})`;\n }\n\n if (title) {\n return title;\n }\n\n if (code) {\n return code;\n }\n\n // Check for statusText\n if (typeof obj.statusText === 'string' && obj.statusText.trim()) {\n return obj.statusText;\n }\n\n // Common nested structures (Axios/Fetch-like)\n const response = obj.response as Record<string, unknown> | undefined;\n if (response && typeof response === 'object') {\n const data = response.data as unknown;\n const fromData = pickFieldsFromObject(data, seen);\n if (fromData) return fromData;\n }\n\n const data = obj.data as unknown;\n const fromData = pickFieldsFromObject(data, seen);\n if (fromData) return fromData;\n\n // Nested cause chain\n const cause = (obj as { cause?: unknown }).cause;\n const fromCause =\n pickFieldsFromObject(cause, seen) ??\n (typeof (cause as any)?.message === 'string'\n ? (cause as any).message\n : undefined);\n if (fromCause) return fromCause;\n\n // Arrays of errors\n const errors = obj.errors as unknown;\n if (Array.isArray(errors)) {\n for (const item of errors) {\n const fromItem = pickFieldsFromObject(item, seen);\n if (fromItem) return fromItem;\n if (typeof (item as any)?.message === 'string')\n return (item as any).message;\n }\n }\n\n return undefined;\n };\n\n const tryParseJsonString = (maybeJson: string): string | undefined => {\n if (!looksLikeJson(maybeJson)) return undefined;\n try {\n const parsed = JSON.parse(maybeJson);\n const picked = pickFieldsFromObject(parsed, new Set());\n if (picked) return picked;\n if (typeof parsed === 'string') return parsed;\n return undefined;\n } catch {\n return undefined;\n }\n };\n\n if (typeof error === 'string') {\n const cleaned = sanitizeUnexpectedTokenMessage(error);\n return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);\n }\n\n if (error && typeof error === 'object') {\n // Native Error instance\n if (error instanceof Error) {\n const cleaned = sanitizeUnexpectedTokenMessage(error.message);\n const fromMessage = tryParseJsonString(cleaned);\n if (fromMessage) return trimToSingleLine(fromMessage);\n // Dive into cause when present\n const fromCause = extractErrorMessage(error.cause as unknown);\n if (fromCause && fromCause !== 'An unknown error occurred')\n return trimToSingleLine(fromCause);\n return trimToSingleLine(cleaned);\n }\n\n // Generic object\n const seen = new Set<unknown>();\n const fromObject = pickFieldsFromObject(error, seen);\n if (fromObject) {\n const cleaned = sanitizeUnexpectedTokenMessage(fromObject);\n return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);\n }\n\n try {\n const serialized = JSON.stringify(error);\n return trimToSingleLine(serialized);\n } catch {\n return trimToSingleLine(String(error));\n }\n }\n\n return 'An unknown error occurred';\n};\n"],"mappings":"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"}
@@ -1,53 +0,0 @@
1
- //#region src/utils/verifyIdenticObjectFormat copy.ts
2
- /**
3
- * Verifies that two objects have identical structure (same keys, array lengths, and types)
4
- * but not necessarily the same values.
5
- * Useful for validating translations maintain the same format as the original.
6
- *
7
- * @param object - The object to verify
8
- * @param expectedFormat - The expected format to compare against
9
- * @param path - Current path in the object tree (for error messages)
10
- * @returns true if structures match, throws error with details if they don't
11
- */
12
- const verifyIdenticObjectFormat = (object, expectedFormat, path = "root") => {
13
- if (expectedFormat === null || expectedFormat === void 0) {
14
- if (expectedFormat !== object) return {
15
- isIdentic: false,
16
- error: `Type mismatch at ${path}: expected ${expectedFormat === null ? "null" : "undefined"}, got ${object === null ? "null" : typeof object}`
17
- };
18
- return { isIdentic: true };
19
- }
20
- const expectedType = Array.isArray(expectedFormat) ? "array" : typeof expectedFormat;
21
- const objectType = Array.isArray(object) ? "array" : typeof object;
22
- if (expectedType !== objectType) return {
23
- isIdentic: false,
24
- error: `Type mismatch at ${path}: expected ${expectedType}, got ${objectType}`
25
- };
26
- if (Array.isArray(expectedFormat) && Array.isArray(object)) {
27
- if (expectedFormat.length !== object.length) return {
28
- isIdentic: false,
29
- error: `Array length mismatch at ${path}: expected ${expectedFormat.length} elements, got ${object.length}`
30
- };
31
- for (let i = 0; i < expectedFormat.length; i++) verifyIdenticObjectFormat(object[i], expectedFormat[i], `${path}[${i}]`);
32
- return { isIdentic: true };
33
- }
34
- if (typeof expectedFormat === "object" && typeof object === "object" && expectedFormat !== null && object !== null) {
35
- const expectedKeys = Object.keys(expectedFormat);
36
- const objectKeys = Object.keys(object);
37
- if (expectedKeys.length !== objectKeys.length) return {
38
- isIdentic: false,
39
- error: `Object keys count mismatch at ${path}: expected ${expectedKeys.length} keys, got ${objectKeys.length}`
40
- };
41
- for (let i = 0; i < expectedKeys.length; i++) if (expectedKeys[i] !== objectKeys[i]) return {
42
- isIdentic: false,
43
- error: `Object keys mismatch at ${path}: expected key "${expectedKeys[i]}" at position ${i}, got "${objectKeys[i]}"`
44
- };
45
- for (const key of expectedKeys) verifyIdenticObjectFormat(object[key], expectedFormat[key], `${path}.${key}`);
46
- return { isIdentic: true };
47
- }
48
- return { isIdentic: true };
49
- };
50
-
51
- //#endregion
52
- export { verifyIdenticObjectFormat };
53
- //# sourceMappingURL=verifyIdenticObjectFormat copy.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"verifyIdenticObjectFormat copy.mjs","names":[],"sources":["../../../src/utils/verifyIdenticObjectFormat copy.ts"],"sourcesContent":["type FlatType = string | number | boolean | object | null | undefined;\n\ntype RecursiveType =\n | FlatType\n | { [key: string]: RecursiveType }\n | Array<RecursiveType>;\n\ntype VerifyIdenticObjectFormatResult = {\n isIdentic: boolean;\n error?: string;\n};\n\n/**\n * Verifies that two objects have identical structure (same keys, array lengths, and types)\n * but not necessarily the same values.\n * Useful for validating translations maintain the same format as the original.\n *\n * @param object - The object to verify\n * @param expectedFormat - The expected format to compare against\n * @param path - Current path in the object tree (for error messages)\n * @returns true if structures match, throws error with details if they don't\n */\nexport const verifyIdenticObjectFormat = (\n object: RecursiveType,\n expectedFormat: RecursiveType,\n path: string = 'root'\n): VerifyIdenticObjectFormatResult => {\n // Check if both are null or undefined\n if (expectedFormat === null || expectedFormat === undefined) {\n if (expectedFormat !== object) {\n return {\n isIdentic: false,\n error: `Type mismatch at ${path}: expected ${expectedFormat === null ? 'null' : 'undefined'}, got ${object === null ? 'null' : typeof object}`,\n };\n }\n return {\n isIdentic: true,\n };\n }\n\n // Get the type of both values\n const expectedType = Array.isArray(expectedFormat)\n ? 'array'\n : typeof expectedFormat;\n const objectType = Array.isArray(object) ? 'array' : typeof object;\n\n // Check if types match\n if (expectedType !== objectType) {\n return {\n isIdentic: false,\n error: `Type mismatch at ${path}: expected ${expectedType}, got ${objectType}`,\n };\n }\n\n // Handle arrays\n if (Array.isArray(expectedFormat) && Array.isArray(object)) {\n if (expectedFormat.length !== object.length) {\n return {\n isIdentic: false,\n error: `Array length mismatch at ${path}: expected ${expectedFormat.length} elements, got ${object.length}`,\n };\n }\n\n // Recursively check each element\n for (let i = 0; i < expectedFormat.length; i++) {\n verifyIdenticObjectFormat(object[i], expectedFormat[i], `${path}[${i}]`);\n }\n\n return {\n isIdentic: true,\n };\n }\n\n // Handle objects (excluding null and arrays)\n if (\n typeof expectedFormat === 'object' &&\n typeof object === 'object' &&\n expectedFormat !== null &&\n object !== null\n ) {\n const expectedKeys = Object.keys(expectedFormat);\n const objectKeys = Object.keys(object);\n\n // Check if number of keys match\n if (expectedKeys.length !== objectKeys.length) {\n return {\n isIdentic: false,\n error: `Object keys count mismatch at ${path}: expected ${expectedKeys.length} keys, got ${objectKeys.length}`,\n };\n }\n\n // Check if keys match and are in the same order\n for (let i = 0; i < expectedKeys.length; i++) {\n if (expectedKeys[i] !== objectKeys[i]) {\n return {\n isIdentic: false,\n error: `Object keys mismatch at ${path}: expected key \"${expectedKeys[i]}\" at position ${i}, got \"${objectKeys[i]}\"`,\n };\n }\n }\n\n // Recursively check each property\n for (const key of expectedKeys) {\n verifyIdenticObjectFormat(\n (object as Record<string, RecursiveType>)[key],\n (expectedFormat as Record<string, RecursiveType>)[key],\n `${path}.${key}`\n );\n }\n\n return {\n isIdentic: true,\n };\n }\n\n // For primitive types (string, number, boolean), just verify they're the same type\n // We don't check the actual values as per requirements\n return {\n isIdentic: true,\n };\n};\n"],"mappings":";;;;;;;;;;;AAsBA,MAAa,6BACX,QACA,gBACA,OAAe,WACqB;AAEpC,KAAI,mBAAmB,QAAQ,mBAAmB,QAAW;AAC3D,MAAI,mBAAmB,OACrB,QAAO;GACL,WAAW;GACX,OAAO,oBAAoB,KAAK,aAAa,mBAAmB,OAAO,SAAS,YAAY,QAAQ,WAAW,OAAO,SAAS,OAAO;GACvI;AAEH,SAAO,EACL,WAAW,MACZ;;CAIH,MAAM,eAAe,MAAM,QAAQ,eAAe,GAC9C,UACA,OAAO;CACX,MAAM,aAAa,MAAM,QAAQ,OAAO,GAAG,UAAU,OAAO;AAG5D,KAAI,iBAAiB,WACnB,QAAO;EACL,WAAW;EACX,OAAO,oBAAoB,KAAK,aAAa,aAAa,QAAQ;EACnE;AAIH,KAAI,MAAM,QAAQ,eAAe,IAAI,MAAM,QAAQ,OAAO,EAAE;AAC1D,MAAI,eAAe,WAAW,OAAO,OACnC,QAAO;GACL,WAAW;GACX,OAAO,4BAA4B,KAAK,aAAa,eAAe,OAAO,iBAAiB,OAAO;GACpG;AAIH,OAAK,IAAI,IAAI,GAAG,IAAI,eAAe,QAAQ,IACzC,2BAA0B,OAAO,IAAI,eAAe,IAAI,GAAG,KAAK,GAAG,EAAE,GAAG;AAG1E,SAAO,EACL,WAAW,MACZ;;AAIH,KACE,OAAO,mBAAmB,YAC1B,OAAO,WAAW,YAClB,mBAAmB,QACnB,WAAW,MACX;EACA,MAAM,eAAe,OAAO,KAAK,eAAe;EAChD,MAAM,aAAa,OAAO,KAAK,OAAO;AAGtC,MAAI,aAAa,WAAW,WAAW,OACrC,QAAO;GACL,WAAW;GACX,OAAO,iCAAiC,KAAK,aAAa,aAAa,OAAO,aAAa,WAAW;GACvG;AAIH,OAAK,IAAI,IAAI,GAAG,IAAI,aAAa,QAAQ,IACvC,KAAI,aAAa,OAAO,WAAW,GACjC,QAAO;GACL,WAAW;GACX,OAAO,2BAA2B,KAAK,kBAAkB,aAAa,GAAG,gBAAgB,EAAE,SAAS,WAAW,GAAG;GACnH;AAKL,OAAK,MAAM,OAAO,aAChB,2BACG,OAAyC,MACzC,eAAiD,MAClD,GAAG,KAAK,GAAG,MACZ;AAGH,SAAO,EACL,WAAW,MACZ;;AAKH,QAAO,EACL,WAAW,MACZ"}
@@ -1,23 +0,0 @@
1
- //#region src/utils/verifyIdenticObjectFormat copy.d.ts
2
- type FlatType = string | number | boolean | object | null | undefined;
3
- type RecursiveType = FlatType | {
4
- [key: string]: RecursiveType;
5
- } | Array<RecursiveType>;
6
- type VerifyIdenticObjectFormatResult = {
7
- isIdentic: boolean;
8
- error?: string;
9
- };
10
- /**
11
- * Verifies that two objects have identical structure (same keys, array lengths, and types)
12
- * but not necessarily the same values.
13
- * Useful for validating translations maintain the same format as the original.
14
- *
15
- * @param object - The object to verify
16
- * @param expectedFormat - The expected format to compare against
17
- * @param path - Current path in the object tree (for error messages)
18
- * @returns true if structures match, throws error with details if they don't
19
- */
20
- declare const verifyIdenticObjectFormat: (object: RecursiveType, expectedFormat: RecursiveType, path?: string) => VerifyIdenticObjectFormatResult;
21
- //#endregion
22
- export { verifyIdenticObjectFormat };
23
- //# sourceMappingURL=verifyIdenticObjectFormat copy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"verifyIdenticObjectFormat copy.d.ts","names":[],"sources":["../../../src/utils/verifyIdenticObjectFormat copy.ts"],"sourcesContent":[],"mappings":";KAAK,QAAA;KAEA,aAAA,GACD,QAHS,GAAA;EAER,CAAA,GAAA,EAAA,MAAA,CAAA,EAEgB,aAFH;CACd,GAEA,KAFA,CAEM,aAFN,CAAA;KAIC,+BAAA,GAHgB;EACX,SAAA,EAAA,OAAA;EAAN,KAAA,CAAA,EAAA,MAAA;CAAK;AAAA;AAiBT;;;;;;;;;cAAa,oCACH,+BACQ,iCAEf"}