#!/usr/bin/env node

process.emitWarning = () => {};
process.removeAllListeners("warning");

// ast-grep gives annoying warnings
console.debug = () => {};

// Suppress specific experimental warnings
const originalEmit = process.emit;
process.emit = function (event, ...args) {
  if (event === "warning" && args[0]) {
    const warning = args[0];
    // Suppress ExperimentalWarning (including JSON module imports)
    if (warning.name === "ExperimentalWarning") {
      return false;
    }
    // Suppress DEP0040
    if (warning.code === "DEP0040") {
      return false;
    }
  }
  return originalEmit.apply(process, [event, ...args]);
};

// Initialize Sentry for Node.js (performance monitoring, no profiling)
// This runs before the main CLI to ensure all errors are captured
(async () => {
  if (process.env.POWERLINT_SENTRY_DSN) {
    const Sentry = await import("@sentry/node");
    
    Sentry.init({
      dsn: process.env.POWERLINT_SENTRY_DSN,
      environment: "production",
      sendDefaultPii: true,
      tracesSampleRate: 1.0,
      // No profiling integration
    });

    // Set CLI context for better error tracking
    // Note: getCurrentVersion is in the bundle, we'll set basic context here
    Sentry.setContext("cli", {
      platform: process.platform,
      arch: process.arch,
      runtime: "node",
      nodeVersion: process.version,
    });
  }

  // Use the file extension to help the module resolver find the file
  await import("./cli-bundle.js");
})().catch(console.error);
