pepr 0.48.1 → 0.49.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.
@@ -0,0 +1,34 @@
1
+ import { ControllerHooks } from ".";
2
+ import { resolveIgnoreNamespaces } from "../assets/webhooks";
3
+ import { Capability } from "../core/capability";
4
+ import { isWatchMode, isDevMode } from "../core/envChecks";
5
+ import { setupWatch } from "../processors/watch-processor";
6
+ import { PeprModuleOptions } from "../types";
7
+
8
+ /**
9
+ * Creates controller hooks with proper handling of watch setup
10
+ *
11
+ * @param opts Module options including hooks
12
+ * @param capabilities List of capabilities
13
+ * @param ignoreNamespaces Namespaces to ignore
14
+ * @returns Controller hooks configuration
15
+ */
16
+ export function createControllerHooks(
17
+ opts: PeprModuleOptions,
18
+ capabilities: Capability[],
19
+ ignoreNamespaces: string[] = [],
20
+ ): ControllerHooks {
21
+ return {
22
+ beforeHook: opts.beforeHook,
23
+ afterHook: opts.afterHook,
24
+ onReady: async (): Promise<void> => {
25
+ if (isWatchMode() || isDevMode()) {
26
+ try {
27
+ setupWatch(capabilities, resolveIgnoreNamespaces(ignoreNamespaces));
28
+ } catch (error) {
29
+ throw new Error(`WatchError: Could not set up watch.`, { cause: error });
30
+ }
31
+ }
32
+ },
33
+ };
34
+ }
@@ -132,10 +132,10 @@ export class Controller {
132
132
 
133
133
  // Listen for the SIGTERM signal and gracefully close the server
134
134
  process.on("SIGTERM", () => {
135
- Log.info("Received SIGTERM, closing server");
135
+ Log.info("Received SIGTERM, closing server.");
136
136
  server.close(() => {
137
- Log.info("Server closed");
138
- process.exit(0);
137
+ Log.info("Server closed.");
138
+ process.exit(143);
139
139
  });
140
140
  });
141
141
  };
@@ -2,14 +2,12 @@
2
2
  // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
3
3
  import { clone } from "ramda";
4
4
  import { Capability } from "./capability";
5
- import { Controller, ControllerHooks } from "../controller";
5
+ import { Controller } from "../controller";
6
6
  import { ValidateError } from "../errors";
7
7
  import { CapabilityExport } from "../types";
8
- import { setupWatch } from "../processors/watch-processor";
9
- import Log from "../../lib/telemetry/logger";
10
- import { resolveIgnoreNamespaces } from "../assets/webhooks";
11
- import { isBuildMode, isDevMode, isWatchMode } from "./envChecks";
8
+ import { isBuildMode } from "./envChecks";
12
9
  import { PackageJSON, PeprModuleOptions, ModuleConfig } from "../types";
10
+ import { createControllerHooks } from "../controller/createHooks";
13
11
 
14
12
  export class PeprModule {
15
13
  #controller!: Controller;
@@ -59,21 +57,11 @@ export class PeprModule {
59
57
  return;
60
58
  }
61
59
 
62
- const controllerHooks: ControllerHooks = {
63
- beforeHook: opts.beforeHook,
64
- afterHook: opts.afterHook,
65
- onReady: async (): Promise<void> => {
66
- // Wait for the controller to be ready before setting up watches
67
- if (isWatchMode() || isDevMode()) {
68
- try {
69
- setupWatch(capabilities, resolveIgnoreNamespaces(pepr?.alwaysIgnore?.namespaces));
70
- } catch (e) {
71
- Log.error(e, "Error setting up watch");
72
- process.exit(1);
73
- }
74
- }
75
- },
76
- };
60
+ const controllerHooks = createControllerHooks(
61
+ opts,
62
+ capabilities,
63
+ pepr?.alwaysIgnore?.namespaces,
64
+ );
77
65
 
78
66
  this.#controller = new Controller(config, capabilities, controllerHooks);
79
67