@powerlines/engine 0.43.31 → 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.
Files changed (31) hide show
  1. package/dist/_internal/worker.cjs +187 -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 +188 -170
  5. package/dist/_internal/worker.mjs.map +1 -1
  6. package/dist/api.cjs +6 -5
  7. package/dist/api.d.cts.map +1 -1
  8. package/dist/api.d.mts.map +1 -1
  9. package/dist/api.mjs +4 -3
  10. package/dist/api.mjs.map +1 -1
  11. package/dist/{base-context-CPoqO4io.cjs → base-context-DkGTyGX0.cjs} +34 -44
  12. package/dist/{base-context-SmQ6OfXm.mjs → base-context-Dv5OTHxZ.mjs} +35 -45
  13. package/dist/base-context-Dv5OTHxZ.mjs.map +1 -0
  14. package/dist/context/index.cjs +3 -3
  15. package/dist/context/index.d.cts +40 -36
  16. package/dist/context/index.d.cts.map +1 -1
  17. package/dist/context/index.d.mts +40 -36
  18. package/dist/context/index.d.mts.map +1 -1
  19. package/dist/context/index.mjs +3 -3
  20. package/dist/{engine-context-CEu21ZZf.cjs → engine-context-CDSR7PHF.cjs} +1 -1
  21. package/dist/{engine-context-D7CWyTsr.mjs → engine-context-CytME-Ht.mjs} +2 -2
  22. package/dist/{engine-context-D7CWyTsr.mjs.map → engine-context-CytME-Ht.mjs.map} +1 -1
  23. package/dist/{execution-context-DsT6s1du.cjs → execution-context-B-CVP76S.cjs} +148 -105
  24. package/dist/{execution-context-C_7IC8er.mjs → execution-context-F7RyGqff.mjs} +150 -107
  25. package/dist/execution-context-F7RyGqff.mjs.map +1 -0
  26. package/dist/index.cjs +8 -12
  27. package/dist/index.mjs +8 -12
  28. package/dist/index.mjs.map +1 -1
  29. package/package.json +3 -3
  30. package/dist/base-context-SmQ6OfXm.mjs.map +0 -1
  31. package/dist/execution-context-C_7IC8er.mjs.map +0 -1
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env -S NODE_OPTIONS=--enable-source-maps node
2
- import { colorText, createLog, extendLog } 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 } 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";
@@ -32,12 +32,10 @@ import { isString } from "@stryke/type-checks/is-string";
32
32
  import chalk from "chalk";
33
33
  import defu, { createDefu, defu as defu$1 } from "defu";
34
34
  import Handlebars from "handlebars";
35
- import { createLog as createLog$1 } from "@powerlines/core";
36
- import { CACHE_HASH_LENGTH, DEFAULT_ENVIRONMENT, GLOBAL_ENVIRONMENT, PLUGIN_NON_HOOK_FIELDS, ROOT_HASH_LENGTH } from "@powerlines/core/constants";
35
+ import { CACHE_HASH_LENGTH, DEFAULT_DEVELOPMENT_LOG_LEVEL, DEFAULT_ENVIRONMENT, DEFAULT_PRODUCTION_LOG_LEVEL, DEFAULT_TEST_LOG_LEVEL, GLOBAL_ENVIRONMENT, PLUGIN_NON_HOOK_FIELDS, ROOT_HASH_LENGTH } from "@powerlines/core/constants";
37
36
  import { readJsonFile, readJsonFileSync } from "@stryke/fs/json";
38
37
  import { deepClone } from "@stryke/helpers/deep-clone";
39
38
  import { joinPaths as joinPaths$1 } from "@stryke/path/join";
40
- import { isNull } from "@stryke/type-checks/is-null";
41
39
  import { uuid } from "@stryke/unique-id/uuid";
42
40
  import { getUniqueInputs, isTypeDefinition, resolveInputsSync } from "@powerlines/core/lib/entry";
43
41
  import { relativeToWorkspaceRoot } from "@stryke/fs/get-workspace-root";
@@ -52,7 +50,7 @@ import { create } from "flat-cache";
52
50
  import { parse } from "oxc-parser";
53
51
  import { Agent, Response, interceptors, setGlobalDispatcher } from "undici";
54
52
  import "@stryke/fs/remove-file";
55
- import { LogLevelLabel } from "@storm-software/config-tools/types";
53
+ import { LogCategories } from "@powerlines/core";
56
54
  import * as $ from "@stryke/capnp";
57
55
  import { readFileBuffer, readFileBufferSync, writeFileBuffer } from "@stryke/fs/buffer";
58
56
  import { correctPath, stripStars } from "@stryke/path/correct-path";
@@ -168,6 +166,40 @@ async function writeMetaFile(context) {
168
166
  await context.fs.write(metaFilePath, JSON.stringify(context.meta, null, 2));
169
167
  }
170
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
+
171
203
  //#endregion
172
204
  //#region schemas/fs.ts
173
205
  var FileMetadata_KeyValuePair = class extends $.Struct {
@@ -985,9 +1017,9 @@ var VirtualFileSystem = class VirtualFileSystem {
985
1017
  */
986
1018
  #context;
987
1019
  /**
988
- * The file system's logging function.
1020
+ * The file system's logger client utility.
989
1021
  */
990
- #log;
1022
+ #logger;
991
1023
  /**
992
1024
  * Normalizes a given module id by resolving it against the built-ins path.
993
1025
  *
@@ -1201,7 +1233,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1201
1233
  }
1202
1234
  }));
1203
1235
  } else result = new VirtualFileSystem(context, new $.Message().initRoot(FileSystem));
1204
- result.#log(LogLevelLabel.DEBUG, "Successfully completed virtual file system (VFS) initialization.");
1236
+ result.#logger.debug("Successfully completed virtual file system (VFS) initialization.");
1205
1237
  return result;
1206
1238
  }
1207
1239
  /**
@@ -1235,7 +1267,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1235
1267
  }
1236
1268
  });
1237
1269
  } else result = new VirtualFileSystem(context, new $.Message().initRoot(FileSystem));
1238
- result.#log(LogLevelLabel.DEBUG, "Successfully completed virtual file system (VFS) initialization.");
1270
+ result.#logger.debug("Successfully completed virtual file system (VFS) initialization.");
1239
1271
  return result;
1240
1272
  }
1241
1273
  /**
@@ -1369,7 +1401,10 @@ var VirtualFileSystem = class VirtualFileSystem {
1369
1401
  return ret;
1370
1402
  }, {});
1371
1403
  }
1372
- this.#log = context.extendLog("VFS");
1404
+ this.#logger = context.extendLogger({
1405
+ source: "VFS",
1406
+ category: "fs"
1407
+ });
1373
1408
  }
1374
1409
  /**
1375
1410
  * Asynchronously checks if a file exists in the virtual file system (VFS).
@@ -1496,7 +1531,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1496
1531
  listSync(path) {
1497
1532
  let resolvedPath = path;
1498
1533
  if (resolvedPath.includes("*")) {
1499
- this.#log(LogLevelLabel.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}`);
1500
1535
  resolvedPath = stripStars(resolvedPath);
1501
1536
  }
1502
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));
@@ -1510,7 +1545,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1510
1545
  async list(path) {
1511
1546
  let resolvedPath = path;
1512
1547
  if (resolvedPath.includes("*")) {
1513
- this.#log(LogLevelLabel.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}`);
1514
1549
  resolvedPath = stripStars(resolvedPath);
1515
1550
  }
1516
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));
@@ -1522,7 +1557,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1522
1557
  */
1523
1558
  async remove(path) {
1524
1559
  const normalizedPath = this.#normalizePath(path);
1525
- this.#log(LogLevelLabel.TRACE, `Removing file: ${normalizedPath}`);
1560
+ this.#logger.trace(`Removing file: ${normalizedPath}`);
1526
1561
  const { relativeKey, adapter } = this.#getStorage(normalizedPath);
1527
1562
  if (hasFileExtension(normalizedPath)) await adapter.remove(relativeKey);
1528
1563
  else await adapter.clear(relativeKey);
@@ -1540,7 +1575,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1540
1575
  */
1541
1576
  removeSync(path) {
1542
1577
  const normalizedPath = this.#normalizePath(path);
1543
- this.#log(LogLevelLabel.TRACE, `Removing file: ${normalizedPath}`);
1578
+ this.#logger.trace(`Removing file: ${normalizedPath}`);
1544
1579
  const { relativeKey, adapter } = this.#getStorage(normalizedPath);
1545
1580
  if (hasFileExtension(normalizedPath)) adapter.removeSync(relativeKey);
1546
1581
  else adapter.clearSync(relativeKey);
@@ -1686,7 +1721,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1686
1721
  const filePath = await this.resolve(path, void 0, { isFile: true });
1687
1722
  if (!filePath || !this.existsSync(filePath)) return;
1688
1723
  const { adapter } = this.#getStorage(filePath);
1689
- this.#log(LogLevelLabel.TRACE, `Reading ${adapter.name} file: ${filePath}`);
1724
+ this.#logger.trace(`Reading ${adapter.name} file: ${filePath}`);
1690
1725
  return await adapter.get(filePath) ?? void 0;
1691
1726
  }
1692
1727
  /**
@@ -1699,7 +1734,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1699
1734
  const filePath = this.resolveSync(path, void 0, { isFile: true });
1700
1735
  if (!filePath || !this.existsSync(filePath)) return;
1701
1736
  const { adapter } = this.#getStorage(filePath);
1702
- this.#log(LogLevelLabel.TRACE, `Reading ${adapter.name} file: ${filePath}`);
1737
+ this.#logger.trace(`Reading ${adapter.name} file: ${filePath}`);
1703
1738
  return adapter.getSync(filePath) ?? void 0;
1704
1739
  }
1705
1740
  /**
@@ -1714,15 +1749,15 @@ var VirtualFileSystem = class VirtualFileSystem {
1714
1749
  const meta = options.meta ?? {};
1715
1750
  const resolvedPath = await this.resolve(this.#normalizePath(path)) || path;
1716
1751
  const { relativeKey, adapter } = this.#getStorage(resolvedPath, options.storage);
1717
- this.#log(LogLevelLabel.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)})`);
1718
1753
  let code = data;
1719
1754
  try {
1720
1755
  if (!options.skipFormat) code = await format(this.#context, resolvedPath, data);
1721
1756
  } catch (err) {
1722
- if (DEFAULT_EXTENSIONS.includes(findFileExtensionSafe(resolvedPath, { fullExtension: true }))) this.#log(LogLevelLabel.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}`);
1723
1758
  code = data;
1724
1759
  }
1725
- this.#log(LogLevelLabel.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)})`);
1726
1761
  const id = this.#normalizeId(meta.id || resolvedPath);
1727
1762
  this.metadata[id] = {
1728
1763
  type: "normal",
@@ -1745,7 +1780,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1745
1780
  const meta = options.meta ?? {};
1746
1781
  const resolvedPath = this.resolveSync(this.#normalizePath(path)) || path;
1747
1782
  const { relativeKey, adapter } = this.#getStorage(resolvedPath, options.storage);
1748
- this.#log(LogLevelLabel.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)})`);
1749
1784
  const id = this.#normalizeId(meta.id || resolvedPath);
1750
1785
  this.metadata[id] = {
1751
1786
  type: "normal",
@@ -1909,7 +1944,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1909
1944
  async dispose() {
1910
1945
  if (!this.#isDisposed) {
1911
1946
  this.#isDisposed = true;
1912
- this.#log(LogLevelLabel.DEBUG, "Disposing virtual file system...");
1947
+ this.#logger.debug("Disposing virtual file system...");
1913
1948
  await this.remove(joinPaths$1(this.#context.dataPath, "fs.bin"));
1914
1949
  const message = new $.Message();
1915
1950
  const fs = message.initRoot(FileSystem);
@@ -1944,9 +1979,15 @@ var VirtualFileSystem = class VirtualFileSystem {
1944
1979
  await writeFileBuffer(joinPaths$1(this.#context.dataPath, "fs.bin"), message.toArrayBuffer());
1945
1980
  if (!this.#context.config.skipCache) this.resolverCache.save(true);
1946
1981
  await Promise.all(this.#getStorages().map(async (storage) => storage.adapter.dispose()));
1947
- this.#log(LogLevelLabel.TRACE, "Virtual file system has been disposed.");
1982
+ this.#logger.trace("Virtual file system has been disposed.");
1948
1983
  }
1949
1984
  }
1985
+ /**
1986
+ * Asynchronously disposes of the virtual file system (VFS) by saving its state to disk.
1987
+ *
1988
+ * @remarks
1989
+ * This method is automatically called when the VFS instance is used within a `using` block, or can be manually invoked to ensure that the VFS state is saved and resources are cleaned up properly.
1990
+ */
1950
1991
  async [Symbol.asyncDispose]() {
1951
1992
  return this.dispose();
1952
1993
  }
@@ -2119,7 +2160,6 @@ function createResolver(options) {
2119
2160
  //#region src/context/base-context.ts
2120
2161
  var PowerlinesBaseContext = class PowerlinesBaseContext {
2121
2162
  #timestamp = Date.now();
2122
- #logLevel = "info";
2123
2163
  /**
2124
2164
  * The path to the Powerlines package
2125
2165
  */
@@ -2141,27 +2181,22 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2141
2181
  */
2142
2182
  configFile;
2143
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
+ /**
2144
2193
  * A timestamp representing when the context was initialized
2145
2194
  */
2146
2195
  get timestamp() {
2147
- return new Date(this.#timestamp);
2196
+ return this.#timestamp;
2148
2197
  }
2149
2198
  get logLevel() {
2150
- return this.#logLevel || "info";
2151
- }
2152
- set logLevel(level) {
2153
- this.#logLevel = level;
2154
- }
2155
- /**
2156
- * The logger function
2157
- */
2158
- get log() {
2159
- const level = this.logLevel || "info";
2160
- if (!this.logger || this.logger.level !== level) this.logger = {
2161
- log: this.createLog(),
2162
- level
2163
- };
2164
- return this.logger.log;
2199
+ return resolveLogLevel(this.options.logLevel, this.options.mode);
2165
2200
  }
2166
2201
  /**
2167
2202
  * The environment paths for the project
@@ -2192,7 +2227,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2192
2227
  * @param message - The message to log.
2193
2228
  */
2194
2229
  fatal(message) {
2195
- this.log(LogLevelLabel.FATAL, isString(message) ? message : StormJSON.stringify(message));
2230
+ this.logger.error(isString(message) ? message : StormJSON.stringify(message));
2196
2231
  }
2197
2232
  /**
2198
2233
  * A logging function for error messages
@@ -2200,7 +2235,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2200
2235
  * @param message - The message to log.
2201
2236
  */
2202
2237
  error(message) {
2203
- this.log(LogLevelLabel.ERROR, isString(message) ? message : StormJSON.stringify(message));
2238
+ this.logger.error(isString(message) ? message : StormJSON.stringify(message));
2204
2239
  }
2205
2240
  /**
2206
2241
  * A logging function for warning messages
@@ -2208,7 +2243,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2208
2243
  * @param message - The message to log.
2209
2244
  */
2210
2245
  warn(message) {
2211
- this.log(LogLevelLabel.WARN, isString(message) ? message : StormJSON.stringify(message));
2246
+ this.logger.warn(isString(message) ? message : StormJSON.stringify(message));
2212
2247
  }
2213
2248
  /**
2214
2249
  * A logging function for informational messages
@@ -2216,7 +2251,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2216
2251
  * @param message - The message to log.
2217
2252
  */
2218
2253
  info(message) {
2219
- this.log(LogLevelLabel.INFO, isString(message) ? message : StormJSON.stringify(message));
2254
+ this.logger.info(isString(message) ? message : StormJSON.stringify(message));
2220
2255
  }
2221
2256
  /**
2222
2257
  * A logging function for debug messages
@@ -2224,7 +2259,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2224
2259
  * @param message - The message to log.
2225
2260
  */
2226
2261
  debug(message) {
2227
- this.log(LogLevelLabel.DEBUG, isString(message) ? message : StormJSON.stringify(message));
2262
+ this.logger.debug(isString(message) ? message : StormJSON.stringify(message));
2228
2263
  }
2229
2264
  /**
2230
2265
  * A logging function for trace messages
@@ -2232,7 +2267,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2232
2267
  * @param message - The message to log.
2233
2268
  */
2234
2269
  trace(message) {
2235
- this.log(LogLevelLabel.TRACE, isString(message) ? message : StormJSON.stringify(message));
2270
+ this.logger.trace(isString(message) ? message : StormJSON.stringify(message));
2236
2271
  }
2237
2272
  /**
2238
2273
  * A function to create a timer for measuring the duration of asynchronous operations
@@ -2252,35 +2287,31 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2252
2287
  const startDuration = performance.now();
2253
2288
  return () => {
2254
2289
  const duration = performance.now() - startDuration;
2255
- this.log(LogLevelLabel.PERFORMANCE, `${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
+ });
2256
2294
  };
2257
2295
  }
2258
2296
  /**
2259
2297
  * Create a new logger instance
2260
2298
  *
2261
- * @param source - The source name to use for the logger instance, which can be used to identify the origin of log messages in the logs for better traceability. This is typically the name of the plugin or module that is creating the logger instance.
2262
- * @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.
2263
2301
  */
2264
- createLog(source = null) {
2265
- return createLog(source, {
2266
- ...this.options,
2267
- logLevel: isNull(this.logLevel) ? "silent" : this.logLevel
2268
- });
2302
+ createLogger(options, callback) {
2303
+ return createLogger$1(this.options.name || this.options.framework || "powerlines", options, callback);
2269
2304
  }
2270
2305
  /**
2271
- * Extend the current logger instance with a new source
2306
+ * Extend the base logger with additional configuration options
2272
2307
  *
2273
- * @param source - The source name to use for the extended logger instance, which can be used to identify the origin of log messages in the logs for better traceability. This is typically the name of the plugin or module that is creating the logger instance.
2274
- * @returns A logger function
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.
2275
2310
  */
2276
- extendLog(source) {
2277
- return extendLog(this.log, source);
2311
+ extendLogger(options) {
2312
+ return extendLogger(this.logger, options);
2278
2313
  }
2279
2314
  /**
2280
- * A logger function specific to this context
2281
- */
2282
- logger;
2283
- /**
2284
2315
  * Initialize the context with the provided configuration options
2285
2316
  *
2286
2317
  * @remarks
@@ -2289,7 +2320,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2289
2320
  * @param options - The configuration options to initialize the context with
2290
2321
  */
2291
2322
  async init(options = {}) {
2292
- this.inputOptions = options;
2323
+ this.inputOptions = { ...options };
2293
2324
  if (!this.powerlinesPath) {
2294
2325
  const powerlinesPath = await resolvePackage("powerlines");
2295
2326
  if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
@@ -2301,6 +2332,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2301
2332
  root,
2302
2333
  cwd,
2303
2334
  mode: options.mode,
2335
+ logLevel: options.logLevel,
2304
2336
  framework: options.framework,
2305
2337
  organization: options.organization,
2306
2338
  configFile: options.configFile
@@ -2462,7 +2494,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2462
2494
  buildId: this.#buildId,
2463
2495
  releaseId: this.#releaseId,
2464
2496
  checksum: this.#checksum,
2465
- timestamp: this.timestamp.getTime(),
2497
+ timestamp: this.timestamp,
2466
2498
  rootHash: murmurhash({
2467
2499
  workspaceRoot: this.options?.cwd,
2468
2500
  root: this.config?.root
@@ -2566,6 +2598,18 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2566
2598
  }, {}) : this.config.resolve.alias : {});
2567
2599
  }
2568
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
+ /**
2569
2613
  * Gets the parser cache.
2570
2614
  */
2571
2615
  get parserCache() {
@@ -2662,6 +2706,9 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2662
2706
  headers: cached.headers
2663
2707
  });
2664
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()}`);
2665
2712
  const response = await fetchRequest(input, {
2666
2713
  timeout: 12e3,
2667
2714
  ...options
@@ -2675,6 +2722,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2675
2722
  if (!this.config.skipCache && !options.skipCache) try {
2676
2723
  this.requestCache.set(cacheKey, result);
2677
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]"}`);
2678
2726
  return new Response(result.body, {
2679
2727
  status: result.status,
2680
2728
  statusText: result.statusText,
@@ -3029,6 +3077,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3029
3077
  */
3030
3078
  async init(options = {}) {
3031
3079
  await super.init(options);
3080
+ this.options.executionId = options.executionId ?? this.options.executionId;
3032
3081
  this.options.executionIndex = options.executionIndex ?? this.options.executionIndex ?? 0;
3033
3082
  const projectJsonPath = joinPaths$1(this.options.cwd, this.options.root, "project.json");
3034
3083
  if (existsSync(projectJsonPath)) this.projectJson = await readJsonFile(projectJsonPath);
@@ -3049,6 +3098,13 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3049
3098
  * Initialize the context with the provided configuration options
3050
3099
  */
3051
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)}`);
3052
3108
  if (!this.inputOptions.mode && !this.config.userConfig?.mode && !this.config.inlineConfig?.mode && !this.config.pluginConfig?.mode) {
3053
3109
  this.options.mode = "production";
3054
3110
  this.config.mode = "production";
@@ -3058,10 +3114,6 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3058
3114
  this.config.framework = "powerlines";
3059
3115
  }
3060
3116
  this.resolvedConfig.compatibilityDate = resolveCompatibilityDates(this.config.inlineConfig.compatibilityDate ?? this.config.userConfig.compatibilityDate ?? this.config.pluginConfig.compatibilityDate, "latest");
3061
- this.logger = {
3062
- log: this.createLog(this.config.name),
3063
- level: isNull(this.logLevel) ? "silent" : this.logLevel
3064
- };
3065
3117
  this.config.input = getUniqueInputs(this.config.input);
3066
3118
  if (this.config.name?.startsWith("@") && this.config.name.split("/").filter(Boolean).length > 1) this.config.name = this.config.name.split("/").filter(Boolean)[1];
3067
3119
  this.config.title ??= titleCase(this.config.name);
@@ -3074,11 +3126,12 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3074
3126
  ret.push(plugin);
3075
3127
  return ret;
3076
3128
  }, []);
3077
- if (!this.config.userConfig?.logLevel && !this.config.inlineConfig?.logLevel) if (this.config.mode === "development") this.config.logLevel = "debug";
3078
- else this.config.logLevel = "info";
3079
- if (!this.config.userConfig?.tsconfig && !this.config.inlineConfig?.tsconfig) this.config.tsconfig = getTsconfigFilePath(this.options.cwd, this.options.root);
3129
+ if (!this.config.userConfig?.logLevel && !this.config.inlineConfig?.logLevel) if (this.config.mode === "development") this.config.logLevel = DEFAULT_DEVELOPMENT_LOG_LEVEL;
3130
+ else if (this.config.mode === "test") this.config.logLevel = DEFAULT_TEST_LOG_LEVEL;
3131
+ else this.config.logLevel = DEFAULT_PRODUCTION_LOG_LEVEL;
3132
+ if (!this.config.userConfig?.tsconfig && !this.config.inlineConfig?.tsconfig) this.config.tsconfig = getTsconfigFilePath(this.config.cwd, this.config.root);
3080
3133
  else if (this.config.tsconfig) this.config.tsconfig = replacePath(replacePathTokens(this, this.config.tsconfig), this.config.cwd);
3081
- this.resolvedConfig.output = defu(this.resolvedConfig.output ?? {}, {
3134
+ this.resolvedConfig.output = defu(this.config.output ?? {}, {
3082
3135
  path: joinPaths$1(this.config.root, "dist"),
3083
3136
  copy: { assets: [
3084
3137
  { glob: "LICENSE" },
@@ -3123,6 +3176,12 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3123
3176
  }));
3124
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;
3125
3178
  this.#fs ??= await VirtualFileSystem.create(this);
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)}`);
3126
3185
  }
3127
3186
  };
3128
3187
 
@@ -3172,7 +3231,7 @@ function mergeConfigs(currentResult, previousResults) {
3172
3231
  async function callHook(context, key, options, ...args) {
3173
3232
  const hooks = context.selectHooks(key, options);
3174
3233
  if (hooks.length > 0) {
3175
- 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")}`);
3176
3235
  const invokeHook = async (hook, hookArgs) => {
3177
3236
  return Reflect.apply(hook.handler, hook.context, hookArgs);
3178
3237
  };
@@ -3272,7 +3331,7 @@ function createPluginContext(pluginId, plugin, environment) {
3272
3331
  const normalizeMessage = (message) => {
3273
3332
  return isString(message) ? message : message.message;
3274
3333
  };
3275
- const log = environment.extendLog(pluginId, plugin.name.replaceAll(":", " - "));
3334
+ const logger = environment.extendLogger({ plugin: plugin.name.replaceAll(":", " - ") });
3276
3335
  const callHookFn = async (hook, options, ...args) => {
3277
3336
  return environment.$$internal.api.callHook(hook, {
3278
3337
  sequential: true,
@@ -3291,24 +3350,24 @@ function createPluginContext(pluginId, plugin, environment) {
3291
3350
  meta
3292
3351
  };
3293
3352
  if (prop === "id") return pluginId;
3294
- if (prop === "log" || prop === "logger") return log;
3353
+ if (prop === "logger") return logger;
3295
3354
  if (prop === "fatal") return (message) => {
3296
- log(LogLevelLabel.FATAL, normalizeMessage(message));
3355
+ logger.error(normalizeMessage(message));
3297
3356
  };
3298
3357
  if (prop === "error") return (message) => {
3299
- log(LogLevelLabel.ERROR, normalizeMessage(message));
3358
+ logger.error(normalizeMessage(message));
3300
3359
  };
3301
3360
  if (prop === "warn") return (message) => {
3302
- log(LogLevelLabel.WARN, normalizeMessage(message));
3361
+ logger.warn(normalizeMessage(message));
3303
3362
  };
3304
3363
  if (prop === "info") return (message) => {
3305
- log(LogLevelLabel.INFO, normalizeMessage(message));
3364
+ logger.info(normalizeMessage(message));
3306
3365
  };
3307
3366
  if (prop === "debug") return (message) => {
3308
- log(LogLevelLabel.DEBUG, normalizeMessage(message));
3367
+ logger.debug(normalizeMessage(message));
3309
3368
  };
3310
3369
  if (prop === "trace") return (message) => {
3311
- log(LogLevelLabel.TRACE, normalizeMessage(message));
3370
+ logger.trace(normalizeMessage(message));
3312
3371
  };
3313
3372
  return environment[prop];
3314
3373
  },
@@ -3327,7 +3386,7 @@ function createPluginContext(pluginId, plugin, environment) {
3327
3386
  "addPlugin",
3328
3387
  "selectHooks"
3329
3388
  ].includes(prop)) {
3330
- log(LogLevelLabel.WARN, `Cannot set read-only property "${String(prop)}"`);
3389
+ logger.warn(`Cannot set the read-only "${String(prop)}" property`);
3331
3390
  return false;
3332
3391
  }
3333
3392
  environment[prop] = value;
@@ -3381,50 +3440,26 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
3381
3440
  /**
3382
3441
  * Create a new logger instance
3383
3442
  *
3384
- * @param source - The source name to use for the logger instance, which can be used to identify the origin of log messages in the logs for better traceability. This is typically the name of the plugin or module that is creating the logger instance.
3385
- * @returns A logger function
3386
- */
3387
- createLog(source = null) {
3388
- return (level, ...args) => {
3389
- process.send?.({
3390
- id: uuid(),
3391
- type: "write-log",
3392
- executionId: this.options.executionId,
3393
- executionIndex: this.options.executionIndex,
3394
- timestamp: Date.now(),
3395
- payload: {
3396
- level,
3397
- source,
3398
- environment: this.environment?.name,
3399
- args
3400
- }
3401
- });
3402
- };
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.
3445
+ */
3446
+ createLogger(options, callback) {
3447
+ return super.createLogger({
3448
+ ...options,
3449
+ environment: this.environment?.name
3450
+ }, callback);
3403
3451
  }
3404
3452
  /**
3405
- * Extend the current logger instance with a new name
3406
- *
3407
- * @param source - The name of the source to use for the extended logger instance
3408
- * @param plugin - An optional plugin name to use for the extended logger instance, which can be used to identify the origin of log messages in the logs for better traceability. This is typically the name of the plugin or module that is creating the logger instance.
3409
- * @returns A logger function
3410
- */
3411
- extendLog(source, plugin) {
3412
- return (level, ...args) => {
3413
- process.send?.({
3414
- id: uuid(),
3415
- type: "write-log",
3416
- executionId: this.options.executionId,
3417
- executionIndex: this.options.executionIndex,
3418
- timestamp: Date.now(),
3419
- payload: {
3420
- level,
3421
- source,
3422
- plugin,
3423
- environment: this.environment?.name,
3424
- args
3425
- }
3426
- });
3427
- };
3453
+ * Extend the base logger with additional configuration options
3454
+ *
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.
3457
+ */
3458
+ extendLogger(options) {
3459
+ return super.extendLogger({
3460
+ ...options,
3461
+ environment: this.environment?.name
3462
+ });
3428
3463
  }
3429
3464
  /**
3430
3465
  * 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.
@@ -3610,29 +3645,28 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
3610
3645
  /**
3611
3646
  * Create a new logger instance
3612
3647
  *
3613
- * @param source - The source name to use for the logger instance, which can be used to identify the origin of log messages in the logs for better traceability. This is typically the name of the plugin or module that is creating the logger instance.
3614
- * @returns A logger function
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.
3615
3650
  */
3616
- createLog(source = null) {
3617
- const logger = createLog$1(source, {
3618
- ...this.config,
3619
- logLevel: isNull(this.config.logLevel) ? "silent" : this.config.logLevel
3651
+ createLogger(options, callback) {
3652
+ return super.createLogger({
3653
+ ...options,
3654
+ executionId: this.id,
3655
+ executionIndex: this.options.executionIndex
3656
+ }, callback);
3657
+ }
3658
+ /**
3659
+ * Extend the base logger with additional configuration options
3660
+ *
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.
3663
+ */
3664
+ extendLogger(options) {
3665
+ return super.extendLogger({
3666
+ ...options,
3667
+ executionId: this.id,
3668
+ executionIndex: this.options.executionIndex
3620
3669
  });
3621
- return (level, ...args) => {
3622
- logger(level, ...args);
3623
- process.send?.({
3624
- id: uuid(),
3625
- type: "write-log",
3626
- executionId: this.id,
3627
- executionIndex: this.options.executionIndex,
3628
- timestamp: Date.now(),
3629
- payload: {
3630
- source,
3631
- level,
3632
- args
3633
- }
3634
- });
3635
- };
3636
3670
  }
3637
3671
  /**
3638
3672
  * 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.
@@ -4838,44 +4872,28 @@ ${formatTypes(code)}
4838
4872
  //#endregion
4839
4873
  //#region src/_internal/worker.ts
4840
4874
  async function clean({ options, config }) {
4841
- const execution = await PowerlinesExecution.fromConfig(options, config);
4842
- await execution.clean(config);
4843
- await execution.finalize();
4875
+ await (await PowerlinesExecution.fromConfig(options, config)).clean(config);
4844
4876
  }
4845
4877
  async function prepare({ options, config }) {
4846
- const execution = await PowerlinesExecution.fromConfig(options, config);
4847
- await execution.prepare(config);
4848
- await execution.finalize();
4878
+ await (await PowerlinesExecution.fromConfig(options, config)).prepare(config);
4849
4879
  }
4850
4880
  async function types({ options, config }) {
4851
- const execution = await PowerlinesExecution.fromConfig(options, config);
4852
- await execution.types(config);
4853
- await execution.finalize();
4881
+ await (await PowerlinesExecution.fromConfig(options, config)).types(config);
4854
4882
  }
4855
4883
  async function lint({ options, config }) {
4856
- const execution = await PowerlinesExecution.fromConfig(options, config);
4857
- await execution.lint(config);
4858
- await execution.finalize();
4884
+ await (await PowerlinesExecution.fromConfig(options, config)).lint(config);
4859
4885
  }
4860
4886
  async function test({ options, config }) {
4861
- const execution = await PowerlinesExecution.fromConfig(options, config);
4862
- await execution.test(config);
4863
- await execution.finalize();
4887
+ await (await PowerlinesExecution.fromConfig(options, config)).test(config);
4864
4888
  }
4865
4889
  async function build({ options, config }) {
4866
- const execution = await PowerlinesExecution.fromConfig(options, config);
4867
- await execution.build(config);
4868
- await execution.finalize();
4890
+ await (await PowerlinesExecution.fromConfig(options, config)).build(config);
4869
4891
  }
4870
4892
  async function docs({ options, config }) {
4871
- const execution = await PowerlinesExecution.fromConfig(options, config);
4872
- await execution.docs(config);
4873
- await execution.finalize();
4893
+ await (await PowerlinesExecution.fromConfig(options, config)).docs(config);
4874
4894
  }
4875
4895
  async function deploy({ options, config }) {
4876
- const execution = await PowerlinesExecution.fromConfig(options, config);
4877
- await execution.deploy(config);
4878
- await execution.finalize();
4896
+ await (await PowerlinesExecution.fromConfig(options, config)).deploy(config);
4879
4897
  }
4880
4898
 
4881
4899
  //#endregion