attempt to move cluster.setupPrimary to polyfill

deepsource-autofix-76c6eb20
Dan Gowans 2023-03-23 15:08:42 -04:00
parent 1bf2d18140
commit 29f69945e5
5 changed files with 17 additions and 14 deletions

2
bin/www.d.ts vendored
View File

@ -1 +1 @@
export {}; import '../helpers/polyfills.js';

View File

@ -1,3 +1,4 @@
import '../helpers/polyfills.js';
import cluster from 'node:cluster'; import cluster from 'node:cluster';
import os from 'node:os'; import os from 'node:os';
import { dirname } from 'node:path'; import { dirname } from 'node:path';
@ -14,12 +15,7 @@ debug(`Launching ${processCount} processes`);
const clusterSettings = { const clusterSettings = {
exec: directoryName + '/wwwProcess.js' exec: directoryName + '/wwwProcess.js'
}; };
if (cluster.setupPrimary) { cluster.setupPrimary(clusterSettings);
cluster.setupPrimary(clusterSettings);
}
else {
cluster.setupMaster(clusterSettings);
}
for (let index = 0; index < processCount; index += 1) { for (let index = 0; index < processCount; index += 1) {
cluster.fork(); cluster.fork();
} }

View File

@ -1,3 +1,5 @@
import '../helpers/polyfills.js'
import cluster from 'node:cluster' import cluster from 'node:cluster'
import os from 'node:os' import os from 'node:os'
import { dirname } from 'node:path' import { dirname } from 'node:path'
@ -27,13 +29,7 @@ const clusterSettings = {
exec: directoryName + '/wwwProcess.js' exec: directoryName + '/wwwProcess.js'
} }
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions cluster.setupPrimary(clusterSettings)
if (cluster.setupPrimary) {
cluster.setupPrimary(clusterSettings)
} else {
// Maintain Node 14 support
cluster.setupMaster(clusterSettings)
}
for (let index = 0; index < processCount; index += 1) { for (let index = 0; index < processCount; index += 1) {
cluster.fork() cluster.fork()

View File

@ -1,3 +1,4 @@
import cluster from 'node:cluster';
import hasOwn from 'object.hasown'; import hasOwn from 'object.hasown';
import Debug from 'debug'; import Debug from 'debug';
const debug = Debug('lot-occupancy-system:polyfills'); const debug = Debug('lot-occupancy-system:polyfills');
@ -6,6 +7,10 @@ export function applyPolyfills() {
debug('Applying Object.hasOwn(o, v) polyfill'); debug('Applying Object.hasOwn(o, v) polyfill');
Object.hasOwn = hasOwn; Object.hasOwn = hasOwn;
} }
if (!Object.hasOwn(cluster, 'setupPrimary') && Object.hasOwn(cluster, 'setupMaster')) {
debug('Applying cluster.setupPrimary() polyfill');
cluster.setupPrimary = cluster.setupMaster;
}
} }
applyPolyfills(); applyPolyfills();
export default applyPolyfills; export default applyPolyfills;

View File

@ -1,3 +1,4 @@
import cluster from 'node:cluster'
import hasOwn from 'object.hasown' import hasOwn from 'object.hasown'
import Debug from 'debug' import Debug from 'debug'
@ -8,6 +9,11 @@ export function applyPolyfills(): void {
debug('Applying Object.hasOwn(o, v) polyfill') debug('Applying Object.hasOwn(o, v) polyfill')
Object.hasOwn = hasOwn Object.hasOwn = hasOwn
} }
if (!Object.hasOwn(cluster, 'setupPrimary') && Object.hasOwn(cluster, 'setupMaster')) {
debug('Applying cluster.setupPrimary() polyfill')
cluster.setupPrimary = cluster.setupMaster
}
} }
applyPolyfills() applyPolyfills()