fix!: rename addEnv options to be simpler

This commit is contained in:
Amin Yahyaabadi 2024-08-15 17:26:17 -07:00
parent fce9cac0b5
commit efbc01e1b5
No known key found for this signature in database
GPG Key ID: F52AF77F636088F0
12 changed files with 44 additions and 44 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -9,9 +9,9 @@ const { appendFile } = promises
export type AddEnvOptions = {
/** If true, the value will be escaped with quotes and spaces will be escaped with backslash */
shouldEscapeSpace: boolean
/** If true, the variable will be only added if it is not defined */
shouldAddOnlyIfNotDefined: boolean
escapeSpace: boolean
/** If false, the variable will be only added if it is not already defined (Default to true) */
overwrite: boolean
/**
* The path to the RC file that the env variables should be added to.
*/
@ -31,17 +31,17 @@ export async function addEnv(
givenOptions: Partial<AddEnvOptions> = {},
) {
const options = {
shouldEscapeSpace: false,
shouldAddOnlyIfNotDefined: false,
escapeSpace: false,
overwrite: true,
rcPath: defaultRcPath,
...givenOptions,
}
const val = escapeString(valGiven ?? "", options.shouldEscapeSpace)
const val = escapeString(valGiven ?? "", options.escapeSpace)
try {
if (GITHUB_ACTIONS) {
try {
if (options.shouldAddOnlyIfNotDefined) {
if (!options.overwrite) {
if (process.env[name] !== undefined) {
info(`Environment variable ${name} is already defined. Skipping.`)
return
@ -64,7 +64,7 @@ async function addEnvSystem(name: string, valGiven: string | undefined, options:
const val = valGiven ?? ""
switch (process.platform) {
case "win32": {
if (options.shouldAddOnlyIfNotDefined) {
if (!options.overwrite) {
if (process.env[name] !== undefined) {
info(`Environment variable ${name} is already defined. Skipping.`)
return
@ -78,7 +78,7 @@ async function addEnvSystem(name: string, valGiven: string | undefined, options:
case "linux":
case "darwin": {
await sourceRCInRc(options)
if (options.shouldAddOnlyIfNotDefined) {
if (!options.overwrite) {
await appendFile(options.rcPath, `\nif [ -z "\${${name}}" ]; then export ${name}="${val}"; fi\n`)
info(`if not defined ${name} then ${name}="${val}" was added to "${options.rcPath}`)
} else {

View File

@ -222,10 +222,10 @@ async function initApt(apt: string) {
addAptKeyViaServer(["1E9377A2BA9EF27F"], "launchpad-toolchain.gpg"),
]
if (apt === "nala") {
// enable utf8 otherwise it fails because of the usage of ASCII encoding
// If LANGE/LC_ALL is not set, enable utf8 otherwise nala fails because of ASCII encoding
promises.push(
addEnv("LANG", "C.UTF-8", { shouldAddOnlyIfNotDefined: true, ...rcOptions }),
addEnv("LC_ALL", "C.UTF-8", { shouldAddOnlyIfNotDefined: true, ...rcOptions }),
addEnv("LANG", "C.UTF-8", { overwrite: false, ...rcOptions }),
addEnv("LC_ALL", "C.UTF-8", { overwrite: false, ...rcOptions }),
)
}
await Promise.all(promises)

View File

@ -8,11 +8,11 @@
"outputs": ["dist/**"]
},
"lint.tsc": {
"dependsOn": ["^lint.tsc"],
"dependsOn": ["build", "^lint.tsc"],
"inputs": ["$TURBO_DEFAULT$", ".env*"]
},
"lint.eslint": {
"dependsOn": ["^lint.eslint"],
"dependsOn": ["build", "^lint.eslint"],
"inputs": ["$TURBO_DEFAULT$", ".env*"]
},
"lint": {