exguard-backend 1.0.26 → 1.0.28
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/package.json +1 -1
- package/scripts/setup-nestjs.cjs +38 -27
package/package.json
CHANGED
package/scripts/setup-nestjs.cjs
CHANGED
|
@@ -598,34 +598,45 @@ function updateAppModule() {
|
|
|
598
598
|
return;
|
|
599
599
|
}
|
|
600
600
|
|
|
601
|
-
// Add at the
|
|
602
|
-
|
|
601
|
+
// Add import at the top
|
|
602
|
+
const importStatement = "import { ExGuardModule } from './exguard/exguard.module';\n";
|
|
603
|
+
appModuleContent = importStatement + appModuleContent;
|
|
604
|
+
|
|
605
|
+
// Check if ThrottlerModule.forRootAsync exists and add ExGuardModule to its imports
|
|
606
|
+
const throttlerAsyncMatch = appModuleContent.match(/ThrottlerModule\.forRootAsync\(\{[\s\S]*?imports:\s*\[([^\]]*)\]/);
|
|
607
|
+
let addedToThrottler = false;
|
|
608
|
+
if (throttlerAsyncMatch) {
|
|
609
|
+
const throttlerImports = throttlerAsyncMatch[1];
|
|
610
|
+
if (!throttlerImports.includes('ExGuardModule')) {
|
|
611
|
+
// Clean up trailing commas and add ExGuardModule
|
|
612
|
+
let cleanedImports = throttlerImports.trim().replace(/,\s*,/g, ',').replace(/,\s*\]/g, ']');
|
|
613
|
+
if (!cleanedImports.endsWith(']')) {
|
|
614
|
+
cleanedImports = cleanedImports.replace(/,\s*$/, '') + ',\n ExGuardModule';
|
|
615
|
+
appModuleContent = appModuleContent.replace(
|
|
616
|
+
throttlerAsyncMatch[0],
|
|
617
|
+
throttlerAsyncMatch[0].replace(throttlerImports, cleanedImports)
|
|
618
|
+
);
|
|
619
|
+
addedToThrottler = true;
|
|
620
|
+
logSuccess('Added ExGuardModule to ThrottlerModule.forRootAsync imports');
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
603
624
|
|
|
604
|
-
//
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
} else {
|
|
620
|
-
// Add imports array after @Module({
|
|
621
|
-
const moduleStartMatch = appModuleContent.match(/@Module\s*\(\s*\{/);
|
|
622
|
-
if (moduleStartMatch) {
|
|
623
|
-
const moduleStartIndex = appModuleContent.indexOf(moduleStartMatch[0]);
|
|
624
|
-
const afterModuleStart = appModuleContent.substring(moduleStartIndex + moduleStartMatch[0].length);
|
|
625
|
-
|
|
626
|
-
appModuleContent = appModuleContent.substring(0, moduleStartIndex + moduleStartMatch[0].length) +
|
|
627
|
-
`\n imports: [ExGuardModule],` +
|
|
628
|
-
afterModuleStart;
|
|
625
|
+
// Only add to main imports if not added to ThrottlerModule
|
|
626
|
+
if (!addedToThrottler) {
|
|
627
|
+
const moduleDecoratorMatch = appModuleContent.match(/@Module\s*\(\s*\{([\s\S]*?)\n\}\s*\)/);
|
|
628
|
+
if (moduleDecoratorMatch) {
|
|
629
|
+
const moduleContent = moduleDecoratorMatch[1];
|
|
630
|
+
const importsArrayMatch = moduleContent.match(/imports:\s*\[([\s\S]*?)\]/);
|
|
631
|
+
if (importsArrayMatch) {
|
|
632
|
+
let importsContent = importsArrayMatch[1].trim().replace(/,\s*,/g, ',').replace(/,\s*\]/g, ']');
|
|
633
|
+
if (!importsContent.endsWith(']')) {
|
|
634
|
+
importsContent = importsContent.replace(/,\s*$/, '') + ',\n ExGuardModule';
|
|
635
|
+
appModuleContent = appModuleContent.replace(
|
|
636
|
+
importsArrayMatch[0],
|
|
637
|
+
`imports: [${importsContent}]`
|
|
638
|
+
);
|
|
639
|
+
}
|
|
629
640
|
}
|
|
630
641
|
}
|
|
631
642
|
}
|