diff --git a/.env b/.env index 30c4cfc3b..215582d4c 100644 --- a/.env +++ b/.env @@ -9,7 +9,7 @@ REDIS_URL=redis://127.0.0.1:6379 ROCKET_CHAT_API_USER_ID=an-user-id ROCKET_CHAT_API_AUTH_TOKEN=an-auth-token ROCKET_CHAT_URL=https://community.serlo.org/ -SERLO_ORG_DATABASE_LAYER_HOST=localhost:8080 +SERLO_ORG_DATABASE_LAYER_HOST=127.0.0.1:8080 SERLO_ORG_SECRET=serlo.org-secret CACHE_TYPE=empty diff --git a/.yarn/cache/@zerollup-ts-helpers-npm-1.7.18-fa39b91899-6ad5cc3501.zip b/.yarn/cache/@zerollup-ts-helpers-npm-1.7.18-fa39b91899-6ad5cc3501.zip deleted file mode 100644 index 4de5299b7..000000000 Binary files a/.yarn/cache/@zerollup-ts-helpers-npm-1.7.18-fa39b91899-6ad5cc3501.zip and /dev/null differ diff --git a/.yarn/cache/@zerollup-ts-transform-paths-npm-1.7.18-14319406c9-2a3b258222.zip b/.yarn/cache/@zerollup-ts-transform-paths-npm-1.7.18-14319406c9-2a3b258222.zip deleted file mode 100644 index af6512cc0..000000000 Binary files a/.yarn/cache/@zerollup-ts-transform-paths-npm-1.7.18-14319406c9-2a3b258222.zip and /dev/null differ diff --git a/.yarn/cache/babel-plugin-import-graphql-npm-2.8.1-2a6a1b69ec-8e156d514c.zip b/.yarn/cache/babel-plugin-import-graphql-npm-2.8.1-2a6a1b69ec-8e156d514c.zip deleted file mode 100644 index c7b49c73d..000000000 Binary files a/.yarn/cache/babel-plugin-import-graphql-npm-2.8.1-2a6a1b69ec-8e156d514c.zip and /dev/null differ diff --git a/.yarn/cache/babel-plugin-module-resolver-npm-5.0.0-67eb48a53b-d6880e49fc.zip b/.yarn/cache/babel-plugin-module-resolver-npm-5.0.0-67eb48a53b-d6880e49fc.zip deleted file mode 100644 index ec0488290..000000000 Binary files a/.yarn/cache/babel-plugin-module-resolver-npm-5.0.0-67eb48a53b-d6880e49fc.zip and /dev/null differ diff --git a/.yarn/cache/find-babel-config-npm-2.0.0-fc8c84f53e-d110308b02.zip b/.yarn/cache/find-babel-config-npm-2.0.0-fc8c84f53e-d110308b02.zip deleted file mode 100644 index 141f02e90..000000000 Binary files a/.yarn/cache/find-babel-config-npm-2.0.0-fc8c84f53e-d110308b02.zip and /dev/null differ diff --git a/.yarn/cache/pkg-up-npm-3.1.0-1eebe033b7-5bac346b7c.zip b/.yarn/cache/pkg-up-npm-3.1.0-1eebe033b7-5bac346b7c.zip deleted file mode 100644 index cb3a63d96..000000000 Binary files a/.yarn/cache/pkg-up-npm-3.1.0-1eebe033b7-5bac346b7c.zip and /dev/null differ diff --git a/.yarn/cache/reselect-npm-4.1.8-cad5f0a3f3-a4ac87ceda.zip b/.yarn/cache/reselect-npm-4.1.8-cad5f0a3f3-a4ac87ceda.zip deleted file mode 100644 index edd6e9a1f..000000000 Binary files a/.yarn/cache/reselect-npm-4.1.8-cad5f0a3f3-a4ac87ceda.zip and /dev/null differ diff --git a/package.json b/package.json index bc4aa4218..2e7f1aa6d 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "_prettier": "prettier .", "auth": "scripts/authenticate.sh", "_build": "node --loader ts-node/esm --experimental-specifier-resolution=node scripts/build", + "_start": "node --loader ts-node/esm --experimental-specifier-resolution=node scripts/start", "build:server": "yarn _build packages/server/src/server.ts server.cjs", "build:swr-queue-worker": "yarn _build packages/server/src/swr-queue-worker.ts swr-queue-worker.cjs", "build:packages": "yarn lerna run build", @@ -52,11 +53,11 @@ "redis:cli": "docker compose exec redis redis-cli", "redis:empty": "docker compose exec redis redis-cli FLUSHDB", "redis:list": "docker compose exec redis redis-cli KEYS '*'", - "start": "npm-run-all start:redis start:server", + "start": "run-s start:redis start:server", "start:enmeshed": "docker-compose -f enmeshed/docker-compose.yml up -d", "start:redis": "docker compose up --detach", - "start:server": "lerna run --stream --scope @serlo/api.serlo.org start", - "start:swr-queue-worker": "lerna run --stream --scope @serlo/api.serlo.org start:swr-queue-worker", + "start:server": "yarn _start packages/server/src/server.ts server.cjs", + "start:swr-queue-worker": "yarn _start packages/server/src/swr-queue-worker.ts swr-queue-worker.cjs", "stop": "docker compose stop", "stop:enmeshed": "docker-compose -f enmeshed/docker-compose.yml down", "stop:redis": "docker-compose stop", diff --git a/packages/server/.babelrc b/packages/server/.babelrc deleted file mode 100644 index 69d2d4b59..000000000 --- a/packages/server/.babelrc +++ /dev/null @@ -1,13 +0,0 @@ -{ - "plugins": [ - "babel-plugin-import-graphql", - [ - "babel-plugin-module-resolver", - { - "alias": { - "~": "./src" - } - } - ] - ] -} diff --git a/packages/server/package.json b/packages/server/package.json index b54de255c..244347858 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -14,10 +14,7 @@ "build:server": "yarn _build --format cjs --target node --entry src/server.ts", "build:swr-queue-worker": "yarn _build --format cjs --target node --entry src/swr-queue-worker.ts", "codegen": "graphql-codegen --config codegen.yml", - "deploy:image": "ts-node --experimental-specifier-resolution=node scripts/deploy", - "prestart": "lerna run build", - "start": "tsdx watch --transpileOnly --format cjs --target node --entry src/server.ts --tsconfig tsconfig.prod.json --onSuccess \"node dist\"", - "start:swr-queue-worker": "tsdx watch --transpileOnly --format cjs --target node --entry src/swr-queue-worker.ts --tsconfig tsconfig.prod.json --onSuccess \"node dist\"" + "deploy:image": "ts-node --experimental-specifier-resolution=node scripts/deploy" }, "dependencies": { "bee-queue": "^1.7.1" @@ -41,10 +38,7 @@ "@types/redlock": "^4.0.7", "@types/semver": "^7.5.6", "@types/uuid": "^9.0.7", - "@zerollup/ts-transform-paths": "^1.7.18", "apollo-datasource-rest": "^3.7.0", - "babel-plugin-import-graphql": "^2.8.1", - "babel-plugin-module-resolver": "^5.0.0", "basic-auth": "^2.0.1", "bull-arena": "^4.1.0", "default-import": "^1.1.5", diff --git a/packages/server/src/internals/server/index.ts b/packages/server/src/internals/server/index.ts index 29d3bba60..19802d8e2 100644 --- a/packages/server/src/internals/server/index.ts +++ b/packages/server/src/internals/server/index.ts @@ -1,6 +1,5 @@ import dotenv from 'dotenv' import createApp from 'express' -import path from 'path' import { applyGraphQLMiddleware } from './graphql-middleware' import { applySwrQueueDashboardMiddleware } from './swr-queue-dashboard-middleware' @@ -15,9 +14,8 @@ import { applyKratosMiddleware } from '~/internals/server/kratos-middleware' export { getGraphQLOptions } from './graphql-middleware' export async function start() { - dotenv.config({ - path: path.join(__dirname, '..', '..', '..', '.env'), - }) + dotenv.config() + initializeSentry({ context: 'server' }) const timer = createTimer() const cache = @@ -53,7 +51,7 @@ async function initializeServer({ }) const enmeshedPath = applyEnmeshedMiddleware({ app, cache }) - app.get(healthPath, (req, res) => { + app.get(healthPath, (_req, res) => { res.status(200).send('Okay!') }) diff --git a/packages/server/src/internals/swr-queue-worker.ts b/packages/server/src/internals/swr-queue-worker.ts index e09f886da..1eeee02f4 100644 --- a/packages/server/src/internals/swr-queue-worker.ts +++ b/packages/server/src/internals/swr-queue-worker.ts @@ -1,6 +1,5 @@ import dotenv from 'dotenv' import createApp from 'express' -import path from 'path' import { createCache } from './cache' import { initializeSentry } from './sentry' @@ -8,9 +7,7 @@ import { createSwrQueueWorker } from './swr-queue' import { createTimer } from './timer' export async function start() { - dotenv.config({ - path: path.join(__dirname, '..', '..', '..', '.env'), - }) + dotenv.config() initializeSentry({ context: 'swr-queue-worker' }) const timer = createTimer() const cache = createCache({ timer }) diff --git a/scripts/build.ts b/scripts/build.ts index dc67c6e46..e3bcab8c6 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -6,14 +6,19 @@ import * as path from 'path' import { fileURLToPath } from 'url' const graphqlLoaderPlugin = defaultImport(graphqlLoaderPlugin_) -const __dirname = path.dirname(fileURLToPath(import.meta.url)) - -const root = path.join(__dirname, '..') -const dist = path.join(root, 'dist') await main() async function main() { + const { source, outfile } = loadSourceAndOutput() + + await esbuild.build(getEsbuildOptions(source, outfile)) +} + +export function loadSourceAndOutput() { + const __dirname = path.dirname(fileURLToPath(import.meta.url)) + const root = path.join(__dirname, '..') + const dist = path.join(root, 'dist') const [sourceArg, targetArg] = process.argv.slice(2) const source = path.resolve(sourceArg) @@ -24,7 +29,11 @@ async function main() { const outfile = path.join(dist, targetArg) - await esbuild.build({ + return { source, outfile } +} + +export function getEsbuildOptions(source: string, outfile: string) { + return { entryPoints: [source], treeShaking: true, minifySyntax: false, @@ -41,5 +50,5 @@ async function main() { external: ['bee-queue'], outfile, plugins: [graphqlLoaderPlugin()], - }) + } as esbuild.BuildOptions } diff --git a/scripts/start.ts b/scripts/start.ts new file mode 100644 index 000000000..ac7c812fa --- /dev/null +++ b/scripts/start.ts @@ -0,0 +1,44 @@ +import { spawn, ChildProcess } from 'child_process' +import * as esbuild from 'esbuild' + +import { getEsbuildOptions, loadSourceAndOutput } from './build' + +await main() + +async function main() { + const { source, outfile } = loadSourceAndOutput() + + let serverProcess: ChildProcess | null = null + + const startServerPlugin: esbuild.Plugin = { + name: 'startServer', + setup(build) { + build.onStart(() => { + // eslint-disable-next-line no-console + console.info('\nINFO: (Re)start of process...') + }) + + build.onEnd(({ errors }) => { + if (errors.length > 0) { + // eslint-disable-next-line no-console + console.info('INFO: Process will not be (re)started due to error.') + + return + } + + if (serverProcess) serverProcess.kill() + + serverProcess = spawn('node', [outfile], { stdio: 'inherit' }) + }) + }, + } + + const { plugins = [], ...options } = getEsbuildOptions(source, outfile) + + const ctx = await esbuild.context({ + ...options, + plugins: [...plugins, startServerPlugin], + }) + + await ctx.watch({}) +} diff --git a/yarn.lock b/yarn.lock index 7cb826d7b..e08fad8f5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4105,10 +4105,7 @@ __metadata: "@types/redlock": ^4.0.7 "@types/semver": ^7.5.6 "@types/uuid": ^9.0.7 - "@zerollup/ts-transform-paths": ^1.7.18 apollo-datasource-rest: ^3.7.0 - babel-plugin-import-graphql: ^2.8.1 - babel-plugin-module-resolver: ^5.0.0 basic-auth: ^2.0.1 bee-queue: ^1.7.1 bull-arena: ^4.1.0 @@ -5204,28 +5201,6 @@ __metadata: languageName: node linkType: hard -"@zerollup/ts-helpers@npm:^1.7.18": - version: 1.7.18 - resolution: "@zerollup/ts-helpers@npm:1.7.18" - dependencies: - resolve: ^1.12.0 - peerDependencies: - typescript: ">=3.7.2" - checksum: 6ad5cc350139e28866ecff6138b38771a385b8f6c66af07bfff5f7a6d54a9071c06cdd43e0ae0e71157cce2815e6207c0ce15a28ef862d87fe2ad8381b0465dd - languageName: node - linkType: hard - -"@zerollup/ts-transform-paths@npm:^1.7.18": - version: 1.7.18 - resolution: "@zerollup/ts-transform-paths@npm:1.7.18" - dependencies: - "@zerollup/ts-helpers": ^1.7.18 - peerDependencies: - typescript: ">=3.7.2" - checksum: 2a3b258222c954e6cbcb85fdbb8fe0a8781128015951d352a42fe4b59379b7051397592c9be0dd96d15fc8c6f2916b2805cd85adff93aaa3b9346beaf144a0dd - languageName: node - linkType: hard - "@zkochan/js-yaml@npm:0.0.6": version: 0.0.6 resolution: "@zkochan/js-yaml@npm:0.0.6" @@ -6038,18 +6013,6 @@ __metadata: languageName: node linkType: hard -"babel-plugin-import-graphql@npm:^2.8.1": - version: 2.8.1 - resolution: "babel-plugin-import-graphql@npm:2.8.1" - dependencies: - graphql-tag: ^2.9.2 - peerDependencies: - graphql: ">=0.9.6" - graphql-tag: ^2.1.0 - checksum: 8e156d514c785f49df8d4934276104a48b4e6c09da70641eca1b439ae9eeff13b0a98cdfb869752762bc8719084ccdf8cc1960a3b084ca66a740ad09010ccbfa - languageName: node - linkType: hard - "babel-plugin-istanbul@npm:^6.0.0, babel-plugin-istanbul@npm:^6.1.1": version: 6.1.1 resolution: "babel-plugin-istanbul@npm:6.1.1" @@ -6097,19 +6060,6 @@ __metadata: languageName: node linkType: hard -"babel-plugin-module-resolver@npm:^5.0.0": - version: 5.0.0 - resolution: "babel-plugin-module-resolver@npm:5.0.0" - dependencies: - find-babel-config: ^2.0.0 - glob: ^8.0.3 - pkg-up: ^3.1.0 - reselect: ^4.1.7 - resolve: ^1.22.1 - checksum: d6880e49fc8e7bac509a2c183b4303ee054a47a80032a59a6f7844bb468ebe5e333b5dc5378443afdab5839e2da2b31a6c8d9a985a0047cd076b82bb9161cc78 - languageName: node - linkType: hard - "babel-plugin-polyfill-corejs2@npm:^0.3.0": version: 0.3.0 resolution: "babel-plugin-polyfill-corejs2@npm:0.3.0" @@ -9709,16 +9659,6 @@ __metadata: languageName: node linkType: hard -"find-babel-config@npm:^2.0.0": - version: 2.0.0 - resolution: "find-babel-config@npm:2.0.0" - dependencies: - json5: ^2.1.1 - path-exists: ^4.0.0 - checksum: d110308b02fe6a6411a0cfb7fd50af6740fbf5093eada3d6ddacf99b07fc8eea4aa3475356484710a0032433029a21ce733bb3ef88fda1d6e35c29a3e4983014 - languageName: node - linkType: hard - "find-cache-dir@npm:^3.3.1": version: 3.3.2 resolution: "find-cache-dir@npm:3.3.2" @@ -10379,7 +10319,7 @@ __metadata: languageName: node linkType: hard -"glob@npm:^8.0.0, glob@npm:^8.0.1, glob@npm:^8.0.3": +"glob@npm:^8.0.0, glob@npm:^8.0.1": version: 8.1.0 resolution: "glob@npm:8.1.0" dependencies: @@ -10598,7 +10538,7 @@ __metadata: languageName: node linkType: hard -"graphql-tag@npm:^2.11.0, graphql-tag@npm:^2.12.6, graphql-tag@npm:^2.9.1, graphql-tag@npm:^2.9.2": +"graphql-tag@npm:^2.11.0, graphql-tag@npm:^2.12.6, graphql-tag@npm:^2.9.1": version: 2.12.6 resolution: "graphql-tag@npm:2.12.6" dependencies: @@ -13233,7 +13173,7 @@ __metadata: languageName: node linkType: hard -"json5@npm:2.x, json5@npm:^2.1.1, json5@npm:^2.2.2, json5@npm:^2.2.3": +"json5@npm:2.x, json5@npm:^2.2.2, json5@npm:^2.2.3": version: 2.2.3 resolution: "json5@npm:2.2.3" bin: @@ -16670,15 +16610,6 @@ __metadata: languageName: node linkType: hard -"pkg-up@npm:^3.1.0": - version: 3.1.0 - resolution: "pkg-up@npm:3.1.0" - dependencies: - find-up: ^3.0.0 - checksum: 5bac346b7c7c903613c057ae3ab722f320716199d753f4a7d053d38f2b5955460f3e6ab73b4762c62fd3e947f58e04f1343e92089e7bb6091c90877406fcd8c8 - languageName: node - linkType: hard - "pkginfo@npm:^0.4.1": version: 0.4.1 resolution: "pkginfo@npm:0.4.1" @@ -17690,13 +17621,6 @@ __metadata: languageName: node linkType: hard -"reselect@npm:^4.1.7": - version: 4.1.8 - resolution: "reselect@npm:4.1.8" - checksum: a4ac87cedab198769a29be92bc221c32da76cfdad6911eda67b4d3e7136dca86208c3b210e31632eae31ebd2cded18596f0dd230d3ccc9e978df22f233b5583e - languageName: node - linkType: hard - "resolve-cwd@npm:^3.0.0": version: 3.0.0 resolution: "resolve-cwd@npm:3.0.0" @@ -17760,7 +17684,7 @@ __metadata: languageName: node linkType: hard -"resolve@npm:^1.1.6, resolve@npm:^1.10.0, resolve@npm:^1.11.0, resolve@npm:^1.12.0, resolve@npm:^1.14.2, resolve@npm:^1.17.0, resolve@npm:^1.20.0, resolve@npm:^1.22.1, resolve@npm:^1.22.3, resolve@npm:^1.22.4": +"resolve@npm:^1.1.6, resolve@npm:^1.10.0, resolve@npm:^1.11.0, resolve@npm:^1.12.0, resolve@npm:^1.14.2, resolve@npm:^1.17.0, resolve@npm:^1.20.0, resolve@npm:^1.22.3, resolve@npm:^1.22.4": version: 1.22.8 resolution: "resolve@npm:1.22.8" dependencies: @@ -17802,7 +17726,7 @@ __metadata: languageName: node linkType: hard -"resolve@patch:resolve@^1.1.6#~builtin, resolve@patch:resolve@^1.10.0#~builtin, resolve@patch:resolve@^1.11.0#~builtin, resolve@patch:resolve@^1.12.0#~builtin, resolve@patch:resolve@^1.14.2#~builtin, resolve@patch:resolve@^1.17.0#~builtin, resolve@patch:resolve@^1.20.0#~builtin, resolve@patch:resolve@^1.22.1#~builtin, resolve@patch:resolve@^1.22.3#~builtin, resolve@patch:resolve@^1.22.4#~builtin": +"resolve@patch:resolve@^1.1.6#~builtin, resolve@patch:resolve@^1.10.0#~builtin, resolve@patch:resolve@^1.11.0#~builtin, resolve@patch:resolve@^1.12.0#~builtin, resolve@patch:resolve@^1.14.2#~builtin, resolve@patch:resolve@^1.17.0#~builtin, resolve@patch:resolve@^1.20.0#~builtin, resolve@patch:resolve@^1.22.3#~builtin, resolve@patch:resolve@^1.22.4#~builtin": version: 1.22.8 resolution: "resolve@patch:resolve@npm%3A1.22.8#~builtin::version=1.22.8&hash=c3c19d" dependencies: