@powerlines/engine 0.43.31 → 0.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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";
2
+ import { colorText, createLogFn, extendLogFn } from "@powerlines/core/lib/logger";
3
3
  import { getFileHeaderWarningText, getTypescriptFileHeader } from "@powerlines/core/lib/utilities/file-header";
4
4
  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";
5
+ import { addPluginHook, dedupeHooklist, findInvalidPluginConfig, isDuplicate, isPlugin, isPluginConfig, isPluginConfigObject, isPluginConfigTuple, isPluginHook, isPluginHookField, mergeConfig, replacePathTokens, resolveLogLevel } from "@powerlines/core/plugin-utils";
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,13 +32,12 @@ 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";
40
+ import { createLogFn as createLogFn$1, extendLogFn as extendLogFn$1 } from "@powerlines/core";
42
41
  import { getUniqueInputs, isTypeDefinition, resolveInputsSync } from "@powerlines/core/lib/entry";
43
42
  import { relativeToWorkspaceRoot } from "@stryke/fs/get-workspace-root";
44
43
  import { murmurhash } from "@stryke/hash";
@@ -52,7 +51,6 @@ import { create } from "flat-cache";
52
51
  import { parse } from "oxc-parser";
53
52
  import { Agent, Response, interceptors, setGlobalDispatcher } from "undici";
54
53
  import "@stryke/fs/remove-file";
55
- import { LogLevelLabel } from "@storm-software/config-tools/types";
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";
@@ -1201,7 +1199,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1201
1199
  }
1202
1200
  }));
1203
1201
  } else result = new VirtualFileSystem(context, new $.Message().initRoot(FileSystem));
1204
- result.#log(LogLevelLabel.DEBUG, "Successfully completed virtual file system (VFS) initialization.");
1202
+ result.#log("debug", "Successfully completed virtual file system (VFS) initialization.");
1205
1203
  return result;
1206
1204
  }
1207
1205
  /**
@@ -1235,7 +1233,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1235
1233
  }
1236
1234
  });
1237
1235
  } else result = new VirtualFileSystem(context, new $.Message().initRoot(FileSystem));
1238
- result.#log(LogLevelLabel.DEBUG, "Successfully completed virtual file system (VFS) initialization.");
1236
+ result.#log("debug", "Successfully completed virtual file system (VFS) initialization.");
1239
1237
  return result;
1240
1238
  }
1241
1239
  /**
@@ -1369,7 +1367,10 @@ var VirtualFileSystem = class VirtualFileSystem {
1369
1367
  return ret;
1370
1368
  }, {});
1371
1369
  }
1372
- this.#log = context.extendLog("VFS");
1370
+ this.#log = context.extendLog({
1371
+ source: "VFS",
1372
+ category: "fs"
1373
+ });
1373
1374
  }
1374
1375
  /**
1375
1376
  * Asynchronously checks if a file exists in the virtual file system (VFS).
@@ -1496,7 +1497,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1496
1497
  listSync(path) {
1497
1498
  let resolvedPath = path;
1498
1499
  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}`);
1500
+ this.#log("warn", `Invoking "listSync" with a glob pattern is not supported. It is likely you meant to use "globSync". Path: ${path}`);
1500
1501
  resolvedPath = stripStars(resolvedPath);
1501
1502
  }
1502
1503
  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 +1511,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1510
1511
  async list(path) {
1511
1512
  let resolvedPath = path;
1512
1513
  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}`);
1514
+ this.#log("warn", `Invoking "list" with a glob pattern is not supported. It is likely you meant to use "glob". Path: ${path}`);
1514
1515
  resolvedPath = stripStars(resolvedPath);
1515
1516
  }
1516
1517
  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 +1523,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1522
1523
  */
1523
1524
  async remove(path) {
1524
1525
  const normalizedPath = this.#normalizePath(path);
1525
- this.#log(LogLevelLabel.TRACE, `Removing file: ${normalizedPath}`);
1526
+ this.#log("trace", `Removing file: ${normalizedPath}`);
1526
1527
  const { relativeKey, adapter } = this.#getStorage(normalizedPath);
1527
1528
  if (hasFileExtension(normalizedPath)) await adapter.remove(relativeKey);
1528
1529
  else await adapter.clear(relativeKey);
@@ -1540,7 +1541,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1540
1541
  */
1541
1542
  removeSync(path) {
1542
1543
  const normalizedPath = this.#normalizePath(path);
1543
- this.#log(LogLevelLabel.TRACE, `Removing file: ${normalizedPath}`);
1544
+ this.#log("trace", `Removing file: ${normalizedPath}`);
1544
1545
  const { relativeKey, adapter } = this.#getStorage(normalizedPath);
1545
1546
  if (hasFileExtension(normalizedPath)) adapter.removeSync(relativeKey);
1546
1547
  else adapter.clearSync(relativeKey);
@@ -1686,7 +1687,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1686
1687
  const filePath = await this.resolve(path, void 0, { isFile: true });
1687
1688
  if (!filePath || !this.existsSync(filePath)) return;
1688
1689
  const { adapter } = this.#getStorage(filePath);
1689
- this.#log(LogLevelLabel.TRACE, `Reading ${adapter.name} file: ${filePath}`);
1690
+ this.#log("trace", `Reading ${adapter.name} file: ${filePath}`);
1690
1691
  return await adapter.get(filePath) ?? void 0;
1691
1692
  }
1692
1693
  /**
@@ -1699,7 +1700,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1699
1700
  const filePath = this.resolveSync(path, void 0, { isFile: true });
1700
1701
  if (!filePath || !this.existsSync(filePath)) return;
1701
1702
  const { adapter } = this.#getStorage(filePath);
1702
- this.#log(LogLevelLabel.TRACE, `Reading ${adapter.name} file: ${filePath}`);
1703
+ this.#log("trace", `Reading ${adapter.name} file: ${filePath}`);
1703
1704
  return adapter.getSync(filePath) ?? void 0;
1704
1705
  }
1705
1706
  /**
@@ -1714,15 +1715,15 @@ var VirtualFileSystem = class VirtualFileSystem {
1714
1715
  const meta = options.meta ?? {};
1715
1716
  const resolvedPath = await this.resolve(this.#normalizePath(path)) || path;
1716
1717
  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)})`);
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)})`);
1718
1719
  let code = data;
1719
1720
  try {
1720
1721
  if (!options.skipFormat) code = await format(this.#context, resolvedPath, data);
1721
1722
  } catch (err) {
1722
- if (DEFAULT_EXTENSIONS.includes(findFileExtensionSafe(resolvedPath, { fullExtension: true }))) this.#log(LogLevelLabel.WARN, `Failed to format file ${resolvedPath} before writing: ${err.message}`);
1723
+ if (DEFAULT_EXTENSIONS.includes(findFileExtensionSafe(resolvedPath, { fullExtension: true }))) this.#log("warn", `Failed to format file ${resolvedPath} before writing: ${err.message}`);
1723
1724
  code = data;
1724
1725
  }
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)})`);
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)})`);
1726
1727
  const id = this.#normalizeId(meta.id || resolvedPath);
1727
1728
  this.metadata[id] = {
1728
1729
  type: "normal",
@@ -1745,7 +1746,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1745
1746
  const meta = options.meta ?? {};
1746
1747
  const resolvedPath = this.resolveSync(this.#normalizePath(path)) || path;
1747
1748
  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)})`);
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)})`);
1749
1750
  const id = this.#normalizeId(meta.id || resolvedPath);
1750
1751
  this.metadata[id] = {
1751
1752
  type: "normal",
@@ -1909,7 +1910,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1909
1910
  async dispose() {
1910
1911
  if (!this.#isDisposed) {
1911
1912
  this.#isDisposed = true;
1912
- this.#log(LogLevelLabel.DEBUG, "Disposing virtual file system...");
1913
+ this.#log("debug", "Disposing virtual file system...");
1913
1914
  await this.remove(joinPaths$1(this.#context.dataPath, "fs.bin"));
1914
1915
  const message = new $.Message();
1915
1916
  const fs = message.initRoot(FileSystem);
@@ -1944,9 +1945,15 @@ var VirtualFileSystem = class VirtualFileSystem {
1944
1945
  await writeFileBuffer(joinPaths$1(this.#context.dataPath, "fs.bin"), message.toArrayBuffer());
1945
1946
  if (!this.#context.config.skipCache) this.resolverCache.save(true);
1946
1947
  await Promise.all(this.#getStorages().map(async (storage) => storage.adapter.dispose()));
1947
- this.#log(LogLevelLabel.TRACE, "Virtual file system has been disposed.");
1948
+ this.#log("trace", "Virtual file system has been disposed.");
1948
1949
  }
1949
1950
  }
1951
+ /**
1952
+ * Asynchronously disposes of the virtual file system (VFS) by saving its state to disk.
1953
+ *
1954
+ * @remarks
1955
+ * 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.
1956
+ */
1950
1957
  async [Symbol.asyncDispose]() {
1951
1958
  return this.dispose();
1952
1959
  }
@@ -2119,7 +2126,6 @@ function createResolver(options) {
2119
2126
  //#region src/context/base-context.ts
2120
2127
  var PowerlinesBaseContext = class PowerlinesBaseContext {
2121
2128
  #timestamp = Date.now();
2122
- #logLevel = "info";
2123
2129
  /**
2124
2130
  * The path to the Powerlines package
2125
2131
  */
@@ -2144,24 +2150,16 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2144
2150
  * A timestamp representing when the context was initialized
2145
2151
  */
2146
2152
  get timestamp() {
2147
- return new Date(this.#timestamp);
2153
+ return this.#timestamp;
2148
2154
  }
2149
2155
  get logLevel() {
2150
- return this.#logLevel || "info";
2151
- }
2152
- set logLevel(level) {
2153
- this.#logLevel = level;
2156
+ return resolveLogLevel(this.options.logLevel, this.options.mode);
2154
2157
  }
2155
2158
  /**
2156
2159
  * The logger function
2157
2160
  */
2158
2161
  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;
2162
+ return this.createLog();
2165
2163
  }
2166
2164
  /**
2167
2165
  * The environment paths for the project
@@ -2192,7 +2190,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2192
2190
  * @param message - The message to log.
2193
2191
  */
2194
2192
  fatal(message) {
2195
- this.log(LogLevelLabel.FATAL, isString(message) ? message : StormJSON.stringify(message));
2193
+ this.log("error", isString(message) ? message : StormJSON.stringify(message));
2196
2194
  }
2197
2195
  /**
2198
2196
  * A logging function for error messages
@@ -2200,7 +2198,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2200
2198
  * @param message - The message to log.
2201
2199
  */
2202
2200
  error(message) {
2203
- this.log(LogLevelLabel.ERROR, isString(message) ? message : StormJSON.stringify(message));
2201
+ this.log("error", isString(message) ? message : StormJSON.stringify(message));
2204
2202
  }
2205
2203
  /**
2206
2204
  * A logging function for warning messages
@@ -2208,7 +2206,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2208
2206
  * @param message - The message to log.
2209
2207
  */
2210
2208
  warn(message) {
2211
- this.log(LogLevelLabel.WARN, isString(message) ? message : StormJSON.stringify(message));
2209
+ this.log("warn", isString(message) ? message : StormJSON.stringify(message));
2212
2210
  }
2213
2211
  /**
2214
2212
  * A logging function for informational messages
@@ -2216,7 +2214,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2216
2214
  * @param message - The message to log.
2217
2215
  */
2218
2216
  info(message) {
2219
- this.log(LogLevelLabel.INFO, isString(message) ? message : StormJSON.stringify(message));
2217
+ this.log("info", isString(message) ? message : StormJSON.stringify(message));
2220
2218
  }
2221
2219
  /**
2222
2220
  * A logging function for debug messages
@@ -2224,7 +2222,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2224
2222
  * @param message - The message to log.
2225
2223
  */
2226
2224
  debug(message) {
2227
- this.log(LogLevelLabel.DEBUG, isString(message) ? message : StormJSON.stringify(message));
2225
+ this.log("debug", isString(message) ? message : StormJSON.stringify(message));
2228
2226
  }
2229
2227
  /**
2230
2228
  * A logging function for trace messages
@@ -2232,7 +2230,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2232
2230
  * @param message - The message to log.
2233
2231
  */
2234
2232
  trace(message) {
2235
- this.log(LogLevelLabel.TRACE, isString(message) ? message : StormJSON.stringify(message));
2233
+ this.log("trace", isString(message) ? message : StormJSON.stringify(message));
2236
2234
  }
2237
2235
  /**
2238
2236
  * A function to create a timer for measuring the duration of asynchronous operations
@@ -2252,29 +2250,32 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2252
2250
  const startDuration = performance.now();
2253
2251
  return () => {
2254
2252
  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))}`);
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))}`);
2256
2257
  };
2257
2258
  }
2258
2259
  /**
2259
2260
  * Create a new logger instance
2260
2261
  *
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
+ * @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.
2262
2263
  * @returns A logger function
2263
2264
  */
2264
- createLog(source = null) {
2265
- return createLog(source, {
2265
+ createLog(config) {
2266
+ return createLogFn({
2266
2267
  ...this.options,
2267
- logLevel: isNull(this.logLevel) ? "silent" : this.logLevel
2268
+ ...config
2268
2269
  });
2269
2270
  }
2270
2271
  /**
2271
2272
  * Extend the current logger instance with a new source
2272
2273
  *
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
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.
2275
2276
  */
2276
- extendLog(source) {
2277
- return extendLog(this.log, source);
2277
+ extendLog(config) {
2278
+ return extendLogFn(this.log, config);
2278
2279
  }
2279
2280
  /**
2280
2281
  * A logger function specific to this context
@@ -2289,7 +2290,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2289
2290
  * @param options - The configuration options to initialize the context with
2290
2291
  */
2291
2292
  async init(options = {}) {
2292
- this.inputOptions = options;
2293
+ this.inputOptions = { ...options };
2293
2294
  if (!this.powerlinesPath) {
2294
2295
  const powerlinesPath = await resolvePackage("powerlines");
2295
2296
  if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
@@ -2301,6 +2302,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2301
2302
  root,
2302
2303
  cwd,
2303
2304
  mode: options.mode,
2305
+ logLevel: options.logLevel,
2304
2306
  framework: options.framework,
2305
2307
  organization: options.organization,
2306
2308
  configFile: options.configFile
@@ -2462,7 +2464,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2462
2464
  buildId: this.#buildId,
2463
2465
  releaseId: this.#releaseId,
2464
2466
  checksum: this.#checksum,
2465
- timestamp: this.timestamp.getTime(),
2467
+ timestamp: this.timestamp,
2466
2468
  rootHash: murmurhash({
2467
2469
  workspaceRoot: this.options?.cwd,
2468
2470
  root: this.config?.root
@@ -2620,6 +2622,60 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2620
2622
  this.options = options;
2621
2623
  }
2622
2624
  /**
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
+ /**
2623
2679
  * 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.
2624
2680
  *
2625
2681
  * @remarks
@@ -3029,6 +3085,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3029
3085
  */
3030
3086
  async init(options = {}) {
3031
3087
  await super.init(options);
3088
+ this.options.executionId = options.executionId ?? this.options.executionId;
3032
3089
  this.options.executionIndex = options.executionIndex ?? this.options.executionIndex ?? 0;
3033
3090
  const projectJsonPath = joinPaths$1(this.options.cwd, this.options.root, "project.json");
3034
3091
  if (existsSync(projectJsonPath)) this.projectJson = await readJsonFile(projectJsonPath);
@@ -3058,10 +3115,6 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3058
3115
  this.config.framework = "powerlines";
3059
3116
  }
3060
3117
  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
3118
  this.config.input = getUniqueInputs(this.config.input);
3066
3119
  if (this.config.name?.startsWith("@") && this.config.name.split("/").filter(Boolean).length > 1) this.config.name = this.config.name.split("/").filter(Boolean)[1];
3067
3120
  this.config.title ??= titleCase(this.config.name);
@@ -3074,11 +3127,12 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3074
3127
  ret.push(plugin);
3075
3128
  return ret;
3076
3129
  }, []);
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);
3130
+ if (!this.config.userConfig?.logLevel && !this.config.inlineConfig?.logLevel) if (this.config.mode === "development") this.config.logLevel = DEFAULT_DEVELOPMENT_LOG_LEVEL;
3131
+ else if (this.config.mode === "test") this.config.logLevel = DEFAULT_TEST_LOG_LEVEL;
3132
+ else this.config.logLevel = DEFAULT_PRODUCTION_LOG_LEVEL;
3133
+ if (!this.config.userConfig?.tsconfig && !this.config.inlineConfig?.tsconfig) this.config.tsconfig = getTsconfigFilePath(this.config.cwd, this.config.root);
3080
3134
  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 ?? {}, {
3135
+ this.resolvedConfig.output = defu(this.config.output ?? {}, {
3082
3136
  path: joinPaths$1(this.config.root, "dist"),
3083
3137
  copy: { assets: [
3084
3138
  { glob: "LICENSE" },
@@ -3123,6 +3177,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3123
3177
  }));
3124
3178
  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
3179
  this.#fs ??= await VirtualFileSystem.create(this);
3180
+ this.extendLog({ category: "config" })("debug", `Resolved Powerlines configuration object: \n${JSON.stringify(this.resolvedConfig, null, 2)}`);
3126
3181
  }
3127
3182
  };
3128
3183
 
@@ -3272,7 +3327,7 @@ function createPluginContext(pluginId, plugin, environment) {
3272
3327
  const normalizeMessage = (message) => {
3273
3328
  return isString(message) ? message : message.message;
3274
3329
  };
3275
- const log = environment.extendLog(pluginId, plugin.name.replaceAll(":", " - "));
3330
+ const log = environment.extendLog({ plugin: plugin.name.replaceAll(":", " - ") });
3276
3331
  const callHookFn = async (hook, options, ...args) => {
3277
3332
  return environment.$$internal.api.callHook(hook, {
3278
3333
  sequential: true,
@@ -3293,22 +3348,22 @@ function createPluginContext(pluginId, plugin, environment) {
3293
3348
  if (prop === "id") return pluginId;
3294
3349
  if (prop === "log" || prop === "logger") return log;
3295
3350
  if (prop === "fatal") return (message) => {
3296
- log(LogLevelLabel.FATAL, normalizeMessage(message));
3351
+ log("error", normalizeMessage(message));
3297
3352
  };
3298
3353
  if (prop === "error") return (message) => {
3299
- log(LogLevelLabel.ERROR, normalizeMessage(message));
3354
+ log("error", normalizeMessage(message));
3300
3355
  };
3301
3356
  if (prop === "warn") return (message) => {
3302
- log(LogLevelLabel.WARN, normalizeMessage(message));
3357
+ log("warn", normalizeMessage(message));
3303
3358
  };
3304
3359
  if (prop === "info") return (message) => {
3305
- log(LogLevelLabel.INFO, normalizeMessage(message));
3360
+ log("info", normalizeMessage(message));
3306
3361
  };
3307
3362
  if (prop === "debug") return (message) => {
3308
- log(LogLevelLabel.DEBUG, normalizeMessage(message));
3363
+ log("debug", normalizeMessage(message));
3309
3364
  };
3310
3365
  if (prop === "trace") return (message) => {
3311
- log(LogLevelLabel.TRACE, normalizeMessage(message));
3366
+ log("trace", normalizeMessage(message));
3312
3367
  };
3313
3368
  return environment[prop];
3314
3369
  },
@@ -3327,7 +3382,7 @@ function createPluginContext(pluginId, plugin, environment) {
3327
3382
  "addPlugin",
3328
3383
  "selectHooks"
3329
3384
  ].includes(prop)) {
3330
- log(LogLevelLabel.WARN, `Cannot set read-only property "${String(prop)}"`);
3385
+ log("warn", `Cannot set read-only property "${String(prop)}"`);
3331
3386
  return false;
3332
3387
  }
3333
3388
  environment[prop] = value;
@@ -3379,52 +3434,28 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
3379
3434
  return this.#hooks;
3380
3435
  }
3381
3436
  /**
3382
- * Create a new logger instance
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.
3383
3438
  *
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
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.
3386
3441
  */
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
- };
3442
+ createLog(config) {
3443
+ return super.createLog({
3444
+ ...config,
3445
+ environment: this.environment?.name
3446
+ });
3403
3447
  }
3404
3448
  /**
3405
- * Extend the current logger instance with a new name
3449
+ * Extend the current log function instance with a new name
3406
3450
  *
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
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
3410
3453
  */
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
- };
3454
+ extendLog(config) {
3455
+ return super.extendLog({
3456
+ ...config,
3457
+ environment: this.environment?.name
3458
+ });
3428
3459
  }
3429
3460
  /**
3430
3461
  * 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.
@@ -3608,31 +3639,30 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
3608
3639
  super(options);
3609
3640
  }
3610
3641
  /**
3611
- * Create a new logger instance
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.
3612
3643
  *
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
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.
3615
3646
  */
3616
- createLog(source = null) {
3617
- const logger = createLog$1(source, {
3618
- ...this.config,
3619
- logLevel: isNull(this.config.logLevel) ? "silent" : this.config.logLevel
3647
+ createLog(config) {
3648
+ return super.createLog({
3649
+ ...config,
3650
+ executionId: this.id,
3651
+ executionIndex: this.options.executionIndex
3652
+ });
3653
+ }
3654
+ /**
3655
+ * Extend the current log function instance with a new name
3656
+ *
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
3659
+ */
3660
+ extendLog(config) {
3661
+ return super.extendLog({
3662
+ ...config,
3663
+ executionId: this.id,
3664
+ executionIndex: this.options.executionIndex
3620
3665
  });
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
3666
  }
3637
3667
  /**
3638
3668
  * 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.