@powerlines/engine 0.43.29 → 0.43.31

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 +112 -42
  2. package/dist/_internal/worker.mjs +112 -42
  3. package/dist/_internal/worker.mjs.map +1 -1
  4. package/dist/api.cjs +9 -7
  5. package/dist/api.d.cts.map +1 -1
  6. package/dist/api.d.mts.map +1 -1
  7. package/dist/api.mjs +9 -7
  8. package/dist/api.mjs.map +1 -1
  9. package/dist/{base-context-B9AROf66.cjs → base-context-CPoqO4io.cjs} +9 -8
  10. package/dist/{base-context-D8a2XGIK.mjs → base-context-SmQ6OfXm.mjs} +10 -9
  11. package/dist/base-context-SmQ6OfXm.mjs.map +1 -0
  12. package/dist/context/index.cjs +3 -3
  13. package/dist/context/index.d.cts +37 -20
  14. package/dist/context/index.d.cts.map +1 -1
  15. package/dist/context/index.d.mts +37 -20
  16. package/dist/context/index.d.mts.map +1 -1
  17. package/dist/context/index.mjs +3 -3
  18. package/dist/{engine-context-qCVw66U_.cjs → engine-context-CEu21ZZf.cjs} +36 -10
  19. package/dist/{engine-context-DsA9XGVb.mjs → engine-context-D7CWyTsr.mjs} +36 -11
  20. package/dist/engine-context-D7CWyTsr.mjs.map +1 -0
  21. package/dist/{execution-context-CBJxP2B2.mjs → execution-context-C_7IC8er.mjs} +110 -40
  22. package/dist/execution-context-C_7IC8er.mjs.map +1 -0
  23. package/dist/{execution-context-CprxWvYn.cjs → execution-context-DsT6s1du.cjs} +108 -38
  24. package/dist/index.cjs +135 -54
  25. package/dist/index.d.cts.map +1 -1
  26. package/dist/index.d.mts.map +1 -1
  27. package/dist/index.mjs +135 -54
  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
@@ -63,10 +63,13 @@ let defu = require("defu");
63
63
  defu = __toESM(defu, 1);
64
64
  let handlebars = require("handlebars");
65
65
  handlebars = __toESM(handlebars, 1);
66
+ let _powerlines_core = require("@powerlines/core");
66
67
  let _powerlines_core_constants = require("@powerlines/core/constants");
67
68
  let _stryke_fs_json = require("@stryke/fs/json");
68
69
  let _stryke_helpers_deep_clone = require("@stryke/helpers/deep-clone");
69
70
  let _stryke_path_join = require("@stryke/path/join");
71
+ let _stryke_type_checks_is_null = require("@stryke/type-checks/is-null");
72
+ let _stryke_unique_id_uuid = require("@stryke/unique-id/uuid");
70
73
  let _powerlines_core_lib_entry = require("@powerlines/core/lib/entry");
71
74
  let _stryke_fs_get_workspace_root = require("@stryke/fs/get-workspace-root");
72
75
  let _stryke_hash = require("@stryke/hash");
@@ -74,8 +77,6 @@ let _stryke_hash_node = require("@stryke/hash/node");
74
77
  let _stryke_http_fetch = require("@stryke/http/fetch");
75
78
  let _stryke_path_is_equal = require("@stryke/path/is-equal");
76
79
  let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
77
- let _stryke_type_checks_is_null = require("@stryke/type-checks/is-null");
78
- let _stryke_unique_id_uuid = require("@stryke/unique-id/uuid");
79
80
  let bundle_require = require("bundle-require");
80
81
  let compatx = require("compatx");
81
82
  let flat_cache = require("flat-cache");
@@ -115,6 +116,7 @@ let _donedeal0_superdiff = require("@donedeal0/superdiff");
115
116
  //#region src/_internal/helpers/environment.ts
116
117
  function createEnvironment(name, config = {}) {
117
118
  return (0, defu.default)(config.environments?.[name] ?? {}, {
119
+ environmentId: (0, _stryke_unique_id_uuid.uuid)(),
118
120
  name,
119
121
  title: config.title ?? (0, _stryke_string_format_title_case.titleCase)(config.name),
120
122
  ssr: false,
@@ -1400,7 +1402,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1400
1402
  return ret;
1401
1403
  }, {});
1402
1404
  }
1403
- this.#log = (0, _powerlines_core_lib_logger.extendLog)(this.#context.log, "file-system");
1405
+ this.#log = context.extendLog("VFS");
1404
1406
  }
1405
1407
  /**
1406
1408
  * Asynchronously checks if a file exists in the virtual file system (VFS).
@@ -2289,23 +2291,23 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2289
2291
  /**
2290
2292
  * Create a new logger instance
2291
2293
  *
2292
- * @param name - The name to use for the logger instance
2294
+ * @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.
2293
2295
  * @returns A logger function
2294
2296
  */
2295
- createLog(name = null) {
2296
- return (0, _powerlines_core_lib_logger.createLog)(name, {
2297
+ createLog(source = null) {
2298
+ return (0, _powerlines_core_lib_logger.createLog)(source, {
2297
2299
  ...this.options,
2298
2300
  logLevel: (0, _stryke_type_checks_is_null.isNull)(this.logLevel) ? "silent" : this.logLevel
2299
2301
  });
2300
2302
  }
2301
2303
  /**
2302
- * Extend the current logger instance with a new name
2304
+ * Extend the current logger instance with a new source
2303
2305
  *
2304
- * @param name - The name to use for the extended logger instance
2306
+ * @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.
2305
2307
  * @returns A logger function
2306
2308
  */
2307
- extendLog(name) {
2308
- return (0, _powerlines_core_lib_logger.extendLog)(this.log, name);
2309
+ extendLog(source) {
2310
+ return (0, _powerlines_core_lib_logger.extendLog)(this.log, source);
2309
2311
  }
2310
2312
  /**
2311
2313
  * A logger function specific to this context
@@ -2327,7 +2329,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2327
2329
  this.powerlinesPath = powerlinesPath;
2328
2330
  }
2329
2331
  const cwd = options.cwd || this.options?.cwd || process.cwd();
2330
- const root = (options.root || this.options?.root) && (options.root || this.options.root).replace(/^\.\/?/, "") && !(0, _stryke_path_is_equal.isEqual)(options.root || this.options.root, cwd) ? options.root || this.options.root : ".";
2332
+ const root = (0, _stryke_path_replace.replacePath)((options.root || this.options?.root) && (options.root || this.options.root).replace(/^\.\/?/, "") && !(0, _stryke_path_is_equal.isEqual)(options.root || this.options.root, cwd) ? options.root || this.options.root : ".", cwd);
2331
2333
  this.options = (0, defu.default)({
2332
2334
  root,
2333
2335
  cwd,
@@ -2659,22 +2661,10 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2659
2661
  * @returns A promise that resolves to the cloned context.
2660
2662
  */
2661
2663
  async clone() {
2662
- const clone = await PowerlinesContext.fromOptions(this.config);
2664
+ const clone = await PowerlinesContext.fromOptions(this.options);
2663
2665
  return this.copyTo(clone);
2664
2666
  }
2665
2667
  /**
2666
- * Create a new logger instance
2667
- *
2668
- * @param name - The name to use for the logger instance
2669
- * @returns A logger function
2670
- */
2671
- createLog(name = null) {
2672
- return (0, _powerlines_core_lib_logger.createLog)(name, {
2673
- ...this.config,
2674
- logLevel: (0, _stryke_type_checks_is_null.isNull)(this.logLevel) ? "silent" : this.logLevel
2675
- });
2676
- }
2677
- /**
2678
2668
  * A function to perform HTTP fetch requests
2679
2669
  *
2680
2670
  * @remarks
@@ -3050,6 +3040,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3050
3040
  for (const [key, value] of Object.entries(this)) if (!SKIP_CLONING_PROPS.includes(key)) if ((0, _stryke_type_checks_is_object.isObject)(value) || Array.isArray(value)) context[key] = (0, _stryke_helpers_deep_clone.deepClone)(value);
3051
3041
  else context[key] = value;
3052
3042
  context.inputOptions = (0, _stryke_helpers_deep_clone.deepClone)(this.inputOptions);
3043
+ context.options = (0, _stryke_helpers_deep_clone.deepClone)(this.options);
3053
3044
  context.dependencies = (0, _stryke_helpers_deep_clone.deepClone)(this.dependencies);
3054
3045
  context.devDependencies = (0, _stryke_helpers_deep_clone.deepClone)(this.devDependencies);
3055
3046
  context.persistedMeta = this.persistedMeta ? (0, _stryke_helpers_deep_clone.deepClone)(this.persistedMeta) : void 0;
@@ -3071,7 +3062,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3071
3062
  */
3072
3063
  async init(options = {}) {
3073
3064
  await super.init(options);
3074
- this.options.configIndex = options.configIndex ?? this.options.configIndex ?? 0;
3065
+ this.options.executionIndex = options.executionIndex ?? this.options.executionIndex ?? 0;
3075
3066
  const projectJsonPath = (0, _stryke_path_join.joinPaths)(this.options.cwd, this.options.root, "project.json");
3076
3067
  if ((0, _stryke_fs_exists.existsSync)(projectJsonPath)) this.projectJson = await (0, _stryke_fs_json.readJsonFile)(projectJsonPath);
3077
3068
  const packageJsonPath = (0, _stryke_path_join.joinPaths)(this.options.cwd, this.options.root, "package.json");
@@ -3080,7 +3071,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3080
3071
  this.options.organization ??= (0, _stryke_type_checks_is_set_object.isSetObject)(this.packageJson?.author) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.packageJson?.author?.name) : (0, _stryke_string_format_kebab_case.kebabCase)(this.packageJson?.author);
3081
3072
  }
3082
3073
  this.#checksum = await this.generateChecksum((0, _stryke_path_join.joinPaths)(this.options.cwd, this.options.root));
3083
- 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 : {};
3074
+ 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 : {};
3084
3075
  this.resolvedConfig = {
3085
3076
  ...this.options,
3086
3077
  ...userConfig,
@@ -3111,7 +3102,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3111
3102
  if (this.config.userConfig.resolve?.noExternal) this.config.userConfig.resolve.noExternal = (0, _stryke_helpers_get_unique.getUnique)(this.config.userConfig.resolve.noExternal);
3112
3103
  if (this.config.resolve.external) this.config.resolve.external = (0, _stryke_helpers_get_unique.getUnique)(this.config.resolve.external);
3113
3104
  if (this.config.resolve.noExternal) this.config.resolve.noExternal = (0, _stryke_helpers_get_unique.getUnique)(this.config.resolve.noExternal);
3114
- this.config.plugins = (this.config.plugins ?? []).filter(Boolean).reduce((ret, plugin) => {
3105
+ this.config.plugins = (this.config.plugins ?? []).flatMap((plugin) => (0, _stryke_convert_to_array.toArray)(plugin)).filter(Boolean).reduce((ret, plugin) => {
3115
3106
  if ((0, _powerlines_core_plugin_utils.isPlugin)(plugin) && (0, _powerlines_core_plugin_utils.isDuplicate)(plugin, ret.filter((p) => (0, _powerlines_core_plugin_utils.isPlugin)(p)))) return ret;
3116
3107
  ret.push(plugin);
3117
3108
  return ret;
@@ -3143,7 +3134,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3143
3134
  if (!this.config.root.replace(/^\.\/?/, "")) this.config.output.copy.path = this.config.output.copy.path ? (0, _stryke_path_append.appendPath)((0, _powerlines_core_plugin_utils.replacePathTokens)(this, this.config.output.copy.path), this.config.cwd) : this.config.output.path;
3144
3135
  else this.config.output.copy.path = (0, _stryke_path_append.appendPath)((0, _powerlines_core_plugin_utils.replacePathTokens)(this, this.config.output.copy.path || (0, _stryke_path_join.joinPaths)("dist", this.config.root)), this.config.cwd);
3145
3136
  }
3146
- if (this.config.output.dts !== false && this.config.output.types !== false) this.config.output.types = (0, _stryke_path_append.appendPath)((0, _powerlines_core_plugin_utils.replacePathTokens)(this, this.config.output.types || (0, _stryke_path_join.joinPaths)(this.config.root, `${this.config.framework ?? "powerlines"}.d.ts`)), this.config.cwd);
3137
+ if (this.config.output.dts !== false && this.config.output.types !== false) this.config.output.types = (0, _stryke_path_append.appendPath)((0, _powerlines_core_plugin_utils.replacePathTokens)(this, this.config.userConfig?.output?.types || this.config.inlineConfig?.output?.types || this.config.pluginConfig?.output?.types || (0, _stryke_path_join.joinPaths)(this.config.root, `${this.config.framework ?? "powerlines"}.d.ts`)), this.config.cwd);
3147
3138
  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 = (0, _stryke_helpers_get_unique.getUniqueBy)(this.config.output.copy.assets.map((asset) => {
3148
3139
  return {
3149
3140
  glob: (0, _stryke_type_checks_is_set_object.isSetObject)(asset) ? asset.glob : asset,
@@ -3305,15 +3296,16 @@ function extractHooks(context, hooks, plugin, key, parentKey) {
3305
3296
  /**
3306
3297
  * Create a Proxy-based PluginContext
3307
3298
  *
3299
+ * @param pluginId - The unique identifier of the plugin
3308
3300
  * @param plugin - The plugin instance
3309
3301
  * @param environment - The environment context
3310
3302
  * @returns The proxied plugin context
3311
3303
  */
3312
- function createPluginContext(plugin, environment) {
3304
+ function createPluginContext(pluginId, plugin, environment) {
3313
3305
  const normalizeMessage = (message) => {
3314
3306
  return (0, _stryke_type_checks_is_string.isString)(message) ? message : message.message;
3315
3307
  };
3316
- const log = environment.extendLog(plugin.name.replaceAll(":", " - "));
3308
+ const log = environment.extendLog(pluginId, plugin.name.replaceAll(":", " - "));
3317
3309
  const callHookFn = async (hook, options, ...args) => {
3318
3310
  return environment.$$internal.api.callHook(hook, {
3319
3311
  sequential: true,
@@ -3331,6 +3323,7 @@ function createPluginContext(plugin, environment) {
3331
3323
  callHook: callHookFn,
3332
3324
  meta
3333
3325
  };
3326
+ if (prop === "id") return pluginId;
3334
3327
  if (prop === "log" || prop === "logger") return log;
3335
3328
  if (prop === "fatal") return (message) => {
3336
3329
  log(_storm_software_config_tools_types.LogLevelLabel.FATAL, normalizeMessage(message));
@@ -3355,6 +3348,7 @@ function createPluginContext(plugin, environment) {
3355
3348
  set(_, prop, value) {
3356
3349
  if ([
3357
3350
  "$$internal",
3351
+ "id",
3358
3352
  "environment",
3359
3353
  "config",
3360
3354
  "log",
@@ -3406,17 +3400,10 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
3406
3400
  */
3407
3401
  plugins = [];
3408
3402
  /**
3409
- * Create a new logger instance
3410
- *
3411
- * @param name - The name to use for the logger instance
3412
- * @returns A logger function
3403
+ * 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.
3413
3404
  */
3414
- createLog(name = null) {
3415
- return (0, _powerlines_core_lib_logger.createLog)(name, {
3416
- ...this.config,
3417
- logLevel: (0, _stryke_type_checks_is_null.isNull)(this.config.logLevel) ? "silent" : this.config.logLevel,
3418
- environment: this.environment?.name
3419
- });
3405
+ get id() {
3406
+ return this.environment.environmentId;
3420
3407
  }
3421
3408
  /**
3422
3409
  * The hooks registered by plugins in this environment
@@ -3425,6 +3412,54 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
3425
3412
  return this.#hooks;
3426
3413
  }
3427
3414
  /**
3415
+ * Create a new logger instance
3416
+ *
3417
+ * @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.
3418
+ * @returns A logger function
3419
+ */
3420
+ createLog(source = null) {
3421
+ return (level, ...args) => {
3422
+ process.send?.({
3423
+ id: (0, _stryke_unique_id_uuid.uuid)(),
3424
+ type: "write-log",
3425
+ executionId: this.options.executionId,
3426
+ executionIndex: this.options.executionIndex,
3427
+ timestamp: Date.now(),
3428
+ payload: {
3429
+ level,
3430
+ source,
3431
+ environment: this.environment?.name,
3432
+ args
3433
+ }
3434
+ });
3435
+ };
3436
+ }
3437
+ /**
3438
+ * Extend the current logger instance with a new name
3439
+ *
3440
+ * @param source - The name of the source to use for the extended logger instance
3441
+ * @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.
3442
+ * @returns A logger function
3443
+ */
3444
+ extendLog(source, plugin) {
3445
+ return (level, ...args) => {
3446
+ process.send?.({
3447
+ id: (0, _stryke_unique_id_uuid.uuid)(),
3448
+ type: "write-log",
3449
+ executionId: this.options.executionId,
3450
+ executionIndex: this.options.executionIndex,
3451
+ timestamp: Date.now(),
3452
+ payload: {
3453
+ level,
3454
+ source,
3455
+ plugin,
3456
+ environment: this.environment?.name,
3457
+ args
3458
+ }
3459
+ });
3460
+ };
3461
+ }
3462
+ /**
3428
3463
  * 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.
3429
3464
  *
3430
3465
  * @remarks
@@ -3454,8 +3489,10 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
3454
3489
  if ((0, _powerlines_core_plugin_utils.isPluginConfig)(result)) return this.$$internal.addPlugin(result);
3455
3490
  resolvedPlugin = (0, _powerlines_core_plugin_utils.isPlugin)(result) ? result : plugin;
3456
3491
  }
3457
- const context = createPluginContext(resolvedPlugin, this);
3492
+ const pluginId = (0, _stryke_unique_id_uuid.uuid)();
3493
+ const context = createPluginContext(pluginId, resolvedPlugin, this);
3458
3494
  this.plugins.push({
3495
+ pluginId,
3459
3496
  plugin: resolvedPlugin,
3460
3497
  context
3461
3498
  });
@@ -3581,6 +3618,12 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
3581
3618
  for (const environment of Object.values(this.environments)) environment.$$internal = super.$$internal;
3582
3619
  }
3583
3620
  /**
3621
+ * 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.
3622
+ */
3623
+ get id() {
3624
+ return this.options.executionId;
3625
+ }
3626
+ /**
3584
3627
  * A record of all environments by name
3585
3628
  */
3586
3629
  get environments() {
@@ -3598,6 +3641,33 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
3598
3641
  super(options);
3599
3642
  }
3600
3643
  /**
3644
+ * Create a new logger instance
3645
+ *
3646
+ * @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.
3647
+ * @returns A logger function
3648
+ */
3649
+ createLog(source = null) {
3650
+ const logger = (0, _powerlines_core.createLog)(source, {
3651
+ ...this.config,
3652
+ logLevel: (0, _stryke_type_checks_is_null.isNull)(this.config.logLevel) ? "silent" : this.config.logLevel
3653
+ });
3654
+ return (level, ...args) => {
3655
+ logger(level, ...args);
3656
+ process.send?.({
3657
+ id: (0, _stryke_unique_id_uuid.uuid)(),
3658
+ type: "write-log",
3659
+ executionId: this.id,
3660
+ executionIndex: this.options.executionIndex,
3661
+ timestamp: Date.now(),
3662
+ payload: {
3663
+ source,
3664
+ level,
3665
+ args
3666
+ }
3667
+ });
3668
+ };
3669
+ }
3670
+ /**
3601
3671
  * 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.
3602
3672
  *
3603
3673
  * @remarks
@@ -4459,7 +4529,7 @@ ${formatTypes(code)}
4459
4529
  addPlugin: api.addPlugin.bind(api)
4460
4530
  };
4461
4531
  const timer = api.context.timer("Initialization");
4462
- for (const plugin of api.context.config.plugins.flat(10) ?? []) await api.addPlugin(plugin);
4532
+ for (const plugin of api.context.config.plugins.flatMap((p) => (0, _stryke_convert_to_array.toArray)(p)) ?? []) await api.addPlugin(plugin);
4463
4533
  if (api.context.plugins.length === 0) api.context.warn("No Powerlines plugins were specified in the options. Please ensure this is correct, as it is generally not recommended.");
4464
4534
  else api.context.info(`Loaded ${api.context.plugins.length} ${(0, _stryke_string_format_title_case.titleCase)(api.context.config.framework)} plugin${api.context.plugins.length > 1 ? "s" : ""}: \n${api.context.plugins.map((plugin, index) => ` ${index + 1}. ${(0, _powerlines_core_lib_logger.colorText)(plugin.name)}`).join("\n")}`);
4465
4535
  const pluginConfig = await api.callHook("config", {
@@ -32,10 +32,13 @@ 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";
35
36
  import { CACHE_HASH_LENGTH, DEFAULT_ENVIRONMENT, GLOBAL_ENVIRONMENT, PLUGIN_NON_HOOK_FIELDS, ROOT_HASH_LENGTH } from "@powerlines/core/constants";
36
37
  import { readJsonFile, readJsonFileSync } from "@stryke/fs/json";
37
38
  import { deepClone } from "@stryke/helpers/deep-clone";
38
39
  import { joinPaths as joinPaths$1 } from "@stryke/path/join";
40
+ import { isNull } from "@stryke/type-checks/is-null";
41
+ import { uuid } from "@stryke/unique-id/uuid";
39
42
  import { getUniqueInputs, isTypeDefinition, resolveInputsSync } from "@powerlines/core/lib/entry";
40
43
  import { relativeToWorkspaceRoot } from "@stryke/fs/get-workspace-root";
41
44
  import { murmurhash } from "@stryke/hash";
@@ -43,8 +46,6 @@ import { hashDirectory } from "@stryke/hash/node";
43
46
  import { fetchRequest } from "@stryke/http/fetch";
44
47
  import { isEqual } from "@stryke/path/is-equal";
45
48
  import { kebabCase } from "@stryke/string-format/kebab-case";
46
- import { isNull } from "@stryke/type-checks/is-null";
47
- import { uuid } from "@stryke/unique-id/uuid";
48
49
  import { match, tsconfigPathsToRegExp } from "bundle-require";
49
50
  import { resolveCompatibilityDates } from "compatx";
50
51
  import { create } from "flat-cache";
@@ -82,6 +83,7 @@ import { getObjectDiff } from "@donedeal0/superdiff";
82
83
  //#region src/_internal/helpers/environment.ts
83
84
  function createEnvironment(name, config = {}) {
84
85
  return defu(config.environments?.[name] ?? {}, {
86
+ environmentId: uuid(),
85
87
  name,
86
88
  title: config.title ?? titleCase(config.name),
87
89
  ssr: false,
@@ -1367,7 +1369,7 @@ var VirtualFileSystem = class VirtualFileSystem {
1367
1369
  return ret;
1368
1370
  }, {});
1369
1371
  }
1370
- this.#log = extendLog(this.#context.log, "file-system");
1372
+ this.#log = context.extendLog("VFS");
1371
1373
  }
1372
1374
  /**
1373
1375
  * Asynchronously checks if a file exists in the virtual file system (VFS).
@@ -2256,23 +2258,23 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2256
2258
  /**
2257
2259
  * Create a new logger instance
2258
2260
  *
2259
- * @param name - The name to use for the logger instance
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.
2260
2262
  * @returns A logger function
2261
2263
  */
2262
- createLog(name = null) {
2263
- return createLog(name, {
2264
+ createLog(source = null) {
2265
+ return createLog(source, {
2264
2266
  ...this.options,
2265
2267
  logLevel: isNull(this.logLevel) ? "silent" : this.logLevel
2266
2268
  });
2267
2269
  }
2268
2270
  /**
2269
- * Extend the current logger instance with a new name
2271
+ * Extend the current logger instance with a new source
2270
2272
  *
2271
- * @param name - The name to use for the extended logger instance
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.
2272
2274
  * @returns A logger function
2273
2275
  */
2274
- extendLog(name) {
2275
- return extendLog(this.log, name);
2276
+ extendLog(source) {
2277
+ return extendLog(this.log, source);
2276
2278
  }
2277
2279
  /**
2278
2280
  * A logger function specific to this context
@@ -2294,7 +2296,7 @@ var PowerlinesBaseContext = class PowerlinesBaseContext {
2294
2296
  this.powerlinesPath = powerlinesPath;
2295
2297
  }
2296
2298
  const cwd = options.cwd || this.options?.cwd || process.cwd();
2297
- const root = (options.root || this.options?.root) && (options.root || this.options.root).replace(/^\.\/?/, "") && !isEqual(options.root || this.options.root, cwd) ? options.root || this.options.root : ".";
2299
+ 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);
2298
2300
  this.options = defu({
2299
2301
  root,
2300
2302
  cwd,
@@ -2626,22 +2628,10 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
2626
2628
  * @returns A promise that resolves to the cloned context.
2627
2629
  */
2628
2630
  async clone() {
2629
- const clone = await PowerlinesContext.fromOptions(this.config);
2631
+ const clone = await PowerlinesContext.fromOptions(this.options);
2630
2632
  return this.copyTo(clone);
2631
2633
  }
2632
2634
  /**
2633
- * Create a new logger instance
2634
- *
2635
- * @param name - The name to use for the logger instance
2636
- * @returns A logger function
2637
- */
2638
- createLog(name = null) {
2639
- return createLog(name, {
2640
- ...this.config,
2641
- logLevel: isNull(this.logLevel) ? "silent" : this.logLevel
2642
- });
2643
- }
2644
- /**
2645
2635
  * A function to perform HTTP fetch requests
2646
2636
  *
2647
2637
  * @remarks
@@ -3017,6 +3007,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3017
3007
  for (const [key, value] of Object.entries(this)) if (!SKIP_CLONING_PROPS.includes(key)) if (isObject(value) || Array.isArray(value)) context[key] = deepClone(value);
3018
3008
  else context[key] = value;
3019
3009
  context.inputOptions = deepClone(this.inputOptions);
3010
+ context.options = deepClone(this.options);
3020
3011
  context.dependencies = deepClone(this.dependencies);
3021
3012
  context.devDependencies = deepClone(this.devDependencies);
3022
3013
  context.persistedMeta = this.persistedMeta ? deepClone(this.persistedMeta) : void 0;
@@ -3038,7 +3029,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3038
3029
  */
3039
3030
  async init(options = {}) {
3040
3031
  await super.init(options);
3041
- this.options.configIndex = options.configIndex ?? this.options.configIndex ?? 0;
3032
+ this.options.executionIndex = options.executionIndex ?? this.options.executionIndex ?? 0;
3042
3033
  const projectJsonPath = joinPaths$1(this.options.cwd, this.options.root, "project.json");
3043
3034
  if (existsSync(projectJsonPath)) this.projectJson = await readJsonFile(projectJsonPath);
3044
3035
  const packageJsonPath = joinPaths$1(this.options.cwd, this.options.root, "package.json");
@@ -3047,7 +3038,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3047
3038
  this.options.organization ??= isSetObject(this.packageJson?.author) ? kebabCase(this.packageJson?.author?.name) : kebabCase(this.packageJson?.author);
3048
3039
  }
3049
3040
  this.#checksum = await this.generateChecksum(joinPaths$1(this.options.cwd, this.options.root));
3050
- 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 : {};
3041
+ 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 : {};
3051
3042
  this.resolvedConfig = {
3052
3043
  ...this.options,
3053
3044
  ...userConfig,
@@ -3078,7 +3069,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3078
3069
  if (this.config.userConfig.resolve?.noExternal) this.config.userConfig.resolve.noExternal = getUnique(this.config.userConfig.resolve.noExternal);
3079
3070
  if (this.config.resolve.external) this.config.resolve.external = getUnique(this.config.resolve.external);
3080
3071
  if (this.config.resolve.noExternal) this.config.resolve.noExternal = getUnique(this.config.resolve.noExternal);
3081
- this.config.plugins = (this.config.plugins ?? []).filter(Boolean).reduce((ret, plugin) => {
3072
+ this.config.plugins = (this.config.plugins ?? []).flatMap((plugin) => toArray(plugin)).filter(Boolean).reduce((ret, plugin) => {
3082
3073
  if (isPlugin(plugin) && isDuplicate(plugin, ret.filter((p) => isPlugin(p)))) return ret;
3083
3074
  ret.push(plugin);
3084
3075
  return ret;
@@ -3110,7 +3101,7 @@ var PowerlinesContext = class PowerlinesContext extends PowerlinesBaseContext {
3110
3101
  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;
3111
3102
  else this.config.output.copy.path = appendPath(replacePathTokens(this, this.config.output.copy.path || joinPaths$1("dist", this.config.root)), this.config.cwd);
3112
3103
  }
3113
- if (this.config.output.dts !== false && this.config.output.types !== false) this.config.output.types = appendPath(replacePathTokens(this, this.config.output.types || joinPaths$1(this.config.root, `${this.config.framework ?? "powerlines"}.d.ts`)), this.config.cwd);
3104
+ 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$1(this.config.root, `${this.config.framework ?? "powerlines"}.d.ts`)), this.config.cwd);
3114
3105
  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) => {
3115
3106
  return {
3116
3107
  glob: isSetObject(asset) ? asset.glob : asset,
@@ -3272,15 +3263,16 @@ function extractHooks(context, hooks, plugin, key, parentKey) {
3272
3263
  /**
3273
3264
  * Create a Proxy-based PluginContext
3274
3265
  *
3266
+ * @param pluginId - The unique identifier of the plugin
3275
3267
  * @param plugin - The plugin instance
3276
3268
  * @param environment - The environment context
3277
3269
  * @returns The proxied plugin context
3278
3270
  */
3279
- function createPluginContext(plugin, environment) {
3271
+ function createPluginContext(pluginId, plugin, environment) {
3280
3272
  const normalizeMessage = (message) => {
3281
3273
  return isString(message) ? message : message.message;
3282
3274
  };
3283
- const log = environment.extendLog(plugin.name.replaceAll(":", " - "));
3275
+ const log = environment.extendLog(pluginId, plugin.name.replaceAll(":", " - "));
3284
3276
  const callHookFn = async (hook, options, ...args) => {
3285
3277
  return environment.$$internal.api.callHook(hook, {
3286
3278
  sequential: true,
@@ -3298,6 +3290,7 @@ function createPluginContext(plugin, environment) {
3298
3290
  callHook: callHookFn,
3299
3291
  meta
3300
3292
  };
3293
+ if (prop === "id") return pluginId;
3301
3294
  if (prop === "log" || prop === "logger") return log;
3302
3295
  if (prop === "fatal") return (message) => {
3303
3296
  log(LogLevelLabel.FATAL, normalizeMessage(message));
@@ -3322,6 +3315,7 @@ function createPluginContext(plugin, environment) {
3322
3315
  set(_, prop, value) {
3323
3316
  if ([
3324
3317
  "$$internal",
3318
+ "id",
3325
3319
  "environment",
3326
3320
  "config",
3327
3321
  "log",
@@ -3373,17 +3367,10 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
3373
3367
  */
3374
3368
  plugins = [];
3375
3369
  /**
3376
- * Create a new logger instance
3377
- *
3378
- * @param name - The name to use for the logger instance
3379
- * @returns A logger function
3370
+ * 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.
3380
3371
  */
3381
- createLog(name = null) {
3382
- return createLog(name, {
3383
- ...this.config,
3384
- logLevel: isNull(this.config.logLevel) ? "silent" : this.config.logLevel,
3385
- environment: this.environment?.name
3386
- });
3372
+ get id() {
3373
+ return this.environment.environmentId;
3387
3374
  }
3388
3375
  /**
3389
3376
  * The hooks registered by plugins in this environment
@@ -3392,6 +3379,54 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
3392
3379
  return this.#hooks;
3393
3380
  }
3394
3381
  /**
3382
+ * Create a new logger instance
3383
+ *
3384
+ * @param source - The source name to use for the logger instance, which can be used to identify the origin of log messages in the logs for better traceability. This is typically the name of the plugin or module that is creating the logger instance.
3385
+ * @returns A logger function
3386
+ */
3387
+ createLog(source = null) {
3388
+ return (level, ...args) => {
3389
+ process.send?.({
3390
+ id: uuid(),
3391
+ type: "write-log",
3392
+ executionId: this.options.executionId,
3393
+ executionIndex: this.options.executionIndex,
3394
+ timestamp: Date.now(),
3395
+ payload: {
3396
+ level,
3397
+ source,
3398
+ environment: this.environment?.name,
3399
+ args
3400
+ }
3401
+ });
3402
+ };
3403
+ }
3404
+ /**
3405
+ * Extend the current logger instance with a new name
3406
+ *
3407
+ * @param source - The name of the source to use for the extended logger instance
3408
+ * @param plugin - An optional plugin name to use for the extended logger instance, which can be used to identify the origin of log messages in the logs for better traceability. This is typically the name of the plugin or module that is creating the logger instance.
3409
+ * @returns A logger function
3410
+ */
3411
+ extendLog(source, plugin) {
3412
+ return (level, ...args) => {
3413
+ process.send?.({
3414
+ id: uuid(),
3415
+ type: "write-log",
3416
+ executionId: this.options.executionId,
3417
+ executionIndex: this.options.executionIndex,
3418
+ timestamp: Date.now(),
3419
+ payload: {
3420
+ level,
3421
+ source,
3422
+ plugin,
3423
+ environment: this.environment?.name,
3424
+ args
3425
+ }
3426
+ });
3427
+ };
3428
+ }
3429
+ /**
3395
3430
  * 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.
3396
3431
  *
3397
3432
  * @remarks
@@ -3421,8 +3456,10 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
3421
3456
  if (isPluginConfig(result)) return this.$$internal.addPlugin(result);
3422
3457
  resolvedPlugin = isPlugin(result) ? result : plugin;
3423
3458
  }
3424
- const context = createPluginContext(resolvedPlugin, this);
3459
+ const pluginId = uuid();
3460
+ const context = createPluginContext(pluginId, resolvedPlugin, this);
3425
3461
  this.plugins.push({
3462
+ pluginId,
3426
3463
  plugin: resolvedPlugin,
3427
3464
  context
3428
3465
  });
@@ -3548,6 +3585,12 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
3548
3585
  for (const environment of Object.values(this.environments)) environment.$$internal = super.$$internal;
3549
3586
  }
3550
3587
  /**
3588
+ * 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.
3589
+ */
3590
+ get id() {
3591
+ return this.options.executionId;
3592
+ }
3593
+ /**
3551
3594
  * A record of all environments by name
3552
3595
  */
3553
3596
  get environments() {
@@ -3565,6 +3608,33 @@ var PowerlinesExecutionContext = class PowerlinesExecutionContext extends Powerl
3565
3608
  super(options);
3566
3609
  }
3567
3610
  /**
3611
+ * Create a new logger instance
3612
+ *
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
3615
+ */
3616
+ createLog(source = null) {
3617
+ const logger = createLog$1(source, {
3618
+ ...this.config,
3619
+ logLevel: isNull(this.config.logLevel) ? "silent" : this.config.logLevel
3620
+ });
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
+ }
3637
+ /**
3568
3638
  * 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.
3569
3639
  *
3570
3640
  * @remarks
@@ -4426,7 +4496,7 @@ ${formatTypes(code)}
4426
4496
  addPlugin: api.addPlugin.bind(api)
4427
4497
  };
4428
4498
  const timer = api.context.timer("Initialization");
4429
- for (const plugin of api.context.config.plugins.flat(10) ?? []) await api.addPlugin(plugin);
4499
+ for (const plugin of api.context.config.plugins.flatMap((p) => toArray(p)) ?? []) await api.addPlugin(plugin);
4430
4500
  if (api.context.plugins.length === 0) api.context.warn("No Powerlines plugins were specified in the options. Please ensure this is correct, as it is generally not recommended.");
4431
4501
  else api.context.info(`Loaded ${api.context.plugins.length} ${titleCase(api.context.config.framework)} plugin${api.context.plugins.length > 1 ? "s" : ""}: \n${api.context.plugins.map((plugin, index) => ` ${index + 1}. ${colorText(plugin.name)}`).join("\n")}`);
4432
4502
  const pluginConfig = await api.callHook("config", {