@powerlines/engine 0.44.0 → 0.44.1

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.
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env -S NODE_OPTIONS=--enable-source-maps node
2
- import { colorText, createLogFn, extendLogFn } from "@powerlines/core/lib/logger";
3
2
  import { getFileHeaderWarningText, getTypescriptFileHeader } from "@powerlines/core/lib/utilities/file-header";
4
3
  import { format, formatFolder } from "@powerlines/core/lib/utilities/format";
5
- import { addPluginHook, dedupeHooklist, findInvalidPluginConfig, isDuplicate, isPlugin, isPluginConfig, isPluginConfigObject, isPluginConfigTuple, isPluginHook, isPluginHookField, mergeConfig, replacePathTokens, resolveLogLevel } from "@powerlines/core/plugin-utils";
4
+ import { addPluginHook, createLogger, dedupeHooklist, findInvalidPluginConfig, isDuplicate, isPlugin, isPluginConfig, isPluginConfigObject, isPluginConfigTuple, isPluginHook, isPluginHookField, mergeConfig, replacePathTokens, resolveLogLevel, withCustomLogger, withLogger } from "@powerlines/core/plugin-utils";
5
+ import { colorText, createLogger as createLogger$1, extendLogger } from "@powerlines/core/plugin-utils/logging";
6
6
  import { formatLogMessage } from "@storm-software/config-tools/logger/console";
7
7
  import { toArray } from "@stryke/convert/to-array";
8
8
  import { copyFiles } from "@stryke/fs/copy-file";
@@ -37,7 +37,6 @@ import { readJsonFile, readJsonFileSync } from "@stryke/fs/json";
37
37
  import { deepClone } from "@stryke/helpers/deep-clone";
38
38
  import { joinPaths as joinPaths$1 } from "@stryke/path/join";
39
39
  import { uuid } from "@stryke/unique-id/uuid";
40
- import { createLogFn as createLogFn$1, extendLogFn as extendLogFn$1 } from "@powerlines/core";
41
40
  import { getUniqueInputs, isTypeDefinition, resolveInputsSync } from "@powerlines/core/lib/entry";
42
41
  import { relativeToWorkspaceRoot } from "@stryke/fs/get-workspace-root";
43
42
  import { murmurhash } from "@stryke/hash";
@@ -51,6 +50,7 @@ import { create } from "flat-cache";
51
50
  import { parse } from "oxc-parser";
52
51
  import { Agent, Response, interceptors, setGlobalDispatcher } from "undici";
53
52
  import "@stryke/fs/remove-file";
53
+ import { LogCategories } from "@powerlines/core";
54
54
  import * as $ from "@stryke/capnp";
55
55
  import { readFileBuffer, readFileBufferSync, writeFileBuffer } from "@stryke/fs/buffer";
56
56
  import { correctPath, stripStars } from "@stryke/path/correct-path";
@@ -166,6 +166,40 @@ async function writeMetaFile(context) {
166
166
  await context.fs.write(metaFilePath, JSON.stringify(context.meta, null, 2));
167
167
  }
168
168
 
169
+ //#endregion
170
+ //#region src/_internal/ipc/send.ts
171
+ function sendWriteLogMessage(context, type, message) {
172
+ const meta = {
173
+ ...isSetObject(message) && isSetObject(message.meta) ? message.meta : {},
174
+ ...context.logger.options
175
+ };
176
+ process.send?.({
177
+ id: uuid(),
178
+ type: "write-log",
179
+ executionId: meta.executionId ?? context.config.executionId,
180
+ executionIndex: meta.executionIndex ?? context.config.executionIndex,
181
+ environment: meta.environment,
182
+ timestamp: Date.now(),
183
+ payload: {
184
+ meta: {
185
+ type,
186
+ category: meta.category ?? LogCategories.GENERAL,
187
+ logId: meta.logId ?? uuid(),
188
+ timestamp: meta.timestamp ?? Date.now(),
189
+ name: meta.name ?? context.config.name,
190
+ executionId: meta.executionId ?? context.config.executionId,
191
+ executionIndex: meta.executionIndex ?? context.config.executionIndex,
192
+ command: meta.command ?? context.config.command,
193
+ hook: meta.hook,
194
+ environment: meta.environment,
195
+ plugin: meta.plugin,
196
+ source: meta.source
197
+ },
198
+ message: isSetString(message) ? message : message.message
199
+ }
200
+ });
201
+ }
202
+
169
203
  //#endregion
170
204
  //#region schemas/fs.ts
171
205
  var FileMetadata_KeyValuePair = class extends $.Struct {
@@ -983,9 +1017,9 @@ var VirtualFileSystem = class VirtualFileSystem {
983
1017
  */
984
1018
  #context;
985
1019
  /**
986
- * The file system's logging function.
1020
+ * The file system's logger client utility.
987
1021
  */
988
- #log;
1022
+ #logger;
989
1023
  /**
990
1024
  * Normalizes a given module id by resolving it against the built-ins path.
991
1025
  *
@@ -1199,7 +1233,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1199
1233
  }
1200
1234
  }));
1201
1235
  } else result = new VirtualFileSystem(context, new $.Message().initRoot(FileSystem));
1202
- result.#log("debug", "Successfully completed virtual file system (VFS) initialization.");
1236
+ result.#logger.debug("Successfully completed virtual file system (VFS) initialization.");
1203
1237
  return result;
1204
1238
  }
1205
1239
  /**
@@ -1233,7 +1267,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1233
1267
  }
1234
1268
  });
1235
1269
  } else result = new VirtualFileSystem(context, new $.Message().initRoot(FileSystem));
1236
- result.#log("debug", "Successfully completed virtual file system (VFS) initialization.");
1270
+ result.#logger.debug("Successfully completed virtual file system (VFS) initialization.");
1237
1271
  return result;
1238
1272
  }
1239
1273
  /**
@@ -1367,7 +1401,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1367
1401
  return ret;
1368
1402
  }, {});
1369
1403
  }
1370
- this.#log = context.extendLog({
1404
+ this.#logger = context.extendLogger({
1371
1405
  source: "VFS",
1372
1406
  category: "fs"
1373
1407
  });
@@ -1497,7 +1531,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1497
1531
  listSync(path) {
1498
1532
  let resolvedPath = path;
1499
1533
  if (resolvedPath.includes("*")) {
1500
- this.#log("warn", `Invoking "listSync" with a glob pattern is not supported. It is likely you meant to use "globSync". Path: ${path}`);
1534
+ this.#logger.warn(`Invoking "listSync" with a glob pattern is not supported. It is likely you meant to use "globSync". Path: ${path}`);
1501
1535
  resolvedPath = stripStars(resolvedPath);
1502
1536
  }
1503
1537
  return getUnique(this.#getStorages(resolvedPath, true).map((storage) => storage.adapter.listSync(storage.relativeBase ? storage.base ? appendPath(storage.relativeBase, storage.base) : storage.relativeBase : storage.base)).flat().filter(Boolean));
@@ -1511,7 +1545,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1511
1545
  async list(path) {
1512
1546
  let resolvedPath = path;
1513
1547
  if (resolvedPath.includes("*")) {
1514
- this.#log("warn", `Invoking "list" with a glob pattern is not supported. It is likely you meant to use "glob". Path: ${path}`);
1548
+ this.#logger.warn(`Invoking "list" with a glob pattern is not supported. It is likely you meant to use "glob". Path: ${path}`);
1515
1549
  resolvedPath = stripStars(resolvedPath);
1516
1550
  }
1517
1551
  return getUnique((await Promise.all(this.#getStorages(resolvedPath, true).map(async (storage) => storage.adapter.list(storage.relativeBase ? storage.base ? appendPath(storage.relativeBase, storage.base) : storage.relativeBase : storage.base)))).flat().filter(Boolean));
@@ -1523,7 +1557,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1523
1557
  */
1524
1558
  async remove(path) {
1525
1559
  const normalizedPath = this.#normalizePath(path);
1526
- this.#log("trace", `Removing file: ${normalizedPath}`);
1560
+ this.#logger.trace(`Removing file: ${normalizedPath}`);
1527
1561
  const { relativeKey, adapter } = this.#getStorage(normalizedPath);
1528
1562
  if (hasFileExtension(normalizedPath)) await adapter.remove(relativeKey);
1529
1563
  else await adapter.clear(relativeKey);
@@ -1541,7 +1575,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1541
1575
  */
1542
1576
  removeSync(path) {
1543
1577
  const normalizedPath = this.#normalizePath(path);
1544
- this.#log("trace", `Removing file: ${normalizedPath}`);
1578
+ this.#logger.trace(`Removing file: ${normalizedPath}`);
1545
1579
  const { relativeKey, adapter } = this.#getStorage(normalizedPath);
1546
1580
  if (hasFileExtension(normalizedPath)) adapter.removeSync(relativeKey);
1547
1581
  else adapter.clearSync(relativeKey);
@@ -1687,7 +1721,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1687
1721
  const filePath = await this.resolve(path, void 0, { isFile: true });
1688
1722
  if (!filePath || !this.existsSync(filePath)) return;
1689
1723
  const { adapter } = this.#getStorage(filePath);
1690
- this.#log("trace", `Reading ${adapter.name} file: ${filePath}`);
1724
+ this.#logger.trace(`Reading ${adapter.name} file: ${filePath}`);
1691
1725
  return await adapter.get(filePath) ?? void 0;
1692
1726
  }
1693
1727
  /**
@@ -1700,7 +1734,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1700
1734
  const filePath = this.resolveSync(path, void 0, { isFile: true });
1701
1735
  if (!filePath || !this.existsSync(filePath)) return;
1702
1736
  const { adapter } = this.#getStorage(filePath);
1703
- this.#log("trace", `Reading ${adapter.name} file: ${filePath}`);
1737
+ this.#logger.trace(`Reading ${adapter.name} file: ${filePath}`);
1704
1738
  return adapter.getSync(filePath) ?? void 0;
1705
1739
  }
1706
1740
  /**
@@ -1715,15 +1749,15 @@ var VirtualFileSystem = class VirtualFileSystem {
1715
1749
  const meta = options.meta ?? {};
1716
1750
  const resolvedPath = await this.resolve(this.#normalizePath(path)) || path;
1717
1751
  const { relativeKey, adapter } = this.#getStorage(resolvedPath, options.storage);
1718
- this.#log("trace", `Writing ${resolvedPath} to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${prettyBytes(new Blob$1(toArray(data)).size)})`);
1752
+ this.#logger.trace(`Writing ${resolvedPath} to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${prettyBytes(new Blob$1(toArray(data)).size)})`);
1719
1753
  let code = data;
1720
1754
  try {
1721
1755
  if (!options.skipFormat) code = await format(this.#context, resolvedPath, data);
1722
1756
  } catch (err) {
1723
- if (DEFAULT_EXTENSIONS.includes(findFileExtensionSafe(resolvedPath, { fullExtension: true }))) this.#log("warn", `Failed to format file ${resolvedPath} before writing: ${err.message}`);
1757
+ if (DEFAULT_EXTENSIONS.includes(findFileExtensionSafe(resolvedPath, { fullExtension: true }))) this.#logger.warn(`Failed to format file ${resolvedPath} before writing: ${err.message}`);
1724
1758
  code = data;
1725
1759
  }
1726
- this.#log("trace", `Writing ${resolvedPath} to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${prettyBytes(new Blob$1(toArray(code)).size)})`);
1760
+ this.#logger.trace(`Writing ${resolvedPath} to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${prettyBytes(new Blob$1(toArray(code)).size)})`);
1727
1761
  const id = this.#normalizeId(meta.id || resolvedPath);
1728
1762
  this.metadata[id] = {
1729
1763
  type: "normal",
@@ -1746,7 +1780,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1746
1780
  const meta = options.meta ?? {};
1747
1781
  const resolvedPath = this.resolveSync(this.#normalizePath(path)) || path;
1748
1782
  const { relativeKey, adapter } = this.#getStorage(resolvedPath, options.storage);
1749
- this.#log("trace", `Writing ${resolvedPath} file to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${prettyBytes(new Blob$1(toArray(data)).size)})`);
1783
+ this.#logger.trace(`Writing ${resolvedPath} file to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${prettyBytes(new Blob$1(toArray(data)).size)})`);
1750
1784
  const id = this.#normalizeId(meta.id || resolvedPath);
1751
1785
  this.metadata[id] = {
1752
1786
  type: "normal",
@@ -1910,7 +1944,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1910
1944
  async dispose() {
1911
1945
  if (!this.#isDisposed) {
1912
1946
  this.#isDisposed = true;
1913
- this.#log("debug", "Disposing virtual file system...");
1947
+ this.#logger.debug("Disposing virtual file system...");
1914
1948
  await this.remove(joinPaths$1(this.#context.dataPath, "fs.bin"));
1915
1949
  const message = new $.Message();
1916
1950
  const fs = message.initRoot(FileSystem);
@@ -1945,7 +1979,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1945
1979
  await writeFileBuffer(joinPaths$1(this.#context.dataPath, "fs.bin"), message.toArrayBuffer());
1946
1980
  if (!this.#context.config.skipCache) this.resolverCache.save(true);
1947
1981
  await Promise.all(this.#getStorages().map(async (storage) => storage.adapter.dispose()));
1948
- this.#log("trace", "Virtual file system has been disposed.");
1982
+ this.#logger.trace("Virtual file system has been disposed.");
1949
1983
  }
1950
1984
  }
1951
1985
  /**
@@ -2147,6 +2181,15 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2147
2181
  */
2148
2182
  configFile;
2149
2183
  /**
2184
+ * 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.
2185
+ */
2186
+ get logger() {
2187
+ return this.createLogger({
2188
+ ...this.configFile.config,
2189
+ ...this.options
2190
+ });
2191
+ }
2192
+ /**
2150
2193
  * A timestamp representing when the context was initialized
2151
2194
  */
2152
2195
  get timestamp() {
@@ -2156,12 +2199,6 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2156
2199
  return resolveLogLevel(this.options.logLevel, this.options.mode);
2157
2200
  }
2158
2201
  /**
2159
- * The logger function
2160
- */
2161
- get log() {
2162
- return this.createLog();
2163
- }
2164
- /**
2165
2202
  * The environment paths for the project
2166
2203
  */
2167
2204
  get envPaths() {
@@ -2190,7 +2227,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2190
2227
  * @param message - The message to log.
2191
2228
  */
2192
2229
  fatal(message) {
2193
- this.log("error", isString(message) ? message : StormJSON.stringify(message));
2230
+ this.logger.error(isString(message) ? message : StormJSON.stringify(message));
2194
2231
  }
2195
2232
  /**
2196
2233
  * A logging function for error messages
@@ -2198,7 +2235,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2198
2235
  * @param message - The message to log.
2199
2236
  */
2200
2237
  error(message) {
2201
- this.log("error", isString(message) ? message : StormJSON.stringify(message));
2238
+ this.logger.error(isString(message) ? message : StormJSON.stringify(message));
2202
2239
  }
2203
2240
  /**
2204
2241
  * A logging function for warning messages
@@ -2206,7 +2243,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2206
2243
  * @param message - The message to log.
2207
2244
  */
2208
2245
  warn(message) {
2209
- this.log("warn", isString(message) ? message : StormJSON.stringify(message));
2246
+ this.logger.warn(isString(message) ? message : StormJSON.stringify(message));
2210
2247
  }
2211
2248
  /**
2212
2249
  * A logging function for informational messages
@@ -2214,7 +2251,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2214
2251
  * @param message - The message to log.
2215
2252
  */
2216
2253
  info(message) {
2217
- this.log("info", isString(message) ? message : StormJSON.stringify(message));
2254
+ this.logger.info(isString(message) ? message : StormJSON.stringify(message));
2218
2255
  }
2219
2256
  /**
2220
2257
  * A logging function for debug messages
@@ -2222,7 +2259,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2222
2259
  * @param message - The message to log.
2223
2260
  */
2224
2261
  debug(message) {
2225
- this.log("debug", isString(message) ? message : StormJSON.stringify(message));
2262
+ this.logger.debug(isString(message) ? message : StormJSON.stringify(message));
2226
2263
  }
2227
2264
  /**
2228
2265
  * A logging function for trace messages
@@ -2230,7 +2267,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2230
2267
  * @param message - The message to log.
2231
2268
  */
2232
2269
  trace(message) {
2233
- this.log("trace", isString(message) ? message : StormJSON.stringify(message));
2270
+ this.logger.trace(isString(message) ? message : StormJSON.stringify(message));
2234
2271
  }
2235
2272
  /**
2236
2273
  * A function to create a timer for measuring the duration of asynchronous operations
@@ -2250,38 +2287,31 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2250
2287
  const startDuration = performance.now();
2251
2288
  return () => {
2252
2289
  const duration = performance.now() - startDuration;
2253
- this.log({
2254
- level: "info",
2255
- category: "performance"
2256
- }, `${chalk.bold.cyanBright(name)} completed in ${chalk.bold.cyanBright(duration < 1e3 ? `${duration.toFixed(2)} milliseconds` : formatDistanceToNowStrict(startDate))}`);
2290
+ this.logger.info({
2291
+ meta: { category: "performance" },
2292
+ message: `${chalk.bold.cyanBright(name)} completed in ${chalk.bold.cyanBright(duration < 1e3 ? `${duration.toFixed(2)} milliseconds` : formatDistanceToNowStrict(startDate))}`
2293
+ });
2257
2294
  };
2258
2295
  }
2259
2296
  /**
2260
2297
  * Create a new logger instance
2261
2298
  *
2262
- * @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.
2263
- * @returns A logger function
2299
+ * @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.
2300
+ * @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
2264
2301
  */
2265
- createLog(config) {
2266
- return createLogFn({
2267
- ...this.options,
2268
- ...config
2269
- });
2302
+ createLogger(options, callback) {
2303
+ return createLogger$1(this.options.name || this.options.framework || "powerlines", options, callback);
2270
2304
  }
2271
2305
  /**
2272
- * Extend the current logger instance with a new source
2306
+ * Extend the base logger with additional configuration options
2273
2307
  *
2274
- * @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.
2275
- * @returns A new logger function that includes the badge in its output.
2308
+ * @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.
2309
+ * @returns A new logger client instance that extends the base logger with the provided configuration options.
2276
2310
  */
2277
- extendLog(config) {
2278
- return extendLogFn(this.log, config);
2311
+ extendLogger(options) {
2312
+ return extendLogger(this.logger, options);
2279
2313
  }
2280
2314
  /**
2281
- * A logger function specific to this context
2282
- */
2283
- logger;
2284
- /**
2285
2315
  * Initialize the context with the provided configuration options
2286
2316
  *
2287
2317
  * @remarks
@@ -2568,6 +2598,18 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2568
2598
  }, {}) : this.config.resolve.alias : {});
2569
2599
  }
2570
2600
  /**
2601
+ * 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.
2602
+ */
2603
+ get logger() {
2604
+ const options = {
2605
+ ...this.config,
2606
+ ...this.options
2607
+ };
2608
+ const logger = withLogger(createLogger(this.config.name, options), createLogger(this.config.name, options, (type, message) => sendWriteLogMessage(this, type, message)));
2609
+ if (this.config.customLogger) return withCustomLogger(logger, this.config.customLogger);
2610
+ return logger;
2611
+ }
2612
+ /**
2571
2613
  * Gets the parser cache.
2572
2614
  */
2573
2615
  get parserCache() {
@@ -2622,60 +2664,6 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2622
2664
  this.options = options;
2623
2665
  }
2624
2666
  /**
2625
- * Create a new log function with the specified configuration, which can include properties such as log level, colors, and other metadata to be included with each log message. This allows you to customize the behavior and appearance of the logger instance according to your needs.
2626
- *
2627
- * @param config - Optional configuration for the log function instance, which can include properties such as log level, colors, and other metadata to be included with each log message. This allows you to customize the behavior and appearance of the logger instance according to your needs.
2628
- * @returns A log function that can be used to log messages with the specified configuration.
2629
- */
2630
- createLog(config) {
2631
- const log = createLogFn$1({
2632
- ...config,
2633
- logLevel: this.logLevel
2634
- });
2635
- return (meta, ...args) => {
2636
- log(meta, ...args);
2637
- process.send?.({
2638
- id: uuid(),
2639
- type: "write-log",
2640
- executionId: config?.executionId ?? this.options.executionId,
2641
- executionIndex: config?.executionIndex ?? this.options.executionIndex,
2642
- timestamp: Date.now(),
2643
- payload: {
2644
- level: meta && isSetObject(meta) && isSetString(meta.level) ? meta.level : isSetString(meta) ? meta : "info",
2645
- ...config,
2646
- args
2647
- }
2648
- });
2649
- };
2650
- }
2651
- /**
2652
- * Extend the current log function instance with a new name
2653
- *
2654
- * @param config - The configuration for the extended log function instance, which can include properties such as log level, colors, and other metadata to be included with each log message. This allows you to customize the behavior and appearance of the log function instance according to your needs.
2655
- * @returns A log function
2656
- */
2657
- extendLog(config) {
2658
- const log = extendLogFn$1(this.log, {
2659
- ...config,
2660
- logLevel: this.logLevel
2661
- });
2662
- return (meta, ...args) => {
2663
- log(meta, ...args);
2664
- process.send?.({
2665
- id: uuid(),
2666
- type: "write-log",
2667
- executionId: config.executionId ?? this.options.executionId,
2668
- executionIndex: config.executionIndex ?? this.options.executionIndex,
2669
- timestamp: Date.now(),
2670
- payload: {
2671
- level: meta && isSetObject(meta) && isSetString(meta.level) ? meta.level : isSetString(meta) ? meta : "info",
2672
- ...config,
2673
- args
2674
- }
2675
- });
2676
- };
2677
- }
2678
- /**
2679
2667
  * 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.
2680
2668
  *
2681
2669
  * @remarks
@@ -2718,6 +2706,9 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2718
2706
  headers: cached.headers
2719
2707
  });
2720
2708
  }
2709
+ const logger = this.extendLogger({ category: "network" });
2710
+ const startTime = Date.now();
2711
+ logger.trace(`Sending fetch request (${options.method?.toUpperCase() || "GET"}): ${input.toString()}`);
2721
2712
  const response = await fetchRequest(input, {
2722
2713
  timeout: 12e3,
2723
2714
  ...options
@@ -2731,6 +2722,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2731
2722
  if (!this.config.skipCache && !options.skipCache) try {
2732
2723
  this.requestCache.set(cacheKey, result);
2733
2724
  } catch {}
2725
+ logger.trace(`Fetch request (${options.method?.toUpperCase() || "GET"}) completed in ${Date.now() - startTime}ms: ${input.toString()} - ${response.status} / ${response.statusText} \n - Response Headers: ${JSON.stringify(result.headers)}\n - Response Body: ${typeof result.body === "string" ? result.body.length > 1e3 ? `${result.body.slice(0, 1e3)}... (truncated, total length: ${result.body.length})` : result.body : "[Non-string body]"}`);
2734
2726
  return new Response(result.body, {
2735
2727
  status: result.status,
2736
2728
  statusText: result.statusText,
@@ -3106,6 +3098,13 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3106
3098
  * Initialize the context with the provided configuration options
3107
3099
  */
3108
3100
  async innerSetup() {
3101
+ const logger = this.extendLogger({ category: "config" });
3102
+ logger.debug(`Pre-setup Powerlines configuration object: \n${JSON.stringify({
3103
+ ...omit(this.config, ["plugins"]),
3104
+ userConfig: this.config.userConfig ? omit(this.config.userConfig, ["plugins"]) : {},
3105
+ inlineConfig: this.config.inlineConfig ? omit(this.config.inlineConfig, ["plugins"]) : {},
3106
+ pluginConfig: this.config.pluginConfig ? omit(this.config.pluginConfig, ["plugins"]) : {}
3107
+ }, null, 2)}`);
3109
3108
  if (!this.inputOptions.mode && !this.config.userConfig?.mode && !this.config.inlineConfig?.mode && !this.config.pluginConfig?.mode) {
3110
3109
  this.options.mode = "production";
3111
3110
  this.config.mode = "production";
@@ -3177,7 +3176,12 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3177
3176
  }));
3178
3177
  if (isSetString(this.config.output?.storage) && this.config.output.storage === "virtual" || isSetObject(this.config.output?.storage) && Object.values(this.config.output.storage).every((adapter) => adapter.preset === "virtual")) this.config.output.overwrite = true;
3179
3178
  this.#fs ??= await VirtualFileSystem.create(this);
3180
- this.extendLog({ category: "config" })("debug", `Resolved Powerlines configuration object: \n${JSON.stringify(this.resolvedConfig, null, 2)}`);
3179
+ logger.debug(`Post-setup Powerlines configuration object: \n${JSON.stringify({
3180
+ ...omit(this.config, ["plugins"]),
3181
+ userConfig: this.config.userConfig ? omit(this.config.userConfig, ["plugins"]) : {},
3182
+ inlineConfig: this.config.inlineConfig ? omit(this.config.inlineConfig, ["plugins"]) : {},
3183
+ pluginConfig: this.config.pluginConfig ? omit(this.config.pluginConfig, ["plugins"]) : {}
3184
+ }, null, 2)}`);
3181
3185
  }
3182
3186
  };
3183
3187
 
@@ -3227,7 +3231,7 @@ function mergeConfigs(currentResult, previousResults) {
3227
3231
  async function callHook(context, key, options, ...args) {
3228
3232
  const hooks = context.selectHooks(key, options);
3229
3233
  if (hooks.length > 0) {
3230
- context.debug(` 🧩 Calling ${hooks.length} ${chalk.bold.cyanBright(`${key}${options?.order ? ` (${options.order})` : ""}`)} plugin hook${hooks.length > 1 ? "s" : ""}:\n${hooks.map((hook, index) => ` ${index + 1}. ${colorText(hook.plugin.name)}`).join("\n")}`);
3234
+ context.extendLogger({ category: "hooks" }).debug(` 🧩 Calling ${hooks.length} ${chalk.bold.cyanBright(`${key}${options?.order ? ` (${options.order})` : ""}`)} plugin hook${hooks.length > 1 ? "s" : ""}:\n${hooks.map((hook, index) => ` ${index + 1}. ${colorText(hook.plugin.name)}`).join("\n")}`);
3231
3235
  const invokeHook = async (hook, hookArgs) => {
3232
3236
  return Reflect.apply(hook.handler, hook.context, hookArgs);
3233
3237
  };
@@ -3327,7 +3331,7 @@ function createPluginContext(pluginId, plugin, environment) {
3327
3331
  const normalizeMessage = (message) => {
3328
3332
  return isString(message) ? message : message.message;
3329
3333
  };
3330
- const log = environment.extendLog({ plugin: plugin.name.replaceAll(":", " - ") });
3334
+ const logger = environment.extendLogger({ plugin: plugin.name.replaceAll(":", " - ") });
3331
3335
  const callHookFn = async (hook, options, ...args) => {
3332
3336
  return environment.$$internal.api.callHook(hook, {
3333
3337
  sequential: true,
@@ -3346,24 +3350,24 @@ function createPluginContext(pluginId, plugin, environment) {
3346
3350
  meta
3347
3351
  };
3348
3352
  if (prop === "id") return pluginId;
3349
- if (prop === "log" || prop === "logger") return log;
3353
+ if (prop === "logger") return logger;
3350
3354
  if (prop === "fatal") return (message) => {
3351
- log("error", normalizeMessage(message));
3355
+ logger.error(normalizeMessage(message));
3352
3356
  };
3353
3357
  if (prop === "error") return (message) => {
3354
- log("error", normalizeMessage(message));
3358
+ logger.error(normalizeMessage(message));
3355
3359
  };
3356
3360
  if (prop === "warn") return (message) => {
3357
- log("warn", normalizeMessage(message));
3361
+ logger.warn(normalizeMessage(message));
3358
3362
  };
3359
3363
  if (prop === "info") return (message) => {
3360
- log("info", normalizeMessage(message));
3364
+ logger.info(normalizeMessage(message));
3361
3365
  };
3362
3366
  if (prop === "debug") return (message) => {
3363
- log("debug", normalizeMessage(message));
3367
+ logger.debug(normalizeMessage(message));
3364
3368
  };
3365
3369
  if (prop === "trace") return (message) => {
3366
- log("trace", normalizeMessage(message));
3370
+ logger.trace(normalizeMessage(message));
3367
3371
  };
3368
3372
  return environment[prop];
3369
3373
  },
@@ -3382,7 +3386,7 @@ function createPluginContext(pluginId, plugin, environment) {
3382
3386
  "addPlugin",
3383
3387
  "selectHooks"
3384
3388
  ].includes(prop)) {
3385
- log("warn", `Cannot set read-only property "${String(prop)}"`);
3389
+ logger.warn(`Cannot set the read-only "${String(prop)}" property`);
3386
3390
  return false;
3387
3391
  }
3388
3392
  environment[prop] = value;
@@ -3434,26 +3438,26 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
3434
3438
  return this.#hooks;
3435
3439
  }
3436
3440
  /**
3437
- * Create a new log function with the specified configuration, which can include properties such as log level, colors, and other metadata to be included with each log message. This allows you to customize the behavior and appearance of the logger instance according to your needs.
3441
+ * Create a new logger instance
3438
3442
  *
3439
- * @param config - Optional configuration for the log function instance, which can include properties such as log level, colors, and other metadata to be included with each log message. This allows you to customize the behavior and appearance of the logger instance according to your needs.
3440
- * @returns A log function that can be used to log messages with the specified configuration.
3443
+ * @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.
3444
+ * @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
3441
3445
  */
3442
- createLog(config) {
3443
- return super.createLog({
3444
- ...config,
3446
+ createLogger(options, callback) {
3447
+ return super.createLogger({
3448
+ ...options,
3445
3449
  environment: this.environment?.name
3446
- });
3450
+ }, callback);
3447
3451
  }
3448
3452
  /**
3449
- * Extend the current log function instance with a new name
3453
+ * Extend the base logger with additional configuration options
3450
3454
  *
3451
- * @param config - The configuration for the extended log function instance, which can include properties such as log level, colors, and other metadata to be included with each log message. This allows you to customize the behavior and appearance of the log function instance according to your needs.
3452
- * @returns A log function
3455
+ * @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.
3456
+ * @returns A new logger client instance that extends the base logger with the provided configuration options.
3453
3457
  */
3454
- extendLog(config) {
3455
- return super.extendLog({
3456
- ...config,
3458
+ extendLogger(options) {
3459
+ return super.extendLogger({
3460
+ ...options,
3457
3461
  environment: this.environment?.name
3458
3462
  });
3459
3463
  }
@@ -3639,27 +3643,27 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
3639
3643
  super(options);
3640
3644
  }
3641
3645
  /**
3642
- * Create a new log function with the specified configuration, which can include properties such as log level, colors, and other metadata to be included with each log message. This allows you to customize the behavior and appearance of the logger instance according to your needs.
3646
+ * Create a new logger instance
3643
3647
  *
3644
- * @param config - Optional configuration for the log function instance, which can include properties such as log level, colors, and other metadata to be included with each log message. This allows you to customize the behavior and appearance of the logger instance according to your needs.
3645
- * @returns A log function that can be used to log messages with the specified configuration.
3648
+ * @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.
3649
+ * @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
3646
3650
  */
3647
- createLog(config) {
3648
- return super.createLog({
3649
- ...config,
3651
+ createLogger(options, callback) {
3652
+ return super.createLogger({
3653
+ ...options,
3650
3654
  executionId: this.id,
3651
3655
  executionIndex: this.options.executionIndex
3652
- });
3656
+ }, callback);
3653
3657
  }
3654
3658
  /**
3655
- * Extend the current log function instance with a new name
3659
+ * Extend the base logger with additional configuration options
3656
3660
  *
3657
- * @param config - The configuration for the extended log function instance, which can include properties such as log level, colors, and other metadata to be included with each log message. This allows you to customize the behavior and appearance of the log function instance according to your needs.
3658
- * @returns A log function
3661
+ * @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.
3662
+ * @returns A new logger client instance that extends the base logger with the provided configuration options.
3659
3663
  */
3660
- extendLog(config) {
3661
- return super.extendLog({
3662
- ...config,
3664
+ extendLogger(options) {
3665
+ return super.extendLogger({
3666
+ ...options,
3663
3667
  executionId: this.id,
3664
3668
  executionIndex: this.options.executionIndex
3665
3669
  });
@@ -4868,44 +4872,28 @@ ${formatTypes(code)}
4868
4872
  //#endregion
4869
4873
  //#region src/_internal/worker.ts
4870
4874
  async function clean({ options, config }) {
4871
- const execution = await PowerlinesExecution.fromConfig(options, config);
4872
- await execution.clean(config);
4873
- await execution.finalize();
4875
+ await (await PowerlinesExecution.fromConfig(options, config)).clean(config);
4874
4876
  }
4875
4877
  async function prepare({ options, config }) {
4876
- const execution = await PowerlinesExecution.fromConfig(options, config);
4877
- await execution.prepare(config);
4878
- await execution.finalize();
4878
+ await (await PowerlinesExecution.fromConfig(options, config)).prepare(config);
4879
4879
  }
4880
4880
  async function types({ options, config }) {
4881
- const execution = await PowerlinesExecution.fromConfig(options, config);
4882
- await execution.types(config);
4883
- await execution.finalize();
4881
+ await (await PowerlinesExecution.fromConfig(options, config)).types(config);
4884
4882
  }
4885
4883
  async function lint({ options, config }) {
4886
- const execution = await PowerlinesExecution.fromConfig(options, config);
4887
- await execution.lint(config);
4888
- await execution.finalize();
4884
+ await (await PowerlinesExecution.fromConfig(options, config)).lint(config);
4889
4885
  }
4890
4886
  async function test({ options, config }) {
4891
- const execution = await PowerlinesExecution.fromConfig(options, config);
4892
- await execution.test(config);
4893
- await execution.finalize();
4887
+ await (await PowerlinesExecution.fromConfig(options, config)).test(config);
4894
4888
  }
4895
4889
  async function build({ options, config }) {
4896
- const execution = await PowerlinesExecution.fromConfig(options, config);
4897
- await execution.build(config);
4898
- await execution.finalize();
4890
+ await (await PowerlinesExecution.fromConfig(options, config)).build(config);
4899
4891
  }
4900
4892
  async function docs({ options, config }) {
4901
- const execution = await PowerlinesExecution.fromConfig(options, config);
4902
- await execution.docs(config);
4903
- await execution.finalize();
4893
+ await (await PowerlinesExecution.fromConfig(options, config)).docs(config);
4904
4894
  }
4905
4895
  async function deploy({ options, config }) {
4906
- const execution = await PowerlinesExecution.fromConfig(options, config);
4907
- await execution.deploy(config);
4908
- await execution.finalize();
4896
+ await (await PowerlinesExecution.fromConfig(options, config)).deploy(config);
4909
4897
  }
4910
4898
 
4911
4899
  //#endregion