From f200fcb6335511df11dcaf8a8aac9fd101764c54 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 18 Apr 2023 02:58:38 +0900 Subject: [PATCH 1/4] Update tsconfig and eslint config for TS5 era --- .eslintrc.yml | 3 +++ tsconfig.base.json | 30 ++++++++++++++++++++++++++++++ tsconfig.json | 4 ++-- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 tsconfig.base.json diff --git a/.eslintrc.yml b/.eslintrc.yml index 5be673f8..4558c71a 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -29,6 +29,9 @@ rules: '@typescript-eslint/prefer-readonly-parameter-types': - error - ignoreInferredTypes: true + # See https://zenn.dev/teppeis/articles/2023-04-typescript-5_0-verbatim-module-syntax for enabling reason + '@typescript-eslint/consistent-type-imports': 'error' + '@typescript-eslint/no-import-type-side-effects': 'error' parser: '@typescript-eslint/parser' parserOptions: ecmaVersion: 12 diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 00000000..7ab0cb8f --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,30 @@ +{ + // Import from https://github.com/tsconfig/bases/commit/0ae4791797d8ba3dd2bca9aca880eb2d3e30e6fb + // To avoid issues around tsconfig.extends array + "$schema": "https://json.schemastore.org/tsconfig", + "display": "Node 16 + Strictest", + "compilerOptions": { + "lib": [ + "es2021" + ], + "module": "commonjs", + "target": "es2021", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "moduleResolution": "node", + "allowUnusedLabels": false, + "allowUnreachableCode": false, + "exactOptionalPropertyTypes": true, + "noFallthroughCasesInSwitch": true, + "noImplicitOverride": true, + "noImplicitReturns": true, + "noPropertyAccessFromIndexSignature": true, + "noUncheckedIndexedAccess": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "verbatimModuleSyntax": true, + "checkJs": true + } +} diff --git a/tsconfig.json b/tsconfig.json index 67d7432d..c3570837 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { - // https://github.com/tsconfig/bases/blob/d1543a94d47c3ef9af9987790742b09caf71b71d/bases/node16-strictest-esm.combined.json - "extends": "@tsconfig/node16-strictest-esm/tsconfig.json", + // TODO: Use tsconfig/base after all tools support tsconfig.extends array + "extends": "./tsconfig.base.json", "compilerOptions": { // https://www.typescriptlang.org/docs/handbook/esm-node.html "module": "node16", From 73319e3e114078c046227642b6e3004aad8f861b Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 18 Apr 2023 03:07:57 +0900 Subject: [PATCH 2/4] `npm uninstall @tsconfig/node16-strictest-esm` --- package-lock.json | 13 ------------- package.json | 1 - 2 files changed, 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index c7cad597..55a2c7cf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,6 @@ "zod": "^3.21.4" }, "devDependencies": { - "@tsconfig/node16-strictest-esm": "^1.0.3", "@types/node": "^16.18.23", "@typescript-eslint/eslint-plugin": "^5.58.0", "@typescript-eslint/parser": "^5.58.0", @@ -1827,12 +1826,6 @@ "integrity": "sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==", "dev": true }, - "node_modules/@tsconfig/node16-strictest-esm": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@tsconfig/node16-strictest-esm/-/node16-strictest-esm-1.0.3.tgz", - "integrity": "sha512-0/QTPDkKmE2dy0dMRstPCv4VJ+gUGgvMKzaWd5P3hgdlmPqYqe1pJxDGUlNYbSgUBlncIvvX+mIeZarokysNgg==", - "dev": true - }, "node_modules/@types/babel__core": { "version": "7.20.0", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.0.tgz", @@ -7824,12 +7817,6 @@ "integrity": "sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==", "dev": true }, - "@tsconfig/node16-strictest-esm": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@tsconfig/node16-strictest-esm/-/node16-strictest-esm-1.0.3.tgz", - "integrity": "sha512-0/QTPDkKmE2dy0dMRstPCv4VJ+gUGgvMKzaWd5P3hgdlmPqYqe1pJxDGUlNYbSgUBlncIvvX+mIeZarokysNgg==", - "dev": true - }, "@types/babel__core": { "version": "7.20.0", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.0.tgz", diff --git a/package.json b/package.json index 8da93390..d8226d00 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,6 @@ "zod": "^3.21.4" }, "devDependencies": { - "@tsconfig/node16-strictest-esm": "^1.0.3", "@types/node": "^16.18.23", "@typescript-eslint/eslint-plugin": "^5.58.0", "@typescript-eslint/parser": "^5.58.0", From ea13cf089d521992d6c7991498c1ff15e5dace5f Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 18 Apr 2023 03:08:14 +0900 Subject: [PATCH 3/4] `npm uninstall typescript && npm install --save-dev typescript` --- package-lock.json | 16 ++++++++-------- package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 55a2c7cf..79c207f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,7 @@ "jest": "^29.5.0", "ts-node": "^10.9.1", "tsx": "^3.12.6", - "typescript": "^4.9.5" + "typescript": "^5.0.4" }, "engines": { "node": "16.x" @@ -6193,16 +6193,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.0.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", + "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { - "node": ">=4.2.0" + "node": ">=12.20" } }, "node_modules/unbox-primitive": { @@ -10993,9 +10993,9 @@ } }, "typescript": { - "version": "4.9.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", - "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", + "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", "dev": true }, "unbox-primitive": { diff --git a/package.json b/package.json index d8226d00..f0a5a636 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,6 @@ "jest": "^29.5.0", "ts-node": "^10.9.1", "tsx": "^3.12.6", - "typescript": "^4.9.5" + "typescript": "^5.0.4" } } From 85a2200d14d76b2c03de4d7b19375c6a57b308ec Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 18 Apr 2023 03:10:57 +0900 Subject: [PATCH 4/4] Update code for TS5 verbatimModuleSyntax --- jest.config.ts | 2 +- src/elm-package-detector.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jest.config.ts b/jest.config.ts index 77ecbb95..ba40cf80 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -17,4 +17,4 @@ const config: Config.InitialOptions = { extensionsToTreatAsEsm: ['.ts'], testMatch: ['**/**/*.test.ts'], }; -export default config; +module.exports = config; diff --git a/src/elm-package-detector.ts b/src/elm-package-detector.ts index 472a16d9..02fef49a 100644 --- a/src/elm-package-detector.ts +++ b/src/elm-package-detector.ts @@ -1,5 +1,5 @@ import { readFileSync } from 'fs'; -import { BuildTarget, Package, PackageCache, Snapshot } from '@github/dependency-submission-toolkit'; +import { BuildTarget, type Package, PackageCache, Snapshot } from '@github/dependency-submission-toolkit'; import { context } from '@actions/github'; import { PackageURL } from 'packageurl-js'; import { assertIsDefined } from './typeguards';