From 4c1d9b4300d5f75dd80fa293b722a3d1921ea9bb Mon Sep 17 00:00:00 2001 From: Ankur Narkhede Date: Sat, 17 Dec 2022 08:36:34 +0530 Subject: [PATCH] Convert to type module --- app.ts | 6 +++--- controllers/auth.ts | 4 ++-- controllers/health.ts | 2 +- controllers/users.ts | 2 +- middlewares/authenticate.ts | 4 ++-- middlewares/index.ts | 6 +++--- package.json | 1 + prisma/migrations/migration_lock.toml | 3 --- routes/auth.ts | 2 +- routes/calendar.ts | 2 +- routes/health.ts | 2 +- routes/index.ts | 8 ++++---- routes/users.ts | 8 ++++---- server.ts | 4 ++-- services/authService.ts | 6 +++--- test/integration/auth.test.ts | 2 +- test/integration/health.test.ts | 2 +- test/unit/security.test.ts | 2 +- tsconfig.json | 2 +- 19 files changed, 33 insertions(+), 35 deletions(-) delete mode 100644 prisma/migrations/migration_lock.toml diff --git a/app.ts b/app.ts index 2842b93..79bf542 100644 --- a/app.ts +++ b/app.ts @@ -1,8 +1,8 @@ import express, { NextFunction, Request, Response } from "express"; import createError from "http-errors"; -import AppMiddlewares from "./middlewares"; -import indexRouter from "./routes/index"; -import health from "./controllers/health"; +import AppMiddlewares from "./middlewares/index.js"; +import indexRouter from "./routes/index.js"; +import health from "./controllers/health.js"; // Initialise express const app = express(); diff --git a/controllers/auth.ts b/controllers/auth.ts index ca70207..f433c28 100644 --- a/controllers/auth.ts +++ b/controllers/auth.ts @@ -1,7 +1,7 @@ import passport from "passport"; import { NextFunction, Request, Response } from "express"; -import logger from "../utils/logger"; -import * as authService from "../services/authService"; +import logger from "../utils/logger.js"; +import * as authService from "../services/authService.js"; /** * Fetches the user info from Google and authenticates User diff --git a/controllers/health.ts b/controllers/health.ts index 23955f2..c3f1d52 100644 --- a/controllers/health.ts +++ b/controllers/health.ts @@ -1,5 +1,5 @@ import { Request, Response } from "express"; -import { healthResponse } from "../@types/apiReponse"; +import { healthResponse } from "../@types/apiReponse.js"; import { version } from "../package.json"; /** diff --git a/controllers/users.ts b/controllers/users.ts index 3699c32..5452793 100644 --- a/controllers/users.ts +++ b/controllers/users.ts @@ -1,5 +1,5 @@ import { Request, Response } from "express"; -import prisma from "../prisma/prisma"; +import prisma from "../prisma/prisma.js"; import { Users } from "@prisma/client"; /** diff --git a/middlewares/authenticate.ts b/middlewares/authenticate.ts index 4165239..55e2ae0 100644 --- a/middlewares/authenticate.ts +++ b/middlewares/authenticate.ts @@ -1,5 +1,5 @@ -import * as authService from "../services/authService"; -import prisma from "../prisma/prisma"; +import * as authService from "../services/authService.js"; +import prisma from "../prisma/prisma.js"; import { NextFunction, Request, Response } from "express"; /** diff --git a/middlewares/index.ts b/middlewares/index.ts index f6558da..8ad0401 100644 --- a/middlewares/index.ts +++ b/middlewares/index.ts @@ -6,9 +6,9 @@ import cors from "cors"; import config from "config"; import passport from "passport"; import * as dotenv from "dotenv"; -import morganMiddleware from "../utils/httpLogger"; -import "../providers/google"; -import "../providers/microsoft"; +import morganMiddleware from "../utils/httpLogger.js"; +import "../providers/google.js"; +import "../providers/microsoft.js"; const middleware = (app: express.Application): void => { // Load vars from .env to process.env diff --git a/package.json b/package.json index 8b0fe9f..aa275d1 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.0.1", "private": true, "main": "dist/server.js", + "type": "module", "scripts": { "lint": "eslint . && echo '✔ Your .js files look good.'", "lint-fix": "eslint . --fix", diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml deleted file mode 100644 index e5a788a..0000000 --- a/prisma/migrations/migration_lock.toml +++ /dev/null @@ -1,3 +0,0 @@ -# Please do not edit this file manually -# It should be added in your version-control system (i.e. Git) -provider = "mysql" \ No newline at end of file diff --git a/routes/auth.ts b/routes/auth.ts index 83bf601..f5e9769 100644 --- a/routes/auth.ts +++ b/routes/auth.ts @@ -3,7 +3,7 @@ import { googleAuthCallback, microsoftAuthCallback, logOut, -} from "../controllers/auth"; +} from "../controllers/auth.js"; import passport from "passport"; const router = Router(); diff --git a/routes/calendar.ts b/routes/calendar.ts index 2a61c35..f6bb778 100644 --- a/routes/calendar.ts +++ b/routes/calendar.ts @@ -2,7 +2,7 @@ import { Router } from "express"; import { googleConnectHandler, googleCallbackHandler, -} from "../controllers/calendar"; +} from "../controllers/calendar.js"; const router = Router(); diff --git a/routes/health.ts b/routes/health.ts index 8da0bd1..9225167 100644 --- a/routes/health.ts +++ b/routes/health.ts @@ -1,5 +1,5 @@ import { Router } from "express"; -import health from "../controllers/health"; +import health from "../controllers/health.js"; const router = Router(); diff --git a/routes/index.ts b/routes/index.ts index 691f36d..cffa93f 100644 --- a/routes/index.ts +++ b/routes/index.ts @@ -1,8 +1,8 @@ import express from "express"; -import health from "./health"; -import auth from "./auth"; -import users from "./users"; -import calendar from "./calendar"; +import health from "./health.js"; +import auth from "./auth.js"; +import users from "./users.js"; +import calendar from "./calendar.js"; const app = express(); diff --git a/routes/users.ts b/routes/users.ts index 700e53a..4b44694 100644 --- a/routes/users.ts +++ b/routes/users.ts @@ -1,8 +1,8 @@ import { Router } from "express"; -import { getSelfData, patchSelfData } from "../controllers/users"; -import authenticate from "../middlewares/authenticate"; -import { validate } from "../middlewares/validators/validator"; -import { patchUserSelfSchema } from "../middlewares/validators/userSchema"; +import { getSelfData, patchSelfData } from "../controllers/users.js"; +import authenticate from "../middlewares/authenticate.js"; +import { validate } from "../middlewares/validators/validator.js"; +import { patchUserSelfSchema } from "../middlewares/validators/userSchema.js"; const router = Router(); diff --git a/server.ts b/server.ts index fe1c4cc..98965a7 100644 --- a/server.ts +++ b/server.ts @@ -1,7 +1,7 @@ import config from "config"; -import logger from "./utils/logger"; +import logger from "./utils/logger.js"; import * as http from "http"; -import app from "./app"; +import app from "./app.js"; import ErrnoException = NodeJS.ErrnoException; // Initialise globals diff --git a/services/authService.ts b/services/authService.ts index 4b71ee8..e6dcf4e 100644 --- a/services/authService.ts +++ b/services/authService.ts @@ -1,7 +1,7 @@ import jwt from "jsonwebtoken"; -import { GoogleOAuthJson, MicrosoftOAuthJson } from "../@types/providers"; -import prisma from "../prisma/prisma"; -import { jwtPayload } from "../@types/services"; +import { GoogleOAuthJson, MicrosoftOAuthJson } from "../@types/providers.js"; +import prisma from "../prisma/prisma.js"; +import { jwtPayload } from "../@types/services.js"; import { Users } from "@prisma/client"; /** diff --git a/test/integration/auth.test.ts b/test/integration/auth.test.ts index 894cd00..3b86c91 100644 --- a/test/integration/auth.test.ts +++ b/test/integration/auth.test.ts @@ -1,7 +1,7 @@ import chai from "chai"; import chaiHttp from "chai-http"; -import app from "../../server"; +import app from "../../server.js"; const { expect } = chai; chai.use(chaiHttp); diff --git a/test/integration/health.test.ts b/test/integration/health.test.ts index aebc8a6..976b803 100644 --- a/test/integration/health.test.ts +++ b/test/integration/health.test.ts @@ -1,7 +1,7 @@ import chai from "chai"; import chaiHttp from "chai-http"; -import app from "../../server"; +import app from "../../server.js"; const { expect } = chai; chai.use(chaiHttp); diff --git a/test/unit/security.test.ts b/test/unit/security.test.ts index 6738ba9..975c25a 100644 --- a/test/unit/security.test.ts +++ b/test/unit/security.test.ts @@ -1,7 +1,7 @@ import chai from "chai"; import chaiHttp from "chai-http"; -import app from "../../server"; +import app from "../../server.js"; const { expect } = chai; chai.use(chaiHttp); diff --git a/tsconfig.json b/tsconfig.json index 664ae75..e473f2f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -29,7 +29,7 @@ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ - "module": "commonjs", + "module": "nodenext", /* Specify what module code is generated. */ // "rootDir": "./", /* Specify the root folder within your source files. */ // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */