@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,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";
@@ -64,13 +64,15 @@ import { fileURLToPath } from "node:url";
64
64
  import { isDirectory, isFile } from "@stryke/fs/is-file";
65
65
  import { readFile, readFileSync } from "@stryke/fs/read-file";
66
66
  import { writeFile, writeFileSync } from "@stryke/fs/write-file";
67
- import { unlinkSync } from "node:fs";
67
+ import { existsSync as existsSync$1, unlinkSync } from "node:fs";
68
68
  import { unlink } from "node:fs/promises";
69
69
  import { resolve as resolve$1 } from "node:path";
70
70
  import ts from "typescript";
71
71
  import { loadUserConfigFile } from "@powerlines/core/lib/config";
72
72
  import { getEnvPaths } from "@stryke/env/get-env-paths";
73
+ import { readJsonFile as readJsonFile$1 } from "@stryke/fs";
73
74
  import { StormJSON } from "@stryke/json/storm-json";
75
+ import { joinPaths as joinPaths$2 } from "@stryke/path";
74
76
  import { formatDistanceToNowStrict } from "date-fns/formatDistanceToNowStrict";
75
77
  import { createJiti } from "jiti";
76
78
  import { getField } from "@stryke/helpers/get-field";
@@ -166,6 +168,40 @@ async function writeMetaFile(context) {
166
168
  await context.fs.write(metaFilePath, JSON.stringify(context.meta, null, 2));
167
169
  }
168
170
 
171
+ //#endregion
172
+ //#region src/_internal/ipc/send.ts
173
+ function sendWriteLogMessage(context, type, message) {
174
+ const meta = {
175
+ ...isSetObject(message) && isSetObject(message.meta) ? message.meta : {},
176
+ ...context.logger.options
177
+ };
178
+ process.send?.({
179
+ id: uuid(),
180
+ type: "write-log",
181
+ executionId: meta.executionId ?? context.config.executionId,
182
+ executionIndex: meta.executionIndex ?? context.config.executionIndex,
183
+ environment: meta.environment,
184
+ timestamp: Date.now(),
185
+ payload: {
186
+ meta: {
187
+ type,
188
+ category: meta.category ?? LogCategories.GENERAL,
189
+ logId: meta.logId ?? uuid(),
190
+ timestamp: meta.timestamp ?? Date.now(),
191
+ name: meta.name ?? context.config.name,
192
+ executionId: meta.executionId ?? context.config.executionId,
193
+ executionIndex: meta.executionIndex ?? context.config.executionIndex,
194
+ command: meta.command ?? context.config.command,
195
+ hook: meta.hook,
196
+ environment: meta.environment,
197
+ plugin: meta.plugin,
198
+ source: meta.source
199
+ },
200
+ message: isSetString(message) ? message : message.message
201
+ }
202
+ });
203
+ }
204
+
169
205
  //#endregion
170
206
  //#region schemas/fs.ts
171
207
  var FileMetadata_KeyValuePair = class extends $.Struct {
@@ -983,9 +1019,9 @@ var VirtualFileSystem = class VirtualFileSystem {
983
1019
  */
984
1020
  #context;
985
1021
  /**
986
- * The file system's logging function.
1022
+ * The file system's logger client utility.
987
1023
  */
988
- #log;
1024
+ #logger;
989
1025
  /**
990
1026
  * Normalizes a given module id by resolving it against the built-ins path.
991
1027
  *
@@ -1199,7 +1235,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1199
1235
  }
1200
1236
  }));
1201
1237
  } else result = new VirtualFileSystem(context, new $.Message().initRoot(FileSystem));
1202
- result.#log("debug", "Successfully completed virtual file system (VFS) initialization.");
1238
+ result.#logger.debug("Successfully completed virtual file system (VFS) initialization.");
1203
1239
  return result;
1204
1240
  }
1205
1241
  /**
@@ -1233,7 +1269,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1233
1269
  }
1234
1270
  });
1235
1271
  } else result = new VirtualFileSystem(context, new $.Message().initRoot(FileSystem));
1236
- result.#log("debug", "Successfully completed virtual file system (VFS) initialization.");
1272
+ result.#logger.debug("Successfully completed virtual file system (VFS) initialization.");
1237
1273
  return result;
1238
1274
  }
1239
1275
  /**
@@ -1367,7 +1403,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1367
1403
  return ret;
1368
1404
  }, {});
1369
1405
  }
1370
- this.#log = context.extendLog({
1406
+ this.#logger = context.extendLogger({
1371
1407
  source: "VFS",
1372
1408
  category: "fs"
1373
1409
  });
@@ -1497,7 +1533,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1497
1533
  listSync(path) {
1498
1534
  let resolvedPath = path;
1499
1535
  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}`);
1536
+ this.#logger.warn(`Invoking "listSync" with a glob pattern is not supported. It is likely you meant to use "globSync". Path: ${path}`);
1501
1537
  resolvedPath = stripStars(resolvedPath);
1502
1538
  }
1503
1539
  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 +1547,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1511
1547
  async list(path) {
1512
1548
  let resolvedPath = path;
1513
1549
  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}`);
1550
+ this.#logger.warn(`Invoking "list" with a glob pattern is not supported. It is likely you meant to use "glob". Path: ${path}`);
1515
1551
  resolvedPath = stripStars(resolvedPath);
1516
1552
  }
1517
1553
  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 +1559,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1523
1559
  */
1524
1560
  async remove(path) {
1525
1561
  const normalizedPath = this.#normalizePath(path);
1526
- this.#log("trace", `Removing file: ${normalizedPath}`);
1562
+ this.#logger.trace(`Removing file: ${normalizedPath}`);
1527
1563
  const { relativeKey, adapter } = this.#getStorage(normalizedPath);
1528
1564
  if (hasFileExtension(normalizedPath)) await adapter.remove(relativeKey);
1529
1565
  else await adapter.clear(relativeKey);
@@ -1541,7 +1577,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1541
1577
  */
1542
1578
  removeSync(path) {
1543
1579
  const normalizedPath = this.#normalizePath(path);
1544
- this.#log("trace", `Removing file: ${normalizedPath}`);
1580
+ this.#logger.trace(`Removing file: ${normalizedPath}`);
1545
1581
  const { relativeKey, adapter } = this.#getStorage(normalizedPath);
1546
1582
  if (hasFileExtension(normalizedPath)) adapter.removeSync(relativeKey);
1547
1583
  else adapter.clearSync(relativeKey);
@@ -1687,7 +1723,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1687
1723
  const filePath = await this.resolve(path, void 0, { isFile: true });
1688
1724
  if (!filePath || !this.existsSync(filePath)) return;
1689
1725
  const { adapter } = this.#getStorage(filePath);
1690
- this.#log("trace", `Reading ${adapter.name} file: ${filePath}`);
1726
+ this.#logger.trace(`Reading ${adapter.name} file: ${filePath}`);
1691
1727
  return await adapter.get(filePath) ?? void 0;
1692
1728
  }
1693
1729
  /**
@@ -1700,7 +1736,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1700
1736
  const filePath = this.resolveSync(path, void 0, { isFile: true });
1701
1737
  if (!filePath || !this.existsSync(filePath)) return;
1702
1738
  const { adapter } = this.#getStorage(filePath);
1703
- this.#log("trace", `Reading ${adapter.name} file: ${filePath}`);
1739
+ this.#logger.trace(`Reading ${adapter.name} file: ${filePath}`);
1704
1740
  return adapter.getSync(filePath) ?? void 0;
1705
1741
  }
1706
1742
  /**
@@ -1715,15 +1751,15 @@ var VirtualFileSystem = class VirtualFileSystem {
1715
1751
  const meta = options.meta ?? {};
1716
1752
  const resolvedPath = await this.resolve(this.#normalizePath(path)) || path;
1717
1753
  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)})`);
1754
+ 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
1755
  let code = data;
1720
1756
  try {
1721
1757
  if (!options.skipFormat) code = await format(this.#context, resolvedPath, data);
1722
1758
  } catch (err) {
1723
- if (DEFAULT_EXTENSIONS.includes(findFileExtensionSafe(resolvedPath, { fullExtension: true }))) this.#log("warn", `Failed to format file ${resolvedPath} before writing: ${err.message}`);
1759
+ if (DEFAULT_EXTENSIONS.includes(findFileExtensionSafe(resolvedPath, { fullExtension: true }))) this.#logger.warn(`Failed to format file ${resolvedPath} before writing: ${err.message}`);
1724
1760
  code = data;
1725
1761
  }
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)})`);
1762
+ 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
1763
  const id = this.#normalizeId(meta.id || resolvedPath);
1728
1764
  this.metadata[id] = {
1729
1765
  type: "normal",
@@ -1746,7 +1782,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1746
1782
  const meta = options.meta ?? {};
1747
1783
  const resolvedPath = this.resolveSync(this.#normalizePath(path)) || path;
1748
1784
  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)})`);
1785
+ 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
1786
  const id = this.#normalizeId(meta.id || resolvedPath);
1751
1787
  this.metadata[id] = {
1752
1788
  type: "normal",
@@ -1910,7 +1946,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1910
1946
  async dispose() {
1911
1947
  if (!this.#isDisposed) {
1912
1948
  this.#isDisposed = true;
1913
- this.#log("debug", "Disposing virtual file system...");
1949
+ this.#logger.debug("Disposing virtual file system...");
1914
1950
  await this.remove(joinPaths$1(this.#context.dataPath, "fs.bin"));
1915
1951
  const message = new $.Message();
1916
1952
  const fs = message.initRoot(FileSystem);
@@ -1945,7 +1981,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1945
1981
  await writeFileBuffer(joinPaths$1(this.#context.dataPath, "fs.bin"), message.toArrayBuffer());
1946
1982
  if (!this.#context.config.skipCache) this.resolverCache.save(true);
1947
1983
  await Promise.all(this.#getStorages().map(async (storage) => storage.adapter.dispose()));
1948
- this.#log("trace", "Virtual file system has been disposed.");
1984
+ this.#logger.trace("Virtual file system has been disposed.");
1949
1985
  }
1950
1986
  }
1951
1987
  /**
@@ -2126,6 +2162,7 @@ function createResolver(options) {
2126
2162
  //#region src/context/base-context.ts
2127
2163
  var PowerlinesBaseContext = class PowerlinesBaseContext {
2128
2164
  #timestamp = Date.now();
2165
+ #name = "powerlines";
2129
2166
  /**
2130
2167
  * The path to the Powerlines package
2131
2168
  */
@@ -2147,6 +2184,15 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2147
2184
  */
2148
2185
  configFile;
2149
2186
  /**
2187
+ * 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.
2188
+ */
2189
+ get logger() {
2190
+ return this.createLogger({
2191
+ ...this.configFile.config,
2192
+ ...this.options
2193
+ });
2194
+ }
2195
+ /**
2150
2196
  * A timestamp representing when the context was initialized
2151
2197
  */
2152
2198
  get timestamp() {
@@ -2156,12 +2202,6 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2156
2202
  return resolveLogLevel(this.options.logLevel, this.options.mode);
2157
2203
  }
2158
2204
  /**
2159
- * The logger function
2160
- */
2161
- get log() {
2162
- return this.createLog();
2163
- }
2164
- /**
2165
2205
  * The environment paths for the project
2166
2206
  */
2167
2207
  get envPaths() {
@@ -2190,7 +2230,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2190
2230
  * @param message - The message to log.
2191
2231
  */
2192
2232
  fatal(message) {
2193
- this.log("error", isString(message) ? message : StormJSON.stringify(message));
2233
+ this.logger.error(isString(message) ? message : StormJSON.stringify(message));
2194
2234
  }
2195
2235
  /**
2196
2236
  * A logging function for error messages
@@ -2198,7 +2238,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2198
2238
  * @param message - The message to log.
2199
2239
  */
2200
2240
  error(message) {
2201
- this.log("error", isString(message) ? message : StormJSON.stringify(message));
2241
+ this.logger.error(isString(message) ? message : StormJSON.stringify(message));
2202
2242
  }
2203
2243
  /**
2204
2244
  * A logging function for warning messages
@@ -2206,7 +2246,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2206
2246
  * @param message - The message to log.
2207
2247
  */
2208
2248
  warn(message) {
2209
- this.log("warn", isString(message) ? message : StormJSON.stringify(message));
2249
+ this.logger.warn(isString(message) ? message : StormJSON.stringify(message));
2210
2250
  }
2211
2251
  /**
2212
2252
  * A logging function for informational messages
@@ -2214,7 +2254,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2214
2254
  * @param message - The message to log.
2215
2255
  */
2216
2256
  info(message) {
2217
- this.log("info", isString(message) ? message : StormJSON.stringify(message));
2257
+ this.logger.info(isString(message) ? message : StormJSON.stringify(message));
2218
2258
  }
2219
2259
  /**
2220
2260
  * A logging function for debug messages
@@ -2222,7 +2262,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2222
2262
  * @param message - The message to log.
2223
2263
  */
2224
2264
  debug(message) {
2225
- this.log("debug", isString(message) ? message : StormJSON.stringify(message));
2265
+ this.logger.debug(isString(message) ? message : StormJSON.stringify(message));
2226
2266
  }
2227
2267
  /**
2228
2268
  * A logging function for trace messages
@@ -2230,7 +2270,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2230
2270
  * @param message - The message to log.
2231
2271
  */
2232
2272
  trace(message) {
2233
- this.log("trace", isString(message) ? message : StormJSON.stringify(message));
2273
+ this.logger.trace(isString(message) ? message : StormJSON.stringify(message));
2234
2274
  }
2235
2275
  /**
2236
2276
  * A function to create a timer for measuring the duration of asynchronous operations
@@ -2250,38 +2290,31 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2250
2290
  const startDuration = performance.now();
2251
2291
  return () => {
2252
2292
  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))}`);
2293
+ this.logger.info({
2294
+ meta: { category: "performance" },
2295
+ message: `${chalk.bold.cyanBright(name)} completed in ${chalk.bold.cyanBright(duration < 1e3 ? `${duration.toFixed(2)} milliseconds` : formatDistanceToNowStrict(startDate))}`
2296
+ });
2257
2297
  };
2258
2298
  }
2259
2299
  /**
2260
2300
  * Create a new logger instance
2261
2301
  *
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
2302
+ * @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.
2303
+ * @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
2264
2304
  */
2265
- createLog(config) {
2266
- return createLogFn({
2267
- ...this.options,
2268
- ...config
2269
- });
2305
+ createLogger(options, callback) {
2306
+ return createLogger$1(this.options.name || this.options.root, options, callback);
2270
2307
  }
2271
2308
  /**
2272
- * Extend the current logger instance with a new source
2309
+ * Extend the base logger with additional configuration options
2273
2310
  *
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.
2311
+ * @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.
2312
+ * @returns A new logger client instance that extends the base logger with the provided configuration options.
2276
2313
  */
2277
- extendLog(config) {
2278
- return extendLogFn(this.log, config);
2314
+ extendLogger(options) {
2315
+ return extendLogger(this.logger, options);
2279
2316
  }
2280
2317
  /**
2281
- * A logger function specific to this context
2282
- */
2283
- logger;
2284
- /**
2285
2318
  * Initialize the context with the provided configuration options
2286
2319
  *
2287
2320
  * @remarks
@@ -2299,6 +2332,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2299
2332
  const cwd = options.cwd || this.options?.cwd || process.cwd();
2300
2333
  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);
2301
2334
  this.options = defu({
2335
+ name: options.name,
2302
2336
  root,
2303
2337
  cwd,
2304
2338
  mode: options.mode,
@@ -2318,6 +2352,31 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2318
2352
  logLevel: this.logLevel
2319
2353
  });
2320
2354
  this.configFile = await loadUserConfigFile(this.options, this.resolver);
2355
+ if (!this.options.name) {
2356
+ if (this.configFile.config) {
2357
+ if (isSetObject(this.configFile.config) && isSetString(this.configFile.config.name)) this.options.name = this.configFile.config.name;
2358
+ else if (Array.isArray(this.configFile.config)) {
2359
+ for (const config of this.configFile.config) if (isSetObject(config) && isSetString(config.name)) {
2360
+ this.options.name = config.name;
2361
+ break;
2362
+ }
2363
+ }
2364
+ }
2365
+ if (!this.options.name) {
2366
+ const packageJsonPath = joinPaths$2(appendPath(this.options.root, this.options.cwd), "package.json");
2367
+ if (existsSync$1(packageJsonPath)) {
2368
+ const packageJson = await readJsonFile$1(packageJsonPath);
2369
+ this.options.name = packageJson.name;
2370
+ }
2371
+ if (!this.options.name) {
2372
+ const projectJsonPath = joinPaths$2(appendPath(this.options.root, this.options.cwd), "project.json");
2373
+ if (existsSync$1(projectJsonPath)) {
2374
+ const projectJson = await readJsonFile$1(projectJsonPath);
2375
+ this.options.name = projectJson.name;
2376
+ }
2377
+ }
2378
+ }
2379
+ }
2321
2380
  }
2322
2381
  };
2323
2382
 
@@ -2568,6 +2627,18 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2568
2627
  }, {}) : this.config.resolve.alias : {});
2569
2628
  }
2570
2629
  /**
2630
+ * 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.
2631
+ */
2632
+ get logger() {
2633
+ const options = {
2634
+ ...this.config,
2635
+ ...this.options
2636
+ };
2637
+ const logger = withLogger(createLogger(this.config.name, options), createLogger(this.config.name, options, (type, message) => sendWriteLogMessage(this, type, message)));
2638
+ if (this.config.customLogger) return withCustomLogger(logger, this.config.customLogger);
2639
+ return logger;
2640
+ }
2641
+ /**
2571
2642
  * Gets the parser cache.
2572
2643
  */
2573
2644
  get parserCache() {
@@ -2622,60 +2693,6 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2622
2693
  this.options = options;
2623
2694
  }
2624
2695
  /**
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
2696
  * 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
2697
  *
2681
2698
  * @remarks
@@ -2718,6 +2735,9 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2718
2735
  headers: cached.headers
2719
2736
  });
2720
2737
  }
2738
+ const logger = this.extendLogger({ category: "network" });
2739
+ const startTime = Date.now();
2740
+ logger.trace(`Sending fetch request (${options.method?.toUpperCase() || "GET"}): ${input.toString()}`);
2721
2741
  const response = await fetchRequest(input, {
2722
2742
  timeout: 12e3,
2723
2743
  ...options
@@ -2731,6 +2751,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2731
2751
  if (!this.config.skipCache && !options.skipCache) try {
2732
2752
  this.requestCache.set(cacheKey, result);
2733
2753
  } catch {}
2754
+ 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
2755
  return new Response(result.body, {
2735
2756
  status: result.status,
2736
2757
  statusText: result.statusText,
@@ -3106,6 +3127,13 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3106
3127
  * Initialize the context with the provided configuration options
3107
3128
  */
3108
3129
  async innerSetup() {
3130
+ const logger = this.extendLogger({ category: "config" });
3131
+ logger.trace(`Pre-setup Powerlines configuration object: \n${JSON.stringify({
3132
+ ...omit(this.config, ["plugins"]),
3133
+ userConfig: this.config.userConfig ? omit(this.config.userConfig, ["plugins"]) : {},
3134
+ inlineConfig: this.config.inlineConfig ? omit(this.config.inlineConfig, ["plugins"]) : {},
3135
+ pluginConfig: this.config.pluginConfig ? omit(this.config.pluginConfig, ["plugins"]) : {}
3136
+ }, null, 2)}`);
3109
3137
  if (!this.inputOptions.mode && !this.config.userConfig?.mode && !this.config.inlineConfig?.mode && !this.config.pluginConfig?.mode) {
3110
3138
  this.options.mode = "production";
3111
3139
  this.config.mode = "production";
@@ -3132,8 +3160,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3132
3160
  else this.config.logLevel = DEFAULT_PRODUCTION_LOG_LEVEL;
3133
3161
  if (!this.config.userConfig?.tsconfig && !this.config.inlineConfig?.tsconfig) this.config.tsconfig = getTsconfigFilePath(this.config.cwd, this.config.root);
3134
3162
  else if (this.config.tsconfig) this.config.tsconfig = replacePath(replacePathTokens(this, this.config.tsconfig), this.config.cwd);
3135
- this.resolvedConfig.output = defu(this.config.output ?? {}, {
3136
- path: joinPaths$1(this.config.root, "dist"),
3163
+ this.config.output = defu(this.config.output ?? {}, {
3137
3164
  copy: { assets: [
3138
3165
  { glob: "LICENSE" },
3139
3166
  {
@@ -3150,6 +3177,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3150
3177
  });
3151
3178
  this.config.output.format = getUnique(toArray(this.config.output?.format ?? (this.config.projectType === "library" ? ["cjs", "esm"] : ["esm"])));
3152
3179
  if (this.config.output.path) this.config.output.path = appendPath(replacePathTokens(this, this.config.output.path), this.config.cwd);
3180
+ else this.config.output.path = appendPath(joinPaths$1(this.config.root, "dist"), this.config.cwd);
3153
3181
  if (this.config.output.copy !== false) {
3154
3182
  this.config.output.copy ??= {};
3155
3183
  if (!this.config.root.replace(/^\.\/?/, "")) this.config.output.copy.path = this.config.output.copy.path ? appendPath(replacePathTokens(this, this.config.output.copy.path), this.config.cwd) : this.config.output.path;
@@ -3177,7 +3205,12 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3177
3205
  }));
3178
3206
  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
3207
  this.#fs ??= await VirtualFileSystem.create(this);
3180
- this.extendLog({ category: "config" })("debug", `Resolved Powerlines configuration object: \n${JSON.stringify(this.resolvedConfig, null, 2)}`);
3208
+ if (isSetObject(this.config.userConfig) && isSetObject(this.config.inlineConfig) && isSetObject(this.config.pluginConfig)) logger.debug(`Resolved Powerlines configuration object: \n${JSON.stringify({
3209
+ ...omit(this.config, ["plugins"]),
3210
+ userConfig: this.config.userConfig ? omit(this.config.userConfig, ["plugins"]) : {},
3211
+ inlineConfig: this.config.inlineConfig ? omit(this.config.inlineConfig, ["plugins"]) : {},
3212
+ pluginConfig: this.config.pluginConfig ? omit(this.config.pluginConfig, ["plugins"]) : {}
3213
+ }, null, 2)}`);
3181
3214
  }
3182
3215
  };
3183
3216
 
@@ -3227,7 +3260,7 @@ function mergeConfigs(currentResult, previousResults) {
3227
3260
  async function callHook(context, key, options, ...args) {
3228
3261
  const hooks = context.selectHooks(key, options);
3229
3262
  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")}`);
3263
+ 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
3264
  const invokeHook = async (hook, hookArgs) => {
3232
3265
  return Reflect.apply(hook.handler, hook.context, hookArgs);
3233
3266
  };
@@ -3327,7 +3360,7 @@ function createPluginContext(pluginId, plugin, environment) {
3327
3360
  const normalizeMessage = (message) => {
3328
3361
  return isString(message) ? message : message.message;
3329
3362
  };
3330
- const log = environment.extendLog({ plugin: plugin.name.replaceAll(":", " - ") });
3363
+ const logger = environment.extendLogger({ plugin: plugin.name.replaceAll(":", " - ") });
3331
3364
  const callHookFn = async (hook, options, ...args) => {
3332
3365
  return environment.$$internal.api.callHook(hook, {
3333
3366
  sequential: true,
@@ -3346,24 +3379,24 @@ function createPluginContext(pluginId, plugin, environment) {
3346
3379
  meta
3347
3380
  };
3348
3381
  if (prop === "id") return pluginId;
3349
- if (prop === "log" || prop === "logger") return log;
3382
+ if (prop === "logger") return logger;
3350
3383
  if (prop === "fatal") return (message) => {
3351
- log("error", normalizeMessage(message));
3384
+ logger.error(normalizeMessage(message));
3352
3385
  };
3353
3386
  if (prop === "error") return (message) => {
3354
- log("error", normalizeMessage(message));
3387
+ logger.error(normalizeMessage(message));
3355
3388
  };
3356
3389
  if (prop === "warn") return (message) => {
3357
- log("warn", normalizeMessage(message));
3390
+ logger.warn(normalizeMessage(message));
3358
3391
  };
3359
3392
  if (prop === "info") return (message) => {
3360
- log("info", normalizeMessage(message));
3393
+ logger.info(normalizeMessage(message));
3361
3394
  };
3362
3395
  if (prop === "debug") return (message) => {
3363
- log("debug", normalizeMessage(message));
3396
+ logger.debug(normalizeMessage(message));
3364
3397
  };
3365
3398
  if (prop === "trace") return (message) => {
3366
- log("trace", normalizeMessage(message));
3399
+ logger.trace(normalizeMessage(message));
3367
3400
  };
3368
3401
  return environment[prop];
3369
3402
  },
@@ -3382,7 +3415,7 @@ function createPluginContext(pluginId, plugin, environment) {
3382
3415
  "addPlugin",
3383
3416
  "selectHooks"
3384
3417
  ].includes(prop)) {
3385
- log("warn", `Cannot set read-only property "${String(prop)}"`);
3418
+ logger.warn(`Cannot set the read-only "${String(prop)}" property`);
3386
3419
  return false;
3387
3420
  }
3388
3421
  environment[prop] = value;
@@ -3434,26 +3467,26 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
3434
3467
  return this.#hooks;
3435
3468
  }
3436
3469
  /**
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.
3470
+ * Create a new logger instance
3438
3471
  *
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.
3472
+ * @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.
3473
+ * @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
3441
3474
  */
3442
- createLog(config) {
3443
- return super.createLog({
3444
- ...config,
3475
+ createLogger(options, callback) {
3476
+ return super.createLogger({
3477
+ ...options,
3445
3478
  environment: this.environment?.name
3446
- });
3479
+ }, callback);
3447
3480
  }
3448
3481
  /**
3449
- * Extend the current log function instance with a new name
3482
+ * Extend the base logger with additional configuration options
3450
3483
  *
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
3484
+ * @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.
3485
+ * @returns A new logger client instance that extends the base logger with the provided configuration options.
3453
3486
  */
3454
- extendLog(config) {
3455
- return super.extendLog({
3456
- ...config,
3487
+ extendLogger(options) {
3488
+ return super.extendLogger({
3489
+ ...options,
3457
3490
  environment: this.environment?.name
3458
3491
  });
3459
3492
  }
@@ -3639,27 +3672,27 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
3639
3672
  super(options);
3640
3673
  }
3641
3674
  /**
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.
3675
+ * Create a new logger instance
3643
3676
  *
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.
3677
+ * @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.
3678
+ * @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.
3646
3679
  */
3647
- createLog(config) {
3648
- return super.createLog({
3649
- ...config,
3680
+ createLogger(options, callback) {
3681
+ return super.createLogger({
3682
+ ...options,
3650
3683
  executionId: this.id,
3651
3684
  executionIndex: this.options.executionIndex
3652
- });
3685
+ }, callback);
3653
3686
  }
3654
3687
  /**
3655
- * Extend the current log function instance with a new name
3688
+ * Extend the base logger with additional configuration options
3656
3689
  *
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
3690
+ * @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.
3691
+ * @returns A new logger client instance that extends the base logger with the provided configuration options.
3659
3692
  */
3660
- extendLog(config) {
3661
- return super.extendLog({
3662
- ...config,
3693
+ extendLogger(options) {
3694
+ return super.extendLogger({
3695
+ ...options,
3663
3696
  executionId: this.id,
3664
3697
  executionIndex: this.options.executionIndex
3665
3698
  });
@@ -4868,44 +4901,28 @@ ${formatTypes(code)}
4868
4901
  //#endregion
4869
4902
  //#region src/_internal/worker.ts
4870
4903
  async function clean({ options, config }) {
4871
- const execution = await PowerlinesExecution.fromConfig(options, config);
4872
- await execution.clean(config);
4873
- await execution.finalize();
4904
+ await (await PowerlinesExecution.fromConfig(options, config)).clean(config);
4874
4905
  }
4875
4906
  async function prepare({ options, config }) {
4876
- const execution = await PowerlinesExecution.fromConfig(options, config);
4877
- await execution.prepare(config);
4878
- await execution.finalize();
4907
+ await (await PowerlinesExecution.fromConfig(options, config)).prepare(config);
4879
4908
  }
4880
4909
  async function types({ options, config }) {
4881
- const execution = await PowerlinesExecution.fromConfig(options, config);
4882
- await execution.types(config);
4883
- await execution.finalize();
4910
+ await (await PowerlinesExecution.fromConfig(options, config)).types(config);
4884
4911
  }
4885
4912
  async function lint({ options, config }) {
4886
- const execution = await PowerlinesExecution.fromConfig(options, config);
4887
- await execution.lint(config);
4888
- await execution.finalize();
4913
+ await (await PowerlinesExecution.fromConfig(options, config)).lint(config);
4889
4914
  }
4890
4915
  async function test({ options, config }) {
4891
- const execution = await PowerlinesExecution.fromConfig(options, config);
4892
- await execution.test(config);
4893
- await execution.finalize();
4916
+ await (await PowerlinesExecution.fromConfig(options, config)).test(config);
4894
4917
  }
4895
4918
  async function build({ options, config }) {
4896
- const execution = await PowerlinesExecution.fromConfig(options, config);
4897
- await execution.build(config);
4898
- await execution.finalize();
4919
+ await (await PowerlinesExecution.fromConfig(options, config)).build(config);
4899
4920
  }
4900
4921
  async function docs({ options, config }) {
4901
- const execution = await PowerlinesExecution.fromConfig(options, config);
4902
- await execution.docs(config);
4903
- await execution.finalize();
4922
+ await (await PowerlinesExecution.fromConfig(options, config)).docs(config);
4904
4923
  }
4905
4924
  async function deploy({ options, config }) {
4906
- const execution = await PowerlinesExecution.fromConfig(options, config);
4907
- await execution.deploy(config);
4908
- await execution.finalize();
4925
+ await (await PowerlinesExecution.fromConfig(options, config)).deploy(config);
4909
4926
  }
4910
4927
 
4911
4928
  //#endregion