@intlayer/config 6.1.6 → 7.0.0-canary.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 (236) hide show
  1. package/dist/cjs/_virtual/rolldown_runtime.cjs +34 -0
  2. package/dist/cjs/alias.cjs +27 -100
  3. package/dist/cjs/alias.cjs.map +1 -1
  4. package/dist/cjs/built.cjs +7 -25
  5. package/dist/cjs/built.cjs.map +1 -1
  6. package/dist/cjs/bundleJSFile.cjs +30 -51
  7. package/dist/cjs/bundleJSFile.cjs.map +1 -1
  8. package/dist/cjs/client.cjs +19 -52
  9. package/dist/cjs/configFile/buildConfigurationFields.cjs +100 -657
  10. package/dist/cjs/configFile/buildConfigurationFields.cjs.map +1 -1
  11. package/dist/cjs/configFile/getConfiguration.cjs +60 -114
  12. package/dist/cjs/configFile/getConfiguration.cjs.map +1 -1
  13. package/dist/cjs/configFile/index.cjs +8 -25
  14. package/dist/cjs/configFile/loadConfigurationFile.cjs +22 -47
  15. package/dist/cjs/configFile/loadConfigurationFile.cjs.map +1 -1
  16. package/dist/cjs/configFile/searchConfigurationFile.cjs +49 -55
  17. package/dist/cjs/configFile/searchConfigurationFile.cjs.map +1 -1
  18. package/dist/cjs/defaultValues/build.cjs +23 -35
  19. package/dist/cjs/defaultValues/build.cjs.map +1 -1
  20. package/dist/cjs/defaultValues/content.cjs +68 -70
  21. package/dist/cjs/defaultValues/content.cjs.map +1 -1
  22. package/dist/cjs/defaultValues/editor.cjs +29 -41
  23. package/dist/cjs/defaultValues/editor.cjs.map +1 -1
  24. package/dist/cjs/defaultValues/index.cjs +62 -0
  25. package/dist/cjs/defaultValues/index.cjs.map +1 -0
  26. package/dist/cjs/defaultValues/internationalization.cjs +23 -34
  27. package/dist/cjs/defaultValues/internationalization.cjs.map +1 -1
  28. package/dist/cjs/defaultValues/log.cjs +17 -29
  29. package/dist/cjs/defaultValues/log.cjs.map +1 -1
  30. package/dist/cjs/defaultValues/routing.cjs +38 -0
  31. package/dist/cjs/defaultValues/routing.cjs.map +1 -0
  32. package/dist/cjs/extractErrorMessage.cjs +95 -0
  33. package/dist/cjs/extractErrorMessage.cjs.map +1 -0
  34. package/dist/cjs/index.cjs +67 -98
  35. package/dist/cjs/loadEnvFile.cjs +30 -51
  36. package/dist/cjs/loadEnvFile.cjs.map +1 -1
  37. package/dist/cjs/loadExternalFile/bundleFile.cjs +74 -0
  38. package/dist/cjs/loadExternalFile/bundleFile.cjs.map +1 -0
  39. package/dist/cjs/loadExternalFile/loadExternalFile.cjs +86 -0
  40. package/dist/cjs/loadExternalFile/loadExternalFile.cjs.map +1 -0
  41. package/dist/cjs/loadExternalFile/parseFileContent.cjs +67 -0
  42. package/dist/cjs/loadExternalFile/parseFileContent.cjs.map +1 -0
  43. package/dist/cjs/loadExternalFile/transpileTSToMJS.cjs +60 -0
  44. package/dist/cjs/loadExternalFile/transpileTSToMJS.cjs.map +1 -0
  45. package/dist/cjs/logger.cjs +124 -152
  46. package/dist/cjs/logger.cjs.map +1 -1
  47. package/dist/cjs/package.cjs +12 -0
  48. package/dist/cjs/package.cjs.map +1 -0
  49. package/dist/cjs/retryManager.cjs +42 -49
  50. package/dist/cjs/retryManager.cjs.map +1 -1
  51. package/dist/cjs/utils/ESMxCJSHelpers.cjs +24 -33
  52. package/dist/cjs/utils/ESMxCJSHelpers.cjs.map +1 -1
  53. package/dist/cjs/utils/cache.cjs +426 -0
  54. package/dist/cjs/utils/cache.cjs.map +1 -0
  55. package/dist/cjs/utils/clearModuleCache.cjs +23 -46
  56. package/dist/cjs/utils/clearModuleCache.cjs.map +1 -1
  57. package/dist/cjs/utils/extractErrorMessage.cjs +95 -0
  58. package/dist/cjs/utils/extractErrorMessage.cjs.map +1 -0
  59. package/dist/cjs/utils/getExtension.cjs +12 -35
  60. package/dist/cjs/utils/getExtension.cjs.map +1 -1
  61. package/dist/cjs/utils/getPackageJsonPath.cjs +37 -0
  62. package/dist/cjs/utils/getPackageJsonPath.cjs.map +1 -0
  63. package/dist/cjs/utils/logStack.cjs +16 -0
  64. package/dist/cjs/utils/logStack.cjs.map +1 -0
  65. package/dist/cjs/utils/normalizePath.cjs +15 -27
  66. package/dist/cjs/utils/normalizePath.cjs.map +1 -1
  67. package/dist/esm/_virtual/rolldown_runtime.mjs +17 -0
  68. package/dist/esm/alias.mjs +23 -74
  69. package/dist/esm/alias.mjs.map +1 -1
  70. package/dist/esm/built.mjs +5 -3
  71. package/dist/esm/built.mjs.map +1 -1
  72. package/dist/esm/bundleJSFile.mjs +26 -25
  73. package/dist/esm/bundleJSFile.mjs.map +1 -1
  74. package/dist/esm/client.mjs +4 -31
  75. package/dist/esm/configFile/buildConfigurationFields.mjs +97 -674
  76. package/dist/esm/configFile/buildConfigurationFields.mjs.map +1 -1
  77. package/dist/esm/configFile/getConfiguration.mjs +52 -75
  78. package/dist/esm/configFile/getConfiguration.mjs.map +1 -1
  79. package/dist/esm/configFile/index.mjs +5 -3
  80. package/dist/esm/configFile/loadConfigurationFile.mjs +22 -23
  81. package/dist/esm/configFile/loadConfigurationFile.mjs.map +1 -1
  82. package/dist/esm/configFile/searchConfigurationFile.mjs +45 -30
  83. package/dist/esm/configFile/searchConfigurationFile.mjs.map +1 -1
  84. package/dist/esm/defaultValues/build.mjs +16 -11
  85. package/dist/esm/defaultValues/build.mjs.map +1 -1
  86. package/dist/esm/defaultValues/content.mjs +48 -34
  87. package/dist/esm/defaultValues/content.mjs.map +1 -1
  88. package/dist/esm/defaultValues/editor.mjs +17 -11
  89. package/dist/esm/defaultValues/editor.mjs.map +1 -1
  90. package/dist/esm/defaultValues/index.mjs +21 -0
  91. package/dist/esm/defaultValues/index.mjs.map +1 -0
  92. package/dist/esm/defaultValues/internationalization.mjs +13 -7
  93. package/dist/esm/defaultValues/internationalization.mjs.map +1 -1
  94. package/dist/esm/defaultValues/log.mjs +10 -4
  95. package/dist/esm/defaultValues/log.mjs.map +1 -1
  96. package/dist/esm/defaultValues/routing.mjs +25 -0
  97. package/dist/esm/defaultValues/routing.mjs.map +1 -0
  98. package/dist/esm/extractErrorMessage.mjs +94 -0
  99. package/dist/esm/extractErrorMessage.mjs.map +1 -0
  100. package/dist/esm/index.mjs +18 -61
  101. package/dist/esm/loadEnvFile.mjs +27 -17
  102. package/dist/esm/loadEnvFile.mjs.map +1 -1
  103. package/dist/esm/loadExternalFile/bundleFile.mjs +68 -0
  104. package/dist/esm/loadExternalFile/bundleFile.mjs.map +1 -0
  105. package/dist/esm/loadExternalFile/loadExternalFile.mjs +81 -0
  106. package/dist/esm/loadExternalFile/loadExternalFile.mjs.map +1 -0
  107. package/dist/esm/loadExternalFile/parseFileContent.mjs +63 -0
  108. package/dist/esm/loadExternalFile/parseFileContent.mjs.map +1 -0
  109. package/dist/esm/loadExternalFile/transpileTSToMJS.mjs +55 -0
  110. package/dist/esm/loadExternalFile/transpileTSToMJS.mjs.map +1 -0
  111. package/dist/esm/logger.mjs +110 -115
  112. package/dist/esm/logger.mjs.map +1 -1
  113. package/dist/esm/package.mjs +6 -0
  114. package/dist/esm/package.mjs.map +1 -0
  115. package/dist/esm/retryManager.mjs +40 -23
  116. package/dist/esm/retryManager.mjs.map +1 -1
  117. package/dist/esm/utils/ESMxCJSHelpers.mjs +20 -6
  118. package/dist/esm/utils/ESMxCJSHelpers.mjs.map +1 -1
  119. package/dist/esm/utils/cache.mjs +414 -0
  120. package/dist/esm/utils/cache.mjs.map +1 -0
  121. package/dist/esm/utils/clearModuleCache.mjs +22 -21
  122. package/dist/esm/utils/clearModuleCache.mjs.map +1 -1
  123. package/dist/esm/utils/extractErrorMessage.mjs +94 -0
  124. package/dist/esm/utils/extractErrorMessage.mjs.map +1 -0
  125. package/dist/esm/utils/getExtension.mjs +11 -11
  126. package/dist/esm/utils/getExtension.mjs.map +1 -1
  127. package/dist/esm/utils/getPackageJsonPath.mjs +33 -0
  128. package/dist/esm/utils/getPackageJsonPath.mjs.map +1 -0
  129. package/dist/esm/utils/logStack.mjs +16 -0
  130. package/dist/esm/utils/logStack.mjs.map +1 -0
  131. package/dist/esm/utils/normalizePath.mjs +14 -3
  132. package/dist/esm/utils/normalizePath.mjs.map +1 -1
  133. package/dist/types/alias.d.ts +20 -12
  134. package/dist/types/alias.d.ts.map +1 -1
  135. package/dist/types/built.d.ts +7 -6
  136. package/dist/types/built.d.ts.map +1 -1
  137. package/dist/types/bundleJSFile.d.ts +97 -93
  138. package/dist/types/bundleJSFile.d.ts.map +1 -1
  139. package/dist/types/client.d.ts +3 -5
  140. package/dist/types/configFile/buildConfigurationFields.d.ts +7 -2
  141. package/dist/types/configFile/buildConfigurationFields.d.ts.map +1 -1
  142. package/dist/types/configFile/getConfiguration.d.ts +19 -15
  143. package/dist/types/configFile/getConfiguration.d.ts.map +1 -1
  144. package/dist/types/configFile/index.d.ts +4 -3
  145. package/dist/types/configFile/loadConfigurationFile.d.ts +8 -3
  146. package/dist/types/configFile/loadConfigurationFile.d.ts.map +1 -1
  147. package/dist/types/configFile/searchConfigurationFile.d.ts +6 -4
  148. package/dist/types/configFile/searchConfigurationFile.d.ts.map +1 -1
  149. package/dist/types/defaultValues/build.d.ts +10 -4
  150. package/dist/types/defaultValues/build.d.ts.map +1 -1
  151. package/dist/types/defaultValues/content.d.ts +23 -16
  152. package/dist/types/defaultValues/content.d.ts.map +1 -1
  153. package/dist/types/defaultValues/editor.d.ts +14 -9
  154. package/dist/types/defaultValues/editor.d.ts.map +1 -1
  155. package/dist/types/defaultValues/index.d.ts +14 -0
  156. package/dist/types/defaultValues/index.d.ts.map +1 -0
  157. package/dist/types/defaultValues/internationalization.d.ts +12 -6
  158. package/dist/types/defaultValues/internationalization.d.ts.map +1 -1
  159. package/dist/types/defaultValues/log.d.ts +7 -2
  160. package/dist/types/defaultValues/log.d.ts.map +1 -1
  161. package/dist/types/defaultValues/routing.d.ts +14 -0
  162. package/dist/types/defaultValues/routing.d.ts.map +1 -0
  163. package/dist/types/extractErrorMessage.d.ts +5 -0
  164. package/dist/types/extractErrorMessage.d.ts.map +1 -0
  165. package/dist/types/index.d.ts +21 -17
  166. package/dist/types/loadEnvFile.d.ts +8 -5
  167. package/dist/types/loadEnvFile.d.ts.map +1 -1
  168. package/dist/types/loadExternalFile/bundleFile.d.ts +10 -0
  169. package/dist/types/loadExternalFile/bundleFile.d.ts.map +1 -0
  170. package/dist/types/loadExternalFile/loadExternalFile.d.ts +25 -0
  171. package/dist/types/loadExternalFile/loadExternalFile.d.ts.map +1 -0
  172. package/dist/types/loadExternalFile/parseFileContent.d.ts +29 -0
  173. package/dist/types/loadExternalFile/parseFileContent.d.ts.map +1 -0
  174. package/dist/types/loadExternalFile/transpileTSToMJS.d.ts +9 -0
  175. package/dist/types/loadExternalFile/transpileTSToMJS.d.ts.map +1 -0
  176. package/dist/types/logger.d.ts +41 -37
  177. package/dist/types/logger.d.ts.map +1 -1
  178. package/dist/types/retryManager.d.ts +26 -8
  179. package/dist/types/retryManager.d.ts.map +1 -1
  180. package/dist/types/utils/ESMxCJSHelpers.d.ts +16 -2
  181. package/dist/types/utils/ESMxCJSHelpers.d.ts.map +1 -1
  182. package/dist/types/utils/cache.d.ts +50 -0
  183. package/dist/types/utils/cache.d.ts.map +1 -0
  184. package/dist/types/utils/clearModuleCache.d.ts +4 -1
  185. package/dist/types/utils/clearModuleCache.d.ts.map +1 -1
  186. package/dist/types/utils/extractErrorMessage.d.ts +5 -0
  187. package/dist/types/utils/extractErrorMessage.d.ts.map +1 -0
  188. package/dist/types/utils/getExtension.d.ts +6 -2
  189. package/dist/types/utils/getExtension.d.ts.map +1 -1
  190. package/dist/types/utils/getPackageJsonPath.d.ts +10 -0
  191. package/dist/types/utils/getPackageJsonPath.d.ts.map +1 -0
  192. package/dist/types/utils/logStack.d.ts +7 -0
  193. package/dist/types/utils/logStack.d.ts.map +1 -0
  194. package/dist/types/utils/normalizePath.d.ts +4 -1
  195. package/dist/types/utils/normalizePath.d.ts.map +1 -1
  196. package/package.json +40 -35
  197. package/LICENSE +0 -202
  198. package/dist/cjs/client.cjs.map +0 -1
  199. package/dist/cjs/configFile/index.cjs.map +0 -1
  200. package/dist/cjs/defaultValues/middleware.cjs +0 -47
  201. package/dist/cjs/defaultValues/middleware.cjs.map +0 -1
  202. package/dist/cjs/getSandboxContext.cjs +0 -64
  203. package/dist/cjs/getSandboxContext.cjs.map +0 -1
  204. package/dist/cjs/index.cjs.map +0 -1
  205. package/dist/cjs/loadExternalFile.cjs +0 -105
  206. package/dist/cjs/loadExternalFile.cjs.map +0 -1
  207. package/dist/cjs/types/config.cjs +0 -17
  208. package/dist/cjs/types/config.cjs.map +0 -1
  209. package/dist/cjs/types/locales.cjs +0 -310
  210. package/dist/cjs/types/locales.cjs.map +0 -1
  211. package/dist/esm/client.mjs.map +0 -1
  212. package/dist/esm/configFile/index.mjs.map +0 -1
  213. package/dist/esm/defaultValues/middleware.mjs +0 -17
  214. package/dist/esm/defaultValues/middleware.mjs.map +0 -1
  215. package/dist/esm/getSandboxContext.mjs +0 -40
  216. package/dist/esm/getSandboxContext.mjs.map +0 -1
  217. package/dist/esm/index.mjs.map +0 -1
  218. package/dist/esm/loadExternalFile.mjs +0 -81
  219. package/dist/esm/loadExternalFile.mjs.map +0 -1
  220. package/dist/esm/types/config.mjs +0 -1
  221. package/dist/esm/types/config.mjs.map +0 -1
  222. package/dist/esm/types/locales.mjs +0 -286
  223. package/dist/esm/types/locales.mjs.map +0 -1
  224. package/dist/types/client.d.ts.map +0 -1
  225. package/dist/types/configFile/index.d.ts.map +0 -1
  226. package/dist/types/defaultValues/middleware.d.ts +0 -8
  227. package/dist/types/defaultValues/middleware.d.ts.map +0 -1
  228. package/dist/types/getSandboxContext.d.ts +0 -4
  229. package/dist/types/getSandboxContext.d.ts.map +0 -1
  230. package/dist/types/index.d.ts.map +0 -1
  231. package/dist/types/loadExternalFile.d.ts +0 -8
  232. package/dist/types/loadExternalFile.d.ts.map +0 -1
  233. package/dist/types/types/config.d.ts +0 -659
  234. package/dist/types/types/config.d.ts.map +0 -1
  235. package/dist/types/types/locales.d.ts +0 -564
  236. package/dist/types/types/locales.d.ts.map +0 -1
@@ -0,0 +1,81 @@
1
+ import { colorizePath, logger } from "../logger.mjs";
2
+ import { ESMxCJSRequire } from "../utils/ESMxCJSHelpers.mjs";
3
+ import { parseFileContent } from "./parseFileContent.mjs";
4
+ import { transpileTSToMJS, transpileTSToMJSSync } from "./transpileTSToMJS.mjs";
5
+ import { extname } from "node:path";
6
+ import { readFile } from "node:fs/promises";
7
+ import { readFileSync } from "node:fs";
8
+
9
+ //#region src/loadExternalFile/loadExternalFile.ts
10
+ /**
11
+ * Load the content declaration from the given path
12
+ *
13
+ * Accepts JSON, JS, MJS and TS files as configuration
14
+ */
15
+ const loadExternalFileSync = (filePath, options) => {
16
+ const fileExtension = extname(filePath);
17
+ const safeProjectRequire = options?.projectRequire ?? ESMxCJSRequire;
18
+ try {
19
+ if (fileExtension === "json") {
20
+ delete safeProjectRequire.cache[safeProjectRequire.resolve(filePath)];
21
+ return safeProjectRequire(filePath);
22
+ }
23
+ const moduleResultString = transpileTSToMJSSync(readFileSync(filePath, "utf-8"), filePath);
24
+ if (!moduleResultString) {
25
+ logger("File could not be loaded.", { level: "error" });
26
+ return;
27
+ }
28
+ const fileContent = parseFileContent(moduleResultString, {
29
+ projectRequire: options?.projectRequire,
30
+ envVarOptions: options?.envVarOptions,
31
+ additionalEnvVars: options?.additionalEnvVars,
32
+ mocks: options?.mocks,
33
+ aliases: options?.aliases
34
+ });
35
+ if (typeof fileContent === "undefined") {
36
+ logger(`File file could not be loaded. Path : ${filePath}`);
37
+ return;
38
+ }
39
+ return fileContent;
40
+ } catch (error) {
41
+ logger([`Error: ${error.message} - `, JSON.stringify(error.stack, null, 2)], { level: "error" });
42
+ }
43
+ };
44
+ /**
45
+ * Load the content declaration from the given path
46
+ *
47
+ * Accepts JSON, JS, MJS and TS files as configuration
48
+ */
49
+ const loadExternalFile = async (filePath, options) => {
50
+ const fileExtension = extname(filePath);
51
+ const safeProjectRequire = options?.projectRequire ?? ESMxCJSRequire;
52
+ try {
53
+ if (fileExtension === "json") {
54
+ delete safeProjectRequire.cache[safeProjectRequire.resolve(filePath)];
55
+ return safeProjectRequire(filePath);
56
+ }
57
+ const moduleResultString = await transpileTSToMJS(await readFile(filePath, "utf-8"), filePath, options?.buildOptions);
58
+ if (!moduleResultString) {
59
+ logger("File could not be loaded.", { level: "error" });
60
+ return;
61
+ }
62
+ const fileContent = parseFileContent(moduleResultString, {
63
+ projectRequire: options?.projectRequire,
64
+ envVarOptions: options?.envVarOptions,
65
+ additionalEnvVars: options?.additionalEnvVars,
66
+ mocks: options?.mocks,
67
+ aliases: options?.aliases
68
+ });
69
+ if (typeof fileContent === "undefined") {
70
+ logger(`File file could not be loaded. Path : ${colorizePath(filePath)}`);
71
+ return;
72
+ }
73
+ return fileContent;
74
+ } catch (error) {
75
+ logger([`Error: ${error.message} - `, JSON.stringify(error.stack, null, 2)], { level: "error" });
76
+ }
77
+ };
78
+
79
+ //#endregion
80
+ export { loadExternalFile, loadExternalFileSync };
81
+ //# sourceMappingURL=loadExternalFile.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadExternalFile.mjs","names":["moduleResultString: string | undefined"],"sources":["../../../src/loadExternalFile/loadExternalFile.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport type { BuildOptions, Plugin } from 'esbuild';\nimport { colorizePath, logger } from '../logger';\nimport { ESMxCJSRequire } from '../utils/ESMxCJSHelpers';\nimport {\n parseFileContent,\n type SandBoxContextOptions,\n} from './parseFileContent';\nimport { transpileTSToMJS, transpileTSToMJSSync } from './transpileTSToMJS';\n\nexport type ESBuildPlugin = Plugin;\n\nexport type LoadExternalFileOptions = {\n configuration?: IntlayerConfig;\n buildOptions?: BuildOptions;\n} & SandBoxContextOptions;\n\n/**\n * Load the content declaration from the given path\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nexport const loadExternalFileSync = (\n filePath: string,\n options?: LoadExternalFileOptions\n): any | undefined => {\n const fileExtension = extname(filePath);\n const safeProjectRequire = options?.projectRequire ?? ESMxCJSRequire;\n\n try {\n if (fileExtension === 'json') {\n // Remove cache to force getting fresh content\n delete safeProjectRequire.cache[safeProjectRequire.resolve(filePath)];\n // Assume JSON\n return safeProjectRequire(filePath);\n }\n\n // Rest is JS, MJS or TS\n const code = readFileSync(filePath, 'utf-8');\n\n const moduleResultString: string | undefined = transpileTSToMJSSync(\n code,\n filePath\n );\n\n if (!moduleResultString) {\n logger('File could not be loaded.', { level: 'error' });\n return undefined;\n }\n\n const fileContent = parseFileContent(moduleResultString, {\n projectRequire: options?.projectRequire,\n envVarOptions: options?.envVarOptions,\n additionalEnvVars: options?.additionalEnvVars,\n mocks: options?.mocks,\n aliases: options?.aliases,\n });\n\n if (typeof fileContent === 'undefined') {\n logger(`File file could not be loaded. Path : ${filePath}`);\n return undefined;\n }\n\n return fileContent;\n } catch (error) {\n logger(\n [\n `Error: ${(error as Error).message} - `,\n JSON.stringify((error as Error).stack, null, 2),\n ],\n {\n level: 'error',\n }\n );\n }\n};\n\n/**\n * Load the content declaration from the given path\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nexport const loadExternalFile = async (\n filePath: string,\n options?: LoadExternalFileOptions\n): Promise<any | undefined> => {\n const fileExtension = extname(filePath);\n const safeProjectRequire = options?.projectRequire ?? ESMxCJSRequire;\n\n try {\n if (fileExtension === 'json') {\n // Remove cache to force getting fresh content\n delete safeProjectRequire.cache[safeProjectRequire.resolve(filePath)];\n // Assume JSON\n return safeProjectRequire(filePath);\n }\n\n // Rest is JS, MJS or TS\n const code = await readFile(filePath, 'utf-8');\n\n const moduleResultString: string | undefined = await transpileTSToMJS(\n code,\n filePath,\n options?.buildOptions\n );\n\n if (!moduleResultString) {\n logger('File could not be loaded.', { level: 'error' });\n return undefined;\n }\n\n const fileContent = parseFileContent(moduleResultString, {\n projectRequire: options?.projectRequire,\n envVarOptions: options?.envVarOptions,\n additionalEnvVars: options?.additionalEnvVars,\n mocks: options?.mocks,\n aliases: options?.aliases,\n });\n\n if (typeof fileContent === 'undefined') {\n logger(`File file could not be loaded. Path : ${colorizePath(filePath)}`);\n return undefined;\n }\n\n return fileContent;\n } catch (error) {\n logger(\n [\n `Error: ${(error as Error).message} - `,\n JSON.stringify((error as Error).stack, null, 2),\n ],\n {\n level: 'error',\n }\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;AAyBA,MAAa,wBACX,UACA,YACoB;CACpB,MAAM,gBAAgB,QAAQ,SAAS;CACvC,MAAM,qBAAqB,SAAS,kBAAkB;AAEtD,KAAI;AACF,MAAI,kBAAkB,QAAQ;AAE5B,UAAO,mBAAmB,MAAM,mBAAmB,QAAQ,SAAS;AAEpE,UAAO,mBAAmB,SAAS;;EAMrC,MAAMA,qBAAyC,qBAFlC,aAAa,UAAU,QAAQ,EAI1C,SACD;AAED,MAAI,CAAC,oBAAoB;AACvB,UAAO,6BAA6B,EAAE,OAAO,SAAS,CAAC;AACvD;;EAGF,MAAM,cAAc,iBAAiB,oBAAoB;GACvD,gBAAgB,SAAS;GACzB,eAAe,SAAS;GACxB,mBAAmB,SAAS;GAC5B,OAAO,SAAS;GAChB,SAAS,SAAS;GACnB,CAAC;AAEF,MAAI,OAAO,gBAAgB,aAAa;AACtC,UAAO,yCAAyC,WAAW;AAC3D;;AAGF,SAAO;UACA,OAAO;AACd,SACE,CACE,UAAW,MAAgB,QAAQ,MACnC,KAAK,UAAW,MAAgB,OAAO,MAAM,EAAE,CAChD,EACD,EACE,OAAO,SACR,CACF;;;;;;;;AASL,MAAa,mBAAmB,OAC9B,UACA,YAC6B;CAC7B,MAAM,gBAAgB,QAAQ,SAAS;CACvC,MAAM,qBAAqB,SAAS,kBAAkB;AAEtD,KAAI;AACF,MAAI,kBAAkB,QAAQ;AAE5B,UAAO,mBAAmB,MAAM,mBAAmB,QAAQ,SAAS;AAEpE,UAAO,mBAAmB,SAAS;;EAMrC,MAAMA,qBAAyC,MAAM,iBAFxC,MAAM,SAAS,UAAU,QAAQ,EAI5C,UACA,SAAS,aACV;AAED,MAAI,CAAC,oBAAoB;AACvB,UAAO,6BAA6B,EAAE,OAAO,SAAS,CAAC;AACvD;;EAGF,MAAM,cAAc,iBAAiB,oBAAoB;GACvD,gBAAgB,SAAS;GACzB,eAAe,SAAS;GACxB,mBAAmB,SAAS;GAC5B,OAAO,SAAS;GAChB,SAAS,SAAS;GACnB,CAAC;AAEF,MAAI,OAAO,gBAAgB,aAAa;AACtC,UAAO,yCAAyC,aAAa,SAAS,GAAG;AACzE;;AAGF,SAAO;UACA,OAAO;AACd,SACE,CACE,UAAW,MAAgB,QAAQ,MACnC,KAAK,UAAW,MAAgB,OAAO,MAAM,EAAE,CAChD,EACD,EACE,OAAO,SACR,CACF"}
@@ -0,0 +1,63 @@
1
+ import { ESMxCJSRequire } from "../utils/ESMxCJSHelpers.mjs";
2
+ import { loadEnvFile } from "../loadEnvFile.mjs";
3
+ import { runInNewContext } from "node:vm";
4
+ import * as esbuild from "esbuild";
5
+
6
+ //#region src/loadExternalFile/parseFileContent.ts
7
+ const getSandBoxContext = (options) => {
8
+ const { envVarOptions, projectRequire, additionalEnvVars, mocks, aliases } = options ?? {};
9
+ let additionalGlobalVar = {};
10
+ const baseRequire = typeof projectRequire === "function" ? projectRequire : ESMxCJSRequire;
11
+ const mockedRequire = (() => {
12
+ const mockTable = Object.assign({ esbuild }, mocks);
13
+ const aliasTable = Object.assign({}, aliases);
14
+ const wrappedRequire = function mockableRequire(id) {
15
+ const target = aliasTable?.[id] ? aliasTable[id] : id;
16
+ if (mockTable && Object.hasOwn(mockTable, target)) return mockTable[target];
17
+ if (target !== id && mockTable && Object.hasOwn(mockTable, id)) return mockTable[id];
18
+ return baseRequire(target);
19
+ };
20
+ wrappedRequire.resolve = baseRequire.resolve.bind(baseRequire);
21
+ wrappedRequire.main = baseRequire.main;
22
+ wrappedRequire.extensions = baseRequire.extensions;
23
+ wrappedRequire.cache = baseRequire.cache;
24
+ return wrappedRequire;
25
+ })();
26
+ try {
27
+ additionalGlobalVar = { React: baseRequire("react") };
28
+ } catch (_err) {}
29
+ const sandboxContext = {
30
+ exports: { default: {} },
31
+ module: { exports: {} },
32
+ process: {
33
+ ...process,
34
+ env: {
35
+ ...process.env,
36
+ ...loadEnvFile(envVarOptions),
37
+ ...additionalEnvVars
38
+ }
39
+ },
40
+ console,
41
+ require: mockedRequire,
42
+ ...additionalGlobalVar
43
+ };
44
+ Object.getOwnPropertyNames(globalThis).forEach((key) => {
45
+ if (!(key in sandboxContext)) sandboxContext[key] = globalThis[key];
46
+ });
47
+ return sandboxContext;
48
+ };
49
+ const parseFileContent = (fileContentString, options) => {
50
+ const sandboxContext = getSandBoxContext(options);
51
+ runInNewContext(`"use strict";\n${fileContentString}`, sandboxContext);
52
+ const candidates = [
53
+ sandboxContext.exports?.default,
54
+ sandboxContext.module?.exports?.defaults,
55
+ sandboxContext.module?.exports?.default,
56
+ sandboxContext.module?.exports
57
+ ];
58
+ for (const candidate of candidates) if (candidate && typeof candidate === "object" && Object.keys(candidate).length > 0) return candidate;
59
+ };
60
+
61
+ //#endregion
62
+ export { getSandBoxContext, parseFileContent };
63
+ //# sourceMappingURL=parseFileContent.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseFileContent.mjs","names":["baseRequire: NodeJS.Require","mockedRequire: NodeJS.Require","sandboxContext: Context","candidates: unknown[]"],"sources":["../../../src/loadExternalFile/parseFileContent.ts"],"sourcesContent":["import { type Context, runInNewContext } from 'node:vm';\nimport * as esbuild from 'esbuild';\nimport { type LoadEnvFileOptions, loadEnvFile } from '../loadEnvFile';\nimport { ESMxCJSRequire } from '../utils/ESMxCJSHelpers';\n\nexport type SandBoxContextOptions = {\n envVarOptions?: LoadEnvFileOptions;\n projectRequire?: NodeJS.Require;\n additionalEnvVars?: Record<string, string>;\n /**\n * Map of specifier -> mocked export to be returned when code in the VM calls require(specifier).\n * Example:\n * mocks: {\n * '@intlayer/config/built': { getConfig: () => ({}), Locales: {} }\n * }\n */\n mocks?: Record<string, any>;\n /**\n * Optional alias map if you want to redirect specifiers.\n * Useful when user code imports a subpath you want to collapse.\n * Example:\n * aliases: { '@intlayer/config/built': '@intlayer/config' }\n */\n aliases?: Record<string, string>;\n};\n\nexport const getSandBoxContext = (options?: SandBoxContextOptions): Context => {\n const { envVarOptions, projectRequire, additionalEnvVars, mocks, aliases } =\n options ?? {};\n\n let additionalGlobalVar = {};\n\n const baseRequire: NodeJS.Require =\n typeof projectRequire === 'function' ? projectRequire : ESMxCJSRequire;\n\n // Wrap require to honor mocks and aliases inside the VM\n const mockedRequire: NodeJS.Require = (() => {\n const mockTable = Object.assign(\n {\n esbuild,\n },\n mocks\n );\n const aliasTable = Object.assign({}, aliases);\n\n const wrappedRequire = function mockableRequire(id: string) {\n const target = aliasTable?.[id] ? aliasTable[id] : id;\n\n if (mockTable && Object.hasOwn(mockTable, target)) {\n return mockTable[target];\n }\n\n // If the original id was aliased, allow mocks to be defined on either key.\n if (target !== id && mockTable && Object.hasOwn(mockTable, id)) {\n return mockTable[id];\n }\n\n return baseRequire(target);\n } as NodeJS.Require;\n\n // Mirror NodeJS.Require properties\n wrappedRequire.resolve = baseRequire.resolve.bind(baseRequire);\n wrappedRequire.main = baseRequire.main;\n wrappedRequire.extensions = baseRequire.extensions;\n wrappedRequire.cache = baseRequire.cache;\n\n return wrappedRequire;\n })();\n\n try {\n // Dynamically try to require React if it's installed in the project\n additionalGlobalVar = {\n React: baseRequire('react'),\n };\n } catch (_err) {\n // React is not installed, so we don't inject it\n }\n\n const sandboxContext: Context = {\n exports: {\n default: {},\n },\n module: {\n exports: {},\n },\n process: {\n ...process,\n env: {\n ...process.env,\n ...loadEnvFile(envVarOptions),\n ...additionalEnvVars,\n },\n },\n console,\n require: mockedRequire,\n ...additionalGlobalVar,\n };\n\n // Dynamically inject all global variables\n Object.getOwnPropertyNames(globalThis).forEach((key) => {\n if (!(key in sandboxContext)) {\n sandboxContext[key] = globalThis[key as keyof typeof globalThis];\n }\n });\n\n return sandboxContext;\n};\n\nexport const parseFileContent = <T>(\n fileContentString: string,\n options?: SandBoxContextOptions\n): T | undefined => {\n const sandboxContext = getSandBoxContext(options);\n\n // Force strict mode so illegal writes throw instead of silently failing.\n runInNewContext(`\"use strict\";\\n${fileContentString}`, sandboxContext);\n\n const candidates: unknown[] = [\n sandboxContext.exports?.default,\n sandboxContext.module?.exports?.defaults,\n sandboxContext.module?.exports?.default,\n sandboxContext.module?.exports,\n ];\n\n for (const candidate of candidates) {\n if (\n candidate &&\n typeof candidate === 'object' &&\n Object.keys(candidate as object).length > 0\n ) {\n return candidate as T;\n }\n }\n};\n"],"mappings":";;;;;;AA0BA,MAAa,qBAAqB,YAA6C;CAC7E,MAAM,EAAE,eAAe,gBAAgB,mBAAmB,OAAO,YAC/D,WAAW,EAAE;CAEf,IAAI,sBAAsB,EAAE;CAE5B,MAAMA,cACJ,OAAO,mBAAmB,aAAa,iBAAiB;CAG1D,MAAMC,uBAAuC;EAC3C,MAAM,YAAY,OAAO,OACvB,EACE,SACD,EACD,MACD;EACD,MAAM,aAAa,OAAO,OAAO,EAAE,EAAE,QAAQ;EAE7C,MAAM,iBAAiB,SAAS,gBAAgB,IAAY;GAC1D,MAAM,SAAS,aAAa,MAAM,WAAW,MAAM;AAEnD,OAAI,aAAa,OAAO,OAAO,WAAW,OAAO,CAC/C,QAAO,UAAU;AAInB,OAAI,WAAW,MAAM,aAAa,OAAO,OAAO,WAAW,GAAG,CAC5D,QAAO,UAAU;AAGnB,UAAO,YAAY,OAAO;;AAI5B,iBAAe,UAAU,YAAY,QAAQ,KAAK,YAAY;AAC9D,iBAAe,OAAO,YAAY;AAClC,iBAAe,aAAa,YAAY;AACxC,iBAAe,QAAQ,YAAY;AAEnC,SAAO;KACL;AAEJ,KAAI;AAEF,wBAAsB,EACpB,OAAO,YAAY,QAAQ,EAC5B;UACM,MAAM;CAIf,MAAMC,iBAA0B;EAC9B,SAAS,EACP,SAAS,EAAE,EACZ;EACD,QAAQ,EACN,SAAS,EAAE,EACZ;EACD,SAAS;GACP,GAAG;GACH,KAAK;IACH,GAAG,QAAQ;IACX,GAAG,YAAY,cAAc;IAC7B,GAAG;IACJ;GACF;EACD;EACA,SAAS;EACT,GAAG;EACJ;AAGD,QAAO,oBAAoB,WAAW,CAAC,SAAS,QAAQ;AACtD,MAAI,EAAE,OAAO,gBACX,gBAAe,OAAO,WAAW;GAEnC;AAEF,QAAO;;AAGT,MAAa,oBACX,mBACA,YACkB;CAClB,MAAM,iBAAiB,kBAAkB,QAAQ;AAGjD,iBAAgB,kBAAkB,qBAAqB,eAAe;CAEtE,MAAMC,aAAwB;EAC5B,eAAe,SAAS;EACxB,eAAe,QAAQ,SAAS;EAChC,eAAe,QAAQ,SAAS;EAChC,eAAe,QAAQ;EACxB;AAED,MAAK,MAAM,aAAa,WACtB,KACE,aACA,OAAO,cAAc,YACrB,OAAO,KAAK,UAAoB,CAAC,SAAS,EAE1C,QAAO"}
@@ -0,0 +1,55 @@
1
+ import { getLoader } from "./bundleFile.mjs";
2
+ import { dirname, extname, join } from "node:path";
3
+ import { build, buildSync } from "esbuild";
4
+ import { pathToFileURL } from "node:url";
5
+
6
+ //#region src/loadExternalFile/transpileTSToMJS.ts
7
+ const getTransformationOptions = (filePath) => ({
8
+ loader: {
9
+ ".js": "js",
10
+ ".jsx": "jsx",
11
+ ".mjs": "js",
12
+ ".ts": "ts",
13
+ ".tsx": "tsx",
14
+ ".cjs": "js",
15
+ ".json": "json",
16
+ ".md": "text",
17
+ ".mdx": "text"
18
+ },
19
+ format: "cjs",
20
+ target: "node20",
21
+ platform: "node",
22
+ write: false,
23
+ packages: "external",
24
+ bundle: true,
25
+ tsconfig: join(process.cwd(), "tsconfig.json"),
26
+ define: { "import.meta.url": JSON.stringify(pathToFileURL(filePath).href) }
27
+ });
28
+ const transpileTSToMJSSync = (code, filePath, options) => {
29
+ return buildSync({
30
+ stdin: {
31
+ contents: code,
32
+ loader: getLoader(extname(filePath)),
33
+ resolveDir: dirname(filePath),
34
+ sourcefile: filePath
35
+ },
36
+ ...getTransformationOptions(filePath),
37
+ ...options
38
+ }).outputFiles?.[0].text;
39
+ };
40
+ const transpileTSToMJS = async (code, filePath, options) => {
41
+ return (await build({
42
+ stdin: {
43
+ contents: code,
44
+ loader: getLoader(extname(filePath)),
45
+ resolveDir: dirname(filePath),
46
+ sourcefile: filePath
47
+ },
48
+ ...getTransformationOptions(filePath),
49
+ ...options
50
+ })).outputFiles?.[0].text;
51
+ };
52
+
53
+ //#endregion
54
+ export { transpileTSToMJS, transpileTSToMJSSync };
55
+ //# sourceMappingURL=transpileTSToMJS.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transpileTSToMJS.mjs","names":[],"sources":["../../../src/loadExternalFile/transpileTSToMJS.ts"],"sourcesContent":["import { dirname, extname, join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport {\n type BuildOptions,\n type BuildResult,\n build,\n buildSync,\n type Plugin,\n} from 'esbuild';\nimport { getLoader } from './bundleFile';\n\nexport type ESBuildPlugin = Plugin;\n\nconst getTransformationOptions = (filePath: string): BuildOptions => ({\n loader: {\n '.js': 'js',\n '.jsx': 'jsx',\n '.mjs': 'js',\n '.ts': 'ts',\n '.tsx': 'tsx',\n '.cjs': 'js',\n '.json': 'json',\n '.md': 'text',\n '.mdx': 'text',\n },\n format: 'cjs',\n target: 'node20',\n platform: 'node',\n write: false,\n packages: 'external',\n bundle: true,\n tsconfig: join(process.cwd(), 'tsconfig.json'),\n define: {\n 'import.meta.url': JSON.stringify(pathToFileURL(filePath).href),\n },\n});\n\nexport const transpileTSToMJSSync = (\n code: string,\n filePath: string,\n options?: BuildOptions\n): string | undefined => {\n const extension = extname(filePath);\n const loader = getLoader(extension);\n\n const moduleResult: BuildResult = buildSync({\n stdin: {\n contents: code,\n loader,\n resolveDir: dirname(filePath), // Add resolveDir to resolve imports relative to the file's location\n sourcefile: filePath, // Add sourcefile for better error messages\n },\n ...getTransformationOptions(filePath),\n ...options,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n return moduleResultString;\n};\n\nexport const transpileTSToMJS = async (\n code: string,\n filePath: string,\n options?: BuildOptions\n): Promise<string | undefined> => {\n const extension = extname(filePath);\n const loader = getLoader(extension);\n\n const moduleResult: BuildResult = await build({\n stdin: {\n contents: code,\n loader,\n resolveDir: dirname(filePath), // Add resolveDir to resolve imports relative to the file's location\n sourcefile: filePath, // Add sourcefile for better error messages\n },\n ...getTransformationOptions(filePath),\n ...options,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n return moduleResultString;\n};\n"],"mappings":";;;;;;AAaA,MAAM,4BAA4B,cAAoC;CACpE,QAAQ;EACN,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,SAAS;EACT,OAAO;EACP,QAAQ;EACT;CACD,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,OAAO;CACP,UAAU;CACV,QAAQ;CACR,UAAU,KAAK,QAAQ,KAAK,EAAE,gBAAgB;CAC9C,QAAQ,EACN,mBAAmB,KAAK,UAAU,cAAc,SAAS,CAAC,KAAK,EAChE;CACF;AAED,MAAa,wBACX,MACA,UACA,YACuB;AAiBvB,QAbkC,UAAU;EAC1C,OAAO;GACL,UAAU;GACV,QALW,UADG,QAAQ,SAAS,CACA;GAM/B,YAAY,QAAQ,SAAS;GAC7B,YAAY;GACb;EACD,GAAG,yBAAyB,SAAS;EACrC,GAAG;EACJ,CAAC,CAEsC,cAAc,GAAG;;AAK3D,MAAa,mBAAmB,OAC9B,MACA,UACA,YACgC;AAiBhC,SAbkC,MAAM,MAAM;EAC5C,OAAO;GACL,UAAU;GACV,QALW,UADG,QAAQ,SAAS,CACA;GAM/B,YAAY,QAAQ,SAAS;GAC7B,YAAY;GACb;EACD,GAAG,yBAAyB,SAAS;EACrC,GAAG;EACJ,CAAC,EAEsC,cAAc,GAAG"}
@@ -1,129 +1,124 @@
1
+ //#region src/logger.ts
1
2
  const logger = (content, details) => {
2
- const isVerbose = details?.isVerbose ?? false;
3
- const mode = details?.config?.mode ?? "default";
4
- const level = details?.level ?? "info";
5
- const prefix = Boolean(details?.config?.prefix) ? details?.config?.prefix : void 0;
6
- const log = details?.config?.log ?? console.log;
7
- const info = details?.config?.info ?? console.info;
8
- const warn = details?.config?.warn ?? console.warn;
9
- const error = details?.config?.error ?? console.error;
10
- const debug = details?.config?.debug ?? console.debug;
11
- if (mode === "disabled") return;
12
- if (isVerbose && mode !== "verbose") return;
13
- const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();
14
- if (level === "debug") {
15
- return debug(...flatContent);
16
- }
17
- if (level === "info") {
18
- return info(...flatContent);
19
- }
20
- if (level === "warn") {
21
- return warn(...flatContent);
22
- }
23
- if (level === "error") {
24
- return error(...flatContent);
25
- }
26
- log(...flatContent);
3
+ const isVerbose = details?.isVerbose ?? false;
4
+ const mode = details?.config?.mode ?? "default";
5
+ const level = details?.level ?? "info";
6
+ const prefix = details?.config?.prefix ? details?.config?.prefix : void 0;
7
+ const log = details?.config?.log ?? console.log;
8
+ const info = details?.config?.info ?? console.info;
9
+ const warn = details?.config?.warn ?? console.warn;
10
+ const error = details?.config?.error ?? console.error;
11
+ const debug = details?.config?.debug ?? console.debug;
12
+ if (mode === "disabled") return;
13
+ if (isVerbose && mode !== "verbose") return;
14
+ const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();
15
+ if (level === "debug") return debug(...flatContent);
16
+ if (level === "info") return info(...flatContent);
17
+ if (level === "warn") return warn(...flatContent);
18
+ if (level === "error") return error(...flatContent);
19
+ log(...flatContent);
27
20
  };
28
- var ANSIColors = /* @__PURE__ */ ((ANSIColors2) => {
29
- ANSIColors2["RESET"] = "\x1B[0m";
30
- ANSIColors2["GREY"] = "\x1B[90m";
31
- ANSIColors2["GREY_DARK"] = "\x1B[38;5;239m";
32
- ANSIColors2["BLUE"] = "\x1B[34m";
33
- ANSIColors2["RED"] = "\x1B[31m";
34
- ANSIColors2["GREEN"] = "\x1B[32m";
35
- ANSIColors2["YELLOW"] = "\x1B[33m";
36
- ANSIColors2["MAGENTA"] = "\x1B[35m";
37
- ANSIColors2["BEIGE"] = "\x1B[38;5;3m";
38
- ANSIColors2["CYAN"] = "\x1B[36m";
39
- ANSIColors2["WHITE"] = "\x1B[37m";
40
- return ANSIColors2;
41
- })(ANSIColors || {});
42
- const spinnerFrames = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
21
+ let ANSIColors = /* @__PURE__ */ function(ANSIColors$1) {
22
+ ANSIColors$1["RESET"] = "\x1B[0m";
23
+ ANSIColors$1["GREY"] = "\x1B[90m";
24
+ ANSIColors$1["GREY_DARK"] = "\x1B[38;5;239m";
25
+ ANSIColors$1["BLUE"] = "\x1B[34m";
26
+ ANSIColors$1["RED"] = "\x1B[31m";
27
+ ANSIColors$1["GREEN"] = "\x1B[32m";
28
+ ANSIColors$1["YELLOW"] = "\x1B[38;5;226m";
29
+ ANSIColors$1["MAGENTA"] = "\x1B[35m";
30
+ ANSIColors$1["BEIGE"] = "\x1B[38;5;3m";
31
+ ANSIColors$1["ORANGE"] = "\x1B[38;5;208m";
32
+ ANSIColors$1["CYAN"] = "\x1B[36m";
33
+ ANSIColors$1["WHITE"] = "\x1B[37m";
34
+ return ANSIColors$1;
35
+ }({});
36
+ const spinnerFrames = [
37
+ "⠋",
38
+ "⠙",
39
+ "⠹",
40
+ "⠸",
41
+ "⠼",
42
+ "⠴",
43
+ "⠦",
44
+ "⠧",
45
+ "⠇",
46
+ "⠏"
47
+ ];
48
+ /**
49
+ * The appLogger function takes the logger and merges it with the configuration from the intlayer config file.
50
+ * It allows overriding the default configuration by passing a config object in the details parameter.
51
+ * The configuration is merged with the default configuration from the intlayer config file.
52
+ */
43
53
  const getAppLogger = (configuration, globalDetails) => (content, details) => logger(content, {
44
- ...details ?? {},
45
- config: {
46
- ...configuration?.log,
47
- ...globalDetails?.config,
48
- ...details?.config ?? {}
49
- }
54
+ ...details ?? {},
55
+ config: {
56
+ ...configuration?.log,
57
+ ...globalDetails?.config,
58
+ ...details?.config ?? {}
59
+ }
50
60
  });
51
- const colorize = (s, color, reset) => color ? `${color}${s}${reset ? typeof reset === "boolean" ? "\x1B[0m" /* RESET */ : reset : "\x1B[0m" /* RESET */}` : s;
52
- const colorizeLocales = (locales, color = "\x1B[32m" /* GREEN */, reset = "\x1B[0m" /* RESET */) => [locales].flat().map((locale) => colorize(locale, color, reset)).join(`, `);
53
- const colorizeKey = (keyPath, color = "\x1B[38;5;3m" /* BEIGE */, reset = "\x1B[0m" /* RESET */) => [keyPath].flat().map((key) => colorize(key, color, reset)).join(`, `);
54
- const colorizePath = (path, color = "\x1B[90m" /* GREY */, reset = "\x1B[0m" /* RESET */) => [path].flat().map((p) => colorize(p, color, reset)).join(`, `);
61
+ const colorize = (s, color, reset) => color ? `${color}${s}${reset ? typeof reset === "boolean" ? ANSIColors.RESET : reset : ANSIColors.RESET}` : s;
62
+ const colorizeLocales = (locales, color = ANSIColors.GREEN, reset = ANSIColors.RESET) => [locales].flat().map((locale) => colorize(locale, color, reset)).join(`, `);
63
+ const colorizeKey = (keyPath, color = ANSIColors.BEIGE, reset = ANSIColors.RESET) => [keyPath].flat().map((key) => colorize(key, color, reset)).join(`, `);
64
+ const colorizePath = (path, color = ANSIColors.GREY, reset = ANSIColors.RESET) => [path].flat().map((p) => colorize(p, color, reset)).join(`, `);
65
+ /**
66
+ * Colorize numeric value using Intl.NumberFormat and optional ANSI colors.
67
+ *
68
+ * Examples:
69
+ * colorizeNumber(2, [{ pluralRule: 'one' , color: ANSIColors.GREEN}, { pluralRule: 'other' , color: ANSIColors.RED}]) // "'\x1b[31m2\x1b[0m"
70
+ */
55
71
  const colorizeNumber = (number, options = {
56
- zero: "\x1B[34m" /* BLUE */,
57
- one: "\x1B[34m" /* BLUE */,
58
- two: "\x1B[34m" /* BLUE */,
59
- few: "\x1B[34m" /* BLUE */,
60
- many: "\x1B[34m" /* BLUE */,
61
- other: "\x1B[34m" /* BLUE */
72
+ zero: ANSIColors.BLUE,
73
+ one: ANSIColors.BLUE,
74
+ two: ANSIColors.BLUE,
75
+ few: ANSIColors.BLUE,
76
+ many: ANSIColors.BLUE,
77
+ other: ANSIColors.BLUE
62
78
  }) => {
63
- if (number === 0) {
64
- const color2 = options.zero ?? "\x1B[32m" /* GREEN */;
65
- return colorize(number.toString(), color2);
66
- }
67
- const rule = new Intl.PluralRules("en").select(number);
68
- const color = options[rule];
69
- return colorize(number.toString(), color);
79
+ if (number === 0) {
80
+ const color$1 = options.zero ?? ANSIColors.GREEN;
81
+ return colorize(number.toString(), color$1);
82
+ }
83
+ const color = options[new Intl.PluralRules("en").select(number)];
84
+ return colorize(number.toString(), color);
70
85
  };
71
86
  const removeColor = (text) => text.replace(/\x1b\[[0-9;]*m/g, "");
72
87
  const getLength = (length) => {
73
- let value = 0;
74
- if (typeof length === "number") {
75
- value = length;
76
- }
77
- if (typeof length === "string") {
78
- value = length.length;
79
- }
80
- if (Array.isArray(length) && length.every((l) => typeof l === "string")) {
81
- value = Math.max(...length.map((str) => str.length));
82
- }
83
- if (Array.isArray(length) && length.every((l) => typeof l === "number")) {
84
- value = Math.max(...length);
85
- }
86
- return Math.max(value, 0);
88
+ let value = 0;
89
+ if (typeof length === "number") value = length;
90
+ if (typeof length === "string") value = length.length;
91
+ if (Array.isArray(length) && length.every((l) => typeof l === "string")) value = Math.max(...length.map((str) => str.length));
92
+ if (Array.isArray(length) && length.every((l) => typeof l === "number")) value = Math.max(...length);
93
+ return Math.max(value, 0);
87
94
  };
88
95
  const defaultColonOptions = {
89
- colSize: 0,
90
- minSize: 0,
91
- maxSize: Infinity,
92
- pad: "right",
93
- padChar: "0"
96
+ colSize: 0,
97
+ minSize: 0,
98
+ maxSize: Infinity,
99
+ pad: "right",
100
+ padChar: "0"
94
101
  };
95
- const colon = (text, options) => [text].flat().map((text2) => {
96
- const { colSize, minSize, maxSize, pad, padChar } = {
97
- ...defaultColonOptions,
98
- ...options ?? {}
99
- };
100
- const length = getLength(colSize);
101
- const spacesLength = Math.max(
102
- minSize,
103
- Math.min(maxSize, length - removeColor(text2).length)
104
- );
105
- if (pad === "left") {
106
- return `${" ".repeat(spacesLength)}${text2}`;
107
- }
108
- return `${text2}${" ".repeat(spacesLength)}`;
102
+ /**
103
+ * Create a string of spaces of a given length.
104
+ *
105
+ * @param colSize - The length of the string to create.
106
+ * @returns A string of spaces.
107
+ */
108
+ const colon = (text, options) => [text].flat().map((text$1) => {
109
+ const { colSize, minSize, maxSize, pad, padChar } = {
110
+ ...defaultColonOptions,
111
+ ...options ?? {}
112
+ };
113
+ const length = getLength(colSize);
114
+ const spacesLength = Math.max(minSize, Math.min(maxSize, length - removeColor(text$1).length));
115
+ if (pad === "left") return `${" ".repeat(spacesLength)}${text$1}`;
116
+ return `${text$1}${" ".repeat(spacesLength)}`;
109
117
  }).join("");
110
- const x = colorize("\u2717", "\x1B[31m" /* RED */);
111
- const v = colorize("\u2713", "\x1B[32m" /* GREEN */);
112
- const clock = colorize("\u23F2", "\x1B[34m" /* BLUE */);
113
- export {
114
- ANSIColors,
115
- clock,
116
- colon,
117
- colorize,
118
- colorizeKey,
119
- colorizeLocales,
120
- colorizeNumber,
121
- colorizePath,
122
- getAppLogger,
123
- logger,
124
- removeColor,
125
- spinnerFrames,
126
- v,
127
- x
128
- };
118
+ const x = colorize("", ANSIColors.RED);
119
+ const v = colorize("", ANSIColors.GREEN);
120
+ const clock = colorize("", ANSIColors.BLUE);
121
+
122
+ //#endregion
123
+ export { ANSIColors, clock, colon, colorize, colorizeKey, colorizeLocales, colorizeNumber, colorizePath, getAppLogger, logger, removeColor, spinnerFrames, v, x };
129
124
  //# sourceMappingURL=logger.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/logger.ts"],"sourcesContent":["import type { CustomIntlayerConfig } from './types/config';\nimport { Locales } from './types/locales';\n\nexport type Details = {\n isVerbose?: boolean;\n level?: 'info' | 'warn' | 'error' | 'debug';\n config?: CustomIntlayerConfig['log'];\n};\n\nexport type Logger = (content: any, details?: Details) => void;\n\nexport const logger: Logger = (content, details) => {\n const isVerbose = details?.isVerbose ?? false;\n const mode = details?.config?.mode ?? 'default';\n const level = details?.level ?? 'info';\n const prefix = Boolean(details?.config?.prefix)\n ? details?.config?.prefix\n : undefined;\n const log = details?.config?.log ?? console.log;\n const info = details?.config?.info ?? console.info;\n const warn = details?.config?.warn ?? console.warn;\n const error = details?.config?.error ?? console.error;\n const debug = details?.config?.debug ?? console.debug;\n\n if (mode === 'disabled') return;\n\n if (isVerbose && mode !== 'verbose') return;\n\n const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();\n\n if (level === 'debug') {\n return debug(...flatContent);\n }\n\n if (level === 'info') {\n return info(...flatContent);\n }\n\n if (level === 'warn') {\n return warn(...flatContent);\n }\n\n if (level === 'error') {\n return error(...flatContent);\n }\n\n log(...flatContent);\n};\n\nexport enum ANSIColors {\n RESET = '\\x1b[0m',\n GREY = '\\x1b[90m',\n GREY_DARK = '\\x1b[38;5;239m',\n BLUE = '\\x1b[34m',\n RED = '\\x1b[31m',\n GREEN = '\\x1b[32m',\n YELLOW = '\\x1b[33m',\n MAGENTA = '\\x1b[35m',\n BEIGE = '\\x1b[38;5;3m',\n CYAN = '\\x1b[36m',\n WHITE = '\\x1b[37m',\n}\n\nexport const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\n/**\n * The appLogger function takes the logger and merges it with the configuration from the intlayer config file.\n * It allows overriding the default configuration by passing a config object in the details parameter.\n * The configuration is merged with the default configuration from the intlayer config file.\n */\nexport const getAppLogger =\n (configuration?: CustomIntlayerConfig, globalDetails?: Details) =>\n (content: any, details?: Details) =>\n logger(content, {\n ...(details ?? {}),\n config: {\n ...configuration?.log,\n ...globalDetails?.config,\n ...(details?.config ?? {}),\n },\n });\n\nexport const colorize = (\n s: string,\n color?: ANSIColors,\n reset?: boolean | ANSIColors\n): string =>\n color\n ? `${color}${s}${reset ? (typeof reset === 'boolean' ? ANSIColors.RESET : reset) : ANSIColors.RESET}`\n : s;\n\nexport const colorizeLocales = (\n locales: Locales | Locales[],\n color = ANSIColors.GREEN,\n reset: boolean | ANSIColors = ANSIColors.RESET\n) =>\n [locales]\n .flat()\n .map((locale) => colorize(locale, color, reset))\n .join(`, `);\n\nexport const colorizeKey = (\n keyPath: string | string[],\n color = ANSIColors.BEIGE,\n reset: boolean | ANSIColors = ANSIColors.RESET\n) =>\n [keyPath]\n .flat()\n .map((key) => colorize(key, color, reset))\n .join(`, `);\n\nexport const colorizePath = (\n path: string | string[],\n color = ANSIColors.GREY,\n reset: boolean | ANSIColors = ANSIColors.RESET\n) =>\n [path]\n .flat()\n .map((p) => colorize(p, color, reset))\n .join(`, `);\n\n/**\n * Colorize numeric value using Intl.NumberFormat and optional ANSI colors.\n *\n * Examples:\n * colorizeNumber(2, [{ pluralRule: 'one' , color: ANSIColors.GREEN}, { pluralRule: 'other' , color: ANSIColors.RED}]) // \"'\\x1b[31m2\\x1b[0m\"\n */\nexport const colorizeNumber = (\n number: number,\n options: Partial<Record<Intl.LDMLPluralRule, ANSIColors>> = {\n zero: ANSIColors.BLUE,\n one: ANSIColors.BLUE,\n two: ANSIColors.BLUE,\n few: ANSIColors.BLUE,\n many: ANSIColors.BLUE,\n other: ANSIColors.BLUE,\n }\n): string => {\n if (number === 0) {\n const color = options.zero ?? ANSIColors.GREEN;\n return colorize(number.toString(), color);\n }\n\n const rule = new Intl.PluralRules('en').select(number);\n const color = options[rule];\n return colorize(number.toString(), color);\n};\n\nexport const removeColor = (text: string) =>\n text.replace(/\\x1b\\[[0-9;]*m/g, '');\n\nconst getLength = (length: number | number[] | string | string[]): number => {\n let value: number = 0;\n if (typeof length === 'number') {\n value = length;\n }\n if (typeof length === 'string') {\n value = length.length;\n }\n if (Array.isArray(length) && length.every((l) => typeof l === 'string')) {\n value = Math.max(...length.map((str) => str.length));\n }\n if (Array.isArray(length) && length.every((l) => typeof l === 'number')) {\n value = Math.max(...length);\n }\n return Math.max(value, 0);\n};\n\nconst defaultColonOptions = {\n colSize: 0,\n minSize: 0,\n maxSize: Infinity,\n pad: 'right',\n padChar: '0',\n};\n\n/**\n * Create a string of spaces of a given length.\n *\n * @param colSize - The length of the string to create.\n * @returns A string of spaces.\n */\nexport const colon = (\n text: string | string[],\n options?: {\n colSize?: number | number[] | string | string[];\n minSize?: number;\n maxSize?: number;\n pad?: 'left' | 'right';\n padChar?: string;\n }\n): string =>\n [text]\n .flat()\n .map((text) => {\n const { colSize, minSize, maxSize, pad, padChar } = {\n ...defaultColonOptions,\n ...(options ?? {}),\n };\n\n const length = getLength(colSize);\n const spacesLength = Math.max(\n minSize!,\n Math.min(maxSize!, length - removeColor(text).length)\n );\n\n if (pad === 'left') {\n return `${' '.repeat(spacesLength)}${text}`;\n }\n\n return `${text}${' '.repeat(spacesLength)}`;\n })\n .join('');\n\nexport const x = colorize('✗', ANSIColors.RED);\nexport const v = colorize('✓', ANSIColors.GREEN);\nexport const clock = colorize('⏲', ANSIColors.BLUE);\n"],"mappings":"AAWO,MAAM,SAAiB,CAAC,SAAS,YAAY;AAClD,QAAM,YAAY,SAAS,aAAa;AACxC,QAAM,OAAO,SAAS,QAAQ,QAAQ;AACtC,QAAM,QAAQ,SAAS,SAAS;AAChC,QAAM,SAAS,QAAQ,SAAS,QAAQ,MAAM,IAC1C,SAAS,QAAQ,SACjB;AACJ,QAAM,MAAM,SAAS,QAAQ,OAAO,QAAQ;AAC5C,QAAM,OAAO,SAAS,QAAQ,QAAQ,QAAQ;AAC9C,QAAM,OAAO,SAAS,QAAQ,QAAQ,QAAQ;AAC9C,QAAM,QAAQ,SAAS,QAAQ,SAAS,QAAQ;AAChD,QAAM,QAAQ,SAAS,QA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AG,OAAO,IAAI,CAAC,QAAQ,IAAI,MAAM,CAAC;AAAA,EACrD;AACA,MAAI,MAAM,QAAQ,MAAM,KAAK,OAAO,MAAM,CAAC,MAAM,OAAO,MAAM,QAAQ,GAAG;AACvE,YAAQ,KAAK,IAAI,GAAG,MAAM;AAAA,EAC5B;AACA,SAAO,KAAK,IAAI,OAAO,CAAC;AAC1B;AAEA,MAAM,sBAAsB;AAAA,EAC1B,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,KAAK;AAAA,EACL,SAAS;AACX;AAQO,MAAM,QAAQ,CACnB,MACA,YAQA,CAAC,IAAI,EACF,KAAK,EACL,IAAI,CAACC,UAAS;AACb,QAAM,EAAE,SAAS,SAAS,SAAS,KAAK,QAAQ,IAAI;AAAA,IAClD,GAAG;AAAA,IACH,GAAI,WAAW,CAAC;AAAA,EAClB;AAEA,QAAM,SAAS,UAAU,OAAO;AAChC,QAAM,eAAe,KAAK;AAAA,IACxB;AAAA,IACA,KAAK,IAAI,SAAU,SAAS,YAAYA,KAAI,EAAE,MAAM;AAAA,EACtD;AAEA,MAAI,QAAQ,QAAQ;AAClB,WAAO,GAAG,IAAI,OAAO,YAAY,CAAC,GAAGA,KAAI;AAAA,EAC3C;AAEA,SAAO,GAAGA,KAAI,GAAG,IAAI,OAAO,YAAY,CAAC;AAC3C,CAAC,EACA,KAAK,EAAE;AAEL,MAAM,IAAI,SAAS,UAAK,oBAAc;AACtC,MAAM,IAAI,SAAS,UAAK,sBAAgB;AACxC,MAAM,QAAQ,SAAS,UAAK,qBAAe;","names":["ANSIColors","color","text"]}
1
+ {"version":3,"file":"logger.mjs","names":["logger: Logger","color","value: number","text"],"sources":["../../src/logger.ts"],"sourcesContent":["import type { CustomIntlayerConfig, Locale } from '@intlayer/types';\n\nexport type Details = {\n isVerbose?: boolean;\n level?: 'info' | 'warn' | 'error' | 'debug';\n config?: CustomIntlayerConfig['log'];\n};\n\nexport type Logger = (content: any, details?: Details) => void;\n\nexport const logger: Logger = (content, details) => {\n const isVerbose = details?.isVerbose ?? false;\n const mode = details?.config?.mode ?? 'default';\n const level = details?.level ?? 'info';\n const prefix = details?.config?.prefix ? details?.config?.prefix : undefined;\n const log = details?.config?.log ?? console.log;\n const info = details?.config?.info ?? console.info;\n const warn = details?.config?.warn ?? console.warn;\n const error = details?.config?.error ?? console.error;\n const debug = details?.config?.debug ?? console.debug;\n\n if (mode === 'disabled') return;\n\n if (isVerbose && mode !== 'verbose') return;\n\n const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();\n\n if (level === 'debug') {\n return debug(...flatContent);\n }\n\n if (level === 'info') {\n return info(...flatContent);\n }\n\n if (level === 'warn') {\n return warn(...flatContent);\n }\n\n if (level === 'error') {\n return error(...flatContent);\n }\n\n log(...flatContent);\n};\n\nexport enum ANSIColors {\n RESET = '\\x1b[0m',\n GREY = '\\x1b[90m',\n GREY_DARK = '\\x1b[38;5;239m',\n BLUE = '\\x1b[34m',\n RED = '\\x1b[31m',\n GREEN = '\\x1b[32m',\n YELLOW = '\\x1b[38;5;226m',\n MAGENTA = '\\x1b[35m',\n BEIGE = '\\x1b[38;5;3m',\n ORANGE = '\\x1b[38;5;208m',\n CYAN = '\\x1b[36m',\n WHITE = '\\x1b[37m',\n}\n\nexport const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\n/**\n * The appLogger function takes the logger and merges it with the configuration from the intlayer config file.\n * It allows overriding the default configuration by passing a config object in the details parameter.\n * The configuration is merged with the default configuration from the intlayer config file.\n */\nexport const getAppLogger =\n (configuration?: CustomIntlayerConfig, globalDetails?: Details) =>\n (content: any, details?: Details) =>\n logger(content, {\n ...(details ?? {}),\n config: {\n ...configuration?.log,\n ...globalDetails?.config,\n ...(details?.config ?? {}),\n },\n });\n\nexport const colorize = (\n s: string,\n color?: ANSIColors,\n reset?: boolean | ANSIColors\n): string =>\n color\n ? `${color}${s}${reset ? (typeof reset === 'boolean' ? ANSIColors.RESET : reset) : ANSIColors.RESET}`\n : s;\n\nexport const colorizeLocales = (\n locales: Locale | Locale[],\n color = ANSIColors.GREEN,\n reset: boolean | ANSIColors = ANSIColors.RESET\n) =>\n [locales]\n .flat()\n .map((locale) => colorize(locale, color, reset))\n .join(`, `);\n\nexport const colorizeKey = (\n keyPath: string | string[],\n color = ANSIColors.BEIGE,\n reset: boolean | ANSIColors = ANSIColors.RESET\n) =>\n [keyPath]\n .flat()\n .map((key) => colorize(key, color, reset))\n .join(`, `);\n\nexport const colorizePath = (\n path: string | string[],\n color = ANSIColors.GREY,\n reset: boolean | ANSIColors = ANSIColors.RESET\n) =>\n [path]\n .flat()\n .map((p) => colorize(p, color, reset))\n .join(`, `);\n\n/**\n * Colorize numeric value using Intl.NumberFormat and optional ANSI colors.\n *\n * Examples:\n * colorizeNumber(2, [{ pluralRule: 'one' , color: ANSIColors.GREEN}, { pluralRule: 'other' , color: ANSIColors.RED}]) // \"'\\x1b[31m2\\x1b[0m\"\n */\nexport const colorizeNumber = (\n number: number,\n options: Partial<Record<Intl.LDMLPluralRule, ANSIColors>> = {\n zero: ANSIColors.BLUE,\n one: ANSIColors.BLUE,\n two: ANSIColors.BLUE,\n few: ANSIColors.BLUE,\n many: ANSIColors.BLUE,\n other: ANSIColors.BLUE,\n }\n): string => {\n if (number === 0) {\n const color = options.zero ?? ANSIColors.GREEN;\n return colorize(number.toString(), color);\n }\n\n const rule = new Intl.PluralRules('en').select(number);\n const color = options[rule];\n return colorize(number.toString(), color);\n};\n\nexport const removeColor = (text: string) =>\n // biome-ignore lint/suspicious/noControlCharactersInRegex: we need to remove the color codes\n text.replace(/\\x1b\\[[0-9;]*m/g, '');\n\nconst getLength = (length: number | number[] | string | string[]): number => {\n let value: number = 0;\n if (typeof length === 'number') {\n value = length;\n }\n if (typeof length === 'string') {\n value = length.length;\n }\n if (Array.isArray(length) && length.every((l) => typeof l === 'string')) {\n value = Math.max(...length.map((str) => str.length));\n }\n if (Array.isArray(length) && length.every((l) => typeof l === 'number')) {\n value = Math.max(...length);\n }\n return Math.max(value, 0);\n};\n\nconst defaultColonOptions = {\n colSize: 0,\n minSize: 0,\n maxSize: Infinity,\n pad: 'right',\n padChar: '0',\n};\n\n/**\n * Create a string of spaces of a given length.\n *\n * @param colSize - The length of the string to create.\n * @returns A string of spaces.\n */\nexport const colon = (\n text: string | string[],\n options?: {\n colSize?: number | number[] | string | string[];\n minSize?: number;\n maxSize?: number;\n pad?: 'left' | 'right';\n padChar?: string;\n }\n): string =>\n [text]\n .flat()\n .map((text) => {\n const { colSize, minSize, maxSize, pad, padChar } = {\n ...defaultColonOptions,\n ...(options ?? {}),\n };\n\n const length = getLength(colSize);\n const spacesLength = Math.max(\n minSize!,\n Math.min(maxSize!, length - removeColor(text).length)\n );\n\n if (pad === 'left') {\n return `${' '.repeat(spacesLength)}${text}`;\n }\n\n return `${text}${' '.repeat(spacesLength)}`;\n })\n .join('');\n\nexport const x = colorize('✗', ANSIColors.RED);\nexport const v = colorize('✓', ANSIColors.GREEN);\nexport const clock = colorize('⏲', ANSIColors.BLUE);\n"],"mappings":";AAUA,MAAaA,UAAkB,SAAS,YAAY;CAClD,MAAM,YAAY,SAAS,aAAa;CACxC,MAAM,OAAO,SAAS,QAAQ,QAAQ;CACtC,MAAM,QAAQ,SAAS,SAAS;CAChC,MAAM,SAAS,SAAS,QAAQ,SAAS,SAAS,QAAQ,SAAS;CACnE,MAAM,MAAM,SAAS,QAAQ,OAAO,QAAQ;CAC5C,MAAM,OAAO,SAAS,QAAQ,QAAQ,QAAQ;CAC9C,MAAM,OAAO,SAAS,QAAQ,QAAQ,QAAQ;CAC9C,MAAM,QAAQ,SAAS,QAAQ,SAAS,QAAQ;CAChD,MAAM,QAAQ,SAAS,QAAQ,SAAS,QAAQ;AAEhD,KAAI,SAAS,WAAY;AAEzB,KAAI,aAAa,SAAS,UAAW;CAErC,MAAM,cAAc,SAAS,CAAC,QAAQ,GAAG,CAAC,QAAQ,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AAGA;AAGvC,QAAO,GAAGA,SAAO,IAAI,OAAO,aAAa;EACzC,CACD,KAAK,GAAG;AAEb,MAAa,IAAI,SAAS,KAAK,WAAW,IAAI;AAC9C,MAAa,IAAI,SAAS,KAAK,WAAW,MAAM;AAChD,MAAa,QAAQ,SAAS,KAAK,WAAW,KAAK"}
@@ -0,0 +1,6 @@
1
+ //#region package.json
2
+ var version = "7.0.0-canary.0";
3
+
4
+ //#endregion
5
+ export { version };
6
+ //# sourceMappingURL=package.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.mjs","names":[],"sources":["../../package.json"],"sourcesContent":["{\n \"name\": \"@intlayer/config\",\n \"version\": \"7.0.0-canary.0\",\n \"private\": false,\n \"description\": \"Retrieve Intlayer configurations and manage environment variables for both server-side and client-side environments.\",\n \"keywords\": [\n \"intlayer\",\n \"layer\",\n \"abstraction\",\n \"data\",\n \"internationalization\",\n \"i18n\",\n \"typescript\",\n \"javascript\",\n \"json\",\n \"file\"\n ],\n \"homepage\": \"https://intlayer.org\",\n \"bugs\": {\n \"url\": \"https://github.com/aymericzip/intlayer/issues\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/aymericzip/intlayer.git\"\n },\n \"license\": \"Apache-2.0\",\n \"author\": {\n \"name\": \"Aymeric PINEAU\",\n \"url\": \"https://github.com/aymericzip\"\n },\n \"contributors\": [\n {\n \"name\": \"Aymeric Pineau\",\n \"email\": \"ay.pineau@gmail.com\",\n \"url\": \"https://github.com/aymericzip\"\n }\n ],\n \"sideEffects\": false,\n \"exports\": {\n \".\": {\n \"types\": \"./dist/types/index.d.ts\",\n \"browser\": \"./dist/esm/client.mjs\",\n \"require\": \"./dist/cjs/index.cjs\",\n \"import\": \"./dist/esm/index.mjs\"\n },\n \"./client\": {\n \"types\": \"./dist/types/client.d.ts\",\n \"require\": \"./dist/cjs/client.cjs\",\n \"import\": \"./dist/esm/client.mjs\"\n },\n \"./built\": {\n \"types\": \"./dist/types/built.d.ts\",\n \"require\": \"./dist/cjs/built.cjs\",\n \"import\": \"./dist/esm/built.mjs\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"main\": \"dist/cjs/index.cjs\",\n \"module\": \"dist/esm/index.mjs\",\n \"types\": \"dist/types/index.d.ts\",\n \"typesVersions\": {\n \"*\": {\n \".\": [\n \"./dist/types/index.d.ts\"\n ],\n \"client\": [\n \"./dist/types/client.d.ts\"\n ],\n \"built\": [\n \"./dist/types/built.d.ts\"\n ],\n \"package.json\": [\n \"./package.json\"\n ]\n }\n },\n \"files\": [\n \"./dist\",\n \"./package.json\"\n ],\n \"scripts\": {\n \"build\": \"tsdown --config tsdown.config.ts\",\n \"build:ci\": \"tsdown --config tsdown.config.ts\",\n \"clean\": \"rimraf ./dist .turbo\",\n \"dev\": \"tsdown --config tsdown.config.ts --watch\",\n \"format\": \"biome format . --check\",\n \"format:fix\": \"biome format --write .\",\n \"lint\": \"biome lint .\",\n \"lint:fix\": \"biome lint --write .\",\n \"prepublish\": \"cp -f ../../../README.md ./README.md\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"typecheck\": \"tsc --noEmit --project tsconfig.types.json\"\n },\n \"dependencies\": {\n \"@intlayer/types\": \"workspace:*\",\n \"deepmerge\": \"4.3.1\",\n \"dotenv\": \"16.6.1\",\n \"esbuild\": \"0.25.2\"\n },\n \"devDependencies\": {\n \"@types/node\": \"24.9.1\",\n \"@utils/ts-config\": \"workspace:*\",\n \"@utils/ts-config-types\": \"workspace:*\",\n \"@utils/tsdown-config\": \"workspace:*\",\n \"rimraf\": \"6.0.1\",\n \"tsdown\": \"0.15.9\",\n \"typescript\": \"5.9.3\",\n \"vitest\": \"4.0.3\"\n },\n \"peerDependencies\": {\n \"intlayer\": \"workspace:*\",\n \"react\": \">=16.0.0\"\n },\n \"peerDependenciesMeta\": {\n \"intlayer\": {\n \"optional\": true\n },\n \"react\": {\n \"optional\": true\n }\n },\n \"engines\": {\n \"node\": \">=14.18\"\n },\n \"bug\": {\n \"url\": \"https://github.com/aymericzip/intlayer/issues\"\n }\n}\n"],"mappings":";cAEa"}
@@ -1,28 +1,45 @@
1
1
  import { logger } from "./logger.mjs";
2
+ import { extractErrorMessage } from "./utils/extractErrorMessage.mjs";
3
+
4
+ //#region src/retryManager.ts
2
5
  const DEFAULT_MAX_RETRY = 3;
3
6
  const DEFAULT_DELAY = 0;
4
- const retryManager = (fn, {
5
- maxRetry = DEFAULT_MAX_RETRY,
6
- delay = DEFAULT_DELAY,
7
- onError
8
- } = {}) => (
9
- // ───────────────────────────────^ returned wrapper function
10
- async (...args) => {
11
- for (let attempt = 0; ; attempt++) {
12
- try {
13
- return await fn(...args);
14
- } catch (err) {
15
- onError?.(err);
16
- logger(["Request failed", err], {
17
- level: "error"
18
- });
19
- if (attempt >= maxRetry) throw err;
20
- if (delay > 0) await new Promise((res) => setTimeout(res, delay));
21
- }
22
- }
23
- }
24
- );
25
- export {
26
- retryManager
7
+ /**
8
+ * Wrap an async function `fn` so it’s retried on failure.
9
+ *
10
+ * @param fn The async function to wrap
11
+ * @param options { maxRetry, delay }
12
+ * @returns A new function with the same signature as `fn`
13
+ */
14
+ const retryManager = (fn, { maxRetry = DEFAULT_MAX_RETRY, delay = DEFAULT_DELAY, onError, onMaxTryReached } = {}) => async (...args) => {
15
+ let lastError;
16
+ for (let attempt = 0; attempt <= maxRetry; attempt++) try {
17
+ return await fn(...args);
18
+ } catch (err) {
19
+ lastError = err;
20
+ const error = extractErrorMessage(err);
21
+ if (attempt >= maxRetry) {
22
+ if (onMaxTryReached) {
23
+ onMaxTryReached?.({
24
+ error,
25
+ attempt,
26
+ maxRetry
27
+ });
28
+ return null;
29
+ }
30
+ throw err;
31
+ }
32
+ if (onError) onError?.({
33
+ error,
34
+ attempt,
35
+ maxRetry
36
+ });
37
+ else logger(error, { level: "error" });
38
+ if (delay > 0) await new Promise((res) => setTimeout(res, delay));
39
+ }
40
+ throw lastError ?? /* @__PURE__ */ new Error("Unexpected: retry loop completed without result");
27
41
  };
42
+
43
+ //#endregion
44
+ export { retryManager };
28
45
  //# sourceMappingURL=retryManager.mjs.map