@powerlines/engine 0.43.30 → 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.
Files changed (39) hide show
  1. package/dist/_internal/worker.cjs +195 -95
  2. package/dist/_internal/worker.mjs +198 -98
  3. package/dist/_internal/worker.mjs.map +1 -1
  4. package/dist/api.cjs +11 -8
  5. package/dist/api.d.cts.map +1 -1
  6. package/dist/api.d.mts.map +1 -1
  7. package/dist/api.mjs +11 -8
  8. package/dist/api.mjs.map +1 -1
  9. package/dist/{base-context-B9AROf66.cjs → base-context-5_AZZYFu.cjs} +27 -32
  10. package/dist/{base-context-D8a2XGIK.mjs → base-context-D_ZidDDm.mjs} +29 -34
  11. package/dist/base-context-D_ZidDDm.mjs.map +1 -0
  12. package/dist/context/index.cjs +3 -3
  13. package/dist/context/index.d.cts +67 -32
  14. package/dist/context/index.d.cts.map +1 -1
  15. package/dist/context/index.d.mts +67 -32
  16. package/dist/context/index.d.mts.map +1 -1
  17. package/dist/context/index.mjs +3 -3
  18. package/dist/{engine-context-DsA9XGVb.mjs → engine-context-PQ3BgcgR.mjs} +36 -11
  19. package/dist/engine-context-PQ3BgcgR.mjs.map +1 -0
  20. package/dist/{engine-context-qCVw66U_.cjs → engine-context-w4fts28j.cjs} +36 -10
  21. package/dist/{execution-context-CprxWvYn.cjs → execution-context-0GmpbWbs.cjs} +176 -71
  22. package/dist/{execution-context-CBJxP2B2.mjs → execution-context-zedP0h4Z.mjs} +179 -74
  23. package/dist/execution-context-zedP0h4Z.mjs.map +1 -0
  24. package/dist/index.cjs +140 -58
  25. package/dist/index.d.cts.map +1 -1
  26. package/dist/index.d.mts.map +1 -1
  27. package/dist/index.mjs +140 -58
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/storage/index.cjs +1 -1
  30. package/dist/storage/index.d.mts +1 -1
  31. package/dist/storage/index.mjs +1 -1
  32. package/dist/typescript/index.d.mts +1 -1
  33. package/dist/{virtual-BNdKVkRw.cjs → virtual-1hYa9zCy.cjs} +1 -1
  34. package/dist/{virtual-gIlTc3Lj.mjs → virtual-CUgOdyIa.mjs} +2 -2
  35. package/dist/{virtual-gIlTc3Lj.mjs.map → virtual-CUgOdyIa.mjs.map} +1 -1
  36. package/package.json +3 -3
  37. package/dist/base-context-D8a2XGIK.mjs.map +0 -1
  38. package/dist/engine-context-DsA9XGVb.mjs.map +0 -1
  39. package/dist/execution-context-CBJxP2B2.mjs.map +0 -1
@@ -1,34 +1,34 @@
1
- import { t as PowerlinesBaseContext } from "./base-context-D8a2XGIK.mjs";
1
+ import { t as PowerlinesBaseContext } from "./base-context-D_ZidDDm.mjs";
2
2
  import { a as FileSystem } from "./fs-D1nIP45P.mjs";
3
- import { n as FileSystemStorageAdapter, t as VirtualStorageAdapter } from "./virtual-gIlTc3Lj.mjs";
3
+ import { n as FileSystemStorageAdapter, t as VirtualStorageAdapter } from "./virtual-CUgOdyIa.mjs";
4
4
  import { i as getTsconfigFilePath } from "./tsconfig-Cstsoprg.mjs";
5
- import { CACHE_HASH_LENGTH, DEFAULT_ENVIRONMENT, GLOBAL_ENVIRONMENT, PLUGIN_NON_HOOK_FIELDS, ROOT_HASH_LENGTH } from "@powerlines/core/constants";
5
+ 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";
6
6
  import { getResolutionCombinations, resolve, resolvePackage, resolveSync } from "@stryke/fs/resolve";
7
7
  import { joinPaths } from "@stryke/path/join";
8
- import { LogLevelLabel } from "@storm-software/config-tools/types";
8
+ import { createLogFn, extendLogFn } from "@powerlines/core";
9
9
  import { isSet } from "@stryke/type-checks/is-set";
10
+ import { isSetObject } from "@stryke/type-checks/is-set-object";
10
11
  import { isString } from "@stryke/type-checks/is-string";
11
- import { colorText, createLog, extendLog } from "@powerlines/core/lib/logger";
12
+ import { toArray } from "@stryke/convert/to-array";
13
+ import { isSetString } from "@stryke/type-checks/is-set-string";
14
+ import { uuid } from "@stryke/unique-id/uuid";
15
+ import { colorText } from "@powerlines/core/lib/logger";
16
+ import { addPluginHook, dedupeHooklist, isDuplicate, isPlugin, isPluginConfig, isPluginHook, isPluginHookField, mergeConfig, replacePathTokens } from "@powerlines/core/plugin-utils";
12
17
  import { isEqual } from "@stryke/path/is-equal";
13
- import { isNull } from "@stryke/type-checks/is-null";
18
+ import { replaceExtension, replacePath } from "@stryke/path/replace";
14
19
  import chalk from "chalk";
15
20
  import defu, { createDefu, defu as defu$1 } from "defu";
16
21
  import { joinPaths as joinPaths$1 } from "@stryke/path/join-paths";
17
22
  import { titleCase } from "@stryke/string-format/title-case";
18
- import { isSetObject } from "@stryke/type-checks/is-set-object";
19
23
  import { format } from "@powerlines/core/lib/utilities/format";
20
- import { addPluginHook, dedupeHooklist, isDuplicate, isPlugin, isPluginConfig, isPluginHook, isPluginHookField, mergeConfig, replacePathTokens } from "@powerlines/core/plugin-utils";
21
- import { toArray } from "@stryke/convert/to-array";
22
24
  import { existsSync } from "@stryke/fs/exists";
23
25
  import { getUnique, getUniqueBy } from "@stryke/helpers/get-unique";
24
26
  import { omit } from "@stryke/helpers/omit";
25
27
  import { appendPath } from "@stryke/path/append";
26
28
  import { findFileDotExtensionSafe, findFileExtensionSafe, findFileName, findFilePath, hasFileExtension } from "@stryke/path/file-path-fns";
27
29
  import { isParentPath } from "@stryke/path/is-parent-path";
28
- import { replaceExtension, replacePath } from "@stryke/path/replace";
29
30
  import { isFunction } from "@stryke/type-checks/is-function";
30
31
  import { isObject } from "@stryke/type-checks/is-object";
31
- import { isSetString } from "@stryke/type-checks/is-set-string";
32
32
  import { readJsonFile } from "@stryke/fs/json";
33
33
  import { deepClone } from "@stryke/helpers/deep-clone";
34
34
  import { getUniqueInputs, isTypeDefinition, resolveInputsSync } from "@powerlines/core/lib/entry";
@@ -37,7 +37,6 @@ import { murmurhash } from "@stryke/hash";
37
37
  import { hashDirectory } from "@stryke/hash/node";
38
38
  import { fetchRequest } from "@stryke/http/fetch";
39
39
  import { kebabCase } from "@stryke/string-format/kebab-case";
40
- import { uuid } from "@stryke/unique-id/uuid";
41
40
  import { match, tsconfigPathsToRegExp } from "bundle-require";
42
41
  import { resolveCompatibilityDates } from "compatx";
43
42
  import { create } from "flat-cache";
@@ -59,6 +58,7 @@ import { getField } from "@stryke/helpers/get-field";
59
58
  //#region src/_internal/helpers/environment.ts
60
59
  function createEnvironment(name, config = {}) {
61
60
  return defu(config.environments?.[name] ?? {}, {
61
+ environmentId: uuid(),
62
62
  name,
63
63
  title: config.title ?? titleCase(config.name),
64
64
  ssr: false,
@@ -470,7 +470,7 @@ var VirtualFileSystem = class VirtualFileSystem {
470
470
  }
471
471
  }));
472
472
  } else result = new VirtualFileSystem(context, new capnp.Message().initRoot(FileSystem));
473
- result.#log(LogLevelLabel.DEBUG, "Successfully completed virtual file system (VFS) initialization.");
473
+ result.#log("debug", "Successfully completed virtual file system (VFS) initialization.");
474
474
  return result;
475
475
  }
476
476
  /**
@@ -504,7 +504,7 @@ var VirtualFileSystem = class VirtualFileSystem {
504
504
  }
505
505
  });
506
506
  } else result = new VirtualFileSystem(context, new capnp.Message().initRoot(FileSystem));
507
- result.#log(LogLevelLabel.DEBUG, "Successfully completed virtual file system (VFS) initialization.");
507
+ result.#log("debug", "Successfully completed virtual file system (VFS) initialization.");
508
508
  return result;
509
509
  }
510
510
  /**
@@ -638,7 +638,10 @@ var VirtualFileSystem = class VirtualFileSystem {
638
638
  return ret;
639
639
  }, {});
640
640
  }
641
- this.#log = extendLog(this.#context.log, "file-system");
641
+ this.#log = context.extendLog({
642
+ source: "VFS",
643
+ category: "fs"
644
+ });
642
645
  }
643
646
  /**
644
647
  * Asynchronously checks if a file exists in the virtual file system (VFS).
@@ -765,7 +768,7 @@ var VirtualFileSystem = class VirtualFileSystem {
765
768
  listSync(path) {
766
769
  let resolvedPath = path;
767
770
  if (resolvedPath.includes("*")) {
768
- this.#log(LogLevelLabel.WARN, `Invoking "listSync" with a glob pattern is not supported. It is likely you meant to use "globSync". Path: ${path}`);
771
+ this.#log("warn", `Invoking "listSync" with a glob pattern is not supported. It is likely you meant to use "globSync". Path: ${path}`);
769
772
  resolvedPath = stripStars(resolvedPath);
770
773
  }
771
774
  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));
@@ -779,7 +782,7 @@ var VirtualFileSystem = class VirtualFileSystem {
779
782
  async list(path) {
780
783
  let resolvedPath = path;
781
784
  if (resolvedPath.includes("*")) {
782
- this.#log(LogLevelLabel.WARN, `Invoking "list" with a glob pattern is not supported. It is likely you meant to use "glob". Path: ${path}`);
785
+ this.#log("warn", `Invoking "list" with a glob pattern is not supported. It is likely you meant to use "glob". Path: ${path}`);
783
786
  resolvedPath = stripStars(resolvedPath);
784
787
  }
785
788
  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));
@@ -791,7 +794,7 @@ var VirtualFileSystem = class VirtualFileSystem {
791
794
  */
792
795
  async remove(path) {
793
796
  const normalizedPath = this.#normalizePath(path);
794
- this.#log(LogLevelLabel.TRACE, `Removing file: ${normalizedPath}`);
797
+ this.#log("trace", `Removing file: ${normalizedPath}`);
795
798
  const { relativeKey, adapter } = this.#getStorage(normalizedPath);
796
799
  if (hasFileExtension(normalizedPath)) await adapter.remove(relativeKey);
797
800
  else await adapter.clear(relativeKey);
@@ -809,7 +812,7 @@ var VirtualFileSystem = class VirtualFileSystem {
809
812
  */
810
813
  removeSync(path) {
811
814
  const normalizedPath = this.#normalizePath(path);
812
- this.#log(LogLevelLabel.TRACE, `Removing file: ${normalizedPath}`);
815
+ this.#log("trace", `Removing file: ${normalizedPath}`);
813
816
  const { relativeKey, adapter } = this.#getStorage(normalizedPath);
814
817
  if (hasFileExtension(normalizedPath)) adapter.removeSync(relativeKey);
815
818
  else adapter.clearSync(relativeKey);
@@ -955,7 +958,7 @@ var VirtualFileSystem = class VirtualFileSystem {
955
958
  const filePath = await this.resolve(path, void 0, { isFile: true });
956
959
  if (!filePath || !this.existsSync(filePath)) return;
957
960
  const { adapter } = this.#getStorage(filePath);
958
- this.#log(LogLevelLabel.TRACE, `Reading ${adapter.name} file: ${filePath}`);
961
+ this.#log("trace", `Reading ${adapter.name} file: ${filePath}`);
959
962
  return await adapter.get(filePath) ?? void 0;
960
963
  }
961
964
  /**
@@ -968,7 +971,7 @@ var VirtualFileSystem = class VirtualFileSystem {
968
971
  const filePath = this.resolveSync(path, void 0, { isFile: true });
969
972
  if (!filePath || !this.existsSync(filePath)) return;
970
973
  const { adapter } = this.#getStorage(filePath);
971
- this.#log(LogLevelLabel.TRACE, `Reading ${adapter.name} file: ${filePath}`);
974
+ this.#log("trace", `Reading ${adapter.name} file: ${filePath}`);
972
975
  return adapter.getSync(filePath) ?? void 0;
973
976
  }
974
977
  /**
@@ -983,15 +986,15 @@ var VirtualFileSystem = class VirtualFileSystem {
983
986
  const meta = options.meta ?? {};
984
987
  const resolvedPath = await this.resolve(this.#normalizePath(path)) || path;
985
988
  const { relativeKey, adapter } = this.#getStorage(resolvedPath, options.storage);
986
- 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(toArray(data)).size)})`);
989
+ 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(toArray(data)).size)})`);
987
990
  let code = data;
988
991
  try {
989
992
  if (!options.skipFormat) code = await format(this.#context, resolvedPath, data);
990
993
  } catch (err) {
991
- if (DEFAULT_EXTENSIONS.includes(findFileExtensionSafe(resolvedPath, { fullExtension: true }))) this.#log(LogLevelLabel.WARN, `Failed to format file ${resolvedPath} before writing: ${err.message}`);
994
+ if (DEFAULT_EXTENSIONS.includes(findFileExtensionSafe(resolvedPath, { fullExtension: true }))) this.#log("warn", `Failed to format file ${resolvedPath} before writing: ${err.message}`);
992
995
  code = data;
993
996
  }
994
- 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(toArray(code)).size)})`);
997
+ 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(toArray(code)).size)})`);
995
998
  const id = this.#normalizeId(meta.id || resolvedPath);
996
999
  this.metadata[id] = {
997
1000
  type: "normal",
@@ -1014,7 +1017,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1014
1017
  const meta = options.meta ?? {};
1015
1018
  const resolvedPath = this.resolveSync(this.#normalizePath(path)) || path;
1016
1019
  const { relativeKey, adapter } = this.#getStorage(resolvedPath, options.storage);
1017
- 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(toArray(data)).size)})`);
1020
+ 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(toArray(data)).size)})`);
1018
1021
  const id = this.#normalizeId(meta.id || resolvedPath);
1019
1022
  this.metadata[id] = {
1020
1023
  type: "normal",
@@ -1178,7 +1181,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1178
1181
  async dispose() {
1179
1182
  if (!this.#isDisposed) {
1180
1183
  this.#isDisposed = true;
1181
- this.#log(LogLevelLabel.DEBUG, "Disposing virtual file system...");
1184
+ this.#log("debug", "Disposing virtual file system...");
1182
1185
  await this.remove(joinPaths(this.#context.dataPath, "fs.bin"));
1183
1186
  const message = new capnp.Message();
1184
1187
  const fs = message.initRoot(FileSystem);
@@ -1213,9 +1216,15 @@ var VirtualFileSystem = class VirtualFileSystem {
1213
1216
  await writeFileBuffer(joinPaths(this.#context.dataPath, "fs.bin"), message.toArrayBuffer());
1214
1217
  if (!this.#context.config.skipCache) this.resolverCache.save(true);
1215
1218
  await Promise.all(this.#getStorages().map(async (storage) => storage.adapter.dispose()));
1216
- this.#log(LogLevelLabel.TRACE, "Virtual file system has been disposed.");
1219
+ this.#log("trace", "Virtual file system has been disposed.");
1217
1220
  }
1218
1221
  }
1222
+ /**
1223
+ * Asynchronously disposes of the virtual file system (VFS) by saving its state to disk.
1224
+ *
1225
+ * @remarks
1226
+ * 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.
1227
+ */
1219
1228
  async [Symbol.asyncDispose]() {
1220
1229
  return this.dispose();
1221
1230
  }
@@ -1364,7 +1373,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
1364
1373
  buildId: this.#buildId,
1365
1374
  releaseId: this.#releaseId,
1366
1375
  checksum: this.#checksum,
1367
- timestamp: this.timestamp.getTime(),
1376
+ timestamp: this.timestamp,
1368
1377
  rootHash: murmurhash({
1369
1378
  workspaceRoot: this.options?.cwd,
1370
1379
  root: this.config?.root
@@ -1522,6 +1531,60 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
1522
1531
  this.options = options;
1523
1532
  }
1524
1533
  /**
1534
+ * 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.
1535
+ *
1536
+ * @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.
1537
+ * @returns A log function that can be used to log messages with the specified configuration.
1538
+ */
1539
+ createLog(config) {
1540
+ const log = createLogFn({
1541
+ ...config,
1542
+ logLevel: this.logLevel
1543
+ });
1544
+ return (meta, ...args) => {
1545
+ log(meta, ...args);
1546
+ process.send?.({
1547
+ id: uuid(),
1548
+ type: "write-log",
1549
+ executionId: config?.executionId ?? this.options.executionId,
1550
+ executionIndex: config?.executionIndex ?? this.options.executionIndex,
1551
+ timestamp: Date.now(),
1552
+ payload: {
1553
+ level: meta && isSetObject(meta) && isSetString(meta.level) ? meta.level : isSetString(meta) ? meta : "info",
1554
+ ...config,
1555
+ args
1556
+ }
1557
+ });
1558
+ };
1559
+ }
1560
+ /**
1561
+ * Extend the current log function instance with a new name
1562
+ *
1563
+ * @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.
1564
+ * @returns A log function
1565
+ */
1566
+ extendLog(config) {
1567
+ const log = extendLogFn(this.log, {
1568
+ ...config,
1569
+ logLevel: this.logLevel
1570
+ });
1571
+ return (meta, ...args) => {
1572
+ log(meta, ...args);
1573
+ process.send?.({
1574
+ id: uuid(),
1575
+ type: "write-log",
1576
+ executionId: config.executionId ?? this.options.executionId,
1577
+ executionIndex: config.executionIndex ?? this.options.executionIndex,
1578
+ timestamp: Date.now(),
1579
+ payload: {
1580
+ level: meta && isSetObject(meta) && isSetString(meta.level) ? meta.level : isSetString(meta) ? meta : "info",
1581
+ ...config,
1582
+ args
1583
+ }
1584
+ });
1585
+ };
1586
+ }
1587
+ /**
1525
1588
  * 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.
1526
1589
  *
1527
1590
  * @remarks
@@ -1530,22 +1593,10 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
1530
1593
  * @returns A promise that resolves to the cloned context.
1531
1594
  */
1532
1595
  async clone() {
1533
- const clone = await PowerlinesContext.fromOptions(this.config);
1596
+ const clone = await PowerlinesContext.fromOptions(this.options);
1534
1597
  return this.copyTo(clone);
1535
1598
  }
1536
1599
  /**
1537
- * Create a new logger instance
1538
- *
1539
- * @param name - The name to use for the logger instance
1540
- * @returns A logger function
1541
- */
1542
- createLog(name = null) {
1543
- return createLog(name, {
1544
- ...this.config,
1545
- logLevel: isNull(this.logLevel) ? "silent" : this.logLevel
1546
- });
1547
- }
1548
- /**
1549
1600
  * A function to perform HTTP fetch requests
1550
1601
  *
1551
1602
  * @remarks
@@ -1921,6 +1972,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
1921
1972
  for (const [key, value] of Object.entries(this)) if (!SKIP_CLONING_PROPS.includes(key)) if (isObject(value) || Array.isArray(value)) context[key] = deepClone(value);
1922
1973
  else context[key] = value;
1923
1974
  context.inputOptions = deepClone(this.inputOptions);
1975
+ context.options = deepClone(this.options);
1924
1976
  context.dependencies = deepClone(this.dependencies);
1925
1977
  context.devDependencies = deepClone(this.devDependencies);
1926
1978
  context.persistedMeta = this.persistedMeta ? deepClone(this.persistedMeta) : void 0;
@@ -1942,7 +1994,8 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
1942
1994
  */
1943
1995
  async init(options = {}) {
1944
1996
  await super.init(options);
1945
- this.options.configIndex = options.configIndex ?? this.options.configIndex ?? 0;
1997
+ this.options.executionId = options.executionId ?? this.options.executionId;
1998
+ this.options.executionIndex = options.executionIndex ?? this.options.executionIndex ?? 0;
1946
1999
  const projectJsonPath = joinPaths(this.options.cwd, this.options.root, "project.json");
1947
2000
  if (existsSync(projectJsonPath)) this.projectJson = await readJsonFile(projectJsonPath);
1948
2001
  const packageJsonPath = joinPaths(this.options.cwd, this.options.root, "package.json");
@@ -1951,7 +2004,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
1951
2004
  this.options.organization ??= isSetObject(this.packageJson?.author) ? kebabCase(this.packageJson?.author?.name) : kebabCase(this.packageJson?.author);
1952
2005
  }
1953
2006
  this.#checksum = await this.generateChecksum(joinPaths(this.options.cwd, this.options.root));
1954
- const userConfig = this.configFile.config ? Array.isArray(this.configFile.config) && this.configFile.config.length > this.options.configIndex ? this.configFile.config[this.options.configIndex] : this.configFile.config : {};
2007
+ const userConfig = this.configFile.config ? Array.isArray(this.configFile.config) && this.configFile.config.length > this.options.executionIndex ? this.configFile.config[this.options.executionIndex] : this.configFile.config : {};
1955
2008
  this.resolvedConfig = {
1956
2009
  ...this.options,
1957
2010
  ...userConfig,
@@ -1971,10 +2024,6 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
1971
2024
  this.config.framework = "powerlines";
1972
2025
  }
1973
2026
  this.resolvedConfig.compatibilityDate = resolveCompatibilityDates(this.config.inlineConfig.compatibilityDate ?? this.config.userConfig.compatibilityDate ?? this.config.pluginConfig.compatibilityDate, "latest");
1974
- this.logger = {
1975
- log: this.createLog(this.config.name),
1976
- level: isNull(this.logLevel) ? "silent" : this.logLevel
1977
- };
1978
2027
  this.config.input = getUniqueInputs(this.config.input);
1979
2028
  if (this.config.name?.startsWith("@") && this.config.name.split("/").filter(Boolean).length > 1) this.config.name = this.config.name.split("/").filter(Boolean)[1];
1980
2029
  this.config.title ??= titleCase(this.config.name);
@@ -1982,16 +2031,17 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
1982
2031
  if (this.config.userConfig.resolve?.noExternal) this.config.userConfig.resolve.noExternal = getUnique(this.config.userConfig.resolve.noExternal);
1983
2032
  if (this.config.resolve.external) this.config.resolve.external = getUnique(this.config.resolve.external);
1984
2033
  if (this.config.resolve.noExternal) this.config.resolve.noExternal = getUnique(this.config.resolve.noExternal);
1985
- this.config.plugins = (this.config.plugins ?? []).filter(Boolean).reduce((ret, plugin) => {
2034
+ this.config.plugins = (this.config.plugins ?? []).flatMap((plugin) => toArray(plugin)).filter(Boolean).reduce((ret, plugin) => {
1986
2035
  if (isPlugin(plugin) && isDuplicate(plugin, ret.filter((p) => isPlugin(p)))) return ret;
1987
2036
  ret.push(plugin);
1988
2037
  return ret;
1989
2038
  }, []);
1990
- if (!this.config.userConfig?.logLevel && !this.config.inlineConfig?.logLevel) if (this.config.mode === "development") this.config.logLevel = "debug";
1991
- else this.config.logLevel = "info";
1992
- if (!this.config.userConfig?.tsconfig && !this.config.inlineConfig?.tsconfig) this.config.tsconfig = getTsconfigFilePath(this.options.cwd, this.options.root);
2039
+ if (!this.config.userConfig?.logLevel && !this.config.inlineConfig?.logLevel) if (this.config.mode === "development") this.config.logLevel = DEFAULT_DEVELOPMENT_LOG_LEVEL;
2040
+ else if (this.config.mode === "test") this.config.logLevel = DEFAULT_TEST_LOG_LEVEL;
2041
+ else this.config.logLevel = DEFAULT_PRODUCTION_LOG_LEVEL;
2042
+ if (!this.config.userConfig?.tsconfig && !this.config.inlineConfig?.tsconfig) this.config.tsconfig = getTsconfigFilePath(this.config.cwd, this.config.root);
1993
2043
  else if (this.config.tsconfig) this.config.tsconfig = replacePath(replacePathTokens(this, this.config.tsconfig), this.config.cwd);
1994
- this.resolvedConfig.output = defu(this.resolvedConfig.output ?? {}, {
2044
+ this.resolvedConfig.output = defu(this.config.output ?? {}, {
1995
2045
  path: joinPaths(this.config.root, "dist"),
1996
2046
  copy: { assets: [
1997
2047
  { glob: "LICENSE" },
@@ -2014,7 +2064,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2014
2064
  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;
2015
2065
  else this.config.output.copy.path = appendPath(replacePathTokens(this, this.config.output.copy.path || joinPaths("dist", this.config.root)), this.config.cwd);
2016
2066
  }
2017
- if (this.config.output.dts !== false && this.config.output.types !== false) this.config.output.types = appendPath(replacePathTokens(this, this.config.output.types || joinPaths(this.config.root, `${this.config.framework ?? "powerlines"}.d.ts`)), this.config.cwd);
2067
+ if (this.config.output.dts !== false && this.config.output.types !== false) this.config.output.types = appendPath(replacePathTokens(this, this.config.userConfig?.output?.types || this.config.inlineConfig?.output?.types || this.config.pluginConfig?.output?.types || joinPaths(this.config.root, `${this.config.framework ?? "powerlines"}.d.ts`)), this.config.cwd);
2018
2068
  if (this.config.output.copy && this.config.output.copy.path && this.config.output.copy.assets && Array.isArray(this.config.output.copy.assets)) this.config.output.copy.assets = getUniqueBy(this.config.output.copy.assets.map((asset) => {
2019
2069
  return {
2020
2070
  glob: isSetObject(asset) ? asset.glob : asset,
@@ -2036,6 +2086,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2036
2086
  }));
2037
2087
  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;
2038
2088
  this.#fs ??= await VirtualFileSystem.create(this);
2089
+ this.extendLog({ category: "config" })("debug", `Resolved Powerlines configuration object: \n${JSON.stringify(this.resolvedConfig, null, 2)}`);
2039
2090
  }
2040
2091
  };
2041
2092
 
@@ -2176,15 +2227,16 @@ function extractHooks(context, hooks, plugin, key, parentKey) {
2176
2227
  /**
2177
2228
  * Create a Proxy-based PluginContext
2178
2229
  *
2230
+ * @param pluginId - The unique identifier of the plugin
2179
2231
  * @param plugin - The plugin instance
2180
2232
  * @param environment - The environment context
2181
2233
  * @returns The proxied plugin context
2182
2234
  */
2183
- function createPluginContext(plugin, environment) {
2235
+ function createPluginContext(pluginId, plugin, environment) {
2184
2236
  const normalizeMessage = (message) => {
2185
2237
  return isString(message) ? message : message.message;
2186
2238
  };
2187
- const log = environment.extendLog(plugin.name.replaceAll(":", " - "));
2239
+ const log = environment.extendLog({ plugin: plugin.name.replaceAll(":", " - ") });
2188
2240
  const callHookFn = async (hook, options, ...args) => {
2189
2241
  return environment.$$internal.api.callHook(hook, {
2190
2242
  sequential: true,
@@ -2202,30 +2254,32 @@ function createPluginContext(plugin, environment) {
2202
2254
  callHook: callHookFn,
2203
2255
  meta
2204
2256
  };
2257
+ if (prop === "id") return pluginId;
2205
2258
  if (prop === "log" || prop === "logger") return log;
2206
2259
  if (prop === "fatal") return (message) => {
2207
- log(LogLevelLabel.FATAL, normalizeMessage(message));
2260
+ log("error", normalizeMessage(message));
2208
2261
  };
2209
2262
  if (prop === "error") return (message) => {
2210
- log(LogLevelLabel.ERROR, normalizeMessage(message));
2263
+ log("error", normalizeMessage(message));
2211
2264
  };
2212
2265
  if (prop === "warn") return (message) => {
2213
- log(LogLevelLabel.WARN, normalizeMessage(message));
2266
+ log("warn", normalizeMessage(message));
2214
2267
  };
2215
2268
  if (prop === "info") return (message) => {
2216
- log(LogLevelLabel.INFO, normalizeMessage(message));
2269
+ log("info", normalizeMessage(message));
2217
2270
  };
2218
2271
  if (prop === "debug") return (message) => {
2219
- log(LogLevelLabel.DEBUG, normalizeMessage(message));
2272
+ log("debug", normalizeMessage(message));
2220
2273
  };
2221
2274
  if (prop === "trace") return (message) => {
2222
- log(LogLevelLabel.TRACE, normalizeMessage(message));
2275
+ log("trace", normalizeMessage(message));
2223
2276
  };
2224
2277
  return environment[prop];
2225
2278
  },
2226
2279
  set(_, prop, value) {
2227
2280
  if ([
2228
2281
  "$$internal",
2282
+ "id",
2229
2283
  "environment",
2230
2284
  "config",
2231
2285
  "log",
@@ -2237,7 +2291,7 @@ function createPluginContext(plugin, environment) {
2237
2291
  "addPlugin",
2238
2292
  "selectHooks"
2239
2293
  ].includes(prop)) {
2240
- log(LogLevelLabel.WARN, `Cannot set read-only property "${String(prop)}"`);
2294
+ log("warn", `Cannot set read-only property "${String(prop)}"`);
2241
2295
  return false;
2242
2296
  }
2243
2297
  environment[prop] = value;
@@ -2277,17 +2331,10 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
2277
2331
  */
2278
2332
  plugins = [];
2279
2333
  /**
2280
- * Create a new logger instance
2281
- *
2282
- * @param name - The name to use for the logger instance
2283
- * @returns A logger function
2334
+ * The unique identifier of the environment associated with this context, which can be used for logging and other purposes to distinguish between different environments in the same process.
2284
2335
  */
2285
- createLog(name = null) {
2286
- return createLog(name, {
2287
- ...this.config,
2288
- logLevel: isNull(this.config.logLevel) ? "silent" : this.config.logLevel,
2289
- environment: this.environment?.name
2290
- });
2336
+ get id() {
2337
+ return this.environment.environmentId;
2291
2338
  }
2292
2339
  /**
2293
2340
  * The hooks registered by plugins in this environment
@@ -2296,6 +2343,30 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
2296
2343
  return this.#hooks;
2297
2344
  }
2298
2345
  /**
2346
+ * 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.
2347
+ *
2348
+ * @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.
2349
+ * @returns A log function that can be used to log messages with the specified configuration.
2350
+ */
2351
+ createLog(config) {
2352
+ return super.createLog({
2353
+ ...config,
2354
+ environment: this.environment?.name
2355
+ });
2356
+ }
2357
+ /**
2358
+ * Extend the current log function instance with a new name
2359
+ *
2360
+ * @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.
2361
+ * @returns A log function
2362
+ */
2363
+ extendLog(config) {
2364
+ return super.extendLog({
2365
+ ...config,
2366
+ environment: this.environment?.name
2367
+ });
2368
+ }
2369
+ /**
2299
2370
  * 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.
2300
2371
  *
2301
2372
  * @remarks
@@ -2325,8 +2396,10 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
2325
2396
  if (isPluginConfig(result)) return this.$$internal.addPlugin(result);
2326
2397
  resolvedPlugin = isPlugin(result) ? result : plugin;
2327
2398
  }
2328
- const context = createPluginContext(resolvedPlugin, this);
2399
+ const pluginId = uuid();
2400
+ const context = createPluginContext(pluginId, resolvedPlugin, this);
2329
2401
  this.plugins.push({
2402
+ pluginId,
2330
2403
  plugin: resolvedPlugin,
2331
2404
  context
2332
2405
  });
@@ -2452,6 +2525,12 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
2452
2525
  for (const environment of Object.values(this.environments)) environment.$$internal = super.$$internal;
2453
2526
  }
2454
2527
  /**
2528
+ * The unique identifier of the execution context, which can be used for logging and other purposes to distinguish between different executions in the same process.
2529
+ */
2530
+ get id() {
2531
+ return this.options.executionId;
2532
+ }
2533
+ /**
2455
2534
  * A record of all environments by name
2456
2535
  */
2457
2536
  get environments() {
@@ -2469,6 +2548,32 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
2469
2548
  super(options);
2470
2549
  }
2471
2550
  /**
2551
+ * 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.
2552
+ *
2553
+ * @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.
2554
+ * @returns A log function that can be used to log messages with the specified configuration.
2555
+ */
2556
+ createLog(config) {
2557
+ return super.createLog({
2558
+ ...config,
2559
+ executionId: this.id,
2560
+ executionIndex: this.options.executionIndex
2561
+ });
2562
+ }
2563
+ /**
2564
+ * Extend the current log function instance with a new name
2565
+ *
2566
+ * @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.
2567
+ * @returns A log function
2568
+ */
2569
+ extendLog(config) {
2570
+ return super.extendLog({
2571
+ ...config,
2572
+ executionId: this.id,
2573
+ executionIndex: this.options.executionIndex
2574
+ });
2575
+ }
2576
+ /**
2472
2577
  * 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.
2473
2578
  *
2474
2579
  * @remarks
@@ -2570,4 +2675,4 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
2570
2675
 
2571
2676
  //#endregion
2572
2677
  export { mergeConfigs as a, callHook as i, PowerlinesEnvironmentContext as n, PowerlinesContext as o, createPluginContext as r, writeMetaFile as s, PowerlinesExecutionContext as t };
2573
- //# sourceMappingURL=execution-context-CBJxP2B2.mjs.map
2678
+ //# sourceMappingURL=execution-context-zedP0h4Z.mjs.map