xtrm-tools 2.1.8 → 2.1.9

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.
@@ -37306,10 +37306,71 @@ function isValueProtected(keyPath) {
37306
37306
  (protectedPath) => keyPath === protectedPath || keyPath.startsWith(protectedPath + ".")
37307
37307
  );
37308
37308
  }
37309
+ function extractHookCommands(wrapper) {
37310
+ if (!wrapper || !Array.isArray(wrapper.hooks)) return [];
37311
+ return wrapper.hooks.map((h) => h?.command).filter((c) => typeof c === "string" && c.trim().length > 0);
37312
+ }
37313
+ function commandKey(command) {
37314
+ const m = command.match(/([A-Za-z0-9._-]+\.(?:py|cjs|mjs|js))(?!.*[A-Za-z0-9._-]+\.(?:py|cjs|mjs|js))/);
37315
+ return m?.[1] || command.trim();
37316
+ }
37317
+ function mergeMatcher(existingMatcher, incomingMatcher) {
37318
+ const parts = [
37319
+ ...existingMatcher.split("|").map((s) => s.trim()),
37320
+ ...incomingMatcher.split("|").map((s) => s.trim())
37321
+ ].filter(Boolean);
37322
+ return Array.from(new Set(parts)).join("|");
37323
+ }
37324
+ function mergeHookWrappers(existing, incoming) {
37325
+ const merged = existing.map((w) => ({ ...w }));
37326
+ for (const incomingWrapper of incoming) {
37327
+ const incomingCommands = extractHookCommands(incomingWrapper);
37328
+ if (incomingCommands.length === 0) {
37329
+ merged.push(incomingWrapper);
37330
+ continue;
37331
+ }
37332
+ const incomingKeys = new Set(incomingCommands.map(commandKey));
37333
+ const existingIndex = merged.findIndex((existingWrapper2) => {
37334
+ const existingCommands = extractHookCommands(existingWrapper2);
37335
+ return existingCommands.some((c) => incomingKeys.has(commandKey(c)));
37336
+ });
37337
+ if (existingIndex === -1) {
37338
+ merged.push(incomingWrapper);
37339
+ continue;
37340
+ }
37341
+ const existingWrapper = merged[existingIndex];
37342
+ if (typeof existingWrapper.matcher === "string" && typeof incomingWrapper.matcher === "string") {
37343
+ existingWrapper.matcher = mergeMatcher(existingWrapper.matcher, incomingWrapper.matcher);
37344
+ }
37345
+ if (Array.isArray(existingWrapper.hooks) && Array.isArray(incomingWrapper.hooks)) {
37346
+ const existingByKey = new Set(existingWrapper.hooks.map((h) => h?.command).filter((c) => typeof c === "string").map(commandKey));
37347
+ for (const hook of incomingWrapper.hooks) {
37348
+ const cmd = hook?.command;
37349
+ if (typeof cmd !== "string" || !existingByKey.has(commandKey(cmd))) {
37350
+ existingWrapper.hooks.push(hook);
37351
+ }
37352
+ }
37353
+ }
37354
+ }
37355
+ return merged;
37356
+ }
37357
+ function mergeHooksObject(existingHooks, incomingHooks) {
37358
+ const result = { ...existingHooks || {} };
37359
+ for (const [event, incomingWrappers] of Object.entries(incomingHooks || {})) {
37360
+ const existingWrappers = Array.isArray(result[event]) ? result[event] : [];
37361
+ const incomingArray = Array.isArray(incomingWrappers) ? incomingWrappers : [];
37362
+ result[event] = mergeHookWrappers(existingWrappers, incomingArray);
37363
+ }
37364
+ return result;
37365
+ }
37309
37366
  function deepMergeWithProtection(original, updates, currentPath = "") {
37310
37367
  const result = { ...original };
37311
37368
  for (const [key, value] of Object.entries(updates)) {
37312
37369
  const keyPath = currentPath ? `${currentPath}.${key}` : key;
37370
+ if (key === "hooks" && typeof value === "object" && value !== null && typeof original[key] === "object" && original[key] !== null) {
37371
+ result[key] = mergeHooksObject(original[key], value);
37372
+ continue;
37373
+ }
37313
37374
  if (isValueProtected(keyPath) && original.hasOwnProperty(key)) {
37314
37375
  continue;
37315
37376
  }
@@ -40953,7 +41014,7 @@ function deepMergeHooks(existing, incoming) {
40953
41014
  const m = cmd.match(/([A-Za-z0-9._-]+\.(?:py|cjs|mjs|js))(?!.*[A-Za-z0-9._-]+\.(?:py|cjs|mjs|js))/);
40954
41015
  return m?.[1] ?? null;
40955
41016
  };
40956
- const mergeMatcher = (existingMatcher, incomingMatcher) => {
41017
+ const mergeMatcher2 = (existingMatcher, incomingMatcher) => {
40957
41018
  const existingParts = existingMatcher.split("|").map((s) => s.trim()).filter(Boolean);
40958
41019
  const incomingParts = incomingMatcher.split("|").map((s) => s.trim()).filter(Boolean);
40959
41020
  const merged = [...existingParts];
@@ -40982,7 +41043,7 @@ function deepMergeHooks(existing, incoming) {
40982
41043
  }
40983
41044
  const existingHook = mergedEventHooks[existingIndex];
40984
41045
  if (typeof existingHook.matcher === "string" && typeof incomingHook.matcher === "string") {
40985
- existingHook.matcher = mergeMatcher(existingHook.matcher, incomingHook.matcher);
41046
+ existingHook.matcher = mergeMatcher2(existingHook.matcher, incomingHook.matcher);
40986
41047
  }
40987
41048
  }
40988
41049
  result.hooks[event] = mergedEventHooks;