@powerlines/core 0.43.31 → 0.44.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 (67) hide show
  1. package/dist/constants/index.cjs +4 -0
  2. package/dist/constants/index.d.cts +2 -1
  3. package/dist/constants/index.d.mts +2 -1
  4. package/dist/constants/index.mjs +2 -1
  5. package/dist/constants/log-level.cjs +43 -0
  6. package/dist/constants/log-level.d.cts +40 -0
  7. package/dist/constants/log-level.d.cts.map +1 -0
  8. package/dist/constants/log-level.d.mts +40 -0
  9. package/dist/constants/log-level.d.mts.map +1 -0
  10. package/dist/constants/log-level.mjs +41 -0
  11. package/dist/constants/log-level.mjs.map +1 -0
  12. package/dist/index.cjs +6 -3
  13. package/dist/index.d.cts +5 -4
  14. package/dist/index.d.mts +5 -4
  15. package/dist/index.mjs +4 -3
  16. package/dist/lib/index.cjs +3 -3
  17. package/dist/lib/index.d.cts +2 -2
  18. package/dist/lib/index.d.mts +2 -2
  19. package/dist/lib/index.mjs +3 -3
  20. package/dist/lib/logger.cjs +29 -23
  21. package/dist/lib/logger.d.cts +11 -23
  22. package/dist/lib/logger.d.cts.map +1 -1
  23. package/dist/lib/logger.d.mts +11 -23
  24. package/dist/lib/logger.d.mts.map +1 -1
  25. package/dist/lib/logger.mjs +28 -22
  26. package/dist/lib/logger.mjs.map +1 -1
  27. package/dist/lib/unplugin/plugin.cjs +3 -3
  28. package/dist/lib/unplugin/plugin.mjs +4 -4
  29. package/dist/lib/unplugin/plugin.mjs.map +1 -1
  30. package/dist/lib/utilities/index.cjs +1 -1
  31. package/dist/lib/utilities/index.mjs +1 -1
  32. package/dist/lib/utilities/write-file.cjs +1 -2
  33. package/dist/lib/utilities/write-file.d.cts +1 -1
  34. package/dist/lib/utilities/write-file.d.cts.map +1 -1
  35. package/dist/lib/utilities/write-file.d.mts +1 -1
  36. package/dist/lib/utilities/write-file.d.mts.map +1 -1
  37. package/dist/lib/utilities/write-file.mjs +1 -2
  38. package/dist/lib/utilities/write-file.mjs.map +1 -1
  39. package/dist/plugin-utils/index.cjs +3 -2
  40. package/dist/plugin-utils/index.d.cts +2 -2
  41. package/dist/plugin-utils/index.d.mts +2 -2
  42. package/dist/plugin-utils/index.mjs +3 -3
  43. package/dist/plugin-utils/logging.cjs +54 -1
  44. package/dist/plugin-utils/logging.d.cts +11 -1
  45. package/dist/plugin-utils/logging.d.cts.map +1 -1
  46. package/dist/plugin-utils/logging.d.mts +11 -1
  47. package/dist/plugin-utils/logging.d.mts.map +1 -1
  48. package/dist/plugin-utils/logging.mjs +53 -1
  49. package/dist/plugin-utils/logging.mjs.map +1 -1
  50. package/dist/types/config.d.cts +25 -27
  51. package/dist/types/config.d.cts.map +1 -1
  52. package/dist/types/config.d.mts +25 -27
  53. package/dist/types/config.d.mts.map +1 -1
  54. package/dist/types/context.d.cts +21 -24
  55. package/dist/types/context.d.cts.map +1 -1
  56. package/dist/types/context.d.mts +21 -24
  57. package/dist/types/context.d.mts.map +1 -1
  58. package/dist/types/index.d.cts +3 -2
  59. package/dist/types/index.d.mts +3 -2
  60. package/dist/types/log.cjs +26 -0
  61. package/dist/types/log.d.cts +90 -0
  62. package/dist/types/log.d.cts.map +1 -0
  63. package/dist/types/log.d.mts +90 -0
  64. package/dist/types/log.d.mts.map +1 -0
  65. package/dist/types/log.mjs +25 -0
  66. package/dist/types/log.mjs.map +1 -0
  67. package/package.json +2 -2
@@ -1,24 +1,6 @@
1
- import { LogFn, WorkspaceConfig } from "../types/config.cjs";
2
- import { LogLevelLabel } from "@storm-software/config-tools/types";
1
+ import { LogFn, LogFnConfig } from "../types/log.cjs";
3
2
 
4
3
  //#region src/lib/logger.d.ts
5
- interface CreateLogOptions {
6
- source?: string;
7
- command?: string;
8
- environment?: string;
9
- plugin?: string;
10
- logLevel?: LogLevelLabel | null;
11
- customLogger?: LogFn;
12
- colors?: WorkspaceConfig["colors"];
13
- }
14
- /**
15
- * Create a logging function with a specific name and options.
16
- *
17
- * @param name - The name of the logging function.
18
- * @param options - The options to configure the logging function.
19
- * @returns A logging function.
20
- */
21
- declare const createLog: (name: string | null, options?: CreateLogOptions) => LogFn;
22
4
  /**
23
5
  * Generate a consistent color based on the input text.
24
6
  *
@@ -40,15 +22,21 @@ declare const colorText: (text: string) => string;
40
22
  * @return A hexadecimal color string.
41
23
  */
42
24
  declare const colorBackground: (text: string) => string;
25
+ /**
26
+ * Create a logging function with a specific name and options.
27
+ *
28
+ * @param config - The options to configure the logging function, including the source, command, environment, plugin, log level, custom logger, and colors. These options can be used to customize the appearance and behavior of the log messages generated by the logging function.
29
+ * @returns A logging function.
30
+ */
31
+ declare const createLogFn: (config: LogFnConfig) => LogFn;
43
32
  /**
44
33
  * Extend a logging function with a specific name, adding a colored badge to the log output.
45
34
  *
46
35
  * @param logFn - The original logging function to extend.
47
- * @param name - The name to use for the badge in the log output.
36
+ * @param config - The overlay metadata to use for the badge in the log output.
48
37
  * @returns A new logging function that includes the badge in its output.
49
38
  */
50
- declare const extendLog: (logFn: LogFn, name: string) => LogFn;
51
- declare type __ΩCreateLogOptions = any[];
39
+ declare const extendLogFn: (logFn: LogFn, config: LogFnConfig) => LogFn;
52
40
  //#endregion
53
- export { CreateLogOptions, __ΩCreateLogOptions, colorBackground, colorText, createLog, extendLog, getTextColor };
41
+ export { colorBackground, colorText, createLogFn, extendLogFn, getTextColor };
54
42
  //# sourceMappingURL=logger.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.cts","names":[],"sources":["../../src/lib/logger.ts"],"mappings":";;;;UA4BiB,gBAAA;EACf,MAAA;EACA,OAAA;EACA,WAAA;EACA,MAAA;EACA,QAAA,GAAW,aAAA;EACX,YAAA,GAAe,KAAA;EACf,MAAA,GAAS,eAAA;AAAA;;;;;;;;cAUE,SAAA,GACX,IAAA,iBACA,OAAA,GAAS,gBAAA,KACR,KAAA;;;;;;;cAyEU,YAAA,GAAgB,IAAA;;;;;;;cAiBhB,SAAA,GAAa,IAAA;;;AAjB1B;;;;cA6Ba,eAAA,GAAmB,IAAA;AAZhC;;;;;AAYA;;AAZA,cAyBa,SAAA,GAAa,KAAA,EAAO,KAAA,EAAO,IAAA,aAAe,KAAA;AAAA"}
1
+ {"version":3,"file":"logger.d.cts","names":[],"sources":["../../src/lib/logger.ts"],"mappings":";;;;;AA6DA;;;;cAAa,YAAA,GAAgB,IAAA;AAiB7B;;;;;AAYA;AAZA,cAAa,SAAA,GAAa,IAAA;;;;AAwB1B;;;cAZa,eAAA,GAAmB,IAAA;;;;;;AAgEhC;cApDa,WAAA,GAAe,MAAA,EAAQ,WAAA,KAAc,KAAA;;;;;;;;cAoDrC,WAAA,GAAe,KAAA,EAAO,KAAA,EAAO,MAAA,EAAQ,WAAA,KAAc,KAAA"}
@@ -1,24 +1,6 @@
1
- import { LogFn, WorkspaceConfig } from "../types/config.mjs";
2
- import { LogLevelLabel } from "@storm-software/config-tools/types";
1
+ import { LogFn, LogFnConfig } from "../types/log.mjs";
3
2
 
4
3
  //#region src/lib/logger.d.ts
5
- interface CreateLogOptions {
6
- source?: string;
7
- command?: string;
8
- environment?: string;
9
- plugin?: string;
10
- logLevel?: LogLevelLabel | null;
11
- customLogger?: LogFn;
12
- colors?: WorkspaceConfig["colors"];
13
- }
14
- /**
15
- * Create a logging function with a specific name and options.
16
- *
17
- * @param name - The name of the logging function.
18
- * @param options - The options to configure the logging function.
19
- * @returns A logging function.
20
- */
21
- declare const createLog: (name: string | null, options?: CreateLogOptions) => LogFn;
22
4
  /**
23
5
  * Generate a consistent color based on the input text.
24
6
  *
@@ -40,15 +22,21 @@ declare const colorText: (text: string) => string;
40
22
  * @return A hexadecimal color string.
41
23
  */
42
24
  declare const colorBackground: (text: string) => string;
25
+ /**
26
+ * Create a logging function with a specific name and options.
27
+ *
28
+ * @param config - The options to configure the logging function, including the source, command, environment, plugin, log level, custom logger, and colors. These options can be used to customize the appearance and behavior of the log messages generated by the logging function.
29
+ * @returns A logging function.
30
+ */
31
+ declare const createLogFn: (config: LogFnConfig) => LogFn;
43
32
  /**
44
33
  * Extend a logging function with a specific name, adding a colored badge to the log output.
45
34
  *
46
35
  * @param logFn - The original logging function to extend.
47
- * @param name - The name to use for the badge in the log output.
36
+ * @param config - The overlay metadata to use for the badge in the log output.
48
37
  * @returns A new logging function that includes the badge in its output.
49
38
  */
50
- declare const extendLog: (logFn: LogFn, name: string) => LogFn;
51
- declare type __ΩCreateLogOptions = any[];
39
+ declare const extendLogFn: (logFn: LogFn, config: LogFnConfig) => LogFn;
52
40
  //#endregion
53
- export { CreateLogOptions, __ΩCreateLogOptions, colorBackground, colorText, createLog, extendLog, getTextColor };
41
+ export { colorBackground, colorText, createLogFn, extendLogFn, getTextColor };
54
42
  //# sourceMappingURL=logger.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.mts","names":[],"sources":["../../src/lib/logger.ts"],"mappings":";;;;UA4BiB,gBAAA;EACf,MAAA;EACA,OAAA;EACA,WAAA;EACA,MAAA;EACA,QAAA,GAAW,aAAA;EACX,YAAA,GAAe,KAAA;EACf,MAAA,GAAS,eAAA;AAAA;;;;;;;;cAUE,SAAA,GACX,IAAA,iBACA,OAAA,GAAS,gBAAA,KACR,KAAA;;;;;;;cAyEU,YAAA,GAAgB,IAAA;;;;;;;cAiBhB,SAAA,GAAa,IAAA;;;AAjB1B;;;;cA6Ba,eAAA,GAAmB,IAAA;AAZhC;;;;;AAYA;;AAZA,cAyBa,SAAA,GAAa,KAAA,EAAO,KAAA,EAAO,IAAA,aAAe,KAAA;AAAA"}
1
+ {"version":3,"file":"logger.d.mts","names":[],"sources":["../../src/lib/logger.ts"],"mappings":";;;;;AA6DA;;;;cAAa,YAAA,GAAgB,IAAA;AAiB7B;;;;;AAYA;AAZA,cAAa,SAAA,GAAa,IAAA;;;;AAwB1B;;;cAZa,eAAA,GAAmB,IAAA;;;;;;AAgEhC;cApDa,WAAA,GAAe,MAAA,EAAQ,WAAA,KAAc,KAAA;;;;;;;;cAoDrC,WAAA,GAAe,KAAA,EAAO,KAAA,EAAO,MAAA,EAAQ,WAAA,KAAc,KAAA"}
@@ -1,6 +1,9 @@
1
1
  import { DEFAULT_ENVIRONMENT } from "../constants/environments.mjs";
2
+ import { resolveLogLevel } from "../plugin-utils/logging.mjs";
3
+ import "../plugin-utils/index.mjs";
4
+ import { isSetObject } from "@stryke/type-checks/is-set-object";
5
+ import { isSetString } from "@stryke/type-checks/is-set-string";
2
6
  import { getLogFn, getLogLevel } from "@storm-software/config-tools/logger";
3
- import { LogLevelLabel } from "@storm-software/config-tools/types";
4
7
  import { getColor } from "@storm-software/config-tools/utilities/colors";
5
8
  import { noop } from "@stryke/helpers/noop";
6
9
  import { kebabCase } from "@stryke/string-format/kebab-case";
@@ -8,23 +11,6 @@ import { titleCase } from "@stryke/string-format/title-case";
8
11
  import chalk from "chalk";
9
12
 
10
13
  //#region src/lib/logger.ts
11
- /**
12
- * Create a logging function with a specific name and options.
13
- *
14
- * @param name - The name of the logging function.
15
- * @param options - The options to configure the logging function.
16
- * @returns A logging function.
17
- */
18
- const createLog = (name, options = {}) => {
19
- const logLevel = options.logLevel === null ? LogLevelLabel.SILENT : options.logLevel || LogLevelLabel.INFO;
20
- if (logLevel === LogLevelLabel.SILENT) return noop;
21
- if (options.customLogger) return options.customLogger;
22
- const source = options.plugin || options.source;
23
- return (type, ...args) => getLogFn(getLogLevel(type), {
24
- ...options,
25
- logLevel
26
- })(`${name ? chalk.bold.hex(getColor("brand", options))(kebabCase(name)) : ""}${options.command ? chalk.hex(getColor("brand", options))(` (${options.command})`) : ""}${name ? chalk.grey(" > ") : ""}${source && (!name || kebabCase(source) !== kebabCase(name)) ? `${chalk.bold.hex(getColor("brand", options))(kebabCase(source))}${chalk.grey(" > ")}` : ""}${options.environment && options.environment !== "default" ? `${chalk.bold.hex(getColor("brand", options))(kebabCase(options.environment))}${chalk.grey(" > ")}` : ""}${args.join(" ")} `.trim());
27
- };
28
14
  const BADGE_COLORS = [
29
15
  "#00A0DD",
30
16
  "#6FCE4E",
@@ -79,16 +65,36 @@ const colorBackground = (text) => {
79
65
  return chalk.inverse.hex(getTextColor(title))(` ${title} `);
80
66
  };
81
67
  /**
68
+ * Create a logging function with a specific name and options.
69
+ *
70
+ * @param config - The options to configure the logging function, including the source, command, environment, plugin, log level, custom logger, and colors. These options can be used to customize the appearance and behavior of the log messages generated by the logging function.
71
+ * @returns A logging function.
72
+ */
73
+ const createLogFn = (config) => {
74
+ if (config.logLevel === "silent") return noop;
75
+ const logLevel = resolveLogLevel(config.logLevel || "info", config.mode);
76
+ return (meta, ...args) => getLogFn(getLogLevel(isSetString(meta) ? meta : meta.level), {
77
+ ...config,
78
+ logLevel: logLevel[isSetObject(meta) && isSetString(meta.category) ? meta.category : isSetString(meta) ? meta : "general"]
79
+ })(`${config.source ? chalk.bold.hex(getColor("brand", config))(kebabCase(config.source)) : ""}${config.command ? chalk.hex(getColor("brand", config))(` (${config.command})`) : ""}${config.source ? chalk.grey(" > ") : ""}${config.plugin && (!config.source || kebabCase(config.plugin) !== kebabCase(config.source)) ? `${chalk.bold.hex(getColor("brand", config))(kebabCase(config.plugin))}${chalk.grey(" > ")}` : ""}${config.environment && config.environment !== "default" ? `${chalk.bold.hex(getColor("brand", config))(kebabCase(config.environment))}${chalk.grey(" > ")}` : ""}${args.join(" ")} `.trim());
80
+ };
81
+ /**
82
82
  * Extend a logging function with a specific name, adding a colored badge to the log output.
83
83
  *
84
84
  * @param logFn - The original logging function to extend.
85
- * @param name - The name to use for the badge in the log output.
85
+ * @param config - The overlay metadata to use for the badge in the log output.
86
86
  * @returns A new logging function that includes the badge in its output.
87
87
  */
88
- const extendLog = (logFn, name) => {
89
- return (type, ...args) => logFn(type, `${colorBackground(name)} ${args.filter(Boolean).map((arg) => String(arg).trim()).join(" ")} `);
88
+ const extendLogFn = (logFn, config) => {
89
+ return (meta, ...args) => config.source || config.category ? logFn(isSetObject(meta) ? {
90
+ ...config,
91
+ ...meta
92
+ } : {
93
+ ...config,
94
+ level: meta
95
+ }, `${colorBackground(String(config.source || config.category))} ${args.filter(Boolean).map((arg) => String(arg).trim()).join(" ")} `) : logFn(meta, ...args);
90
96
  };
91
97
 
92
98
  //#endregion
93
- export { colorBackground, colorText, createLog, extendLog, getTextColor };
99
+ export { colorBackground, colorText, createLogFn, extendLogFn, getTextColor };
94
100
  //# sourceMappingURL=logger.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.mjs","names":[],"sources":["../../src/lib/logger.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { getLogFn, getLogLevel } from \"@storm-software/config-tools/logger\";\nimport { LogLevelLabel } from \"@storm-software/config-tools/types\";\nimport { getColor } from \"@storm-software/config-tools/utilities/colors\";\nimport { noop } from \"@stryke/helpers/noop\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport chalk from \"chalk\";\nimport { DEFAULT_ENVIRONMENT } from \"../constants/environments\";\nimport type { LogFn, WorkspaceConfig } from \"../types\";\n\nexport interface CreateLogOptions {\n source?: string;\n command?: string;\n environment?: string;\n plugin?: string;\n logLevel?: LogLevelLabel | null;\n customLogger?: LogFn;\n colors?: WorkspaceConfig[\"colors\"];\n}\n\n/**\n * Create a logging function with a specific name and options.\n *\n * @param name - The name of the logging function.\n * @param options - The options to configure the logging function.\n * @returns A logging function.\n */\nexport const createLog = (\n name: string | null,\n options: CreateLogOptions = {}\n): LogFn => {\n const logLevel =\n options.logLevel === null\n ? LogLevelLabel.SILENT\n : options.logLevel || LogLevelLabel.INFO;\n if (logLevel === LogLevelLabel.SILENT) {\n return noop;\n }\n\n if (options.customLogger) {\n return options.customLogger;\n }\n\n const source = options.plugin || options.source;\n\n return (type: LogLevelLabel, ...args: string[]) =>\n getLogFn(getLogLevel(type), {\n ...options,\n logLevel\n })(\n `${\n name ? chalk.bold.hex(getColor(\"brand\", options))(kebabCase(name)) : \"\"\n }${\n options.command\n ? chalk.hex(getColor(\"brand\", options))(` (${options.command})`)\n : \"\"\n }${name ? chalk.grey(\" > \") : \"\"}${\n source && (!name || kebabCase(source) !== kebabCase(name))\n ? `${chalk.bold.hex(getColor(\"brand\", options))(\n kebabCase(source)\n )}${chalk.grey(\" > \")}`\n : \"\"\n }${\n options.environment && options.environment !== DEFAULT_ENVIRONMENT\n ? `${chalk.bold.hex(getColor(\"brand\", options))(\n kebabCase(options.environment)\n )}${chalk.grey(\" > \")}`\n : \"\"\n }${args.join(\" \")} `.trim()\n );\n};\n\nconst BADGE_COLORS = [\n \"#00A0DD\",\n \"#6FCE4E\",\n \"#FBBF24\",\n \"#F43F5E\",\n \"#3B82F6\",\n \"#A855F7\",\n \"#469592\",\n \"#288EDF\",\n \"#D8B4FE\",\n \"#10B981\",\n \"#EF4444\",\n \"#F0EC56\",\n \"#F472B6\",\n \"#22D3EE\",\n \"#EAB308\",\n \"#84CC16\",\n \"#F87171\",\n \"#0EA5E9\",\n \"#D946EF\",\n \"#FACC15\",\n \"#34D399\",\n \"#8B5CF6\"\n] as const;\n\n/**\n * Generate a consistent color based on the input text.\n *\n * @param text - The input text to generate the color from.\n * @return A hexadecimal color string.\n */\nexport const getTextColor = (text: string): string => {\n return (\n BADGE_COLORS[\n text\n .split(\"\")\n .map(char => char.charCodeAt(0))\n .reduce((ret, charCode) => ret + charCode, 0) % BADGE_COLORS.length\n ] || BADGE_COLORS[0]\n );\n};\n\n/**\n * Generate a consistent color based on the input text.\n *\n * @param text - The input text to generate the color from.\n * @return A hexadecimal color string.\n */\nexport const colorText = (text: string): string => {\n const title = titleCase(text);\n\n return chalk.hex(getTextColor(title))(title);\n};\n\n/**\n * Generate a consistent color based on the input text.\n *\n * @param text - The input text to generate the color from.\n * @return A hexadecimal color string.\n */\nexport const colorBackground = (text: string): string => {\n const title = titleCase(text);\n\n return chalk.inverse.hex(getTextColor(title))(` ${title} `);\n};\n\n/**\n * Extend a logging function with a specific name, adding a colored badge to the log output.\n *\n * @param logFn - The original logging function to extend.\n * @param name - The name to use for the badge in the log output.\n * @returns A new logging function that includes the badge in its output.\n */\nexport const extendLog = (logFn: LogFn, name: string): LogFn => {\n return (type: LogLevelLabel, ...args: string[]) =>\n logFn(\n type,\n `${colorBackground(name)} ${args\n .filter(Boolean)\n .map(arg => String(arg).trim())\n .join(\" \")} `\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AA6CA,MAAa,aACX,MACA,UAA4B,EAAE,KACpB;CACV,MAAM,WACJ,QAAQ,aAAa,OACjB,cAAc,SACd,QAAQ,YAAY,cAAc;AACxC,KAAI,aAAa,cAAc,OAC7B,QAAO;AAGT,KAAI,QAAQ,aACV,QAAO,QAAQ;CAGjB,MAAM,SAAS,QAAQ,UAAU,QAAQ;AAEzC,SAAQ,MAAqB,GAAG,SAC9B,SAAS,YAAY,KAAK,EAAE;EAC1B,GAAG;EACH;EACD,CAAC,CACA,GACE,OAAO,MAAM,KAAK,IAAI,SAAS,SAAS,QAAQ,CAAC,CAAC,UAAU,KAAK,CAAC,GAAG,KAErE,QAAQ,UACJ,MAAM,IAAI,SAAS,SAAS,QAAQ,CAAC,CAAC,KAAK,QAAQ,QAAQ,GAAG,GAC9D,KACH,OAAO,MAAM,KAAK,MAAM,GAAG,KAC5B,WAAW,CAAC,QAAQ,UAAU,OAAO,KAAK,UAAU,KAAK,IACrD,GAAG,MAAM,KAAK,IAAI,SAAS,SAAS,QAAQ,CAAC,CAC3C,UAAU,OAAO,CAClB,GAAG,MAAM,KAAK,MAAM,KACrB,KAEJ,QAAQ,eAAe,QAAQ,4BAC3B,GAAG,MAAM,KAAK,IAAI,SAAS,SAAS,QAAQ,CAAC,CAC3C,UAAU,QAAQ,YAAY,CAC/B,GAAG,MAAM,KAAK,MAAM,KACrB,KACH,KAAK,KAAK,IAAI,CAAC,GAAG,MAAM,CAC5B;;AAGL,MAAM,eAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;AAQD,MAAa,gBAAgB,SAAyB;AACpD,QACE,aACE,KACG,MAAM,GAAG,CACT,KAAI,SAAQ,KAAK,WAAW,EAAE,CAAC,CAC/B,QAAQ,KAAK,aAAa,MAAM,UAAU,EAAE,GAAG,aAAa,WAC5D,aAAa;;;;;;;;AAUtB,MAAa,aAAa,SAAyB;CACjD,MAAM,QAAQ,UAAU,KAAK;AAE7B,QAAO,MAAM,IAAI,aAAa,MAAM,CAAC,CAAC,MAAM;;;;;;;;AAS9C,MAAa,mBAAmB,SAAyB;CACvD,MAAM,QAAQ,UAAU,KAAK;AAE7B,QAAO,MAAM,QAAQ,IAAI,aAAa,MAAM,CAAC,CAAC,IAAI,MAAM,GAAG;;;;;;;;;AAU7D,MAAa,aAAa,OAAc,SAAwB;AAC9D,SAAQ,MAAqB,GAAG,SAC9B,MACE,MACA,GAAG,gBAAgB,KAAK,CAAC,GAAG,KACzB,OAAO,QAAQ,CACf,KAAI,QAAO,OAAO,IAAI,CAAC,MAAM,CAAC,CAC9B,KAAK,IAAI,CAAC,GACd"}
1
+ {"version":3,"file":"logger.mjs","names":[],"sources":["../../src/lib/logger.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { getLogFn, getLogLevel } from \"@storm-software/config-tools/logger\";\nimport { getColor } from \"@storm-software/config-tools/utilities/colors\";\nimport { noop } from \"@stryke/helpers/noop\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport chalk from \"chalk\";\nimport { DEFAULT_ENVIRONMENT } from \"../constants/environments\";\nimport { resolveLogLevel } from \"../plugin-utils\";\nimport type { LogFn, LogFnConfig } from \"../types/log\";\n\nconst BADGE_COLORS = [\n \"#00A0DD\",\n \"#6FCE4E\",\n \"#FBBF24\",\n \"#F43F5E\",\n \"#3B82F6\",\n \"#A855F7\",\n \"#469592\",\n \"#288EDF\",\n \"#D8B4FE\",\n \"#10B981\",\n \"#EF4444\",\n \"#F0EC56\",\n \"#F472B6\",\n \"#22D3EE\",\n \"#EAB308\",\n \"#84CC16\",\n \"#F87171\",\n \"#0EA5E9\",\n \"#D946EF\",\n \"#FACC15\",\n \"#34D399\",\n \"#8B5CF6\"\n] as const;\n\n/**\n * Generate a consistent color based on the input text.\n *\n * @param text - The input text to generate the color from.\n * @return A hexadecimal color string.\n */\nexport const getTextColor = (text: string): string => {\n return (\n BADGE_COLORS[\n text\n .split(\"\")\n .map(char => char.charCodeAt(0))\n .reduce((ret, charCode) => ret + charCode, 0) % BADGE_COLORS.length\n ] || BADGE_COLORS[0]\n );\n};\n\n/**\n * Generate a consistent color based on the input text.\n *\n * @param text - The input text to generate the color from.\n * @return A hexadecimal color string.\n */\nexport const colorText = (text: string): string => {\n const title = titleCase(text);\n\n return chalk.hex(getTextColor(title))(title);\n};\n\n/**\n * Generate a consistent color based on the input text.\n *\n * @param text - The input text to generate the color from.\n * @return A hexadecimal color string.\n */\nexport const colorBackground = (text: string): string => {\n const title = titleCase(text);\n\n return chalk.inverse.hex(getTextColor(title))(` ${title} `);\n};\n\n/**\n * Create a logging function with a specific name and options.\n *\n * @param config - The options to configure the logging function, including the source, command, environment, plugin, log level, custom logger, and colors. These options can be used to customize the appearance and behavior of the log messages generated by the logging function.\n * @returns A logging function.\n */\nexport const createLogFn = (config: LogFnConfig): LogFn => {\n if (config.logLevel === \"silent\") {\n return noop;\n }\n\n const logLevel = resolveLogLevel(config.logLevel || \"info\", config.mode);\n\n return (meta, ...args) =>\n getLogFn(getLogLevel(isSetString(meta) ? meta : meta.level), {\n ...config,\n logLevel:\n logLevel[\n (isSetObject(meta) && isSetString(meta.category)\n ? meta.category\n : isSetString(meta)\n ? meta\n : \"general\") as keyof typeof logLevel\n ]\n })(\n `${\n config.source\n ? chalk.bold.hex(getColor(\"brand\", config))(kebabCase(config.source))\n : \"\"\n }${\n config.command\n ? chalk.hex(getColor(\"brand\", config))(` (${config.command})`)\n : \"\"\n }${config.source ? chalk.grey(\" > \") : \"\"}${\n config.plugin &&\n (!config.source ||\n kebabCase(config.plugin) !== kebabCase(config.source))\n ? `${chalk.bold.hex(getColor(\"brand\", config))(\n kebabCase(config.plugin)\n )}${chalk.grey(\" > \")}`\n : \"\"\n }${\n config.environment && config.environment !== DEFAULT_ENVIRONMENT\n ? `${chalk.bold.hex(getColor(\"brand\", config))(\n kebabCase(config.environment)\n )}${chalk.grey(\" > \")}`\n : \"\"\n }${args.join(\" \")} `.trim()\n );\n};\n\n/**\n * Extend a logging function with a specific name, adding a colored badge to the log output.\n *\n * @param logFn - The original logging function to extend.\n * @param config - The overlay metadata to use for the badge in the log output.\n * @returns A new logging function that includes the badge in its output.\n */\nexport const extendLogFn = (logFn: LogFn, config: LogFnConfig): LogFn => {\n return (meta, ...args) =>\n config.source || config.category\n ? logFn(\n isSetObject(meta)\n ? { ...config, ...meta }\n : { ...config, level: meta },\n `${colorBackground(String(config.source || config.category))} ${args\n .filter(Boolean)\n .map(arg => String(arg).trim())\n .join(\" \")} `\n )\n : logFn(meta, ...args);\n};\n"],"mappings":";;;;;;;;;;;;;AA8BA,MAAM,eAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;AAQD,MAAa,gBAAgB,SAAyB;AACpD,QACE,aACE,KACG,MAAM,GAAG,CACT,KAAI,SAAQ,KAAK,WAAW,EAAE,CAAC,CAC/B,QAAQ,KAAK,aAAa,MAAM,UAAU,EAAE,GAAG,aAAa,WAC5D,aAAa;;;;;;;;AAUtB,MAAa,aAAa,SAAyB;CACjD,MAAM,QAAQ,UAAU,KAAK;AAE7B,QAAO,MAAM,IAAI,aAAa,MAAM,CAAC,CAAC,MAAM;;;;;;;;AAS9C,MAAa,mBAAmB,SAAyB;CACvD,MAAM,QAAQ,UAAU,KAAK;AAE7B,QAAO,MAAM,QAAQ,IAAI,aAAa,MAAM,CAAC,CAAC,IAAI,MAAM,GAAG;;;;;;;;AAS7D,MAAa,eAAe,WAA+B;AACzD,KAAI,OAAO,aAAa,SACtB,QAAO;CAGT,MAAM,WAAW,gBAAgB,OAAO,YAAY,QAAQ,OAAO,KAAK;AAExE,SAAQ,MAAM,GAAG,SACf,SAAS,YAAY,YAAY,KAAK,GAAG,OAAO,KAAK,MAAM,EAAE;EAC3D,GAAG;EACH,UACE,SACG,YAAY,KAAK,IAAI,YAAY,KAAK,SAAS,GAC5C,KAAK,WACL,YAAY,KAAK,GACf,OACA;EAEX,CAAC,CACA,GACE,OAAO,SACH,MAAM,KAAK,IAAI,SAAS,SAAS,OAAO,CAAC,CAAC,UAAU,OAAO,OAAO,CAAC,GACnE,KAEJ,OAAO,UACH,MAAM,IAAI,SAAS,SAAS,OAAO,CAAC,CAAC,KAAK,OAAO,QAAQ,GAAG,GAC5D,KACH,OAAO,SAAS,MAAM,KAAK,MAAM,GAAG,KACrC,OAAO,WACN,CAAC,OAAO,UACP,UAAU,OAAO,OAAO,KAAK,UAAU,OAAO,OAAO,IACnD,GAAG,MAAM,KAAK,IAAI,SAAS,SAAS,OAAO,CAAC,CAC1C,UAAU,OAAO,OAAO,CACzB,GAAG,MAAM,KAAK,MAAM,KACrB,KAEJ,OAAO,eAAe,OAAO,4BACzB,GAAG,MAAM,KAAK,IAAI,SAAS,SAAS,OAAO,CAAC,CAC1C,UAAU,OAAO,YAAY,CAC9B,GAAG,MAAM,KAAK,MAAM,KACrB,KACH,KAAK,KAAK,IAAI,CAAC,GAAG,MAAM,CAC5B;;;;;;;;;AAUL,MAAa,eAAe,OAAc,WAA+B;AACvE,SAAQ,MAAM,GAAG,SACf,OAAO,UAAU,OAAO,WACpB,MACE,YAAY,KAAK,GACb;EAAE,GAAG;EAAQ,GAAG;EAAM,GACtB;EAAE,GAAG;EAAQ,OAAO;EAAM,EAC9B,GAAG,gBAAgB,OAAO,OAAO,UAAU,OAAO,SAAS,CAAC,CAAC,GAAG,KAC7D,OAAO,QAAQ,CACf,KAAI,QAAO,OAAO,IAAI,CAAC,MAAM,CAAC,CAC9B,KAAK,IAAI,CAAC,GACd,GACD,MAAM,MAAM,GAAG,KAAK"}
@@ -5,9 +5,9 @@ const require_lib_unplugin_helpers = require('./helpers.cjs');
5
5
  const require_virtual_modules = require('../../constants/virtual-modules.cjs');
6
6
  const require_lib_unplugin_module_resolution = require('./module-resolution.cjs');
7
7
  const require_lib_utilities_source_file = require('../utilities/source-file.cjs');
8
- let _storm_software_config_tools_types = require("@storm-software/config-tools/types");
9
8
  let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
10
9
  let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
10
+ let _storm_software_config_tools_types = require("@storm-software/config-tools/types");
11
11
  let unplugin = require("unplugin");
12
12
 
13
13
  //#region src/lib/unplugin/plugin.ts
@@ -22,7 +22,7 @@ function createUnpluginResolver(context, options = {}) {
22
22
  (0, unplugin.setParseImpl)(ctx.parse);
23
23
  const name = options.name || "powerlines";
24
24
  return () => {
25
- const log = require_lib_logger.extendLog(ctx.log, name);
25
+ const log = require_lib_logger.extendLogFn(ctx.log, name);
26
26
  log(_storm_software_config_tools_types.LogLevelLabel.DEBUG, `Initializing ${(0, _stryke_string_format_title_case.titleCase)(name)} plugin`);
27
27
  try {
28
28
  const { resolveId, load } = require_lib_unplugin_module_resolution.createUnpluginModuleResolutionFunctions(context, options);
@@ -49,7 +49,7 @@ function createUnplugin(context, options = {}) {
49
49
  (0, unplugin.setParseImpl)(ctx.parse);
50
50
  const name = options.name || "powerlines";
51
51
  return () => {
52
- const log = options.name ? require_lib_logger.extendLog(ctx.log, name) : ctx.log;
52
+ const log = options.name ? require_lib_logger.extendLogFn(ctx.log, name) : ctx.log;
53
53
  log(_storm_software_config_tools_types.LogLevelLabel.DEBUG, `Initializing ${(0, _stryke_string_format_title_case.titleCase)(name)} plugin`);
54
54
  try {
55
55
  const { resolveId, load } = require_lib_unplugin_module_resolution.createUnpluginModuleResolutionFunctions(context, options);
@@ -1,11 +1,11 @@
1
- import { extendLog } from "../logger.mjs";
1
+ import { extendLogFn } from "../logger.mjs";
2
2
  import { combineContexts } from "./helpers.mjs";
3
3
  import { VIRTUAL_MODULE_PREFIX_REGEX } from "../../constants/virtual-modules.mjs";
4
4
  import { createUnpluginModuleResolutionFunctions } from "./module-resolution.mjs";
5
5
  import { getString } from "../utilities/source-file.mjs";
6
- import { LogLevelLabel } from "@storm-software/config-tools/types";
7
6
  import { kebabCase } from "@stryke/string-format/kebab-case";
8
7
  import { titleCase } from "@stryke/string-format/title-case";
8
+ import { LogLevelLabel } from "@storm-software/config-tools/types";
9
9
  import { setParseImpl } from "unplugin";
10
10
 
11
11
  //#region src/lib/unplugin/plugin.ts
@@ -20,7 +20,7 @@ function createUnpluginResolver(context, options = {}) {
20
20
  setParseImpl(ctx.parse);
21
21
  const name = options.name || "powerlines";
22
22
  return () => {
23
- const log = extendLog(ctx.log, name);
23
+ const log = extendLogFn(ctx.log, name);
24
24
  log(LogLevelLabel.DEBUG, `Initializing ${titleCase(name)} plugin`);
25
25
  try {
26
26
  const { resolveId, load } = createUnpluginModuleResolutionFunctions(context, options);
@@ -47,7 +47,7 @@ function createUnplugin(context, options = {}) {
47
47
  setParseImpl(ctx.parse);
48
48
  const name = options.name || "powerlines";
49
49
  return () => {
50
- const log = options.name ? extendLog(ctx.log, name) : ctx.log;
50
+ const log = options.name ? extendLogFn(ctx.log, name) : ctx.log;
51
51
  log(LogLevelLabel.DEBUG, `Initializing ${titleCase(name)} plugin`);
52
52
  try {
53
53
  const { resolveId, load } = createUnpluginModuleResolutionFunctions(context, options);
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.mjs","names":[],"sources":["../../../src/lib/unplugin/plugin.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { Unstable_PluginContext } from \"@powerlines/core/types/_internal\";\nimport { LogLevelLabel } from \"@storm-software/config-tools/types\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport type {\n TransformResult,\n UnpluginBuildContext,\n UnpluginContext\n} from \"unplugin\";\nimport { setParseImpl } from \"unplugin\";\nimport { VIRTUAL_MODULE_PREFIX_REGEX } from \"../../constants/virtual-modules\";\nimport { PluginContext } from \"../../types/context\";\nimport { UnpluginFactory } from \"../../types/unplugin\";\nimport { extendLog } from \"../logger\";\nimport { getString } from \"../utilities/source-file\";\nimport { combineContexts } from \"./helpers\";\nimport {\n createUnpluginModuleResolutionFunctions,\n CreateUnpluginModuleResolutionFunctionsOptions\n} from \"./module-resolution\";\n\nexport interface CreateUnpluginResolverOptions extends CreateUnpluginModuleResolutionFunctionsOptions {\n /**\n * A name to use for the unplugin instance. This is used for logging and to generate the plugin name. It does not affect the functionality of the plugin.\n *\n * @remarks\n * If not provided, the plugin will be named \"powerlines\". If provided, the plugin will be named `${name} - Powerlines` (e.g., \"MyPlugin - Powerlines\").\n *\n * @defaultValue \"powerlines\"\n */\n name?: string;\n}\n\n/**\n * Creates a Powerlines unplugin instance.\n *\n * @param context - The plugin context.\n * @returns The unplugin instance.\n */\nexport function createUnpluginResolver<\n TContext extends PluginContext = PluginContext\n>(\n context: TContext,\n options: CreateUnpluginResolverOptions = {}\n): UnpluginFactory<TContext> {\n const ctx = context as unknown as Unstable_PluginContext;\n setParseImpl(ctx.parse);\n\n const name = options.name || \"powerlines\";\n\n return () => {\n const log = extendLog(ctx.log, name);\n log(LogLevelLabel.DEBUG, `Initializing ${titleCase(name)} plugin`);\n\n try {\n const { resolveId, load } =\n createUnpluginModuleResolutionFunctions<TContext>(context, options);\n\n return {\n name:\n name.toLowerCase() === \"powerlines\"\n ? \"powerlines\"\n : `powerlines:${kebabCase(name)}`,\n api: ctx.$$internal.api,\n resolveId,\n load\n };\n } catch (error) {\n log(LogLevelLabel.FATAL, (error as Error)?.message);\n\n throw error;\n }\n };\n}\n\nexport interface CreateUnpluginOptions extends CreateUnpluginResolverOptions {\n /**\n * Whether to silence logging for the plugin hooks. This can be useful for plugins that run frequently or have hooks that are called often, to reduce noise in the logs. When set to `true`, the plugin will not log any messages for its hooks. When set to `false` (the default), the plugin will log messages for its hooks as normal.\n *\n * @defaultValue false\n */\n silenceHookLogging?: boolean;\n}\n\n/**\n * Creates a Powerlines unplugin instance.\n *\n * @param context - The plugin context.\n * @returns The unplugin instance.\n */\nexport function createUnplugin<TContext extends PluginContext = PluginContext>(\n context: TContext,\n options: CreateUnpluginOptions = {}\n): UnpluginFactory<TContext> {\n const ctx = context as unknown as Unstable_PluginContext;\n setParseImpl(ctx.parse);\n\n const name = options.name || \"powerlines\";\n\n return () => {\n const log = options.name ? extendLog(ctx.log, name) : ctx.log;\n log(LogLevelLabel.DEBUG, `Initializing ${titleCase(name)} plugin`);\n\n try {\n const { resolveId, load } =\n createUnpluginModuleResolutionFunctions<TContext>(context, options);\n\n async function buildStart(this: UnpluginBuildContext) {\n if (!options.silenceHookLogging) {\n log(LogLevelLabel.DEBUG, \"Powerlines build plugin starting...\");\n }\n\n await ctx.$$internal.callHook(\"buildStart\", {\n sequential: true\n });\n }\n\n async function transform(\n this: UnpluginBuildContext & UnpluginContext,\n code: string,\n id: string\n ): Promise<TransformResult | null | undefined> {\n let transformed: TransformResult | string = code;\n\n for (const hook of ctx.$$internal.environment.selectHooks(\n \"transform\"\n )) {\n const result: TransformResult | string | undefined =\n await hook.handler.apply(combineContexts(ctx, this), [\n getString(transformed),\n id.replace(VIRTUAL_MODULE_PREFIX_REGEX, \"\")\n ]);\n if (result) {\n transformed = result;\n }\n }\n\n return transformed;\n }\n\n async function buildEnd(this: UnpluginBuildContext): Promise<void> {\n if (!options.silenceHookLogging) {\n log(LogLevelLabel.DEBUG, \"Powerlines build plugin finishing...\");\n }\n\n return ctx.$$internal.callHook(\"buildEnd\", {\n sequential: true\n });\n }\n\n async function writeBundle(): Promise<void> {\n if (!options.silenceHookLogging) {\n log(LogLevelLabel.DEBUG, \"Finalizing Powerlines project output...\");\n }\n\n return ctx.$$internal.callHook(\"writeBundle\", {\n sequential: true\n });\n }\n\n return {\n name:\n name.toLowerCase() === \"powerlines\"\n ? \"powerlines\"\n : `powerlines:${kebabCase(name)}`,\n api: ctx.$$internal.api,\n resolveId,\n load,\n transform,\n buildStart,\n buildEnd,\n writeBundle,\n vite: {\n sharedDuringBuild: true\n }\n };\n } catch (error) {\n log(LogLevelLabel.FATAL, (error as Error)?.message);\n\n throw error;\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyDA,SAAgB,uBAGd,SACA,UAAyC,EAAE,EAChB;CAC3B,MAAM,MAAM;AACZ,cAAa,IAAI,MAAM;CAEvB,MAAM,OAAO,QAAQ,QAAQ;AAE7B,cAAa;EACX,MAAM,MAAM,UAAU,IAAI,KAAK,KAAK;AACpC,MAAI,cAAc,OAAO,gBAAgB,UAAU,KAAK,CAAC,SAAS;AAElE,MAAI;GACF,MAAM,EAAE,WAAW,SACjB,wCAAkD,SAAS,QAAQ;AAErE,UAAO;IACL,MACE,KAAK,aAAa,KAAK,eACnB,eACA,cAAc,UAAU,KAAK;IACnC,KAAK,IAAI,WAAW;IACpB;IACA;IACD;WACM,OAAO;AACd,OAAI,cAAc,OAAQ,OAAiB,QAAQ;AAEnD,SAAM;;;;;;;;;;AAoBZ,SAAgB,eACd,SACA,UAAiC,EAAE,EACR;CAC3B,MAAM,MAAM;AACZ,cAAa,IAAI,MAAM;CAEvB,MAAM,OAAO,QAAQ,QAAQ;AAE7B,cAAa;EACX,MAAM,MAAM,QAAQ,OAAO,UAAU,IAAI,KAAK,KAAK,GAAG,IAAI;AAC1D,MAAI,cAAc,OAAO,gBAAgB,UAAU,KAAK,CAAC,SAAS;AAElE,MAAI;GACF,MAAM,EAAE,WAAW,SACjB,wCAAkD,SAAS,QAAQ;GAErE,eAAe,aAAuC;AACpD,QAAI,CAAC,QAAQ,mBACX,KAAI,cAAc,OAAO,sCAAsC;AAGjE,UAAM,IAAI,WAAW,SAAS,cAAc,EAC1C,YAAY,MACb,CAAC;;GAGJ,eAAe,UAEb,MACA,IAC6C;IAC7C,IAAI,cAAwC;AAE5C,SAAK,MAAM,QAAQ,IAAI,WAAW,YAAY,YAC5C,YACD,EAAE;KACD,MAAM,SACJ,MAAM,KAAK,QAAQ,MAAM,gBAAgB,KAAK,KAAK,EAAE,CACnD,UAAU,YAAY,EACtB,GAAG,QAAQ,6BAA6B,GAAG,CAC5C,CAAC;AACJ,SAAI,OACF,eAAc;;AAIlB,WAAO;;GAGT,eAAe,WAAoD;AACjE,QAAI,CAAC,QAAQ,mBACX,KAAI,cAAc,OAAO,uCAAuC;AAGlE,WAAO,IAAI,WAAW,SAAS,YAAY,EACzC,YAAY,MACb,CAAC;;GAGJ,eAAe,cAA6B;AAC1C,QAAI,CAAC,QAAQ,mBACX,KAAI,cAAc,OAAO,0CAA0C;AAGrE,WAAO,IAAI,WAAW,SAAS,eAAe,EAC5C,YAAY,MACb,CAAC;;AAGJ,UAAO;IACL,MACE,KAAK,aAAa,KAAK,eACnB,eACA,cAAc,UAAU,KAAK;IACnC,KAAK,IAAI,WAAW;IACpB;IACA;IACA;IACA;IACA;IACA;IACA,MAAM,EACJ,mBAAmB,MACpB;IACF;WACM,OAAO;AACd,OAAI,cAAc,OAAQ,OAAiB,QAAQ;AAEnD,SAAM"}
1
+ {"version":3,"file":"plugin.mjs","names":[],"sources":["../../../src/lib/unplugin/plugin.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { Unstable_PluginContext } from \"@powerlines/core/types/_internal\";\nimport { LogLevelLabel } from \"@storm-software/config-tools/types\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport type {\n TransformResult,\n UnpluginBuildContext,\n UnpluginContext\n} from \"unplugin\";\nimport { setParseImpl } from \"unplugin\";\nimport { VIRTUAL_MODULE_PREFIX_REGEX } from \"../../constants/virtual-modules\";\nimport { PluginContext } from \"../../types/context\";\nimport { UnpluginFactory } from \"../../types/unplugin\";\nimport { extendLogFn } from \"../logger\";\nimport { getString } from \"../utilities/source-file\";\nimport { combineContexts } from \"./helpers\";\nimport {\n createUnpluginModuleResolutionFunctions,\n CreateUnpluginModuleResolutionFunctionsOptions\n} from \"./module-resolution\";\n\nexport interface CreateUnpluginResolverOptions extends CreateUnpluginModuleResolutionFunctionsOptions {\n /**\n * A name to use for the unplugin instance. This is used for logging and to generate the plugin name. It does not affect the functionality of the plugin.\n *\n * @remarks\n * If not provided, the plugin will be named \"powerlines\". If provided, the plugin will be named `${name} - Powerlines` (e.g., \"MyPlugin - Powerlines\").\n *\n * @defaultValue \"powerlines\"\n */\n name?: string;\n}\n\n/**\n * Creates a Powerlines unplugin instance.\n *\n * @param context - The plugin context.\n * @returns The unplugin instance.\n */\nexport function createUnpluginResolver<\n TContext extends PluginContext = PluginContext\n>(\n context: TContext,\n options: CreateUnpluginResolverOptions = {}\n): UnpluginFactory<TContext> {\n const ctx = context as unknown as Unstable_PluginContext;\n setParseImpl(ctx.parse);\n\n const name = options.name || \"powerlines\";\n\n return () => {\n const log = extendLogFn(ctx.log, name);\n log(LogLevelLabel.DEBUG, `Initializing ${titleCase(name)} plugin`);\n\n try {\n const { resolveId, load } =\n createUnpluginModuleResolutionFunctions<TContext>(context, options);\n\n return {\n name:\n name.toLowerCase() === \"powerlines\"\n ? \"powerlines\"\n : `powerlines:${kebabCase(name)}`,\n api: ctx.$$internal.api,\n resolveId,\n load\n };\n } catch (error) {\n log(LogLevelLabel.FATAL, (error as Error)?.message);\n\n throw error;\n }\n };\n}\n\nexport interface CreateUnpluginOptions extends CreateUnpluginResolverOptions {\n /**\n * Whether to silence logging for the plugin hooks. This can be useful for plugins that run frequently or have hooks that are called often, to reduce noise in the logs. When set to `true`, the plugin will not log any messages for its hooks. When set to `false` (the default), the plugin will log messages for its hooks as normal.\n *\n * @defaultValue false\n */\n silenceHookLogging?: boolean;\n}\n\n/**\n * Creates a Powerlines unplugin instance.\n *\n * @param context - The plugin context.\n * @returns The unplugin instance.\n */\nexport function createUnplugin<TContext extends PluginContext = PluginContext>(\n context: TContext,\n options: CreateUnpluginOptions = {}\n): UnpluginFactory<TContext> {\n const ctx = context as unknown as Unstable_PluginContext;\n setParseImpl(ctx.parse);\n\n const name = options.name || \"powerlines\";\n\n return () => {\n const log = options.name ? extendLogFn(ctx.log, name) : ctx.log;\n log(LogLevelLabel.DEBUG, `Initializing ${titleCase(name)} plugin`);\n\n try {\n const { resolveId, load } =\n createUnpluginModuleResolutionFunctions<TContext>(context, options);\n\n async function buildStart(this: UnpluginBuildContext) {\n if (!options.silenceHookLogging) {\n log(LogLevelLabel.DEBUG, \"Powerlines build plugin starting...\");\n }\n\n await ctx.$$internal.callHook(\"buildStart\", {\n sequential: true\n });\n }\n\n async function transform(\n this: UnpluginBuildContext & UnpluginContext,\n code: string,\n id: string\n ): Promise<TransformResult | null | undefined> {\n let transformed: TransformResult | string = code;\n\n for (const hook of ctx.$$internal.environment.selectHooks(\n \"transform\"\n )) {\n const result: TransformResult | string | undefined =\n await hook.handler.apply(combineContexts(ctx, this), [\n getString(transformed),\n id.replace(VIRTUAL_MODULE_PREFIX_REGEX, \"\")\n ]);\n if (result) {\n transformed = result;\n }\n }\n\n return transformed;\n }\n\n async function buildEnd(this: UnpluginBuildContext): Promise<void> {\n if (!options.silenceHookLogging) {\n log(LogLevelLabel.DEBUG, \"Powerlines build plugin finishing...\");\n }\n\n return ctx.$$internal.callHook(\"buildEnd\", {\n sequential: true\n });\n }\n\n async function writeBundle(): Promise<void> {\n if (!options.silenceHookLogging) {\n log(LogLevelLabel.DEBUG, \"Finalizing Powerlines project output...\");\n }\n\n return ctx.$$internal.callHook(\"writeBundle\", {\n sequential: true\n });\n }\n\n return {\n name:\n name.toLowerCase() === \"powerlines\"\n ? \"powerlines\"\n : `powerlines:${kebabCase(name)}`,\n api: ctx.$$internal.api,\n resolveId,\n load,\n transform,\n buildStart,\n buildEnd,\n writeBundle,\n vite: {\n sharedDuringBuild: true\n }\n };\n } catch (error) {\n log(LogLevelLabel.FATAL, (error as Error)?.message);\n\n throw error;\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyDA,SAAgB,uBAGd,SACA,UAAyC,EAAE,EAChB;CAC3B,MAAM,MAAM;AACZ,cAAa,IAAI,MAAM;CAEvB,MAAM,OAAO,QAAQ,QAAQ;AAE7B,cAAa;EACX,MAAM,MAAM,YAAY,IAAI,KAAK,KAAK;AACtC,MAAI,cAAc,OAAO,gBAAgB,UAAU,KAAK,CAAC,SAAS;AAElE,MAAI;GACF,MAAM,EAAE,WAAW,SACjB,wCAAkD,SAAS,QAAQ;AAErE,UAAO;IACL,MACE,KAAK,aAAa,KAAK,eACnB,eACA,cAAc,UAAU,KAAK;IACnC,KAAK,IAAI,WAAW;IACpB;IACA;IACD;WACM,OAAO;AACd,OAAI,cAAc,OAAQ,OAAiB,QAAQ;AAEnD,SAAM;;;;;;;;;;AAoBZ,SAAgB,eACd,SACA,UAAiC,EAAE,EACR;CAC3B,MAAM,MAAM;AACZ,cAAa,IAAI,MAAM;CAEvB,MAAM,OAAO,QAAQ,QAAQ;AAE7B,cAAa;EACX,MAAM,MAAM,QAAQ,OAAO,YAAY,IAAI,KAAK,KAAK,GAAG,IAAI;AAC5D,MAAI,cAAc,OAAO,gBAAgB,UAAU,KAAK,CAAC,SAAS;AAElE,MAAI;GACF,MAAM,EAAE,WAAW,SACjB,wCAAkD,SAAS,QAAQ;GAErE,eAAe,aAAuC;AACpD,QAAI,CAAC,QAAQ,mBACX,KAAI,cAAc,OAAO,sCAAsC;AAGjE,UAAM,IAAI,WAAW,SAAS,cAAc,EAC1C,YAAY,MACb,CAAC;;GAGJ,eAAe,UAEb,MACA,IAC6C;IAC7C,IAAI,cAAwC;AAE5C,SAAK,MAAM,QAAQ,IAAI,WAAW,YAAY,YAC5C,YACD,EAAE;KACD,MAAM,SACJ,MAAM,KAAK,QAAQ,MAAM,gBAAgB,KAAK,KAAK,EAAE,CACnD,UAAU,YAAY,EACtB,GAAG,QAAQ,6BAA6B,GAAG,CAC5C,CAAC;AACJ,SAAI,OACF,eAAc;;AAIlB,WAAO;;GAGT,eAAe,WAAoD;AACjE,QAAI,CAAC,QAAQ,mBACX,KAAI,cAAc,OAAO,uCAAuC;AAGlE,WAAO,IAAI,WAAW,SAAS,YAAY,EACzC,YAAY,MACb,CAAC;;GAGJ,eAAe,cAA6B;AAC1C,QAAI,CAAC,QAAQ,mBACX,KAAI,cAAc,OAAO,0CAA0C;AAGrE,WAAO,IAAI,WAAW,SAAS,eAAe,EAC5C,YAAY,MACb,CAAC;;AAGJ,UAAO;IACL,MACE,KAAK,aAAa,KAAK,eACnB,eACA,cAAc,UAAU,KAAK;IACnC,KAAK,IAAI,WAAW;IACpB;IACA;IACA;IACA;IACA;IACA;IACA,MAAM,EACJ,mBAAmB,MACpB;IACF;WACM,OAAO;AACd,OAAI,cAAc,OAAQ,OAAiB,QAAQ;AAEnD,SAAM"}
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_lib_utilities_format = require('./format.cjs');
2
3
  const require_lib_utilities_source_file = require('./source-file.cjs');
3
4
  const require_lib_utilities_file_header = require('./file-header.cjs');
4
- const require_lib_utilities_format = require('./format.cjs');
5
5
  const require_lib_utilities_source_map = require('./source-map.cjs');
6
6
  const require_lib_utilities_write_file = require('./write-file.cjs');
7
7
 
@@ -1,6 +1,6 @@
1
+ import { format, formatFolder } from "./format.mjs";
1
2
  import { getMagicString, getSourceFile, getString } from "./source-file.mjs";
2
3
  import { getFileHeader, getFileHeaderWarning, getFileHeaderWarningText, getTypescriptFileHeader } from "./file-header.mjs";
3
- import { format, formatFolder } from "./format.mjs";
4
4
  import { generateSourceMap } from "./source-map.mjs";
5
5
  import { writeFile } from "./write-file.mjs";
6
6
 
@@ -1,6 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
3
- let _storm_software_config_tools_types = require("@storm-software/config-tools/types");
4
3
  let prettier = require("prettier");
5
4
  let _stryke_fs_write_file = require("@stryke/fs/write-file");
6
5
 
@@ -21,7 +20,7 @@ async function writeFile(log, filepath, content, skipFormat = false) {
21
20
  filepath
22
21
  }) || "");
23
22
  } catch (error) {
24
- log(_storm_software_config_tools_types.LogLevelLabel.ERROR, `Failed to write file ${filepath} to disk \n${error?.message ? error.message : ""}`);
23
+ log("error", `Failed to write file ${filepath} to disk \n${error?.message ? error.message : ""}`);
25
24
  }
26
25
  }
27
26
 
@@ -1,4 +1,4 @@
1
- import { LogFn } from "../../types/config.cjs";
1
+ import { LogFn } from "../../types/log.cjs";
2
2
 
3
3
  //#region src/lib/utilities/write-file.d.ts
4
4
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"write-file.d.cts","names":[],"sources":["../../../src/lib/utilities/write-file.ts"],"mappings":";;;;;AA+BA;;;;;;iBAAsB,SAAA,CACpB,GAAA,EAAK,KAAA,EACL,QAAA,UACA,OAAA,UACA,UAAA,aAAkB,OAAA"}
1
+ {"version":3,"file":"write-file.d.cts","names":[],"sources":["../../../src/lib/utilities/write-file.ts"],"mappings":";;;;;AA8BA;;;;;;iBAAsB,SAAA,CACpB,GAAA,EAAK,KAAA,EACL,QAAA,UACA,OAAA,UACA,UAAA,aAAkB,OAAA"}
@@ -1,4 +1,4 @@
1
- import { LogFn } from "../../types/config.mjs";
1
+ import { LogFn } from "../../types/log.mjs";
2
2
 
3
3
  //#region src/lib/utilities/write-file.d.ts
4
4
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"write-file.d.mts","names":[],"sources":["../../../src/lib/utilities/write-file.ts"],"mappings":";;;;;AA+BA;;;;;;iBAAsB,SAAA,CACpB,GAAA,EAAK,KAAA,EACL,QAAA,UACA,OAAA,UACA,UAAA,aAAkB,OAAA"}
1
+ {"version":3,"file":"write-file.d.mts","names":[],"sources":["../../../src/lib/utilities/write-file.ts"],"mappings":";;;;;AA8BA;;;;;;iBAAsB,SAAA,CACpB,GAAA,EAAK,KAAA,EACL,QAAA,UACA,OAAA,UACA,UAAA,aAAkB,OAAA"}
@@ -1,4 +1,3 @@
1
- import { LogLevelLabel } from "@storm-software/config-tools/types";
2
1
  import { format, resolveConfig } from "prettier";
3
2
  import { writeFile as writeFile$1 } from "@stryke/fs/write-file";
4
3
 
@@ -19,7 +18,7 @@ async function writeFile(log, filepath, content, skipFormat = false) {
19
18
  filepath
20
19
  }) || "");
21
20
  } catch (error) {
22
- log(LogLevelLabel.ERROR, `Failed to write file ${filepath} to disk \n${error?.message ? error.message : ""}`);
21
+ log("error", `Failed to write file ${filepath} to disk \n${error?.message ? error.message : ""}`);
23
22
  }
24
23
  }
25
24
 
@@ -1 +1 @@
1
- {"version":3,"file":"write-file.mjs","names":["writeFileBase"],"sources":["../../../src/lib/utilities/write-file.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { LogLevelLabel } from \"@storm-software/config-tools/types\";\nimport { writeFile as writeFileBase } from \"@stryke/fs/write-file\";\nimport { format, resolveConfig } from \"prettier\";\nimport type { LogFn } from \"../../types/config\";\n\n/**\n * Writes and formats a file to the file system\n *\n * @param log - The logging function to use for logging errors\n * @param filepath - The file path to write the file\n * @param content - The content to write to the file\n * @param skipFormat - Should the plugin skip formatting the `content` string with Prettier\n */\nexport async function writeFile(\n log: LogFn,\n filepath: string,\n content: string,\n skipFormat = false\n) {\n try {\n if (skipFormat) {\n await writeFileBase(filepath, content);\n } else {\n const config = await resolveConfig(filepath);\n const formatted = await format(content, {\n ...(config ?? {}),\n filepath\n });\n\n await writeFileBase(filepath, formatted || \"\");\n }\n } catch (error) {\n log(\n LogLevelLabel.ERROR,\n `Failed to write file ${filepath} to disk \\n${(error as Error)?.message ? (error as Error).message : \"\"}`\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA+BA,eAAsB,UACpB,KACA,UACA,SACA,aAAa,OACb;AACA,KAAI;AACF,MAAI,WACF,OAAMA,YAAc,UAAU,QAAQ;MAQtC,OAAMA,YAAc,UAAU,MALN,OAAO,SAAS;GACtC,GAAI,MAFe,cAAc,SAAS,IAE5B,EAAE;GAChB;GACD,CAAC,IAEyC,GAAG;UAEzC,OAAO;AACd,MACE,cAAc,OACd,wBAAwB,SAAS,aAAc,OAAiB,UAAW,MAAgB,UAAU,KACtG"}
1
+ {"version":3,"file":"write-file.mjs","names":["writeFileBase"],"sources":["../../../src/lib/utilities/write-file.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { writeFile as writeFileBase } from \"@stryke/fs/write-file\";\nimport { format, resolveConfig } from \"prettier\";\nimport type { LogFn } from \"../../types/log\";\n\n/**\n * Writes and formats a file to the file system\n *\n * @param log - The logging function to use for logging errors\n * @param filepath - The file path to write the file\n * @param content - The content to write to the file\n * @param skipFormat - Should the plugin skip formatting the `content` string with Prettier\n */\nexport async function writeFile(\n log: LogFn,\n filepath: string,\n content: string,\n skipFormat = false\n) {\n try {\n if (skipFormat) {\n await writeFileBase(filepath, content);\n } else {\n const config = await resolveConfig(filepath);\n const formatted = await format(content, {\n ...(config ?? {}),\n filepath\n });\n\n await writeFileBase(filepath, formatted || \"\");\n }\n } catch (error) {\n log(\n \"error\",\n `Failed to write file ${filepath} to disk \\n${(error as Error)?.message ? (error as Error).message : \"\"}`\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;AA8BA,eAAsB,UACpB,KACA,UACA,SACA,aAAa,OACb;AACA,KAAI;AACF,MAAI,WACF,OAAMA,YAAc,UAAU,QAAQ;MAQtC,OAAMA,YAAc,UAAU,MALN,OAAO,SAAS;GACtC,GAAI,MAFe,cAAc,SAAS,IAE5B,EAAE;GAChB;GACD,CAAC,IAEyC,GAAG;UAEzC,OAAO;AACd,MACE,SACA,wBAAwB,SAAS,aAAc,OAAiB,UAAW,MAAgB,UAAU,KACtG"}
@@ -1,6 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_plugin_utils_paths = require('./paths.cjs');
3
- const require_plugin_utils_format_package_json = require('./format-package-json.cjs');
4
3
  const require_plugin_utils_build_helpers = require('./build-helpers.cjs');
5
4
  const require_plugin_utils_helpers = require('./helpers.cjs');
6
5
  const require_plugin_utils_merge = require('./merge.cjs');
@@ -9,6 +8,7 @@ const require_plugin_utils_context_helpers = require('./context-helpers.cjs');
9
8
  const require_plugin_utils_docs_helper = require('./docs-helper.cjs');
10
9
  const require_plugin_utils_extend = require('./extend.cjs');
11
10
  const require_plugin_utils_filter = require('./filter.cjs');
11
+ const require_plugin_utils_format_package_json = require('./format-package-json.cjs');
12
12
  const require_plugin_utils_get_config_path = require('./get-config-path.cjs');
13
13
  const require_plugin_utils_logging = require('./logging.cjs');
14
14
  const require_plugin_utils_modules = require('./modules.cjs');
@@ -50,4 +50,5 @@ exports.mergeConfig = require_plugin_utils_merge.mergeConfig;
50
50
  exports.normalizeFilter = require_plugin_utils_filter.normalizeFilter;
51
51
  exports.patternToCodeFilter = require_plugin_utils_filter.patternToCodeFilter;
52
52
  exports.patternToIdFilter = require_plugin_utils_filter.patternToIdFilter;
53
- exports.replacePathTokens = require_plugin_utils_paths.replacePathTokens;
53
+ exports.replacePathTokens = require_plugin_utils_paths.replacePathTokens;
54
+ exports.resolveLogLevel = require_plugin_utils_logging.resolveLogLevel;
@@ -7,8 +7,8 @@ import { createCodeFilter, createFilter, createFilterForId, createFilterForTrans
7
7
  import { formatPackageJson } from "./format-package-json.cjs";
8
8
  import { getConfigPath } from "./get-config-path.cjs";
9
9
  import { GetHookHandlerReturnType, __ΩGetHookHandlerReturnType, addPluginHook, dedupeHooklist, extractPluginHook, findInvalidPluginConfig, getHookHandler, isDuplicate, isPlugin, isPluginConfig, isPluginConfigObject, isPluginConfigTuple, isPluginHook, isPluginHookField, isPluginHookFunction, isPluginHookObject, isUnpluginHookField, isUnpluginHookKey } from "./helpers.cjs";
10
- import { isVerbose } from "./logging.cjs";
10
+ import { isVerbose, resolveLogLevel } from "./logging.cjs";
11
11
  import { MergeResult, __ΩMergeResult, merge, mergeConfig } from "./merge.cjs";
12
12
  import { isBuiltinModule } from "./modules.cjs";
13
13
  import { replacePathTokens } from "./paths.cjs";
14
- export { CombinePluginsOptions, GetDependencyConfigResult, GetHookHandlerReturnType, MergeResult, __ΩCombinePluginsOptions, __ΩGetDependencyConfigResult, __ΩGetHookHandlerReturnType, __ΩMergeResult, addPluginHook, combinePluginOptions, combinePlugins, createCodeFilter, createFilter, createFilterForId, createFilterForTransform, createIdFilter, dedupeHooklist, extend, extractPluginHook, findInvalidPluginConfig, formatPackageJson, getConfigPath, getDependencyConfig, getDocsOutputPath, getHookHandler, getOrganizationName, getWorkspaceName, isBuiltinModule, isDuplicate, isPlugin, isPluginConfig, isPluginConfigObject, isPluginConfigTuple, isPluginHook, isPluginHookField, isPluginHookFunction, isPluginHookObject, isUnpluginHookField, isUnpluginHookKey, isVerbose, merge, mergeConfig, normalizeFilter, patternToCodeFilter, patternToIdFilter, replacePathTokens };
14
+ export { CombinePluginsOptions, GetDependencyConfigResult, GetHookHandlerReturnType, MergeResult, __ΩCombinePluginsOptions, __ΩGetDependencyConfigResult, __ΩGetHookHandlerReturnType, __ΩMergeResult, addPluginHook, combinePluginOptions, combinePlugins, createCodeFilter, createFilter, createFilterForId, createFilterForTransform, createIdFilter, dedupeHooklist, extend, extractPluginHook, findInvalidPluginConfig, formatPackageJson, getConfigPath, getDependencyConfig, getDocsOutputPath, getHookHandler, getOrganizationName, getWorkspaceName, isBuiltinModule, isDuplicate, isPlugin, isPluginConfig, isPluginConfigObject, isPluginConfigTuple, isPluginHook, isPluginHookField, isPluginHookFunction, isPluginHookObject, isUnpluginHookField, isUnpluginHookKey, isVerbose, merge, mergeConfig, normalizeFilter, patternToCodeFilter, patternToIdFilter, replacePathTokens, resolveLogLevel };
@@ -7,8 +7,8 @@ import { createCodeFilter, createFilter, createFilterForId, createFilterForTrans
7
7
  import { formatPackageJson } from "./format-package-json.mjs";
8
8
  import { getConfigPath } from "./get-config-path.mjs";
9
9
  import { GetHookHandlerReturnType, __ΩGetHookHandlerReturnType, addPluginHook, dedupeHooklist, extractPluginHook, findInvalidPluginConfig, getHookHandler, isDuplicate, isPlugin, isPluginConfig, isPluginConfigObject, isPluginConfigTuple, isPluginHook, isPluginHookField, isPluginHookFunction, isPluginHookObject, isUnpluginHookField, isUnpluginHookKey } from "./helpers.mjs";
10
- import { isVerbose } from "./logging.mjs";
10
+ import { isVerbose, resolveLogLevel } from "./logging.mjs";
11
11
  import { MergeResult, __ΩMergeResult, merge, mergeConfig } from "./merge.mjs";
12
12
  import { isBuiltinModule } from "./modules.mjs";
13
13
  import { replacePathTokens } from "./paths.mjs";
14
- export { CombinePluginsOptions, GetDependencyConfigResult, GetHookHandlerReturnType, MergeResult, __ΩCombinePluginsOptions, __ΩGetDependencyConfigResult, __ΩGetHookHandlerReturnType, __ΩMergeResult, addPluginHook, combinePluginOptions, combinePlugins, createCodeFilter, createFilter, createFilterForId, createFilterForTransform, createIdFilter, dedupeHooklist, extend, extractPluginHook, findInvalidPluginConfig, formatPackageJson, getConfigPath, getDependencyConfig, getDocsOutputPath, getHookHandler, getOrganizationName, getWorkspaceName, isBuiltinModule, isDuplicate, isPlugin, isPluginConfig, isPluginConfigObject, isPluginConfigTuple, isPluginHook, isPluginHookField, isPluginHookFunction, isPluginHookObject, isUnpluginHookField, isUnpluginHookKey, isVerbose, merge, mergeConfig, normalizeFilter, patternToCodeFilter, patternToIdFilter, replacePathTokens };
14
+ export { CombinePluginsOptions, GetDependencyConfigResult, GetHookHandlerReturnType, MergeResult, __ΩCombinePluginsOptions, __ΩGetDependencyConfigResult, __ΩGetHookHandlerReturnType, __ΩMergeResult, addPluginHook, combinePluginOptions, combinePlugins, createCodeFilter, createFilter, createFilterForId, createFilterForTransform, createIdFilter, dedupeHooklist, extend, extractPluginHook, findInvalidPluginConfig, formatPackageJson, getConfigPath, getDependencyConfig, getDocsOutputPath, getHookHandler, getOrganizationName, getWorkspaceName, isBuiltinModule, isDuplicate, isPlugin, isPluginConfig, isPluginConfigObject, isPluginConfigTuple, isPluginHook, isPluginHookField, isPluginHookFunction, isPluginHookObject, isUnpluginHookField, isUnpluginHookKey, isVerbose, merge, mergeConfig, normalizeFilter, patternToCodeFilter, patternToIdFilter, replacePathTokens, resolveLogLevel };
@@ -1,5 +1,4 @@
1
1
  import { replacePathTokens } from "./paths.mjs";
2
- import { formatPackageJson } from "./format-package-json.mjs";
3
2
  import { getDependencyConfig } from "./build-helpers.mjs";
4
3
  import { addPluginHook, dedupeHooklist, extractPluginHook, findInvalidPluginConfig, getHookHandler, isDuplicate, isPlugin, isPluginConfig, isPluginConfigObject, isPluginConfigTuple, isPluginHook, isPluginHookField, isPluginHookFunction, isPluginHookObject, isUnpluginHookField, isUnpluginHookKey } from "./helpers.mjs";
5
4
  import { merge, mergeConfig } from "./merge.mjs";
@@ -8,8 +7,9 @@ import { getOrganizationName, getWorkspaceName } from "./context-helpers.mjs";
8
7
  import { getDocsOutputPath } from "./docs-helper.mjs";
9
8
  import { extend } from "./extend.mjs";
10
9
  import { createCodeFilter, createFilter, createFilterForId, createFilterForTransform, createIdFilter, normalizeFilter, patternToCodeFilter, patternToIdFilter } from "./filter.mjs";
10
+ import { formatPackageJson } from "./format-package-json.mjs";
11
11
  import { getConfigPath } from "./get-config-path.mjs";
12
- import { isVerbose } from "./logging.mjs";
12
+ import { isVerbose, resolveLogLevel } from "./logging.mjs";
13
13
  import { isBuiltinModule } from "./modules.mjs";
14
14
 
15
- export { addPluginHook, combinePluginOptions, combinePlugins, createCodeFilter, createFilter, createFilterForId, createFilterForTransform, createIdFilter, dedupeHooklist, extend, extractPluginHook, findInvalidPluginConfig, formatPackageJson, getConfigPath, getDependencyConfig, getDocsOutputPath, getHookHandler, getOrganizationName, getWorkspaceName, isBuiltinModule, isDuplicate, isPlugin, isPluginConfig, isPluginConfigObject, isPluginConfigTuple, isPluginHook, isPluginHookField, isPluginHookFunction, isPluginHookObject, isUnpluginHookField, isUnpluginHookKey, isVerbose, merge, mergeConfig, normalizeFilter, patternToCodeFilter, patternToIdFilter, replacePathTokens };
15
+ export { addPluginHook, combinePluginOptions, combinePlugins, createCodeFilter, createFilter, createFilterForId, createFilterForTransform, createIdFilter, dedupeHooklist, extend, extractPluginHook, findInvalidPluginConfig, formatPackageJson, getConfigPath, getDependencyConfig, getDocsOutputPath, getHookHandler, getOrganizationName, getWorkspaceName, isBuiltinModule, isDuplicate, isPlugin, isPluginConfig, isPluginConfigObject, isPluginConfigTuple, isPluginHook, isPluginHookField, isPluginHookFunction, isPluginHookObject, isUnpluginHookField, isUnpluginHookKey, isVerbose, merge, mergeConfig, normalizeFilter, patternToCodeFilter, patternToIdFilter, replacePathTokens, resolveLogLevel };
@@ -1,5 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ const require_log_level = require('../constants/log-level.cjs');
4
+ let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
5
+ let defu = require("defu");
6
+ let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
3
7
  let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
4
8
 
5
9
  //#region src/plugin-utils/logging.ts
@@ -13,6 +17,55 @@ function isVerbose(logLevelOrContext) {
13
17
  const level = (0, _stryke_type_checks_is_string.isString)(logLevelOrContext) ? logLevelOrContext : logLevelOrContext.config.logLevel;
14
18
  return level === "debug" || level === "trace";
15
19
  }
20
+ /**
21
+ * Resolves the log level configuration based on the provided log level and mode, returning a complete LogLevelResolvedConfig object that specifies the log level for each log category.
22
+ *
23
+ * @param logLevel - The user-provided log level configuration, which can be a string or an object specifying log levels for each category.
24
+ * @param mode - The current mode of the application (e.g., "development", "test", "production"), which determines the default log levels.
25
+ * @returns A LogLevelResolvedConfig object specifying the log level for each log category.
26
+ */
27
+ function resolveLogLevel(logLevel, mode) {
28
+ if (logLevel === "trace") return {
29
+ general: "trace",
30
+ fs: "trace",
31
+ performance: "trace",
32
+ network: "trace",
33
+ plugins: "trace",
34
+ hooks: "trace",
35
+ env: "trace",
36
+ ipc: "trace",
37
+ config: "trace"
38
+ };
39
+ else if (logLevel === "silent") return {
40
+ general: "silent",
41
+ fs: "silent",
42
+ performance: "silent",
43
+ network: "silent",
44
+ plugins: "silent",
45
+ hooks: "silent",
46
+ env: "silent",
47
+ ipc: "silent",
48
+ config: "silent"
49
+ };
50
+ let defaultLogLevel;
51
+ if (mode === "development") defaultLogLevel = require_log_level.DEFAULT_DEVELOPMENT_LOG_LEVEL;
52
+ else if (mode === "test") defaultLogLevel = require_log_level.DEFAULT_TEST_LOG_LEVEL;
53
+ else defaultLogLevel = require_log_level.DEFAULT_PRODUCTION_LOG_LEVEL;
54
+ if ((0, _stryke_type_checks_is_set_string.isSetString)(logLevel)) return {
55
+ general: logLevel,
56
+ fs: defaultLogLevel.fs,
57
+ performance: logLevel,
58
+ network: defaultLogLevel.network,
59
+ plugins: logLevel,
60
+ hooks: logLevel,
61
+ env: defaultLogLevel.env,
62
+ ipc: defaultLogLevel.ipc,
63
+ config: defaultLogLevel.config
64
+ };
65
+ else if ((0, _stryke_type_checks_is_set_object.isSetObject)(logLevel)) return (0, defu.defu)(logLevel, defaultLogLevel);
66
+ return defaultLogLevel;
67
+ }
16
68
 
17
69
  //#endregion
18
- exports.isVerbose = isVerbose;
70
+ exports.isVerbose = isVerbose;
71
+ exports.resolveLogLevel = resolveLogLevel;
@@ -1,4 +1,6 @@
1
+ import { LogLevelResolvedConfig, LogLevelUserConfig } from "../types/log.cjs";
1
2
  import { UnresolvedContext } from "../types/context.cjs";
3
+ import { Mode } from "../types/config.cjs";
2
4
  //#region src/plugin-utils/logging.d.ts
3
5
  /**
4
6
  * Determines if the provided log level is considered verbose (debug or trace).
@@ -14,6 +16,14 @@ declare function isVerbose(logLevel: string): boolean;
14
16
  * @returns True if the log level is "debug" or "trace", false otherwise.
15
17
  */
16
18
  declare function isVerbose(context: UnresolvedContext): boolean;
19
+ /**
20
+ * Resolves the log level configuration based on the provided log level and mode, returning a complete LogLevelResolvedConfig object that specifies the log level for each log category.
21
+ *
22
+ * @param logLevel - The user-provided log level configuration, which can be a string or an object specifying log levels for each category.
23
+ * @param mode - The current mode of the application (e.g., "development", "test", "production"), which determines the default log levels.
24
+ * @returns A LogLevelResolvedConfig object specifying the log level for each log category.
25
+ */
26
+ declare function resolveLogLevel(logLevel: LogLevelUserConfig, mode?: Mode): LogLevelResolvedConfig;
17
27
  //#endregion
18
- export { isVerbose };
28
+ export { isVerbose, resolveLogLevel };
19
29
  //# sourceMappingURL=logging.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logging.d.cts","names":[],"sources":["../../src/plugin-utils/logging.ts"],"mappings":";;;;;AA2BA;;;iBAAgB,SAAA,CAAU,QAAA;;AAQ1B;;;;;iBAAgB,SAAA,CAAU,OAAA,EAAS,iBAAA"}
1
+ {"version":3,"file":"logging.d.cts","names":[],"sources":["../../src/plugin-utils/logging.ts"],"mappings":";;;;;;;;AAoCA;;iBAAgB,SAAA,CAAU,QAAA;;;AAQ1B;;;;iBAAgB,SAAA,CAAU,OAAA,EAAS,iBAAA;AAyBnC;;;;;;;AAAA,iBAAgB,eAAA,CACd,QAAA,EAAU,kBAAA,EACV,IAAA,GAAO,IAAA,GACN,sBAAA"}