powerlines 0.42.33 → 0.42.34

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.
@@ -2,7 +2,7 @@ const require_chunk = require('./chunk-AIJqnxB6.cjs');
2
2
  const require_ts_morph = require('./ts-morph-Cf4wz3E0.cjs');
3
3
  const require_utils = require('./utils.cjs');
4
4
  const require_plugin_utils = require('./plugin-utils.cjs');
5
- const require_api_context = require('./api-context-Ck0P2lLD.cjs');
5
+ const require_api_context = require('./api-context-4t-rlsAr.cjs');
6
6
  const require_tsconfig = require('./tsconfig-ChmbpAO7.cjs');
7
7
  let _storm_software_config_tools_logger_console = require("@storm-software/config-tools/logger/console");
8
8
  let _stryke_convert_to_array = require("@stryke/convert/to-array");
@@ -37,7 +37,6 @@ defu = require_chunk.__toESM(defu);
37
37
  let handlebars = require("handlebars");
38
38
  handlebars = require_chunk.__toESM(handlebars);
39
39
  let _stryke_string_format_pretty_bytes = require("@stryke/string-format/pretty-bytes");
40
- let bundle_require = require("bundle-require");
41
40
  let ts_morph = require("ts-morph");
42
41
  let _stryke_string_format_package = require("@stryke/string-format/package");
43
42
  let _stryke_fs_json = require("@stryke/fs/json");
@@ -46,7 +45,7 @@ let _stryke_json_storm_json = require("@stryke/json/storm-json");
46
45
 
47
46
  //#region package.json
48
47
  var name = "powerlines";
49
- var version = "0.42.33";
48
+ var version = "0.42.34";
50
49
 
51
50
  //#endregion
52
51
  //#region src/_internal/helpers/generate-types.ts
@@ -59,31 +58,96 @@ var version = "0.42.33";
59
58
  function formatTypes(code = "") {
60
59
  return code.replaceAll("#private;", "").replace(/__Ω/g, "");
61
60
  }
62
- /**
63
- * Formats a generated TypeScript module in the types source code.
64
- *
65
- * @param context - The Powerlines context.
66
- * @param id - The module ID for the generated TypeScript module.
67
- * @param code - The generated TypeScript module code.
68
- * @returns The formatted TypeScript module code.
69
- */
70
- async function formatTypesModule(context, id, code) {
71
- const moduleComment = code.match(new RegExp(`\\/\\*\\*(?s:.)*?@module\\s+${context.config.framework}:${id}(?s:.)*?\\*\\/\\s+`))?.find((comment) => (0, _stryke_type_checks_is_set_string.isSetString)(comment?.trim()));
72
- const ast = await context.parse(code, {
73
- lang: "dts",
74
- astType: "ts"
61
+ async function extractModuleDeclarations(context, filePath, id, code, fileToModuleMap) {
62
+ const mappings = /* @__PURE__ */ new Map();
63
+ const ambient = [];
64
+ const sourceFile = new ts_morph.Project({ useInMemoryFileSystem: true }).createSourceFile("module.d.ts", code);
65
+ for (const ref of sourceFile.getTypeReferenceDirectives()) ambient.push({
66
+ id: ref.getFileName(),
67
+ external: true
75
68
  });
69
+ const importLines = [];
70
+ const reExportLines = [];
71
+ const declarationLines = [];
72
+ for (const statement of sourceFile.getStatements()) {
73
+ if (ts_morph.Node.isImportDeclaration(statement)) {
74
+ const moduleSpec = statement.getModuleSpecifierValue();
75
+ const defaultImport = statement.getDefaultImport();
76
+ const namedImports = statement.getNamedImports();
77
+ const namespaceImport = statement.getNamespaceImport();
78
+ if (!defaultImport && namedImports.length === 0 && !namespaceImport) {
79
+ ambient.push({
80
+ id: moduleSpec,
81
+ external: !context.fs.isResolvableId(moduleSpec, filePath)
82
+ });
83
+ continue;
84
+ }
85
+ let resolvedSpec = moduleSpec;
86
+ if (context.fs.isResolvableId(moduleSpec, filePath)) {
87
+ const resolved = await context.resolve(moduleSpec, filePath);
88
+ if (resolved) {
89
+ const mapped = fileToModuleMap.get(resolved.id);
90
+ if (mapped) resolvedSpec = mapped;
91
+ else context.trace(`Could not resolve relative import '${moduleSpec}' from '${filePath}' to a builtin module. Keeping as-is.`);
92
+ }
93
+ }
94
+ if (namespaceImport) importLines.push(`\timport * as ${namespaceImport.getText()} from '${resolvedSpec}';`);
95
+ else {
96
+ const specifiers = [];
97
+ if (defaultImport) specifiers.push(`default as ${defaultImport.getText()}`);
98
+ for (const named of namedImports) {
99
+ const alias = named.getAliasNode()?.getText();
100
+ specifiers.push(alias ? `${named.getName()} as ${alias}` : named.getName());
101
+ }
102
+ if (specifiers.length > 0) {
103
+ const typeOnly = statement.isTypeOnly() ? " type" : "";
104
+ importLines.push(`\timport${typeOnly} { ${specifiers.join(", ")} } from '${resolvedSpec}';`);
105
+ }
106
+ }
107
+ continue;
108
+ }
109
+ if (ts_morph.Node.isExportDeclaration(statement)) {
110
+ const moduleSpec = statement.getModuleSpecifierValue();
111
+ if (moduleSpec) {
112
+ let resolvedSpec = moduleSpec;
113
+ if (context.fs.isResolvableId(moduleSpec, filePath)) {
114
+ const resolved = await context.resolve(moduleSpec, filePath);
115
+ if (resolved) {
116
+ const mapped = fileToModuleMap.get(resolved.id);
117
+ if (mapped) resolvedSpec = mapped;
118
+ else context.trace(`Could not resolve relative import '${moduleSpec}' from '${filePath}' to a builtin module. Keeping as-is.`);
119
+ }
120
+ }
121
+ const namedExports = statement.getNamedExports();
122
+ if (namedExports.length > 0) {
123
+ const specifiers = namedExports.map((named) => {
124
+ const alias = named.getAliasNode()?.getText();
125
+ return alias ? `${named.getName()} as ${alias}` : named.getName();
126
+ });
127
+ const typeOnly = statement.isTypeOnly() ? " type" : "";
128
+ reExportLines.push(`\texport${typeOnly} { ${specifiers.join(", ")} } from '${resolvedSpec}';`);
129
+ } else reExportLines.push(`\texport * from '${resolvedSpec}';`);
130
+ } else declarationLines.push(`\t${statement.getText()}`);
131
+ continue;
132
+ }
133
+ if (ts_morph.Node.isExportAssignment(statement)) {
134
+ declarationLines.push(`\t${statement.getText()}`);
135
+ continue;
136
+ }
137
+ const text = statement.getText();
138
+ if (text.includes("//# sourceMappingURL=")) continue;
139
+ declarationLines.push(formatTypes(text.replace(/^(export\s+)?declare\s+/, "$1")).split("\n").map((line) => `\t${line}`).join("\n"));
140
+ }
141
+ const moduleComment = code.match(new RegExp(`\\/\\*\\*(?s:.)*?@module\\s+${context.config.framework}:${id}(?s:.)*?\\*\\/\\s+`))?.find((comment) => (0, _stryke_type_checks_is_set_string.isSetString)(comment?.trim()));
142
+ let content = `${moduleComment ? `${moduleComment.trim()}\n` : ""}declare module "${context.config.framework}:${id}" {`;
143
+ for (const line of importLines) content += `\n${line}`;
144
+ for (const line of reExportLines) content += `\n${line}`;
145
+ for (const line of declarationLines) content += `\n${line}`;
146
+ content += "\n}";
76
147
  return {
77
- code: `${moduleComment ? `
78
- ${moduleComment.trim()}` : ""}
79
- declare module "${context.config.framework}:${id}" {
80
- ${ast.module.staticImports.filter((staticImport) => !(0, bundle_require.match)(staticImport.moduleRequest.value, context.config.resolve.external) && !staticImport.moduleRequest.value.startsWith("node:")).reduce((ret, staticImport) => {
81
- return ret.replaceAll(new RegExp(`^import.*from\\s+['"]${staticImport.moduleRequest.value}['"]\\s*;?$`, "gm"), "");
82
- }, code).replace(moduleComment ?? "", "").replaceAll(/^\s*export\s*declare\s*/gm, "export ").replaceAll(/^\s*declare\s*/gm, "").replaceAll(/^\s*export\s*\{\s*\}/gm, "").replaceAll(/^\s*export\s*=\s*/gm, "export default ").replaceAll(/^\s*export\s*\{/gm, "export {").replaceAll(/^\s*export\s*default\s*\{/gm, "export default {").replaceAll(/^\s*export\s*function\s*/gm, "export function ").replaceAll(/^\s*export\s*class\s*/gm, "export class ").replaceAll(/^\s*export\s*interface\s*/gm, "export interface ").replaceAll(/^\s*export\s*type\s*/gm, "export type ").replaceAll(/^\s*export\s*enum\s*/gm, "export enum ").replaceAll(/^\s*export\s*namespace\s*/gm, "export namespace ")}${ast.module.staticExports.length === 0 ? `
83
- export {};` : ""}
84
- }
85
- `,
86
- directives: ast.module.staticImports.filter((staticImport) => (0, bundle_require.match)(staticImport.moduleRequest.value, context.config.resolve.external) || staticImport.moduleRequest.value.startsWith("node:")).map((staticImport) => staticImport.moduleRequest.value.startsWith("node:") ? "node" : Object.keys(context.packageJson.dependencies ?? {}).find((dependency) => staticImport.moduleRequest.value.startsWith(dependency) || staticImport.moduleRequest.value.startsWith(dependency.replace(/^@types\//, ""))) || Object.keys(context.packageJson.devDependencies ?? {}).find((dependency) => staticImport.moduleRequest.value.startsWith(dependency) || staticImport.moduleRequest.value.startsWith(dependency.replace(/^@types\//, ""))) || Object.keys(context.packageJson.peerDependencies ?? {}).find((dependency) => staticImport.moduleRequest.value.startsWith(dependency) || staticImport.moduleRequest.value.startsWith(dependency.replace(/^@types\//, ""))) || staticImport.moduleRequest.value).filter(Boolean).map((dependency) => dependency.replace(/^@types\//, ""))
148
+ content,
149
+ mappings,
150
+ ambient
87
151
  };
88
152
  }
89
153
  /**
@@ -130,24 +194,73 @@ async function emitBuiltinTypes(context, files) {
130
194
  directives: []
131
195
  };
132
196
  }
133
- let result = "";
134
- const directives = [];
197
+ const fileToModuleMap = /* @__PURE__ */ new Map();
198
+ const emittedBuiltinFiles = [];
135
199
  for (const emittedFile of emittedFiles) {
136
- context.trace(`Processing emitted type declaration file: ${emittedFile.filePath}`);
137
200
  const filePath = (0, _stryke_path_append.appendPath)(emittedFile.filePath, context.workspaceConfig.workspaceRoot);
138
201
  if (!filePath.endsWith(".map") && (0, _stryke_path_file_path_fns.findFileName)(filePath) !== "tsconfig.tsbuildinfo" && (0, _stryke_path_is_parent_path.isParentPath)(filePath, context.builtinsPath)) {
139
202
  const moduleId = (0, _stryke_path_replace.replaceExtension)((0, _stryke_path_replace.replacePath)((0, _stryke_path_replace.replacePath)(filePath, context.builtinsPath), (0, _stryke_path_replace.replacePath)(context.builtinsPath, context.workspaceConfig.workspaceRoot)), "", { fullExtension: true });
140
203
  if (context.builtins.includes(moduleId)) {
141
- const formatted = await formatTypesModule(context, moduleId, emittedFile.text);
142
- result += formatted.code;
143
- directives.push(...formatted.directives);
204
+ fileToModuleMap.set(filePath, moduleId);
205
+ emittedBuiltinFiles.push({
206
+ filePath,
207
+ text: emittedFile.text
208
+ });
144
209
  }
145
210
  }
146
211
  }
147
- result = await (0, require_utils.utils_exports.format)(context, context.typesPath, formatTypes(result));
148
- context.debug(`A TypeScript declaration file (size: ${(0, _stryke_string_format_pretty_bytes.prettyBytes)(new Blob((0, _stryke_convert_to_array.toArray)(result)).size)}) emitted for the built-in modules types.`);
212
+ const builtins = await context.getBuiltins();
213
+ const emittedContentMap = /* @__PURE__ */ new Map();
214
+ for (const emittedFile of emittedFiles) {
215
+ const filePath = (0, _stryke_path_append.appendPath)(emittedFile.filePath, context.workspaceConfig.workspaceRoot);
216
+ if (!filePath.endsWith(".map") && (0, _stryke_path_file_path_fns.findFileName)(filePath) !== "tsconfig.tsbuildinfo") emittedContentMap.set(filePath, emittedFile.text);
217
+ }
218
+ let code = "";
219
+ const directives = [];
220
+ const ambientModules = /* @__PURE__ */ new Set();
221
+ let isFirst = true;
222
+ for (const entry of emittedBuiltinFiles) {
223
+ context.trace(`Processing emitted type declaration file: ${entry.filePath}`);
224
+ const moduleId = fileToModuleMap.get(entry.filePath);
225
+ const moduleDecl = await extractModuleDeclarations(context, entry.filePath, moduleId, entry.text, fileToModuleMap);
226
+ if (!isFirst) code += "\n\n";
227
+ isFirst = false;
228
+ code += moduleDecl.content;
229
+ for (const dep of moduleDecl.ambient) if (dep.external) {
230
+ const directive = dep.id;
231
+ if (!directives.includes(directive)) directives.push(directive);
232
+ } else if (builtins.some((builtin) => builtin.id === dep.id)) ambientModules.add(builtins.find((builtin) => builtin.id === dep.id).path);
233
+ else if (builtins.some((builtin) => (0, _stryke_path_replace.replaceExtension)(builtin.path) === (0, _stryke_path_replace.replaceExtension)(dep.id))) ambientModules.add(dep.id);
234
+ else {
235
+ const resolved = await context.resolve(dep.id, entry.filePath);
236
+ if (resolved) {
237
+ for (const name of [
238
+ resolved.id,
239
+ `${resolved.id}.d.ts`,
240
+ `${resolved.id}.d.mts`,
241
+ `${resolved.id}.d.cts`,
242
+ (0, _stryke_path_replace.replaceExtension)(resolved.id, ".d.ts"),
243
+ (0, _stryke_path_replace.replaceExtension)(resolved.id, ".d.mts"),
244
+ (0, _stryke_path_replace.replaceExtension)(resolved.id, ".d.cts"),
245
+ `${resolved.id}/index.d.ts`
246
+ ]) if (emittedContentMap.has(name)) {
247
+ ambientModules.add(name);
248
+ break;
249
+ }
250
+ }
251
+ }
252
+ }
253
+ for (const ambientFile of ambientModules) {
254
+ const dts = emittedContentMap.get(ambientFile);
255
+ if (dts) {
256
+ const cleaned = dts.replace(/\/\/# sourceMappingURL=.*$/m, "").trim();
257
+ if (cleaned) code += `\n\n${formatTypes(cleaned)}`;
258
+ }
259
+ }
260
+ code = await (0, require_utils.utils_exports.format)(context, context.typesPath, code);
261
+ context.debug(`A TypeScript declaration file (size: ${(0, _stryke_string_format_pretty_bytes.prettyBytes)(new Blob((0, _stryke_convert_to_array.toArray)(code)).size)}) emitted for the built-in modules types.`);
149
262
  return {
150
- code: result,
263
+ code,
151
264
  directives
152
265
  };
153
266
  }
@@ -327,7 +440,7 @@ var PowerlinesAPI = class PowerlinesAPI {
327
440
  api.context.info(`🔌 The Powerlines Engine v${version} has started`);
328
441
  for (const plugin of api.context.config.plugins.flat(10) ?? []) await api.#addPlugin(plugin);
329
442
  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.");
330
- 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\n${api.context.plugins.map((plugin, index) => ` ${index + 1}. ${(0, require_utils.utils_exports.colorText)(plugin.name)}`).join("\n")}`);
443
+ 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, require_utils.utils_exports.colorText)(plugin.name)}`).join("\n")}`);
331
444
  const pluginConfig = await api.callHook("config", {
332
445
  environment: await api.context.getEnvironment(),
333
446
  sequential: true,
@@ -768,7 +881,7 @@ var PowerlinesAPI = class PowerlinesAPI {
768
881
  if (!plugins) throw new Error(`The plugin configuration ${JSON.stringify(awaited)} is invalid. This configuration must point to a valid Powerlines plugin module.`);
769
882
  if (plugins.length > 0 && !plugins.every(require_plugin_utils.plugin_utils_exports.isPlugin)) throw new Error(`The plugin option ${JSON.stringify(plugins)} does not export a valid module. This configuration must point to a valid Powerlines plugin module.`);
770
883
  const result = [];
771
- for (const plugin of plugins) if ((0, require_plugin_utils.plugin_utils_exports.checkDedupe)(plugin, this.context.plugins)) this.context.trace(`Duplicate ${chalk.default.bold.cyanBright(plugin.name)} plugin dependency detected - Skipping initialization.`);
884
+ for (const plugin of plugins) if ((0, require_plugin_utils.plugin_utils_exports.isDuplicate)(plugin, this.context.plugins)) this.context.trace(`Duplicate ${chalk.default.bold.cyanBright(plugin.name)} plugin dependency detected - Skipping initialization.`);
772
885
  else {
773
886
  result.push(plugin);
774
887
  this.context.trace(`Initializing the ${chalk.default.bold.cyanBright(plugin.name)} plugin...`);
@@ -28,7 +28,7 @@ chalk = require_chunk.__toESM(chalk);
28
28
  let defu = require("defu");
29
29
  defu = require_chunk.__toESM(defu);
30
30
  let _stryke_string_format_pretty_bytes = require("@stryke/string-format/pretty-bytes");
31
- let bundle_require = require("bundle-require");
31
+ let _powerlines_core_lib_logger = require("@powerlines/core/lib/logger");
32
32
  let _stryke_helpers_get_field = require("@stryke/helpers/get-field");
33
33
  let _stryke_fs_json = require("@stryke/fs/json");
34
34
  require("@stryke/fs/remove-file");
@@ -43,6 +43,7 @@ let _stryke_http_fetch = require("@stryke/http/fetch");
43
43
  let _stryke_path_join = require("@stryke/path/join");
44
44
  let _stryke_type_checks_is_null = require("@stryke/type-checks/is-null");
45
45
  let _stryke_unique_id_uuid = require("@stryke/unique-id/uuid");
46
+ let bundle_require = require("bundle-require");
46
47
  let compatx = require("compatx");
47
48
  let flat_cache = require("flat-cache");
48
49
  let oxc_parser = require("oxc-parser");
@@ -104,7 +105,7 @@ function mergeConfigs(currentResult, previousResults) {
104
105
  async function callHook(context, key, options, ...args) {
105
106
  const hooks = context.selectHooks(key, options);
106
107
  if (hooks.length > 0) {
107
- context.debug(` 🧩 Calling plugin hook: ${chalk.default.bold.cyanBright(`${key}${options?.order ? ` (${options.order})` : ""}`)}`);
108
+ context.debug(` 🧩 Calling ${hooks.length} ${chalk.default.bold.cyanBright(`${key}${options?.order ? ` (${options.order})` : ""}`)} plugin hook${hooks.length > 1 ? "s" : ""}:\n${hooks.map((hook, index) => ` ${index + 1}. ${(0, require_utils.utils_exports.colorText)(hook.plugin.name)}`).join("\n")}`);
108
109
  const invokeHook = async (hook, hookArgs) => {
109
110
  return Reflect.apply(hook.handler, hook.context, hookArgs);
110
111
  };
@@ -151,21 +152,42 @@ function extractHooks(context, hooks, plugin, key, parentKey) {
151
152
  if (plugin.enforce) {
152
153
  const hookListOrder = `${plugin.enforce}Enforced`;
153
154
  hooks[combinedKey][hookListOrder] ??= [];
154
- const bucket = hooks[combinedKey][hookListOrder];
155
- (0, require_plugin_utils.plugin_utils_exports.addPluginHook)(context, plugin, pluginHook, bucket);
155
+ hooks[combinedKey][hookListOrder] = (0, require_plugin_utils.plugin_utils_exports.addPluginHook)(context, plugin, pluginHook, hooks[combinedKey][hookListOrder]);
156
156
  return hooks;
157
157
  }
158
158
  if ((0, _stryke_type_checks_is_function.isFunction)(pluginHook) || !pluginHook.order) {
159
159
  hooks[combinedKey].normal ??= [];
160
- const bucket = hooks[combinedKey].normal;
161
- (0, require_plugin_utils.plugin_utils_exports.addPluginHook)(context, plugin, pluginHook, bucket);
160
+ hooks[combinedKey].normal = (0, require_plugin_utils.plugin_utils_exports.addPluginHook)(context, plugin, pluginHook, hooks[combinedKey].normal);
162
161
  return hooks;
163
162
  }
164
163
  const hookListOrder = `${pluginHook.order}Ordered`;
165
164
  hooks[combinedKey][hookListOrder] ??= [];
166
- (0, require_plugin_utils.plugin_utils_exports.addPluginHook)(context, plugin, pluginHook, hooks[combinedKey][hookListOrder]);
165
+ hooks[combinedKey][hookListOrder] = (0, require_plugin_utils.plugin_utils_exports.addPluginHook)(context, plugin, pluginHook, hooks[combinedKey][hookListOrder]);
167
166
  return hooks;
168
- } else if ((0, _stryke_type_checks_is_set_object.isSetObject)(pluginField)) return Object.keys(pluginField).map((pluginKey) => extractHooks(context, hooks, plugin, pluginKey, combinedKey)).reduce((ret, current) => (0, defu.defu)(ret, current), hooks);
167
+ } else if ((0, _stryke_type_checks_is_set_object.isSetObject)(pluginField)) return Object.keys(pluginField).map((pluginKey) => extractHooks(context, hooks, plugin, pluginKey, combinedKey)).reduce((ret, current) => {
168
+ Object.keys(current).forEach((key) => {
169
+ ret[key] ??= {
170
+ preEnforced: [],
171
+ preOrdered: [],
172
+ normal: [],
173
+ postEnforced: [],
174
+ postOrdered: []
175
+ };
176
+ [
177
+ "preEnforced",
178
+ "preOrdered",
179
+ "normal",
180
+ "postEnforced",
181
+ "postOrdered"
182
+ ].forEach((order) => {
183
+ if (current[key]?.[order]) {
184
+ ret[key][order] ??= [];
185
+ ret[key][order] = ret[key][order].concat(current[key][order]);
186
+ }
187
+ });
188
+ });
189
+ return ret;
190
+ }, hooks);
169
191
  return hooks;
170
192
  }
171
193
 
@@ -2328,7 +2350,8 @@ var PowerlinesContext = class PowerlinesContext {
2328
2350
  createLog(name = null) {
2329
2351
  return (0, require_utils.utils_exports.createLog)(name, {
2330
2352
  ...this.config,
2331
- logLevel: (0, _stryke_type_checks_is_null.isNull)(this.config.logLevel) ? "silent" : this.config.logLevel
2353
+ logLevel: (0, _stryke_type_checks_is_null.isNull)(this.config.logLevel) ? "silent" : this.config.logLevel,
2354
+ command: this.config.command
2332
2355
  });
2333
2356
  }
2334
2357
  /**
@@ -2518,7 +2541,7 @@ var PowerlinesContext = class PowerlinesContext {
2518
2541
  };
2519
2542
  }), (a) => `${a.input}-${a.glob}-${a.output}`);
2520
2543
  this.config.plugins = (this.config.plugins ?? []).filter(Boolean).reduce((ret, plugin) => {
2521
- if ((0, require_plugin_utils.plugin_utils_exports.isPlugin)(plugin) && (0, require_plugin_utils.plugin_utils_exports.checkDedupe)(plugin, ret.filter((p) => (0, require_plugin_utils.plugin_utils_exports.isPlugin)(p)))) return ret;
2544
+ if ((0, require_plugin_utils.plugin_utils_exports.isPlugin)(plugin) && (0, require_plugin_utils.plugin_utils_exports.isDuplicate)(plugin, ret.filter((p) => (0, require_plugin_utils.plugin_utils_exports.isPlugin)(p)))) return ret;
2522
2545
  ret.push(plugin);
2523
2546
  return ret;
2524
2547
  }, []);
@@ -2539,7 +2562,7 @@ var PowerlinesContext = class PowerlinesContext {
2539
2562
  this.config.userConfig = (0, require_plugin_utils.plugin_utils_exports.mergeConfig)(from, into);
2540
2563
  if (this.config.userConfig.output?.format) this.config.userConfig.output.format = (0, _stryke_helpers_get_unique.getUnique)((0, _stryke_convert_to_array.toArray)(this.config.userConfig.output?.format));
2541
2564
  this.config.userConfig.plugins = (this.config.userConfig.plugins ?? []).filter(Boolean).reduce((ret, plugin) => {
2542
- if ((0, require_plugin_utils.plugin_utils_exports.isPlugin)(plugin) && (0, require_plugin_utils.plugin_utils_exports.checkDedupe)(plugin, ret.filter((p) => (0, require_plugin_utils.plugin_utils_exports.isPlugin)(p)))) return ret;
2565
+ if ((0, require_plugin_utils.plugin_utils_exports.isPlugin)(plugin) && (0, require_plugin_utils.plugin_utils_exports.isDuplicate)(plugin, ret.filter((p) => (0, require_plugin_utils.plugin_utils_exports.isPlugin)(p)))) return ret;
2543
2566
  ret.push(plugin);
2544
2567
  return ret;
2545
2568
  }, []);
@@ -2657,6 +2680,22 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
2657
2680
  get config() {
2658
2681
  return super.config;
2659
2682
  }
2683
+ /**
2684
+ * Create a new logger instance
2685
+ *
2686
+ * @param name - The name to use for the logger instance
2687
+ * @returns A logger function
2688
+ */
2689
+ createLog(name = null) {
2690
+ return (0, _powerlines_core_lib_logger.createLog)(name, {
2691
+ ...this.config,
2692
+ logLevel: (0, _stryke_type_checks_is_null.isNull)(this.config.logLevel) ? "silent" : this.config.logLevel,
2693
+ environment: this.environment?.name
2694
+ });
2695
+ }
2696
+ /**
2697
+ * The hooks registered by plugins in this environment
2698
+ */
2660
2699
  get hooks() {
2661
2700
  return this.#hooks;
2662
2701
  }
@@ -2694,8 +2733,7 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
2694
2733
  selectHooks(key, options) {
2695
2734
  const result = [];
2696
2735
  if ((0, require_plugin_utils.plugin_utils_exports.isPluginHookField)(key) && this.hooks[key]) {
2697
- const hooks = this.hooks[key];
2698
- if (hooks) if (options?.order) {
2736
+ if (this.hooks[key]) if (options?.order) {
2699
2737
  const mapHooksToResult = (hooksList) => hooksList.map((hook) => {
2700
2738
  const plugin = this.plugins.find((p) => p.plugin.name === hook.plugin.name);
2701
2739
  if (!plugin) throw new Error(`Could not find plugin context for plugin "${hook.plugin.name}".`);
@@ -2706,12 +2744,12 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
2706
2744
  };
2707
2745
  });
2708
2746
  if (options?.order === "pre") {
2709
- result.push(...mapHooksToResult(hooks.preOrdered ?? []));
2710
- result.push(...mapHooksToResult(hooks.preEnforced ?? []));
2747
+ result.push(...mapHooksToResult(this.hooks[key].preOrdered ?? []));
2748
+ result.push(...mapHooksToResult(this.hooks[key].preEnforced ?? []));
2711
2749
  } else if (options?.order === "post") {
2712
- result.push(...mapHooksToResult(hooks.postOrdered ?? []));
2713
- result.push(...mapHooksToResult(hooks.postEnforced ?? []));
2714
- } else result.push(...mapHooksToResult(hooks.normal ?? []));
2750
+ result.push(...mapHooksToResult(this.hooks[key].postOrdered ?? []));
2751
+ result.push(...mapHooksToResult(this.hooks[key].postEnforced ?? []));
2752
+ } else result.push(...mapHooksToResult(this.hooks[key].normal ?? []));
2715
2753
  } else {
2716
2754
  result.push(...this.selectHooks(key, { order: "pre" }));
2717
2755
  result.push(...this.selectHooks(key, { order: "normal" }));
@@ -25,7 +25,7 @@ import { isString } from "@stryke/type-checks/is-string";
25
25
  import chalk from "chalk";
26
26
  import defu$1, { createDefu, defu } from "defu";
27
27
  import { prettyBytes } from "@stryke/string-format/pretty-bytes";
28
- import { match, tsconfigPathsToRegExp } from "bundle-require";
28
+ import { createLog } from "@powerlines/core/lib/logger";
29
29
  import { getField } from "@stryke/helpers/get-field";
30
30
  import { readJsonFile } from "@stryke/fs/json";
31
31
  import "@stryke/fs/remove-file";
@@ -40,6 +40,7 @@ import { fetchRequest } from "@stryke/http/fetch";
40
40
  import { joinPaths as joinPaths$1 } from "@stryke/path/join";
41
41
  import { isNull } from "@stryke/type-checks/is-null";
42
42
  import { uuid } from "@stryke/unique-id/uuid";
43
+ import { match, tsconfigPathsToRegExp } from "bundle-require";
43
44
  import { resolveCompatibilityDates } from "compatx";
44
45
  import { create } from "flat-cache";
45
46
  import { parse } from "oxc-parser";
@@ -100,7 +101,7 @@ function mergeConfigs(currentResult, previousResults) {
100
101
  async function callHook(context, key, options, ...args) {
101
102
  const hooks = context.selectHooks(key, options);
102
103
  if (hooks.length > 0) {
103
- context.debug(` 🧩 Calling plugin hook: ${chalk.bold.cyanBright(`${key}${options?.order ? ` (${options.order})` : ""}`)}`);
104
+ context.debug(` 🧩 Calling ${hooks.length} ${chalk.bold.cyanBright(`${key}${options?.order ? ` (${options.order})` : ""}`)} plugin hook${hooks.length > 1 ? "s" : ""}:\n${hooks.map((hook, index) => ` ${index + 1}. ${(0, utils_exports.colorText)(hook.plugin.name)}`).join("\n")}`);
104
105
  const invokeHook = async (hook, hookArgs) => {
105
106
  return Reflect.apply(hook.handler, hook.context, hookArgs);
106
107
  };
@@ -147,21 +148,42 @@ function extractHooks(context, hooks, plugin, key, parentKey) {
147
148
  if (plugin.enforce) {
148
149
  const hookListOrder = `${plugin.enforce}Enforced`;
149
150
  hooks[combinedKey][hookListOrder] ??= [];
150
- const bucket = hooks[combinedKey][hookListOrder];
151
- (0, plugin_utils_exports.addPluginHook)(context, plugin, pluginHook, bucket);
151
+ hooks[combinedKey][hookListOrder] = (0, plugin_utils_exports.addPluginHook)(context, plugin, pluginHook, hooks[combinedKey][hookListOrder]);
152
152
  return hooks;
153
153
  }
154
154
  if (isFunction(pluginHook) || !pluginHook.order) {
155
155
  hooks[combinedKey].normal ??= [];
156
- const bucket = hooks[combinedKey].normal;
157
- (0, plugin_utils_exports.addPluginHook)(context, plugin, pluginHook, bucket);
156
+ hooks[combinedKey].normal = (0, plugin_utils_exports.addPluginHook)(context, plugin, pluginHook, hooks[combinedKey].normal);
158
157
  return hooks;
159
158
  }
160
159
  const hookListOrder = `${pluginHook.order}Ordered`;
161
160
  hooks[combinedKey][hookListOrder] ??= [];
162
- (0, plugin_utils_exports.addPluginHook)(context, plugin, pluginHook, hooks[combinedKey][hookListOrder]);
161
+ hooks[combinedKey][hookListOrder] = (0, plugin_utils_exports.addPluginHook)(context, plugin, pluginHook, hooks[combinedKey][hookListOrder]);
163
162
  return hooks;
164
- } else if (isSetObject(pluginField)) return Object.keys(pluginField).map((pluginKey) => extractHooks(context, hooks, plugin, pluginKey, combinedKey)).reduce((ret, current) => defu(ret, current), hooks);
163
+ } else if (isSetObject(pluginField)) return Object.keys(pluginField).map((pluginKey) => extractHooks(context, hooks, plugin, pluginKey, combinedKey)).reduce((ret, current) => {
164
+ Object.keys(current).forEach((key) => {
165
+ ret[key] ??= {
166
+ preEnforced: [],
167
+ preOrdered: [],
168
+ normal: [],
169
+ postEnforced: [],
170
+ postOrdered: []
171
+ };
172
+ [
173
+ "preEnforced",
174
+ "preOrdered",
175
+ "normal",
176
+ "postEnforced",
177
+ "postOrdered"
178
+ ].forEach((order) => {
179
+ if (current[key]?.[order]) {
180
+ ret[key][order] ??= [];
181
+ ret[key][order] = ret[key][order].concat(current[key][order]);
182
+ }
183
+ });
184
+ });
185
+ return ret;
186
+ }, hooks);
165
187
  return hooks;
166
188
  }
167
189
 
@@ -2324,7 +2346,8 @@ var PowerlinesContext = class PowerlinesContext {
2324
2346
  createLog(name = null) {
2325
2347
  return (0, utils_exports.createLog)(name, {
2326
2348
  ...this.config,
2327
- logLevel: isNull(this.config.logLevel) ? "silent" : this.config.logLevel
2349
+ logLevel: isNull(this.config.logLevel) ? "silent" : this.config.logLevel,
2350
+ command: this.config.command
2328
2351
  });
2329
2352
  }
2330
2353
  /**
@@ -2514,7 +2537,7 @@ var PowerlinesContext = class PowerlinesContext {
2514
2537
  };
2515
2538
  }), (a) => `${a.input}-${a.glob}-${a.output}`);
2516
2539
  this.config.plugins = (this.config.plugins ?? []).filter(Boolean).reduce((ret, plugin) => {
2517
- if ((0, plugin_utils_exports.isPlugin)(plugin) && (0, plugin_utils_exports.checkDedupe)(plugin, ret.filter((p) => (0, plugin_utils_exports.isPlugin)(p)))) return ret;
2540
+ if ((0, plugin_utils_exports.isPlugin)(plugin) && (0, plugin_utils_exports.isDuplicate)(plugin, ret.filter((p) => (0, plugin_utils_exports.isPlugin)(p)))) return ret;
2518
2541
  ret.push(plugin);
2519
2542
  return ret;
2520
2543
  }, []);
@@ -2535,7 +2558,7 @@ var PowerlinesContext = class PowerlinesContext {
2535
2558
  this.config.userConfig = (0, plugin_utils_exports.mergeConfig)(from, into);
2536
2559
  if (this.config.userConfig.output?.format) this.config.userConfig.output.format = getUnique(toArray(this.config.userConfig.output?.format));
2537
2560
  this.config.userConfig.plugins = (this.config.userConfig.plugins ?? []).filter(Boolean).reduce((ret, plugin) => {
2538
- if ((0, plugin_utils_exports.isPlugin)(plugin) && (0, plugin_utils_exports.checkDedupe)(plugin, ret.filter((p) => (0, plugin_utils_exports.isPlugin)(p)))) return ret;
2561
+ if ((0, plugin_utils_exports.isPlugin)(plugin) && (0, plugin_utils_exports.isDuplicate)(plugin, ret.filter((p) => (0, plugin_utils_exports.isPlugin)(p)))) return ret;
2539
2562
  ret.push(plugin);
2540
2563
  return ret;
2541
2564
  }, []);
@@ -2653,6 +2676,22 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
2653
2676
  get config() {
2654
2677
  return super.config;
2655
2678
  }
2679
+ /**
2680
+ * Create a new logger instance
2681
+ *
2682
+ * @param name - The name to use for the logger instance
2683
+ * @returns A logger function
2684
+ */
2685
+ createLog(name = null) {
2686
+ return createLog(name, {
2687
+ ...this.config,
2688
+ logLevel: isNull(this.config.logLevel) ? "silent" : this.config.logLevel,
2689
+ environment: this.environment?.name
2690
+ });
2691
+ }
2692
+ /**
2693
+ * The hooks registered by plugins in this environment
2694
+ */
2656
2695
  get hooks() {
2657
2696
  return this.#hooks;
2658
2697
  }
@@ -2690,8 +2729,7 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
2690
2729
  selectHooks(key, options) {
2691
2730
  const result = [];
2692
2731
  if ((0, plugin_utils_exports.isPluginHookField)(key) && this.hooks[key]) {
2693
- const hooks = this.hooks[key];
2694
- if (hooks) if (options?.order) {
2732
+ if (this.hooks[key]) if (options?.order) {
2695
2733
  const mapHooksToResult = (hooksList) => hooksList.map((hook) => {
2696
2734
  const plugin = this.plugins.find((p) => p.plugin.name === hook.plugin.name);
2697
2735
  if (!plugin) throw new Error(`Could not find plugin context for plugin "${hook.plugin.name}".`);
@@ -2702,12 +2740,12 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
2702
2740
  };
2703
2741
  });
2704
2742
  if (options?.order === "pre") {
2705
- result.push(...mapHooksToResult(hooks.preOrdered ?? []));
2706
- result.push(...mapHooksToResult(hooks.preEnforced ?? []));
2743
+ result.push(...mapHooksToResult(this.hooks[key].preOrdered ?? []));
2744
+ result.push(...mapHooksToResult(this.hooks[key].preEnforced ?? []));
2707
2745
  } else if (options?.order === "post") {
2708
- result.push(...mapHooksToResult(hooks.postOrdered ?? []));
2709
- result.push(...mapHooksToResult(hooks.postEnforced ?? []));
2710
- } else result.push(...mapHooksToResult(hooks.normal ?? []));
2746
+ result.push(...mapHooksToResult(this.hooks[key].postOrdered ?? []));
2747
+ result.push(...mapHooksToResult(this.hooks[key].postEnforced ?? []));
2748
+ } else result.push(...mapHooksToResult(this.hooks[key].normal ?? []));
2711
2749
  } else {
2712
2750
  result.push(...this.selectHooks(key, { order: "pre" }));
2713
2751
  result.push(...this.selectHooks(key, { order: "normal" }));
@@ -2915,4 +2953,4 @@ var PowerlinesAPIContext = class PowerlinesAPIContext extends PowerlinesContext
2915
2953
 
2916
2954
  //#endregion
2917
2955
  export { FileId as a, FileStorage as c, writeMetaFile as d, callHook as f, PowerlinesContext as i, FileSystem as l, PowerlinesEnvironmentContext as n, FileMetadata as o, mergeConfigs as p, createPluginContext as r, FileMetadata_KeyValuePair as s, PowerlinesAPIContext as t, _capnpFileId as u };
2918
- //# sourceMappingURL=api-context-DiZCovj6.mjs.map
2956
+ //# sourceMappingURL=api-context-CmuOyg7q.mjs.map