Skip to content

Commit

Permalink
Update build setup for ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
SeinopSys committed Nov 27, 2024
1 parent 8977d77 commit 5c69099
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 21 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "muffins",
"version": "2.0.0",
"type": "module",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.21.1",
Expand All @@ -14,6 +15,7 @@
},
"scripts": {
"start": "pm2 start pm2.json",
"preview": "node ./build/server.js",
"start:dev": "tsx src/server.ts",
"prebuild": "rimraf build",
"build": "tsc"
Expand Down
2 changes: 1 addition & 1 deletion src/common-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Socket } from "socket.io";
import { ClientToServerEvents, ServerToClientEvents } from "./event-names";
import { ClientToServerEvents, ServerToClientEvents } from "./event-names.js";
import { Moment } from "moment-timezone";

export interface ResponseWithStatus {
Expand Down
2 changes: 1 addition & 1 deletion src/config.example.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppConfig } from './app-config';
import { AppConfig } from './app-config.js';

const defaultConfig: AppConfig = {
PORT: 3672,
Expand Down
2 changes: 1 addition & 1 deletion src/database.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pg from "pg";
import config from "./config";
import config from "./config.js";

export const Database = new pg.Client(`postgres://${config.DB_USER}:${config.DB_PASS}@${config.DB_HOST}/mlpvc-rr`)
2 changes: 1 addition & 1 deletion src/event-names.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClientMetadata, ObjectResponse, ResponseWithStatus } from "./common-types";
import { ClientMetadata, ObjectResponse, ResponseWithStatus } from "./common-types.js";

export enum ClientToServerEventNames {
DEV_QUERY = 'devquery',
Expand Down
2 changes: 1 addition & 1 deletion src/log.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import moment from './moment-setup';
import moment from './moment-setup.js';
export default (text: string) => console.log(moment().format('YYYY-MM-DD HH:mm:ss.SSS')+' | ' + text);
3 changes: 2 additions & 1 deletion src/moment-setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const moment = require('moment-timezone');
import moment from 'moment-timezone';

moment.locale('en');
moment.tz.add('Europe/Budapest|CET CEST|-10 -20|01010101010101010101010|1BWp0 1qM0 WM0 1qM0 WM0 1qM0 11A0 1o00 11A0 1o00 11A0 1o00 11A0 1qM0 WM0 1qM0 WM0 1qM0 11A0 1o00 11A0 1o00|11e6');
moment.tz.setDefault('Europe/Budapest');
Expand Down
2 changes: 1 addition & 1 deletion src/real-ip.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fetch from 'node-fetch';
import ipRangeCheck from 'range_check';
import log from './log';
import log from './log.js';
import { Socket } from 'socket.io';

const state: { ranges: string[], fetched: boolean } = { ranges: ['127.0.0.0/24'], fetched: false };
Expand Down
16 changes: 8 additions & 8 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import express from 'express';
import { Server } from 'socket.io';
import { createHash } from 'node:crypto';

import config from './config';
import log from './log';
import moment from './moment-setup';
import { ClientToServerEventNames, ClientToServerEvents, ServerToClientEventNames, ServerToClientEvents } from './event-names';
import findRealIp from './real-ip';
import { authByCookie, authGuest, decodeJson, getGuestID, leaveRoom, sendNotificationCount } from './utils';
import { Database } from './database';
import { AppSocket, ClientMetadata, InterServerEvents, SocketMetadata } from './common-types';
import config from './config.js';
import log from './log.js';
import moment from './moment-setup.js';
import { ClientToServerEventNames, ClientToServerEvents, ServerToClientEventNames, ServerToClientEvents } from './event-names.js';
import findRealIp from './real-ip.js';
import { authByCookie, authGuest, decodeJson, getGuestID, leaveRoom, sendNotificationCount } from './utils.js';
import { Database } from './database.js';
import { AppSocket, ClientMetadata, InterServerEvents, SocketMetadata } from './common-types.js';
import { createServer } from 'http';

process.title = 'Muffins';
Expand Down
8 changes: 4 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Socket } from "socket.io";
import { ClientToServerEvents, ServerToClientEventNames, ServerToClientEvents } from "./event-names";
import { ClientToServerEvents, ServerToClientEventNames, ServerToClientEvents } from "./event-names.js";
import { QueryResult, QueryResultRow } from 'pg';
import { Database } from "./database";
import { AppSocket, UserMetadata } from "./common-types";
import config from "./config";
import { Database } from "./database.js";
import { AppSocket, UserMetadata } from "./common-types.js";
import config from "./config.js";
import createHash from "sha.js";

const sha256hash = (data: string) => createHash('sha256').update(data, 'utf8').digest('hex');
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"incremental": true,
"target": "es2016",
"module": "commonjs",
"target": "ESNext",
"module": "ESNext",
"rootDir": "./src",
"baseUrl": "./src",
"moduleResolution": "node",
Expand Down

0 comments on commit 5c69099

Please sign in to comment.