feat: add version to pool information
[poolifier.git] / src / pools / abstract-pool.ts
index 69f6a592162ee1323fc5681a3905604bfb7782c6..03f8c199be642dda1cac20171d0b2410ef73d1c3 100644 (file)
@@ -1,5 +1,6 @@
 import crypto from 'node:crypto'
 import { performance } from 'node:perf_hooks'
+import { readFileSync } from 'node:fs'
 import type { MessageValue, PromiseResponseWrapper } from '../utility-types'
 import {
   DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS,
@@ -39,6 +40,12 @@ import {
 } from './selection-strategies/selection-strategies-types'
 import { WorkerChoiceStrategyContext } from './selection-strategies/worker-choice-strategy-context'
 
+const version = (
+  JSON.parse(
+    readFileSync(new URL('../../package.json', import.meta.url), 'utf8')
+  ) as Record<string, unknown>
+).version as string
+
 /**
  * Base class that implements some shared logic for all poolifier pools.
  *
@@ -249,6 +256,7 @@ export abstract class AbstractPool<
   /** @inheritDoc */
   public get info (): PoolInfo {
     return {
+      version,
       type: this.type,
       worker: this.worker,
       minSize: this.minSize,