From c3d78a8cb87c472cb663a710334c92cf055117f5 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 26 Aug 2023 16:23:24 +0200 Subject: [PATCH 1/3] Organise TSConfig files using inheritance Removed duplicated TSConfig options by using a shared base config which all plugins inherit shared settings from. --- packages/controller/tsconfig.json | 20 +++++--------------- packages/ctl/tsconfig.json | 22 +++++----------------- packages/host/tsconfig.json | 22 +++++----------------- packages/lib/build_mod.d.ts | 10 ++++++++++ packages/lib/tsconfig.json | 22 ++++++---------------- plugins/global_chat/tsconfig.json | 12 ++---------- plugins/inventory_sync/tsconfig.json | 13 ++----------- plugins/player_auth/tsconfig.json | 12 ++---------- plugins/research_sync/tsconfig.json | 12 ++---------- plugins/statistics_exporter/tsconfig.json | 12 ++---------- plugins/subspace_storage/tsconfig.json | 12 ++---------- tsconfig.base.json | 12 ++++++++++++ tsconfig.node.json | 12 ++++++++++++ 13 files changed, 67 insertions(+), 126 deletions(-) create mode 100644 packages/lib/build_mod.d.ts create mode 100644 tsconfig.base.json create mode 100644 tsconfig.node.json diff --git a/packages/controller/tsconfig.json b/packages/controller/tsconfig.json index a0c4cf46..58902a7a 100644 --- a/packages/controller/tsconfig.json +++ b/packages/controller/tsconfig.json @@ -1,17 +1,7 @@ { - "include": ["controller.ts", "package.json", "src/**/*.ts"], - "compilerOptions": { - "lib": ["es2023"], - "module": "commonjs", - "target": "es2022", - "rootDir": ".", - "outDir": "dist/controller", - "composite": true, - "sourceMap": true, - "strict": true, - "alwaysStrict": true, - "esModuleInterop": true, - "skipLibCheck": true, - "resolveJsonModule": true - } + "extends": "../../tsconfig.node.json", + "include": ["controller.ts", "package.json", "src/**/*.ts"], + "compilerOptions": { + "outDir": "dist/controller", + }, } diff --git a/packages/ctl/tsconfig.json b/packages/ctl/tsconfig.json index b3104ba5..eccb6bdc 100644 --- a/packages/ctl/tsconfig.json +++ b/packages/ctl/tsconfig.json @@ -1,19 +1,7 @@ { - "include": ["package.json", "ctl.ts", "src/**/*.ts"], - "compilerOptions": { - "lib": ["es2023"], - "module": "commonjs", - "target": "es2022", - "rootDir": ".", - "outDir": "dist", - "composite": true, - "sourceMap": true, - "strict": true, - "alwaysStrict": true, - "allowJs": true, - "checkJs": false, - "resolveJsonModule": true, - "esModuleInterop": true, - "skipLibCheck": true - } + "extends": "../../tsconfig.node.json", + "include": ["package.json", "ctl.ts", "src/**/*.ts"], + "compilerOptions": { + "outDir": "dist", + }, } diff --git a/packages/host/tsconfig.json b/packages/host/tsconfig.json index 0d450dbb..a7c73ecc 100644 --- a/packages/host/tsconfig.json +++ b/packages/host/tsconfig.json @@ -1,19 +1,7 @@ { - "include": ["host.ts", "package.json", "src/**/*.ts", "src/**/*.js"], - "compilerOptions": { - "lib": ["es2023"], - "module": "commonjs", - "target": "es2022", - "rootDir": ".", - "outDir": "dist", - "composite": true, - "sourceMap": true, - "strict": true, - "alwaysStrict": true, - "allowJs": true, - "checkJs": false, - "resolveJsonModule": true, - "esModuleInterop": true, - "skipLibCheck": true - } + "extends": "../../tsconfig.node.json", + "include": ["host.ts", "package.json", "src/**/*.ts", "src/**/*.js"], + "compilerOptions": { + "outDir": "dist", + }, } diff --git a/packages/lib/build_mod.d.ts b/packages/lib/build_mod.d.ts new file mode 100644 index 00000000..064d7e81 --- /dev/null +++ b/packages/lib/build_mod.d.ts @@ -0,0 +1,10 @@ +export interface BuildArgs { + factorioVersion?: string; + dependencies?: Record; + clean?: boolean; + pack?: boolean; + build?: boolean; + outputDir: string; + sourceDir: string; +}; +export function build(args: BuildArgs): Promise; diff --git a/packages/lib/tsconfig.json b/packages/lib/tsconfig.json index f4ae38e6..e64350e1 100644 --- a/packages/lib/tsconfig.json +++ b/packages/lib/tsconfig.json @@ -1,18 +1,8 @@ { - "include": ["index.ts", "build_mod.js", "src/**/*.ts", "src/**/*.js"], - "compilerOptions": { - "lib": ["es2023"], - "module": "commonjs", - "target": "es2022", - "rootDir": ".", - "outDir": "dist", - "composite": true, - "sourceMap": true, - "strict": true, - "alwaysStrict": true, - "allowJs": true, - "checkJs": false, - "esModuleInterop": true, - "skipLibCheck": true - } + "extends": "../../tsconfig.node.json", + "include": ["index.ts", "build_mod.js", "src/**/*.ts", "src/**/*.js"], + "compilerOptions": { + "outDir": "dist", + "allowJs": true, + }, } diff --git a/plugins/global_chat/tsconfig.json b/plugins/global_chat/tsconfig.json index 5408f6b2..d930730d 100644 --- a/plugins/global_chat/tsconfig.json +++ b/plugins/global_chat/tsconfig.json @@ -1,16 +1,8 @@ { + "extends": "../../tsconfig.node.json", "include": ["./**/*.ts"], "exclude": ["test/*", "./dist/*"], "compilerOptions": { - "lib": ["es2023"], - "module": "commonjs", - "target": "es2022", - "rootDir": ".", "outDir": "dist/plugin", - "sourceMap": true, - "strict": true, - "alwaysStrict": true, - "esModuleInterop": true, - "skipLibCheck": true - } + }, } diff --git a/plugins/inventory_sync/tsconfig.json b/plugins/inventory_sync/tsconfig.json index cf0cf5e6..d930730d 100644 --- a/plugins/inventory_sync/tsconfig.json +++ b/plugins/inventory_sync/tsconfig.json @@ -1,17 +1,8 @@ { + "extends": "../../tsconfig.node.json", "include": ["./**/*.ts"], "exclude": ["test/*", "./dist/*"], "compilerOptions": { - "lib": ["es2023"], - "module": "commonjs", - "target": "es2022", - "rootDir": ".", "outDir": "dist/plugin", - "sourceMap": true, - "strict": true, - "alwaysStrict": true, - "esModuleInterop": true, - "resolveJsonModule": true, - "skipLibCheck": true - } + }, } diff --git a/plugins/player_auth/tsconfig.json b/plugins/player_auth/tsconfig.json index 5408f6b2..d930730d 100644 --- a/plugins/player_auth/tsconfig.json +++ b/plugins/player_auth/tsconfig.json @@ -1,16 +1,8 @@ { + "extends": "../../tsconfig.node.json", "include": ["./**/*.ts"], "exclude": ["test/*", "./dist/*"], "compilerOptions": { - "lib": ["es2023"], - "module": "commonjs", - "target": "es2022", - "rootDir": ".", "outDir": "dist/plugin", - "sourceMap": true, - "strict": true, - "alwaysStrict": true, - "esModuleInterop": true, - "skipLibCheck": true - } + }, } diff --git a/plugins/research_sync/tsconfig.json b/plugins/research_sync/tsconfig.json index 5408f6b2..d930730d 100644 --- a/plugins/research_sync/tsconfig.json +++ b/plugins/research_sync/tsconfig.json @@ -1,16 +1,8 @@ { + "extends": "../../tsconfig.node.json", "include": ["./**/*.ts"], "exclude": ["test/*", "./dist/*"], "compilerOptions": { - "lib": ["es2023"], - "module": "commonjs", - "target": "es2022", - "rootDir": ".", "outDir": "dist/plugin", - "sourceMap": true, - "strict": true, - "alwaysStrict": true, - "esModuleInterop": true, - "skipLibCheck": true - } + }, } diff --git a/plugins/statistics_exporter/tsconfig.json b/plugins/statistics_exporter/tsconfig.json index 5408f6b2..d930730d 100644 --- a/plugins/statistics_exporter/tsconfig.json +++ b/plugins/statistics_exporter/tsconfig.json @@ -1,16 +1,8 @@ { + "extends": "../../tsconfig.node.json", "include": ["./**/*.ts"], "exclude": ["test/*", "./dist/*"], "compilerOptions": { - "lib": ["es2023"], - "module": "commonjs", - "target": "es2022", - "rootDir": ".", "outDir": "dist/plugin", - "sourceMap": true, - "strict": true, - "alwaysStrict": true, - "esModuleInterop": true, - "skipLibCheck": true - } + }, } diff --git a/plugins/subspace_storage/tsconfig.json b/plugins/subspace_storage/tsconfig.json index 5408f6b2..d930730d 100644 --- a/plugins/subspace_storage/tsconfig.json +++ b/plugins/subspace_storage/tsconfig.json @@ -1,16 +1,8 @@ { + "extends": "../../tsconfig.node.json", "include": ["./**/*.ts"], "exclude": ["test/*", "./dist/*"], "compilerOptions": { - "lib": ["es2023"], - "module": "commonjs", - "target": "es2022", - "rootDir": ".", "outDir": "dist/plugin", - "sourceMap": true, - "strict": true, - "alwaysStrict": true, - "esModuleInterop": true, - "skipLibCheck": true - } + }, } diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 00000000..02016d99 --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "composite": true, + "declaration": true, + "declarationMap": true, + "incremental": true, + "sourceMap": true, + "strict": true, + "resolveJsonModule": true, + "skipLibCheck": true, + }, +} diff --git a/tsconfig.node.json b/tsconfig.node.json new file mode 100644 index 00000000..daa42608 --- /dev/null +++ b/tsconfig.node.json @@ -0,0 +1,12 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "lib": ["es2023"], + "module": "node16", + "moduleResolution": "node16", + "target": "es2022", + "esModuleInterop": true, + "alwaysStrict": true, + "forceConsistentCasingInFileNames": true, + }, +} From 425daac6b6a0fc94cb1ac4bff94a74c5d34505fc Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 26 Aug 2023 16:36:29 +0200 Subject: [PATCH 2/3] Set up references in TSConfig Link the projects together properly so that builds don't use out of date files and editor "go to definition" function give the right file. --- package.json | 3 ++- packages/controller/tsconfig.json | 3 +++ packages/ctl/tsconfig.json | 3 +++ packages/host/tsconfig.json | 3 +++ plugins/global_chat/tsconfig.json | 3 +++ plugins/inventory_sync/tsconfig.json | 3 +++ plugins/player_auth/tsconfig.json | 3 +++ plugins/research_sync/tsconfig.json | 3 +++ plugins/statistics_exporter/tsconfig.json | 3 +++ plugins/subspace_storage/tsconfig.json | 3 +++ tsconfig.json | 15 +++++++++++++++ 11 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tsconfig.json diff --git a/package.json b/package.json index 7ff3a61b..d33c61a0 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "mocha": "^10.2.0", "nyc": "^15.1.0", "phin": "^3.7.0", - "typedoc": "^0.24.8" + "typedoc": "^0.24.8", + "typescript": "^5.1.6" } } diff --git a/packages/controller/tsconfig.json b/packages/controller/tsconfig.json index 58902a7a..b123e16d 100644 --- a/packages/controller/tsconfig.json +++ b/packages/controller/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../tsconfig.node.json", + "references": [ + { "path": "../lib" }, + ], "include": ["controller.ts", "package.json", "src/**/*.ts"], "compilerOptions": { "outDir": "dist/controller", diff --git a/packages/ctl/tsconfig.json b/packages/ctl/tsconfig.json index eccb6bdc..396154b5 100644 --- a/packages/ctl/tsconfig.json +++ b/packages/ctl/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../tsconfig.node.json", + "references": [ + { "path": "../lib" }, + ], "include": ["package.json", "ctl.ts", "src/**/*.ts"], "compilerOptions": { "outDir": "dist", diff --git a/packages/host/tsconfig.json b/packages/host/tsconfig.json index a7c73ecc..1ad44b08 100644 --- a/packages/host/tsconfig.json +++ b/packages/host/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../tsconfig.node.json", + "references": [ + { "path": "../lib" }, + ], "include": ["host.ts", "package.json", "src/**/*.ts", "src/**/*.js"], "compilerOptions": { "outDir": "dist", diff --git a/plugins/global_chat/tsconfig.json b/plugins/global_chat/tsconfig.json index d930730d..087576d6 100644 --- a/plugins/global_chat/tsconfig.json +++ b/plugins/global_chat/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../tsconfig.node.json", + "references": [ + { "path": "../../packages/lib" }, + ], "include": ["./**/*.ts"], "exclude": ["test/*", "./dist/*"], "compilerOptions": { diff --git a/plugins/inventory_sync/tsconfig.json b/plugins/inventory_sync/tsconfig.json index d930730d..087576d6 100644 --- a/plugins/inventory_sync/tsconfig.json +++ b/plugins/inventory_sync/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../tsconfig.node.json", + "references": [ + { "path": "../../packages/lib" }, + ], "include": ["./**/*.ts"], "exclude": ["test/*", "./dist/*"], "compilerOptions": { diff --git a/plugins/player_auth/tsconfig.json b/plugins/player_auth/tsconfig.json index d930730d..087576d6 100644 --- a/plugins/player_auth/tsconfig.json +++ b/plugins/player_auth/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../tsconfig.node.json", + "references": [ + { "path": "../../packages/lib" }, + ], "include": ["./**/*.ts"], "exclude": ["test/*", "./dist/*"], "compilerOptions": { diff --git a/plugins/research_sync/tsconfig.json b/plugins/research_sync/tsconfig.json index d930730d..087576d6 100644 --- a/plugins/research_sync/tsconfig.json +++ b/plugins/research_sync/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../tsconfig.node.json", + "references": [ + { "path": "../../packages/lib" }, + ], "include": ["./**/*.ts"], "exclude": ["test/*", "./dist/*"], "compilerOptions": { diff --git a/plugins/statistics_exporter/tsconfig.json b/plugins/statistics_exporter/tsconfig.json index d930730d..087576d6 100644 --- a/plugins/statistics_exporter/tsconfig.json +++ b/plugins/statistics_exporter/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../tsconfig.node.json", + "references": [ + { "path": "../../packages/lib" }, + ], "include": ["./**/*.ts"], "exclude": ["test/*", "./dist/*"], "compilerOptions": { diff --git a/plugins/subspace_storage/tsconfig.json b/plugins/subspace_storage/tsconfig.json index d930730d..087576d6 100644 --- a/plugins/subspace_storage/tsconfig.json +++ b/plugins/subspace_storage/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../tsconfig.node.json", + "references": [ + { "path": "../../packages/lib" }, + ], "include": ["./**/*.ts"], "exclude": ["test/*", "./dist/*"], "compilerOptions": { diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..ac1e9fe0 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,15 @@ +{ + "files": [], + "references": [ + { "path": "./packages/lib" }, + { "path": "./packages/controller" }, + { "path": "./packages/host" }, + { "path": "./packages/ctl" }, + { "path": "./plugins/global_chat" }, + { "path": "./plugins/inventory_sync" }, + { "path": "./plugins/player_auth" }, + { "path": "./plugins/research_sync" }, + { "path": "./plugins/statistics_exporter" }, + { "path": "./plugins/subspace_storage" }, + ], +} From 55da66234498938ed4442f07147f7914f68e45a1 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 26 Aug 2023 16:56:15 +0200 Subject: [PATCH 3/3] Rebuild TypeScript files on test Prevent testing the wrong files by making sure the TypeScript build is up to date before running the tests. --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d33c61a0..dc107cc8 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,8 @@ "name": "root", "private": true, "scripts": { - "test": "mocha --check-leaks -R spec --recursive test \"plugins/*/test/**\"", + "build": "tsc --build", + "test": "pnpm run build && mocha --check-leaks -R spec --recursive test \"plugins/*/test/**\"", "fast-test": "FAST_TEST=y pnpm test", "cover": "nyc pnpm test", "fast-cover": "FAST_TEST=y nyc pnpm test",