From 4d63251d7d1d9069e2c4ef4115c4a29018c705e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Wouts?= Date: Thu, 24 Feb 2022 23:24:52 +1100 Subject: [PATCH] refactor: always use property access for process.env This is in preparation for migrating from webpack to esbuild. See https://github.com/evanw/esbuild/issues/2050. --- .github/workflows/test-app-e2e.yaml | 2 +- app/testing/run-test-suite.ts | 11 +++++------ cli/src/main.ts | 4 ++-- integrations/intellij/controller/src/install.ts | 4 ++-- integrations/intellij/controller/src/is-installed.ts | 4 ++-- integrations/intellij/controller/src/run-server.ts | 6 +++--- integrations/intellij/controller/webpack.config.js | 2 +- integrations/vscode/src/index.ts | 6 +++--- tsconfig.base.json | 1 - 9 files changed, 19 insertions(+), 21 deletions(-) diff --git a/.github/workflows/test-app-e2e.yaml b/.github/workflows/test-app-e2e.yaml index dc380ef334a..5e2e62970e9 100644 --- a/.github/workflows/test-app-e2e.yaml +++ b/.github/workflows/test-app-e2e.yaml @@ -118,7 +118,7 @@ jobs: issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: `⚠️ Screenshots have changed: group ${process.env["MATRIX_GROUP"]}, ${process.env["MATRIX_OS"]} (Node ${process.env["MATRIX_NODE_VERSION"]})` + body: `⚠️ Screenshots have changed: group ${process.env.MATRIX_GROUP}, ${process.env.MATRIX_OS} (Node ${process.env.MATRIX_NODE_VERSION})` }) - name: Fail if screenshots have changed on main branch run: git diff --exit-code diff --git a/app/testing/run-test-suite.ts b/app/testing/run-test-suite.ts index e0f533029c4..01de83a3508 100644 --- a/app/testing/run-test-suite.ts +++ b/app/testing/run-test-suite.ts @@ -4,14 +4,13 @@ import { runTests } from "."; async function main() { let failed = false; - const groupCount = parseInt(process.env["GROUP_COUNT"] || "1"); - const groupIndex = parseInt(process.env["GROUP_INDEX"] || "0"); + const groupCount = parseInt(process.env.GROUP_COUNT || "1"); + const groupIndex = parseInt(process.env.GROUP_INDEX || "0"); const setupEnvironmentPath = - process.env["SETUP_ENVIRONMENT_MODULE"] || - path.resolve(__dirname, "../src"); + process.env.SETUP_ENVIRONMENT_MODULE || path.resolve(__dirname, "../src"); const testsPath = - process.env["TESTS_MODULE"] || path.resolve(__dirname, "../tests"); - const headless = process.env["HEADLESS"] !== "0"; + process.env.TESTS_MODULE || path.resolve(__dirname, "../tests"); + const headless = process.env.HEADLESS !== "0"; const browser = await playwright.chromium.launch({ headless, devtools: !headless, diff --git a/cli/src/main.ts b/cli/src/main.ts index fb8a6967f97..a9ea928758c 100644 --- a/cli/src/main.ts +++ b/cli/src/main.ts @@ -31,8 +31,8 @@ program .option(...VERBOSE_OPTION) .action(async (dirPath: string | undefined, options: SharedOptions) => { const previewjs = await load({ - installDir: process.env["PREVIEWJS_MODULES_DIR"] || "..", - packageName: process.env["PREVIEWJS_PACKAGE_NAME"] || "@previewjs/app", + installDir: process.env.PREVIEWJS_MODULES_DIR || "..", + packageName: process.env.PREVIEWJS_PACKAGE_NAME || "@previewjs/app", }); const workspace = await previewjs.getWorkspace({ versionCode: `cli-${version}`, diff --git a/integrations/intellij/controller/src/install.ts b/integrations/intellij/controller/src/install.ts index 4dfd6b9cc3b..0a4877481c7 100644 --- a/integrations/intellij/controller/src/install.ts +++ b/integrations/intellij/controller/src/install.ts @@ -7,11 +7,11 @@ main().catch((e) => { }); async function main() { - const packageName = process.env["PREVIEWJS_PACKAGE_NAME"]; + const packageName = process.env.PREVIEWJS_PACKAGE_NAME; if (!packageName) { throw new Error(`Missing environment variable: PREVIEWJS_PACKAGE_NAME`); } - const packageVersion = process.env["PREVIEWJS_PACKAGE_VERSION"]; + const packageVersion = process.env.PREVIEWJS_PACKAGE_VERSION; if (!packageVersion) { throw new Error(`Missing environment variable: PREVIEWJS_PACKAGE_VERSION`); } diff --git a/integrations/intellij/controller/src/is-installed.ts b/integrations/intellij/controller/src/is-installed.ts index 46abe66d71a..0d8effc9b7e 100644 --- a/integrations/intellij/controller/src/is-installed.ts +++ b/integrations/intellij/controller/src/is-installed.ts @@ -7,11 +7,11 @@ main().catch((e) => { }); async function main() { - const packageName = process.env["PREVIEWJS_PACKAGE_NAME"]; + const packageName = process.env.PREVIEWJS_PACKAGE_NAME; if (!packageName) { throw new Error(`Missing environment variable: PREVIEWJS_PACKAGE_NAME`); } - const packageVersion = process.env["PREVIEWJS_PACKAGE_VERSION"]; + const packageVersion = process.env.PREVIEWJS_PACKAGE_VERSION; if (!packageVersion) { throw new Error(`Missing environment variable: PREVIEWJS_PACKAGE_VERSION`); } diff --git a/integrations/intellij/controller/src/run-server.ts b/integrations/intellij/controller/src/run-server.ts index 458d5aa9d27..015878fe817 100644 --- a/integrations/intellij/controller/src/run-server.ts +++ b/integrations/intellij/controller/src/run-server.ts @@ -18,8 +18,8 @@ import { UpdatePendingFileResponse, } from "./api"; -const port = parseInt(process.env["PORT"] || "9100"); -const version = process.env["PREVIEWJS_INTELLIJ_VERSION"]; +const port = parseInt(process.env.PORT || "9100"); +const version = process.env.PREVIEWJS_INTELLIJ_VERSION; if (!version) { throw new Error(`IntelliJ version was not set`); @@ -31,7 +31,7 @@ main().catch((e) => { }); async function main() { - const packageName = process.env["PREVIEWJS_PACKAGE_NAME"]; + const packageName = process.env.PREVIEWJS_PACKAGE_NAME; if (!packageName) { throw new Error(`Missing environment variable: PREVIEWJS_PACKAGE_NAME`); } diff --git a/integrations/intellij/controller/webpack.config.js b/integrations/intellij/controller/webpack.config.js index b97819ff999..9247d775f36 100644 --- a/integrations/intellij/controller/webpack.config.js +++ b/integrations/intellij/controller/webpack.config.js @@ -6,7 +6,7 @@ module.exports = { install: "./src/install.ts", "run-server": "./src/run-server.ts", }, - mode: process.env["NODE_ENV"] || "production", + mode: process.env.NODE_ENV || "production", target: "node", module: { rules: [ diff --git a/integrations/vscode/src/index.ts b/integrations/vscode/src/index.ts index 02fe3ad9feb..443c2407846 100644 --- a/integrations/vscode/src/index.ts +++ b/integrations/vscode/src/index.ts @@ -28,15 +28,15 @@ let dispose = async () => { export async function activate(context: vscode.ExtensionContext) { const config = vscode.workspace.getConfiguration(); - const packageName = process.env["PREVIEWJS_PACKAGE_NAME"]; + const packageName = process.env.PREVIEWJS_PACKAGE_NAME; if (!packageName) { throw new Error(`Missing environment variable: PREVIEWJS_PACKAGE_NAME`); } - let requirePath = process.env["PREVIEWJS_MODULES_DIR"]; + let requirePath = process.env.PREVIEWJS_MODULES_DIR; if (!requirePath) { requirePath = path.join(__dirname, "installed"); - const packageVersion = process.env["PREVIEWJS_PACKAGE_VERSION"]; + const packageVersion = process.env.PREVIEWJS_PACKAGE_VERSION; if (!packageVersion) { throw new Error( `Missing environment variable: PREVIEWJS_PACKAGE_VERSION` diff --git a/tsconfig.base.json b/tsconfig.base.json index 628b058a9bb..1e8fb70d295 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -17,7 +17,6 @@ "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, "noUncheckedIndexedAccess": true, - "noPropertyAccessFromIndexSignature": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true