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 c969264
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"devDependencies": {
"@lzwme/fed-lint-helper": "^2.6.0",
"@types/node": "^20.12.8",
"@types/node": "^20.12.12",
"base64-js": "^1.5.1",
"crypto-js": "^4.2.0",
"husky": "^9.0.11",
Expand Down
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 c969264

Please sign in to comment.