File tree Expand file tree Collapse file tree 1 file changed +30
-2
lines changed
Expand file tree Collapse file tree 1 file changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -218,6 +218,30 @@ export class ConfigValidator {
218218 return / ^ @ [ ^ / ] + \/ [ ^ / ] + ( \/ [ ^ / ] + ) ? $ | ^ l o c a l $ | ^ < .* > $ / . test ( target ) ;
219219 }
220220
221+ /**
222+ * 从 target 字符串中提取引用的环境变量键名
223+ * 支持格式:
224+ * - @username/project/key -> key
225+ * - 直接键名(存在于 config.env 中)-> 键名本身
226+ */
227+ private static extractReferencedKey ( config : EnvxConfig , target : string ) : string | null {
228+ // @username /project/key 格式:提取最后一段作为 key
229+ const match = target . match ( / ^ @ [ ^ / ] + \/ [ ^ / ] + \/ ( [ ^ / ] + ) $ / ) ;
230+ if ( match ) {
231+ const key = match [ 1 ] ;
232+ if ( key in config . env ) {
233+ return key ;
234+ }
235+ }
236+
237+ // 直接键名引用
238+ if ( target in config . env ) {
239+ return target ;
240+ }
241+
242+ return null ;
243+ }
244+
221245 /**
222246 * 检查循环引用
223247 */
@@ -234,8 +258,12 @@ export class ConfigValidator {
234258 const current = config . env [ currentKey ] ;
235259
236260 if ( typeof current === 'object' && current !== null && current . target ) {
237- // 这里可以添加更复杂的循环引用检测逻辑
238- // 目前只是简单的检查
261+ const referencedKey = this . extractReferencedKey ( config , current . target ) ;
262+ if ( referencedKey ) {
263+ if ( this . hasCircularReference ( config , referencedKey , visited ) ) {
264+ return true ;
265+ }
266+ }
239267 }
240268
241269 visited . delete ( currentKey ) ;
You can’t perform that action at this time.
0 commit comments