diff --git a/README.md b/README.md index bf6220d..9b1522b 100644 --- a/README.md +++ b/README.md @@ -2005,7 +2005,7 @@ Type: type concurrency = number; ``` -Default: `Math.max(1, os.cpus().length - 1)` +Default: `Math.max(1, os.availableParallelism() - 1)` Maximum number of concurrency optimization processes in one time. diff --git a/src/index.js b/src/index.js index f8e0a1b..4af2877 100644 --- a/src/index.js +++ b/src/index.js @@ -315,10 +315,21 @@ class ImageMinimizerPlugin { // In some cases cpus() returns undefined // https://github.com/nodejs/node/issues/19022 - // TODO fix me const limit = Math.max( 1, - this.options.concurrency ?? os.cpus()?.length ?? 1, + this.options.concurrency || + // eslint-disable-next-line n/no-unsupported-features/node-builtins + (typeof os.availableParallelism === "function" + ? { + // eslint-disable-next-line n/no-unsupported-features/node-builtins + length: os.availableParallelism(), + } + : os.cpus() || { + // In some cases cpus() returns undefined + // https://github.com/nodejs/node/issues/19022 + length: 1, + } + ).length - 1, ); const { RawSource } = compiler.webpack.sources;