codeplay-common 2.0.1 → 2.0.2
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.
|
@@ -984,6 +984,72 @@ checkPlugins();
|
|
|
984
984
|
|
|
985
985
|
|
|
986
986
|
|
|
987
|
+
// ====================================================================
|
|
988
|
+
// AUTO-ADD esbuild.drop: ['console','debugger'] to vite.config.js
|
|
989
|
+
// ====================================================================
|
|
990
|
+
const checkAndupdateDropInViteConfig=()=>{
|
|
991
|
+
const viteConfigPath = path.join(process.cwd(), "vite.config.js");
|
|
992
|
+
|
|
993
|
+
if (fs.existsSync(viteConfigPath)) {
|
|
994
|
+
let viteContent = fs.readFileSync(viteConfigPath, "utf8");
|
|
995
|
+
|
|
996
|
+
// If drop already exists → skip
|
|
997
|
+
if (/drop\s*:\s*\[.*['"]console['"].*\]/.test(viteContent)) {
|
|
998
|
+
console.log("ℹ️ esbuild.drop already exists. Skipping.");
|
|
999
|
+
} else {
|
|
1000
|
+
console.log("🔧 Adding aligned esbuild.drop to vite.config.js ...");
|
|
1001
|
+
|
|
1002
|
+
// If esbuild block exists
|
|
1003
|
+
if (/esbuild\s*:\s*{/.test(viteContent)) {
|
|
1004
|
+
viteContent = viteContent.replace(
|
|
1005
|
+
/esbuild\s*:\s*{([\s\S]*?)(^ {0,8})}/m,
|
|
1006
|
+
(full, inner, indent) => {
|
|
1007
|
+
// Split & clean lines
|
|
1008
|
+
let lines = inner
|
|
1009
|
+
.split("\n")
|
|
1010
|
+
.map(l => l.trim())
|
|
1011
|
+
.filter(l => l.length > 0);
|
|
1012
|
+
|
|
1013
|
+
// Fix the last property: remove extra commas then add 1 comma
|
|
1014
|
+
if (lines.length > 0) {
|
|
1015
|
+
lines[lines.length - 1] =
|
|
1016
|
+
lines[lines.length - 1].replace(/,+$/, "") + ",";
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
// Re-indent correctly
|
|
1020
|
+
lines = lines.map(l => indent + " " + l);
|
|
1021
|
+
|
|
1022
|
+
// Insert drop at end (no comma needed because it's last)
|
|
1023
|
+
lines.push(`${indent} drop: ['console','debugger'],`);
|
|
1024
|
+
|
|
1025
|
+
// Final block
|
|
1026
|
+
return `esbuild: {\n${lines.join("\n")}\n${indent}}`;
|
|
1027
|
+
}
|
|
1028
|
+
);
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
// If esbuild block missing → add new
|
|
1032
|
+
else {
|
|
1033
|
+
viteContent = viteContent.replace(
|
|
1034
|
+
/export default defineConfig\s*\(\s*{/,
|
|
1035
|
+
m => `${m}\n esbuild: {\n drop: ['console','debugger'],\n },`
|
|
1036
|
+
);
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
// Save
|
|
1040
|
+
fs.writeFileSync(viteConfigPath, viteContent, "utf8");
|
|
1041
|
+
console.log("✅ Added successfully with perfect comma alignment.");
|
|
1042
|
+
}
|
|
1043
|
+
} else {
|
|
1044
|
+
console.warn("⚠️ vite.config.js not found, skipping.");
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
checkAndupdateDropInViteConfig();
|
|
1049
|
+
|
|
1050
|
+
|
|
1051
|
+
|
|
1052
|
+
|
|
987
1053
|
|
|
988
1054
|
|
|
989
1055
|
|