@powerlines/engine 0.44.0 → 0.44.2

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 (44) hide show
  1. package/dist/_internal/worker.cjs +186 -169
  2. package/dist/_internal/worker.d.cts.map +1 -1
  3. package/dist/_internal/worker.d.mts.map +1 -1
  4. package/dist/_internal/worker.mjs +187 -170
  5. package/dist/_internal/worker.mjs.map +1 -1
  6. package/dist/api.cjs +7 -7
  7. package/dist/api.mjs +5 -5
  8. package/dist/api.mjs.map +1 -1
  9. package/dist/{base-context-5_AZZYFu.cjs → base-context-CAA1druQ.cjs} +62 -33
  10. package/dist/{base-context-D_ZidDDm.mjs → base-context-fOM4ZWUo.mjs} +67 -38
  11. package/dist/base-context-fOM4ZWUo.mjs.map +1 -0
  12. package/dist/context/index.cjs +3 -3
  13. package/dist/context/index.d.cts +38 -52
  14. package/dist/context/index.d.cts.map +1 -1
  15. package/dist/context/index.d.mts +38 -52
  16. package/dist/context/index.d.mts.map +1 -1
  17. package/dist/context/index.mjs +3 -3
  18. package/dist/{engine-context-PQ3BgcgR.mjs → engine-context-BWGxMU_n.mjs} +2 -2
  19. package/dist/{engine-context-PQ3BgcgR.mjs.map → engine-context-BWGxMU_n.mjs.map} +1 -1
  20. package/dist/{engine-context-w4fts28j.cjs → engine-context-CUPubmrM.cjs} +1 -1
  21. package/dist/{execution-context-0GmpbWbs.cjs → execution-context-BoJhCK0d.cjs} +125 -117
  22. package/dist/{execution-context-zedP0h4Z.mjs → execution-context-CFJst4Fz.mjs} +127 -119
  23. package/dist/execution-context-CFJst4Fz.mjs.map +1 -0
  24. package/dist/index.cjs +114 -53
  25. package/dist/index.d.cts +8 -0
  26. package/dist/index.d.cts.map +1 -1
  27. package/dist/index.d.mts +8 -0
  28. package/dist/index.d.mts.map +1 -1
  29. package/dist/index.mjs +114 -53
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/storage/index.cjs +1 -1
  32. package/dist/storage/index.mjs +1 -1
  33. package/dist/{tsconfig-Cstsoprg.mjs → tsconfig-CI6bla4E.mjs} +2 -2
  34. package/dist/{tsconfig-Cstsoprg.mjs.map → tsconfig-CI6bla4E.mjs.map} +1 -1
  35. package/dist/{tsconfig-DeyWQC2N.cjs → tsconfig-QMSxSwBD.cjs} +1 -1
  36. package/dist/typescript/index.cjs +1 -1
  37. package/dist/typescript/index.mjs +1 -1
  38. package/dist/{virtual-CUgOdyIa.mjs → virtual-CYGZHTDd.mjs} +5 -5
  39. package/dist/virtual-CYGZHTDd.mjs.map +1 -0
  40. package/dist/{virtual-1hYa9zCy.cjs → virtual-Ct3ZqPeN.cjs} +2 -2
  41. package/package.json +3 -3
  42. package/dist/base-context-D_ZidDDm.mjs.map +0 -1
  43. package/dist/execution-context-zedP0h4Z.mjs.map +0 -1
  44. package/dist/virtual-CUgOdyIa.mjs.map +0 -1
@@ -1,11 +1,16 @@
1
1
  const require_chunk = require('./chunk-C0xms8kb.cjs');
2
2
  let _stryke_fs_resolve = require("@stryke/fs/resolve");
3
+ let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
3
4
  let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
5
+ let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
4
6
  let _powerlines_core_lib_config = require("@powerlines/core/lib/config");
5
- let _powerlines_core_lib_logger = require("@powerlines/core/lib/logger");
6
7
  let _powerlines_core_plugin_utils = require("@powerlines/core/plugin-utils");
8
+ let _powerlines_core_plugin_utils_logging = require("@powerlines/core/plugin-utils/logging");
7
9
  let _stryke_env_get_env_paths = require("@stryke/env/get-env-paths");
10
+ let _stryke_fs = require("@stryke/fs");
8
11
  let _stryke_json_storm_json = require("@stryke/json/storm-json");
12
+ let _stryke_path = require("@stryke/path");
13
+ let _stryke_path_append = require("@stryke/path/append");
9
14
  let _stryke_path_is_equal = require("@stryke/path/is-equal");
10
15
  let _stryke_path_replace = require("@stryke/path/replace");
11
16
  let chalk = require("chalk");
@@ -13,6 +18,7 @@ chalk = require_chunk.__toESM(chalk, 1);
13
18
  let date_fns_formatDistanceToNowStrict = require("date-fns/formatDistanceToNowStrict");
14
19
  let defu = require("defu");
15
20
  defu = require_chunk.__toESM(defu, 1);
21
+ let node_fs = require("node:fs");
16
22
  let _stryke_path_join_paths = require("@stryke/path/join-paths");
17
23
  let jiti = require("jiti");
18
24
 
@@ -46,6 +52,7 @@ function createResolver(options) {
46
52
  //#region src/context/base-context.ts
47
53
  var PowerlinesBaseContext = class PowerlinesBaseContext {
48
54
  #timestamp = Date.now();
55
+ #name = "powerlines";
49
56
  /**
50
57
  * The path to the Powerlines package
51
58
  */
@@ -67,6 +74,15 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
67
74
  */
68
75
  configFile;
69
76
  /**
77
+ * The logger instance for the context, which can be used to create log messages with consistent formatting and metadata. This logger is extended by plugin contexts to include additional metadata such as the plugin name and category, which can be used to filter and format log messages in a more granular way.
78
+ */
79
+ get logger() {
80
+ return this.createLogger({
81
+ ...this.configFile.config,
82
+ ...this.options
83
+ });
84
+ }
85
+ /**
70
86
  * A timestamp representing when the context was initialized
71
87
  */
72
88
  get timestamp() {
@@ -76,12 +92,6 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
76
92
  return (0, _powerlines_core_plugin_utils.resolveLogLevel)(this.options.logLevel, this.options.mode);
77
93
  }
78
94
  /**
79
- * The logger function
80
- */
81
- get log() {
82
- return this.createLog();
83
- }
84
- /**
85
95
  * The environment paths for the project
86
96
  */
87
97
  get envPaths() {
@@ -110,7 +120,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
110
120
  * @param message - The message to log.
111
121
  */
112
122
  fatal(message) {
113
- this.log("error", (0, _stryke_type_checks_is_string.isString)(message) ? message : _stryke_json_storm_json.StormJSON.stringify(message));
123
+ this.logger.error((0, _stryke_type_checks_is_string.isString)(message) ? message : _stryke_json_storm_json.StormJSON.stringify(message));
114
124
  }
115
125
  /**
116
126
  * A logging function for error messages
@@ -118,7 +128,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
118
128
  * @param message - The message to log.
119
129
  */
120
130
  error(message) {
121
- this.log("error", (0, _stryke_type_checks_is_string.isString)(message) ? message : _stryke_json_storm_json.StormJSON.stringify(message));
131
+ this.logger.error((0, _stryke_type_checks_is_string.isString)(message) ? message : _stryke_json_storm_json.StormJSON.stringify(message));
122
132
  }
123
133
  /**
124
134
  * A logging function for warning messages
@@ -126,7 +136,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
126
136
  * @param message - The message to log.
127
137
  */
128
138
  warn(message) {
129
- this.log("warn", (0, _stryke_type_checks_is_string.isString)(message) ? message : _stryke_json_storm_json.StormJSON.stringify(message));
139
+ this.logger.warn((0, _stryke_type_checks_is_string.isString)(message) ? message : _stryke_json_storm_json.StormJSON.stringify(message));
130
140
  }
131
141
  /**
132
142
  * A logging function for informational messages
@@ -134,7 +144,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
134
144
  * @param message - The message to log.
135
145
  */
136
146
  info(message) {
137
- this.log("info", (0, _stryke_type_checks_is_string.isString)(message) ? message : _stryke_json_storm_json.StormJSON.stringify(message));
147
+ this.logger.info((0, _stryke_type_checks_is_string.isString)(message) ? message : _stryke_json_storm_json.StormJSON.stringify(message));
138
148
  }
139
149
  /**
140
150
  * A logging function for debug messages
@@ -142,7 +152,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
142
152
  * @param message - The message to log.
143
153
  */
144
154
  debug(message) {
145
- this.log("debug", (0, _stryke_type_checks_is_string.isString)(message) ? message : _stryke_json_storm_json.StormJSON.stringify(message));
155
+ this.logger.debug((0, _stryke_type_checks_is_string.isString)(message) ? message : _stryke_json_storm_json.StormJSON.stringify(message));
146
156
  }
147
157
  /**
148
158
  * A logging function for trace messages
@@ -150,7 +160,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
150
160
  * @param message - The message to log.
151
161
  */
152
162
  trace(message) {
153
- this.log("trace", (0, _stryke_type_checks_is_string.isString)(message) ? message : _stryke_json_storm_json.StormJSON.stringify(message));
163
+ this.logger.trace((0, _stryke_type_checks_is_string.isString)(message) ? message : _stryke_json_storm_json.StormJSON.stringify(message));
154
164
  }
155
165
  /**
156
166
  * A function to create a timer for measuring the duration of asynchronous operations
@@ -170,38 +180,31 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
170
180
  const startDuration = performance.now();
171
181
  return () => {
172
182
  const duration = performance.now() - startDuration;
173
- this.log({
174
- level: "info",
175
- category: "performance"
176
- }, `${chalk.default.bold.cyanBright(name)} completed in ${chalk.default.bold.cyanBright(duration < 1e3 ? `${duration.toFixed(2)} milliseconds` : (0, date_fns_formatDistanceToNowStrict.formatDistanceToNowStrict)(startDate))}`);
183
+ this.logger.info({
184
+ meta: { category: "performance" },
185
+ message: `${chalk.default.bold.cyanBright(name)} completed in ${chalk.default.bold.cyanBright(duration < 1e3 ? `${duration.toFixed(2)} milliseconds` : (0, date_fns_formatDistanceToNowStrict.formatDistanceToNowStrict)(startDate))}`
186
+ });
177
187
  };
178
188
  }
179
189
  /**
180
190
  * Create a new logger instance
181
191
  *
182
- * @param config - The configuration options to use for the logger instance, which can be used to customize the appearance and behavior of the log messages generated by the logger. This is typically the name of the plugin or module that is creating the logger instance.
183
- * @returns A logger function
192
+ * @param options - The configuration options to use for the logger instance, which can be used to customize the appearance and behavior of the log messages generated by the logger. This is typically the name of the plugin or module that is creating the logger instance.
193
+ * @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
184
194
  */
185
- createLog(config) {
186
- return (0, _powerlines_core_lib_logger.createLogFn)({
187
- ...this.options,
188
- ...config
189
- });
195
+ createLogger(options, callback) {
196
+ return (0, _powerlines_core_plugin_utils_logging.createLogger)(this.options.name || this.options.root, options, callback);
190
197
  }
191
198
  /**
192
- * Extend the current logger instance with a new source
199
+ * Extend the base logger with additional configuration options
193
200
  *
194
- * @param config - The overlay metadata to use for the badge in the log output, which can be used to customize the appearance and behavior of the log messages generated by the extended logger. This typically includes the name of the plugin or module that is creating the logger instance, and can also include other metadata such as the command or environment.
195
- * @returns A new logger function that includes the badge in its output.
201
+ * @param options - The configuration options to extend the base logger with, which can be used to add additional metadata or customize the appearance of log messages generated by the logger. This is typically the name of the plugin or module that is creating the logger instance, as well as any additional metadata such as the plugin category or environment.
202
+ * @returns A new logger client instance that extends the base logger with the provided configuration options.
196
203
  */
197
- extendLog(config) {
198
- return (0, _powerlines_core_lib_logger.extendLogFn)(this.log, config);
204
+ extendLogger(options) {
205
+ return (0, _powerlines_core_plugin_utils_logging.extendLogger)(this.logger, options);
199
206
  }
200
207
  /**
201
- * A logger function specific to this context
202
- */
203
- logger;
204
- /**
205
208
  * Initialize the context with the provided configuration options
206
209
  *
207
210
  * @remarks
@@ -219,6 +222,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
219
222
  const cwd = options.cwd || this.options?.cwd || process.cwd();
220
223
  const root = (0, _stryke_path_replace.replacePath)((options.root || this.options?.root) && (options.root || this.options.root).replace(/^\.\/?/, "") && !(0, _stryke_path_is_equal.isEqual)(options.root || this.options.root, cwd) ? options.root || this.options.root : ".", cwd);
221
224
  this.options = (0, defu.default)({
225
+ name: options.name,
222
226
  root,
223
227
  cwd,
224
228
  mode: options.mode,
@@ -238,6 +242,31 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
238
242
  logLevel: this.logLevel
239
243
  });
240
244
  this.configFile = await (0, _powerlines_core_lib_config.loadUserConfigFile)(this.options, this.resolver);
245
+ if (!this.options.name) {
246
+ if (this.configFile.config) {
247
+ if ((0, _stryke_type_checks_is_set_object.isSetObject)(this.configFile.config) && (0, _stryke_type_checks_is_set_string.isSetString)(this.configFile.config.name)) this.options.name = this.configFile.config.name;
248
+ else if (Array.isArray(this.configFile.config)) {
249
+ for (const config of this.configFile.config) if ((0, _stryke_type_checks_is_set_object.isSetObject)(config) && (0, _stryke_type_checks_is_set_string.isSetString)(config.name)) {
250
+ this.options.name = config.name;
251
+ break;
252
+ }
253
+ }
254
+ }
255
+ if (!this.options.name) {
256
+ const packageJsonPath = (0, _stryke_path.joinPaths)((0, _stryke_path_append.appendPath)(this.options.root, this.options.cwd), "package.json");
257
+ if ((0, node_fs.existsSync)(packageJsonPath)) {
258
+ const packageJson = await (0, _stryke_fs.readJsonFile)(packageJsonPath);
259
+ this.options.name = packageJson.name;
260
+ }
261
+ if (!this.options.name) {
262
+ const projectJsonPath = (0, _stryke_path.joinPaths)((0, _stryke_path_append.appendPath)(this.options.root, this.options.cwd), "project.json");
263
+ if ((0, node_fs.existsSync)(projectJsonPath)) {
264
+ const projectJson = await (0, _stryke_fs.readJsonFile)(projectJsonPath);
265
+ this.options.name = projectJson.name;
266
+ }
267
+ }
268
+ }
269
+ }
241
270
  }
242
271
  };
243
272
 
@@ -1,16 +1,22 @@
1
1
  import { resolvePackage } from "@stryke/fs/resolve";
2
+ import { isSetObject } from "@stryke/type-checks/is-set-object";
2
3
  import { isString } from "@stryke/type-checks/is-string";
4
+ import { isSetString } from "@stryke/type-checks/is-set-string";
3
5
  import { loadUserConfigFile } from "@powerlines/core/lib/config";
4
- import { createLogFn, extendLogFn } from "@powerlines/core/lib/logger";
5
6
  import { resolveLogLevel } from "@powerlines/core/plugin-utils";
7
+ import { createLogger as createLogger$1, extendLogger } from "@powerlines/core/plugin-utils/logging";
6
8
  import { getEnvPaths } from "@stryke/env/get-env-paths";
9
+ import { readJsonFile } from "@stryke/fs";
7
10
  import { StormJSON } from "@stryke/json/storm-json";
11
+ import { joinPaths } from "@stryke/path";
12
+ import { appendPath } from "@stryke/path/append";
8
13
  import { isEqual } from "@stryke/path/is-equal";
9
14
  import { replacePath } from "@stryke/path/replace";
10
15
  import chalk from "chalk";
11
16
  import { formatDistanceToNowStrict } from "date-fns/formatDistanceToNowStrict";
12
17
  import defu from "defu";
13
- import { joinPaths } from "@stryke/path/join-paths";
18
+ import { existsSync } from "node:fs";
19
+ import { joinPaths as joinPaths$1 } from "@stryke/path/join-paths";
14
20
  import { createJiti } from "jiti";
15
21
 
16
22
  //#region src/_internal/helpers/resolver.ts
@@ -23,7 +29,7 @@ import { createJiti } from "jiti";
23
29
  function resolveOptions(options) {
24
30
  return defu(options, {
25
31
  interopDefault: true,
26
- fsCache: options.mode !== "development" ? joinPaths(options.cacheDir, "jiti") : false,
32
+ fsCache: options.mode !== "development" ? joinPaths$1(options.cacheDir, "jiti") : false,
27
33
  moduleCache: options.mode !== "development"
28
34
  });
29
35
  }
@@ -34,8 +40,8 @@ function resolveOptions(options) {
34
40
  * @returns A Jiti instance configured for the specified workspace and project root.
35
41
  */
36
42
  function createResolver(options) {
37
- const baseResolver = createJiti(joinPaths(options.workspaceRoot, options.root), resolveOptions(options));
38
- baseResolver.plugin = createJiti(joinPaths(options.workspaceRoot, options.root), resolveOptions(options));
43
+ const baseResolver = createJiti(joinPaths$1(options.workspaceRoot, options.root), resolveOptions(options));
44
+ baseResolver.plugin = createJiti(joinPaths$1(options.workspaceRoot, options.root), resolveOptions(options));
39
45
  return baseResolver;
40
46
  }
41
47
 
@@ -43,6 +49,7 @@ function createResolver(options) {
43
49
  //#region src/context/base-context.ts
44
50
  var PowerlinesBaseContext = class PowerlinesBaseContext {
45
51
  #timestamp = Date.now();
52
+ #name = "powerlines";
46
53
  /**
47
54
  * The path to the Powerlines package
48
55
  */
@@ -64,6 +71,15 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
64
71
  */
65
72
  configFile;
66
73
  /**
74
+ * The logger instance for the context, which can be used to create log messages with consistent formatting and metadata. This logger is extended by plugin contexts to include additional metadata such as the plugin name and category, which can be used to filter and format log messages in a more granular way.
75
+ */
76
+ get logger() {
77
+ return this.createLogger({
78
+ ...this.configFile.config,
79
+ ...this.options
80
+ });
81
+ }
82
+ /**
67
83
  * A timestamp representing when the context was initialized
68
84
  */
69
85
  get timestamp() {
@@ -73,12 +89,6 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
73
89
  return resolveLogLevel(this.options.logLevel, this.options.mode);
74
90
  }
75
91
  /**
76
- * The logger function
77
- */
78
- get log() {
79
- return this.createLog();
80
- }
81
- /**
82
92
  * The environment paths for the project
83
93
  */
84
94
  get envPaths() {
@@ -107,7 +117,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
107
117
  * @param message - The message to log.
108
118
  */
109
119
  fatal(message) {
110
- this.log("error", isString(message) ? message : StormJSON.stringify(message));
120
+ this.logger.error(isString(message) ? message : StormJSON.stringify(message));
111
121
  }
112
122
  /**
113
123
  * A logging function for error messages
@@ -115,7 +125,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
115
125
  * @param message - The message to log.
116
126
  */
117
127
  error(message) {
118
- this.log("error", isString(message) ? message : StormJSON.stringify(message));
128
+ this.logger.error(isString(message) ? message : StormJSON.stringify(message));
119
129
  }
120
130
  /**
121
131
  * A logging function for warning messages
@@ -123,7 +133,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
123
133
  * @param message - The message to log.
124
134
  */
125
135
  warn(message) {
126
- this.log("warn", isString(message) ? message : StormJSON.stringify(message));
136
+ this.logger.warn(isString(message) ? message : StormJSON.stringify(message));
127
137
  }
128
138
  /**
129
139
  * A logging function for informational messages
@@ -131,7 +141,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
131
141
  * @param message - The message to log.
132
142
  */
133
143
  info(message) {
134
- this.log("info", isString(message) ? message : StormJSON.stringify(message));
144
+ this.logger.info(isString(message) ? message : StormJSON.stringify(message));
135
145
  }
136
146
  /**
137
147
  * A logging function for debug messages
@@ -139,7 +149,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
139
149
  * @param message - The message to log.
140
150
  */
141
151
  debug(message) {
142
- this.log("debug", isString(message) ? message : StormJSON.stringify(message));
152
+ this.logger.debug(isString(message) ? message : StormJSON.stringify(message));
143
153
  }
144
154
  /**
145
155
  * A logging function for trace messages
@@ -147,7 +157,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
147
157
  * @param message - The message to log.
148
158
  */
149
159
  trace(message) {
150
- this.log("trace", isString(message) ? message : StormJSON.stringify(message));
160
+ this.logger.trace(isString(message) ? message : StormJSON.stringify(message));
151
161
  }
152
162
  /**
153
163
  * A function to create a timer for measuring the duration of asynchronous operations
@@ -167,38 +177,31 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
167
177
  const startDuration = performance.now();
168
178
  return () => {
169
179
  const duration = performance.now() - startDuration;
170
- this.log({
171
- level: "info",
172
- category: "performance"
173
- }, `${chalk.bold.cyanBright(name)} completed in ${chalk.bold.cyanBright(duration < 1e3 ? `${duration.toFixed(2)} milliseconds` : formatDistanceToNowStrict(startDate))}`);
180
+ this.logger.info({
181
+ meta: { category: "performance" },
182
+ message: `${chalk.bold.cyanBright(name)} completed in ${chalk.bold.cyanBright(duration < 1e3 ? `${duration.toFixed(2)} milliseconds` : formatDistanceToNowStrict(startDate))}`
183
+ });
174
184
  };
175
185
  }
176
186
  /**
177
187
  * Create a new logger instance
178
188
  *
179
- * @param config - The configuration options to use for the logger instance, which can be used to customize the appearance and behavior of the log messages generated by the logger. This is typically the name of the plugin or module that is creating the logger instance.
180
- * @returns A logger function
189
+ * @param options - The configuration options to use for the logger instance, which can be used to customize the appearance and behavior of the log messages generated by the logger. This is typically the name of the plugin or module that is creating the logger instance.
190
+ * @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
181
191
  */
182
- createLog(config) {
183
- return createLogFn({
184
- ...this.options,
185
- ...config
186
- });
192
+ createLogger(options, callback) {
193
+ return createLogger$1(this.options.name || this.options.root, options, callback);
187
194
  }
188
195
  /**
189
- * Extend the current logger instance with a new source
196
+ * Extend the base logger with additional configuration options
190
197
  *
191
- * @param config - The overlay metadata to use for the badge in the log output, which can be used to customize the appearance and behavior of the log messages generated by the extended logger. This typically includes the name of the plugin or module that is creating the logger instance, and can also include other metadata such as the command or environment.
192
- * @returns A new logger function that includes the badge in its output.
198
+ * @param options - The configuration options to extend the base logger with, which can be used to add additional metadata or customize the appearance of log messages generated by the logger. This is typically the name of the plugin or module that is creating the logger instance, as well as any additional metadata such as the plugin category or environment.
199
+ * @returns A new logger client instance that extends the base logger with the provided configuration options.
193
200
  */
194
- extendLog(config) {
195
- return extendLogFn(this.log, config);
201
+ extendLogger(options) {
202
+ return extendLogger(this.logger, options);
196
203
  }
197
204
  /**
198
- * A logger function specific to this context
199
- */
200
- logger;
201
- /**
202
205
  * Initialize the context with the provided configuration options
203
206
  *
204
207
  * @remarks
@@ -216,6 +219,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
216
219
  const cwd = options.cwd || this.options?.cwd || process.cwd();
217
220
  const root = replacePath((options.root || this.options?.root) && (options.root || this.options.root).replace(/^\.\/?/, "") && !isEqual(options.root || this.options.root, cwd) ? options.root || this.options.root : ".", cwd);
218
221
  this.options = defu({
222
+ name: options.name,
219
223
  root,
220
224
  cwd,
221
225
  mode: options.mode,
@@ -235,9 +239,34 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
235
239
  logLevel: this.logLevel
236
240
  });
237
241
  this.configFile = await loadUserConfigFile(this.options, this.resolver);
242
+ if (!this.options.name) {
243
+ if (this.configFile.config) {
244
+ if (isSetObject(this.configFile.config) && isSetString(this.configFile.config.name)) this.options.name = this.configFile.config.name;
245
+ else if (Array.isArray(this.configFile.config)) {
246
+ for (const config of this.configFile.config) if (isSetObject(config) && isSetString(config.name)) {
247
+ this.options.name = config.name;
248
+ break;
249
+ }
250
+ }
251
+ }
252
+ if (!this.options.name) {
253
+ const packageJsonPath = joinPaths(appendPath(this.options.root, this.options.cwd), "package.json");
254
+ if (existsSync(packageJsonPath)) {
255
+ const packageJson = await readJsonFile(packageJsonPath);
256
+ this.options.name = packageJson.name;
257
+ }
258
+ if (!this.options.name) {
259
+ const projectJsonPath = joinPaths(appendPath(this.options.root, this.options.cwd), "project.json");
260
+ if (existsSync(projectJsonPath)) {
261
+ const projectJson = await readJsonFile(projectJsonPath);
262
+ this.options.name = projectJson.name;
263
+ }
264
+ }
265
+ }
266
+ }
238
267
  }
239
268
  };
240
269
 
241
270
  //#endregion
242
271
  export { PowerlinesBaseContext as t };
243
- //# sourceMappingURL=base-context-D_ZidDDm.mjs.map
272
+ //# sourceMappingURL=base-context-fOM4ZWUo.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-context-fOM4ZWUo.mjs","names":["joinPaths","#timestamp","createLogger"],"sources":["../src/_internal/helpers/resolver.ts","../src/context/base-context.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 type { ResolvedConfig, Resolver } from \"@powerlines/core\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport defu from \"defu\";\nimport { JitiOptions, createJiti } from \"jiti\";\n\nexport type CreateResolverOptions = Omit<\n JitiOptions,\n \"fsCache\" | \"moduleCache\" | \"interopDefault\"\n> &\n Pick<ResolvedConfig, \"mode\" | \"logLevel\" | \"skipCache\"> & {\n workspaceRoot: string;\n root: string;\n cacheDir: string;\n };\n\n/**\n * Create a Jiti resolver for the given workspace and project root.\n *\n * @param options - The options for creating the resolver.\n * @returns A Jiti instance configured for the specified workspace and project root.\n */\nfunction resolveOptions(options: CreateResolverOptions): JitiOptions {\n return defu(options, {\n interopDefault: true,\n fsCache:\n options.mode !== \"development\"\n ? joinPaths(options.cacheDir, \"jiti\")\n : false,\n moduleCache: options.mode !== \"development\"\n });\n}\n\n/**\n * Create a Jiti resolver for the given workspace and project root.\n *\n * @param options - The options for creating the resolver.\n * @returns A Jiti instance configured for the specified workspace and project root.\n */\nexport function createResolver(options: CreateResolverOptions): Resolver {\n const baseResolver = createJiti(\n joinPaths(options.workspaceRoot, options.root),\n resolveOptions(options)\n ) as Resolver;\n baseResolver.plugin = createJiti(\n joinPaths(options.workspaceRoot, options.root),\n resolveOptions(options)\n );\n\n return baseResolver;\n}\n","/* -------------------------------------------------------------------\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 type {\n BaseContext,\n EngineOptions,\n Logger,\n LoggerMessage,\n LoggerOptions,\n LogLevelResolvedConfig,\n LogMessage,\n ParsedUserConfig,\n ResolvedEngineOptions,\n Resolver\n} from \"@powerlines/core\";\nimport { loadUserConfigFile } from \"@powerlines/core/lib/config\";\nimport { resolveLogLevel } from \"@powerlines/core/plugin-utils\";\nimport {\n createLogger,\n extendLogger\n} from \"@powerlines/core/plugin-utils/logging\";\nimport { EnvPaths, getEnvPaths } from \"@stryke/env/get-env-paths\";\nimport { readJsonFile } from \"@stryke/fs\";\nimport { resolvePackage } from \"@stryke/fs/resolve\";\nimport { StormJSON } from \"@stryke/json/storm-json\";\nimport { joinPaths } from \"@stryke/path\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { isEqual } from \"@stryke/path/is-equal\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport chalk from \"chalk\";\nimport { formatDistanceToNowStrict } from \"date-fns/formatDistanceToNowStrict\";\nimport defu from \"defu\";\nimport { existsSync } from \"node:fs\";\nimport { UserConfig } from \"tsdown/config\";\nimport { createResolver } from \"../_internal/helpers/resolver\";\n\nexport class PowerlinesBaseContext implements BaseContext {\n #timestamp: number = Date.now();\n\n #name: string = \"powerlines\";\n\n /**\n * The path to the Powerlines package\n */\n public powerlinesPath!: string;\n\n /**\n * The module resolver for the project\n */\n public resolver!: Resolver;\n\n /**\n * The options provided to the Powerlines process\n */\n public options!: ResolvedEngineOptions;\n\n /**\n * The input options used to initialize the context, which may be used when cloning the context to ensure the same configuration is applied to the new context\n */\n public inputOptions: Partial<EngineOptions> = {};\n\n /**\n * The parsed configuration file for the project\n */\n public configFile!: ParsedUserConfig;\n\n /**\n * The logger instance for the context, which can be used to create log messages with consistent formatting and metadata. This logger is extended by plugin contexts to include additional metadata such as the plugin name and category, which can be used to filter and format log messages in a more granular way.\n */\n public get logger(): Logger {\n return this.createLogger({ ...this.configFile.config, ...this.options });\n }\n\n /**\n * A timestamp representing when the context was initialized\n */\n public get timestamp(): number {\n return this.#timestamp;\n }\n\n public get logLevel(): LogLevelResolvedConfig {\n return resolveLogLevel(this.options.logLevel, this.options.mode);\n }\n\n /**\n * The environment paths for the project\n */\n public get envPaths(): EnvPaths {\n return getEnvPaths({\n orgId: this.options.organization,\n appId: this.options.framework || \"powerlines\",\n workspaceRoot: this.options.cwd\n });\n }\n\n /**\n * Creates a clone of the current context with the same configuration and workspace settings. This can be useful for running multiple builds in parallel or for creating isolated contexts for different parts of the build process.\n *\n * @remarks\n * The cloned context will have the same configuration and workspace settings as the original context, but will have a different build ID, release ID, and timestamp. The virtual file system and caches will also be separate between the original and cloned contexts.\n *\n * @returns A promise that resolves to the cloned context.\n */\n public async clone(): Promise<BaseContext> {\n const clone = new PowerlinesBaseContext();\n await clone.init(this.options);\n\n return clone;\n }\n\n /**\n * A logging function for fatal messages\n *\n * @param message - The message to log.\n */\n public fatal(message: string | LogMessage) {\n this.logger.error(\n isString(message) ? message : StormJSON.stringify(message)\n );\n }\n\n /**\n * A logging function for error messages\n *\n * @param message - The message to log.\n */\n public error(message: string | LogMessage) {\n this.logger.error(\n isString(message) ? message : StormJSON.stringify(message)\n );\n }\n\n /**\n * A logging function for warning messages\n *\n * @param message - The message to log.\n */\n public warn(message: string | LogMessage) {\n this.logger.warn(\n isString(message) ? message : StormJSON.stringify(message)\n );\n }\n\n /**\n * A logging function for informational messages\n *\n * @param message - The message to log.\n */\n public info(message: string | LogMessage) {\n this.logger.info(\n isString(message) ? message : StormJSON.stringify(message)\n );\n }\n\n /**\n * A logging function for debug messages\n *\n * @param message - The message to log.\n */\n public debug(message: string | LogMessage) {\n this.logger.debug(\n isString(message) ? message : StormJSON.stringify(message)\n );\n }\n\n /**\n * A logging function for trace messages\n *\n * @param message - The message to log.\n */\n public trace(message: string | LogMessage) {\n this.logger.trace(\n isString(message) ? message : StormJSON.stringify(message)\n );\n }\n\n /**\n * A function to create a timer for measuring the duration of asynchronous operations\n *\n * @example\n * ```ts\n * const stopTimer = context.timer(\"Your Async Operation\");\n * await performAsyncOperation();\n * stopTimer(); // \"Your Async Operation completed in 123.45 milliseconds\"\n * ```\n *\n * @param name - The name of the timer.\n * @returns A function that, when called, stops the timer and logs the duration.\n */\n public timer(name: string): () => void {\n const startDate = Date.now();\n const startDuration = performance.now();\n\n return () => {\n const duration = performance.now() - startDuration;\n this.logger.info({\n meta: {\n category: \"performance\"\n },\n message: `${chalk.bold.cyanBright(name)} completed in ${chalk.bold.cyanBright(\n duration < 1000\n ? `${duration.toFixed(2)} milliseconds`\n : formatDistanceToNowStrict(startDate)\n )}`\n });\n };\n }\n\n /**\n * Create a new logger instance\n *\n * @param options - The configuration options to use for the logger instance, which can be used to customize the appearance and behavior of the log messages generated by the logger. This is typically the name of the plugin or module that is creating the logger instance.\n * @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.\n */\n public createLogger(\n options: LoggerOptions,\n callback?: (message: string | LoggerMessage) => void\n ): Logger {\n return createLogger(\n this.options.name || this.options.root,\n options,\n callback\n );\n }\n\n /**\n * Extend the base logger with additional configuration options\n *\n * @param options - The configuration options to extend the base logger with, which can be used to add additional metadata or customize the appearance of log messages generated by the logger. This is typically the name of the plugin or module that is creating the logger instance, as well as any additional metadata such as the plugin category or environment.\n * @returns A new logger client instance that extends the base logger with the provided configuration options.\n */\n public extendLogger(options: LoggerOptions): Logger {\n return extendLogger(this.logger, options);\n }\n\n /**\n * Initialize the context with the provided configuration options\n *\n * @remarks\n * This method will set up the resolver and load the user configuration file based on the provided options. It is called during the construction of the context and can also be called when cloning the context to ensure that the new context has the same configuration and resolver setup.\n *\n * @param options - The configuration options to initialize the context with\n */\n protected async init(options: Partial<EngineOptions> = {}) {\n this.inputOptions = { ...options };\n\n if (!this.powerlinesPath) {\n const powerlinesPath = await resolvePackage(\"powerlines\");\n if (!powerlinesPath) {\n throw new Error(\"Could not resolve `powerlines` package location.\");\n }\n this.powerlinesPath = powerlinesPath;\n }\n\n const cwd = options.cwd || this.options?.cwd || process.cwd();\n const root = replacePath(\n (options.root || this.options?.root) &&\n (options.root || this.options.root).replace(/^\\.\\/?/, \"\") &&\n !isEqual(options.root || this.options.root, cwd)\n ? options.root || this.options.root\n : \".\",\n cwd\n );\n\n this.options = defu(\n {\n name: options.name,\n root,\n cwd,\n mode: options.mode,\n logLevel: options.logLevel,\n framework: options.framework,\n organization: options.organization,\n configFile: options.configFile\n },\n this.options ?? {},\n {\n mode: \"production\",\n framework: \"powerlines\"\n }\n ) as ResolvedEngineOptions;\n\n this.resolver = createResolver({\n workspaceRoot: cwd,\n root,\n cacheDir: this.envPaths.cache,\n mode: this.options.mode,\n logLevel: this.logLevel\n });\n\n this.configFile = await loadUserConfigFile(this.options, this.resolver);\n if (!this.options.name) {\n if (this.configFile.config) {\n if (\n isSetObject(this.configFile.config) &&\n isSetString((this.configFile.config as UserConfig).name)\n ) {\n this.options.name = (this.configFile.config as UserConfig).name;\n } else if (Array.isArray(this.configFile.config)) {\n for (const config of this.configFile.config) {\n if (\n isSetObject(config) &&\n isSetString((config as UserConfig).name)\n ) {\n this.options.name = (config as UserConfig).name;\n break;\n }\n }\n }\n }\n\n if (!this.options.name) {\n const packageJsonPath = joinPaths(\n appendPath(this.options.root, this.options.cwd),\n \"package.json\"\n );\n if (existsSync(packageJsonPath)) {\n const packageJson = await readJsonFile(packageJsonPath);\n this.options.name = packageJson.name;\n }\n\n if (!this.options.name) {\n const projectJsonPath = joinPaths(\n appendPath(this.options.root, this.options.cwd),\n \"project.json\"\n );\n if (existsSync(projectJsonPath)) {\n const projectJson = await readJsonFile(projectJsonPath);\n this.options.name = projectJson.name;\n }\n }\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAS,eAAe,SAA6C;AACnE,QAAO,KAAK,SAAS;EACnB,gBAAgB;EAChB,SACE,QAAQ,SAAS,gBACbA,YAAU,QAAQ,UAAU,OAAO,GACnC;EACN,aAAa,QAAQ,SAAS;EAC/B,CAAC;;;;;;;;AASJ,SAAgB,eAAe,SAA0C;CACvE,MAAM,eAAe,WACnBA,YAAU,QAAQ,eAAe,QAAQ,KAAK,EAC9C,eAAe,QAAQ,CACxB;AACD,cAAa,SAAS,WACpBA,YAAU,QAAQ,eAAe,QAAQ,KAAK,EAC9C,eAAe,QAAQ,CACxB;AAED,QAAO;;;;;ACZT,IAAa,wBAAb,MAAa,sBAA6C;CACxD,aAAqB,KAAK,KAAK;CAE/B,QAAgB;;;;CAKhB,AAAO;;;;CAKP,AAAO;;;;CAKP,AAAO;;;;CAKP,AAAO,eAAuC,EAAE;;;;CAKhD,AAAO;;;;CAKP,IAAW,SAAiB;AAC1B,SAAO,KAAK,aAAa;GAAE,GAAG,KAAK,WAAW;GAAQ,GAAG,KAAK;GAAS,CAAC;;;;;CAM1E,IAAW,YAAoB;AAC7B,SAAO,MAAKC;;CAGd,IAAW,WAAmC;AAC5C,SAAO,gBAAgB,KAAK,QAAQ,UAAU,KAAK,QAAQ,KAAK;;;;;CAMlE,IAAW,WAAqB;AAC9B,S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K,WAAW,OAAsB;aAClD,MAAM,QAAQ,KAAK,WAAW,OAAO,EAC9C;UAAK,MAAM,UAAU,KAAK,WAAW,OACnC,KACE,YAAY,OAAO,IACnB,YAAa,OAAsB,KAAK,EACxC;AACA,WAAK,QAAQ,OAAQ,OAAsB;AAC3C;;;;AAMR,OAAI,CAAC,KAAK,QAAQ,MAAM;IACtB,MAAM,kBAAkB,UACtB,WAAW,KAAK,QAAQ,MAAM,KAAK,QAAQ,IAAI,EAC/C,eACD;AACD,QAAI,WAAW,gBAAgB,EAAE;KAC/B,MAAM,cAAc,MAAM,aAAa,gBAAgB;AACvD,UAAK,QAAQ,OAAO,YAAY;;AAGlC,QAAI,CAAC,KAAK,QAAQ,MAAM;KACtB,MAAM,kBAAkB,UACtB,WAAW,KAAK,QAAQ,MAAM,KAAK,QAAQ,IAAI,EAC/C,eACD;AACD,SAAI,WAAW,gBAAgB,EAAE;MAC/B,MAAM,cAAc,MAAM,aAAa,gBAAgB;AACvD,WAAK,QAAQ,OAAO,YAAY"}
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_base_context = require('../base-context-5_AZZYFu.cjs');
3
- const require_engine_context = require('../engine-context-w4fts28j.cjs');
4
- const require_execution_context = require('../execution-context-0GmpbWbs.cjs');
2
+ const require_base_context = require('../base-context-CAA1druQ.cjs');
3
+ const require_engine_context = require('../engine-context-CUPubmrM.cjs');
4
+ const require_execution_context = require('../execution-context-BoJhCK0d.cjs');
5
5
 
6
6
  exports.PowerlinesBaseContext = require_base_context.PowerlinesBaseContext;
7
7
  exports.PowerlinesContext = require_execution_context.PowerlinesContext;