Skip to content

Commit 609429b

Browse files
authored
Fix dayjs (#5923)
1 parent 3b6a78b commit 609429b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/util.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ var _a;
1212
Object.defineProperty(exports, "__esModule", { value: true });
1313
exports.CONSOLE_STYLE_FgPink = exports.CONSOLE_STYLE_FgBrown = exports.CONSOLE_STYLE_FgViolet = exports.CONSOLE_STYLE_FgLightBlue = exports.CONSOLE_STYLE_FgLightGreen = exports.CONSOLE_STYLE_FgOrange = exports.CONSOLE_STYLE_FgGray = exports.CONSOLE_STYLE_FgWhite = exports.CONSOLE_STYLE_FgCyan = exports.CONSOLE_STYLE_FgMagenta = exports.CONSOLE_STYLE_FgBlue = exports.CONSOLE_STYLE_FgYellow = exports.CONSOLE_STYLE_FgGreen = exports.CONSOLE_STYLE_FgRed = exports.CONSOLE_STYLE_FgBlack = exports.CONSOLE_STYLE_Hidden = exports.CONSOLE_STYLE_Reverse = exports.CONSOLE_STYLE_Blink = exports.CONSOLE_STYLE_Underscore = exports.CONSOLE_STYLE_Dim = exports.CONSOLE_STYLE_Bright = exports.CONSOLE_STYLE_Reset = exports.PING_PER_REQUEST_TIMEOUT_DEFAULT = exports.PING_PER_REQUEST_TIMEOUT_MAX = exports.PING_PER_REQUEST_TIMEOUT_MIN = exports.PING_COUNT_DEFAULT = exports.PING_COUNT_MAX = exports.PING_COUNT_MIN = exports.PING_GLOBAL_TIMEOUT_DEFAULT = exports.PING_GLOBAL_TIMEOUT_MAX = exports.PING_GLOBAL_TIMEOUT_MIN = exports.PING_PACKET_SIZE_DEFAULT = exports.PING_PACKET_SIZE_MAX = exports.PING_PACKET_SIZE_MIN = exports.MIN_INTERVAL_SECOND = exports.MAX_INTERVAL_SECOND = exports.SQL_DATETIME_FORMAT_WITHOUT_SECOND = exports.SQL_DATETIME_FORMAT = exports.SQL_DATE_FORMAT = exports.STATUS_PAGE_MAINTENANCE = exports.STATUS_PAGE_PARTIAL_DOWN = exports.STATUS_PAGE_ALL_UP = exports.STATUS_PAGE_ALL_DOWN = exports.MAINTENANCE = exports.PENDING = exports.UP = exports.DOWN = exports.appName = exports.isNode = exports.isDev = void 0;
1414
exports.evaluateJsonQuery = exports.intHash = exports.localToUTC = exports.utcToLocal = exports.utcToISODateTime = exports.isoToUTCDateTime = exports.parseTimeFromTimeObject = exports.parseTimeObject = exports.getMaintenanceRelativeURL = exports.getMonitorRelativeURL = exports.genSecret = exports.getCryptoRandomInt = exports.getRandomInt = exports.getRandomArbitrary = exports.TimeLogger = exports.polyfill = exports.log = exports.debug = exports.ucfirst = exports.sleep = exports.flipStatus = exports.badgeConstants = exports.CONSOLE_STYLE_BgGray = exports.CONSOLE_STYLE_BgWhite = exports.CONSOLE_STYLE_BgCyan = exports.CONSOLE_STYLE_BgMagenta = exports.CONSOLE_STYLE_BgBlue = exports.CONSOLE_STYLE_BgYellow = exports.CONSOLE_STYLE_BgGreen = exports.CONSOLE_STYLE_BgRed = exports.CONSOLE_STYLE_BgBlack = void 0;
15-
const dayjs = require("dayjs");
15+
const dayjs_1 = require("dayjs");
1616
const jsonata = require("jsonata");
1717
exports.isDev = process.env.NODE_ENV === "development";
1818
exports.isNode = typeof process !== "undefined" && ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node);
19+
const dayjs = (exports.isNode) ? require("dayjs") : dayjs_1.default;
1920
exports.appName = "Uptime Kuma";
2021
exports.DOWN = 0;
2122
exports.UP = 1;

src/util.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
// Frontend uses util.ts
1010
*/
1111

12-
import * as dayjs from "dayjs";
12+
import dayjsFrontend from "dayjs";
1313

14-
// For loading dayjs plugins, don't remove event though it is not used in this file
14+
// For dayjs plugins' type checking, don't remove event though it is not used in this file
1515
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1616
import * as timezone from "dayjs/plugin/timezone";
1717
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -21,6 +21,13 @@ import * as jsonata from "jsonata";
2121

2222
export const isDev = process.env.NODE_ENV === "development";
2323
export const isNode = typeof process !== "undefined" && process?.versions?.node;
24+
25+
/**
26+
* Smarter dayjs import that supports both frontend and backend
27+
* @returns {dayjs.Dayjs} dayjs instance
28+
*/
29+
const dayjs = (isNode) ? require("dayjs") : dayjsFrontend;
30+
2431
export const appName = "Uptime Kuma";
2532
export const DOWN = 0;
2633
export const UP = 1;

0 commit comments

Comments
 (0)