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

View File

@ -222,10 +222,10 @@ async function initApt(apt: string) {
addAptKeyViaServer(["1E9377A2BA9EF27F"], "launchpad-toolchain.gpg"), addAptKeyViaServer(["1E9377A2BA9EF27F"], "launchpad-toolchain.gpg"),
] ]
if (apt === "nala") { 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( promises.push(
addEnv("LANG", "C.UTF-8", { shouldAddOnlyIfNotDefined: true, ...rcOptions }), addEnv("LANG", "C.UTF-8", { overwrite: false, ...rcOptions }),
addEnv("LC_ALL", "C.UTF-8", { shouldAddOnlyIfNotDefined: true, ...rcOptions }), addEnv("LC_ALL", "C.UTF-8", { overwrite: false, ...rcOptions }),
) )
} }
await Promise.all(promises) await Promise.all(promises)

View File

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