patch-fmode-logs.mjs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * Postinstall script: patch fmode-ng console.log to silence HTTP request logging.
  3. * Runs after every pnpm/npm install to keep the patch applied.
  4. */
  5. import { readFileSync, writeFileSync, existsSync } from 'fs';
  6. const FILES = [
  7. 'node_modules/fmode-ng/esm2022/lib/core/parse/fmode.query.mjs',
  8. 'node_modules/fmode-ng/esm2022/lib/core/parse/fmode.object.mjs',
  9. 'node_modules/fmode-ng/esm2022/lib/core/parse/fmode.parse.mjs',
  10. 'node_modules/fmode-ng/esm2022/lib/core/parse/fmode.user.mjs',
  11. 'node_modules/fmode-ng/esm2022/lib/core/parse/fmode.cloud.mjs',
  12. 'node_modules/fmode-ng/esm2022/lib/core/parse/fmode.schema.mjs',
  13. 'node_modules/fmode-ng/fesm2022/fmode-ng.mjs',
  14. ];
  15. let patched = 0;
  16. for (const filePath of FILES) {
  17. if (!existsSync(filePath)) continue;
  18. let content = readFileSync(filePath, 'utf-8');
  19. // Comment out standalone console.log lines
  20. const before = content.length;
  21. content = content.replace(/^\s*console\.log\([^)]*\);?\s*$/gm, '');
  22. content = content.replace(/console\.log\(/g, '// console.log(');
  23. if (content.length !== before) {
  24. writeFileSync(filePath, content);
  25. patched++;
  26. }
  27. }
  28. if (patched > 0) {
  29. console.log(`[patch-fmode-logs] silenced ${patched} files`);
  30. }