From 29f69945e56eb05728d8f61af9381b401aeab06d Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Thu, 23 Mar 2023 15:08:42 -0400 Subject: [PATCH] attempt to move cluster.setupPrimary to polyfill --- bin/www.d.ts | 2 +- bin/www.js | 8 ++------ bin/www.ts | 10 +++------- helpers/polyfills.js | 5 +++++ helpers/polyfills.ts | 6 ++++++ 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/bin/www.d.ts b/bin/www.d.ts index cb0ff5c3..6d453531 100644 --- a/bin/www.d.ts +++ b/bin/www.d.ts @@ -1 +1 @@ -export {}; +import '../helpers/polyfills.js'; diff --git a/bin/www.js b/bin/www.js index 027a970e..f3302eef 100644 --- a/bin/www.js +++ b/bin/www.js @@ -1,3 +1,4 @@ +import '../helpers/polyfills.js'; import cluster from 'node:cluster'; import os from 'node:os'; import { dirname } from 'node:path'; @@ -14,12 +15,7 @@ debug(`Launching ${processCount} processes`); const clusterSettings = { exec: directoryName + '/wwwProcess.js' }; -if (cluster.setupPrimary) { - cluster.setupPrimary(clusterSettings); -} -else { - cluster.setupMaster(clusterSettings); -} +cluster.setupPrimary(clusterSettings); for (let index = 0; index < processCount; index += 1) { cluster.fork(); } diff --git a/bin/www.ts b/bin/www.ts index 9967a031..46bd256e 100644 --- a/bin/www.ts +++ b/bin/www.ts @@ -1,3 +1,5 @@ +import '../helpers/polyfills.js' + import cluster from 'node:cluster' import os from 'node:os' import { dirname } from 'node:path' @@ -27,13 +29,7 @@ const clusterSettings = { exec: directoryName + '/wwwProcess.js' } -// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -if (cluster.setupPrimary) { - cluster.setupPrimary(clusterSettings) -} else { - // Maintain Node 14 support - cluster.setupMaster(clusterSettings) -} +cluster.setupPrimary(clusterSettings) for (let index = 0; index < processCount; index += 1) { cluster.fork() diff --git a/helpers/polyfills.js b/helpers/polyfills.js index 33d23c81..d535d38f 100644 --- a/helpers/polyfills.js +++ b/helpers/polyfills.js @@ -1,3 +1,4 @@ +import cluster from 'node:cluster'; import hasOwn from 'object.hasown'; import Debug from 'debug'; const debug = Debug('lot-occupancy-system:polyfills'); @@ -6,6 +7,10 @@ export function applyPolyfills() { debug('Applying Object.hasOwn(o, v) polyfill'); Object.hasOwn = hasOwn; } + if (!Object.hasOwn(cluster, 'setupPrimary') && Object.hasOwn(cluster, 'setupMaster')) { + debug('Applying cluster.setupPrimary() polyfill'); + cluster.setupPrimary = cluster.setupMaster; + } } applyPolyfills(); export default applyPolyfills; diff --git a/helpers/polyfills.ts b/helpers/polyfills.ts index 97c4bc75..922cecb8 100644 --- a/helpers/polyfills.ts +++ b/helpers/polyfills.ts @@ -1,3 +1,4 @@ +import cluster from 'node:cluster' import hasOwn from 'object.hasown' import Debug from 'debug' @@ -8,6 +9,11 @@ export function applyPolyfills(): void { debug('Applying Object.hasOwn(o, v) polyfill') Object.hasOwn = hasOwn } + + if (!Object.hasOwn(cluster, 'setupPrimary') && Object.hasOwn(cluster, 'setupMaster')) { + debug('Applying cluster.setupPrimary() polyfill') + cluster.setupPrimary = cluster.setupMaster + } } applyPolyfills()