Skip to content

Commit

Permalink
fix(update): 修复 update 本地 envConfig 文件时多行匹配处理错误的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
renxia committed May 14, 2024
1 parent 3e3e203 commit cf73040
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: renxia
* @Date: 2024-01-11 13:38:34
* @LastEditors: renxia
* @LastEditTime: 2024-05-07 09:34:05
* @LastEditTime: 2024-05-13 09:35:32
* @Description:
*/
import fs from 'node:fs';
Expand Down Expand Up @@ -77,7 +77,7 @@ export async function updateEnvConfigFile(envConfig: EnvConfig, updateEnvValue:
const isExist = content.includes(`export ${name}=`);

if (isExist) {
const oldValue = content.match(new RegExp(`export ${name}="(.*)"`))?.[1] || '';
const oldValue = content.match(new RegExp(`export ${name}="([^"]+)"`))?.[1] || '';

if (oldValue.includes(value)) {
logger.log(`[UpdateEnv]${color.cyan(name)} 已存在`, color.gray(value));
Expand All @@ -93,7 +93,7 @@ export async function updateEnvConfigFile(envConfig: EnvConfig, updateEnvValue:
value = updateEnvValueByRegExp(/##([a-z0-9_\-*]+)/i, envConfig, value);
}

content = content.replace(new RegExp(`export ${name}=.*`, 'g'), `export ${name}="${value}"`);
content = content.replace(`export ${name}="${oldValue}"`, `export ${name}="${value}"`);
} else {
if (desc) content += `\n# ${desc}`;
content += `\nexport ${name}="${value}"`;
Expand Down

0 comments on commit cf73040

Please sign in to comment.