From a98ac6d6fc2c64a4cfae064b385e8cbf095867cb Mon Sep 17 00:00:00 2001 From: Sora Morimoto Date: Fri, 23 Sep 2022 17:16:04 +0900 Subject: [PATCH] Use @tsconfig/strictest instead Signed-off-by: Sora Morimoto --- package.json | 1 + pnpm-lock.yaml | 6 ++++++ src/lint-doc/odoc.ts | 2 +- src/lint-fmt/ocamlformat.ts | 2 +- src/setup-ocaml/cache.ts | 6 +++--- src/setup-ocaml/installer.ts | 32 ++++++++++++++--------------- src/setup-ocaml/opam.ts | 39 ++++++++++++++++++++++-------------- src/setup-ocaml/post.ts | 6 +++--- src/setup-ocaml/system.ts | 6 +++--- tsconfig.json | 12 +++++------ 10 files changed, 63 insertions(+), 49 deletions(-) diff --git a/package.json b/package.json index 9dd7a1703..77ae69310 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "yaml": "2.1.1" }, "devDependencies": { + "@tsconfig/strictest": "1.0.1", "@types/node": "18.7.18", "@types/semver": "7.3.12", "@typescript-eslint/eslint-plugin": "5.38.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f8f8e270e..5218277a8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,6 +9,7 @@ specifiers: '@actions/http-client': 2.0.1 '@actions/io': 1.1.2 '@actions/tool-cache': 2.0.1 + '@tsconfig/strictest': 1.0.1 '@types/node': 18.7.18 '@types/semver': 7.3.12 '@typescript-eslint/eslint-plugin': 5.38.0 @@ -44,6 +45,7 @@ dependencies: yaml: 2.1.1 devDependencies: + '@tsconfig/strictest': 1.0.1 '@types/node': 18.7.18 '@types/semver': 7.3.12 '@typescript-eslint/eslint-plugin': 5.38.0_wsb62dxj2oqwgas4kadjymcmry @@ -398,6 +400,10 @@ packages: engines: {node: '>=8.0.0'} dev: false + /@tsconfig/strictest/1.0.1: + resolution: {integrity: sha512-7O8Q537UQdTZSKEV0f5WRLRFtfL9B8agGqIZrCOwOiWvbjZWPP2rAoZ7LHcwjdG4vnjdleHMEE+ZetM+lhRkcA==} + dev: true + /@types/json-schema/7.0.11: resolution: {integrity: sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==} dev: true diff --git a/src/lint-doc/odoc.ts b/src/lint-doc/odoc.ts index 7daeac529..185019415 100644 --- a/src/lint-doc/odoc.ts +++ b/src/lint-doc/odoc.ts @@ -5,7 +5,7 @@ export async function lintOdoc() { const options: ExecOptions = { env: { ...process.env, - PATH: process.env.PATH ?? "", + PATH: process.env["PATH"] ?? "", ODOC_WARN_ERROR: "true", }, }; diff --git a/src/lint-fmt/ocamlformat.ts b/src/lint-fmt/ocamlformat.ts index ac17db428..507a89f72 100644 --- a/src/lint-fmt/ocamlformat.ts +++ b/src/lint-fmt/ocamlformat.ts @@ -5,7 +5,7 @@ import * as path from "path"; import { convertToUnix } from "./compat"; async function parse() { - const githubWorkspace = process.env.GITHUB_WORKSPACE ?? process.cwd(); + const githubWorkspace = process.env["GITHUB_WORKSPACE"] ?? process.cwd(); const fpath = path.join(githubWorkspace, ".ocamlformat"); const buf = await fs.readFile(fpath); const str = buf.toString(); diff --git a/src/setup-ocaml/cache.ts b/src/setup-ocaml/cache.ts index 3fc8f4181..77a52313c 100644 --- a/src/setup-ocaml/cache.ts +++ b/src/setup-ocaml/cache.ts @@ -111,7 +111,7 @@ function composeOpamDownloadCacheKeys() { function composeCygwinCachePaths() { const paths = []; - const githubWorkspace = process.env.GITHUB_WORKSPACE ?? process.cwd(); + const githubWorkspace = process.env["GITHUB_WORKSPACE"] ?? process.cwd(); const cygwinRoot = path.join("D:", "cygwin"); paths.push(cygwinRoot); const cygwinRootSymlinkPath = path.posix.join("/cygdrive", "d", "cygwin"); @@ -132,7 +132,7 @@ function composeDuneCachePaths() { const duneCacheDir = path.join(homeDir, "Local Settings", "Cache", "dune"); paths.push(duneCacheDir); } else { - const xdgCacheHome = process.env.XDG_CACHE_HOME; + const xdgCacheHome = process.env["XDG_CACHE_HOME"]; const duneCacheDir = xdgCacheHome ? path.join(xdgCacheHome, "dune") : path.join(homeDir, ".cache", "dune"); @@ -164,7 +164,7 @@ function composeOpamCachePaths() { const opamRootCachePath = path.join(homeDir, ".opam"); paths.push(opamRootCachePath); } - const githubWorkspace = process.env.GITHUB_WORKSPACE ?? process.cwd(); + const githubWorkspace = process.env["GITHUB_WORKSPACE"] ?? process.cwd(); const opamLocalCachePath = path.join(githubWorkspace, "_opam"); paths.push(opamLocalCachePath); return paths; diff --git a/src/setup-ocaml/installer.ts b/src/setup-ocaml/installer.ts index 6e354f508..f2530bf2d 100644 --- a/src/setup-ocaml/installer.ts +++ b/src/setup-ocaml/installer.ts @@ -66,27 +66,27 @@ export async function installer(): Promise { core.endGroup(); } if (platform === Platform.Win32) { - core.exportVariable("HOME", process.env.USERPROFILE); + core.exportVariable("HOME", process.env["USERPROFILE"]); core.exportVariable("MSYS", "winsymlinks:native"); } if (platform === Platform.Win32) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const originalPath = process.env.PATH!.split(path.delimiter); + const originalPath = process.env["PATH"]!.split(path.delimiter); const msys64Path = path.join("C:", "msys64", "usr", "bin"); const patchedPath = [msys64Path, ...originalPath]; - process.env.PATH = patchedPath.join(path.delimiter); + process.env["PATH"] = patchedPath.join(path.delimiter); await restoreCygwinCache(); - process.env.PATH = originalPath.join(path.delimiter); + process.env["PATH"] = originalPath.join(path.delimiter); } let opamCacheHit; if (platform === Platform.Win32) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const originalPath = process.env.PATH!.split(path.delimiter); + const originalPath = process.env["PATH"]!.split(path.delimiter); const msys64Path = path.join("C:", "msys64", "usr", "bin"); const patchedPath = [msys64Path, ...originalPath]; - process.env.PATH = patchedPath.join(path.delimiter); + process.env["PATH"] = patchedPath.join(path.delimiter); opamCacheHit = await restoreOpamCache(); - process.env.PATH = originalPath.join(path.delimiter); + process.env["PATH"] = originalPath.join(path.delimiter); } else { opamCacheHit = await restoreOpamCache(); } @@ -102,24 +102,24 @@ export async function installer(): Promise { await installOcaml(ocamlCompiler); if (platform === Platform.Win32) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const originalPath = process.env.PATH!.split(path.delimiter); + const originalPath = process.env["PATH"]!.split(path.delimiter); const msys64Path = path.join("C:", "msys64", "usr", "bin"); const patchedPath = [msys64Path, ...originalPath]; - process.env.PATH = patchedPath.join(path.delimiter); + process.env["PATH"] = patchedPath.join(path.delimiter); await saveOpamCache(); - process.env.PATH = originalPath.join(path.delimiter); + process.env["PATH"] = originalPath.join(path.delimiter); } else { await saveOpamCache(); } } if (platform === Platform.Win32) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const originalPath = process.env.PATH!.split(path.delimiter); + const originalPath = process.env["PATH"]!.split(path.delimiter); const msys64Path = path.join("C:", "msys64", "usr", "bin"); const patchedPath = [msys64Path, ...originalPath]; - process.env.PATH = patchedPath.join(path.delimiter); + process.env["PATH"] = patchedPath.join(path.delimiter); await restoreOpamDownloadCache(); - process.env.PATH = originalPath.join(path.delimiter); + process.env["PATH"] = originalPath.join(path.delimiter); } else { await restoreOpamDownloadCache(); } @@ -129,12 +129,12 @@ export async function installer(): Promise { if (DUNE_CACHE) { if (platform === Platform.Win32) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const originalPath = process.env.PATH!.split(path.delimiter); + const originalPath = process.env["PATH"]!.split(path.delimiter); const msys64Path = path.join("C:", "msys64", "usr", "bin"); const patchedPath = [msys64Path, ...originalPath]; - process.env.PATH = patchedPath.join(path.delimiter); + process.env["PATH"] = patchedPath.join(path.delimiter); await restoreDuneCache(); - process.env.PATH = originalPath.join(path.delimiter); + process.env["PATH"] = originalPath.join(path.delimiter); } else { await restoreDuneCache(); } diff --git a/src/setup-ocaml/opam.ts b/src/setup-ocaml/opam.ts index 206571cc6..4f87c6598 100644 --- a/src/setup-ocaml/opam.ts +++ b/src/setup-ocaml/opam.ts @@ -44,14 +44,23 @@ async function getLatestOpamRelease(): Promise<{ .sort(({ tag_name: v1 }, { tag_name: v2 }) => semver.rcompare(v1, v2, { loose: true }) ); - const { assets, tag_name: version } = matchedReleases[0]; - const architecture = getArchitecture(); - const platform = getPlatform(); - const [{ browser_download_url: browserDownloadUrl }] = assets.filter( - ({ browser_download_url }) => + const latestRelease = matchedReleases[0]; + if (latestRelease !== undefined) { + const { assets, tag_name: version } = latestRelease; + const architecture = getArchitecture(); + const platform = getPlatform(); + const matchedAssets = assets.filter(({ browser_download_url }) => browser_download_url.includes(`${architecture}-${platform}`) - ); - return { version, browserDownloadUrl }; + )[0]; + if (matchedAssets !== undefined) { + const { browser_download_url: browserDownloadUrl } = matchedAssets; + return { version, browserDownloadUrl }; + } else { + throw new Error("matchedAssets not found"); + } + } else { + throw new Error("latestRelease not found"); + } } async function findOpam() { @@ -90,7 +99,7 @@ async function acquireOpamUnix() { } async function installUnixSystemPackages() { - const isGitHubRunner = process.env.ImageOS !== undefined; + const isGitHubRunner = process.env["ImageOS"] !== undefined; const platform = getPlatform(); if (isGitHubRunner) { if (platform === Platform.Linux) { @@ -117,7 +126,7 @@ async function installUnixSystemPackages() { } async function updateUnixPackageIndexFiles() { - const isGitHubRunner = process.env.ImageOS !== undefined; + const isGitHubRunner = process.env["ImageOS"] !== undefined; const platform = getPlatform(); if (isGitHubRunner) { if (platform === Platform.Linux) { @@ -260,9 +269,9 @@ async function setupOpamWindows() { await setupCygwin(); core.endGroup(); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const originalPath = process.env.PATH!.split(path.delimiter); + const originalPath = process.env["PATH"]!.split(path.delimiter); const patchedPath = [CYGWIN_ROOT_BIN, ...originalPath]; - process.env.PATH = patchedPath.join(path.delimiter); + process.env["PATH"] = patchedPath.join(path.delimiter); await saveCygwinCache(); core.startGroup("Install opam"); await acquireOpamWindows(); @@ -270,7 +279,7 @@ async function setupOpamWindows() { core.startGroup("Initialise the opam state"); await initializeOpamWindows(); core.endGroup(); - process.env.PATH = originalPath.join(path.delimiter); + process.env["PATH"] = originalPath.join(path.delimiter); } export async function setupOpam(): Promise { @@ -287,9 +296,9 @@ export async function installOcaml(ocamlCompiler: string): Promise { const platform = getPlatform(); if (platform === Platform.Win32) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const originalPath = process.env.PATH!.split(path.delimiter); + const originalPath = process.env["PATH"]!.split(path.delimiter); const patchedPath = [CYGWIN_ROOT_BIN, ...originalPath]; - process.env.PATH = patchedPath.join(path.delimiter); + process.env["PATH"] = patchedPath.join(path.delimiter); await exec("opam", [ "switch", "create", @@ -298,7 +307,7 @@ export async function installOcaml(ocamlCompiler: string): Promise { "--packages", ocamlCompiler, ]); - process.env.PATH = originalPath.join(path.delimiter); + process.env["PATH"] = originalPath.join(path.delimiter); } else { await exec("opam", [ "switch", diff --git a/src/setup-ocaml/post.ts b/src/setup-ocaml/post.ts index dee00c5a6..7c6d34e2f 100644 --- a/src/setup-ocaml/post.ts +++ b/src/setup-ocaml/post.ts @@ -11,11 +11,11 @@ async function run() { try { const platform = getPlatform(); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const originalPath = process.env.PATH!.split(path.delimiter); + const originalPath = process.env["PATH"]!.split(path.delimiter); if (platform === Platform.Win32) { const msys64Path = path.join("C:", "msys64", "usr", "bin"); const patchedPath = [msys64Path, ...originalPath]; - process.env.PATH = patchedPath.join(path.delimiter); + process.env["PATH"] = patchedPath.join(path.delimiter); } if (DUNE_CACHE) { await trimDuneCache(); @@ -23,7 +23,7 @@ async function run() { } await saveOpamDownloadCache(); if (platform === Platform.Win32) { - process.env.PATH = originalPath.join(path.delimiter); + process.env["PATH"] = originalPath.join(path.delimiter); } } catch (error) { if (error instanceof Error) { diff --git a/src/setup-ocaml/system.ts b/src/setup-ocaml/system.ts index fd4460ead..5728aa089 100644 --- a/src/setup-ocaml/system.ts +++ b/src/setup-ocaml/system.ts @@ -41,9 +41,9 @@ export async function getSystemIdentificationInfo(): Promise<{ let version = ""; for (const line of lines) { const [key, value] = line.split("=").map((kv) => kv.trim()); - if (key === "ID") { + if (key === "ID" && value !== undefined) { id = value.toLowerCase(); - } else if (key === "VERSION_ID") { + } else if (key === "VERSION_ID" && value !== undefined) { version = value.toLowerCase().replace(/["]/g, ""); } } @@ -54,7 +54,7 @@ export async function getSystemIdentificationInfo(): Promise<{ let version = ""; for (const line of lines) { const [key, value] = line.split(":").map((kv) => kv.trim()); - if (key === "ProductVersion") { + if (key === "ProductVersion" && value !== undefined) { version = value; } } diff --git a/tsconfig.json b/tsconfig.json index 7a86805bc..3ffc0702d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,14 +1,12 @@ { + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "@tsconfig/strictest/tsconfig.json", "compilerOptions": { - "lib": ["ESNext", "DOM"], + "lib": ["DOM", "DOM.Iterable", "ESNext"], "moduleResolution": "Node", "noEmit": true, - "noFallthroughCasesInSwitch": true, - "noImplicitReturns": true, - "noUnusedLocals": true, - "noUnusedParameters": true, "resolveJsonModule": true, - "strict": true, "target": "ES2022" - } + }, + "include": ["src"] }