From 75e4fa678139c3da3b6b27042aad32953416e718 Mon Sep 17 00:00:00 2001 From: survikrowa Date: Tue, 16 Aug 2022 22:10:10 +0200 Subject: [PATCH 01/16] feat/add-autoload-plugins --- package.json | 2 ++ src/server.ts | 12 ++++++++++-- tsconfig.json | 4 +++- yarn.lock | 43 ++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 4f6937b..d3920cc 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "repository": "git@github.com:Frontlive/school-ecommerce-be.git", "author": "Frontlive-Survi", "license": "MIT", + "type": "module", "scripts": { "build": "tsc -p tsconfig.json", "start": "tsnd --respawn index.ts", @@ -16,6 +17,7 @@ "test": "jest" }, "dependencies": { + "@fastify/autoload": "^5.2.0", "dotenv": "^16.0.1", "fastify": "^4.4.0", "prisma": "^4.2.1" diff --git a/src/server.ts b/src/server.ts index fc603f3..7186603 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,9 +1,17 @@ import fastify from 'fastify'; +import fastifyAutoload from '@fastify/autoload'; +import { fileURLToPath } from 'url'; +import { dirname, join } from 'path'; export const app = fastify({ - logger: true, + logger: true, }); +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +app.register(fastifyAutoload, { dir: join(__dirname, 'plugins') }); + app.get('/', (_, reply) => { - reply.send('hello frontlive'); + reply.send('hello frontlive'); }); diff --git a/tsconfig.json b/tsconfig.json index e296f4a..20bcb35 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,6 +2,8 @@ "extends": "@tsconfig/node16/tsconfig.json", "compilerOptions": { "baseUrl": "./", - "outDir": "./build" + "outDir": "./build", + "target": "ESNext", + "module": "ESNext" } } diff --git a/yarn.lock b/yarn.lock index d842c0c..f046284 100644 --- a/yarn.lock +++ b/yarn.lock @@ -321,6 +321,13 @@ ajv-formats "^2.1.1" fast-uri "^2.0.0" +"@fastify/autoload@^5.2.0": + version "5.2.0" + resolved "https://registry.yarnpkg.com/@fastify/autoload/-/autoload-5.2.0.tgz#1138c3a956487946bf8e863d870413b88d241ba1" + integrity sha512-qpLVPQM+JCiGvRdybGRz8dty3HRJtKgYRCagslyAiVecN+g/xHvB0gR8I1PiOvek2NQFIs3WPDxz2nLBoXqB2A== + dependencies: + pkg-up "^3.1.0" + "@fastify/deepmerge@^1.0.0": version "1.1.0" resolved "https://registry.yarnpkg.com/@fastify/deepmerge/-/deepmerge-1.1.0.tgz#91f0a5a27034ff76b7bece63a5906894940ace82" @@ -1746,6 +1753,13 @@ find-my-way@^7.0.0: fast-deep-equal "^3.1.3" safe-regex2 "^2.0.0" +find-up@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-3.0.0.tgz#49169f1d7993430646da61ecc5ae355c21c97b73" + integrity sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg== + dependencies: + locate-path "^3.0.0" + find-up@^4.0.0, find-up@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/find-up/-/find-up-4.1.0.tgz#97afe7d6cdc0bc5928584b7c8d7b16e8a9aa5d19" @@ -2590,6 +2604,14 @@ listr2@^4.0.5: through "^2.3.8" wrap-ansi "^7.0.0" +locate-path@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-3.0.0.tgz#dbec3b3ab759758071b58fe59fc41871af21400e" + integrity sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A== + dependencies: + p-locate "^3.0.0" + path-exists "^3.0.0" + locate-path@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-5.0.0.tgz#1afba396afd676a6d42504d0a67a3a7eb9f62aa0" @@ -2794,7 +2816,7 @@ optionator@^0.9.1: type-check "^0.4.0" word-wrap "^1.2.3" -p-limit@^2.2.0: +p-limit@^2.0.0, p-limit@^2.2.0: version "2.3.0" resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1" integrity sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w== @@ -2808,6 +2830,13 @@ p-limit@^3.0.2, p-limit@^3.1.0: dependencies: yocto-queue "^0.1.0" +p-locate@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-3.0.0.tgz#322d69a05c0264b25997d9f40cd8a891ab0064a4" + integrity sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ== + dependencies: + p-limit "^2.0.0" + p-locate@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-4.1.0.tgz#a3428bb7088b3a60292f66919278b7c297ad4f07" @@ -2851,6 +2880,11 @@ parse-json@^5.2.0: json-parse-even-better-errors "^2.3.0" lines-and-columns "^1.1.6" +path-exists@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515" + integrity sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ== + path-exists@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3" @@ -2938,6 +2972,13 @@ pkg-dir@^4.2.0: dependencies: find-up "^4.0.0" +pkg-up@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/pkg-up/-/pkg-up-3.1.0.tgz#100ec235cc150e4fd42519412596a28512a0def5" + integrity sha512-nDywThFk1i4BQK4twPQ6TA4RT8bDY96yeuCVBWL3ePARCiEKDRSrNGbFIgUJpLp+XeIR65v8ra7WuJOFUBtkMA== + dependencies: + find-up "^3.0.0" + prelude-ls@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396" From 50d434ea875d91a3fdced3b1d42f932d8cc0da28 Mon Sep 17 00:00:00 2001 From: survikrowa Date: Tue, 16 Aug 2022 22:10:36 +0200 Subject: [PATCH 02/16] prettier --- .prettierrc | 12 +++--- docker-compose.yml | 4 +- index.ts | 12 +++--- package.json | 92 +++++++++++++++++++++++----------------------- 4 files changed, 60 insertions(+), 60 deletions(-) diff --git a/.prettierrc b/.prettierrc index dbad082..c1ccc58 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,8 +1,8 @@ { - "tabWidth": 2, - "printWidth": 100, - "singleQuote": true, - "trailingComma": "all", - "semi": true, - "useTabs": true + "tabWidth": 2, + "printWidth": 100, + "singleQuote": true, + "trailingComma": "all", + "semi": true, + "useTabs": true } diff --git a/docker-compose.yml b/docker-compose.yml index f59b324..47083fb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,8 +4,8 @@ services: database: image: postgres:14.2-alpine ports: - - "5432:5432" + - '5432:5432' environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres - POSTGRES_DB: ecommerce-db \ No newline at end of file + POSTGRES_DB: ecommerce-db diff --git a/index.ts b/index.ts index 90f176a..85ce7b0 100644 --- a/index.ts +++ b/index.ts @@ -4,11 +4,11 @@ import { app } from './src/server'; const port = Number(process.env.PORT) || 4000; const start = async () => { - try { - await app.listen({ port }); - } catch (err) { - app.log.error(err); - process.exit(1); - } + try { + await app.listen({ port }); + } catch (err) { + app.log.error(err); + process.exit(1); + } }; void start(); diff --git a/package.json b/package.json index d3920cc..25bfeaf 100644 --- a/package.json +++ b/package.json @@ -1,48 +1,48 @@ { - "name": "school-ecommerce-be", - "version": "1.0.0", - "main": "index.js", - "repository": "git@github.com:Frontlive/school-ecommerce-be.git", - "author": "Frontlive-Survi", - "license": "MIT", - "type": "module", - "scripts": { - "build": "tsc -p tsconfig.json", - "start": "tsnd --respawn index.ts", - "start:prod": "yarn db:migrate:prod:up && node build/main", - "db:migrate:up": "yarn prisma migrate dev && yarn prisma generate", - "db:migrate:prod:up": "yarn prisma migrate deploy", - "lint": "eslint . --ext .ts", - "prepare": "husky install", - "test": "jest" - }, - "dependencies": { - "@fastify/autoload": "^5.2.0", - "dotenv": "^16.0.1", - "fastify": "^4.4.0", - "prisma": "^4.2.1" - }, - "devDependencies": { - "@tsconfig/node16": "^1.0.3", - "@types/node": "^18.7.2", - "@typescript-eslint/eslint-plugin": "^5.33.0", - "@typescript-eslint/parser": "^5.33.0", - "eslint": "^8.21.0", - "husky": "^8.0.0", - "jest": "^28.1.3", - "lint-staged": "^13.0.3", - "prettier": "^2.7.1", - "supertest": "^6.2.4", - "ts-node-dev": "^2.0.0", - "typescript": "^4.7.4" - }, - "lint-staged": { - "src/**/*.ts": [ - "eslint . --ext .ts", - "prettier --write ." - ] - }, - "jest": { - "testEnvironment": "node" - } + "name": "school-ecommerce-be", + "version": "1.0.0", + "main": "index.js", + "repository": "git@github.com:Frontlive/school-ecommerce-be.git", + "author": "Frontlive-Survi", + "license": "MIT", + "type": "module", + "scripts": { + "build": "tsc -p tsconfig.json", + "start": "tsnd --respawn index.ts", + "start:prod": "yarn db:migrate:prod:up && node build/main", + "db:migrate:up": "yarn prisma migrate dev && yarn prisma generate", + "db:migrate:prod:up": "yarn prisma migrate deploy", + "lint": "eslint . --ext .ts", + "prepare": "husky install", + "test": "jest" + }, + "dependencies": { + "@fastify/autoload": "^5.2.0", + "dotenv": "^16.0.1", + "fastify": "^4.4.0", + "prisma": "^4.2.1" + }, + "devDependencies": { + "@tsconfig/node16": "^1.0.3", + "@types/node": "^18.7.2", + "@typescript-eslint/eslint-plugin": "^5.33.0", + "@typescript-eslint/parser": "^5.33.0", + "eslint": "^8.21.0", + "husky": "^8.0.0", + "jest": "^28.1.3", + "lint-staged": "^13.0.3", + "prettier": "^2.7.1", + "supertest": "^6.2.4", + "ts-node-dev": "^2.0.0", + "typescript": "^4.7.4" + }, + "lint-staged": { + "src/**/*.ts": [ + "eslint . --ext .ts", + "prettier --write ." + ] + }, + "jest": { + "testEnvironment": "node" + } } From 0e9fb948b5fd4fa2b3a68745c70fba30e9637d6b Mon Sep 17 00:00:00 2001 From: survikrowa Date: Sat, 20 Aug 2022 23:50:31 +0200 Subject: [PATCH 03/16] fix/esm-modules --- .idea/codeStyles/Project.xml | 15 +- package.json | 8 +- src/server.ts | 14 +- tsconfig.json | 4 +- yarn.lock | 378 ++++++++++++++++++++++++++--------- 5 files changed, 304 insertions(+), 115 deletions(-) diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 8ba2a12..f986f2f 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -2,24 +2,21 @@ @@ -28,7 +25,7 @@