From e356691b5d07157a26094d50cb3623595b275cf2 Mon Sep 17 00:00:00 2001
From: Benjamin Franzke <ben@bnf.dev>
Date: Mon, 28 Aug 2023 21:45:25 +0200
Subject: [PATCH] [TASK] Use TypeScript tsconfig include instead of exclude

This helps to prevent hard-to-discover build failures, that only
happen on clean installs (e.g. CI).
This is because TypeScript will by default scan the entire source
dictionary (Build/ in our case) for possible includes.
We previously excluded /Build/composer in #95046, but it is actually
much better to explicitly include the actually used source paths
to also exclude build output (Build/JavaScript/) from being
reinterpreted by subsequential eslint or tsc compile runs.

Note that we also refactor the types/ directory in order to
be a folder that conforms to the @types/* packages conventions,
by being actually usable in the compilerOptions.types property.

Note that our custom global type definitions (types/) were previously
implicitly loaded as globally available sourcepaths.
With the new `include` option we could add them back, but then we
wouldn't notice if we do not add proper index.d.ts files (like we
did until now). Therefore index.d.ts files are added in here.

Now, with TypeScript being "clean", we need a another small
adjustment in order for eslint to still being able to lint
our types/ folder. Therefore tsconfig.json is extended to
include the types directory. See [1] for more information on
why eslint needs that.

[1] https://typescript-eslint.io/linting/troubleshooting/#i-get-errors-telling-me-eslint-was-configured-to-run--however-that-tsconfig-does-not--none-of-those-tsconfigs-include-this-file

Resolves: #101782
Related: #95046
Releases: main, 12.4
Change-Id: I3ab8b874192d25470bbd5e71cc5d99e853259f89
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80746
Reviewed-by: Benjamin Franzke <ben@bnf.dev>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benjamin Franzke <ben@bnf.dev>
---
 Build/.eslintrc.json                                    | 2 +-
 Build/tsconfig.eslint.json                              | 7 +++++++
 Build/tsconfig.json                                     | 8 +++++---
 Build/types/{JQuery => jquery-custom}/draguploader.d.ts | 0
 Build/types/{JQuery => jquery-custom}/general.d.ts      | 0
 Build/types/jquery-custom/index.d.ts                    | 4 ++++
 Build/types/{JQuery => jquery-custom}/minicolors.d.ts   | 0
 Build/types/{JQuery => jquery-custom}/paging.d.ts       | 0
 Build/types/{tablesort.d.ts => tablesort/index.d.ts}    | 0
 9 files changed, 17 insertions(+), 4 deletions(-)
 create mode 100644 Build/tsconfig.eslint.json
 rename Build/types/{JQuery => jquery-custom}/draguploader.d.ts (100%)
 rename Build/types/{JQuery => jquery-custom}/general.d.ts (100%)
 create mode 100644 Build/types/jquery-custom/index.d.ts
 rename Build/types/{JQuery => jquery-custom}/minicolors.d.ts (100%)
 rename Build/types/{JQuery => jquery-custom}/paging.d.ts (100%)
 rename Build/types/{tablesort.d.ts => tablesort/index.d.ts} (100%)

diff --git a/Build/.eslintrc.json b/Build/.eslintrc.json
index 8a6cdb5027b6..9960ae2dd02e 100644
--- a/Build/.eslintrc.json
+++ b/Build/.eslintrc.json
@@ -6,7 +6,7 @@
   },
   "parser": "@typescript-eslint/parser",
   "parserOptions": {
-    "project": true
+    "project": ["./tsconfig.eslint.json"]
   },
   "plugins": [
     "@typescript-eslint",
diff --git a/Build/tsconfig.eslint.json b/Build/tsconfig.eslint.json
new file mode 100644
index 000000000000..94523d84a74d
--- /dev/null
+++ b/Build/tsconfig.eslint.json
@@ -0,0 +1,7 @@
+{
+    "extends": "./tsconfig.json",
+    "include": [
+        "Sources/TypeScript/**/*.ts",
+        "types/**/*.ts"
+    ]
+}
diff --git a/Build/tsconfig.json b/Build/tsconfig.json
index 9d9a640ff8d2..e2858cd18dda 100644
--- a/Build/tsconfig.json
+++ b/Build/tsconfig.json
@@ -100,17 +100,19 @@
             "d3-selection",
             "jasmine",
             "jquery",
+            "jquery-custom",
             "bootstrap",
             "nprogress",
             "requirejs",
-            "sortablejs"
+            "sortablejs",
+            "tablesort"
         ],
         "typeRoots": [
             "node_modules/@types",
             "types"
         ]
     },
-    "exclude": [
-        "composer/"
+    "include": [
+        "Sources/TypeScript/**/*.ts"
     ]
 }
diff --git a/Build/types/JQuery/draguploader.d.ts b/Build/types/jquery-custom/draguploader.d.ts
similarity index 100%
rename from Build/types/JQuery/draguploader.d.ts
rename to Build/types/jquery-custom/draguploader.d.ts
diff --git a/Build/types/JQuery/general.d.ts b/Build/types/jquery-custom/general.d.ts
similarity index 100%
rename from Build/types/JQuery/general.d.ts
rename to Build/types/jquery-custom/general.d.ts
diff --git a/Build/types/jquery-custom/index.d.ts b/Build/types/jquery-custom/index.d.ts
new file mode 100644
index 000000000000..c7413500d9c4
--- /dev/null
+++ b/Build/types/jquery-custom/index.d.ts
@@ -0,0 +1,4 @@
+import './draguploader';
+import './minicolors';
+import './general';
+import './paging';
diff --git a/Build/types/JQuery/minicolors.d.ts b/Build/types/jquery-custom/minicolors.d.ts
similarity index 100%
rename from Build/types/JQuery/minicolors.d.ts
rename to Build/types/jquery-custom/minicolors.d.ts
diff --git a/Build/types/JQuery/paging.d.ts b/Build/types/jquery-custom/paging.d.ts
similarity index 100%
rename from Build/types/JQuery/paging.d.ts
rename to Build/types/jquery-custom/paging.d.ts
diff --git a/Build/types/tablesort.d.ts b/Build/types/tablesort/index.d.ts
similarity index 100%
rename from Build/types/tablesort.d.ts
rename to Build/types/tablesort/index.d.ts
-- 
GitLab