diff --git a/app.d.ts b/app.d.ts index 0dd47f8f..6a16f7b4 100644 --- a/app.d.ts +++ b/app.d.ts @@ -1,3 +1,2 @@ -import './helpers/polyfills.js'; export declare const app: import("express-serve-static-core").Express; export default app; diff --git a/app.js b/app.js index dda4e5c9..1616f5e6 100644 --- a/app.js +++ b/app.js @@ -1,4 +1,4 @@ -import './helpers/polyfills.js'; +import { applyPolyfills } from './helpers/polyfills.js'; import createError from 'http-errors'; import express from 'express'; import compression from 'compression'; @@ -31,6 +31,7 @@ import { getSafeRedirectURL } from './helpers/functions.authentication.js'; import debug from 'debug'; import { useTestDatabases } from './data/databasePaths.js'; const debugApp = debug('lot-occupancy-system:app'); +applyPolyfills(); databaseInitializer.initializeDatabase(); const _dirname = '.'; export const app = express(); diff --git a/app.ts b/app.ts index c680ffec..d91c8cc4 100644 --- a/app.ts +++ b/app.ts @@ -1,4 +1,4 @@ -import './helpers/polyfills.js' +import { applyPolyfills } from './helpers/polyfills.js' import createError from 'http-errors' import express, { type RequestHandler } from 'express' @@ -41,6 +41,12 @@ import debug from 'debug' import { useTestDatabases } from './data/databasePaths.js' const debugApp = debug('lot-occupancy-system:app') +/* + * Apply Polyfills + */ + +applyPolyfills() + /* * INITIALIZE THE DATABASE */ diff --git a/helpers/functions.api.d.ts b/helpers/functions.api.d.ts index 1440191d..d5f58abc 100644 --- a/helpers/functions.api.d.ts +++ b/helpers/functions.api.d.ts @@ -1,4 +1,3 @@ -import './polyfills.js'; import type * as recordTypes from '../types/recordTypes'; export declare function regenerateApiKey(userName: string): Promise; export declare function getApiKey(userName: string): Promise; diff --git a/helpers/functions.api.js b/helpers/functions.api.js index 62576861..9d9f13b0 100644 --- a/helpers/functions.api.js +++ b/helpers/functions.api.js @@ -1,8 +1,9 @@ -import './polyfills.js'; +import { applyPolyfills } from './polyfills.js'; import fs from 'node:fs/promises'; import { v4 as uuidv4 } from 'uuid'; import Debug from 'debug'; const debug = Debug('lot-occupancy-system:functions.api'); +applyPolyfills(); const apiKeyPath = 'data/apiKeys.json'; let apiKeys; async function loadApiKeys() { diff --git a/helpers/functions.api.ts b/helpers/functions.api.ts index 82de8605..69229691 100644 --- a/helpers/functions.api.ts +++ b/helpers/functions.api.ts @@ -1,4 +1,4 @@ -import './polyfills.js' +import { applyPolyfills } from './polyfills.js' import fs from 'node:fs/promises' import { v4 as uuidv4 } from 'uuid' @@ -9,6 +9,8 @@ import type * as recordTypes from '../types/recordTypes' const debug = Debug('lot-occupancy-system:functions.api') +applyPolyfills() + const apiKeyPath = 'data/apiKeys.json' let apiKeys: Record diff --git a/helpers/functions.config.d.ts b/helpers/functions.config.d.ts index 4cf0b800..19a15081 100644 --- a/helpers/functions.config.d.ts +++ b/helpers/functions.config.d.ts @@ -1,4 +1,3 @@ -import './polyfills.js'; import type * as configTypes from '../types/configTypes'; export declare function getProperty(propertyName: 'application.applicationName'): string; export declare function getProperty(propertyName: 'application.logoURL'): string; diff --git a/helpers/functions.config.js b/helpers/functions.config.js index 085d4cf4..03ccdd62 100644 --- a/helpers/functions.config.js +++ b/helpers/functions.config.js @@ -1,5 +1,6 @@ -import './polyfills.js'; +import { applyPolyfills } from './polyfills.js'; import { config } from '../data/config.js'; +applyPolyfills(); const configFallbackValues = new Map(); configFallbackValues.set('application.applicationName', 'Lot Occupancy System'); configFallbackValues.set('application.backgroundURL', '/images/cemetery-background.jpg'); diff --git a/helpers/functions.config.ts b/helpers/functions.config.ts index cd44da9c..8633616e 100644 --- a/helpers/functions.config.ts +++ b/helpers/functions.config.ts @@ -1,11 +1,13 @@ /* eslint-disable @typescript-eslint/indent, node/no-unpublished-import */ -import './polyfills.js' +import { applyPolyfills } from './polyfills.js' import { config } from '../data/config.js' import type * as configTypes from '../types/configTypes' +applyPolyfills() + /* * SET UP FALLBACK VALUES */ diff --git a/helpers/polyfills.d.ts b/helpers/polyfills.d.ts index cb0ff5c3..9ecbea09 100644 --- a/helpers/polyfills.d.ts +++ b/helpers/polyfills.d.ts @@ -1 +1,2 @@ -export {}; +export declare function applyPolyfills(): void; +export default applyPolyfills; diff --git a/helpers/polyfills.js b/helpers/polyfills.js index a68cf564..e0fb7022 100644 --- a/helpers/polyfills.js +++ b/helpers/polyfills.js @@ -1,6 +1,10 @@ import Debug from 'debug'; const debug = Debug('lot-occupancy-system:polyfills'); -if (Object.hasOwn === undefined) { - debug('Applying Object.hasOwn(o, v) polyfill'); - Object.hasOwn = Object.prototype.hasOwnProperty.call; +export function applyPolyfills() { + if (Object.hasOwn === undefined) { + debug('Applying Object.hasOwn(o, v) polyfill'); + Object.hasOwn = Object.prototype.hasOwnProperty.call; + } } +applyPolyfills(); +export default applyPolyfills; diff --git a/helpers/polyfills.ts b/helpers/polyfills.ts index d353f12e..5fb21523 100644 --- a/helpers/polyfills.ts +++ b/helpers/polyfills.ts @@ -1,7 +1,13 @@ import Debug from 'debug' const debug = Debug('lot-occupancy-system:polyfills') -if (Object.hasOwn === undefined) { - debug('Applying Object.hasOwn(o, v) polyfill') - Object.hasOwn = Object.prototype.hasOwnProperty.call +export function applyPolyfills(): void { + if (Object.hasOwn === undefined) { + debug('Applying Object.hasOwn(o, v) polyfill') + Object.hasOwn = Object.prototype.hasOwnProperty.call + } } + +applyPolyfills() + +export default applyPolyfills