Skip to content

Draft: migrated to esbulild #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions esbuild.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const path = require('path');
const execSync = require('child_process').execSync;
const { globPlugin } = require('esbuild-plugin-glob');

execSync('npx rimraf ./dist && mkdir dist');

const copy = ['json', 'html', 'png'];

const alias = {
name: 'alias',
setup(build) {
build.onResolve({ filter: /^@\/.*/ }, (args) => {
console.log('Entered onResolve');
return {
path: path.resolve(__dirname, './src', args.path.replace(/^@\//, ''))
};
});
}
};

require('esbuild')
.build({
entryPoints: [`./src/**/*.{js,${copy.join(',')}}`],
bundle: false,
outdir: './dist',
outbase: './src',
platform: 'node',
target: 'node16.0',
format: 'cjs',
minify: false,
sourcemap: true,
keepNames: true,
loader: copy.reduce((acc, ext) => ({ ...acc, [`.${ext}`]: 'copy' }), {}),
plugins: [alias, globPlugin()]
})
.catch(() => process.exit(1));
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -4,10 +4,7 @@
"description": "Backend",
"main": "src/app.js",
"scripts": {
"build": "npm run clean && npm run build-babel && npm run copy",
"build-babel": "babel -d ./dist ./src -s",
"clean": "rm -rf dist && mkdir dist",
"copy": "babel src --out-dir ./dist --copy-files",
"build": "node esbuild.config.js",
"dev": "nodemon --exec babel-node src/app.js",
"format": "prettier --write --cache \"**/*.{js,md}\"",
"lint": "eslint src --ext js,md --ignore-path .gitignore --fix --cache --report-unused-disable-directives",
@@ -59,10 +56,14 @@
"@trivago/prettier-plugin-sort-imports": "4.1.1",
"babel-plugin-module-resolver": "5.0.0",
"dotenv": "16.0.1",
"esbuild": "0.18.17",
"esbuild-plugin-alias-path": "2.0.2",
"esbuild-plugin-glob": "2.2.2",
"eslint": "8.45.0",
"eslint-plugin-import": "2.27.5",
"lefthook": "1.4.3",
"nodemon": "3.0.1",
"prettier": "2.8.8"
"prettier": "2.8.8",
"rimraf": "5.0.1"
}
}
437 changes: 435 additions & 2 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import crypto from 'crypto';
import express from 'express';
import context from 'express-http-context';
import rateLimit from 'express-rate-limit';
import httpLogger from '@sliit-foss/http-logger';
import { moduleLogger } from '@sliit-foss/module-logger';
import compression from 'compression';
import cors from 'cors';
import crypto from 'crypto';
import helmet from 'helmet';
import { pick } from 'lodash';
import { default as connectDB } from '@/database';
2 changes: 1 addition & 1 deletion src/middleware/errors.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { moduleLogger } from '@sliit-foss/module-logger';
import { isCelebrateError } from 'celebrate';
import { responseInterceptor } from './response';
import { makeResponse } from '@/utils';
import { responseInterceptor } from './response';

const logger = moduleLogger('Error-handler');

2 changes: 1 addition & 1 deletion src/routes/index.routes.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import express from 'express';
import { adminProtect, protect } from '@/middleware/auth';
import authRouter from './auth.routes';
import dashboardRouter from './dashboard.routes';
import questionRouter from './question.routes';
import submissionRouter from './submission.routes';
import userRouter from './user.routes';
import { adminProtect, protect } from '@/middleware/auth';

const router = express.Router();

4 changes: 2 additions & 2 deletions src/services/auth.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import crypto from 'crypto';
import bcrypt from 'bcrypt';
import crypto from 'crypto';
import createError from 'http-errors';
import { sendMail } from './email';
import { createUser, findOneAndUpdateUser, getOneUser } from '@/repository/user';
import { decodeJwtToken } from '@/utils';
import { sendMail } from './email';

export const authRegister = async ({ name, email, password, university, members }) => {
const encryptedPassword = await new Promise((resolve, reject) => {
2 changes: 1 addition & 1 deletion src/services/user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import bcrypt from 'bcrypt';
import createError from 'http-errors';
import { sendMail } from './email';
import { getAllQuestionIds } from '@/repository/question';
import { getLatestScore } from '@/repository/submission';
import {
@@ -11,6 +10,7 @@ import {
getAllUsers,
getOneUser
} from '@/repository/user';
import { sendMail } from './email';

export const updateScoreService = async (user) => {
const questions = await getAllQuestionIds();