summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaddy <ty.carlier@gmail.com>2022-01-01 01:15:13 +1100
committerMaddy <ty.carlier@gmail.com>2022-01-01 01:15:13 +1100
commit7820f586b2129a9af03b4a62e9fcf684174ab57d (patch)
tree709b8dbfe15734e09b20f322dd7d10f10c354fbe
parentUpdated stop.ts (diff)
downloadserver-7820f586b2129a9af03b4a62e9fcf684174ab57d.tar.xz
ts-node support. debugging is slightly wonky as vscode will not allow breakpoints in modules that aren't bundle, yet.
-rw-r--r--bundle/.vscode/launch.json15
-rw-r--r--bundle/package.json2
-rw-r--r--bundle/tsconfig.json25
-rw-r--r--util/src/util/TraverseDirectory.ts5
4 files changed, 41 insertions, 6 deletions
diff --git a/bundle/.vscode/launch.json b/bundle/.vscode/launch.json
index aa4e743a..008c9821 100644
--- a/bundle/.vscode/launch.json
+++ b/bundle/.vscode/launch.json
@@ -5,6 +5,21 @@
 	"version": "0.2.0",
 	"configurations": [
 		{
+			"name": "ts-node",
+			"type": "node",
+			"request": "launch",
+			"args": [
+				"${workspaceFolder}/src/start.ts"
+			],
+			"runtimeArgs": [
+				"-r",
+				"ts-node/register"
+			],
+			"cwd": "${workspaceRoot}",
+			"protocol": "inspector",
+			"internalConsoleOptions": "openOnSessionStart"
+		},
+		{
 			"sourceMaps": true,
 			"type": "node",
 			"request": "launch",
diff --git a/bundle/package.json b/bundle/package.json
index e0ae6156..7e41ff9f 100644
--- a/bundle/package.json
+++ b/bundle/package.json
@@ -51,6 +51,7 @@
 		"ts-node": "^10.2.1",
 		"ts-node-dev": "^1.1.6",
 		"ts-patch": "^1.4.4",
+		"tsconfig-paths": "^3.12.0",
 		"typescript": "^4.2.3",
 		"typescript-json-schema": "0.50.1"
 	},
@@ -61,6 +62,7 @@
 		"@babel/preset-typescript": "^7.15.0",
 		"@fosscord/api": "file:../api",
 		"@fosscord/cdn": "file:../cdn",
+		"@fosscord/util": "file:../util",
 		"@fosscord/gateway": "file:../gateway",
 		"@sentry/node": "^6.16.1",
 		"@sentry/tracing": "^6.16.1",
diff --git a/bundle/tsconfig.json b/bundle/tsconfig.json
index 2257b4ab..ef330139 100644
--- a/bundle/tsconfig.json
+++ b/bundle/tsconfig.json
@@ -1,6 +1,21 @@
 {
 	"include": ["dist/**/*.ts"],
 	"exclude": [],
+	"ts-node": {
+		"transpileOnly": true,
+		"preferTsExts": true,
+		"compilerOptions": {
+			"rootDir": "../",
+			"baseUrl": ".",
+			"paths": {
+				"@fosscord/util": ["../util/src/index"],
+				"@fosscord/api": ["../api/src/index"],
+				"@fosscord/gateway": ["../gateway/src/index"],
+				"@fosscord/cdn": ["../cdn/src/index"]
+			},
+		},
+		"require": ["tsconfig-paths/register"]
+	},
 	"compilerOptions": {
 		/* Visit https://aka.ms/tsconfig.json to read more about this file */
 
@@ -16,7 +31,7 @@
 		// "jsx": "preserve",                     /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
 		"declaration": false /* Generates corresponding '.d.ts' file. */,
 		"declarationMap": false /* Generates a sourcemap for each corresponding '.d.ts' file. */,
-		"sourceMap": false /* Generates corresponding '.map' file. */,
+		"sourceMap": true /* Generates corresponding '.map' file. */,
 		// "outFile": "./",                       /* Concatenate and emit output to single file. */
 		"outDir": "./dist/" /* Redirect output structure to the directory. */,
 		"rootDir": "./dist/" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
@@ -74,10 +89,10 @@
 		"resolveJsonModule": true,
 		"baseUrl": "./dist/",
 		"paths": {
-			"@fosscord/api": ["api/src/index"],
-			"@fosscord/gateway": ["gateway/src/index"],
-			"@fosscord/cdn": ["cdn/src/index"],
-			"@fosscord/util": ["util/src/index"]
+			"@fosscord/api": ["api/src/index", "../../api/src/index"],
+			"@fosscord/gateway": ["gateway/src/index", "../../gateway/src/index"],
+			"@fosscord/cdn": ["cdn/src/index", "../../cdn/src/index"],
+			"@fosscord/util": ["util/src/index", "../../util/src/index"]
 		},
 		"plugins": [{ "transform": "@zerollup/ts-transform-paths" }],
 		"noEmitHelpers": true,
diff --git a/util/src/util/TraverseDirectory.ts b/util/src/util/TraverseDirectory.ts
index 275b7dcc..3d0d6279 100644
--- a/util/src/util/TraverseDirectory.ts
+++ b/util/src/util/TraverseDirectory.ts
@@ -1,6 +1,9 @@
 import { Server, traverseDirectory } from "lambert-server";
 
-const DEFAULT_FILTER = /^([^\.].*)(?<!\.d)\.(js)$/;
+//if we're using ts-node, use ts files instead of js
+const extension = Symbol.for("ts-node.register.instance") in process ? "ts" : "js"
+
+const DEFAULT_FILTER = new RegExp("^([^\.].*)(?<!\.d)\.(" + extension + ")$");
 
 export function registerRoutes(server: Server, root: string) {
 	return traverseDirectory(