Converted global to globalThis.

This commit is contained in:
Mike Cao 2025-04-28 23:05:18 -07:00
parent 886b7e9e56
commit c969603001
9 changed files with 25 additions and 22 deletions

View file

@ -1,7 +1,8 @@
generator client {
provider = "prisma-client-js"
provider = "prisma-client"
output = "../src/generated/prisma"
binaryTargets = ["native"]
moduleFormat = "esm"
}
datasource db {

View file

@ -1,7 +1,8 @@
generator client {
provider = "prisma-client-js"
provider = "prisma-client"
output = "../src/generated/prisma"
binaryTargets = ["native"]
moduleFormat = "esm"
}
datasource db {

View file

@ -1,6 +1,6 @@
{
"name": "umami",
"version": "2.18.0",
"version": "3.0.0",
"description": "A modern, privacy-focused alternative to Google Analytics.",
"author": "Umami Software, Inc. <hello@umami.is>",
"license": "MIT",
@ -30,7 +30,7 @@
"set-routes-manifest": "node scripts/set-routes-manifest.mjs",
"update-tracker": "node scripts/update-tracker.mjs",
"update-db": "prisma migrate deploy",
"check-db": "node scripts/check-db.js",
"check-db": "node scripts/check-db.mjs",
"check-env": "node scripts/check-env.mjs",
"copy-db-files": "node scripts/copy-db-files.mjs",
"extract-messages": "formatjs extract \"src/components/messages.ts\" --out-file build/extracted-messages.json",

View file

@ -1,9 +1,10 @@
/* eslint-disable no-console */
require('dotenv').config();
const { PrismaClient } = require('@prisma/client');
const chalk = require('chalk');
const { execSync } = require('child_process');
const semver = require('semver');
import 'dotenv/config';
import { PrismaClient } from '../src/generated/prisma/client';
import chalk from 'chalk';
import { execSync } from 'child_process';
import semver from 'semver';
if (process.env.SKIP_DB_CHECK) {
console.log('Skipping database check.');

View file

@ -41,7 +41,7 @@ function getClient() {
});
if (process.env.NODE_ENV !== 'production') {
global[CLICKHOUSE] = client;
globalThis[CLICKHOUSE] = client;
}
log('Clickhouse initialized');
@ -219,7 +219,7 @@ async function findFirst(data: any[]) {
async function connect() {
if (enabled && !clickhouse) {
clickhouse = process.env.CLICKHOUSE_URL && (global[CLICKHOUSE] || getClient());
clickhouse = process.env.CLICKHOUSE_URL && (globalThis[CLICKHOUSE] || getClient());
}
return clickhouse;

View file

@ -121,13 +121,13 @@ export async function getLocation(ip: string = '', headers: Headers, hasPayloadI
}
// Database lookup
if (!global[MAXMIND]) {
if (!globalThis[MAXMIND]) {
const dir = path.join(process.cwd(), 'geo');
global[MAXMIND] = await maxmind.open(path.resolve(dir, 'GeoLite2-City.mmdb'));
globalThis[MAXMIND] = await maxmind.open(path.resolve(dir, 'GeoLite2-City.mmdb'));
}
const result = global[MAXMIND].get(ip);
const result = globalThis[MAXMIND].get(ip);
if (result) {
const country = result.country?.iso_code ?? result?.registered_country?.iso_code;

View file

@ -41,7 +41,7 @@ function getClient() {
});
if (process.env.NODE_ENV !== 'production') {
global[KAFKA] = client;
globalThis[KAFKA] = client;
}
log('Kafka initialized');
@ -54,7 +54,7 @@ async function getProducer(): Promise<Producer> {
await producer.connect();
if (process.env.NODE_ENV !== 'production') {
global[KAFKA_PRODUCER] = producer;
globalThis[KAFKA_PRODUCER] = producer;
}
log('Kafka producer initialized');
@ -91,10 +91,10 @@ async function sendMessage(
async function connect(): Promise<Kafka> {
if (!kafka) {
kafka = process.env.KAFKA_URL && process.env.KAFKA_BROKER && (global[KAFKA] || getClient());
kafka = process.env.KAFKA_URL && process.env.KAFKA_BROKER && (globalThis[KAFKA] || getClient());
if (kafka) {
producer = global[KAFKA_PRODUCER] || (await getProducer());
producer = globalThis[KAFKA_PRODUCER] || (await getProducer());
}
}

View file

@ -372,7 +372,7 @@ function getClient(params?: {
}
if (process.env.NODE_ENV !== 'production') {
global[PRISMA] = prisma;
globalThis[PRISMA] = prisma;
}
log('Prisma initialized');
@ -380,7 +380,7 @@ function getClient(params?: {
return prisma;
}
const client = global[PRISMA] || getClient();
const client = globalThis[PRISMA] || getClient();
export default {
client,

View file

@ -7,12 +7,12 @@ function getClient() {
const redis = new UmamiRedisClient(process.env.REDIS_URL);
if (process.env.NODE_ENV !== 'production') {
global[REDIS] = redis;
globalThis[REDIS] = redis;
}
return redis;
}
const client = global[REDIS] || getClient();
const client = globalThis[REDIS] || getClient();
export default { client, enabled };