From d8cae18332c4102389acc4f14dc13f543ca6439e Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 20 Aug 2026 17:24:26 -0400 Subject: [PATCH] Upgrade to TypeScript 6 - Adjust module and target settings to allow more flexibility for adapting ES Modules in the future - Adjust source code to new behaviour from the above change - Disable a few compiler errors for now Fixes #4486 Signed-off-by: David Thompson --- package-lock.json | 15 +++++++++------ package.json | 12 ++++++------ src/javaServerStarter.ts | 2 +- src/log.ts | 2 +- src/requirements.ts | 2 +- src/webview/globals.d.ts | 2 ++ test/lightweight-mode-suite/index.ts | 2 +- test/standard-mode-suite/extension.test.ts | 2 +- test/standard-mode-suite/index.ts | 2 +- tsconfig.base.json | 15 ++++++++++++--- tsconfig.webview.json | 1 + 11 files changed, 36 insertions(+), 21 deletions(-) create mode 100644 src/webview/globals.d.ts diff --git a/package-lock.json b/package-lock.json index 644c99f03..2e1cefd77 100644 --- a/package-lock.json +++ b/package-lock.json @@ -55,7 +55,7 @@ "sinon": "^14.0.0", "tar": "^7.5.11", "ts-loader": "^9.4.2", - "typescript": "^4.6.4", + "typescript": "^6.0.3", "typescript-eslint": "^8.65.0", "webpack": "^5.105.0", "webpack-cli": "^7.2.1" @@ -4990,9 +4990,9 @@ } }, "node_modules/typescript": { - "version": "4.9.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", - "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", + "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", "dev": true, "license": "Apache-2.0", "bin": { @@ -5000,7 +5000,7 @@ "tsserver": "bin/tsserver" }, "engines": { - "node": ">=4.2.0" + "node": ">=14.17" } }, "node_modules/typescript-eslint": { @@ -5306,6 +5306,7 @@ "version": "8.2.1-next.1", "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.2.1-next.1.tgz", "integrity": "sha512-L+DYtdUtqUXGpyMgHqer6IBKvFFhl/1ToiMmCmG85LYHuuX0jllHMz77MYt0RicakoYY+Lq1yLK6Qj3YBqgzDQ==", + "license": "MIT", "engines": { "node": ">=14.0.0" } @@ -5348,6 +5349,7 @@ "version": "3.17.6-next.1", "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.6-next.1.tgz", "integrity": "sha512-2npXUc8oe/fb9Bjcwm2HTWYZXyCbW4NTo7jkOrEciGO+/LfWbSMgqZ6PwKWgqUkgCbkPxQHNjoMqr9ol/Ehjgg==", + "license": "MIT", "dependencies": { "vscode-jsonrpc": "8.2.1-next.1", "vscode-languageserver-types": "3.17.6-next.1" @@ -5356,7 +5358,8 @@ "node_modules/vscode-languageserver-types": { "version": "3.17.6-next.1", "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.6-next.1.tgz", - "integrity": "sha512-7xVc/xLtNhKuCKX0mINT6mFUrUuRz0EinhwPGT8Gtsv2hlo+xJb5NKbiGailcWa1/T5e4dr5Pb2MfGchHreHAA==" + "integrity": "sha512-7xVc/xLtNhKuCKX0mINT6mFUrUuRz0EinhwPGT8Gtsv2hlo+xJb5NKbiGailcWa1/T5e4dr5Pb2MfGchHreHAA==", + "license": "MIT" }, "node_modules/vscode-variables": { "version": "1.0.1", diff --git a/package.json b/package.json index fff1f8de0..5e0a6f3d7 100644 --- a/package.json +++ b/package.json @@ -1333,11 +1333,11 @@ "default": false, "scope": "window" }, - "java.codeGeneration.generateCommentsInMarkdown": { - "type": "boolean", - "description": "Generate Javadoc comments in Markdown style (requires source compliance >= 23).", - "default": false - }, + "java.codeGeneration.generateCommentsInMarkdown": { + "type": "boolean", + "description": "Generate Javadoc comments in Markdown style (requires source compliance >= 23).", + "default": false + }, "java.codeGeneration.toString.template": { "type": "string", "description": "The template for generating the toString method.", @@ -2175,7 +2175,7 @@ "sinon": "^14.0.0", "tar": "^7.5.11", "ts-loader": "^9.4.2", - "typescript": "^4.6.4", + "typescript": "^6.0.3", "typescript-eslint": "^8.65.0", "webpack": "^5.105.0", "webpack-cli": "^7.2.1" diff --git a/src/javaServerStarter.ts b/src/javaServerStarter.ts index 9b566f372..00da6400b 100644 --- a/src/javaServerStarter.ts +++ b/src/javaServerStarter.ts @@ -128,7 +128,7 @@ export function getUnicodeLocaleEnv(): { [key: string]: string } { return env; } -export function awaitServerConnection(port): Thenable { +export function awaitServerConnection(port): Promise { const addr = parseInt(port); return new Promise((res, rej) => { const server = net.createServer(stream => { diff --git a/src/log.ts b/src/log.ts index ce340c3d9..30ffea336 100644 --- a/src/log.ts +++ b/src/log.ts @@ -1,5 +1,5 @@ import { createLogger, format, transports } from 'winston'; -import * as DailyRotateFile from 'winston-daily-rotate-file'; +import DailyRotateFile from 'winston-daily-rotate-file'; export function initializeLogFile(filename: string) { logger.add(new DailyRotateFile({ diff --git a/src/requirements.ts b/src/requirements.ts index cedb881ba..11c6015f7 100644 --- a/src/requirements.ts +++ b/src/requirements.ts @@ -1,6 +1,6 @@ 'use strict'; -import * as expandHomeDir from 'expand-home-dir'; +import expandHomeDir from 'expand-home-dir'; import * as fse from 'fs-extra'; import { getRuntime, getSources, JAVAC_FILENAME, JAVA_FILENAME } from 'jdk-utils'; import * as path from 'path'; diff --git a/src/webview/globals.d.ts b/src/webview/globals.d.ts new file mode 100644 index 000000000..8f5aed92b --- /dev/null +++ b/src/webview/globals.d.ts @@ -0,0 +1,2 @@ +/* silence warnings from typescript about not being able to analyse sideeffects of css imports */ +declare module "*.css" {} diff --git a/test/lightweight-mode-suite/index.ts b/test/lightweight-mode-suite/index.ts index a32edaa0c..d2c47a239 100644 --- a/test/lightweight-mode-suite/index.ts +++ b/test/lightweight-mode-suite/index.ts @@ -11,7 +11,7 @@ // a possible error to the callback or null if none. import * as path from 'path'; -import * as Mocha from 'mocha'; +import Mocha from 'mocha'; import { glob } from 'glob'; export async function run(testsRoot: string): Promise { diff --git a/test/standard-mode-suite/extension.test.ts b/test/standard-mode-suite/extension.test.ts index aee1a1d02..9b5371122 100644 --- a/test/standard-mode-suite/extension.test.ts +++ b/test/standard-mode-suite/extension.test.ts @@ -1,4 +1,4 @@ -import * as assert from 'assert'; +import assert from 'assert'; import * as fs from 'fs'; import * as path from 'path'; import { env } from 'process'; diff --git a/test/standard-mode-suite/index.ts b/test/standard-mode-suite/index.ts index 479c5eedf..dd0c0cc2c 100644 --- a/test/standard-mode-suite/index.ts +++ b/test/standard-mode-suite/index.ts @@ -11,7 +11,7 @@ // a possible error to the callback or null if none. import * as path from 'path'; -import * as Mocha from 'mocha'; +import Mocha from 'mocha'; import { glob } from 'glob'; export async function run(testsRoot: string): Promise { diff --git a/tsconfig.base.json b/tsconfig.base.json index 17c7bc77a..5efffd8b4 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1,14 +1,23 @@ { "compilerOptions": { - "target": "es6", - "moduleResolution": "node", + + "target": "es2020", + "module": "nodenext", + "moduleResolution": "bundler", + "outDir": "out", "sourceMap": true, "skipLibCheck": true, + "strictFunctionTypes": false, + "strictNullChecks": false, + "noImplicitAny": false, + "noImplicitThis": false, + "useUnknownInCatchVariables": false, "plugins": [ { "name": "eslint" } ], - } + "types": ["node", "vscode", "mocha"] + }, } diff --git a/tsconfig.webview.json b/tsconfig.webview.json index 0c78cb638..b8a2bd5ea 100644 --- a/tsconfig.webview.json +++ b/tsconfig.webview.json @@ -9,6 +9,7 @@ "jsx": "react-jsx", "esModuleInterop": true, "allowSyntheticDefaultImports": true, + "rootDir": "./src" }, "include": [ "src/webview",