From c0a08d7f14581fe9ee20585349431758f50d4930 Mon Sep 17 00:00:00 2001 From: Sandor Trombitas Date: Mon, 9 Sep 2024 11:23:47 +0300 Subject: [PATCH] chore: upgrade to typescript 5 --- package-lock.json | 106 ++++++++++++++++++++++++--------- package.json | 5 +- src/cli/commands/test/index.ts | 12 ++++ src/cli/main.ts | 2 +- 4 files changed, 96 insertions(+), 29 deletions(-) diff --git a/package-lock.json b/package-lock.json index 332c149ede..2c7a24214f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -91,7 +91,9 @@ "snyk": "bin/snyk" }, "devDependencies": { + "@types/abbrev": "^1.1.5", "@types/body-parser": "^1.19.1", + "@types/chalk": "^2.2.0", "@types/cross-spawn": "^6.0.2", "@types/express": "^4.17.13", "@types/fs-extra": "^9.0.11", @@ -132,7 +134,7 @@ "ts-jest": "29.1.2", "ts-loader": "^9.5.1", "ts-node": "^10.9.2", - "typescript": "^4.9.5", + "typescript": "^5.5.0", "vscode-jsonrpc": "8.1.0", "webpack": "^5.54.0", "webpack-cli": "^4.6.0", @@ -4540,6 +4542,12 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/@types/abbrev": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/@types/abbrev/-/abbrev-1.1.5.tgz", + "integrity": "sha512-rMBwLuLcasbyx7whHiLrz28rX74ATmImbzJUNUNvcUbz0N+zbIUOA2EgPJakp2gtCkVRp12tDIJ7tpj0bQtdjQ==", + "dev": true + }, "node_modules/@types/babel__core": { "version": "7.20.5", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz", @@ -4642,6 +4650,16 @@ "@types/responselike": "*" } }, + "node_modules/@types/chalk": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@types/chalk/-/chalk-2.2.0.tgz", + "integrity": "sha512-1zzPV9FDe1I/WHhRkf9SNgqtRJWZqrBWgu7JGveuHmmyR9CnAPCie2N/x+iHrgnpYBIcCJWHBoMRv2TRWktsvw==", + "deprecated": "This is a stub types definition for chalk (https://github.com/chalk/chalk). chalk provides its own type definitions, so you don't need @types/chalk installed!", + "dev": true, + "dependencies": { + "chalk": "*" + } + }, "node_modules/@types/connect": { "version": "3.4.35", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.35.tgz", @@ -22963,19 +22981,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/tshy/node_modules/typescript": { - "version": "5.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", - "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", - "dev": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=14.17" - } - }, "node_modules/tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", @@ -23072,15 +23077,16 @@ } }, "node_modules/typescript": { - "version": "4.9.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", - "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", + "version": "5.5.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", + "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { - "node": ">=4.2.0" + "node": ">=14.17" } }, "node_modules/uglify-js": { @@ -24213,6 +24219,18 @@ "undici-types": "~5.26.4" } }, + "packages/cli-alert/node_modules/typescript": { + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + }, "packages/iac-cli-alert": { "name": "@snyk/iac-cli-alert", "version": "1.0.0", @@ -24235,6 +24253,19 @@ "undici-types": "~5.26.4" } }, + "packages/iac-cli-alert/node_modules/typescript": { + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + }, "packages/snyk-fix": { "name": "@snyk/fix", "version": "1.0.0-monorepo", @@ -26414,6 +26445,11 @@ "requires": { "undici-types": "~5.26.4" } + }, + "typescript": { + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==" } } }, @@ -26796,6 +26832,12 @@ "requires": { "undici-types": "~5.26.4" } + }, + "typescript": { + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", + "dev": true } } }, @@ -27746,6 +27788,12 @@ } } }, + "@types/abbrev": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/@types/abbrev/-/abbrev-1.1.5.tgz", + "integrity": "sha512-rMBwLuLcasbyx7whHiLrz28rX74ATmImbzJUNUNvcUbz0N+zbIUOA2EgPJakp2gtCkVRp12tDIJ7tpj0bQtdjQ==", + "dev": true + }, "@types/babel__core": { "version": "7.20.5", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz", @@ -27840,6 +27888,15 @@ "@types/responselike": "*" } }, + "@types/chalk": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@types/chalk/-/chalk-2.2.0.tgz", + "integrity": "sha512-1zzPV9FDe1I/WHhRkf9SNgqtRJWZqrBWgu7JGveuHmmyR9CnAPCie2N/x+iHrgnpYBIcCJWHBoMRv2TRWktsvw==", + "dev": true, + "requires": { + "chalk": "*" + } + }, "@types/connect": { "version": "3.4.35", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.35.tgz", @@ -41706,12 +41763,6 @@ "requires": { "glob": "^10.3.7" } - }, - "typescript": { - "version": "5.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", - "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", - "dev": true } } }, @@ -41790,9 +41841,10 @@ } }, "typescript": { - "version": "4.9.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", - "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==" + "version": "5.5.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", + "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "dev": true }, "uglify-js": { "version": "3.17.4", diff --git a/package.json b/package.json index 6b20fae0bd..6bd53c79c1 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "build-cli:prod": "node --max-old-space-size=8192 node_modules/webpack/bin/webpack.js --config webpack.prod.ts", "watch": "npm run build-cli:dev -- --watch", "test": "npm run test:unit && npm run test:acceptance && npm run test:tap", + "test:tsc": "tsc --noEmit", "test:unit": "jest --runInBand --testPathPattern '/test(/jest)?/unit/' --reporters=jest-junit", "test:acceptance": "jest --maxWorkers=1 --testPathPattern \"/test(/jest)?/acceptance/\" --reporters=jest-junit", "test:tap": "tap -Rspec --timeout=300 test/tap/*.test.* ", @@ -136,7 +137,9 @@ "wrap-ansi": "^5.1.0" }, "devDependencies": { + "@types/abbrev": "^1.1.5", "@types/body-parser": "^1.19.1", + "@types/chalk": "^2.2.0", "@types/cross-spawn": "^6.0.2", "@types/express": "^4.17.13", "@types/fs-extra": "^9.0.11", @@ -177,7 +180,7 @@ "ts-jest": "29.1.2", "ts-loader": "^9.5.1", "ts-node": "^10.9.2", - "typescript": "^4.9.5", + "typescript": "^5.5.0", "vscode-jsonrpc": "8.1.0", "webpack": "^5.54.0", "webpack-cli": "^4.6.0", diff --git a/src/cli/commands/test/index.ts b/src/cli/commands/test/index.ts index fb638f3c3f..1bb8703b22 100644 --- a/src/cli/commands/test/index.ts +++ b/src/cli/commands/test/index.ts @@ -247,6 +247,9 @@ export default async function test( // Note: this is done based on the logic done below // for non-json/sarif outputs, where we take the code of // the first error. + // TODO: refactor this to be more consistent + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore: broken type definitions err.code = errorResults[0].code; } err.json = stringifiedData; @@ -292,13 +295,22 @@ export default async function test( if (notSuccess) { response += chalk.bold.red(summaryMessage); const error = new Error(response) as any; + // TODO: refactor this to be more consistent // take the code of the first problem to go through error // translation // HACK as there can be different errors, and we pass only the // first one + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore: broken type definitions error.code = errorResults[0].code; + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore: broken type definitions error.userMessage = errorResults[0].userMessage; + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore: broken type definitions error.strCode = errorResults[0].strCode; + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore: broken type definitions error.innerError = errorResults[0].innerError; throw error; } diff --git a/src/cli/main.ts b/src/cli/main.ts index 86d6d56070..b4818336ed 100755 --- a/src/cli/main.ts +++ b/src/cli/main.ts @@ -321,7 +321,7 @@ export async function main(): Promise { if ( typeof globalArgs.options.detectionDepth !== 'undefined' && - (globalArgs.options.detectionDepth <= 0 || + (globalArgs.options.detectionDepth as number <= 0 || Number.isNaN(globalArgs.options.detectionDepth)) ) { throw new InvalidDetectionDepthValue();