From 98a74e12cfa362e408c5cbc1d960dd3acc52a516 Mon Sep 17 00:00:00 2001 From: ereti <43418802+ereti@users.noreply.github.com> Date: Mon, 28 Nov 2022 00:58:38 +0000 Subject: [PATCH] feat: make monorepo sane --- .dockerignore | 8 ++++++-- .gitignore | 4 +++- Dockerfile.server | 18 +++++++++--------- common/.npmignore | 1 + common/package.json | 10 ++++++---- common/tsconfig.json | 8 ++++++-- package.json | 10 +++++----- pnpm-lock.yaml | 35 ++++++++++++++++++++++++++++++++--- pnpm-workspace.yaml | 2 +- server/package.json | 12 ++++++++---- server/tsconfig.build.json | 5 +++++ server/tsconfig.json | 19 +++++++++++-------- tsconfig.json | 16 +++++++++++++++- 13 files changed, 108 insertions(+), 40 deletions(-) create mode 100644 common/.npmignore diff --git a/.dockerignore b/.dockerignore index 243b5dee4..8e61eb35c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,6 @@ -**/.git -**/node_modules \ No newline at end of file +.git +node_modules +.tsbuildinfo +**/node_modules +**/.tsbuildinfo +database-seeds \ No newline at end of file diff --git a/.gitignore b/.gitignore index 379bc1eef..0a290ff55 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,6 @@ logs .nyc_output coverage out.* -failed-tests.log \ No newline at end of file +failed-tests.log + +.tsbuildinfo \ No newline at end of file diff --git a/Dockerfile.server b/Dockerfile.server index f4d7f2089..21ae294b6 100644 --- a/Dockerfile.server +++ b/Dockerfile.server @@ -11,23 +11,23 @@ RUN apk add --no-cache FROM base AS build WORKDIR /app - COPY pnpm-lock.yaml . RUN pnpm fetch COPY . . -RUN pnpm install -r --offline --silent +RUN pnpm --filter ./common --filter ./server --filter . install --prefer-offline -WORKDIR /app/server - -RUN pnpm build +RUN pnpm --filter ./common --filter ./server build FROM base AS app -WORKDIR /app/server -COPY --from=build /app /app +WORKDIR /app +COPY --from=build /app/node_modules /app/node_modules +COPY --from=build /app/server /app/server +COPY --from=build /app/common /app/common +COPY --from=build /app/package.json /app/package.json HEALTHCHECK --interval=15s --timeout=5s CMD curl -f http://localhost:8080/api/v1/status || exit 1 -ENV NODE_PATH=js/ -CMD ["pnpm", "start-no-build"] +ENV NODE_PATH=/app/server/js +CMD ["node", "/app/server/js/main.js"] diff --git a/common/.npmignore b/common/.npmignore new file mode 100644 index 000000000..aa8e45f12 --- /dev/null +++ b/common/.npmignore @@ -0,0 +1 @@ +src/ \ No newline at end of file diff --git a/common/package.json b/common/package.json index b08ef4a9e..6484e0495 100644 --- a/common/package.json +++ b/common/package.json @@ -2,13 +2,15 @@ "name": "tachi-common", "version": "2.2.0", "description": "Common Types & Utilities for Tachi", - "main": "js/index.js", - "files": [ - "js/**/*" - ], + "main": "./js/index.js", + "exports": { + ".": "./js/index.js", + "./*": "./js/*.js" + }, "scripts": { "test": "tap", "build": "tsc", + "install": "tsc", "prepublish": "tsc", "lint": "eslint . --ext .ts --fix" }, diff --git a/common/tsconfig.json b/common/tsconfig.json index d53a1131d..3ce446705 100644 --- a/common/tsconfig.json +++ b/common/tsconfig.json @@ -1,14 +1,18 @@ { "extends": "../tsconfig.json", "compilerOptions": { - "outDir": "./js", - "target": "ES2020" + "rootDir": "src", + "outDir": "js", + "target": "ES2020", + "composite": true, + "tsBuildInfoFile": ".tsbuildinfo" }, "include": [ "src/**/*.ts", "src/**/*.test.ts" ], "exclude": [ + "node_modules", "src/legacy/**/*.ts" ] } \ No newline at end of file diff --git a/package.json b/package.json index 3ed2c516e..3a05f4545 100644 --- a/package.json +++ b/package.json @@ -26,18 +26,18 @@ "devDependencies": { "@types/node": "16.11.7", "@types/tap": "15.0.3", + "@typescript-eslint/eslint-plugin": "5.22.0", + "@typescript-eslint/parser": "5.22.0", "eslint": "8.18.0", "eslint-plugin-cadence": "0.0.4", "tap": "15.0.9", "ts-node": "10.0.0", - "typescript": "4.6.3", - "@typescript-eslint/eslint-plugin": "5.22.0", - "@typescript-eslint/parser": "5.22.0", - "tsconfig-paths": "3.12.0" + "tsc-alias": "1.7.1", + "typescript": "4.6.3" }, "peerDependencies": { - "@types/mongodb": "3.6.18", "@types/bson": "1.0.11", + "@types/mongodb": "3.6.18", "@types/node": "16.11.7" }, "pnpm": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f1d59c786..dfc292a2d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,7 +18,7 @@ importers: eslint-plugin-cadence: 0.0.4 tap: 15.0.9 ts-node: 10.0.0 - tsconfig-paths: 3.12.0 + tsc-alias: 1.7.1 typescript: 4.6.3 devDependencies: '@types/node': 16.11.7 @@ -29,7 +29,7 @@ importers: eslint-plugin-cadence: 0.0.4_qt5lczejmvvdmrtns7px3uxl6e tap: 15.0.9_brhf6n5slbghal4nq2ewuwl5ie ts-node: 10.0.0_yebhed3ekczgx3zz6hdxw3kxou - tsconfig-paths: 3.12.0 + tsc-alias: 1.7.1 typescript: 4.6.3 bot: @@ -389,6 +389,7 @@ importers: semver: ^7.3.7 seq-logging: 1.1.1 supertest: 6.2.2 + tachi-common: workspace:../common tap: 15.1.6 ts-node: 10.0.0 tsconfig-paths: 3.12.0 @@ -453,6 +454,7 @@ importers: safe-json-stringify: 1.2.0 semver: 7.3.7 seq-logging: 1.1.1 + tachi-common: link:../common ts-node: 10.0.0_eyk5xebzzzbswsv7f7bz54zw5q tsconfig-paths: 3.12.0 typescript: 4.5.5 @@ -5372,7 +5374,6 @@ packages: /commander/9.0.0: resolution: {integrity: sha512-JJfP2saEKbQqvW+FI93OYUB4ByV5cizMpFMiiJI8xDbBvQvSkIk0VvQdn1CZ8mqAO8Loq2h0gYTYtDFUZUeERw==} engines: {node: ^12.20.0 || >=14} - dev: false /commist/1.1.0: resolution: {integrity: sha512-rraC8NXWOEjhADbZe9QBNzLAN5Q3fsTPQtBV+fEVj6xKIgDgNiEVE6ZNfHpZOqfQ21YUzfVNUXLOEZquYvQPPg==} @@ -10198,6 +10199,11 @@ packages: dev: false optional: true + /mylas/2.1.13: + resolution: {integrity: sha512-+MrqnJRtxdF+xngFfUUkIMQrUUL0KsxbADUkn23Z/4ibGg192Q+z+CQyiYwvWTsYjJygmMR8+w3ZDa98Zh6ESg==} + engines: {node: '>=12.0.0'} + dev: true + /nan/2.16.0: resolution: {integrity: sha512-UdAqHyFngu7TfQKsCBgAA6pWDkT8MAO7d0jyOecVhN5354xbLqdn8mV9Tat9gepAupm0bt2DbeaSC8vS52MuFA==} requiresBuild: true @@ -11034,6 +11040,12 @@ packages: find-up: 2.1.0 dev: true + /plimit-lit/1.5.0: + resolution: {integrity: sha512-Eb/MqCb1Iv/ok4m1FqIXqvUKPISufcjZ605hl3KM/n8GaX8zfhtgdLwZU3vKjuHGh2O9Rjog/bHTq8ofIShdng==} + dependencies: + queue-lit: 1.5.0 + dev: true + /pnp-webpack-plugin/1.5.0_typescript@4.3.5: resolution: {integrity: sha512-jd9olUr9D7do+RN8Wspzhpxhgp1n6Vd0NtQ4SFkmIACZoEL1nkyAdW9Ygrinjec0vgDcWjscFQQ1gDW8rsfKTg==} engines: {node: '>=6'} @@ -11939,6 +11951,10 @@ packages: resolution: {integrity: sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==} dev: true + /queue-lit/1.5.0: + resolution: {integrity: sha512-IslToJ4eiCEE9xwMzq3viOO5nH8sUWUCwoElrhNMozzr9IIt2qqvB4I+uHu/zJTQVqc9R5DFwok4ijNK1pU3fA==} + dev: true + /queue-microtask/1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} dev: true @@ -14134,6 +14150,18 @@ packages: dependencies: typescript: 4.3.5 + /tsc-alias/1.7.1: + resolution: {integrity: sha512-P4+0i+OB0hX17Ca+U6EJ4WZZ+OSupqW32VJ34N7g7+Ch+bwSx1AqYOvDdIVYEKymBh3dfG0t1qxbxPlBbtB1lQ==} + hasBin: true + dependencies: + chokidar: 3.5.3 + commander: 9.0.0 + globby: 11.1.0 + mylas: 2.1.13 + normalize-path: 3.0.0 + plimit-lit: 1.5.0 + dev: true + /tsconfig-paths-webpack-plugin/3.5.2: resolution: {integrity: sha512-EhnfjHbzm5IYI9YPNVIxx1moxMI4bpHD2e0zTXeDNQcwjjRaGepP7IhTHJkyDBG0CAOoxRfe7jCG630Ou+C6Pw==} dependencies: @@ -14149,6 +14177,7 @@ packages: json5: 1.0.1 minimist: 1.2.6 strip-bom: 3.0.0 + dev: false /tsconfig-paths/3.14.1: resolution: {integrity: sha512-fxDhWnFSLt3VuTwtvJt5fpwxBHg5AdKWMsgcPOOIilyjymcYVZoCQF8fvFRezCNfblEXmi+PcM1eYHeOAgXCOQ==} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 597bcad4e..eff05b85f 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -7,4 +7,4 @@ packages: - "database-seeds/**" - "server/**" - "sieglinde/**" - - "github-bot/**" + - "github-bot/**" \ No newline at end of file diff --git a/server/package.json b/server/package.json index 77f838245..9b314f57f 100644 --- a/server/package.json +++ b/server/package.json @@ -2,7 +2,10 @@ "name": "tachi-server", "version": "0.1.0-see-project-root", "description": "A score tracking server.", - "main": "js/server/src/main.js", + "main": "./js/main.js", + "files": [ + "/js" + ], "private": true, "scripts": { "test": "tap", @@ -12,8 +15,8 @@ "typecheck": "tsc --project tsconfig.build.json --noEmit", "lint": "eslint ./src --ext .ts --fix", "start": "pnpm build && pnpm start-no-build", - "start-no-build": "node -r ts-node/register -r tsconfig-paths/register js/server/src/main.js", - "runscoreworker": "node -r ts-node/register -r tsconfig-paths/register js/server/src/lib/score-import/worker/worker.js", + "start-no-build": "node js/server/main.js", + "runscoreworker": "node js/server/lib/score-import/worker/worker.js", "sync-database": "ts-node src/scripts/sync-database", "sync-database-local": "ts-node src/scripts/sync-database --localPath '../database-seeds/collections'", "recalc-everything": "ts-node src/scripts/state-sync/sync-state.ts" @@ -90,7 +93,8 @@ "typescript": "4.5.5", "winston": "3.5.1", "winston-daily-rotate-file": "4.6.0", - "winston-transport": "4.5.0" + "winston-transport": "4.5.0", + "tachi-common": "workspace:../common" }, "nyc": { "reporter": [ diff --git a/server/tsconfig.build.json b/server/tsconfig.build.json index 582a4c1e2..8c5fadf78 100644 --- a/server/tsconfig.build.json +++ b/server/tsconfig.build.json @@ -11,5 +11,10 @@ "node_modules", "src/test-utils", "src/**/*.test.ts" + ], + "references": [ + { + "path": "../common" + } ] } \ No newline at end of file diff --git a/server/tsconfig.json b/server/tsconfig.json index 7d7f9a6fe..f5e87ebfc 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -6,8 +6,9 @@ { "extends": "../tsconfig.json", "compilerOptions": { + "rootDir": "src", "baseUrl": "src", - "outDir": "./js", + "outDir": "js", "target": "ES2020", "lib": [ "ES2019", @@ -26,18 +27,20 @@ ], "tachi-common/*": [ "../../common/src/*" - ] - } - }, - "ts-node": { - "require": [ - "tsconfig-paths/register" - ] + ], + }, + "composite": true, + "tsBuildInfoFile": ".tsbuildinfo" }, "include": [ "src/**/*.ts" ], "exclude": [ "node_modules" + ], + "references": [ + { + "path": "../common" + } ] } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 01c749dc2..58e16d4d4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,20 @@ "allowJs": false, "esModuleInterop": true, "noUncheckedIndexedAccess": true, - "sourceMap": true + "sourceMap": true, + "rootDir": ".", + "composite": true, + "tsBuildInfoFile": ".tsbuildinfo" }, + "files": [], + "references": [ + { + "path": "./common", + "prepend": true + }, + { + "path": "./server", + "prepend": true + } + ] } \ No newline at end of file