Skip to content

Commit

Permalink
fix: module resolution
Browse files Browse the repository at this point in the history
- Use `type: module` again. CommonJS does not work.
  • Loading branch information
cgawron committed Sep 24, 2024
1 parent f859dc7 commit c2f37d6
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 40 deletions.
4 changes: 2 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "[email protected]:fhswf/book_me.git"
},
"main": "server.js",
"type": "commonjs",
"type": "module",
"scripts": {
"test": "vitest run src/**/*.spec.ts --coverage",
"ci": "vitest run src/**/*.spec.ts --coverage",
Expand Down Expand Up @@ -72,7 +72,7 @@
"supertest": "^7.0.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2",
"typescript": "^5.6.2",
"vitest": "^2.1.1"
},
"eslintConfig": {
Expand Down
6 changes: 4 additions & 2 deletions backend/src/controller/authentication_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @module authentication_controller
*/
import { UserModel } from "../models/User";
import { UserModel } from "../models/User.js";
import { validationResult } from "express-validator";
import { createTransport } from "nodemailer";
import { google } from "googleapis";
Expand All @@ -18,7 +18,9 @@ const env = dotenv.config({

import { compare } from 'bcrypt';

import { JwtPayload, decode, sign, verify } from 'jsonwebtoken';
import pkg from 'jsonwebtoken';
const { sign, verify } = pkg;
import { JwtPayload } from 'jsonwebtoken';

const REDIRECT_URI = `${process.env.API_URL}/google/oauthcallback`;
console.log("redirectUri: %s", REDIRECT_URI);
Expand Down
6 changes: 3 additions & 3 deletions backend/src/controller/event_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
/**
* @module event_controller
*/
import { EventDocument, EventModel } from "../models/Event";
import { EventDocument, EventModel } from "../models/Event.js";
import { Event, IntervalSet } from "common";
import { freeBusy, events } from "./google_controller";
import { freeBusy, events } from "./google_controller.js";
import { ValidationError, validationResult } from "express-validator";
import { errorHandler } from "../handlers/errorhandler";
import { errorHandler } from "../handlers/errorhandler.js";
import { addMinutes, addDays, startOfHour, startOfDay } from 'date-fns';
import { Request, Response } from "express";

Expand Down
2 changes: 1 addition & 1 deletion backend/src/controller/google_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { calendar_v3, google } from 'googleapis';
import { GaxiosResponse, GaxiosPromise } from "gaxios";
import { OAuth2Client } from 'google-auth-library';
import Schema$Event = calendar_v3.Schema$Event;
import { UserModel, User } from "../models/User";
import { UserModel, User } from "../models/User.js";
import { Request, Response } from 'express';

import { Event, IntervalSet } from 'common';
Expand Down
2 changes: 1 addition & 1 deletion backend/src/controller/user_controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @module user_controller
*/
import { User, UserModel } from "../models/User";
import { User, UserModel } from "../models/User.js";
import { Request, Response } from 'express';

/**
Expand Down
4 changes: 2 additions & 2 deletions backend/src/routes/authentication_route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import { Router } from "express";
export const authenticationRouter = Router();

import { registerController, activationController, loginController, googleLoginController } from "../controller/authentication_controller";
import { registerController, activationController, loginController, googleLoginController } from "../controller/authentication_controller.js";

import { validateRegister, validateLogin } from "../handlers/validation";
import { validateRegister, validateLogin } from "../handlers/validation.js";

/**
* Route to register a new user.
Expand Down
4 changes: 2 additions & 2 deletions backend/src/routes/event_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {
getActiveEventsController,
getEventByUrl,
getAvailableTimes,
} from "../controller/event_controller";
} from "../controller/event_controller.js";

import { requireAuth } from "../handlers/middleware";
import { requireAuth } from "../handlers/middleware.js";

export const eventRouter = Router();
/**
Expand Down
4 changes: 2 additions & 2 deletions backend/src/routes/google_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { Router } from "express";

export const googleRouter = Router();

import { generateAuthUrl, googleCallback, revokeScopes, insertEventToGoogleCal, getCalendarList } from "../controller/google_controller";
import { generateAuthUrl, googleCallback, revokeScopes, insertEventToGoogleCal, getCalendarList } from "../controller/google_controller.js";

import { requireAuth } from "../handlers/middleware";
import { requireAuth } from "../handlers/middleware.js";

/**
* Route to delete an access token from a given user
Expand Down
4 changes: 2 additions & 2 deletions backend/src/routes/user_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* @module router/user
*/
import { Router } from "express";
import { getUser, getUserByUrl, putUser } from "../controller/user_controller";
import { getUser, getUserByUrl, putUser } from "../controller/user_controller.js";

import { requireAuth } from "../handlers/middleware";
import { requireAuth } from "../handlers/middleware.js";

export const userRouter = Router();

Expand Down
10 changes: 5 additions & 5 deletions backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import express from "express";
import bodyParser from "body-parser";
import cors from "cors";
import cookieParser from "cookie-parser";
import { dataBaseConn } from "./config/dbConn";
import { dataBaseConn } from "./config/dbConn.js";

//Load routes
import { authenticationRouter } from "./routes/authentication_route";
import { eventRouter } from "./routes/event_routes";
import { googleRouter } from "./routes/google_routes";
import { userRouter } from "./routes/user_routes";
import { authenticationRouter } from "./routes/authentication_route.js";
import { eventRouter } from "./routes/event_routes.js";
import { googleRouter } from "./routes/google_routes.js";
import { userRouter } from "./routes/user_routes.js";

// Dotenv Config
import dotenv from "dotenv";
Expand Down
2 changes: 1 addition & 1 deletion backend/src/test/server.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { server } from "../server";
import { server } from "../server.js";
import request from "supertest";

describe("Server", () => {
Expand Down
2 changes: 1 addition & 1 deletion backend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"module": "CommonJS",
"module": "ESNext",
"allowJs": true,
"strict": false,
"skipLibCheck": true,
Expand Down
3 changes: 2 additions & 1 deletion client/src/helpers/services/event_services.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from "axios";
import { Event, IntervalSet } from "common";
import { Event } from "common";
import type { IntervalSet } from "common";

export async function saveUserEvent(
token: string,
Expand Down
6 changes: 3 additions & 3 deletions common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"publishConfig": {
"registry": "https://npm.pkg.github.com"
},
"type": "commonjs",
"type": "module",
"main": "./lib/types.js",
"types": "./lib/types.d.ts",
"scripts": {
Expand Down Expand Up @@ -50,7 +50,7 @@
"typescript": "^5.2.2"
},
"dependencies": {
"date-fns": "^2.22.1",
"date-fns-tz": "^1.1.4"
"date-fns": "^4.1.0",
"date-fns-tz": "^3.1.3"
}
}
6 changes: 3 additions & 3 deletions common/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { utcToZonedTime, zonedTimeToUtc } from "date-fns-tz"
import { toZonedTime, fromZonedTime } from "date-fns-tz"
import { th } from "date-fns/locale";

/** Enum type representing a day of week.
Expand Down Expand Up @@ -152,8 +152,8 @@ export class IntervalSet extends Array<TimeRange> {
let end = new Date(t)//utcToZonedTime(t, timezone)
start.setHours(start_h, start_m, 0, 0)
end.setHours(end_h, end_m, 0, 0)
start = zonedTimeToUtc(start, timezone)
end = zonedTimeToUtc(end, timezone)
start = fromZonedTime(start, timezone)
end = fromZonedTime(end, timezone)
this.push({ start, end })
})
t = new Date(t.getTime() + 1000 * 86400)
Expand Down
2 changes: 1 addition & 1 deletion common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"module": "CommonJS",
"module": "ESNext",
"allowJs": true,
"strict": false,
"baseUrl": "./",
Expand Down
25 changes: 17 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6696,7 +6696,7 @@ __metadata:
supertest: "npm:^7.0.0"
ts-jest: "npm:^29.1.1"
ts-node: "npm:^10.9.1"
typescript: "npm:^5.2.2"
typescript: "npm:^5.6.2"
vitest: "npm:^2.1.1"
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -7985,8 +7985,8 @@ __metadata:
"@types/jest": "npm:^29.5.5"
"@types/mocha": "npm:^8.2.2"
chai: "npm:^4.3.4"
date-fns: "npm:^2.22.1"
date-fns-tz: "npm:^1.1.4"
date-fns: "npm:^4.1.0"
date-fns-tz: "npm:^3.1.3"
eslint: "npm:^7.19.0"
jest: "npm:^29.7.0"
jest-junit: "npm:^16.0.0"
Expand Down Expand Up @@ -8495,7 +8495,7 @@ __metadata:
languageName: node
linkType: hard

"date-fns-tz@npm:^1.1.1, date-fns-tz@npm:^1.1.4":
"date-fns-tz@npm:^1.1.1":
version: 1.3.8
resolution: "date-fns-tz@npm:1.3.8"
peerDependencies:
Expand All @@ -8504,7 +8504,16 @@ __metadata:
languageName: node
linkType: hard

"date-fns@npm:^2.22.1, date-fns@npm:^2.30.0":
"date-fns-tz@npm:^3.1.3":
version: 3.1.3
resolution: "date-fns-tz@npm:3.1.3"
peerDependencies:
date-fns: ^3.0.0
checksum: 10/eb5cb3b2cd152340004efda9f7905e571cf5140b8e85267b1eaa36c2f1eaa54a0f2e3b26e19794f2aca4d3b15aa3d52a5b2dadb540fcec74b239049c7792a981
languageName: node
linkType: hard

"date-fns@npm:^2.30.0":
version: 2.30.0
resolution: "date-fns@npm:2.30.0"
dependencies:
Expand All @@ -8513,7 +8522,7 @@ __metadata:
languageName: node
linkType: hard

"date-fns@npm:^4.0.0":
"date-fns@npm:^4.0.0, date-fns@npm:^4.1.0":
version: 4.1.0
resolution: "date-fns@npm:4.1.0"
checksum: 10/d5f6e9de5bbc52310f786099e18609289ed5e30af60a71e0646784c8185ddd1d0eebcf7c96b7faaaefc4a8366f3a3a4244d099b6d0866ee2bec80d1361e64342
Expand Down Expand Up @@ -20888,7 +20897,7 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:^5.0.4":
"typescript@npm:^5.0.4, typescript@npm:^5.6.2":
version: 5.6.2
resolution: "typescript@npm:5.6.2"
bin:
Expand All @@ -20908,7 +20917,7 @@ __metadata:
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A^5.0.4#optional!builtin<compat/typescript>":
"typescript@patch:typescript@npm%3A^5.0.4#optional!builtin<compat/typescript>, typescript@patch:typescript@npm%3A^5.6.2#optional!builtin<compat/typescript>":
version: 5.6.2
resolution: "typescript@patch:typescript@npm%3A5.6.2#optional!builtin<compat/typescript>::version=5.6.2&hash=8c6c40"
bin:
Expand Down

0 comments on commit c2f37d6

Please sign in to comment.