Skip to content

Commit f6f4d6e

Browse files
fix: update environment variable access to bracket notation and enhance TypeScript configuration with stricter checks
1 parent 564f4de commit f6f4d6e

File tree

7 files changed

+46
-52
lines changed

7 files changed

+46
-52
lines changed

index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { installJDK, installAndroidStudio } from "./src/install-scripts";
99
/** Main setup function */
1010
async function setup() {
1111
// Check for config from environment variable (for testing/automation)
12-
const envConfig = process.env.RN_LAB_CONFIG;
12+
const envConfig = process.env["RN_LAB_CONFIG"];
1313
let prompt;
1414

1515
if (envConfig) {

src/helpers/get-pkg-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export type PackageManager = "npm" | "yarn" | "bun";
77
* If no specific package manager is detected, defaults to "npm".
88
*/
99
export default function getPkgManager(): PackageManager {
10-
const userAgent = process.env.npm_config_user_agent || "";
10+
const userAgent = process.env["npm_config_user_agent"] || "";
1111

1212
if (userAgent.startsWith("npm")) {
1313
return "npm";

src/install-scripts.ts

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@ export async function installChocolatey() {
1919
return;
2020
}
2121
spinner.info(
22-
colors.yellow("Running Chocolatey installation as non-admin...")
22+
colors.yellow("Running Chocolatey installation as non-admin..."),
2323
);
2424
const scriptPath = getScriptPath("installChocolately.ps1");
2525
// Execute the PowerShell script for non-admin installation
2626
execSync(`powershell.exe -ExecutionPolicy Bypass -File "${scriptPath}"`, {
2727
stdio: "inherit",
2828
});
2929
spinner.succeed(
30-
colors.green("Chocolatey installed successfully (non-admin).")
30+
colors.green("Chocolatey installed successfully (non-admin)."),
3131
);
3232
// Add Chocolatey to the current session's PATH
33-
const chocoPath = `${process.env.ProgramData}\\chocoportable\\bin`;
34-
process.env.PATH = `${process.env.PATH};${chocoPath}`;
33+
const programData = process.env["ProgramData"] || "C:\\ProgramData";
34+
const chocoPath = `${programData}\\chocoportable\\bin`;
35+
const currentPath = process.env["PATH"] || "";
36+
process.env["PATH"] = `${currentPath};${chocoPath}`;
3537
} catch (error) {
3638
spinner.fail(colors.red("Failed to install Chocolatey."));
3739
console.error(error);
@@ -68,11 +70,11 @@ export async function installJDK() {
6870
stdio: "inherit",
6971
});
7072
spinner.succeed(
71-
colors.green("JAVA_HOME environment variable set successfully.")
73+
colors.green("JAVA_HOME environment variable set successfully."),
7274
);
7375
} catch (error) {
7476
spinner.fail(
75-
colors.red("Failed to set JAVA_HOME environment variable.")
77+
colors.red("Failed to set JAVA_HOME environment variable."),
7678
);
7779
throw error;
7880
}
@@ -102,18 +104,18 @@ export async function installJDK() {
102104
});
103105
execSync("source ~/.bashrc", { stdio: "inherit" });
104106
spinner.succeed(
105-
colors.green("JAVA_HOME environment variable set successfully.")
107+
colors.green("JAVA_HOME environment variable set successfully."),
106108
);
107109
} catch (error) {
108110
spinner.fail(
109-
colors.red("Failed to set JAVA_HOME environment variable.")
111+
colors.red("Failed to set JAVA_HOME environment variable."),
110112
);
111113
throw error;
112114
}
113115
}
114116
} else {
115117
spinner.fail(
116-
colors.red("Please install OpenJDK manually on this operating system.")
118+
colors.red("Please install OpenJDK manually on this operating system."),
117119
);
118120
}
119121
}
@@ -129,11 +131,11 @@ export async function installAndroidStudio() {
129131
await installChocolatey();
130132
}
131133
const androidStudioPath = path.join(
132-
process.env.ProgramFiles || "C:\\Program Files",
134+
process.env["ProgramFiles"] || "C:\\Program Files",
133135
"Android",
134136
"Android Studio",
135137
"bin",
136-
"studio.exe"
138+
"studio.exe",
137139
);
138140

139141
if (process.platform === "win32") {
@@ -163,14 +165,14 @@ export async function installAndroidStudio() {
163165

164166
// Set ANDROID_HOME environment variable
165167
const androidHomePath = path.join(
166-
process.env.ProgramFiles || "C:\\Program Files",
168+
process.env["ProgramFiles"] || "C:\\Program Files",
167169
"Android",
168-
"Sdk"
170+
"Sdk",
169171
);
170172

171173
if (!fs.existsSync(androidHomePath)) {
172174
pathSpinner.fail(
173-
colors.red("Android SDK not found. Please install Android Studio.")
175+
colors.red("Android SDK not found. Please install Android Studio."),
174176
);
175177
return;
176178
}
@@ -185,17 +187,17 @@ export async function installAndroidStudio() {
185187

186188
execSync(
187189
`setx PATH "%PATH%;${androidHomePath}\\tools;${androidHomePath}\\platform-tools" /M`,
188-
{ stdio: "inherit" }
190+
{ stdio: "inherit" },
189191
);
190192

191193
pathSpinner.succeed(
192-
colors.green("Android Studio added to PATH successfully.")
194+
colors.green("Android Studio added to PATH successfully."),
193195
);
194196
} catch (error) {
195197
pathSpinner.fail(
196198
colors.red(
197-
"Failed to set ANDROID_HOME and ANDROID_SDK_ROOT environment variables."
198-
)
199+
"Failed to set ANDROID_HOME and ANDROID_SDK_ROOT environment variables.",
200+
),
199201
);
200202
console.error(error);
201203
throw error;
@@ -219,14 +221,14 @@ export async function installAndroidStudio() {
219221

220222
// Set ANDROID_HOME environment variable
221223
const androidHomePath = path.join(
222-
process.env.HOME || "/home/user",
224+
process.env["HOME"] || "/home/user",
223225
"Android",
224-
"Sdk"
226+
"Sdk",
225227
);
226228

227229
if (!fs.existsSync(androidHomePath)) {
228230
pathSpinner.fail(
229-
colors.red("Android SDK not found. Please install Android Studio.")
231+
colors.red("Android SDK not found. Please install Android Studio."),
230232
);
231233
return;
232234
}
@@ -239,33 +241,33 @@ export async function installAndroidStudio() {
239241
`echo "export ANDROID_SDK_ROOT=${androidHomePath}" >> ~/.bashrc`,
240242
{
241243
stdio: "inherit",
242-
}
244+
},
243245
);
244246
execSync(
245247
`echo "export PATH=$PATH:${androidHomePath}/tools:${androidHomePath}/platform-tools" >> ~/.bashrc`,
246248
{
247249
stdio: "inherit",
248-
}
250+
},
249251
);
250252
execSync("source ~/.bashrc", { stdio: "inherit" });
251253

252254
pathSpinner.succeed(
253-
colors.green("Android Studio added to PATH successfully.")
255+
colors.green("Android Studio added to PATH successfully."),
254256
);
255257
} catch (error) {
256258
pathSpinner.fail(
257259
colors.red(
258-
"Failed to set ANDROID_HOME and ANDROID_SDK_ROOT environment variables."
259-
)
260+
"Failed to set ANDROID_HOME and ANDROID_SDK_ROOT environment variables.",
261+
),
260262
);
261263
console.error(error);
262264
throw error;
263265
}
264266
} else {
265267
spinner.fail(
266268
colors.red(
267-
"Please install Android Studio manually on this operating system."
268-
)
269+
"Please install Android Studio manually on this operating system.",
270+
),
269271
);
270272
}
271273
}

src/prompts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { fetchReactNativeVersions } from "./helpers/fetch-rn-versions";
1616
import { PackageManager } from "./helpers/get-pkg-manager";
1717
import { TemplateType, EnvPackages } from "./types";
1818

19-
const { blue, red, green, yellow } = colors;
19+
const { blue, red, green } = colors;
2020

2121
function handleCancel(value: unknown) {
2222
if (isCancel(value)) {

src/react-native-lab.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,7 @@
22
import colors from "picocolors";
33
import { execSync } from "node:child_process";
44
import { basename, dirname, join, resolve } from "node:path";
5-
import {
6-
copyFileSync,
7-
existsSync,
8-
mkdirSync,
9-
readFileSync,
10-
writeFileSync,
11-
readdirSync,
12-
renameSync,
13-
} from "node:fs";
5+
import { copyFileSync, existsSync, mkdirSync, readdirSync } from "node:fs";
146
import { rmSync } from "node:fs";
157

168
import { getTemplateFile, installTemplate } from "./template";
@@ -22,11 +14,7 @@ import { PackageManager } from "./helpers/get-pkg-manager";
2214
import { EnvPackages, TemplateType } from "./types";
2315
import { setupCI as initCI } from "./helpers/ci";
2416

25-
function fixAndroidPackageStructure(
26-
root: string,
27-
packageName: string,
28-
appName: string,
29-
) {
17+
function fixAndroidPackageStructure(root: string, packageName: string) {
3018
const androidJavaPath = join(root, "android", "app", "src", "main", "java");
3119

3220
if (!existsSync(androidJavaPath)) {
@@ -171,7 +159,7 @@ export default async function createReactNative({
171159

172160
// Fix Android package structure if a custom package name was provided
173161
if (packageName) {
174-
fixAndroidPackageStructure(root, packageName, appName);
162+
fixAndroidPackageStructure(root, packageName);
175163
}
176164

177165
// Copy `.gitignore` if the application did not provide one

src/template.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import os from "os";
22
import fs from "fs/promises";
33
import { fileURLToPath } from "url";
44
import path, { dirname } from "path";
5-
import { execSync } from "child_process";
65
import picocolors from "picocolors";
76
import { copyFiles } from "./helpers/copy";
87
import HookTemplates from "./templates/snippets/hooks";
@@ -32,7 +31,6 @@ export const SRC_DIR_NAMES = ["assets", "screens", "components", "helpers"];
3231

3332
export const installTemplate = async ({
3433
appName,
35-
packageName,
3634
root,
3735
packageManager,
3836
envEnabled,
@@ -43,7 +41,6 @@ export const installTemplate = async ({
4341
template,
4442
srcDir,
4543
nativeWind,
46-
skipInstall,
4744
}: InstallTemplateArgs) => {
4845
console.log(bold(`Using ${packageManager}.`));
4946
const isReactNativeDotEnv =
@@ -119,7 +116,6 @@ export const installTemplate = async ({
119116
const packageJson = await updatePackageJson(
120117
root,
121118
appName,
122-
packageName,
123119
isReactNativeDotEnv,
124120
isReactNativeConfig,
125121
nativeWind,
@@ -240,7 +236,6 @@ function generateTsConfig(srcDir: boolean, template: string) {
240236
async function updatePackageJson(
241237
root: string,
242238
appName: string,
243-
packageName: string | undefined,
244239
isReactNativeDotEnv: boolean,
245240
isReactNativeConfig: boolean,
246241
nativeWind: boolean,

tsconfig.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,16 @@
1919
// Skips type checking of declaration files (can speed up compilation)
2020
"skipLibCheck": true,
2121
// Ensures that file names are case-sensitive
22-
"forceConsistentCasingInFileNames": true
22+
"forceConsistentCasingInFileNames": true,
23+
// Report unused locals and parameters
24+
"noUnusedLocals": true,
25+
"noUnusedParameters": true,
26+
// Prevent fallthrough in switch statements
27+
"noFallthroughCasesInSwitch": true,
28+
// Require explicit override keyword when overriding
29+
"noImplicitOverride": true,
30+
// Ensure index access is intentional
31+
"noPropertyAccessFromIndexSignature": true
2332
},
2433
"exclude": ["node_modules", "dist", "./src/templates"]
2534
}

0 commit comments

Comments
 (0)