From: Jérôme Benoit Date: Sun, 9 Jul 2023 00:02:05 +0000 (+0200) Subject: fix: workaround import issue with `node:os` module in node 16.x.x X-Git-Tag: v2.6.12~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=aa4bf4b27479408af59e1cd36b98fe0c22bc7f03;p=poolifier.git fix: workaround import issue with `node:os` module in node 16.x.x Signed-off-by: Jérôme Benoit --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 1696e716..e2d00ee4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Workaround import issue with `node:os` module in node 16.x.x. + ## [2.6.11] - 2023-07-09 ### Fixed diff --git a/src/utils.ts b/src/utils.ts index 80e6b9f3..128b65da 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -import { cpus, availableParallelism as parallelism } from 'node:os' +import * as os from 'node:os' import type { MeasurementStatisticsRequirements, WorkerChoiceStrategyOptions @@ -41,9 +41,9 @@ export const DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS: MeasurementStatisticsR export const availableParallelism = (): number => { let availableParallelism = 1 try { - availableParallelism = parallelism() + availableParallelism = os.availableParallelism() } catch { - const numberOfCpus = cpus() + const numberOfCpus = os.cpus() if (Array.isArray(numberOfCpus) && numberOfCpus.length > 0) { availableParallelism = numberOfCpus.length }