Skip to content
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

chore: switch to esbuild #1840

Merged
merged 5 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
run: |
corepack enable pnpm
pnpm install
pnpm run build
pnpm test
- name: Codecov
if: ${{ always() }}
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ build
*.tar
packages/**/*.js
package-lock.json

# Sentry Config File
.env.sentry-build-plugin

# Sentry Config File
.env.sentry-build-plugin
meta.json
1 change: 1 addition & 0 deletions apps/main/server.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
5 changes: 1 addition & 4 deletions apps/main/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

import Sentry from "@sentry/node";
import { nodeProfilingIntegration } from "@sentry/profiling-node";
import {
ServerLoggerLevels,
getServerLogger,
} from "../../packages/shared/log.js";
import { getServerLogger } from "../../packages/shared/log.js";
import { verifyLegacyCipherSupport } from "../../packages/gateway/src/encryption.js";
import { getServerConfiguration } from "../../packages/shared/Configuration.js";
import { getGatewayServer } from "../../packages/gateway/src/GatewayServer.js";
Expand Down
76 changes: 76 additions & 0 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { sentryEsbuildPlugin } from "@sentry/esbuild-plugin";
import fs from "node:fs";
import esbuild from "esbuild";
import { createRequire } from "node:module";

const require = createRequire(import.meta.url);

const nativeNodeModulesPlugin = {
name: "native-node-modules",
setup(build) {
// If a ".node" file is imported within a module in the "file" namespace, resolve
// it to an absolute path and put it into the "node-file" virtual namespace.
build.onResolve({ filter: /\.node$/, namespace: "file" }, (args) => ({
path: require.resolve(args.path, { paths: [args.resolveDir] }),
namespace: "node-file",
}));

// Files in the "node-file" virtual namespace call "require()" on the
// path from esbuild of the ".node" file in the output directory.
build.onLoad({ filter: /.*/, namespace: "node-file" }, (args) => ({
contents: `
import path from ${JSON.stringify(args.path)}
try { module.exports = require(path) }
catch {}
`,
}));

// If a ".node" file is imported within a module in the "node-file" namespace, put
// it in the "file" namespace where esbuild's default loading behavior will handle
// it. It is already an absolute path since we resolved it to one above.
build.onResolve(
{ filter: /\.node$/, namespace: "node-file" },
(args) => ({
path: args.path,
namespace: "file",
}),
);

// Tell esbuild's default loading behavior to use the "file" loader for
// these ".node" files.
let opts = build.initialOptions;
opts.loader = opts.loader || {};
opts.loader[".node"] = "file";
},
};

esbuild
.build({
sourcemap: "external", // Source map generation must be turned on
platform: "node",
outdir: "dist",
entryPoints: ["apps/main/server.ts"],
format: "esm",
metafile: true,
bundle: true,
packages: "external",
banner: {
js: "import * as path from 'node:path';import { createRequire } from 'module';import { fileURLToPath } from 'node:url';const require = createRequire(import.meta.url);const __dirname = path.dirname(fileURLToPath(import.meta.url));",
},
plugins: [
nativeNodeModulesPlugin,
// Put the Sentry esbuild plugin after all other plugins
sentryEsbuildPlugin({
authToken: process.env.SENTRY_AUTH_TOKEN,
org: "drazisilcom",
project: "rusty-motors-server",
}),
],
})
.then((result) => {
fs.writeFileSync("meta.json", JSON.stringify(result.metafile));
})
.catch((e) => {
console.error(e);
process.exit(1);
});
80 changes: 41 additions & 39 deletions docs/technical/domains.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
# Domains

* Web
* Network
* Account
* Login
* Persona
* Lobby
* Database
- Web
- Network
- Account
- Login
- Persona
- Lobby
- Database

## Web

The web service is an HTTP/HTTPS server that provides the following external endpoints:

* A binary response to the GET patch URL
* A binary response to the GET update URL
* A POST receive of a username and password using HTTPS which returns a Ticket code if valid, and an error if not
* A response to the GET shardlist URL
- A binary response to the GET patch URL
- A binary response to the GET update URL
- A POST receive of a username and password using HTTPS which returns a Ticket code if valid, and an error if not
- A response to the GET shardlist URL

### AuthLogin

Accept a username and password via HTTPS and requestions from the Account service if the login is valid.

Has the following service relationships:

* Account OUTBOUND (username, password)
* Account INBOUND (isUserValid)
- Account OUTBOUND (username, password)
- Account INBOUND (isUserValid)

### Shard

The shard service responds to a GET call and requests a list of online lobby servers (shards) from the Lobby service.

Has the following service relationships:

* Lobby OUTBOUND
* Lobby INBOUND (shardList)
- Lobby OUTBOUND
- Lobby INBOUND (shardList)

## Network

The Network service handles all inbound and outbound non-HTTP TCP traffic between the server and clients. It has the following subdomains:

* Socket Receive
* Socket Send
* Session Control
* Interservice Transfer
- Socket Receive
- Socket Send
- Session Control
- Interservice Transfer

### Socket receive

Expand All @@ -52,41 +54,41 @@ After the downstream domain finishes with the data, it returns any responses to

Has the following service relationships:

* Session Control OUTBOUND (socketId, remoteAddress, localPort)
* Session Control INBOUND {socketId, SessionId}
* Interservice Transfer OUTBOUND (sessionId, dataBuffer)
- Session Control OUTBOUND (socketId, remoteAddress, localPort)
- Session Control INBOUND {socketId, SessionId}
- Interservice Transfer OUTBOUND (sessionId, dataBuffer)

### Socket Send

Has the following service relationships:

* Interservice Transfer INBOUND (sessionId, dataBuffer)
* Session Control OUTBOUND (sessionId)
* Session Control INBOUND (sessionId, socketId)
- Interservice Transfer INBOUND (sessionId, dataBuffer)
- Session Control OUTBOUND (sessionId)
- Session Control INBOUND (sessionId, socketId)

### Session Control

Has the following service relationships:

* Socket Receive INBOUND (socketId, remoteAddress, localPort)
* Socket Receive OUTBOUND (socketId, sessionId)
* Socket Send INBOUND (sessionId)
* Socket Send OUTBOUND (sessionId, socketId)
- Socket Receive INBOUND (socketId, remoteAddress, localPort)
- Socket Receive OUTBOUND (socketId, sessionId)
- Socket Send INBOUND (sessionId)
- Socket Send OUTBOUND (sessionId, socketId)

### Interservice Transfer

Has the following service relationships:

* Socket Receive INBOUND (sessionId, dataBuffer)
* Socket Send OUTBOUND (sessionId, dataBuffer)
* Login OUTBOUND (sessionId, dataBuffer)
* Login INBOUND (sessionId, dataBuffer)
* Persona OUTBOUND (sessionId, dataBuffer)
* Persona INBOUND (sessionId, dataBuffer)
* Lobby OUTBOUND (sessionId, dataBuffer)
* Lobby INBOUND (sessionId, dataBuffer)
* Database OUTBOUND (sessionId, dataBuffer)
* Database INBOUND (sessionId, dataBuffer)
- Socket Receive INBOUND (sessionId, dataBuffer)
- Socket Send OUTBOUND (sessionId, dataBuffer)
- Login OUTBOUND (sessionId, dataBuffer)
- Login INBOUND (sessionId, dataBuffer)
- Persona OUTBOUND (sessionId, dataBuffer)
- Persona INBOUND (sessionId, dataBuffer)
- Lobby OUTBOUND (sessionId, dataBuffer)
- Lobby INBOUND (sessionId, dataBuffer)
- Database OUTBOUND (sessionId, dataBuffer)
- Database INBOUND (sessionId, dataBuffer)

## Account

Expand Down
29 changes: 23 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
"name": "rusty-motors",
"version": "1.0.1",
"description": "This is a game server, being written from scratch, for a very old and long dead game. The owners of said game have shown no interest in bringing it back, but even so all names of their IP have been avoided to prevent issues.",
"main": "index.js",
"type": "module",
"exports": {
".": "./dist/index.js"
},
"scripts": {
"test": "tsc && eslint --fix . && prettier --write . && node --openssl-legacy-provider node_modules/vitest/vitest.mjs run --coverage packages thebeast",
"start": "pnpm --filter @rustymotors/server start"
"lint": "tsc",
"build": "node build.mjs",
"start": "node --openssl-legacy-provider --env-file=.env dist/server.js",
"dev:rsc": "tsc --watch --preserveWatchOutput",
"dev:node": "node --watch dist/apps/main/server.js",
"dev:esbuild": "pnpm run build --watch",
"dev": "run-p dev:*",
"test": "eslint --fix . && prettier --write . && node --openssl-legacy-provider node_modules/vitest/vitest.mjs run --coverage packages thebeast"
},
"author": "Molly Crendraven <drazi@duck.com>",
"license": "AGPL-3.0",
Expand All @@ -16,24 +24,33 @@
"url": "git@github.com:drazisil/mcos.git"
},
"devDependencies": {
"@sentry/node": "^7.108.0",
"@sentry/profiling-node": "^7.108.0",
"@slonik/migrator": "0.12.0",
"@types/node": "20.11.30",
"@vitest/coverage-v8": "1.4.0",
"esbuild": "^0.20.2",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.1.3",
"npm-run-all": "^4.1.5",
"prettier": "3.2.5",
"typescript": "5.4.3",
"vitest": "1.4.0"
},
"dependencies": {
"@fastify/sensible": "^5.5.0",
"@rustymotors/database": "workspace:^",
"@rustymotors/shared": "workspace:^",
"@rustymotors/shared-packets": "workspace:^",
"@sentry/node": "^7.102.0",
"@sentry/profiling-node": "^7.104.0",
"@sentry/esbuild-plugin": "^2.16.0",
"fastify": "^4.25.2",
"pino": "^8.18.0",
"pino-pretty": "^11.0.0",
"short-unique-id": "^5.0.3",
"slonik": "37",
"tsx": "^4.7.1"
"tsx": "^4.7.1",
"zod": "^3.22.4"
},
"packageManager": "pnpm@8.15.5"
}
31 changes: 31 additions & 0 deletions packages/cli/ConsoleThread.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { SubThread } from "../shared/index.js";
import { Gateway } from "../gateway/src/GatewayServer.js";
import type { TServerLogger } from "../shared/index.js";
/**
* @module ConsoleThread
*/
/**
* Console thread
*/
export declare class ConsoleThread extends SubThread {
parentThread: Gateway;
/**
* @param {object} options
* @param {Gateway} options.parentThread The parent thread
* @param {ServerLogger} options.log The logger
*/
constructor({
parentThread,
log,
}: {
parentThread: Gateway;
log: TServerLogger;
});
/** @param {import("../interfaces/index.js").KeypressEvent} key */
handleKeypressEvent(
key: import("../interfaces/index.js").KeypressEvent,
): void;
init(): void;
run(): void;
stop(): void;
}
5 changes: 1 addition & 4 deletions packages/cli/ConsoleThread.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { emitKeypressEvents } from "node:readline";
import { SubThread } from "@rustymotors/shared";
// eslint-disable-next-line no-unused-vars
import { SubThread, type TServerLogger } from "../shared";

Check failure on line 2 in packages/cli/ConsoleThread.ts

View check run for this annotation

Trunk.io / Trunk Check

eslint

[new] Parsing error: Unexpected token TServerLogger
import { Gateway } from "../gateway/src/GatewayServer.js";

import type { TServerLogger } from "@rustymotors/shared";

/**
* @module ConsoleThread
*/
Expand Down
Loading