@gesslar/uglier 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +45 -10
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -374,7 +374,7 @@ export async function addToConfig(targets = []) {
|
|
|
374
374
|
const existingContent = await configFile.read()
|
|
375
375
|
|
|
376
376
|
// Parse the with array from the existing config
|
|
377
|
-
const withMatch = existingContent.match(/with:\s*\[([\s\S]*?)\]/m)
|
|
377
|
+
const withMatch = existingContent.match(/with:\s*\[([\s\S]*?)\n\s*\]/m)
|
|
378
378
|
const existingTargets = parseTargetsFromConfig(existingContent)
|
|
379
379
|
|
|
380
380
|
if(existingTargets.length === 0 || !withMatch) {
|
|
@@ -427,7 +427,7 @@ export async function addToConfig(targets = []) {
|
|
|
427
427
|
}
|
|
428
428
|
|
|
429
429
|
const newContent = existingContent.replace(
|
|
430
|
-
/with:\s*\[([\s\S]*?)\]/m,
|
|
430
|
+
/with:\s*\[([\s\S]*?)\n\s*\]/m,
|
|
431
431
|
`with: [\n${newWithContent}\n ]`
|
|
432
432
|
)
|
|
433
433
|
|
|
@@ -549,21 +549,56 @@ export async function removeFromConfig(targets = []) {
|
|
|
549
549
|
|
|
550
550
|
// Check for and remove overrides for removed targets
|
|
551
551
|
const removedOverrides = []
|
|
552
|
-
const overridesMatch =
|
|
552
|
+
const overridesMatch = newContent.match(/overrides:\s*\{/m)
|
|
553
553
|
|
|
554
554
|
if(overridesMatch) {
|
|
555
555
|
for(const target of targetsToRemove) {
|
|
556
|
-
//
|
|
557
|
-
const
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
556
|
+
// Find the start of this target's override entry
|
|
557
|
+
const targetPattern = new RegExp(`[\\s,]*(?:\\/\\/[^\\n]*\\n\\s*)?["']${target}["']:\\s*\\{`)
|
|
558
|
+
const targetMatch = targetPattern.exec(newContent)
|
|
559
|
+
|
|
560
|
+
if(targetMatch) {
|
|
561
|
+
// Count braces to find the full extent of the block
|
|
562
|
+
const blockStart = targetMatch.index
|
|
563
|
+
let braceDepth = 0
|
|
564
|
+
let blockEnd = -1
|
|
565
|
+
|
|
566
|
+
for(let i = blockStart; i < newContent.length; i++) {
|
|
567
|
+
if(newContent[i] === "{") {
|
|
568
|
+
braceDepth++
|
|
569
|
+
} else if(newContent[i] === "}") {
|
|
570
|
+
braceDepth--
|
|
571
|
+
|
|
572
|
+
if(braceDepth === 0) {
|
|
573
|
+
blockEnd = i + 1
|
|
574
|
+
|
|
575
|
+
// Skip trailing comma if present
|
|
576
|
+
if(newContent[blockEnd] === ",") {
|
|
577
|
+
blockEnd++
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
break
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
if(blockEnd !== -1) {
|
|
586
|
+
removedOverrides.push(target)
|
|
587
|
+
newContent = newContent.slice(0, blockStart)
|
|
588
|
+
+ newContent.slice(blockEnd)
|
|
589
|
+
}
|
|
562
590
|
}
|
|
563
591
|
}
|
|
564
592
|
|
|
593
|
+
// Ensure commas between remaining override entries
|
|
594
|
+
newContent = newContent.replace(
|
|
595
|
+
/\}(\s*["'][\w-]+["']:\s*\{)/g, "},$1"
|
|
596
|
+
)
|
|
597
|
+
|
|
565
598
|
// Clean up empty overrides object or trailing commas
|
|
566
|
-
newContent = newContent.replace(
|
|
599
|
+
newContent = newContent.replace(
|
|
600
|
+
/overrides:\s*\{\s*,?\s*\}/m, ""
|
|
601
|
+
)
|
|
567
602
|
newContent = newContent.replace(/,(\s*)\}/g, "$1}")
|
|
568
603
|
}
|
|
569
604
|
|