@intlayer/config 8.1.2 → 8.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -43
  2. package/dist/cjs/built.cjs +1 -7
  3. package/dist/cjs/built.cjs.map +1 -1
  4. package/dist/cjs/client.cjs +1 -40
  5. package/dist/cjs/configFile/buildConfigurationFields.cjs +1 -188
  6. package/dist/cjs/configFile/buildConfigurationFields.cjs.map +1 -1
  7. package/dist/cjs/configFile/getConfiguration.cjs +1 -70
  8. package/dist/cjs/configFile/getConfiguration.cjs.map +1 -1
  9. package/dist/cjs/configFile/index.cjs +1 -10
  10. package/dist/cjs/configFile/loadConfigurationFile.cjs +1 -33
  11. package/dist/cjs/configFile/loadConfigurationFile.cjs.map +1 -1
  12. package/dist/cjs/configFile/searchConfigurationFile.cjs +1 -51
  13. package/dist/cjs/configFile/searchConfigurationFile.cjs.map +1 -1
  14. package/dist/cjs/defaultValues/build.cjs +1 -29
  15. package/dist/cjs/defaultValues/build.cjs.map +1 -1
  16. package/dist/cjs/defaultValues/compiler.cjs +1 -24
  17. package/dist/cjs/defaultValues/compiler.cjs.map +1 -1
  18. package/dist/cjs/defaultValues/content.cjs +1 -56
  19. package/dist/cjs/defaultValues/content.cjs.map +1 -1
  20. package/dist/cjs/defaultValues/dictionary.cjs +1 -26
  21. package/dist/cjs/defaultValues/dictionary.cjs.map +1 -1
  22. package/dist/cjs/defaultValues/editor.cjs +1 -41
  23. package/dist/cjs/defaultValues/editor.cjs.map +1 -1
  24. package/dist/cjs/defaultValues/index.cjs +1 -78
  25. package/dist/cjs/defaultValues/internationalization.cjs +1 -27
  26. package/dist/cjs/defaultValues/internationalization.cjs.map +1 -1
  27. package/dist/cjs/defaultValues/log.cjs +1 -21
  28. package/dist/cjs/defaultValues/log.cjs.map +1 -1
  29. package/dist/cjs/defaultValues/routing.cjs +1 -35
  30. package/dist/cjs/defaultValues/routing.cjs.map +1 -1
  31. package/dist/cjs/defaultValues/system.cjs +1 -47
  32. package/dist/cjs/defaultValues/system.cjs.map +1 -1
  33. package/dist/cjs/index.cjs +1 -81
  34. package/dist/cjs/loadEnvFile.cjs +1 -36
  35. package/dist/cjs/loadEnvFile.cjs.map +1 -1
  36. package/dist/cjs/loadExternalFile/bundleFile.cjs +1 -71
  37. package/dist/cjs/loadExternalFile/bundleFile.cjs.map +1 -1
  38. package/dist/cjs/loadExternalFile/bundleJSFile.cjs +2 -0
  39. package/dist/cjs/loadExternalFile/bundleJSFile.cjs.map +1 -0
  40. package/dist/cjs/loadExternalFile/index.cjs +1 -0
  41. package/dist/cjs/loadExternalFile/loadExternalFile.cjs +1 -79
  42. package/dist/cjs/loadExternalFile/loadExternalFile.cjs.map +1 -1
  43. package/dist/cjs/loadExternalFile/parseFileContent.cjs +1 -77
  44. package/dist/cjs/loadExternalFile/parseFileContent.cjs.map +1 -1
  45. package/dist/cjs/loadExternalFile/transpileTSToCJS.cjs +1 -63
  46. package/dist/cjs/loadExternalFile/transpileTSToCJS.cjs.map +1 -1
  47. package/dist/cjs/logger.cjs +1 -150
  48. package/dist/cjs/logger.cjs.map +1 -1
  49. package/dist/cjs/node.cjs +1 -0
  50. package/dist/cjs/utils/ESMxCJSHelpers.cjs +1 -27
  51. package/dist/cjs/utils/ESMxCJSHelpers.cjs.map +1 -1
  52. package/dist/cjs/utils/alias.cjs +2 -0
  53. package/dist/cjs/utils/alias.cjs.map +1 -0
  54. package/dist/cjs/utils/cacheDisk.cjs +1 -162
  55. package/dist/cjs/utils/cacheDisk.cjs.map +1 -1
  56. package/dist/cjs/utils/cacheMemory.cjs +1 -269
  57. package/dist/cjs/utils/cacheMemory.cjs.map +1 -1
  58. package/dist/cjs/utils/clearModuleCache.cjs +1 -26
  59. package/dist/cjs/utils/clearModuleCache.cjs.map +1 -1
  60. package/dist/cjs/utils/compareVersions.cjs +1 -38
  61. package/dist/cjs/utils/compareVersions.cjs.map +1 -1
  62. package/dist/cjs/utils/extractErrorMessage.cjs +1 -95
  63. package/dist/cjs/utils/extractErrorMessage.cjs.map +1 -1
  64. package/dist/cjs/utils/getExtension.cjs +1 -14
  65. package/dist/cjs/utils/getExtension.cjs.map +1 -1
  66. package/dist/cjs/utils/getPackageJsonPath.cjs +1 -35
  67. package/dist/cjs/utils/getPackageJsonPath.cjs.map +1 -1
  68. package/dist/cjs/utils/index.cjs +1 -0
  69. package/dist/cjs/utils/logStack.cjs +1 -16
  70. package/dist/cjs/utils/logStack.cjs.map +1 -1
  71. package/dist/cjs/utils/normalizePath.cjs +1 -17
  72. package/dist/cjs/utils/normalizePath.cjs.map +1 -1
  73. package/dist/cjs/utils/retryManager.cjs +2 -0
  74. package/dist/cjs/utils/retryManager.cjs.map +1 -0
  75. package/dist/cjs/utils/stringFormatter/camelCaseToKebabCase.cjs +1 -13
  76. package/dist/cjs/utils/stringFormatter/camelCaseToKebabCase.cjs.map +1 -1
  77. package/dist/cjs/utils/stringFormatter/camelCaseToSentence.cjs +1 -16
  78. package/dist/cjs/utils/stringFormatter/camelCaseToSentence.cjs.map +1 -1
  79. package/dist/cjs/utils/stringFormatter/index.cjs +1 -10
  80. package/dist/cjs/utils/stringFormatter/kebabCaseToCamelCase.cjs +1 -14
  81. package/dist/cjs/utils/stringFormatter/kebabCaseToCamelCase.cjs.map +1 -1
  82. package/dist/cjs/utils/stringFormatter/toLowerCamelCase.cjs +1 -19
  83. package/dist/cjs/utils/stringFormatter/toLowerCamelCase.cjs.map +1 -1
  84. package/dist/esm/_virtual/_rolldown/runtime.mjs +1 -22
  85. package/dist/esm/built.mjs +1 -7
  86. package/dist/esm/built.mjs.map +1 -1
  87. package/dist/esm/client.mjs +1 -11
  88. package/dist/esm/configFile/buildConfigurationFields.mjs +1 -186
  89. package/dist/esm/configFile/buildConfigurationFields.mjs.map +1 -1
  90. package/dist/esm/configFile/getConfiguration.mjs +1 -67
  91. package/dist/esm/configFile/getConfiguration.mjs.map +1 -1
  92. package/dist/esm/configFile/index.mjs +1 -5
  93. package/dist/esm/configFile/loadConfigurationFile.mjs +1 -32
  94. package/dist/esm/configFile/loadConfigurationFile.mjs.map +1 -1
  95. package/dist/esm/configFile/searchConfigurationFile.mjs +1 -48
  96. package/dist/esm/configFile/searchConfigurationFile.mjs.map +1 -1
  97. package/dist/esm/defaultValues/build.mjs +1 -18
  98. package/dist/esm/defaultValues/build.mjs.map +1 -1
  99. package/dist/esm/defaultValues/compiler.mjs +1 -19
  100. package/dist/esm/defaultValues/compiler.mjs.map +1 -1
  101. package/dist/esm/defaultValues/content.mjs +1 -43
  102. package/dist/esm/defaultValues/content.mjs.map +1 -1
  103. package/dist/esm/defaultValues/dictionary.mjs +1 -16
  104. package/dist/esm/defaultValues/dictionary.mjs.map +1 -1
  105. package/dist/esm/defaultValues/editor.mjs +1 -26
  106. package/dist/esm/defaultValues/editor.mjs.map +1 -1
  107. package/dist/esm/defaultValues/index.mjs +1 -24
  108. package/dist/esm/defaultValues/internationalization.mjs +1 -17
  109. package/dist/esm/defaultValues/internationalization.mjs.map +1 -1
  110. package/dist/esm/defaultValues/log.mjs +1 -13
  111. package/dist/esm/defaultValues/log.mjs.map +1 -1
  112. package/dist/esm/defaultValues/routing.mjs +1 -22
  113. package/dist/esm/defaultValues/routing.mjs.map +1 -1
  114. package/dist/esm/defaultValues/system.mjs +1 -30
  115. package/dist/esm/defaultValues/system.mjs.map +1 -1
  116. package/dist/esm/index.mjs +1 -28
  117. package/dist/esm/loadEnvFile.mjs +1 -32
  118. package/dist/esm/loadEnvFile.mjs.map +1 -1
  119. package/dist/esm/loadExternalFile/bundleFile.mjs +1 -67
  120. package/dist/esm/loadExternalFile/bundleFile.mjs.map +1 -1
  121. package/dist/esm/loadExternalFile/bundleJSFile.mjs +2 -0
  122. package/dist/esm/loadExternalFile/bundleJSFile.mjs.map +1 -0
  123. package/dist/esm/loadExternalFile/index.mjs +1 -0
  124. package/dist/esm/loadExternalFile/loadExternalFile.mjs +1 -75
  125. package/dist/esm/loadExternalFile/loadExternalFile.mjs.map +1 -1
  126. package/dist/esm/loadExternalFile/parseFileContent.mjs +1 -73
  127. package/dist/esm/loadExternalFile/parseFileContent.mjs.map +1 -1
  128. package/dist/esm/loadExternalFile/transpileTSToCJS.mjs +1 -60
  129. package/dist/esm/loadExternalFile/transpileTSToCJS.mjs.map +1 -1
  130. package/dist/esm/logger.mjs +1 -133
  131. package/dist/esm/logger.mjs.map +1 -1
  132. package/dist/esm/node.mjs +1 -0
  133. package/dist/esm/utils/ESMxCJSHelpers.mjs +1 -24
  134. package/dist/esm/utils/ESMxCJSHelpers.mjs.map +1 -1
  135. package/dist/esm/utils/alias.mjs +2 -0
  136. package/dist/esm/utils/alias.mjs.map +1 -0
  137. package/dist/esm/utils/cacheDisk.mjs +1 -159
  138. package/dist/esm/utils/cacheDisk.mjs.map +1 -1
  139. package/dist/esm/utils/cacheMemory.mjs +1 -261
  140. package/dist/esm/utils/cacheMemory.mjs.map +1 -1
  141. package/dist/esm/utils/clearModuleCache.mjs +1 -25
  142. package/dist/esm/utils/clearModuleCache.mjs.map +1 -1
  143. package/dist/esm/utils/compareVersions.mjs +1 -36
  144. package/dist/esm/utils/compareVersions.mjs.map +1 -1
  145. package/dist/esm/utils/extractErrorMessage.mjs +1 -93
  146. package/dist/esm/utils/extractErrorMessage.mjs.map +1 -1
  147. package/dist/esm/utils/getExtension.mjs +1 -12
  148. package/dist/esm/utils/getExtension.mjs.map +1 -1
  149. package/dist/esm/utils/getPackageJsonPath.mjs +1 -32
  150. package/dist/esm/utils/getPackageJsonPath.mjs.map +1 -1
  151. package/dist/esm/utils/index.mjs +1 -0
  152. package/dist/esm/utils/logStack.mjs +1 -15
  153. package/dist/esm/utils/logStack.mjs.map +1 -1
  154. package/dist/esm/utils/normalizePath.mjs +1 -15
  155. package/dist/esm/utils/normalizePath.mjs.map +1 -1
  156. package/dist/esm/utils/retryManager.mjs +2 -0
  157. package/dist/esm/utils/retryManager.mjs.map +1 -0
  158. package/dist/esm/utils/stringFormatter/camelCaseToKebabCase.mjs +1 -11
  159. package/dist/esm/utils/stringFormatter/camelCaseToKebabCase.mjs.map +1 -1
  160. package/dist/esm/utils/stringFormatter/camelCaseToSentence.mjs +1 -14
  161. package/dist/esm/utils/stringFormatter/camelCaseToSentence.mjs.map +1 -1
  162. package/dist/esm/utils/stringFormatter/index.mjs +1 -6
  163. package/dist/esm/utils/stringFormatter/kebabCaseToCamelCase.mjs +1 -12
  164. package/dist/esm/utils/stringFormatter/kebabCaseToCamelCase.mjs.map +1 -1
  165. package/dist/esm/utils/stringFormatter/toLowerCamelCase.mjs +1 -17
  166. package/dist/esm/utils/stringFormatter/toLowerCamelCase.mjs.map +1 -1
  167. package/dist/types/index.d.ts +15 -9
  168. package/dist/types/{bundleJSFile.d.ts → loadExternalFile/bundleJSFile.d.ts} +1 -1
  169. package/dist/types/loadExternalFile/bundleJSFile.d.ts.map +1 -0
  170. package/dist/types/loadExternalFile/index.d.ts +6 -0
  171. package/dist/types/loadExternalFile/loadExternalFile.d.ts +2 -3
  172. package/dist/types/loadExternalFile/loadExternalFile.d.ts.map +1 -1
  173. package/dist/types/loadExternalFile/transpileTSToCJS.d.ts +2 -3
  174. package/dist/types/loadExternalFile/transpileTSToCJS.d.ts.map +1 -1
  175. package/dist/types/node.d.ts +5 -0
  176. package/dist/types/{alias.d.ts → utils/alias.d.ts} +1 -1
  177. package/dist/types/utils/alias.d.ts.map +1 -0
  178. package/dist/types/utils/getPackageJsonPath.d.ts +1 -2
  179. package/dist/types/utils/getPackageJsonPath.d.ts.map +1 -1
  180. package/dist/types/utils/index.d.ts +17 -0
  181. package/dist/types/{retryManager.d.ts → utils/retryManager.d.ts} +1 -1
  182. package/dist/types/utils/retryManager.d.ts.map +1 -0
  183. package/package.json +42 -10
  184. package/dist/cjs/alias.cjs +0 -30
  185. package/dist/cjs/alias.cjs.map +0 -1
  186. package/dist/cjs/bundleJSFile.cjs +0 -34
  187. package/dist/cjs/bundleJSFile.cjs.map +0 -1
  188. package/dist/cjs/retryManager.cjs +0 -46
  189. package/dist/cjs/retryManager.cjs.map +0 -1
  190. package/dist/esm/alias.mjs +0 -28
  191. package/dist/esm/alias.mjs.map +0 -1
  192. package/dist/esm/bundleJSFile.mjs +0 -32
  193. package/dist/esm/bundleJSFile.mjs.map +0 -1
  194. package/dist/esm/retryManager.mjs +0 -45
  195. package/dist/esm/retryManager.mjs.map +0 -1
  196. package/dist/types/alias.d.ts.map +0 -1
  197. package/dist/types/bundleJSFile.d.ts.map +0 -1
  198. package/dist/types/retryManager.d.ts.map +0 -1
@@ -1,151 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
- //#region src/logger.ts
4
- let loggerPrefix;
5
- const setPrefix = (prefix) => {
6
- loggerPrefix = prefix;
7
- };
8
- const getPrefix = (configPrefix) => {
9
- if (typeof loggerPrefix !== "undefined") return loggerPrefix;
10
- return configPrefix;
11
- };
12
- const logger = (content, details) => {
13
- const isVerbose = details?.isVerbose ?? false;
14
- const mode = details?.config?.mode ?? "default";
15
- const level = details?.level ?? "info";
16
- const prefix = getPrefix(details?.config?.prefix);
17
- const log = details?.config?.log ?? console.log;
18
- const info = details?.config?.info ?? console.info;
19
- const warn = details?.config?.warn ?? console.warn;
20
- const error = details?.config?.error ?? console.error;
21
- const debug = details?.config?.debug ?? console.debug;
22
- if (mode === "disabled") return;
23
- if (isVerbose && mode !== "verbose") return;
24
- const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();
25
- if (level === "debug") return debug(...flatContent);
26
- if (level === "info") return info(...flatContent);
27
- if (level === "warn") return warn(...flatContent);
28
- if (level === "error") return error(...flatContent);
29
- log(...flatContent);
30
- };
31
- let ANSIColors = /* @__PURE__ */ function(ANSIColors) {
32
- ANSIColors["RESET"] = "\x1B[0m";
33
- ANSIColors["GREY"] = "\x1B[90m";
34
- ANSIColors["GREY_DARK"] = "\x1B[38;5;239m";
35
- ANSIColors["GREY_LIGHT"] = "\x1B[38;5;252m";
36
- ANSIColors["BLUE"] = "\x1B[34m";
37
- ANSIColors["RED"] = "\x1B[31m";
38
- ANSIColors["GREEN"] = "\x1B[32m";
39
- ANSIColors["YELLOW"] = "\x1B[38;5;226m";
40
- ANSIColors["MAGENTA"] = "\x1B[35m";
41
- ANSIColors["BEIGE"] = "\x1B[38;5;3m";
42
- ANSIColors["ORANGE"] = "\x1B[38;5;208m";
43
- ANSIColors["CYAN"] = "\x1B[36m";
44
- ANSIColors["WHITE"] = "\x1B[37m";
45
- ANSIColors["BOLD"] = "\x1B[1m";
46
- return ANSIColors;
47
- }({});
48
- const spinnerFrames = [
49
- "⠋",
50
- "⠙",
51
- "⠹",
52
- "⠸",
53
- "⠼",
54
- "⠴",
55
- "⠦",
56
- "⠧",
57
- "⠇",
58
- "⠏"
59
- ];
60
- /**
61
- * The appLogger function takes the logger and merges it with the configuration from the intlayer config file.
62
- * It allows overriding the default configuration by passing a config object in the details parameter.
63
- * The configuration is merged with the default configuration from the intlayer config file.
64
- */
65
- const getAppLogger = (configuration, globalDetails) => (content, details) => logger(content, {
66
- ...details ?? {},
67
- config: {
68
- ...configuration?.log,
69
- ...globalDetails?.config,
70
- ...details?.config ?? {}
71
- }
72
- });
73
- const colorize = (s, color, reset) => color ? `${color}${s}${reset ? typeof reset === "boolean" ? ANSIColors.RESET : reset : ANSIColors.RESET}` : s;
74
- const colorizeLocales = (locales, color = ANSIColors.GREEN, reset = ANSIColors.RESET) => [locales].flat().map((locale) => colorize(locale, color, reset)).join(`, `);
75
- const colorizeKey = (keyPath, color = ANSIColors.BEIGE, reset = ANSIColors.RESET) => [keyPath].flat().map((key) => colorize(key, color, reset)).join(`, `);
76
- const colorizePath = (path, color = ANSIColors.GREY, reset = ANSIColors.RESET) => [path].flat().map((p) => colorize(p, color, reset)).join(`, `);
77
- /**
78
- * Colorize numeric value using Intl.NumberFormat and optional ANSI colors.
79
- *
80
- * Examples:
81
- * colorizeNumber(2, [{ pluralRule: 'one' , color: ANSIColors.GREEN}, { pluralRule: 'other' , color: ANSIColors.RED}]) // "'\x1b[31m2\x1b[0m"
82
- */
83
- const colorizeNumber = (number, options = {
84
- zero: ANSIColors.BLUE,
85
- one: ANSIColors.BLUE,
86
- two: ANSIColors.BLUE,
87
- few: ANSIColors.BLUE,
88
- many: ANSIColors.BLUE,
89
- other: ANSIColors.BLUE
90
- }) => {
91
- if (number === 0) {
92
- const color = options.zero ?? ANSIColors.GREEN;
93
- return colorize(number.toString(), color);
94
- }
95
- const color = options[new Intl.PluralRules("en").select(Number(number))];
96
- return colorize(number.toString(), color);
97
- };
98
- const removeColor = (text) => text.replace(/\x1b\[[0-9;]*m/g, "");
99
- const getLength = (length) => {
100
- let value = 0;
101
- if (typeof length === "number") value = length;
102
- if (typeof length === "string") value = length.length;
103
- if (Array.isArray(length) && length.every((l) => typeof l === "string")) value = Math.max(...length.map((str) => str.length));
104
- if (Array.isArray(length) && length.every((l) => typeof l === "number")) value = Math.max(...length);
105
- return Math.max(value, 0);
106
- };
107
- const defaultColonOptions = {
108
- colSize: 0,
109
- minSize: 0,
110
- maxSize: Infinity,
111
- pad: "right",
112
- padChar: "0"
113
- };
114
- /**
115
- * Create a string of spaces of a given length.
116
- *
117
- * @param colSize - The length of the string to create.
118
- * @returns A string of spaces.
119
- */
120
- const colon = (text, options) => [text].flat().map((text) => {
121
- const { colSize, minSize, maxSize, pad, padChar } = {
122
- ...defaultColonOptions,
123
- ...options ?? {}
124
- };
125
- const length = getLength(colSize);
126
- const spacesLength = Math.max(minSize, Math.min(maxSize, length - removeColor(text).length));
127
- if (pad === "left") return `${" ".repeat(spacesLength)}${text}`;
128
- return `${text}${" ".repeat(spacesLength)}`;
129
- }).join("");
130
- const x = colorize("✗", ANSIColors.RED);
131
- const v = colorize("✓", ANSIColors.GREEN);
132
- const clock = colorize("⏲", ANSIColors.BLUE);
133
-
134
- //#endregion
135
- exports.ANSIColors = ANSIColors;
136
- exports.clock = clock;
137
- exports.colon = colon;
138
- exports.colorize = colorize;
139
- exports.colorizeKey = colorizeKey;
140
- exports.colorizeLocales = colorizeLocales;
141
- exports.colorizeNumber = colorizeNumber;
142
- exports.colorizePath = colorizePath;
143
- exports.getAppLogger = getAppLogger;
144
- exports.getPrefix = getPrefix;
145
- exports.logger = logger;
146
- exports.removeColor = removeColor;
147
- exports.setPrefix = setPrefix;
148
- exports.spinnerFrames = spinnerFrames;
149
- exports.v = v;
150
- exports.x = x;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e;const t=t=>{e=t},n=t=>e===void 0?t:e,r=(e,t)=>{let r=t?.isVerbose??!1,i=t?.config?.mode??`default`,a=t?.level??`info`,o=n(t?.config?.prefix),s=t?.config?.log??console.log,c=t?.config?.info??console.info,l=t?.config?.warn??console.warn,u=t?.config?.error??console.error,d=t?.config?.debug??console.debug;if(i===`disabled`||r&&i!==`verbose`)return;let f=o?[o,...[e].flat()]:[e].flat();if(a===`debug`)return d(...f);if(a===`info`)return c(...f);if(a===`warn`)return l(...f);if(a===`error`)return u(...f);s(...f)};let i=function(e){return e.RESET=`\x1B[0m`,e.GREY=`\x1B[90m`,e.GREY_DARK=`\x1B[38;5;239m`,e.GREY_LIGHT=`\x1B[38;5;252m`,e.BLUE=`\x1B[34m`,e.RED=`\x1B[31m`,e.GREEN=`\x1B[32m`,e.YELLOW=`\x1B[38;5;226m`,e.MAGENTA=`\x1B[35m`,e.BEIGE=`\x1B[38;5;3m`,e.ORANGE=`\x1B[38;5;208m`,e.CYAN=`\x1B[36m`,e.WHITE=`\x1B[37m`,e.BOLD=`\x1B[1m`,e}({});const a=[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`],o=(e,t)=>(n,i)=>r(n,{...i??{},config:{...e?.log,...t?.config,...i?.config??{}}}),s=(e,t,n)=>t?`${t}${e}${n?typeof n==`boolean`?i.RESET:n:i.RESET}`:e,c=(e,t=i.GREEN,n=i.RESET)=>[e].flat().map(e=>s(e,t,n)).join(`, `),l=(e,t=i.BEIGE,n=i.RESET)=>[e].flat().map(e=>s(e,t,n)).join(`, `),u=(e,t=i.GREY,n=i.RESET)=>[e].flat().map(e=>s(e,t,n)).join(`, `),d=(e,t={zero:i.BLUE,one:i.BLUE,two:i.BLUE,few:i.BLUE,many:i.BLUE,other:i.BLUE})=>{if(e===0){let n=t.zero??i.GREEN;return s(e.toString(),n)}let n=t[new Intl.PluralRules(`en`).select(Number(e))];return s(e.toString(),n)},f=e=>e.replace(/\x1b\[[0-9;]*m/g,``),p=e=>{let t=0;return typeof e==`number`&&(t=e),typeof e==`string`&&(t=e.length),Array.isArray(e)&&e.every(e=>typeof e==`string`)&&(t=Math.max(...e.map(e=>e.length))),Array.isArray(e)&&e.every(e=>typeof e==`number`)&&(t=Math.max(...e)),Math.max(t,0)},m={colSize:0,minSize:0,maxSize:1/0,pad:`right`,padChar:`0`},h=(e,t)=>[e].flat().map(e=>{let{colSize:n,minSize:r,maxSize:i,pad:a,padChar:o}={...m,...t??{}},s=p(n),c=Math.max(r,Math.min(i,s-f(e).length));return a===`left`?`${` `.repeat(c)}${e}`:`${e}${` `.repeat(c)}`}).join(``),g=s(`✗`,i.RED),_=s(`✓`,i.GREEN),v=s(`⏲`,i.BLUE);exports.ANSIColors=i,exports.clock=v,exports.colon=h,exports.colorize=s,exports.colorizeKey=l,exports.colorizeLocales=c,exports.colorizeNumber=d,exports.colorizePath=u,exports.getAppLogger=o,exports.getPrefix=n,exports.logger=r,exports.removeColor=f,exports.setPrefix=t,exports.spinnerFrames=a,exports.v=_,exports.x=g;
151
2
  //# sourceMappingURL=logger.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.cjs","names":[],"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\nlet loggerPrefix: string | undefined;\n\nexport const setPrefix = (prefix: string | undefined) => {\n loggerPrefix = prefix;\n};\n\nexport const getPrefix = (configPrefix?: string): string | undefined => {\n if (typeof loggerPrefix !== 'undefined') {\n return loggerPrefix;\n }\n\n return configPrefix;\n};\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 = getPrefix(details?.config?.prefix);\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 GREY_LIGHT = '\\x1b[38;5;252m',\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 BOLD = '\\x1b[1m',\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 | string,\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(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,IAAI;AAEJ,MAAa,aAAa,WAA+B;AACvD,gBAAe;;AAGjB,MAAa,aAAa,iBAA8C;AACtE,KAAI,OAAO,iBAAiB,YAC1B,QAAO;AAGT,QAAO;;AAGT,MAAa,UAAkB,SAAS,YAAY;CAClD,MAAM,YAAY,SAAS,aAAa;CACxC,MAAM,OAAO,SAAS,QAAQ,QAAQ;CACtC,MAAM,QAAQ,SAAS,SAAS;CAChC,MAAM,SAAS,U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;CACT,SAAS;CACT,SAAS;CACT,KAAK;CACL,SAAS;CACV;;;;;;;AAQD,MAAa,SACX,MACA,YAQA,CAAC,KAAK,CACH,MAAM,CACN,KAAK,SAAS;CACb,MAAM,EAAE,SAAS,SAAS,SAAS,KAAK,YAAY;EAClD,GAAG;EACH,GAAI,WAAW,EAAE;EAClB;CAED,MAAM,SAAS,UAAU,QAAQ;CACjC,MAAM,eAAe,KAAK,IACxB,SACA,KAAK,IAAI,SAAU,SAAS,YAAY,KAAK,CAAC,OAAO,CACtD;AAED,KAAI,QAAQ,OACV,QAAO,GAAG,IAAI,OAAO,aAAa,GAAG;AAGvC,QAAO,GAAG,OAAO,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"}
1
+ {"version":3,"file":"logger.cjs","names":[],"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\nlet loggerPrefix: string | undefined;\n\nexport const setPrefix = (prefix: string | undefined) => {\n loggerPrefix = prefix;\n};\n\nexport const getPrefix = (configPrefix?: string): string | undefined => {\n if (typeof loggerPrefix !== 'undefined') {\n return loggerPrefix;\n }\n\n return configPrefix;\n};\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 = getPrefix(details?.config?.prefix);\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 GREY_LIGHT = '\\x1b[38;5;252m',\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 BOLD = '\\x1b[1m',\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 | string,\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(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":"mEAUA,IAAI,EAEJ,MAAa,EAAa,GAA+B,CACvD,EAAe,GAGJ,EAAa,GACb,IAAiB,OAIrB,EAHE,EAME,GAAkB,EAAS,IAAY,CAClD,IAAM,EAAY,GAAS,WAAa,GAClC,EAAO,GAAS,QAAQ,MAAQ,UAChC,EAAQ,GAAS,OAAS,OAC1B,EAAS,EAAU,GAAS,QAAQ,OAAO,CAC3C,EAAM,GAAS,QAAQ,KAAO,QAAQ,IACtC,EAAO,GAAS,QAAQ,MAAQ,QAAQ,KACxC,EAAO,GAAS,QAAQ,MAAQ,QAAQ,KACxC,EAAQ,GAAS,QAAQ,OAAS,QAAQ,MAC1C,EAAQ,GAAS,QAAQ,OAAS,QAAQ,MAIhD,GAFI,IAAS,YAET,GAAa,IAAS,UAAW,OAErC,IAAM,EAAc,EAAS,CAAC,EAAQ,GAAG,CAAC,EAAQ,CAAC,MAAM,CAAC,CAAG,CAAC,EAAQ,CAAC,MAAM,CAE7E,GAAI,IAAU,QACZ,OAAO,EAAM,GAAG,EAAY,CAG9B,GAAI,IAAU,OACZ,OAAO,EAAK,GAAG,EAAY,CAG7B,GAAI,IAAU,OACZ,OAAO,EAAK,GAAG,EAAY,CAG7B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CACnC,EAAQ,EAAS,IAAK,EAAW,KAAK"}
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./configFile/buildConfigurationFields.cjs`),t=require(`./configFile/searchConfigurationFile.cjs`),n=require(`./configFile/getConfiguration.cjs`),r=require(`./defaultValues/index.cjs`);Object.defineProperty(exports,`DefaultValues`,{enumerable:!0,get:function(){return r.defaultValues_exports}}),exports.buildConfigurationFields=e.buildConfigurationFields,exports.configurationFilesCandidates=t.configurationFilesCandidates,exports.getConfiguration=n.getConfiguration,exports.getConfigurationAndFilePath=n.getConfigurationAndFilePath,exports.searchConfigurationFile=t.searchConfigurationFile;
@@ -1,28 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- const require_utils_getPackageJsonPath = require('./getPackageJsonPath.cjs');
4
- let node_module = require("node:module");
5
-
6
- //#region src/utils/ESMxCJSHelpers.ts
7
- const isESModule = typeof require("url").pathToFileURL(__filename).href === "string";
8
- /**
9
- * Require relative to the user project
10
- *
11
- * Note: Can resolve package that are installed in the user project, ex `'intlayer'`
12
- */
13
- const getProjectRequire = (startDir) => {
14
- const { packageJsonPath } = require_utils_getPackageJsonPath.getPackageJsonPath(startDir);
15
- return (0, node_module.createRequire)(packageJsonPath);
16
- };
17
- /**
18
- * Require relative to the @intlayer/config package
19
- *
20
- * Note: Can resolve package that are installed in the config package, ex `'@intlayer/types'`
21
- */
22
- const configESMxCJSRequire = isESModule ? (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href) : require;
23
-
24
- //#endregion
25
- exports.configESMxCJSRequire = configESMxCJSRequire;
26
- exports.getProjectRequire = getProjectRequire;
27
- exports.isESModule = isESModule;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./getPackageJsonPath.cjs`);let t=require(`node:module`);const n=typeof require(`url`).pathToFileURL(__filename).href==`string`,r=n=>{let{packageJsonPath:r}=e.getPackageJsonPath(n);return(0,t.createRequire)(r)},i=n?(0,t.createRequire)(require(`url`).pathToFileURL(__filename).href):require;exports.configESMxCJSRequire=i,exports.getProjectRequire=r,exports.isESModule=n;
28
2
  //# sourceMappingURL=ESMxCJSHelpers.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ESMxCJSHelpers.cjs","names":["getPackageJsonPath"],"sources":["../../../src/utils/ESMxCJSHelpers.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { getPackageJsonPath } from './getPackageJsonPath';\n\nexport const isESModule = typeof import.meta.url === 'string';\n\n/**\n * Require relative to the user project\n *\n * Note: Can resolve package that are installed in the user project, ex `'intlayer'`\n */\nexport const getProjectRequire = (startDir?: string): NodeJS.Require => {\n // Can fail on VSCode extensions\n const { packageJsonPath } = getPackageJsonPath(startDir);\n\n return createRequire(packageJsonPath);\n};\n\n/**\n * Require relative to the @intlayer/config package\n *\n * Note: Can resolve package that are installed in the config package, ex `'@intlayer/types'`\n */\nexport const configESMxCJSRequire: NodeJS.Require = isESModule\n ? createRequire(import.meta.url)\n : require;\n"],"mappings":";;;;;;AAGA,MAAa,aAAa,yDAA2B;;;;;;AAOrD,MAAa,qBAAqB,aAAsC;CAEtE,MAAM,EAAE,oBAAoBA,oDAAmB,SAAS;AAExD,uCAAqB,gBAAgB;;;;;;;AAQvC,MAAa,uBAAuC,0FAClB,GAC9B"}
1
+ {"version":3,"file":"ESMxCJSHelpers.cjs","names":["getPackageJsonPath"],"sources":["../../../src/utils/ESMxCJSHelpers.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { getPackageJsonPath } from './getPackageJsonPath';\n\nexport const isESModule = typeof import.meta.url === 'string';\n\n/**\n * Require relative to the user project\n *\n * Note: Can resolve package that are installed in the user project, ex `'intlayer'`\n */\nexport const getProjectRequire = (startDir?: string): NodeJS.Require => {\n // Can fail on VSCode extensions\n const { packageJsonPath } = getPackageJsonPath(startDir);\n\n return createRequire(packageJsonPath);\n};\n\n/**\n * Require relative to the @intlayer/config package\n *\n * Note: Can resolve package that are installed in the config package, ex `'@intlayer/types'`\n */\nexport const configESMxCJSRequire: NodeJS.Require = isESModule\n ? createRequire(import.meta.url)\n : require;\n"],"mappings":"yLAGA,MAAa,EAAa,OAAA,QAAA,MAAA,CAAA,cAAA,WAAA,CAAA,MAA2B,SAOxC,EAAqB,GAAsC,CAEtE,GAAM,CAAE,mBAAoBA,EAAAA,mBAAmB,EAAS,CAExD,OAAA,EAAA,EAAA,eAAqB,EAAgB,EAQ1B,EAAuC,GAAA,EAAA,EAAA,eAAA,QAAA,MAAA,CAAA,cAAA,WAAA,CAAA,KAClB,CAC9B"}
@@ -0,0 +1,2 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./normalizePath.cjs`),t=require(`./getExtension.cjs`);let n=require(`node:path`);const r=({configuration:r,format:i,formatter:a=e=>e})=>{let o=t.getExtension(r,i??r.build.outputFormat[0]??`esm`),{baseDir:s}=r.content,{mainDir:c,configDir:l}=r.system,u=a(e.normalizePath((0,n.relative)(s,(0,n.join)(c,`dictionaries.${o}`)))),d=a(e.normalizePath((0,n.relative)(s,(0,n.join)(c,`unmerged_dictionaries.${o}`)))),f=a(e.normalizePath((0,n.relative)(s,(0,n.join)(c,`remote_dictionaries.${o}`)))),p=a(e.normalizePath((0,n.relative)(s,(0,n.join)(c,`dynamic_dictionaries.${o}`)))),m=a(e.normalizePath((0,n.relative)(s,(0,n.join)(c,`fetch_dictionaries.${o}`)))),h=a(e.normalizePath((0,n.relative)(s,(0,n.join)(l,`configuration.json`))));return{"@intlayer/dictionaries-entry":u,"@intlayer/unmerged-dictionaries-entry":d,"@intlayer/remote-dictionaries-entry":f,"@intlayer/dynamic-dictionaries-entry":p,"@intlayer/fetch-dictionaries-entry":m,"@intlayer/config/built":h}};exports.getAlias=r;
2
+ //# sourceMappingURL=alias.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alias.cjs","names":["getExtension","normalizePath"],"sources":["../../../src/utils/alias.ts"],"sourcesContent":["import { join, relative } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { getExtension } from './getExtension';\nimport { normalizePath } from './normalizePath';\n\nexport type GetAliasOptions = {\n configuration: IntlayerConfig;\n format?: 'esm' | 'cjs';\n formatter?: (value: string) => string;\n};\n\nexport const getAlias = ({\n configuration,\n format,\n formatter = (value: string) => value,\n}: GetAliasOptions) => {\n const extension = getExtension(\n configuration,\n format ?? configuration.build.outputFormat[0] ?? 'esm'\n );\n\n const { baseDir } = configuration.content;\n const { mainDir, configDir } = configuration.system;\n\n /**\n * Dictionaries\n */\n const dictionariesPath = join(mainDir, `dictionaries.${extension}`);\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n const fixedDictionariesPath = formatter(\n normalizePath(relativeDictionariesPath)\n );\n\n /**\n * Unmerged dictionaries\n */\n const unmergedDictionariesPath = join(\n mainDir,\n `unmerged_dictionaries.${extension}`\n );\n const relativeUnmergedDictionariesPath = relative(\n baseDir,\n unmergedDictionariesPath\n );\n const fixedUnmergedDictionariesPath = formatter(\n normalizePath(relativeUnmergedDictionariesPath)\n );\n\n /**\n * Remote dictionaries\n */\n const remoteDictionariesPath = join(\n mainDir,\n `remote_dictionaries.${extension}`\n );\n const relativeRemoteDictionariesPath = relative(\n baseDir,\n remoteDictionariesPath\n );\n const fixedRemoteDictionariesPath = formatter(\n normalizePath(relativeRemoteDictionariesPath)\n );\n\n /**\n * Dynamic dictionaries\n */\n const dynamicDictionariesPath = join(\n mainDir,\n `dynamic_dictionaries.${extension}`\n );\n const relativeDynamicDictionariesPath = relative(\n baseDir,\n dynamicDictionariesPath\n );\n const fixedDynamicDictionariesPath = formatter(\n normalizePath(relativeDynamicDictionariesPath)\n );\n\n /**\n * Fetch dictionaries\n */\n const fetchDictionariesPath = join(\n mainDir,\n `fetch_dictionaries.${extension}`\n );\n const relativeFetchDictionariesPath = relative(\n baseDir,\n fetchDictionariesPath\n );\n const fixedFetchDictionariesPath = formatter(\n normalizePath(relativeFetchDictionariesPath)\n );\n\n /**\n * Configuration\n */\n const configurationPath = join(configDir, `configuration.json`);\n const relativeConfigurationPath = relative(baseDir, configurationPath);\n const fixedConfigurationPath = formatter(\n normalizePath(relativeConfigurationPath)\n );\n\n return {\n '@intlayer/dictionaries-entry': fixedDictionariesPath,\n '@intlayer/unmerged-dictionaries-entry': fixedUnmergedDictionariesPath,\n '@intlayer/remote-dictionaries-entry': fixedRemoteDictionariesPath,\n '@intlayer/dynamic-dictionaries-entry': fixedDynamicDictionariesPath,\n '@intlayer/fetch-dictionaries-entry': fixedFetchDictionariesPath,\n '@intlayer/config/built': fixedConfigurationPath,\n } as const;\n};\n"],"mappings":"kNAWA,MAAa,GAAY,CACvB,gBACA,SACA,YAAa,GAAkB,KACV,CACrB,IAAM,EAAYA,EAAAA,aAChB,EACA,GAAU,EAAc,MAAM,aAAa,IAAM,MAClD,CAEK,CAAE,WAAY,EAAc,QAC5B,CAAE,UAAS,aAAc,EAAc,OAOvC,EAAwB,EAC5BC,EAAAA,eAAAA,EAAAA,EAAAA,UAFwC,GAAA,EAAA,EAAA,MADZ,EAAS,gBAAgB,IAAY,CACC,CAE3B,CACxC,CAaK,EAAgC,EACpCA,EAAAA,eAAAA,EAAAA,EAAAA,UAJA,GAAA,EAAA,EAAA,MAJA,EACA,yBAAyB,IAC1B,CAIA,CAEgD,CAChD,CAaK,EAA8B,EAClCA,EAAAA,eAAAA,EAAAA,EAAAA,UAJA,GAAA,EAAA,EAAA,MAJA,EACA,uBAAuB,IACxB,CAIA,CAE8C,CAC9C,CAaK,EAA+B,EACnCA,EAAAA,eAAAA,EAAAA,EAAAA,UAJA,GAAA,EAAA,EAAA,MAJA,EACA,wBAAwB,IACzB,CAIA,CAE+C,CAC/C,CAaK,EAA6B,EACjCA,EAAAA,eAAAA,EAAAA,EAAAA,UAJA,GAAA,EAAA,EAAA,MAJA,EACA,sBAAsB,IACvB,CAIA,CAE6C,CAC7C,CAOK,EAAyB,EAC7BA,EAAAA,eAAAA,EAAAA,EAAAA,UAFyC,GAAA,EAAA,EAAA,MADZ,EAAW,qBAAqB,CACO,CAE5B,CACzC,CAED,MAAO,CACL,+BAAgC,EAChC,wCAAyC,EACzC,sCAAuC,EACvC,uCAAwC,EACxC,qCAAsC,EACtC,yBAA0B,EAC3B"}
@@ -1,163 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- const require_utils_cacheMemory = require('./cacheMemory.cjs');
4
- let node_path = require("node:path");
5
- let _intlayer_types_package_json = require("@intlayer/types/package.json");
6
- _intlayer_types_package_json = require_runtime.__toESM(_intlayer_types_package_json);
7
- let node_fs_promises = require("node:fs/promises");
8
- let node_v8 = require("node:v8");
9
- let node_zlib = require("node:zlib");
10
-
11
- //#region src/utils/cacheDisk.ts
12
- const DEFAULTS = { compress: true };
13
- const ensureDir = async (dir) => {
14
- await (0, node_fs_promises.mkdir)(dir, { recursive: true });
15
- };
16
- const atomicWriteFile = async (file, data) => {
17
- const tmp = `${file}.tmp-${process.pid}-${Math.random().toString(36).slice(2)}`;
18
- await (0, node_fs_promises.writeFile)(tmp, data);
19
- await (0, node_fs_promises.rename)(tmp, file);
20
- };
21
- const shouldUseCompression = (buf, force) => force === true || force !== false && buf.byteLength > 1024;
22
- /** Derive on-disk path from config dir + namespace + key id. */
23
- const cachePath = (cacheDir, id, ns) => (0, node_path.join)(cacheDir, ns ? (0, node_path.join)(ns, id) : id);
24
- /** ------------------------- Local cache facade ------------------------- **/
25
- const cacheMap = /* @__PURE__ */ new Map();
26
- const cacheDisk = (intlayerConfig, keys, options) => {
27
- const { cacheDir } = intlayerConfig.system;
28
- const buildCacheEnabled = intlayerConfig.build.cache ?? true;
29
- const persistent = options?.persistent === true || typeof options?.persistent === "undefined" && buildCacheEnabled;
30
- const { compress, ttlMs, maxTimeMs, namespace } = {
31
- ...DEFAULTS,
32
- ...options
33
- };
34
- const id = require_utils_cacheMemory.computeKeyId(keys);
35
- const filePath = cachePath(cacheDir, id, namespace);
36
- const readFromDisk = async () => {
37
- try {
38
- const statValue = await (0, node_fs_promises.stat)(filePath).catch(() => void 0);
39
- if (!statValue) return void 0;
40
- if (typeof ttlMs === "number" && ttlMs > 0) {
41
- if (Date.now() - statValue.mtimeMs > ttlMs) return void 0;
42
- }
43
- let raw = await (0, node_fs_promises.readFile)(filePath);
44
- const flag = raw[0];
45
- raw = raw.subarray(1);
46
- const deserialized = (0, node_v8.deserialize)(flag === 1 ? (0, node_zlib.gunzipSync)(raw) : raw);
47
- let value;
48
- const maybeObj = deserialized;
49
- if (!!maybeObj && typeof maybeObj === "object" && typeof maybeObj.version === "string" && typeof maybeObj.timestamp === "number" && Object.hasOwn(maybeObj, "data")) {
50
- const entry = maybeObj;
51
- if (entry.version !== _intlayer_types_package_json.default.version) {
52
- try {
53
- await (0, node_fs_promises.unlink)(filePath);
54
- } catch {}
55
- return;
56
- }
57
- if (typeof maxTimeMs === "number" && maxTimeMs > 0) {
58
- if (Date.now() - entry.timestamp > maxTimeMs) {
59
- try {
60
- await (0, node_fs_promises.unlink)(filePath);
61
- } catch {}
62
- return;
63
- }
64
- }
65
- value = entry.data;
66
- } else {
67
- if (typeof maxTimeMs === "number" && maxTimeMs > 0) {
68
- if (Date.now() - statValue.mtimeMs > maxTimeMs) {
69
- try {
70
- await (0, node_fs_promises.unlink)(filePath);
71
- } catch {}
72
- return;
73
- }
74
- }
75
- value = deserialized;
76
- }
77
- cacheMap.set(id, value);
78
- return value;
79
- } catch {
80
- return;
81
- }
82
- };
83
- const writeToDisk = async (value) => {
84
- try {
85
- await ensureDir((0, node_path.dirname)(filePath));
86
- const envelope = {
87
- version: _intlayer_types_package_json.default.version,
88
- timestamp: Date.now(),
89
- data: value
90
- };
91
- const payload = Buffer.from((0, node_v8.serialize)(envelope));
92
- const gz = shouldUseCompression(payload, compress) ? (0, node_zlib.gzipSync)(payload) : payload;
93
- await atomicWriteFile(filePath, Buffer.concat([Buffer.from([gz === payload ? 0 : 1]), gz]));
94
- } catch {}
95
- };
96
- return {
97
- get: async () => {
98
- const mem = cacheMap.get(id);
99
- if (mem !== void 0) return mem;
100
- if (persistent && buildCacheEnabled) return await readFromDisk();
101
- },
102
- set: async (value) => {
103
- cacheMap.set(id, value);
104
- if (persistent && buildCacheEnabled) await writeToDisk(value);
105
- },
106
- clear: async () => {
107
- cacheMap.delete(id);
108
- try {
109
- await (0, node_fs_promises.unlink)(filePath);
110
- } catch {}
111
- },
112
- clearAll: async () => {
113
- require_utils_cacheMemory.clearAllCache();
114
- if (persistent && buildCacheEnabled) {
115
- const base = namespace ? (0, node_path.join)(cacheDir, namespace) : cacheDir;
116
- try {
117
- await (0, node_fs_promises.rm)(base, {
118
- recursive: true,
119
- force: true
120
- });
121
- } catch {}
122
- try {
123
- await (0, node_fs_promises.mkdir)(base, { recursive: true });
124
- } catch {}
125
- }
126
- },
127
- isValid: async () => {
128
- if (cacheMap.get(id) !== void 0) return true;
129
- if (!persistent || !buildCacheEnabled) return false;
130
- try {
131
- const statValue = await (0, node_fs_promises.stat)(filePath).catch(() => void 0);
132
- if (!statValue) return false;
133
- if (typeof ttlMs === "number" && ttlMs > 0) {
134
- if (Date.now() - statValue.mtimeMs > ttlMs) return false;
135
- }
136
- let raw = await (0, node_fs_promises.readFile)(filePath);
137
- const flag = raw[0];
138
- raw = raw.subarray(1);
139
- const maybeObj = (0, node_v8.deserialize)(flag === 1 ? (0, node_zlib.gunzipSync)(raw) : raw);
140
- if (!!maybeObj && typeof maybeObj === "object" && typeof maybeObj.version === "string" && typeof maybeObj.timestamp === "number" && Object.hasOwn(maybeObj, "data")) {
141
- const entry = maybeObj;
142
- if (entry.version !== _intlayer_types_package_json.default.version) return false;
143
- if (typeof maxTimeMs === "number" && maxTimeMs > 0) {
144
- if (Date.now() - entry.timestamp > maxTimeMs) return false;
145
- }
146
- return true;
147
- }
148
- if (typeof maxTimeMs === "number" && maxTimeMs > 0) {
149
- if (Date.now() - statValue.mtimeMs > maxTimeMs) return false;
150
- }
151
- return true;
152
- } catch {
153
- return false;
154
- }
155
- },
156
- id,
157
- filePath
158
- };
159
- };
160
-
161
- //#endregion
162
- exports.cacheDisk = cacheDisk;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`./cacheMemory.cjs`);let n=require(`node:path`),r=require(`@intlayer/types/package.json`);r=e.__toESM(r);let i=require(`node:fs/promises`),a=require(`node:v8`),o=require(`node:zlib`);const s={compress:!0},c=async e=>{await(0,i.mkdir)(e,{recursive:!0})},l=async(e,t)=>{let n=`${e}.tmp-${process.pid}-${Math.random().toString(36).slice(2)}`;await(0,i.writeFile)(n,t),await(0,i.rename)(n,e)},u=(e,t)=>t===!0||t!==!1&&e.byteLength>1024,d=(e,t,r)=>(0,n.join)(e,r?(0,n.join)(r,t):t),f=new Map,p=(e,p,m)=>{let{cacheDir:h}=e.system,g=e.build.cache??!0,_=m?.persistent===!0||m?.persistent===void 0&&g,{compress:v,ttlMs:y,maxTimeMs:b,namespace:x}={...s,...m},S=t.computeKeyId(p),C=d(h,S,x),w=async()=>{try{let e=await(0,i.stat)(C).catch(()=>void 0);if(!e||typeof y==`number`&&y>0&&Date.now()-e.mtimeMs>y)return;let t=await(0,i.readFile)(C),n=t[0];t=t.subarray(1);let s=(0,a.deserialize)(n===1?(0,o.gunzipSync)(t):t),c,l=s;if(l&&typeof l==`object`&&typeof l.version==`string`&&typeof l.timestamp==`number`&&Object.hasOwn(l,`data`)){let e=l;if(e.version!==r.default.version){try{await(0,i.unlink)(C)}catch{}return}if(typeof b==`number`&&b>0&&Date.now()-e.timestamp>b){try{await(0,i.unlink)(C)}catch{}return}c=e.data}else{if(typeof b==`number`&&b>0&&Date.now()-e.mtimeMs>b){try{await(0,i.unlink)(C)}catch{}return}c=s}return f.set(S,c),c}catch{return}},T=async e=>{try{await c((0,n.dirname)(C));let t={version:r.default.version,timestamp:Date.now(),data:e},i=Buffer.from((0,a.serialize)(t)),s=u(i,v)?(0,o.gzipSync)(i):i;await l(C,Buffer.concat([Buffer.from([s===i?0:1]),s]))}catch{}};return{get:async()=>{let e=f.get(S);if(e!==void 0)return e;if(_&&g)return await w()},set:async e=>{f.set(S,e),_&&g&&await T(e)},clear:async()=>{f.delete(S);try{await(0,i.unlink)(C)}catch{}},clearAll:async()=>{if(t.clearAllCache(),_&&g){let e=x?(0,n.join)(h,x):h;try{await(0,i.rm)(e,{recursive:!0,force:!0})}catch{}try{await(0,i.mkdir)(e,{recursive:!0})}catch{}}},isValid:async()=>{if(f.get(S)!==void 0)return!0;if(!_||!g)return!1;try{let e=await(0,i.stat)(C).catch(()=>void 0);if(!e||typeof y==`number`&&y>0&&Date.now()-e.mtimeMs>y)return!1;let t=await(0,i.readFile)(C),n=t[0];t=t.subarray(1);let s=(0,a.deserialize)(n===1?(0,o.gunzipSync)(t):t);if(s&&typeof s==`object`&&typeof s.version==`string`&&typeof s.timestamp==`number`&&Object.hasOwn(s,`data`)){let e=s;return!(e.version!==r.default.version||typeof b==`number`&&b>0&&Date.now()-e.timestamp>b)}return!(typeof b==`number`&&b>0&&Date.now()-e.mtimeMs>b)}catch{return!1}},id:S,filePath:C}};exports.cacheDisk=p;
163
2
  //# sourceMappingURL=cacheDisk.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"cacheDisk.cjs","names":["computeKeyId","configPackageJson"],"sources":["../../../src/utils/cacheDisk.ts"],"sourcesContent":["import {\n mkdir,\n readFile,\n rename,\n rm,\n stat,\n unlink,\n writeFile,\n} from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\nimport { deserialize, serialize } from 'node:v8';\nimport { gunzipSync, gzipSync } from 'node:zlib';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport configPackageJson from '@intlayer/types/package.json' with {\n type: 'json',\n};\nimport { type CacheKey, clearAllCache, computeKeyId } from './cacheMemory';\n\n/** ------------------------- Persistence layer ------------------------- **/\n\n/** Cache envelope structure stored on disk */\ntype CacheEnvelope = {\n /** Version of the config package (for cache invalidation) */\n version: string;\n /** Timestamp when the cache entry was created (in milliseconds) */\n timestamp: number;\n /** Data payload (the actual cached value) */\n data: unknown;\n};\n\ntype LocalCacheOptions = {\n /** Preferred new option name */\n persistent?: boolean;\n /** Time-to-live in ms; if expired, disk entry is ignored. */\n ttlMs?: number;\n /** Max age in ms based on stored creation timestamp; invalidates on exceed. */\n maxTimeMs?: number;\n /** Optional namespace to separate different logical caches. */\n namespace?: string;\n /** Gzip values on disk (on by default for blobs > 1KB). */\n compress?: boolean;\n};\n\nconst DEFAULTS: Required<Pick<LocalCacheOptions, 'compress'>> = {\n compress: true,\n};\n\nconst ensureDir = async (dir: string) => {\n await mkdir(dir, { recursive: true });\n};\n\nconst atomicWriteFile = async (file: string, data: Buffer) => {\n const tmp = `${file}.tmp-${process.pid}-${Math.random().toString(36).slice(2)}`;\n await writeFile(tmp, data);\n await rename(tmp, file);\n};\n\nconst shouldUseCompression = (buf: Buffer, force?: boolean) =>\n force === true || (force !== false && buf.byteLength > 1024);\n\n/** Derive on-disk path from config dir + namespace + key id. */\nconst cachePath = (cacheDir: string, id: string, ns?: string) =>\n join(cacheDir, ns ? join(ns, id) : id);\n\n/** ------------------------- Local cache facade ------------------------- **/\n\nconst cacheMap = new Map<string, any>();\n\nexport const cacheDisk = (\n intlayerConfig: IntlayerConfig,\n keys: CacheKey[],\n options?: LocalCacheOptions\n) => {\n const { cacheDir } = intlayerConfig.system;\n const buildCacheEnabled = intlayerConfig.build.cache ?? true;\n const persistent =\n options?.persistent === true ||\n (typeof options?.persistent === 'undefined' && buildCacheEnabled);\n\n const { compress, ttlMs, maxTimeMs, namespace } = {\n ...DEFAULTS,\n ...options,\n };\n\n // single stable id for this key tuple (works for both memory & disk)\n const id = computeKeyId(keys);\n const filePath = cachePath(cacheDir, id, namespace);\n\n const readFromDisk = async (): Promise<unknown | undefined> => {\n try {\n const statValue = await stat(filePath).catch(() => undefined);\n\n if (!statValue) return undefined;\n\n if (typeof ttlMs === 'number' && ttlMs > 0) {\n const age = Date.now() - statValue.mtimeMs;\n if (age > ttlMs) return undefined;\n }\n let raw = await readFile(filePath);\n // header: 1 byte flag (0x00 raw, 0x01 gzip)\n const flag = raw[0];\n\n raw = raw.subarray(1);\n\n const payload = flag === 0x01 ? gunzipSync(raw) : raw;\n const deserialized = deserialize(payload) as unknown;\n\n let value: unknown;\n const maybeObj = deserialized as Record<string, unknown> | null;\n const isEnvelope =\n !!maybeObj &&\n typeof maybeObj === 'object' &&\n typeof (maybeObj as any).version === 'string' &&\n typeof (maybeObj as any).timestamp === 'number' &&\n Object.hasOwn(maybeObj, 'data');\n\n if (isEnvelope) {\n const entry = maybeObj as CacheEnvelope;\n\n if (entry.version !== configPackageJson.version) {\n try {\n await unlink(filePath);\n } catch {}\n return undefined;\n }\n\n if (typeof maxTimeMs === 'number' && maxTimeMs > 0) {\n const age = Date.now() - entry.timestamp;\n if (age > maxTimeMs) {\n try {\n await unlink(filePath);\n } catch {}\n return undefined;\n }\n }\n\n value = entry.data;\n } else {\n // Backward compatibility: old entries had raw serialized value.\n if (typeof maxTimeMs === 'number' && maxTimeMs > 0) {\n const age = Date.now() - statValue.mtimeMs;\n if (age > maxTimeMs) {\n try {\n await unlink(filePath);\n } catch {}\n return undefined;\n }\n }\n value = deserialized;\n }\n\n // hydrate memory cache as well\n cacheMap.set(id, value);\n return value;\n } catch {\n return undefined;\n }\n };\n\n const writeToDisk = async (value: unknown) => {\n try {\n await ensureDir(dirname(filePath));\n const envelope: CacheEnvelope = {\n version: configPackageJson.version,\n timestamp: Date.now(),\n data: value,\n };\n const payload = Buffer.from(serialize(envelope));\n\n const gz = shouldUseCompression(payload, compress)\n ? gzipSync(payload)\n : payload;\n\n // prepend a 1-byte header indicating compression\n const buf = Buffer.concat([\n Buffer.from([gz === payload ? 0x00 : 0x01]),\n gz,\n ]);\n\n await atomicWriteFile(filePath, buf);\n } catch {\n // swallow disk errors for cache writes\n }\n };\n\n return {\n /** In-memory first, then disk (if enabled), otherwise undefined. */\n get: async <T>(): Promise<T | undefined> => {\n const mem = cacheMap.get(id);\n\n if (mem !== undefined) return mem as T;\n\n if (persistent && buildCacheEnabled) {\n return (await readFromDisk()) as T | undefined;\n }\n return undefined;\n },\n /** Sets in-memory (always) and persists to disk if enabled. */\n set: async (value: unknown): Promise<void> => {\n cacheMap.set(id, value);\n\n if (persistent && buildCacheEnabled) {\n await writeToDisk(value);\n }\n },\n /** Clears only this entry from memory and disk. */\n clear: async (): Promise<void> => {\n cacheMap.delete(id);\n\n try {\n await unlink(filePath);\n } catch {}\n },\n /** Clears ALL cached entries (memory Map and entire cacheDir namespace if persistent). */\n clearAll: async (): Promise<void> => {\n clearAllCache();\n if (persistent && buildCacheEnabled) {\n // remove only the current namespace (if provided), else the root dir\n const base = namespace ? join(cacheDir, namespace) : cacheDir;\n\n try {\n await rm(base, { recursive: true, force: true });\n } catch {}\n\n try {\n await mkdir(base, { recursive: true });\n } catch {}\n }\n },\n /** Expose the computed id (useful if you want to key other structures). */\n isValid: async (): Promise<boolean> => {\n const cachedValue = cacheMap.get(id);\n if (cachedValue !== undefined) return true;\n\n // If persistence is disabled or build cache disabled, only memory can be valid\n if (!persistent || !buildCacheEnabled) return false;\n\n try {\n const statValue = await stat(filePath).catch(() => undefined);\n if (!statValue) return false;\n\n if (typeof ttlMs === 'number' && ttlMs > 0) {\n const age = Date.now() - statValue.mtimeMs;\n if (age > ttlMs) return false;\n }\n\n let raw = await readFile(filePath);\n const flag = raw[0];\n raw = raw.subarray(1);\n const payload = flag === 0x01 ? gunzipSync(raw) : raw;\n const deserialized = deserialize(payload) as unknown;\n\n const maybeObj = deserialized as Record<string, unknown> | null;\n const isEnvelope =\n !!maybeObj &&\n typeof maybeObj === 'object' &&\n typeof maybeObj.version === 'string' &&\n typeof maybeObj.timestamp === 'number' &&\n Object.hasOwn(maybeObj, 'data');\n\n if (isEnvelope) {\n const entry = maybeObj as CacheEnvelope;\n if (entry.version !== configPackageJson.version) return false;\n\n if (typeof maxTimeMs === 'number' && maxTimeMs > 0) {\n const age = Date.now() - entry.timestamp;\n if (age > maxTimeMs) return false;\n }\n return true;\n }\n\n if (typeof maxTimeMs === 'number' && maxTimeMs > 0) {\n const age = Date.now() - statValue.mtimeMs;\n if (age > maxTimeMs) return false;\n }\n return true;\n } catch {\n return false;\n }\n },\n /** Expose the computed id (useful if you want to key other structures). */\n id,\n /** Expose the absolute file path for debugging. */\n filePath,\n };\n};\n"],"mappings":";;;;;;;;;;;AA2CA,MAAM,WAA0D,EAC9D,UAAU,MACX;AAED,MAAM,YAAY,OAAO,QAAgB;AACvC,mCAAY,KAAK,EAAE,WAAW,MAAM,CAAC;;AAGvC,MAAM,kBAAkB,OAAO,MAAc,SAAiB;CAC5D,MAAM,MAAM,GAAG,KAAK,OAAO,QAAQ,IAAI,GAAG,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE;AAC7E,uCAAgB,KAAK,KAAK;AAC1B,oCAAa,KAAK,KAAK;;AAGzB,MAAM,wBAAwB,KAAa,UACzC,UAAU,QAAS,UAAU,SAAS,IAAI,aAAa;;AAGzD,MAAM,aAAa,UAAkB,IAAY,2BAC1C,UAAU,yBAAU,IAAI,GAAG,GAAG,GAAG;;AAIxC,MAAM,2BAAW,IAAI,KAAkB;AAEvC,MAAa,aACX,gBACA,MACA,YACG;CACH,MAAM,EAAE,aAAa,eAAe;CACpC,MAAM,oBAAoB,eAAe,MAAM,SAAS;CACxD,MAAM,aACJ,SAAS,eAAe,QACvB,OAAO,SAAS,eAAe,eAAe;CAEjD,MAAM,EAAE,UAAU,OAAO,WAAW,cAAc;EAChD,GAAG;EACH,GAAG;EACJ;CAGD,MAAM,KAAKA,uCAAa,KAAK;CAC7B,MAAM,WAAW,UAAU,UAAU,IAA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YAC9B,OAAO,OAAO,UAAU,OAAO,EAEjB;KACd,MAAM,QAAQ;AACd,SAAI,MAAM,YAAYA,qCAAkB,QAAS,QAAO;AAExD,SAAI,OAAO,cAAc,YAAY,YAAY,GAE/C;UADY,KAAK,KAAK,GAAG,MAAM,YACrB,UAAW,QAAO;;AAE9B,YAAO;;AAGT,QAAI,OAAO,cAAc,YAAY,YAAY,GAE/C;SADY,KAAK,KAAK,GAAG,UAAU,UACzB,UAAW,QAAO;;AAE9B,WAAO;WACD;AACN,WAAO;;;EAIX;EAEA;EACD"}
1
+ {"version":3,"file":"cacheDisk.cjs","names":["computeKeyId","configPackageJson"],"sources":["../../../src/utils/cacheDisk.ts"],"sourcesContent":["import {\n mkdir,\n readFile,\n rename,\n rm,\n stat,\n unlink,\n writeFile,\n} from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\nimport { deserialize, serialize } from 'node:v8';\nimport { gunzipSync, gzipSync } from 'node:zlib';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport configPackageJson from '@intlayer/types/package.json' with {\n type: 'json',\n};\nimport { type CacheKey, clearAllCache, computeKeyId } from './cacheMemory';\n\n/** ------------------------- Persistence layer ------------------------- **/\n\n/** Cache envelope structure stored on disk */\ntype CacheEnvelope = {\n /** Version of the config package (for cache invalidation) */\n version: string;\n /** Timestamp when the cache entry was created (in milliseconds) */\n timestamp: number;\n /** Data payload (the actual cached value) */\n data: unknown;\n};\n\ntype LocalCacheOptions = {\n /** Preferred new option name */\n persistent?: boolean;\n /** Time-to-live in ms; if expired, disk entry is ignored. */\n ttlMs?: number;\n /** Max age in ms based on stored creation timestamp; invalidates on exceed. */\n maxTimeMs?: number;\n /** Optional namespace to separate different logical caches. */\n namespace?: string;\n /** Gzip values on disk (on by default for blobs > 1KB). */\n compress?: boolean;\n};\n\nconst DEFAULTS: Required<Pick<LocalCacheOptions, 'compress'>> = {\n compress: true,\n};\n\nconst ensureDir = async (dir: string) => {\n await mkdir(dir, { recursive: true });\n};\n\nconst atomicWriteFile = async (file: string, data: Buffer) => {\n const tmp = `${file}.tmp-${process.pid}-${Math.random().toString(36).slice(2)}`;\n await writeFile(tmp, data);\n await rename(tmp, file);\n};\n\nconst shouldUseCompression = (buf: Buffer, force?: boolean) =>\n force === true || (force !== false && buf.byteLength > 1024);\n\n/** Derive on-disk path from config dir + namespace + key id. */\nconst cachePath = (cacheDir: string, id: string, ns?: string) =>\n join(cacheDir, ns ? join(ns, id) : id);\n\n/** ------------------------- Local cache facade ------------------------- **/\n\nconst cacheMap = new Map<string, any>();\n\nexport const cacheDisk = (\n intlayerConfig: IntlayerConfig,\n keys: CacheKey[],\n options?: LocalCacheOptions\n) => {\n const { cacheDir } = intlayerConfig.system;\n const buildCacheEnabled = intlayerConfig.build.cache ?? true;\n const persistent =\n options?.persistent === true ||\n (typeof options?.persistent === 'undefined' && buildCacheEnabled);\n\n const { compress, ttlMs, maxTimeMs, namespace } = {\n ...DEFAULTS,\n ...options,\n };\n\n // single stable id for this key tuple (works for both memory & disk)\n const id = computeKeyId(keys);\n const filePath = cachePath(cacheDir, id, namespace);\n\n const readFromDisk = async (): Promise<unknown | undefined> => {\n try {\n const statValue = await stat(filePath).catch(() => undefined);\n\n if (!statValue) return undefined;\n\n if (typeof ttlMs === 'number' && ttlMs > 0) {\n const age = Date.now() - statValue.mtimeMs;\n if (age > ttlMs) return undefined;\n }\n let raw = await readFile(filePath);\n // header: 1 byte flag (0x00 raw, 0x01 gzip)\n const flag = raw[0];\n\n raw = raw.subarray(1);\n\n const payload = flag === 0x01 ? gunzipSync(raw) : raw;\n const deserialized = deserialize(payload) as unknown;\n\n let value: unknown;\n const maybeObj = deserialized as Record<string, unknown> | null;\n const isEnvelope =\n !!maybeObj &&\n typeof maybeObj === 'object' &&\n typeof (maybeObj as any).version === 'string' &&\n typeof (maybeObj as any).timestamp === 'number' &&\n Object.hasOwn(maybeObj, 'data');\n\n if (isEnvelope) {\n const entry = maybeObj as CacheEnvelope;\n\n if (entry.version !== configPackageJson.version) {\n try {\n await unlink(filePath);\n } catch {}\n return undefined;\n }\n\n if (typeof maxTimeMs === 'number' && maxTimeMs > 0) {\n const age = Date.now() - entry.timestamp;\n if (age > maxTimeMs) {\n try {\n await unlink(filePath);\n } catch {}\n return undefined;\n }\n }\n\n value = entry.data;\n } else {\n // Backward compatibility: old entries had raw serialized value.\n if (typeof maxTimeMs === 'number' && maxTimeMs > 0) {\n const age = Date.now() - statValue.mtimeMs;\n if (age > maxTimeMs) {\n try {\n await unlink(filePath);\n } catch {}\n return undefined;\n }\n }\n value = deserialized;\n }\n\n // hydrate memory cache as well\n cacheMap.set(id, value);\n return value;\n } catch {\n return undefined;\n }\n };\n\n const writeToDisk = async (value: unknown) => {\n try {\n await ensureDir(dirname(filePath));\n const envelope: CacheEnvelope = {\n version: configPackageJson.version,\n timestamp: Date.now(),\n data: value,\n };\n const payload = Buffer.from(serialize(envelope));\n\n const gz = shouldUseCompression(payload, compress)\n ? gzipSync(payload)\n : payload;\n\n // prepend a 1-byte header indicating compression\n const buf = Buffer.concat([\n Buffer.from([gz === payload ? 0x00 : 0x01]),\n gz,\n ]);\n\n await atomicWriteFile(filePath, buf);\n } catch {\n // swallow disk errors for cache writes\n }\n };\n\n return {\n /** In-memory first, then disk (if enabled), otherwise undefined. */\n get: async <T>(): Promise<T | undefined> => {\n const mem = cacheMap.get(id);\n\n if (mem !== undefined) return mem as T;\n\n if (persistent && buildCacheEnabled) {\n return (await readFromDisk()) as T | undefined;\n }\n return undefined;\n },\n /** Sets in-memory (always) and persists to disk if enabled. */\n set: async (value: unknown): Promise<void> => {\n cacheMap.set(id, value);\n\n if (persistent && buildCacheEnabled) {\n await writeToDisk(value);\n }\n },\n /** Clears only this entry from memory and disk. */\n clear: async (): Promise<void> => {\n cacheMap.delete(id);\n\n try {\n await unlink(filePath);\n } catch {}\n },\n /** Clears ALL cached entries (memory Map and entire cacheDir namespace if persistent). */\n clearAll: async (): Promise<void> => {\n clearAllCache();\n if (persistent && buildCacheEnabled) {\n // remove only the current namespace (if provided), else the root dir\n const base = namespace ? join(cacheDir, namespace) : cacheDir;\n\n try {\n await rm(base, { recursive: true, force: true });\n } catch {}\n\n try {\n await mkdir(base, { recursive: true });\n } catch {}\n }\n },\n /** Expose the computed id (useful if you want to key other structures). */\n isValid: async (): Promise<boolean> => {\n const cachedValue = cacheMap.get(id);\n if (cachedValue !== undefined) return true;\n\n // If persistence is disabled or build cache disabled, only memory can be valid\n if (!persistent || !buildCacheEnabled) return false;\n\n try {\n const statValue = await stat(filePath).catch(() => undefined);\n if (!statValue) return false;\n\n if (typeof ttlMs === 'number' && ttlMs > 0) {\n const age = Date.now() - statValue.mtimeMs;\n if (age > ttlMs) return false;\n }\n\n let raw = await readFile(filePath);\n const flag = raw[0];\n raw = raw.subarray(1);\n const payload = flag === 0x01 ? gunzipSync(raw) : raw;\n const deserialized = deserialize(payload) as unknown;\n\n const maybeObj = deserialized as Record<string, unknown> | null;\n const isEnvelope =\n !!maybeObj &&\n typeof maybeObj === 'object' &&\n typeof maybeObj.version === 'string' &&\n typeof maybeObj.timestamp === 'number' &&\n Object.hasOwn(maybeObj, 'data');\n\n if (isEnvelope) {\n const entry = maybeObj as CacheEnvelope;\n if (entry.version !== configPackageJson.version) return false;\n\n if (typeof maxTimeMs === 'number' && maxTimeMs > 0) {\n const age = Date.now() - entry.timestamp;\n if (age > maxTimeMs) return false;\n }\n return true;\n }\n\n if (typeof maxTimeMs === 'number' && maxTimeMs > 0) {\n const age = Date.now() - statValue.mtimeMs;\n if (age > maxTimeMs) return false;\n }\n return true;\n } catch {\n return false;\n }\n },\n /** Expose the computed id (useful if you want to key other structures). */\n id,\n /** Expose the absolute file path for debugging. */\n filePath,\n };\n};\n"],"mappings":"yTA2CA,MAAM,EAA0D,CAC9D,SAAU,GACX,CAEK,EAAY,KAAO,IAAgB,CACvC,MAAA,EAAA,EAAA,OAAY,EAAK,CAAE,UAAW,GAAM,CAAC,EAGjC,EAAkB,MAAO,EAAc,IAAiB,C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