Skip to content

Commit

Permalink
Use @tsconfig/strictest instead
Browse files Browse the repository at this point in the history
Signed-off-by: Sora Morimoto <[email protected]>
  • Loading branch information
smorimoto committed Sep 23, 2022
1 parent d011f62 commit a98ac6d
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 49 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/lint-doc/odoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/lint-fmt/ocamlformat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/setup-ocaml/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
32 changes: 16 additions & 16 deletions src/setup-ocaml/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,27 @@ export async function installer(): Promise<void> {
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();
}
Expand All @@ -102,24 +102,24 @@ export async function installer(): Promise<void> {
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();
}
Expand All @@ -129,12 +129,12 @@ export async function installer(): Promise<void> {
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();
}
Expand Down
39 changes: 24 additions & 15 deletions src/setup-ocaml/opam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -260,17 +269,17 @@ 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();
core.endGroup();
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<void> {
Expand All @@ -287,9 +296,9 @@ export async function installOcaml(ocamlCompiler: string): Promise<void> {
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",
Expand All @@ -298,7 +307,7 @@ export async function installOcaml(ocamlCompiler: string): Promise<void> {
"--packages",
ocamlCompiler,
]);
process.env.PATH = originalPath.join(path.delimiter);
process.env["PATH"] = originalPath.join(path.delimiter);
} else {
await exec("opam", [
"switch",
Expand Down
6 changes: 3 additions & 3 deletions src/setup-ocaml/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ 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();
await saveDuneCache();
}
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) {
Expand Down
6 changes: 3 additions & 3 deletions src/setup-ocaml/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
}
}
Expand All @@ -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;
}
}
Expand Down
12 changes: 5 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"]
}

0 comments on commit a98ac6d

Please sign in to comment.